1 /*=========================================================================
4 Module: $RCSfile: gdcmDocEntry.cxx,v $
6 Date: $Date: 2004/12/03 20:16:57 $
7 Version: $Revision: 1.34 $
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"
22 #include "gdcmGlobal.h"
25 #include <iomanip> // for std::ios::left, ...
32 #define MAX_SIZE_PRINT_ELEMENT_VALUE 64
34 //-----------------------------------------------------------------------------
35 // Constructor / Destructor
38 * \brief Constructor from a given DictEntry
39 * @param in Pointer to existing dictionary entry
41 DocEntry::DocEntry(DictEntry* in)
45 SetKey( in->GetKey( ) );
46 Offset = 0 ; // To avoid further missprinting
48 // init some variables
54 //-----------------------------------------------------------------------------
58 * \brief Prints the common part of ValEntry, BinEntry, SeqEntry
59 * @param os ostream we want to print in
61 void DocEntry::Print(std::ostream& os)
63 PrintLevel = 2; // FIXME
75 s << DictEntry::TranslateToKey(GetGroup(),GetElement());
80 lgth = GetReadLength(); // ReadLength, as opposed to UsableLength
81 if (lgth == 0xffffffff)
83 st = Util::Format("x(ffff)"); // I said : "x(ffff)" !
84 s.setf(std::ios::left);
85 s << std::setw(10-st.size()) << " ";
87 s.setf(std::ios::left);
88 s << std::setw(8) << "-1";
92 st = Util::Format("x(%x)",lgth);
93 s.setf(std::ios::left);
94 s << std::setw(10-st.size()) << " ";
96 s.setf(std::ios::left);
97 s << std::setw(8) << lgth;
100 st = Util::Format("x(%x)",o);
101 s << std::setw(10-st.size()) << " ";
103 s << std::setw(8) << o;
106 s << "[" << vr << "] ";
110 s.setf(std::ios::left);
111 s << std::setw(66-GetName().length()) << " ";
114 s << "[" << GetName()<< "]";
120 * \brief Writes the common part of any ValEntry, BinEntry, SeqEntry
121 * @param fp already open file pointer
122 * @param filetype type of the file to be written
124 void DocEntry::WriteContent(std::ofstream* fp, FileType filetype)
126 uint32_t ffff = 0xffffffff;
127 uint16_t group = GetGroup();
129 uint16_t el = GetElement();
130 uint32_t lgr = GetReadLength();
132 if ( group == 0xfffe && el == 0x0000 )
134 // Fix in order to make some MR PHILIPS images e-film readable
135 // see gdcmData/gdcm-MR-PHILIPS-16-Multi-Seq.dcm:
136 // we just *always* ignore spurious fffe|0000 tag !
141 // ----------- Writes the common part
143 binary_write( *fp, group); //group
144 binary_write( *fp, el); //element
146 if ( filetype == ExplicitVR )
148 // Special case of delimiters:
151 // Delimiters have NO Value Representation
152 // Hence we skip writing the VR.
153 // In order to avoid further troubles, we choose to write them
154 // as 'no-length' Item Delimitors (we pad by writing 0xffffffff)
155 // The end of a given Item will be found when :
156 // - a new Item Delimitor Item is encountered (the Seq goes on)
157 // - a Sequence Delimitor Item is encountered (the Seq just ended)
159 // TODO : verify if the Sequence Delimitor Item was forced during Parsing
161 uint32_t ff = 0xffffffff;
162 binary_write(*fp, ff);
167 uint16_t shortLgr = lgr;
171 // Unknown was 'written'
172 // deal with Little Endian
173 binary_write(*fp, shortLgr);
174 binary_write(*fp, z);
178 binary_write(*fp, vr);
179 assert( vr.size() == 2 );
181 if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") || (vr == "UN") )
183 binary_write(*fp, z);
186 // we set SQ length to ffffffff
187 // and we shall write a Sequence Delimitor Item
188 // at the end of the Sequence!
189 binary_write(*fp, ffff);
193 binary_write(*fp, lgr);
198 binary_write(*fp, shortLgr);
206 binary_write(*fp, ffff);
210 binary_write(*fp, lgr);
215 //-----------------------------------------------------------------------------
220 * \brief Gets the full length of the elementary DocEntry (not only value
221 * length) depending on the VR.
223 uint32_t DocEntry::GetFullLength()
225 uint32_t l = GetReadLength();
226 if ( IsImplicitVR() )
228 l = l + 8; // 2 (gr) + 2 (el) + 4 (lgth)
232 if ( GetVR()=="OB" || GetVR()=="OW" || GetVR()=="SQ" )
234 l = l + 12; // 2 (gr) + 2 (el) + 2 (vr) + 2 (unused) + 4 (lgth)
238 l = l + 8; // 2 (gr) + 2 (el) + 2 (vr) + 2 (lgth)
246 * \brief Copies all the attributes from an other DocEntry
248 void DocEntry::Copy (DocEntry* e)
250 // DicomDict = e->DicomDict;
251 UsableLength = e->UsableLength;
252 ReadLength = e->ReadLength;
253 ImplicitVR = e->ImplicitVR;
255 PrintLevel = e->PrintLevel;
256 // TODO : remove DocEntry SQDepth
261 * \brief tells us if entry is the last one of a 'no length' SequenceItem
264 bool DocEntry::IsItemDelimitor()
266 return (GetGroup() == 0xfffe && GetElement() == 0xe00d);
270 * \brief tells us if entry is the last one of a 'no length' Sequence
273 bool DocEntry::IsSequenceDelimitor()
275 return (GetGroup() == 0xfffe && GetElement() == 0xe0dd);
278 //-----------------------------------------------------------------------------
282 //-----------------------------------------------------------------------------
285 //-----------------------------------------------------------------------------
287 } // end namespace gdcm