1 /*=========================================================================
4 Module: $RCSfile: gdcmDocEntry.cxx,v $
6 Date: $Date: 2004/11/19 18:49:39 $
7 Version: $Revision: 1.32 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #include "gdcmDocEntry.h"
21 #include "gdcmGlobal.h"
24 #include <iomanip> // for std::ios::left, ...
31 #define MAX_SIZE_PRINT_ELEMENT_VALUE 64
33 //-----------------------------------------------------------------------------
34 // Constructor / Destructor
37 * \brief Constructor from a given DictEntry
38 * @param in Pointer to existing dictionary entry
40 DocEntry::DocEntry(DictEntry* in)
44 SetKey( in->GetKey( ) );
45 Offset = 0 ; // To avoid further missprinting
47 // init some variables
53 //-----------------------------------------------------------------------------
57 * \brief Prints the common part of ValEntry, BinEntry, SeqEntry
58 * @param os ostream we want to print in
60 void DocEntry::Print(std::ostream& os)
62 PrintLevel = 2; // FIXME
74 s << DictEntry::TranslateToKey(GetGroup(),GetElement());
79 lgth = GetReadLength(); // ReadLength, as opposed to UsableLength
80 if (lgth == 0xffffffff)
82 st = Util::Format("x(ffff)"); // I said : "x(ffff)" !
83 s.setf(std::ios::left);
84 s << std::setw(10-st.size()) << " ";
86 s.setf(std::ios::left);
87 s << std::setw(8) << "-1";
91 st = Util::Format("x(%x)",lgth);
92 s.setf(std::ios::left);
93 s << std::setw(10-st.size()) << " ";
95 s.setf(std::ios::left);
96 s << std::setw(8) << lgth;
99 st = Util::Format("x(%x)",o);
100 s << std::setw(10-st.size()) << " ";
102 s << std::setw(8) << o;
105 s << "[" << vr << "] ";
109 s.setf(std::ios::left);
110 s << std::setw(66-GetName().length()) << " ";
113 s << "[" << GetName()<< "]";
119 * \brief Writes the common part of any ValEntry, BinEntry, SeqEntry
120 * @param fp already open file pointer
121 * @param filetype type of the file to be written
123 void DocEntry::Write(std::ofstream* fp, FileType filetype)
125 uint32_t ffff = 0xffffffff;
126 uint16_t group = GetGroup();
128 uint16_t el = GetElement();
129 uint32_t lgr = GetReadLength();
131 if ( group == 0xfffe && el == 0x0000 )
133 // Fix in order to make some MR PHILIPS images e-film readable
134 // see gdcmData/gdcm-MR-PHILIPS-16-Multi-Seq.dcm:
135 // we just *always* ignore spurious fffe|0000 tag !
140 // ----------- Writes the common part
142 binary_write( *fp, group); //group
143 binary_write( *fp, el); //element
145 if ( filetype == ExplicitVR )
147 // Special case of delimiters:
150 // Delimiters have NO Value Representation
151 // Hence we skip writing the VR.
152 // In order to avoid further troubles, we choose to write them
153 // as 'no-length' Item Delimitors (we pad by writing 0xffffffff)
154 // The end of a given Item will be found when :
155 // - a new Item Delimitor Item is encountered (the Seq goes on)
156 // - a Sequence Delimitor Item is encountered (the Seq just ended)
158 // TODO : verify if the Sequence Delimitor Item was forced during Parsing
160 uint32_t ff = 0xffffffff;
161 binary_write(*fp, ff);
166 uint16_t shortLgr = lgr;
170 // Unknown was 'written'
171 // deal with Little Endian
172 binary_write(*fp, shortLgr);
173 binary_write(*fp, z);
177 binary_write(*fp, vr);
178 assert( vr.size() == 2 );
180 if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") || (vr == "UN") )
182 binary_write(*fp, z);
185 // we set SQ length to ffffffff
186 // and we shall write a Sequence Delimitor Item
187 // at the end of the Sequence!
188 binary_write(*fp, ffff);
192 binary_write(*fp, lgr);
197 binary_write(*fp, shortLgr);
205 binary_write(*fp, ffff);
209 binary_write(*fp, lgr);
214 //-----------------------------------------------------------------------------
219 * \brief Gets the full length of the elementary DocEntry (not only value
220 * length) depending on the VR.
222 uint32_t DocEntry::GetFullLength()
224 uint32_t l = GetReadLength();
225 if ( IsImplicitVR() )
227 l = l + 8; // 2 (gr) + 2 (el) + 4 (lgth)
231 if ( GetVR()=="OB" || GetVR()=="OW" || GetVR()=="SQ" )
233 l = l + 12; // 2 (gr) + 2 (el) + 2 (vr) + 2 (unused) + 4 (lgth)
237 l = l + 8; // 2 (gr) + 2 (el) + 2 (vr) + 2 (lgth)
245 * \brief Copies all the attributes from an other DocEntry
247 void DocEntry::Copy (DocEntry* e)
249 // DicomDict = e->DicomDict;
250 UsableLength = e->UsableLength;
251 ReadLength = e->ReadLength;
252 ImplicitVR = e->ImplicitVR;
254 PrintLevel = e->PrintLevel;
255 // TODO : remove DocEntry SQDepth
260 * \brief tells us if entry is the last one of a 'no length' SequenceItem
263 bool DocEntry::IsItemDelimitor()
265 return (GetGroup() == 0xfffe && GetElement() == 0xe00d);
269 * \brief tells us if entry is the last one of a 'no length' Sequence
272 bool DocEntry::IsSequenceDelimitor()
274 return (GetGroup() == 0xfffe && GetElement() == 0xe0dd);
277 //-----------------------------------------------------------------------------
281 //-----------------------------------------------------------------------------
284 //-----------------------------------------------------------------------------
286 } // end namespace gdcm