1 /*=========================================================================
4 Module: $RCSfile: gdcmDocument.h,v $
6 Date: $Date: 2004/06/18 00:11:45 $
7 Version: $Revision: 1.10 $
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 =========================================================================*/
20 //-----------------------------------------------------------------------------
21 #ifndef GDCMDOCUMENT_H
22 #define GDCMDOCUMENT_H
24 #include "gdcmCommon.h"
27 #include "gdcmException.h"
28 #include "gdcmDictSet.h"
29 #include "gdcmDocEntry.h"
35 #include "gdcmDocEntrySet.h"
36 #include "gdcmElementSet.h"
41 //-----------------------------------------------------------------------------
42 typedef std::string VRKey;
43 typedef std::string VRAtr;
44 typedef std::map<VRKey, VRAtr> VRHT; // Value Representation Hash Table
46 //-----------------------------------------------------------------------------
48 * \brief Derived by both gdcmHeader and gdcmDicomDir
50 class GDCM_EXPORT gdcmDocument : public gdcmElementSet
52 friend class gdcmFile;
54 /// Public dictionary used to parse this header
57 /// \brief Optional "shadow dictionary" (private elements) used to parse
61 /// \brief Equals =1 if user wants to skip shadow groups while parsing
65 /// \brief Size threshold above which an element value will NOT be loaded
66 /// in memory (to avoid loading the image/volume itself). By default,
67 /// this upper bound is fixed to 1024 bytes (which might look reasonable
68 /// when one considers the definition of the various VR contents).
69 guint32 MaxSizeLoadEntry;
71 /// \brief Size threshold above which an element value will NOT be *printed*
72 /// in order no to polute the screen output. By default, this upper bound
73 /// is fixed to 64 bytes.
74 guint32 MaxSizePrintEntry;
77 /// Refering underlying filename.
80 /// \brief SWap code (e.g. Big Endian, Little Endian, Bad Big Endian,
81 /// Bad Little Endian) according to the processor Endianity and
82 /// what is written on disc.
85 /// File Pointer, opened during Header parsing.
88 /// ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown
91 /// After opening the file, we read HEADER_LENGTH_TO_READ bytes.
92 static const unsigned int HEADER_LENGTH_TO_READ;
94 /// \brief Elements whose value is longer than MAX_SIZE_LOAD_ELEMENT_VALUE
96 static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
98 /// \brief Elements whose value is longer than MAX_SIZE_PRINT_ELEMENT_VALUE
100 /// \todo Currently not used since collides with #define in
101 /// \ref gdcmDocEntry.cxx. See also
102 /// \ref gdcmDocument::SetMaxSizePrintEntry()
103 static const unsigned int MAX_SIZE_PRINT_ELEMENT_VALUE;
105 /// Will be set 1 if user asks to 'go inside' the 'sequences' (VR = "SQ")
108 /// \brief Amount of printed details for each Header Entry (Dicom Element):
109 /// 0 : stands for the least detail level.
113 // the 2 following will be merged
114 virtual void PrintPubDict (std::ostream &os = std::cout);
115 virtual void PrintShaDict (std::ostream &os = std::cout);
118 gdcmDict *GetPubDict(void);
119 gdcmDict *GetShaDict(void);
120 bool SetShaDict(gdcmDict *dict);
121 bool SetShaDict(DictKey dictName);
123 // Informations contained in the parser
124 virtual bool IsReadable(void);
125 bool IsGivenTransferSyntax(const std::string & SyntaxToCheck);
126 bool IsImplicitVRLittleEndianTransferSyntax(void);
127 bool IsExplicitVRLittleEndianTransferSyntax(void);
128 bool IsDeflatedExplicitVRLittleEndianTransferSyntax(void);
129 bool IsExplicitVRBigEndianTransferSyntax(void);
130 bool IsJPEGBaseLineProcess1TransferSyntax(void);
131 bool IsJPEGExtendedProcess2_4TransferSyntax(void);
132 bool IsJPEGExtendedProcess3_5TransferSyntax(void);
133 bool IsJPEGSpectralSelectionProcess6_8TransferSyntax(void);
134 bool IsRLELossLessTransferSyntax(void);
135 bool IsJPEGLossless(void);
136 bool IsJPEG2000(void);
137 bool IsDicomV3(void);
139 FileType GetFileType(void);
141 // Read (used in gdcmFile, gdcmDicomDir)
142 FILE *OpenFile(bool exception_on_error = false) throw(gdcmFileError);
143 bool CloseFile(void);
145 // Write (used in gdcmFile, gdcmDicomDir)
146 virtual bool Write(FILE *, FileType);
147 virtual void WriteEntryTagVRLength(gdcmDocEntry *tag,
148 FILE *_fp, FileType type);
149 virtual void WriteEntryValue(gdcmDocEntry *tag,FILE *_fp,FileType type);
150 virtual bool WriteEntry(gdcmDocEntry *tag,FILE *_fp,FileType type);
151 virtual bool WriteEntries(FILE *_fp,FileType type);
153 gdcmValEntry * ReplaceOrCreateByNumber(std::string Value,
154 guint16 Group, guint16 Elem);
156 gdcmBinEntry * ReplaceOrCreateByNumber(void *voidArea, int lgth,
157 guint16 Group, guint16 Elem);
158 bool ReplaceIfExistByNumber (char *Value, guint16 Group, guint16 Elem);
160 virtual void *LoadEntryVoidArea (guint16 Group, guint16 Element);
161 void LoadVLEntry (gdcmDocEntry *entry);
164 guint16 SwapShort(guint16); // needed by gdcmFile
165 guint32 SwapLong(guint32); // needed by gdcmFile
166 guint16 UnswapShort(guint16); // needed by gdcmFile
167 guint32 UnswapLong(guint32); // needed by gdcmFile
170 // Constructor and destructor are protected to forbid end user
171 // to instanciate from this class gdcmDocument (only gdcmHeader and
172 // gdcmDicomDir are meaningfull).
173 gdcmDocument(bool exception_on_error = false);
174 gdcmDocument(const char *inFilename,
175 bool exception_on_error = false,
176 bool enable_sequences = false,
177 bool ignore_shadow = false);
178 virtual ~gdcmDocument(void);
180 void gdcmDocument::Parse7FE0 (void);
182 int CheckIfEntryExistByNumber(guint16 Group, guint16 Elem ); // int !
184 virtual std::string GetEntryByName (std::string tagName);
185 virtual std::string GetEntryVRByName (std::string tagName);
186 virtual std::string GetEntryByNumber (guint16 group, guint16 element);
187 virtual std::string GetEntryVRByNumber(guint16 group, guint16 element);
188 virtual int GetEntryLengthByNumber(guint16 group, guint16 element);
190 virtual bool SetEntryByName (std::string content, std::string tagName);
191 virtual bool SetEntryByNumber(std::string content,
192 guint16 group, guint16 element);
193 virtual bool SetEntryByNumber(void *content, int lgth,
194 guint16 group, guint16 element);
195 virtual bool SetEntryLengthByNumber(guint32 length,
196 guint16 group, guint16 element);
198 virtual size_t GetEntryOffsetByNumber (guint16 Group, guint16 Elem);
199 virtual void *GetEntryVoidAreaByNumber(guint16 Group, guint16 Elem);
200 virtual bool SetEntryVoidAreaByNumber(void *a, guint16 Group, guint16 Elem);
202 virtual void UpdateShaEntries(void);
205 gdcmDocEntry *GetDocEntryByNumber (guint16 group, guint16 element);
206 gdcmDocEntry *GetDocEntryByName (std::string Name);
208 gdcmValEntry *GetValEntryByNumber (guint16 group, guint16 element);
209 gdcmBinEntry *GetBinEntryByNumber (guint16 group, guint16 element);
211 void LoadDocEntrySafe(gdcmDocEntry *);
215 long ParseDES(gdcmDocEntrySet *set, long offset, long l_max,bool delim_mode);
216 long ParseSQ(gdcmSeqEntry *seq, long offset, long l_max, bool delim_mode);
218 void LoadDocEntry (gdcmDocEntry *);
219 void FindDocEntryLength(gdcmDocEntry *);
220 void FindDocEntryVR (gdcmDocEntry *);
221 bool CheckDocEntryVR (gdcmDocEntry *, VRKey);
223 std::string GetDocEntryValue (gdcmDocEntry *);
224 std::string GetDocEntryUnvalue(gdcmDocEntry *);
226 void SkipDocEntry (gdcmDocEntry *);
227 void SkipToNextDocEntry (gdcmDocEntry *);
229 void FixDocEntryFoundLength(gdcmDocEntry *, guint32);
230 bool IsDocEntryAnInteger (gdcmDocEntry *);
232 guint32 FindDocEntryLengthOB(void);
234 guint16 ReadInt16(void);
235 guint32 ReadInt32(void);
236 void SkipBytes(guint32);
237 guint32 ReadTagLength(guint16, guint16);
238 guint32 ReadItemTagLength(void);
239 guint32 ReadSequenceDelimiterTagLength(void);
241 void Initialise(void);
242 bool CheckSwap(void);
243 void SwitchSwapToBigEndian(void);
244 void SetMaxSizeLoadEntry(long);
245 void SetMaxSizePrintEntry(long);
247 // DictEntry related utilities
249 gdcmDictEntry *GetDictEntryByName (std::string Name);
250 gdcmDictEntry *GetDictEntryByNumber(guint16, guint16);
251 gdcmDictEntry *NewVirtualDictEntry(guint16 group,
253 std::string vr = "unkn",
254 std::string fourth = "unkn",
255 std::string name = "unkn");
256 // DocEntry related utilities
257 gdcmDocEntry *ReadNextDocEntry (void);
258 gdcmDocEntry *NewDocEntryByNumber(guint16 group,
260 gdcmDocEntry *NewDocEntryByName (std::string Name);
262 gdcmValEntry *NewValEntryByNumber(guint16 group,
264 gdcmBinEntry *NewBinEntryByNumber(guint16 group,
266 guint32 GenerateFreeTagKeyInGroup(guint16 group);
270 /// Accessor to \ref printLevel
271 void SetPrintLevel(int level) { printLevel = level; };
273 /// Accessor to \ref filename
274 inline std::string GetFileName(void) {return filename;}
276 /// Accessor to \ref filename
277 inline void SetFileName(char* fileName) {filename = fileName;}
279 /// Accessor to \ref gdcmElementSet::tagHT
280 inline TagDocEntryHT &GetEntry(void) { return tagHT; };
282 /// 'Swap code' accessor (see \ref sw )
283 inline int GetSwapCode(void) { return sw; }
286 inline FILE * GetFP(void) { return fp; }
288 bool operator<(gdcmDocument &document);
292 //-----------------------------------------------------------------------------