1 /*=========================================================================
4 Module: $RCSfile: gdcmDocument.h,v $
6 Date: $Date: 2004/06/22 14:57:11 $
7 Version: $Revision: 1.14 $
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 //-----------------------------------------------------------------------------
40 typedef std::string VRKey;
41 typedef std::string VRAtr;
42 typedef std::map<VRKey, VRAtr> VRHT; // Value Representation Hash Table
44 //-----------------------------------------------------------------------------
46 * \brief Derived by both gdcmHeader and gdcmDicomDir
48 class GDCM_EXPORT gdcmDocument : public gdcmElementSet
50 friend class gdcmFile;
52 /// Public dictionary used to parse this header
55 /// \brief Optional "shadow dictionary" (private elements) used to parse
59 /// \brief Equals =1 if user wants to skip shadow groups while parsing
63 /// \brief Size threshold above which an element value will NOT be loaded
64 /// in memory (to avoid loading the image/volume itself). By default,
65 /// this upper bound is fixed to 1024 bytes (which might look reasonable
66 /// when one considers the definition of the various VR contents).
67 guint32 MaxSizeLoadEntry;
69 /// \brief Size threshold above which an element value will NOT be *printed*
70 /// in order no to polute the screen output. By default, this upper bound
71 /// is fixed to 64 bytes.
72 guint32 MaxSizePrintEntry;
75 /// Refering underlying filename.
78 /// \brief SWap code (e.g. Big Endian, Little Endian, Bad Big Endian,
79 /// Bad Little Endian) according to the processor Endianity and
80 /// what is written on disc.
83 /// File Pointer, opened during Header parsing.
86 /// ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown
89 /// After opening the file, we read HEADER_LENGTH_TO_READ bytes.
90 static const unsigned int HEADER_LENGTH_TO_READ;
92 /// \brief Elements whose value is longer than MAX_SIZE_LOAD_ELEMENT_VALUE
94 static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
96 /// \brief Elements whose value is longer than MAX_SIZE_PRINT_ELEMENT_VALUE
98 /// \todo Currently not used since collides with #define in
99 /// \ref gdcmDocEntry.cxx. See also
100 /// \ref gdcmDocument::SetMaxSizePrintEntry()
101 static const unsigned int MAX_SIZE_PRINT_ELEMENT_VALUE;
103 /// Will be set 1 if user asks to 'go inside' the 'sequences' (VR = "SQ")
106 /// \brief Amount of printed details for each Header Entry (Dicom Element):
107 /// 0 : stands for the least detail level.
111 // the 2 following will be merged
112 virtual void PrintPubDict (std::ostream &os = std::cout);
113 virtual void PrintShaDict (std::ostream &os = std::cout);
116 gdcmDict *GetPubDict(void);
117 gdcmDict *GetShaDict(void);
118 bool SetShaDict(gdcmDict *dict);
119 bool SetShaDict(DictKey dictName);
121 // Informations contained in the parser
122 virtual bool IsReadable(void);
123 bool IsGivenTransferSyntax(const std::string & SyntaxToCheck);
124 bool IsImplicitVRLittleEndianTransferSyntax(void);
125 bool IsExplicitVRLittleEndianTransferSyntax(void);
126 bool IsDeflatedExplicitVRLittleEndianTransferSyntax(void);
127 bool IsExplicitVRBigEndianTransferSyntax(void);
128 bool IsJPEGBaseLineProcess1TransferSyntax(void);
129 bool IsJPEGExtendedProcess2_4TransferSyntax(void);
130 bool IsJPEGExtendedProcess3_5TransferSyntax(void);
131 bool IsJPEGSpectralSelectionProcess6_8TransferSyntax(void);
132 bool IsRLELossLessTransferSyntax(void);
133 bool IsJPEGLossless(void);
134 bool IsJPEG2000(void);
135 bool IsDicomV3(void);
137 FileType GetFileType(void);
139 // Read (used in gdcmFile, gdcmDicomDir)
140 FILE *OpenFile(bool exception_on_error = false) throw(gdcmFileError);
141 bool CloseFile(void);
143 // Write (used in gdcmFile, gdcmDicomDir)
145 virtual bool WriteF(FileType type); // New stuff, with recursive exploration
147 gdcmValEntry * ReplaceOrCreateByNumber(std::string Value,
148 guint16 Group, guint16 Elem);
150 gdcmBinEntry * ReplaceOrCreateByNumber(void *voidArea, int lgth,
151 guint16 Group, guint16 Elem);
152 bool ReplaceIfExistByNumber (char *Value, guint16 Group, guint16 Elem);
154 virtual void *LoadEntryVoidArea (guint16 Group, guint16 Element);
157 guint16 SwapShort(guint16); // needed by gdcmFile
158 guint32 SwapLong(guint32); // needed by gdcmFile
159 guint16 UnswapShort(guint16); // needed by gdcmFile
160 guint32 UnswapLong(guint32); // needed by gdcmFile
163 // Constructor and destructor are protected to forbid end user
164 // to instanciate from this class gdcmDocument (only gdcmHeader and
165 // gdcmDicomDir are meaningfull).
166 gdcmDocument(bool exception_on_error = false);
167 gdcmDocument(std::string const & inFilename,
168 bool exception_on_error = false,
169 bool enable_sequences = false,
170 bool ignore_shadow = false);
171 virtual ~gdcmDocument(void);
173 void gdcmDocument::Parse7FE0 (void);
175 int CheckIfEntryExistByNumber(guint16 Group, guint16 Elem ); // int !
177 virtual std::string GetEntryByName (TagName tagName);
178 virtual std::string GetEntryVRByName (TagName tagName);
179 virtual std::string GetEntryByNumber (guint16 group, guint16 element);
180 virtual std::string GetEntryVRByNumber(guint16 group, guint16 element);
181 virtual int GetEntryLengthByNumber(guint16 group, guint16 element);
183 virtual bool SetEntryByName (std::string content, std::string tagName);
184 virtual bool SetEntryByNumber(std::string content,
185 guint16 group, guint16 element);
186 virtual bool SetEntryByNumber(void *content, int lgth,
187 guint16 group, guint16 element);
188 virtual bool SetEntryLengthByNumber(guint32 length,
189 guint16 group, guint16 element);
191 virtual size_t GetEntryOffsetByNumber (guint16 Group, guint16 Elem);
192 virtual void *GetEntryVoidAreaByNumber(guint16 Group, guint16 Elem);
193 virtual bool SetEntryVoidAreaByNumber(void *a, guint16 Group, guint16 Elem);
195 virtual void UpdateShaEntries();
198 gdcmDocEntry *GetDocEntryByNumber (guint16 group, guint16 element);
199 gdcmDocEntry *GetDocEntryByName (std::string Name);
201 gdcmValEntry *GetValEntryByNumber (guint16 group, guint16 element);
202 gdcmBinEntry *GetBinEntryByNumber (guint16 group, guint16 element);
204 void LoadDocEntrySafe(gdcmDocEntry *);
208 long ParseDES(gdcmDocEntrySet *set, long offset, long l_max,bool delim_mode);
209 long ParseSQ(gdcmSeqEntry *seq, long offset, long l_max, bool delim_mode);
211 void LoadDocEntry (gdcmDocEntry *);
212 void FindDocEntryLength(gdcmDocEntry *);
213 void FindDocEntryVR (gdcmDocEntry *);
214 bool CheckDocEntryVR (gdcmDocEntry *, VRKey);
216 std::string GetDocEntryValue (gdcmDocEntry *);
217 std::string GetDocEntryUnvalue(gdcmDocEntry *);
219 void SkipDocEntry (gdcmDocEntry *);
220 void SkipToNextDocEntry (gdcmDocEntry *);
222 void FixDocEntryFoundLength(gdcmDocEntry *, guint32);
223 bool IsDocEntryAnInteger (gdcmDocEntry *);
225 guint32 FindDocEntryLengthOB();
229 void SkipBytes(guint32);
230 guint32 ReadTagLength(guint16, guint16);
231 guint32 ReadItemTagLength();
232 guint32 ReadSequenceDelimiterTagLength();
236 void SwitchSwapToBigEndian();
237 void SetMaxSizeLoadEntry(long);
238 void SetMaxSizePrintEntry(long);
241 // DocEntry related utilities
242 gdcmDocEntry *ReadNextDocEntry ();
245 guint32 GenerateFreeTagKeyInGroup(guint16 group);
249 /// Accessor to \ref printLevel
250 inline void SetPrintLevel(int level) { printLevel = level; }
252 /// Accessor to \ref filename
253 inline std::string &GetFileName() { return Filename; }
255 /// Accessor to \ref filename
256 inline void SetFileName(const char* fileName) { Filename = fileName; }
258 /// Accessor to \ref gdcmElementSet::tagHT
259 inline TagDocEntryHT &GetEntry() { return tagHT; };
261 /// 'Swap code' accessor (see \ref sw )
262 inline int GetSwapCode() { return sw; }
265 inline FILE * GetFP() { return fp; }
267 bool operator<(gdcmDocument &document);
271 //-----------------------------------------------------------------------------