1 /*=========================================================================
4 Module: $RCSfile: gdcmDocEntry.cxx,v $
6 Date: $Date: 2004/08/01 03:20:23 $
7 Version: $Revision: 1.15 $
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.htm 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, ...
27 #define MAX_SIZE_PRINT_ELEMENT_VALUE 64
29 //-----------------------------------------------------------------------------
30 // Constructor / Destructor
32 * \ingroup gdcmDocEntry
33 * \brief Constructor from a given gdcmDictEntry
34 * @param in Pointer to existing dictionary entry
36 gdcmDocEntry::gdcmDocEntry(gdcmDictEntry* in)
42 //-----------------------------------------------------------------------------
45 * \ingroup gdcmDocEntry
46 * \brief Prints the common part of gdcmValEntry, gdcmBinEntry, gdcmSeqEntry
47 * @param os ostream we want to print in
49 void gdcmDocEntry::Print(std::ostream & os)
51 PrintLevel = 2; // FIXME
54 unsigned short int g, e;
60 char greltag[10]; //group element tag
66 sprintf(greltag,"%04x|%04x ",g,e);
72 lgth = GetReadLength(); // ReadLength, as opposed to UsableLength
73 if (lgth == 0xffffffff)
75 sprintf(st,"x(ffff)"); // I said : "x(ffff)" !
76 s.setf(std::ios::left);
77 s << std::setw(10-strlen(st)) << " ";
79 s.setf(std::ios::left);
80 s << std::setw(8) << "-1";
84 sprintf(st,"x(%x)",lgth);
85 s.setf(std::ios::left);
86 s << std::setw(10-strlen(st)) << " ";
88 s.setf(std::ios::left);
89 s << std::setw(8) << lgth;
92 sprintf(st,"x(%x)",o);
93 s << std::setw(10-strlen(st)) << " ";
95 s << std::setw(8) << o;
98 s << "[" << vr << "] ";
102 s.setf(std::ios::left);
103 s << std::setw(66-GetName().length()) << " ";
106 s << "[" << GetName()<< "]";
111 * \ingroup gdcmDocEntry
112 * \brief Writes the common part of any gdcmValEntry, gdcmBinEntry, gdcmSeqEntry
114 void gdcmDocEntry::Write(FILE *fp, FileType filetype)
116 uint32_t FFFF = 0xffffffff;
117 uint16_t group = GetGroup();
118 gdcmVRKey vr = GetVR();
119 uint16_t el = GetElement();
120 uint32_t lgr = GetReadLength();
122 if ( group == 0xfffe && el == 0x0000 )
124 // Fix in order to make some MR PHILIPS images e-film readable
125 // see gdcmData/gdcm-MR-PHILIPS-16-Multi-Seq.dcm:
126 // we just *always* ignore spurious fffe|0000 tag !
131 // ----------- Writes the common part
133 fwrite ( &group,(size_t)2 ,(size_t)1 ,fp); //group
134 fwrite ( &el, (size_t)2 ,(size_t)1 ,fp); //element
136 if ( filetype == gdcmExplicitVR )
138 // Special case of delimiters:
141 // Delimiters have NO Value Representation
142 // Hence we skip writing the VR.
143 // In order to avoid further troubles, we choose to write them
144 // as 'no-length' Item Delimitors (we pad by writing 0xffffffff)
145 // The end of a given Item will be found when :
146 // - a new Item Delimitor Item is encountered (the Seq goes on)
147 // - a Sequence Delimitor Item is encountered (the Seq just ended)
149 // TODO : verify if the Sequence Delimitor Item was forced during Parsing
152 fwrite (&ff,(size_t)4 ,(size_t)1 ,fp);
157 uint16_t shortLgr = lgr;
161 // Unknown was 'written'
162 // deal with Little Endian
163 fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,fp);
164 fwrite ( &z, (size_t)2 ,(size_t)1 ,fp);
168 fwrite (vr.c_str(),(size_t)2 ,(size_t)1 ,fp);
170 if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") || (vr == "UN") )
172 fwrite ( &z, (size_t)2 ,(size_t)1 ,fp);
175 // we set SQ length to ffffffff
176 // and we shall write a Sequence Delimitor Item
177 // at the end of the Sequence!
178 fwrite ( &FFFF,(size_t)4 ,(size_t)1 ,fp);
182 fwrite ( &lgr,(size_t)4 ,(size_t)1 ,fp);
187 fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,fp);
195 fwrite ( &FFFF,(size_t)4 ,(size_t)1 ,fp);
199 fwrite ( &lgr,(size_t)4 ,(size_t)1 ,fp);
204 //-----------------------------------------------------------------------------
208 * \ingroup gdcmDocEntry
209 * \brief Gets the full length of the elementary DocEntry (not only value length)
211 uint32_t gdcmDocEntry::GetFullLength()
213 uint32_t l = GetReadLength();
214 if ( IsImplicitVR() )
216 l = l + 8; // 2 (gr) + 2 (el) + 4 (lgth)
220 if ( GetVR()=="OB" || GetVR()=="OW" || GetVR()=="SQ" )
222 l = l + 12; // 2 (gr) + 2 (el) + 2 (vr) + 2 (unused) + 4 (lgth)
226 l = l + 8; // 2 (gr) + 2 (el) + 2 (vr) + 2 (lgth)
233 * \ingroup gdcmDocEntry
234 * \brief Copies all the attributes from an other DocEntry
236 void gdcmDocEntry::Copy (gdcmDocEntry* e)
238 DictEntry = e->DictEntry;
239 UsableLength = e->UsableLength;
240 ReadLength = e->ReadLength;
241 ImplicitVR = e->ImplicitVR;
243 PrintLevel = e->PrintLevel;
244 // TODO : remove gdcmDocEntry SQDepth
248 * \ingroup gdcmDocEntry
249 * \brief tells us if entry is the last one of a 'no length' SequenceItem
252 bool gdcmDocEntry::IsItemDelimitor()
254 return (GetGroup() == 0xfffe && GetElement() == 0xe00d);
257 * \ingroup gdcmDocEntry
258 * \brief tells us if entry is the last one of a 'no length' Sequence
261 bool gdcmDocEntry::IsSequenceDelimitor()
263 return (GetGroup() == 0xfffe && GetElement() == 0xe0dd);
266 //-----------------------------------------------------------------------------
270 //-----------------------------------------------------------------------------
273 //-----------------------------------------------------------------------------