1 /*=========================================================================
4 Module: $RCSfile: gdcmDocEntry.cxx,v $
6 Date: $Date: 2004/11/03 20:52:13 $
7 Version: $Revision: 1.29 $
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
48 //-----------------------------------------------------------------------------
52 * \brief Prints the common part of ValEntry, BinEntry, SeqEntry
53 * @param os ostream we want to print in
55 void DocEntry::Print(std::ostream& os)
57 PrintLevel = 2; // FIXME
60 unsigned short int g, e;
72 s << DictEntry::TranslateToKey(GetGroup(),GetElement());
77 lgth = GetReadLength(); // ReadLength, as opposed to UsableLength
78 if (lgth == 0xffffffff)
80 st = Util::Format("x(ffff)"); // I said : "x(ffff)" !
81 s.setf(std::ios::left);
82 s << std::setw(10-st.size()) << " ";
84 s.setf(std::ios::left);
85 s << std::setw(8) << "-1";
89 st = Util::Format("x(%x)",lgth);
90 s.setf(std::ios::left);
91 s << std::setw(10-st.size()) << " ";
93 s.setf(std::ios::left);
94 s << std::setw(8) << lgth;
97 st = Util::Format("x(%x)",o);
98 s << std::setw(10-st.size()) << " ";
100 s << std::setw(8) << o;
103 s << "[" << vr << "] ";
107 s.setf(std::ios::left);
108 s << std::setw(66-GetName().length()) << " ";
111 s << "[" << GetName()<< "]";
117 * \brief Writes the common part of any ValEntry, BinEntry, SeqEntry
118 * @param fp already open file pointer
119 * @param filetype type of the file to be written
121 void DocEntry::Write(std::ofstream* fp, FileType filetype)
123 uint32_t ffff = 0xffffffff;
124 uint16_t group = GetGroup();
126 uint16_t el = GetElement();
127 uint32_t lgr = GetReadLength();
129 if ( group == 0xfffe && el == 0x0000 )
131 // Fix in order to make some MR PHILIPS images e-film readable
132 // see gdcmData/gdcm-MR-PHILIPS-16-Multi-Seq.dcm:
133 // we just *always* ignore spurious fffe|0000 tag !
138 // ----------- Writes the common part
140 binary_write( *fp, group); //group
141 binary_write( *fp, el); //element
143 if ( filetype == ExplicitVR )
145 // Special case of delimiters:
148 // Delimiters have NO Value Representation
149 // Hence we skip writing the VR.
150 // In order to avoid further troubles, we choose to write them
151 // as 'no-length' Item Delimitors (we pad by writing 0xffffffff)
152 // The end of a given Item will be found when :
153 // - a new Item Delimitor Item is encountered (the Seq goes on)
154 // - a Sequence Delimitor Item is encountered (the Seq just ended)
156 // TODO : verify if the Sequence Delimitor Item was forced during Parsing
158 uint32_t ff = 0xffffffff;
159 binary_write(*fp, ff);
164 uint16_t shortLgr = lgr;
168 // Unknown was 'written'
169 // deal with Little Endian
170 binary_write(*fp, shortLgr);
171 binary_write(*fp, z);
175 binary_write(*fp, vr);
176 assert( vr.size() == 2 );
178 if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") || (vr == "UN") )
180 binary_write(*fp, z);
183 // we set SQ length to ffffffff
184 // and we shall write a Sequence Delimitor Item
185 // at the end of the Sequence!
186 binary_write(*fp, ffff);
190 binary_write(*fp, lgr);
195 binary_write(*fp, shortLgr);
203 binary_write(*fp, ffff);
207 binary_write(*fp, lgr);
212 //-----------------------------------------------------------------------------
217 * \brief Gets the full length of the elementary DocEntry (not only value
218 * length) depending on the VR.
220 uint32_t DocEntry::GetFullLength()
222 uint32_t l = GetReadLength();
223 if ( IsImplicitVR() )
225 l = l + 8; // 2 (gr) + 2 (el) + 4 (lgth)
229 if ( GetVR()=="OB" || GetVR()=="OW" || GetVR()=="SQ" )
231 l = l + 12; // 2 (gr) + 2 (el) + 2 (vr) + 2 (unused) + 4 (lgth)
235 l = l + 8; // 2 (gr) + 2 (el) + 2 (vr) + 2 (lgth)
243 * \brief Copies all the attributes from an other DocEntry
245 void DocEntry::Copy (DocEntry* e)
247 DicomDict = e->DicomDict;
248 UsableLength = e->UsableLength;
249 ReadLength = e->ReadLength;
250 ImplicitVR = e->ImplicitVR;
252 PrintLevel = e->PrintLevel;
253 // TODO : remove DocEntry SQDepth
258 * \brief tells us if entry is the last one of a 'no length' SequenceItem
261 bool DocEntry::IsItemDelimitor()
263 return (GetGroup() == 0xfffe && GetElement() == 0xe00d);
267 * \brief tells us if entry is the last one of a 'no length' Sequence
270 bool DocEntry::IsSequenceDelimitor()
272 return (GetGroup() == 0xfffe && GetElement() == 0xe0dd);
275 //-----------------------------------------------------------------------------
279 //-----------------------------------------------------------------------------
282 //-----------------------------------------------------------------------------
284 } // end namespace gdcm