1 /*=========================================================================
4 Module: $RCSfile: gdcmDocument.h,v $
6 Date: $Date: 2004/10/13 14:15:29 $
7 Version: $Revision: 1.51 $
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"
42 //-----------------------------------------------------------------------------
44 * \brief Derived by both Header and DicomDir
46 class GDCM_EXPORT Document : public ElementSet
50 /// Public dictionary used to parse this header
53 /// \brief Optional "shadow dictionary" (private elements) used to parse
57 /// \brief Size threshold above which an element value will NOT be loaded
58 /// in memory (to avoid loading the image/volume itself). By default,
59 /// this upper bound is fixed to 1024 bytes (which might look reasonable
60 /// when one considers the definition of the various VR contents).
61 uint32_t MaxSizeLoadEntry;
63 /// \brief Size threshold above which an element value will NOT be *printed*
64 /// in order no to polute the screen output. By default, this upper bound
65 /// is fixed to 64 bytes.
66 uint32_t MaxSizePrintEntry;
69 /// Refering underlying filename.
72 /// \brief SWap code (e.g. Big Endian, Little Endian, Bad Big Endian,
73 /// Bad Little Endian) according to the processor Endianity and
74 /// what is written on disc.
77 /// File Pointer, opened during Header parsing.
80 /// ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown
83 /// After opening the file, we read HEADER_LENGTH_TO_READ bytes.
84 static const unsigned int HEADER_LENGTH_TO_READ;
86 /// \brief Elements whose value is longer than MAX_SIZE_LOAD_ELEMENT_VALUE
88 static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
90 /// \brief Elements whose value is longer than MAX_SIZE_PRINT_ELEMENT_VALUE
92 /// \todo Currently not used since collides with #define in
93 /// class DocEntry . See also
94 /// method ref Document::SetMaxSizePrintEntry()
95 static const unsigned int MAX_SIZE_PRINT_ELEMENT_VALUE;
97 /// Store the RLE frames info obtained during parsing of pixels.
98 RLEFramesInfo RLEInfo;
100 /// Store the JPEG fragments info obtained during parsing of pixels.
101 JPEGFragmentsInfo JPEGInfo;
103 /// \brief Amount of printed details for each Header Entry (Dicom Element):
104 /// 0 : stands for the least detail level.
108 // the 2 following will be merged
109 virtual void PrintPubDict (std::ostream &os = std::cout);
110 virtual void PrintShaDict (std::ostream &os = std::cout);
115 bool SetShaDict(Dict *dict);
116 bool SetShaDict(DictKey const & dictName);
118 // Informations contained in the parser
119 virtual bool IsReadable();
120 bool IsGivenTransferSyntax(std::string const & syntaxToCheck);
121 bool IsImplicitVRLittleEndianTransferSyntax();
122 bool IsExplicitVRLittleEndianTransferSyntax();
123 bool IsDeflatedExplicitVRLittleEndianTransferSyntax();
124 bool IsExplicitVRBigEndianTransferSyntax();
125 bool IsRLELossLessTransferSyntax();
126 bool IsJPEGBaseLineProcess1TransferSyntax();
127 bool IsJPEGExtendedProcess2_4TransferSyntax();
128 bool IsJPEGExtendedProcess3_5TransferSyntax();
129 bool IsJPEGSpectralSelectionProcess6_8TransferSyntax();
130 bool IsJPEGLossless();
132 bool IsJPEGTransferSyntax();
133 bool IsEncapsulateTransferSyntax();
136 FileType GetFileType();
141 void Write(FILE* fp, FileType type);
143 ValEntry* ReplaceOrCreateByNumber(std::string const & value,
144 uint16_t group, uint16_t elem,
145 std::string const & VR ="unkn");
147 BinEntry* ReplaceOrCreateByNumber(uint8_t* binArea, int lgth,
148 uint16_t group, uint16_t elem,
149 std::string const & VR="unkn");
151 SeqEntry* ReplaceOrCreateByNumber(uint16_t group, uint16_t elem);
153 bool ReplaceIfExistByNumber ( std::string const & value,
157 virtual void* LoadEntryBinArea(uint16_t group, uint16_t elem);
158 virtual void* LoadEntryBinArea(BinEntry* entry);
160 // System access (meaning endian related !?)
161 uint16_t SwapShort(uint16_t); // needed by File
162 uint32_t SwapLong(uint32_t); // needed by File
163 uint16_t UnswapShort(uint16_t); // needed by File
164 uint32_t UnswapLong(uint32_t); // needed by File
167 // Constructor and destructor are protected to forbid end user
168 // to instanciate from this class Document (only Header and
169 // DicomDir are meaningfull).
171 Document( std::string const & filename );
174 void ReadAndSkipEncapsulatedBasicOffsetTable();
175 void ComputeRLEInfo();
176 void ComputeJPEGFragmentInfo();
178 bool CheckIfEntryExistByNumber(uint16_t group, uint16_t elem );
180 virtual std::string GetEntryByName (TagName const & tagName);
181 virtual std::string GetEntryVRByName (TagName const & tagName);
182 virtual std::string GetEntryByNumber (uint16_t group, uint16_t elem);
183 virtual std::string GetEntryVRByNumber(uint16_t group, uint16_t elem);
184 virtual int GetEntryLengthByNumber(uint16_t group, uint16_t elem);
186 virtual bool SetEntryByName (std::string const & content,
187 std::string const & tagName);
188 virtual bool SetEntryByNumber(std::string const & content,
189 uint16_t group, uint16_t element);
190 virtual bool SetEntryByNumber(uint8_t* content, int lgth,
191 uint16_t group, uint16_t element);
192 virtual bool SetEntryLengthByNumber(uint32_t length,
193 uint16_t group, uint16_t element);
195 virtual size_t GetEntryOffsetByNumber (uint16_t group, uint16_t elem);
196 virtual void* GetEntryBinAreaByNumber(uint16_t group, uint16_t elem);
197 virtual bool SetEntryBinAreaByNumber(uint8_t* a, uint16_t group,
200 virtual void UpdateShaEntries();
203 DocEntry* GetDocEntryByNumber(uint16_t group, uint16_t element);
204 DocEntry* GetDocEntryByName (std::string const & tagName);
206 ValEntry* GetValEntryByNumber(uint16_t group, uint16_t element);
207 //BinEntry* GetBinEntryByNumber(uint16_t group, uint16_t element);
209 void LoadDocEntrySafe(DocEntry* entry);
210 TagDocEntryHT* BuildFlatHashTable();
214 void ParseDES(DocEntrySet *set,long offset, long l_max, bool delim_mode);
215 void ParseSQ (SeqEntry *seq, long offset, long l_max, bool delim_mode);
217 void LoadDocEntry (DocEntry *);
218 void FindDocEntryLength(DocEntry *) throw ( FormatError );
219 void FindDocEntryVR (DocEntry *);
220 bool CheckDocEntryVR (DocEntry *, VRKey);
222 std::string GetDocEntryValue (DocEntry *);
223 std::string GetDocEntryUnvalue(DocEntry *);
225 void SkipDocEntry (DocEntry *);
226 void SkipToNextDocEntry (DocEntry *);
228 void FixDocEntryFoundLength(DocEntry *, uint32_t);
229 bool IsDocEntryAnInteger (DocEntry *);
231 uint32_t FindDocEntryLengthOB() throw( FormatUnexpected );
233 uint16_t ReadInt16() throw ( FormatError );
234 uint32_t ReadInt32() throw ( FormatError );
235 void SkipBytes(uint32_t);
236 bool ReadTag(uint16_t, uint16_t);
237 uint32_t ReadTagLength(uint16_t, uint16_t);
241 void SwitchSwapToBigEndian();
242 void SetMaxSizeLoadEntry(long);
243 void SetMaxSizePrintEntry(long);
245 // DocEntry related utilities
246 DocEntry* ReadNextDocEntry();
248 uint32_t GenerateFreeTagKeyInGroup(uint16_t group);
249 void BuildFlatHashTableRecurse( TagDocEntryHT& builtHT,
255 /// Accessor to \ref PrintLevel
256 void SetPrintLevel(int level) { PrintLevel = level; }
258 /// Accessor to \ref Filename
259 const std::string &GetFileName() { return Filename; }
261 /// Accessor to \ref Filename
262 void SetFileName(std::string const & fileName) { Filename = fileName; }
264 /// 'Swap code' accessor (see \ref SwapCode )
265 int GetSwapCode() { return SwapCode; }
268 FILE * GetFP() { return Fp; }
270 bool operator<(Document &document);
273 } // end namespace gdcm
275 //-----------------------------------------------------------------------------