1 /*=========================================================================
4 Module: $RCSfile: gdcmDocEntry.cxx,v $
6 Date: $Date: 2005/01/30 17:30:57 $
7 Version: $Revision: 1.49 $
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, ...
31 #define MAX_SIZE_PRINT_ELEMENT_VALUE 64
33 //-----------------------------------------------------------------------------
34 // Constructor / Destructor
36 * \brief Constructor from a given DictEntry
37 * @param in Pointer to existing dictionary entry
39 DocEntry::DocEntry(DictEntry *in)
43 SetKey( in->GetKey( ) );
44 Offset = 0 ; // To avoid further missprinting
46 // init some variables
51 //-----------------------------------------------------------------------------
54 * \brief Prints the common part of ValEntry, BinEntry, SeqEntry
55 * @param os ostream we want to print in
56 * @param indent Indentation string to be prepended during printing
58 void DocEntry::Print(std::ostream &os, std::string const & )
72 s << DictEntry::TranslateToKey(GetGroup(),GetElement());
77 lgth = GetReadLength(); // ReadLength, as opposed to Length
78 if (lgth == 0xffffffff)
80 st = Util::Format("x(ffff)"); // I said : "x(ffff)" !
81 s.setf(std::ios::left);
82 s << std::setw(10-st.size()) << " ";
84 s.setf(std::ios::left);
85 s << std::setw(8) << "-1";
89 st = Util::Format("x(%x)",lgth);
90 s.setf(std::ios::left);
91 s << std::setw(10-st.size()) << " ";
93 s.setf(std::ios::left);
94 s << std::setw(8) << lgth;
97 st = Util::Format("x(%x)",o);
98 s << std::setw(10-st.size()) << " ";
100 s << std::setw(8) << o;
103 s << "[" << vr << "] ";
107 s.setf(std::ios::left);
108 s << std::setw(66-GetName().length()) << " ";
111 s << "[" << GetName()<< "]";
115 //-----------------------------------------------------------------------------
118 * \brief Writes the common part of any ValEntry, BinEntry, SeqEntry
119 * @param fp already open ofstream pointer
120 * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...)
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 !
138 // ----------- Writes the common part
140 binary_write( *fp, group); //group
141 binary_write( *fp, el); //element
143 if ( filetype == ExplicitVR )
145 // Special case of delimiters:
148 // Delimiters have NO Value Representation
149 // Hence we skip writing the VR.
150 // In order to avoid further troubles, we choose to write them
151 // as 'no-length' Item Delimitors (we pad by writing 0xffffffff)
152 // We shall force the end of a given Item by writting
153 // a Item Delimitation Item (fffe, e00d)
155 uint32_t ff = 0xffffffff;
156 binary_write(*fp, ff);
161 uint16_t shortLgr = lgr;
163 if (vr == GDCM_UNKNOWN)
165 // Unknown was 'written'
166 // deal with Little Endian
167 binary_write(*fp, shortLgr);
168 binary_write(*fp, z);
172 binary_write(*fp, vr);
173 gdcmAssertMacro( vr.size() == 2 );
175 if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") || (vr == "UN") )
177 binary_write(*fp, z);
180 // we set SQ length to ffffffff
181 // and we shall write a Sequence Delimitor Item
182 // at the end of the Sequence!
183 binary_write(*fp, ffff);
187 binary_write(*fp, lgr);
192 binary_write(*fp, shortLgr);
200 binary_write(*fp, ffff);
204 binary_write(*fp, lgr);
210 * \brief Gets the full length of the elementary DocEntry (not only value
211 * length) depending on the VR.
213 uint32_t DocEntry::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 * \brief Copies all the attributes from an other DocEntry
236 * @param doc entry to copy from
238 void DocEntry::Copy(DocEntry *doc)
240 Length = doc->Length;
241 ReadLength = doc->ReadLength;
242 ImplicitVR = doc->ImplicitVR;
243 Offset = doc->Offset;
247 * \brief tells us if entry is the last one of a 'no length' SequenceItem
250 bool DocEntry::IsItemDelimitor()
252 return (GetGroup() == 0xfffe && GetElement() == 0xe00d);
256 * \brief tells us if entry is the last one of a 'no length' Sequence
259 bool DocEntry::IsSequenceDelimitor()
261 return (GetGroup() == 0xfffe && GetElement() == 0xe0dd);
264 //-----------------------------------------------------------------------------
267 //-----------------------------------------------------------------------------
270 //-----------------------------------------------------------------------------
271 } // end namespace gdcm