1 /*=========================================================================
4 Module: $RCSfile: gdcmDocument.h,v $
6 Date: $Date: 2004/09/14 16:47:08 $
7 Version: $Revision: 1.36 $
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.htm 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"
33 #include "gdcmDocEntrySet.h"
34 #include "gdcmElementSet.h"
39 //-----------------------------------------------------------------------------
41 * \brief Derived by both gdcmHeader and gdcmDicomDir
43 class GDCM_EXPORT gdcmDocument : public gdcmElementSet
45 friend class gdcmFile;
47 /// Public dictionary used to parse this header
50 /// \brief Optional "shadow dictionary" (private elements) used to parse
54 /// \brief Size threshold above which an element value will NOT be loaded
55 /// in memory (to avoid loading the image/volume itself). By default,
56 /// this upper bound is fixed to 1024 bytes (which might look reasonable
57 /// when one considers the definition of the various VR contents).
58 uint32_t MaxSizeLoadEntry;
60 /// \brief Size threshold above which an element value will NOT be *printed*
61 /// in order no to polute the screen output. By default, this upper bound
62 /// is fixed to 64 bytes.
63 uint32_t MaxSizePrintEntry;
66 /// Refering underlying filename.
69 /// \brief SWap code (e.g. Big Endian, Little Endian, Bad Big Endian,
70 /// Bad Little Endian) according to the processor Endianity and
71 /// what is written on disc.
74 /// File Pointer, opened during Header parsing.
77 /// ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown
80 /// After opening the file, we read HEADER_LENGTH_TO_READ bytes.
81 static const unsigned int HEADER_LENGTH_TO_READ;
83 /// \brief Elements whose value is longer than MAX_SIZE_LOAD_ELEMENT_VALUE
85 static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
87 /// \brief Elements whose value is longer than MAX_SIZE_PRINT_ELEMENT_VALUE
89 /// \todo Currently not used since collides with #define in
90 /// \ref gdcmDocEntry.cxx. See also
91 /// \ref gdcmDocument::SetMaxSizePrintEntry()
92 static const unsigned int MAX_SIZE_PRINT_ELEMENT_VALUE;
94 /// Will be set 1 if user asks to 'go inside' the 'sequences' (VR = "SQ")
97 /// \brief Amount of printed details for each Header Entry (Dicom Element):
98 /// 0 : stands for the least detail level.
102 // the 2 following will be merged
103 virtual void PrintPubDict (std::ostream &os = std::cout);
104 virtual void PrintShaDict (std::ostream &os = std::cout);
107 gdcmDict *GetPubDict();
108 gdcmDict *GetShaDict();
109 bool SetShaDict(gdcmDict *dict);
110 bool SetShaDict(DictKey const & dictName);
112 // Informations contained in the parser
113 virtual bool IsReadable();
114 bool IsGivenTransferSyntax(std::string const & syntaxToCheck);
115 bool IsImplicitVRLittleEndianTransferSyntax();
116 bool IsExplicitVRLittleEndianTransferSyntax();
117 bool IsDeflatedExplicitVRLittleEndianTransferSyntax();
118 bool IsExplicitVRBigEndianTransferSyntax();
119 bool IsJPEGBaseLineProcess1TransferSyntax();
120 bool IsJPEGExtendedProcess2_4TransferSyntax();
121 bool IsJPEGExtendedProcess3_5TransferSyntax();
122 bool IsJPEGSpectralSelectionProcess6_8TransferSyntax();
123 bool IsRLELossLessTransferSyntax();
124 bool IsJPEGLossless();
128 FileType GetFileType();
133 void Write(FILE* fp, FileType type);
135 gdcmValEntry* ReplaceOrCreateByNumber(std::string const & value,
136 uint16_t group, uint16_t elem);
138 gdcmValEntry* ReplaceOrCreateByNumber(std::string const & value,
139 uint16_t group, uint16_t elem,
140 std::string const & VR);
142 gdcmBinEntry* ReplaceOrCreateByNumber(void *voidArea, int lgth,
143 uint16_t group, uint16_t elem);
145 gdcmSeqEntry* ReplaceOrCreateByNumber(uint16_t group, uint16_t elem);
147 bool ReplaceIfExistByNumber ( std::string const & value,
151 virtual void* LoadEntryVoidArea(uint16_t group, uint16_t elem);
152 virtual void* LoadEntryVoidArea(gdcmBinEntry* entry);
154 // System access (meaning endian related !?)
155 uint16_t SwapShort(uint16_t); // needed by gdcmFile
156 uint32_t SwapLong(uint32_t); // needed by gdcmFile
157 uint16_t UnswapShort(uint16_t); // needed by gdcmFile
158 uint32_t UnswapLong(uint32_t); // needed by gdcmFile
161 // Constructor and destructor are protected to forbid end user
162 // to instanciate from this class gdcmDocument (only gdcmHeader and
163 // gdcmDicomDir are meaningfull).
165 gdcmDocument( std::string const & filename );
166 virtual ~gdcmDocument();
170 bool CheckIfEntryExistByNumber(uint16_t group, uint16_t elem );
172 virtual std::string GetEntryByName (TagName const & tagName);
173 virtual std::string GetEntryVRByName (TagName const & tagName);
174 virtual std::string GetEntryByNumber (uint16_t group, uint16_t elem);
175 virtual std::string GetEntryVRByNumber(uint16_t group, uint16_t elem);
176 virtual int GetEntryLengthByNumber(uint16_t group, uint16_t elem);
178 virtual bool SetEntryByName (std::string const & content,
179 std::string const & tagName);
180 virtual bool SetEntryByNumber(std::string const & content,
181 uint16_t group, uint16_t element);
182 virtual bool SetEntryByNumber(void *content, int lgth,
183 uint16_t group, uint16_t element);
184 virtual bool SetEntryLengthByNumber(uint32_t length,
185 uint16_t group, uint16_t element);
187 virtual size_t GetEntryOffsetByNumber(uint16_t group, uint16_t elem);
188 virtual void* GetEntryVoidAreaByNumber(uint16_t group, uint16_t elem);
189 virtual bool SetEntryVoidAreaByNumber(void* a, uint16_t group,
192 virtual void UpdateShaEntries();
195 gdcmDocEntry* GetDocEntryByNumber(uint16_t group, uint16_t element);
196 gdcmDocEntry* GetDocEntryByName (std::string const & tagName);
198 gdcmValEntry* GetValEntryByNumber(uint16_t group, uint16_t element);
199 gdcmBinEntry* GetBinEntryByNumber(uint16_t group, uint16_t element);
201 void LoadDocEntrySafe(gdcmDocEntry* entry);
205 long ParseDES(gdcmDocEntrySet *set,long offset, long l_max, bool delim_mode);
206 long ParseSQ (gdcmSeqEntry *seq, long offset, long l_max, bool delim_mode);
208 void LoadDocEntry (gdcmDocEntry *);
209 void FindDocEntryLength(gdcmDocEntry *) throw ( gdcmFormatError );
210 void FindDocEntryVR (gdcmDocEntry *);
211 bool CheckDocEntryVR (gdcmDocEntry *, gdcmVRKey);
213 std::string GetDocEntryValue (gdcmDocEntry *);
214 std::string GetDocEntryUnvalue(gdcmDocEntry *);
216 void SkipDocEntry (gdcmDocEntry *);
217 void SkipToNextDocEntry (gdcmDocEntry *);
219 void FixDocEntryFoundLength(gdcmDocEntry *, uint32_t);
220 bool IsDocEntryAnInteger (gdcmDocEntry *);
222 uint32_t FindDocEntryLengthOB() throw( gdcmFormatUnexpected );
224 uint16_t ReadInt16() throw ( gdcmFormatError );
225 uint32_t ReadInt32() throw ( gdcmFormatError );
226 void SkipBytes(uint32_t);
227 bool ReadTag(uint16_t, uint16_t);
228 uint32_t ReadTagLength(uint16_t, uint16_t);
232 void SwitchSwapToBigEndian();
233 void SetMaxSizeLoadEntry(long);
234 void SetMaxSizePrintEntry(long);
236 // DocEntry related utilities
237 gdcmDocEntry* ReadNextDocEntry();
239 uint32_t GenerateFreeTagKeyInGroup(uint16_t group);
243 /// Accessor to \ref PrintLevel
244 void SetPrintLevel(int level) { PrintLevel = level; }
246 /// Accessor to \ref Filename
247 const std::string &GetFileName() { return Filename; }
249 /// Accessor to \ref Filename
250 void SetFileName(std::string const & fileName) { Filename = fileName; }
252 /// 'Swap code' accessor (see \ref SwapCode )
253 int GetSwapCode() { return SwapCode; }
256 FILE * GetFP() { return Fp; }
258 bool operator<(gdcmDocument &document);
262 //-----------------------------------------------------------------------------