1 /*=========================================================================
4 Module: $RCSfile: gdcmDocEntry.cxx,v $
6 Date: $Date: 2004/08/31 14:24:47 $
7 Version: $Revision: 1.16 $
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
113 * @param fp already open file pointer
114 * @param filetype type of the file to be written
116 void gdcmDocEntry::Write(FILE *fp, FileType filetype)
118 uint32_t FFFF = 0xffffffff;
119 uint16_t group = GetGroup();
120 gdcmVRKey vr = GetVR();
121 uint16_t el = GetElement();
122 uint32_t lgr = GetReadLength();
124 if ( group == 0xfffe && el == 0x0000 )
126 // Fix in order to make some MR PHILIPS images e-film readable
127 // see gdcmData/gdcm-MR-PHILIPS-16-Multi-Seq.dcm:
128 // we just *always* ignore spurious fffe|0000 tag !
133 // ----------- Writes the common part
135 fwrite ( &group,(size_t)2 ,(size_t)1 ,fp); //group
136 fwrite ( &el, (size_t)2 ,(size_t)1 ,fp); //element
138 if ( filetype == gdcmExplicitVR )
140 // Special case of delimiters:
143 // Delimiters have NO Value Representation
144 // Hence we skip writing the VR.
145 // In order to avoid further troubles, we choose to write them
146 // as 'no-length' Item Delimitors (we pad by writing 0xffffffff)
147 // The end of a given Item will be found when :
148 // - a new Item Delimitor Item is encountered (the Seq goes on)
149 // - a Sequence Delimitor Item is encountered (the Seq just ended)
151 // TODO : verify if the Sequence Delimitor Item was forced during Parsing
154 fwrite (&ff,(size_t)4 ,(size_t)1 ,fp);
159 uint16_t shortLgr = lgr;
163 // Unknown was 'written'
164 // deal with Little Endian
165 fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,fp);
166 fwrite ( &z, (size_t)2 ,(size_t)1 ,fp);
170 fwrite (vr.c_str(),(size_t)2 ,(size_t)1 ,fp);
172 if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") || (vr == "UN") )
174 fwrite ( &z, (size_t)2 ,(size_t)1 ,fp);
177 // we set SQ length to ffffffff
178 // and we shall write a Sequence Delimitor Item
179 // at the end of the Sequence!
180 fwrite ( &FFFF,(size_t)4 ,(size_t)1 ,fp);
184 fwrite ( &lgr,(size_t)4 ,(size_t)1 ,fp);
189 fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,fp);
197 fwrite ( &FFFF,(size_t)4 ,(size_t)1 ,fp);
201 fwrite ( &lgr,(size_t)4 ,(size_t)1 ,fp);
206 //-----------------------------------------------------------------------------
210 * \ingroup gdcmDocEntry
211 * \brief Gets the full length of the elementary DocEntry (not only value length)
213 uint32_t gdcmDocEntry::GetFullLength()
215 uint32_t l = GetReadLength();
216 if ( IsImplicitVR() )
218 l = l + 8; // 2 (gr) + 2 (el) + 4 (lgth)
222 if ( GetVR()=="OB" || GetVR()=="OW" || GetVR()=="SQ" )
224 l = l + 12; // 2 (gr) + 2 (el) + 2 (vr) + 2 (unused) + 4 (lgth)
228 l = l + 8; // 2 (gr) + 2 (el) + 2 (vr) + 2 (lgth)
235 * \ingroup gdcmDocEntry
236 * \brief Copies all the attributes from an other DocEntry
238 void gdcmDocEntry::Copy (gdcmDocEntry* e)
240 DictEntry = e->DictEntry;
241 UsableLength = e->UsableLength;
242 ReadLength = e->ReadLength;
243 ImplicitVR = e->ImplicitVR;
245 PrintLevel = e->PrintLevel;
246 // TODO : remove gdcmDocEntry SQDepth
250 * \ingroup gdcmDocEntry
251 * \brief tells us if entry is the last one of a 'no length' SequenceItem
254 bool gdcmDocEntry::IsItemDelimitor()
256 return (GetGroup() == 0xfffe && GetElement() == 0xe00d);
259 * \ingroup gdcmDocEntry
260 * \brief tells us if entry is the last one of a 'no length' Sequence
263 bool gdcmDocEntry::IsSequenceDelimitor()
265 return (GetGroup() == 0xfffe && GetElement() == 0xe0dd);
268 //-----------------------------------------------------------------------------
272 //-----------------------------------------------------------------------------
275 //-----------------------------------------------------------------------------