1 /*=========================================================================
4 Module: $RCSfile: gdcmDocument.h,v $
6 Date: $Date: 2004/06/21 04:18:25 $
7 Version: $Revision: 1.12 $
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)
144 virtual bool Write(FILE *, FileType);
145 virtual void WriteEntryTagVRLength(gdcmDocEntry *tag,
146 FILE *_fp, FileType type);
147 virtual void WriteEntryValue(gdcmDocEntry *tag,FILE *_fp,FileType type);
148 virtual bool WriteEntry(gdcmDocEntry *tag,FILE *_fp,FileType type);
149 virtual bool WriteEntries(FILE *_fp,FileType type);
151 gdcmValEntry * ReplaceOrCreateByNumber(std::string Value,
152 guint16 Group, guint16 Elem);
154 gdcmBinEntry * ReplaceOrCreateByNumber(void *voidArea, int lgth,
155 guint16 Group, guint16 Elem);
156 bool ReplaceIfExistByNumber (char *Value, guint16 Group, guint16 Elem);
158 virtual void *LoadEntryVoidArea (guint16 Group, guint16 Element);
159 void LoadVLEntry (gdcmDocEntry *entry);
162 guint16 SwapShort(guint16); // needed by gdcmFile
163 guint32 SwapLong(guint32); // needed by gdcmFile
164 guint16 UnswapShort(guint16); // needed by gdcmFile
165 guint32 UnswapLong(guint32); // needed by gdcmFile
168 // Constructor and destructor are protected to forbid end user
169 // to instanciate from this class gdcmDocument (only gdcmHeader and
170 // gdcmDicomDir are meaningfull).
171 gdcmDocument(bool exception_on_error = false);
172 gdcmDocument(std::string const & inFilename,
173 bool exception_on_error = false,
174 bool enable_sequences = false,
175 bool ignore_shadow = false);
176 virtual ~gdcmDocument(void);
178 void gdcmDocument::Parse7FE0 (void);
180 int CheckIfEntryExistByNumber(guint16 Group, guint16 Elem ); // int !
182 virtual std::string GetEntryByName (std::string tagName);
183 virtual std::string GetEntryVRByName (std::string tagName);
184 virtual std::string GetEntryByNumber (guint16 group, guint16 element);
185 virtual std::string GetEntryVRByNumber(guint16 group, guint16 element);
186 virtual int GetEntryLengthByNumber(guint16 group, guint16 element);
188 virtual bool SetEntryByName (std::string content, std::string tagName);
189 virtual bool SetEntryByNumber(std::string content,
190 guint16 group, guint16 element);
191 virtual bool SetEntryByNumber(void *content, int lgth,
192 guint16 group, guint16 element);
193 virtual bool SetEntryLengthByNumber(guint32 length,
194 guint16 group, guint16 element);
196 virtual size_t GetEntryOffsetByNumber (guint16 Group, guint16 Elem);
197 virtual void *GetEntryVoidAreaByNumber(guint16 Group, guint16 Elem);
198 virtual bool SetEntryVoidAreaByNumber(void *a, guint16 Group, guint16 Elem);
200 virtual void UpdateShaEntries();
203 gdcmDocEntry *GetDocEntryByNumber (guint16 group, guint16 element);
204 gdcmDocEntry *GetDocEntryByName (std::string Name);
206 gdcmValEntry *GetValEntryByNumber (guint16 group, guint16 element);
207 gdcmBinEntry *GetBinEntryByNumber (guint16 group, guint16 element);
209 void LoadDocEntrySafe(gdcmDocEntry *);
213 long ParseDES(gdcmDocEntrySet *set, long offset, long l_max,bool delim_mode);
214 long ParseSQ(gdcmSeqEntry *seq, long offset, long l_max, bool delim_mode);
216 void LoadDocEntry (gdcmDocEntry *);
217 void FindDocEntryLength(gdcmDocEntry *);
218 void FindDocEntryVR (gdcmDocEntry *);
219 bool CheckDocEntryVR (gdcmDocEntry *, VRKey);
221 std::string GetDocEntryValue (gdcmDocEntry *);
222 std::string GetDocEntryUnvalue(gdcmDocEntry *);
224 void SkipDocEntry (gdcmDocEntry *);
225 void SkipToNextDocEntry (gdcmDocEntry *);
227 void FixDocEntryFoundLength(gdcmDocEntry *, guint32);
228 bool IsDocEntryAnInteger (gdcmDocEntry *);
230 guint32 FindDocEntryLengthOB();
234 void SkipBytes(guint32);
235 guint32 ReadTagLength(guint16, guint16);
236 guint32 ReadItemTagLength();
237 guint32 ReadSequenceDelimiterTagLength();
241 void SwitchSwapToBigEndian();
242 void SetMaxSizeLoadEntry(long);
243 void SetMaxSizePrintEntry(long);
245 // DictEntry related utilities
247 gdcmDictEntry *GetDictEntryByName (std::string Name);
248 gdcmDictEntry *GetDictEntryByNumber(guint16, guint16);
249 gdcmDictEntry *NewVirtualDictEntry(guint16 group,
251 std::string vr = "unkn",
252 std::string fourth = "unkn",
253 std::string name = "unkn");
254 // DocEntry related utilities
255 gdcmDocEntry *ReadNextDocEntry ();
256 gdcmDocEntry *NewDocEntryByNumber(guint16 group,
258 gdcmDocEntry *NewDocEntryByName (std::string Name);
260 gdcmValEntry *NewValEntryByNumber(guint16 group,
262 gdcmBinEntry *NewBinEntryByNumber(guint16 group,
264 guint32 GenerateFreeTagKeyInGroup(guint16 group);
268 /// Accessor to \ref printLevel
269 inline void SetPrintLevel(int level) { printLevel = level; }
271 /// Accessor to \ref filename
272 inline std::string &GetFileName() { return Filename; }
274 /// Accessor to \ref filename
275 inline void SetFileName(const char* fileName) { Filename = fileName; }
277 /// Accessor to \ref gdcmElementSet::tagHT
278 inline TagDocEntryHT &GetEntry() { return tagHT; };
280 /// 'Swap code' accessor (see \ref sw )
281 inline int GetSwapCode() { return sw; }
284 inline FILE * GetFP() { return fp; }
286 bool operator<(gdcmDocument &document);
290 //-----------------------------------------------------------------------------