1 /*=========================================================================
4 Module: $RCSfile: gdcmDocEntry.cxx,v $
6 Date: $Date: 2004/07/02 13:55:27 $
7 Version: $Revision: 1.13 $
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) {
41 //-----------------------------------------------------------------------------
44 * \ingroup gdcmDocEntry
45 * \brief Prints the common part of gdcmValEntry, gdcmBinEntry, gdcmSeqEntry
46 * @param os ostream we want to print in
48 void gdcmDocEntry::Print(std::ostream & os) {
50 printLevel=2; // FIXME
53 unsigned short int g, e;
59 char greltag[10]; //group element tag
65 sprintf(greltag,"%04x|%04x ",g,e);
70 lgth = GetReadLength(); // ReadLength, as opposed to UsableLength
71 if (lgth == 0xffffffff) {
72 sprintf(st,"x(ffff)"); // I said : "x(ffff)" !
73 s.setf(std::ios::left);
74 s << std::setw(10-strlen(st)) << " ";
76 s.setf(std::ios::left);
77 s << std::setw(8) << "-1";
79 sprintf(st,"x(%x)",lgth);
80 s.setf(std::ios::left);
81 s << std::setw(10-strlen(st)) << " ";
83 s.setf(std::ios::left);
84 s << std::setw(8) << lgth;
87 sprintf(st,"x(%x)",o);
88 s << std::setw(10-strlen(st)) << " ";
90 s << std::setw(8) << o;
93 s << "[" << vr << "] ";
96 s.setf(std::ios::left);
97 s << std::setw(66-GetName().length()) << " ";
100 s << "[" << GetName()<< "]";
105 * \ingroup gdcmDocEntry
106 * \brief Writes the common part of any gdcmValEntry, gdcmBinEntry, gdcmSeqEntry
108 void gdcmDocEntry::Write(FILE *fp, FileType filetype) {
110 uint32_t FFFF = 0xffffffff;
111 uint16_t group = GetGroup();
112 gdcmVRKey vr = GetVR();
113 uint16_t el = GetElement();
114 uint32_t lgr = GetReadLength();
116 if ( (group == 0xfffe) && (el == 0x0000) )
117 // Fix in order to make some MR PHILIPS images e-film readable
118 // see gdcmData/gdcm-MR-PHILIPS-16-Multi-Seq.dcm:
119 // we just *always* ignore spurious fffe|0000 tag !
123 // ----------- Writes the common part
125 fwrite ( &group,(size_t)2 ,(size_t)1 ,fp); //group
126 fwrite ( &el, (size_t)2 ,(size_t)1 ,fp); //element
128 if ( filetype == gdcmExplicitVR ) {
130 // Special case of delimiters:
131 if (group == 0xfffe) {
132 // Delimiters have NO Value Representation
133 // Hence we skip writing the VR.
134 // In order to avoid further troubles, we choose to write them
135 // as 'no-length' Item Delimitors (we pad by writing 0xffffffff)
136 // The end of a given Item will be found when :
137 // - a new Item Delimitor Item is encountered (the Seq goes on)
138 // - a Sequence Delimitor Item is encountered (the Seq just ended)
140 // TODO : verify if the Sequence Delimitor Item was forced during Parsing
143 fwrite (&ff,(size_t)4 ,(size_t)1 ,fp);
148 uint16_t shortLgr = lgr;
150 if (vr == "unkn") { // Unknown was 'written'
151 // deal with Little Endian
152 fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,fp);
153 fwrite ( &z, (size_t)2 ,(size_t)1 ,fp);
155 fwrite (vr.c_str(),(size_t)2 ,(size_t)1 ,fp);
157 if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") || (vr == "UN") )
159 fwrite ( &z, (size_t)2 ,(size_t)1 ,fp);
161 // we set SQ length to ffffffff
162 // and we shall write a Sequence Delimitor Item
163 // at the end of the Sequence!
164 fwrite ( &FFFF,(size_t)4 ,(size_t)1 ,fp);
166 fwrite ( &lgr,(size_t)4 ,(size_t)1 ,fp);
169 fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,fp);
176 fwrite ( &FFFF,(size_t)4 ,(size_t)1 ,fp);
178 fwrite ( &lgr,(size_t)4 ,(size_t)1 ,fp);
183 //-----------------------------------------------------------------------------
187 * \ingroup gdcmDocEntry
188 * \brief Gets the full length of the elementary DocEntry (not only value length)
190 uint32_t gdcmDocEntry::GetFullLength(void) {
193 if ( IsImplicitVR() )
194 l = l + 8; // 2 (gr) + 2 (el) + 4 (lgth)
196 if ( GetVR()=="OB" || GetVR()=="OW" || GetVR()=="SQ" )
197 l = l + 12; // 2 (gr) + 2 (el) + 2 (vr) + 2 (unused) + 4 (lgth)
199 l = l + 8; // 2 (gr) + 2 (el) + 2 (vr) + 2 (lgth)
204 * \ingroup gdcmDocEntry
205 * \brief Copies all the attributes from an other DocEntry
207 void gdcmDocEntry::Copy (gdcmDocEntry* e) {
208 this->entry = e->entry;
209 this->UsableLength = e->UsableLength;
210 this->ReadLength = e->ReadLength;
211 this->ImplicitVR = e->ImplicitVR;
212 this->Offset = e->Offset;
213 this->printLevel = e->printLevel;
214 // TODO : remove gdcmDocEntry SQDepth
218 * \ingroup gdcmDocEntry
219 * \brief tells us if entry is the last one of a 'no length' SequenceItem
222 bool gdcmDocEntry::isItemDelimitor() {
223 if ( (GetGroup() == 0xfffe) && (GetElement() == 0xe00d) )
229 * \ingroup gdcmDocEntry
230 * \brief tells us if entry is the last one of a 'no length' Sequence
233 bool gdcmDocEntry::isSequenceDelimitor() {
234 if (GetGroup() == 0xfffe && GetElement() == 0xe0dd)
240 //-----------------------------------------------------------------------------
244 //-----------------------------------------------------------------------------
247 //-----------------------------------------------------------------------------