1 /*=========================================================================
4 Module: $RCSfile: gdcmDocument.h,v $
6 Date: $Date: 2004/06/24 18:03:14 $
7 Version: $Revision: 1.15 $
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);
155 virtual void *LoadEntryVoidArea (gdcmBinEntry*);
158 guint16 SwapShort(guint16); // needed by gdcmFile
159 guint32 SwapLong(guint32); // needed by gdcmFile
160 guint16 UnswapShort(guint16); // needed by gdcmFile
161 guint32 UnswapLong(guint32); // needed by gdcmFile
164 // Constructor and destructor are protected to forbid end user
165 // to instanciate from this class gdcmDocument (only gdcmHeader and
166 // gdcmDicomDir are meaningfull).
167 gdcmDocument(bool exception_on_error = false);
168 gdcmDocument(std::string const & inFilename,
169 bool exception_on_error = false,
170 bool enable_sequences = false,
171 bool ignore_shadow = false);
172 virtual ~gdcmDocument(void);
174 void gdcmDocument::Parse7FE0 (void);
176 int CheckIfEntryExistByNumber(guint16 Group, guint16 Elem ); // int !
178 virtual std::string GetEntryByName (TagName tagName);
179 virtual std::string GetEntryVRByName (TagName tagName);
180 virtual std::string GetEntryByNumber (guint16 group, guint16 element);
181 virtual std::string GetEntryVRByNumber(guint16 group, guint16 element);
182 virtual int GetEntryLengthByNumber(guint16 group, guint16 element);
184 virtual bool SetEntryByName (std::string content, std::string tagName);
185 virtual bool SetEntryByNumber(std::string content,
186 guint16 group, guint16 element);
187 virtual bool SetEntryByNumber(void *content, int lgth,
188 guint16 group, guint16 element);
189 virtual bool SetEntryLengthByNumber(guint32 length,
190 guint16 group, guint16 element);
192 virtual size_t GetEntryOffsetByNumber (guint16 Group, guint16 Elem);
193 virtual void *GetEntryVoidAreaByNumber(guint16 Group, guint16 Elem);
194 virtual bool SetEntryVoidAreaByNumber(void *a, guint16 Group, guint16 Elem);
196 virtual void UpdateShaEntries();
199 gdcmDocEntry *GetDocEntryByNumber (guint16 group, guint16 element);
200 gdcmDocEntry *GetDocEntryByName (std::string Name);
202 gdcmValEntry *GetValEntryByNumber (guint16 group, guint16 element);
203 gdcmBinEntry *GetBinEntryByNumber (guint16 group, guint16 element);
205 void LoadDocEntrySafe(gdcmDocEntry *);
209 long ParseDES(gdcmDocEntrySet *set, long offset, long l_max,bool delim_mode);
210 long ParseSQ(gdcmSeqEntry *seq, long offset, long l_max, bool delim_mode);
212 void LoadDocEntry (gdcmDocEntry *);
213 void FindDocEntryLength(gdcmDocEntry *);
214 void FindDocEntryVR (gdcmDocEntry *);
215 bool CheckDocEntryVR (gdcmDocEntry *, VRKey);
217 std::string GetDocEntryValue (gdcmDocEntry *);
218 std::string GetDocEntryUnvalue(gdcmDocEntry *);
220 void SkipDocEntry (gdcmDocEntry *);
221 void SkipToNextDocEntry (gdcmDocEntry *);
223 void FixDocEntryFoundLength(gdcmDocEntry *, guint32);
224 bool IsDocEntryAnInteger (gdcmDocEntry *);
226 guint32 FindDocEntryLengthOB();
230 void SkipBytes(guint32);
231 guint32 ReadTagLength(guint16, guint16);
232 guint32 ReadItemTagLength();
233 guint32 ReadSequenceDelimiterTagLength();
237 void SwitchSwapToBigEndian();
238 void SetMaxSizeLoadEntry(long);
239 void SetMaxSizePrintEntry(long);
242 // DocEntry related utilities
243 gdcmDocEntry *ReadNextDocEntry ();
246 guint32 GenerateFreeTagKeyInGroup(guint16 group);
250 /// Accessor to \ref printLevel
251 inline void SetPrintLevel(int level) { printLevel = level; }
253 /// Accessor to \ref filename
254 inline std::string &GetFileName() { return Filename; }
256 /// Accessor to \ref filename
257 inline void SetFileName(const char* fileName) { Filename = fileName; }
259 /// Accessor to \ref gdcmElementSet::tagHT
260 inline TagDocEntryHT &GetEntry() { return tagHT; };
262 /// 'Swap code' accessor (see \ref sw )
263 inline int GetSwapCode() { return sw; }
266 inline FILE * GetFP() { return fp; }
268 bool operator<(gdcmDocument &document);
272 //-----------------------------------------------------------------------------