1 /*=========================================================================
4 Module: $RCSfile: gdcmDocEntry.cxx,v $
6 Date: $Date: 2005/01/18 14:28:32 $
7 Version: $Revision: 1.43 $
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"
24 #include "gdcmDebug.h"
26 #include <iomanip> // for std::ios::left, ...
33 #define MAX_SIZE_PRINT_ELEMENT_VALUE 64
35 //-----------------------------------------------------------------------------
36 // 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
53 //-----------------------------------------------------------------------------
56 * \brief Prints the common part of ValEntry, BinEntry, SeqEntry
57 * @param os ostream we want to print in
58 * @param indent Indentation string to be prepended during printing
60 void DocEntry::Print(std::ostream &os, std::string const & )
74 s << DictEntry::TranslateToKey(GetGroup(),GetElement());
79 lgth = GetReadLength(); // ReadLength, as opposed to Length
80 if (lgth == 0xffffffff)
82 st = Util::Format("x(ffff)"); // I said : "x(ffff)" !
83 s.setf(std::ios::left);
84 s << std::setw(10-st.size()) << " ";
86 s.setf(std::ios::left);
87 s << std::setw(8) << "-1";
91 st = Util::Format("x(%x)",lgth);
92 s.setf(std::ios::left);
93 s << std::setw(10-st.size()) << " ";
95 s.setf(std::ios::left);
96 s << std::setw(8) << lgth;
99 st = Util::Format("x(%x)",o);
100 s << std::setw(10-st.size()) << " ";
102 s << std::setw(8) << o;
105 s << "[" << vr << "] ";
109 s.setf(std::ios::left);
110 s << std::setw(66-GetName().length()) << " ";
113 s << "[" << GetName()<< "]";
118 * \brief Writes the common part of any ValEntry, BinEntry, SeqEntry
119 * @param fp already open file pointer
120 * @param filetype type of the file to be written
122 void DocEntry::WriteContent(std::ofstream *fp, FileType filetype)
124 uint32_t ffff = 0xffffffff;
125 uint16_t group = GetGroup();
127 uint16_t el = GetElement();
128 uint32_t lgr = GetLength();
130 if ( group == 0xfffe && el == 0x0000 )
132 // Fix in order to make some MR PHILIPS images e-film readable
133 // see gdcmData/gdcm-MR-PHILIPS-16-Multi-Seq.dcm:
134 // we just *always* ignore spurious fffe|0000 tag !
139 // ----------- Writes the common part
141 binary_write( *fp, group); //group
142 binary_write( *fp, el); //element
144 if ( filetype == ExplicitVR )
146 // Special case of delimiters:
149 // Delimiters have NO Value Representation
150 // Hence we skip writing the VR.
151 // In order to avoid further troubles, we choose to write them
152 // as 'no-length' Item Delimitors (we pad by writing 0xffffffff)
153 // The end of a given Item will be found when :
154 // - a new Item Delimitor Item is encountered (the Seq goes on)
155 // - a Sequence Delimitor Item is encountered (the Seq just ended)
157 // TODO : verify if the Sequence Delimitor Item was forced during Parsing
159 uint32_t ff = 0xffffffff;
160 binary_write(*fp, ff);
165 uint16_t shortLgr = lgr;
167 if (vr == GDCM_UNKNOWN)
169 // Unknown was 'written'
170 // deal with Little Endian
171 binary_write(*fp, shortLgr);
172 binary_write(*fp, z);
176 binary_write(*fp, vr);
177 gdcmAssertMacro( vr.size() == 2 );
179 if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") || (vr == "UN") )
181 binary_write(*fp, z);
184 // we set SQ length to ffffffff
185 // and we shall write a Sequence Delimitor Item
186 // at the end of the Sequence!
187 binary_write(*fp, ffff);
191 binary_write(*fp, lgr);
196 binary_write(*fp, shortLgr);
204 binary_write(*fp, ffff);
208 binary_write(*fp, lgr);
213 //-----------------------------------------------------------------------------
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)
242 * \brief Copies all the attributes from an other DocEntry
243 * @param e entry to copy from
245 void DocEntry::Copy (DocEntry *e)
248 ReadLength = e->ReadLength;
249 ImplicitVR = e->ImplicitVR;
254 * \brief tells us if entry is the last one of a 'no length' SequenceItem
257 bool DocEntry::IsItemDelimitor()
259 return (GetGroup() == 0xfffe && GetElement() == 0xe00d);
262 * \brief tells us if entry is the last one of a 'no length' Sequence
265 bool DocEntry::IsSequenceDelimitor()
267 return (GetGroup() == 0xfffe && GetElement() == 0xe0dd);
270 //-----------------------------------------------------------------------------
274 //-----------------------------------------------------------------------------
277 //-----------------------------------------------------------------------------
279 } // end namespace gdcm