1 /*=========================================================================
4 Module: $RCSfile: gdcmDocument.h,v $
6 Date: $Date: 2004/10/28 03:10:57 $
7 Version: $Revision: 1.56 $
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
22 #include "gdcmCommon.h"
25 #include "gdcmException.h"
26 #include "gdcmDictSet.h"
27 #include "gdcmDocEntry.h"
28 #include "gdcmRLEFramesInfo.h"
29 #include "gdcmJPEGFragmentsInfo.h"
30 #include "gdcmDocEntrySet.h"
31 #include "gdcmElementSet.h"
44 enum TransferSyntaxType {
45 ImplicitVRLittleEndian = 0,
46 ExplicitVRLittleEndian,
47 DeflatedExplicitVRLittleEndian,
50 JPEGExtendedProcess2_4,
51 JPEGExtendedProcess3_5,
52 JPEGSpectralSelectionProcess6_8,
53 JPEGFullProgressionProcess10_12,
54 JPEGLosslessProcess14,
55 JPEGLosslessProcess14_1,
62 //-----------------------------------------------------------------------------
64 * \brief Derived by both Header and DicomDir
66 class GDCM_EXPORT Document : public ElementSet
70 /// Public dictionary used to parse this header
73 /// \brief Optional "shadow dictionary" (private elements) used to parse
77 /// \brief Size threshold above which an element value will NOT be loaded
78 /// in memory (to avoid loading the image/volume itself). By default,
79 /// this upper bound is fixed to 1024 bytes (which might look reasonable
80 /// when one considers the definition of the various VR contents).
81 uint32_t MaxSizeLoadEntry;
83 /// \brief Size threshold above which an element value will NOT be *printed*
84 /// in order no to polute the screen output. By default, this upper bound
85 /// is fixed to 64 bytes.
86 uint32_t MaxSizePrintEntry;
89 /// Refering underlying filename.
92 /// \brief SWap code (e.g. Big Endian, Little Endian, Bad Big Endian,
93 /// Bad Little Endian) according to the processor Endianity and
94 /// what is written on disc.
97 /// File Pointer, opened during Header parsing.
100 /// ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown
103 /// After opening the file, we read HEADER_LENGTH_TO_READ bytes.
104 static const unsigned int HEADER_LENGTH_TO_READ;
106 /// \brief Elements whose value is longer than MAX_SIZE_LOAD_ELEMENT_VALUE
108 static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
110 /// \brief Elements whose value is longer than MAX_SIZE_PRINT_ELEMENT_VALUE
112 /// \todo Currently not used since collides with #define in
113 /// class DocEntry . See also
114 /// method ref Document::SetMaxSizePrintEntry()
115 static const unsigned int MAX_SIZE_PRINT_ELEMENT_VALUE;
117 /// Store the RLE frames info obtained during parsing of pixels.
118 RLEFramesInfo* RLEInfo;
120 /// Store the JPEG fragments info obtained during parsing of pixels.
121 JPEGFragmentsInfo* JPEGInfo;
123 /// \brief Amount of printed details for each Header Entry (Dicom Element):
124 /// 0 : stands for the least detail level.
128 // the 2 following will be merged
129 virtual void PrintPubDict (std::ostream &os = std::cout);
130 virtual void PrintShaDict (std::ostream &os = std::cout);
135 bool SetShaDict(Dict* dict);
136 bool SetShaDict(DictKey const & dictName);
138 // Informations contained in the parser
139 virtual bool IsReadable();
140 TransferSyntaxType GetTransferSyntax();
141 bool IsJPEGLossless();
144 bool IsEncapsulate();
147 FileType GetFileType();
149 std::ifstream * OpenFile();
152 void Write( std::ofstream* fp, FileType type );
154 ValEntry* ReplaceOrCreateByNumber(std::string const & value,
155 uint16_t group, uint16_t elem,
156 std::string const & vr = "unkn");
158 BinEntry* ReplaceOrCreateByNumber(uint8_t* binArea, int lgth,
159 uint16_t group, uint16_t elem,
160 std::string const & vr = "unkn");
162 SeqEntry* ReplaceOrCreateByNumber(uint16_t group, uint16_t elem);
164 bool ReplaceIfExistByNumber ( std::string const & value,
165 uint16_t group, uint16_t elem );
167 virtual void* LoadEntryBinArea(uint16_t group, uint16_t elem);
168 virtual void* LoadEntryBinArea(BinEntry* entry);
170 // System access (meaning endian related !?)
171 uint16_t SwapShort(uint16_t); // needed by File
172 uint32_t SwapLong(uint32_t); // needed by File
173 uint16_t UnswapShort(uint16_t); // needed by File
174 uint32_t UnswapLong(uint32_t); // needed by File
177 // Constructor and destructor are protected to forbid end user
178 // to instanciate from this class Document (only Header and
179 // DicomDir are meaningfull).
181 Document( std::string const & filename );
184 void ReadAndSkipEncapsulatedBasicOffsetTable();
185 void ComputeRLEInfo();
186 void ComputeJPEGFragmentInfo();
188 bool CheckIfEntryExistByNumber(uint16_t group, uint16_t elem );
190 virtual std::string GetEntryByName (TagName const & tagName);
191 virtual std::string GetEntryVRByName (TagName const & tagName);
192 virtual std::string GetEntryByNumber (uint16_t group, uint16_t elem);
193 virtual std::string GetEntryVRByNumber(uint16_t group, uint16_t elem);
194 virtual int GetEntryLengthByNumber(uint16_t group, uint16_t elem);
196 virtual bool SetEntryByName (std::string const & content,
197 std::string const & tagName);
198 virtual bool SetEntryByNumber(std::string const & content,
199 uint16_t group, uint16_t element);
200 virtual bool SetEntryByNumber(uint8_t* content, int lgth,
201 uint16_t group, uint16_t element);
202 virtual bool SetEntryLengthByNumber(uint32_t length,
203 uint16_t group, uint16_t element);
205 virtual size_t GetEntryOffsetByNumber (uint16_t group, uint16_t elem);
206 virtual void* GetEntryBinAreaByNumber(uint16_t group, uint16_t elem);
207 virtual bool SetEntryBinAreaByNumber(uint8_t* a, uint16_t group,
210 virtual void UpdateShaEntries();
213 DocEntry* GetDocEntryByNumber(uint16_t group, uint16_t element);
214 DocEntry* GetDocEntryByName (std::string const & tagName);
216 ValEntry* GetValEntryByNumber(uint16_t group, uint16_t element);
217 //BinEntry* GetBinEntryByNumber(uint16_t group, uint16_t element);
218 RLEFramesInfo* GetRLEInfo() { return RLEInfo; }
219 JPEGFragmentsInfo* GetJPEGInfo() { return JPEGInfo; }
221 void LoadDocEntrySafe(DocEntry* entry);
222 TagDocEntryHT* BuildFlatHashTable();
226 void ParseDES(DocEntrySet *set,long offset, long l_max, bool delim_mode);
227 void ParseSQ (SeqEntry *seq, long offset, long l_max, bool delim_mode);
229 void LoadDocEntry (DocEntry *);
230 void FindDocEntryLength(DocEntry *) throw ( FormatError );
231 void FindDocEntryVR (DocEntry *);
232 bool CheckDocEntryVR (DocEntry *, VRKey);
234 std::string GetDocEntryValue (DocEntry *);
235 std::string GetDocEntryUnvalue(DocEntry *);
237 void SkipDocEntry (DocEntry *);
238 void SkipToNextDocEntry (DocEntry *);
240 void FixDocEntryFoundLength(DocEntry *, uint32_t);
241 bool IsDocEntryAnInteger (DocEntry *);
243 uint32_t FindDocEntryLengthOB() throw( FormatUnexpected );
245 uint16_t ReadInt16() throw ( FormatError );
246 uint32_t ReadInt32() throw ( FormatError );
247 void SkipBytes(uint32_t);
248 bool ReadTag(uint16_t, uint16_t);
249 uint32_t ReadTagLength(uint16_t, uint16_t);
253 void SwitchSwapToBigEndian();
254 void SetMaxSizeLoadEntry(long);
255 void SetMaxSizePrintEntry(long);
257 // DocEntry related utilities
258 DocEntry* ReadNextDocEntry();
260 uint32_t GenerateFreeTagKeyInGroup(uint16_t group);
261 void BuildFlatHashTableRecurse( TagDocEntryHT& builtHT,
266 /// Accessor to \ref PrintLevel
267 void SetPrintLevel(int level) { PrintLevel = level; }
269 /// Accessor to \ref Filename
270 const std::string &GetFileName() const { return Filename; }
272 /// Accessor to \ref Filename
273 void SetFileName(std::string const & fileName) { Filename = fileName; }
275 /// 'Swap code' accessor (see \ref SwapCode )
276 int GetSwapCode() { return SwapCode; }
279 std::ifstream * GetFP() { return Fp; }
281 bool operator<(Document &document);
284 } // end namespace gdcm
286 //-----------------------------------------------------------------------------