1 /*=========================================================================
4 Module: $RCSfile: gdcmDocument.h,v $
6 Date: $Date: 2004/07/19 03:34:11 $
7 Version: $Revision: 1.23 $
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 Equals =1 if user wants to skip shadow groups while parsing
58 /// \brief Size threshold above which an element value will NOT be loaded
59 /// in memory (to avoid loading the image/volume itself). By default,
60 /// this upper bound is fixed to 1024 bytes (which might look reasonable
61 /// when one considers the definition of the various VR contents).
62 uint32_t MaxSizeLoadEntry;
64 /// \brief Size threshold above which an element value will NOT be *printed*
65 /// in order no to polute the screen output. By default, this upper bound
66 /// is fixed to 64 bytes.
67 uint32_t MaxSizePrintEntry;
70 /// Refering underlying filename.
73 /// \brief SWap code (e.g. Big Endian, Little Endian, Bad Big Endian,
74 /// Bad Little Endian) according to the processor Endianity and
75 /// what is written on disc.
78 /// File Pointer, opened during Header parsing.
81 /// ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown
84 /// After opening the file, we read HEADER_LENGTH_TO_READ bytes.
85 static const unsigned int HEADER_LENGTH_TO_READ;
87 /// \brief Elements whose value is longer than MAX_SIZE_LOAD_ELEMENT_VALUE
89 static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
91 /// \brief Elements whose value is longer than MAX_SIZE_PRINT_ELEMENT_VALUE
93 /// \todo Currently not used since collides with #define in
94 /// \ref gdcmDocEntry.cxx. See also
95 /// \ref gdcmDocument::SetMaxSizePrintEntry()
96 static const unsigned int MAX_SIZE_PRINT_ELEMENT_VALUE;
98 /// Will be set 1 if user asks to 'go inside' the 'sequences' (VR = "SQ")
101 /// \brief Amount of printed details for each Header Entry (Dicom Element):
102 /// 0 : stands for the least detail level.
106 // the 2 following will be merged
107 virtual void PrintPubDict (std::ostream &os = std::cout);
108 virtual void PrintShaDict (std::ostream &os = std::cout);
111 gdcmDict *GetPubDict();
112 gdcmDict *GetShaDict();
113 bool SetShaDict(gdcmDict *dict);
114 bool SetShaDict(DictKey dictName);
116 // Informations contained in the parser
117 virtual bool IsReadable();
118 bool IsGivenTransferSyntax(std::string const & SyntaxToCheck);
119 bool IsImplicitVRLittleEndianTransferSyntax();
120 bool IsExplicitVRLittleEndianTransferSyntax();
121 bool IsDeflatedExplicitVRLittleEndianTransferSyntax();
122 bool IsExplicitVRBigEndianTransferSyntax();
123 bool IsJPEGBaseLineProcess1TransferSyntax();
124 bool IsJPEGExtendedProcess2_4TransferSyntax();
125 bool IsJPEGExtendedProcess3_5TransferSyntax();
126 bool IsJPEGSpectralSelectionProcess6_8TransferSyntax();
127 bool IsRLELossLessTransferSyntax();
128 bool IsJPEGLossless();
132 FileType GetFileType();
134 FILE* OpenFile(bool exception_on_error = false) throw(gdcmFileError);
137 void Write(FILE* fp, FileType type);
139 gdcmValEntry* ReplaceOrCreateByNumber(std::string value,
140 uint16_t group, uint16_t elem);
142 gdcmBinEntry* ReplaceOrCreateByNumber(void *voidArea, int lgth,
143 uint16_t group, uint16_t elem);
144 bool ReplaceIfExistByNumber (const char* value, uint16_t group, uint16_t elem);
146 virtual void* LoadEntryVoidArea(uint16_t group, uint16_t elem);
147 virtual void* LoadEntryVoidArea(gdcmBinEntry* entry);
150 uint16_t SwapShort(uint16_t); // needed by gdcmFile
151 uint32_t SwapLong(uint32_t); // needed by gdcmFile
152 uint16_t UnswapShort(uint16_t); // needed by gdcmFile
153 uint32_t UnswapLong(uint32_t); // needed by gdcmFile
156 // Constructor and destructor are protected to forbid end user
157 // to instanciate from this class gdcmDocument (only gdcmHeader and
158 // gdcmDicomDir are meaningfull).
159 gdcmDocument(bool exception_on_error = false);
160 gdcmDocument(std::string const & filename,
161 bool exception_on_error = false,
162 bool enable_sequences = false,
163 bool ignore_shadow = false);
164 virtual ~gdcmDocument();
166 void gdcmDocument::Parse7FE0 ();
168 int CheckIfEntryExistByNumber(uint16_t group, uint16_t elem ); // int !
170 virtual std::string GetEntryByName (TagName tagName);
171 virtual std::string GetEntryVRByName (TagName tagName);
172 virtual std::string GetEntryByNumber (uint16_t group, uint16_t elem);
173 virtual std::string GetEntryVRByNumber(uint16_t group, uint16_t elem);
174 virtual int GetEntryLengthByNumber(uint16_t group, uint16_t elem);
176 virtual bool SetEntryByName (std::string content, std::string tagName);
177 virtual bool SetEntryByNumber(std::string content,
178 uint16_t group, uint16_t element);
179 virtual bool SetEntryByNumber(void *content, int lgth,
180 uint16_t group, uint16_t element);
181 virtual bool SetEntryLengthByNumber(uint32_t length,
182 uint16_t group, uint16_t element);
184 virtual size_t GetEntryOffsetByNumber(uint16_t group, uint16_t elem);
185 virtual void* GetEntryVoidAreaByNumber(uint16_t group, uint16_t elem);
186 virtual bool SetEntryVoidAreaByNumber(void* a, uint16_t group,
189 virtual void UpdateShaEntries();
192 gdcmDocEntry* GetDocEntryByNumber(uint16_t group, uint16_t element);
193 gdcmDocEntry* GetDocEntryByName (std::string const & tagName);
195 gdcmValEntry* GetValEntryByNumber(uint16_t group, uint16_t element);
196 gdcmBinEntry* GetBinEntryByNumber(uint16_t group, uint16_t element);
198 void LoadDocEntrySafe(gdcmDocEntry* entry);
202 long ParseDES(gdcmDocEntrySet *set, long offset, long l_max,bool delim_mode);
203 long ParseSQ(gdcmSeqEntry *seq, long offset, long l_max, bool delim_mode);
205 void LoadDocEntry (gdcmDocEntry *);
206 void FindDocEntryLength(gdcmDocEntry *);
207 void FindDocEntryVR (gdcmDocEntry *);
208 bool CheckDocEntryVR (gdcmDocEntry *, gdcmVRKey);
210 std::string GetDocEntryValue (gdcmDocEntry *);
211 std::string GetDocEntryUnvalue(gdcmDocEntry *);
213 void SkipDocEntry (gdcmDocEntry *);
214 void SkipToNextDocEntry (gdcmDocEntry *);
216 void FixDocEntryFoundLength(gdcmDocEntry *, uint32_t);
217 bool IsDocEntryAnInteger (gdcmDocEntry *);
219 uint32_t FindDocEntryLengthOB();
221 uint16_t ReadInt16();
222 uint32_t ReadInt32();
223 void SkipBytes(uint32_t);
224 bool ReadTag(uint16_t, uint16_t);
225 uint32_t ReadTagLength(uint16_t, uint16_t);
229 void SwitchSwapToBigEndian();
230 void SetMaxSizeLoadEntry(long);
231 void SetMaxSizePrintEntry(long);
233 // DocEntry related utilities
234 gdcmDocEntry* ReadNextDocEntry();
236 uint32_t GenerateFreeTagKeyInGroup(uint16_t group);
240 /// Accessor to \ref printLevel
241 void SetPrintLevel(int level) { PrintLevel = level; }
243 /// Accessor to \ref Filename
244 const std::string &GetFileName() { return Filename; }
246 /// Accessor to \ref Filename
247 void SetFileName(std::string const & fileName) { Filename = fileName; }
249 /// 'Swap code' accessor (see \ref sw )
250 int GetSwapCode() { return SwapCode; }
253 FILE * GetFP() { return Fp; }
255 bool operator<(gdcmDocument &document);
259 //-----------------------------------------------------------------------------