1 /*=========================================================================
4 Module: $RCSfile: gdcmDocument.h,v $
6 Date: $Date: 2004/11/26 10:55:04 $
7 Version: $Revision: 1.66 $
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);
206 // Verify the usefull of this method... otherwise remove it
207 // It's body is commented in the .xx
208 //virtual bool SetEntryLengthByNumber(uint32_t length,
209 // uint16_t group, uint16_t element);
212 // Verify the usefull of this method... otherwise remove it
213 // It's body is commented in the .xx
214 // virtual size_t GetEntryOffsetByNumber(uint16_t group, uint16_t elem);
215 virtual void* GetEntryBinAreaByNumber(uint16_t group, uint16_t elem);
217 // Verify the usefull of this method... otherwise remove it
218 // It's body is commented in the .xx
219 //virtual bool SetEntryBinAreaByNumber(uint8_t* a, uint16_t group,
222 virtual void UpdateShaEntries();
225 DocEntry* GetDocEntryByNumber(uint16_t group, uint16_t element);
226 DocEntry* GetDocEntryByName (TagName const & tagName);
228 ValEntry* GetValEntryByNumber(uint16_t group, uint16_t element);
229 //BinEntry* GetBinEntryByNumber(uint16_t group, uint16_t element);
230 RLEFramesInfo* GetRLEInfo() { return RLEInfo; }
231 JPEGFragmentsInfo* GetJPEGInfo() { return JPEGInfo; }
233 void LoadDocEntrySafe(DocEntry* entry);
234 TagDocEntryHT* BuildFlatHashTable();
238 void ParseDES(DocEntrySet *set,long offset, long l_max, bool delim_mode);
239 void ParseSQ (SeqEntry *seq, long offset, long l_max, bool delim_mode);
241 void LoadDocEntry (DocEntry *);
242 void FindDocEntryLength(DocEntry *) throw ( FormatError );
243 void FindDocEntryVR (DocEntry *);
244 bool CheckDocEntryVR (DocEntry *, VRKey);
246 std::string GetDocEntryValue (DocEntry *);
247 std::string GetDocEntryUnvalue(DocEntry *);
249 void SkipDocEntry (DocEntry *);
250 void SkipToNextDocEntry (DocEntry *);
252 void FixDocEntryFoundLength(DocEntry *, uint32_t);
253 bool IsDocEntryAnInteger (DocEntry *);
255 uint32_t FindDocEntryLengthOB() throw( FormatUnexpected );
257 uint16_t ReadInt16() throw ( FormatError );
258 uint32_t ReadInt32() throw ( FormatError );
259 void SkipBytes(uint32_t);
260 bool ReadTag(uint16_t, uint16_t);
261 uint32_t ReadTagLength(uint16_t, uint16_t);
265 void SwitchSwapToBigEndian();
266 void SetMaxSizeLoadEntry(long);
267 void SetMaxSizePrintEntry(long);
269 // DocEntry related utilities
270 DocEntry* ReadNextDocEntry();
272 uint32_t GenerateFreeTagKeyInGroup(uint16_t group);
273 void BuildFlatHashTableRecurse( TagDocEntryHT& builtHT,
276 void HandleBrokenEndian(uint16_t group, uint16_t elem);
279 /// Accessor to \ref PrintLevel
280 void SetPrintLevel(int level) { PrintLevel = level; }
282 /// Accessor to \ref Filename
283 const std::string &GetFileName() const { return Filename; }
285 /// Accessor to \ref Filename
286 void SetFileName(std::string const & fileName) { Filename = fileName; }
288 /// 'Swap code' accessor (see \ref SwapCode )
289 int GetSwapCode() { return SwapCode; }
291 bool operator<(Document &document);
294 } // end namespace gdcm
296 //-----------------------------------------------------------------------------