1 /*=========================================================================
4 Module: $RCSfile: gdcmDocument.h,v $
6 Date: $Date: 2005/02/06 14:39:35 $
7 Version: $Revision: 1.105 $
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 #ifndef GDCMDOCUMENT_H
20 #define GDCMDOCUMENT_H
24 #include "gdcmElementSet.h"
25 #include "gdcmException.h"
26 //#include "gdcmCommon.h"
39 //-----------------------------------------------------------------------------
41 * \brief Derived by both gdcm::File and gdcm::DicomDir
43 class GDCM_EXPORT Document : public ElementSet
47 typedef std::list<Element> ListElements;
52 bool SetShaDict(Dict *dict);
53 bool SetShaDict(DictKey const &dictName);
55 // Informations contained in the gdcm::Document
56 virtual bool IsReadable();
59 FileType GetFileType();
60 std::string GetTransferSyntax();
61 /// Return the Transfer Syntax as a string
62 std::string GetTransferSyntaxName();
65 /// 'Swap code' accessor (see \ref SwapCode )
66 int GetSwapCode() { return SwapCode; }
67 // System access (meaning endian related !?)
68 uint16_t SwapShort(uint16_t);
69 uint32_t SwapLong(uint32_t);
70 /// \brief Unswaps back the bytes of 2-bytes long integer
71 /// so they agree with the processor order.
72 uint16_t UnswapShort(uint16_t a) { return SwapShort(a);}
73 /// \brief Unswaps back the bytes of 4-byte long integer
74 /// so they agree with the processor order.
75 uint32_t UnswapLong(uint32_t a) { return SwapLong(a);}
78 /// Accessor to \ref Filename
79 const std::string &GetFileName() const { return Filename; }
80 /// Accessor to \ref Filename
81 void SetFileName(std::string const &fileName) { Filename = fileName; }
83 std::ifstream *OpenFile();
85 void WriteContent( std::ofstream *fp, FileType type );
88 virtual void LoadEntryBinArea(uint16_t group, uint16_t elem);
89 virtual void LoadEntryBinArea(BinEntry *entry);
91 void LoadDocEntrySafe(DocEntry *entry);
93 // Ordering of Documents
94 bool operator<(Document &document);
98 // Constructor and destructor are protected to forbid end user
99 // to instanciate from this class Document (only gdcm::File and
100 // gdcm::DicomDir are meaningfull).
102 Document( std::string const &filename );
105 uint16_t ReadInt16() throw ( FormatError );
106 uint32_t ReadInt32() throw ( FormatError );
107 void SkipBytes(uint32_t);
108 int ComputeGroup0002Length( FileType filetype );
111 /// Refering underlying filename.
112 std::string Filename;
114 /// \brief Swap code gives an information on the byte order of a
115 /// supposed to be an int32, as it's read on disc
116 /// (depending on the image Transfer Syntax *and* on the processor endianess)
117 /// as opposed as it should in memory to be dealt as an int32.
119 /// - a 'Little Endian' image, read with a little endian processor
120 /// will have a SwapCode= 1234 (the order is OK; nothing to do)
121 /// - a 'Little Endian' image, read with a big endian procesor
122 /// will have a SwapCode= 4321 (the order is wrong; int32 an int16 must be
124 /// note : values 2143, 4321, 3412 remain for the ACR-NEMA time, and
125 /// the well known 'Bad Big Endian' and 'Bad Little Endian' codes
128 ///\brief whether we already parsed group 0002 (Meta Elements)
129 bool Group0002Parsed;
131 ///\brief whether file has a DCM Preamble
134 /// File Pointer, opened during Document parsing.
137 /// ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown
140 /// After opening the file, we read HEADER_LENGTH_TO_READ bytes.
141 static const unsigned int HEADER_LENGTH_TO_READ;
142 /// \brief Elements whose value is longer than MAX_SIZE_LOAD_ELEMENT_VALUE
144 static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
145 /// \brief Elements whose value is longer than MAX_SIZE_PRINT_ELEMENT_VALUE
147 static const unsigned int MAX_SIZE_PRINT_ELEMENT_VALUE;
149 /// List of element to Anonymize
150 ListElements AnonymizeList;
157 void ParseDES(DocEntrySet *set,long offset, long l_max, bool delim_mode);
158 void ParseSQ (SeqEntry *seq, long offset, long l_max, bool delim_mode);
160 void LoadDocEntry (DocEntry *e);
161 void FindDocEntryLength (DocEntry *e) throw ( FormatError );
162 uint32_t FindDocEntryLengthOBOrOW() throw( FormatUnexpected );
163 std::string FindDocEntryVR();
164 bool CheckDocEntryVR (VRKey k);
166 std::string GetDocEntryValue (DocEntry *entry);
167 std::string GetDocEntryUnvalue(DocEntry *entry);
169 void SkipDocEntry (DocEntry *entry);
170 void SkipToNextDocEntry (DocEntry *entry);
172 void FixDocEntryFoundLength(DocEntry *entry,uint32_t l);
173 bool IsDocEntryAnInteger (DocEntry *entry);
176 void SwitchByteSwapCode();
177 void SetMaxSizeLoadEntry(long);
178 void SetMaxSizePrintEntry(long);
180 // DocEntry related utilities
181 DocEntry *ReadNextDocEntry();
183 void HandleBrokenEndian (uint16_t &group, uint16_t &elem);
184 void HandleOutOfGroup0002(uint16_t &group, uint16_t &elem);
187 /// Public dictionary used to parse this header
189 /// \brief Optional "shadow dictionary" (private elements) used to parse
193 /// \brief Size threshold above which an element value will NOT be loaded
194 /// in memory (to avoid loading the image/volume itself). By default,
195 /// this upper bound is fixed to 1024 bytes (which might look reasonable
196 /// when one considers the definition of the various VR contents).
197 uint32_t MaxSizeLoadEntry;
199 /// \brief Size threshold above which an element value will NOT be *printed*
200 /// in order no to polute the screen output. By default, this upper bound
201 /// is fixed to 64 bytes.
202 uint32_t MaxSizePrintEntry;
205 // uint32_t GenerateFreeTagKeyInGroup(uint16_t group);
206 // void BuildFlatHashTableRecurse( TagDocEntryHT &builtHT,
207 // DocEntrySet *set );
211 } // end namespace gdcm
213 //-----------------------------------------------------------------------------