1 /*=========================================================================
4 Module: $RCSfile: gdcmDocument.h,v $
6 Date: $Date: 2004/11/25 16:35:17 $
7 Version: $Revision: 1.65 $
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 ImplicitVRLittleEndianDLXGE,
47 ExplicitVRLittleEndian,
48 DeflatedExplicitVRLittleEndian,
51 JPEGExtendedProcess2_4,
52 JPEGExtendedProcess3_5,
53 JPEGSpectralSelectionProcess6_8,
54 JPEGFullProgressionProcess10_12,
55 JPEGLosslessProcess14,
56 JPEGLosslessProcess14_1,
63 //-----------------------------------------------------------------------------
65 * \brief Derived by both Header and DicomDir
67 class GDCM_EXPORT Document : public ElementSet
71 /// Public dictionary used to parse this header
74 /// \brief Optional "shadow dictionary" (private elements) used to parse
78 /// \brief Size threshold above which an element value will NOT be loaded
79 /// in memory (to avoid loading the image/volume itself). By default,
80 /// this upper bound is fixed to 1024 bytes (which might look reasonable
81 /// when one considers the definition of the various VR contents).
82 uint32_t MaxSizeLoadEntry;
84 /// \brief Size threshold above which an element value will NOT be *printed*
85 /// in order no to polute the screen output. By default, this upper bound
86 /// is fixed to 64 bytes.
87 uint32_t MaxSizePrintEntry;
90 /// Refering underlying filename.
93 /// \brief SWap code (e.g. Big Endian, Little Endian, Bad Big Endian,
94 /// Bad Little Endian) according to the processor Endianity and
95 /// what is written on disc.
98 /// File Pointer, opened during Header parsing.
101 /// ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown
104 /// After opening the file, we read HEADER_LENGTH_TO_READ bytes.
105 static const unsigned int HEADER_LENGTH_TO_READ;
107 /// \brief Elements whose value is longer than MAX_SIZE_LOAD_ELEMENT_VALUE
109 static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
111 /// \brief Elements whose value is longer than MAX_SIZE_PRINT_ELEMENT_VALUE
113 /// \todo Currently not used since collides with #define in
114 /// class DocEntry . See also
115 /// method ref Document::SetMaxSizePrintEntry()
116 static const unsigned int MAX_SIZE_PRINT_ELEMENT_VALUE;
118 /// Store the RLE frames info obtained during parsing of pixels.
119 RLEFramesInfo* RLEInfo;
121 /// Store the JPEG fragments info obtained during parsing of pixels.
122 JPEGFragmentsInfo* JPEGInfo;
124 /// \brief Amount of printed details for each Header Entry (Dicom Element):
125 /// 0 : stands for the least detail level.
129 // the 2 following will be merged
130 virtual void PrintPubDict (std::ostream &os = std::cout);
131 virtual void PrintShaDict (std::ostream &os = std::cout);
136 bool SetShaDict(Dict* dict);
137 bool SetShaDict(DictKey const & dictName);
139 // Informations contained in the parser
140 virtual bool IsReadable();
141 TransferSyntaxType GetTransferSyntax();
142 bool IsJPEGLossless();
145 bool IsEncapsulate();
148 FileType GetFileType();
150 std::ifstream * OpenFile();
153 void WriteContent( std::ofstream* fp, FileType type );
155 ValEntry* ReplaceOrCreateByNumber(std::string const & value,
156 uint16_t group, uint16_t elem,
157 TagName const & vr = "unkn");
159 BinEntry* ReplaceOrCreateByNumber(uint8_t* binArea, int lgth,
160 uint16_t group, uint16_t elem,
161 TagName const & vr = "unkn");
163 SeqEntry* ReplaceOrCreateByNumber(uint16_t group, uint16_t elem);
165 bool ReplaceIfExistByNumber ( std::string const & value,
166 uint16_t group, uint16_t elem );
168 virtual void LoadEntryBinArea(uint16_t group, uint16_t elem);
169 virtual void LoadEntryBinArea(BinEntry* entry);
171 // System access (meaning endian related !?)
172 uint16_t SwapShort(uint16_t); // needed by File
173 uint32_t SwapLong(uint32_t); // needed by File
174 uint16_t UnswapShort(uint16_t); // needed by File
175 uint32_t UnswapLong(uint32_t); // needed by File
177 static std::string GetTransferSyntaxValue(TransferSyntaxType type);
180 // Constructor and destructor are protected to forbid end user
181 // to instanciate from this class Document (only Header and
182 // DicomDir are meaningfull).
184 Document( std::string const & filename );
187 void ReadAndSkipEncapsulatedBasicOffsetTable();
188 void ComputeRLEInfo();
189 void ComputeJPEGFragmentInfo();
191 bool CheckIfEntryExistByNumber(uint16_t group, uint16_t elem );
193 virtual std::string GetEntryByName (TagName const & tagName);
194 virtual std::string GetEntryVRByName (TagName const & tagName);
195 virtual std::string GetEntryByNumber (uint16_t group, uint16_t elem);
196 virtual std::string GetEntryVRByNumber(uint16_t group, uint16_t elem);
197 virtual int GetEntryLengthByNumber(uint16_t group, uint16_t elem);
199 virtual bool SetEntryByName ( std::string const & content,
200 TagName const & tagName );
201 virtual bool SetEntryByNumber(std::string const & content,
202 uint16_t group, uint16_t element);
203 virtual bool SetEntryByNumber(uint8_t* content, int lgth,
204 uint16_t group, uint16_t element);
205 virtual bool SetEntryLengthByNumber(uint32_t length,
206 uint16_t group, uint16_t element);
208 virtual size_t GetEntryOffsetByNumber(uint16_t group, uint16_t elem);
209 virtual void* GetEntryBinAreaByNumber(uint16_t group, uint16_t elem);
210 virtual bool SetEntryBinAreaByNumber(uint8_t* a, uint16_t group,
213 virtual void UpdateShaEntries();
216 DocEntry* GetDocEntryByNumber(uint16_t group, uint16_t element);
217 DocEntry* GetDocEntryByName (TagName const & tagName);
219 ValEntry* GetValEntryByNumber(uint16_t group, uint16_t element);
220 //BinEntry* GetBinEntryByNumber(uint16_t group, uint16_t element);
221 RLEFramesInfo* GetRLEInfo() { return RLEInfo; }
222 JPEGFragmentsInfo* GetJPEGInfo() { return JPEGInfo; }
224 void LoadDocEntrySafe(DocEntry* entry);
225 TagDocEntryHT* BuildFlatHashTable();
229 void ParseDES(DocEntrySet *set,long offset, long l_max, bool delim_mode);
230 void ParseSQ (SeqEntry *seq, long offset, long l_max, bool delim_mode);
232 void LoadDocEntry (DocEntry *);
233 void FindDocEntryLength(DocEntry *) throw ( FormatError );
234 void FindDocEntryVR (DocEntry *);
235 bool CheckDocEntryVR (DocEntry *, VRKey);
237 std::string GetDocEntryValue (DocEntry *);
238 std::string GetDocEntryUnvalue(DocEntry *);
240 void SkipDocEntry (DocEntry *);
241 void SkipToNextDocEntry (DocEntry *);
243 void FixDocEntryFoundLength(DocEntry *, uint32_t);
244 bool IsDocEntryAnInteger (DocEntry *);
246 uint32_t FindDocEntryLengthOB() throw( FormatUnexpected );
248 uint16_t ReadInt16() throw ( FormatError );
249 uint32_t ReadInt32() throw ( FormatError );
250 void SkipBytes(uint32_t);
251 bool ReadTag(uint16_t, uint16_t);
252 uint32_t ReadTagLength(uint16_t, uint16_t);
256 void SwitchSwapToBigEndian();
257 void SetMaxSizeLoadEntry(long);
258 void SetMaxSizePrintEntry(long);
260 // DocEntry related utilities
261 DocEntry* ReadNextDocEntry();
263 uint32_t GenerateFreeTagKeyInGroup(uint16_t group);
264 void BuildFlatHashTableRecurse( TagDocEntryHT& builtHT,
267 void HandleBrokenEndian(uint16_t group, uint16_t elem);
270 /// Accessor to \ref PrintLevel
271 void SetPrintLevel(int level) { PrintLevel = level; }
273 /// Accessor to \ref Filename
274 const std::string &GetFileName() const { return Filename; }
276 /// Accessor to \ref Filename
277 void SetFileName(std::string const & fileName) { Filename = fileName; }
279 /// 'Swap code' accessor (see \ref SwapCode )
280 int GetSwapCode() { return SwapCode; }
282 bool operator<(Document &document);
285 } // end namespace gdcm
287 //-----------------------------------------------------------------------------