2 //-----------------------------------------------------------------------------
6 #include "gdcmCommon.h"
9 #include "gdcmException.h"
10 #include "gdcmDictSet.h"
11 #include "gdcmDocEntry.h"
17 #include "gdcmDocEntrySet.h"
18 #include "gdcmElementSet.h"
23 //-----------------------------------------------------------------------------
24 typedef std::string VRKey;
25 typedef std::string VRAtr;
26 typedef std::map<VRKey, VRAtr> VRHT; // Value Representation Hash Table
28 //-----------------------------------------------------------------------------
30 * \brief Derived by both gdcmHeader and gdcmDicomDir
32 class GDCM_EXPORT gdcmDocument : public gdcmElementSet
34 friend class gdcmFile;
36 /// Public dictionary used to parse this header
39 /// \brief Optional "shadow dictionary" (private elements) used to parse
43 /// \brief Equals =1 if user wants to skip shadow groups while parsing
47 /// \brief Size threshold above which an element value will NOT be loaded
48 /// in memory (to avoid loading the image/volume itself). By default,
49 /// this upper bound is fixed to 1024 bytes (which might look reasonable
50 /// when one considers the definition of the various VR contents).
51 guint32 MaxSizeLoadEntry;
53 /// \brief Size threshold above which an element value will NOT be *printed*
54 /// in order no to polute the screen output. By default, this upper bound
55 /// is fixed to 64 bytes.
56 guint32 MaxSizePrintEntry;
59 /// Refering underlying filename.
62 /// \brief SWap code (e.g. Big Endian, Little Endian, Bad Big Endian,
63 /// Bad Little Endian) according to the processor Endianity and
64 /// what is written on disc.
67 /// File Pointer, opened during Header parsing.
70 /// ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown
73 /// After opening the file, we read HEADER_LENGTH_TO_READ bytes.
74 static const unsigned int HEADER_LENGTH_TO_READ;
76 /// \brief Elements whose value is longer than MAX_SIZE_LOAD_ELEMENT_VALUE
78 static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
80 /// \brief Elements whose value is longer than MAX_SIZE_PRINT_ELEMENT_VALUE
82 /// \todo Currently not used since collides with #define in
83 /// \ref gdcmDocEntry.cxx. See also
84 /// \ref gdcmDocument::SetMaxSizePrintEntry()
85 static const unsigned int MAX_SIZE_PRINT_ELEMENT_VALUE;
87 /// Will be set 1 if user asks to 'go inside' the 'sequences' (VR = "SQ")
90 /// \brief Amount of printed details for each Header Entry (Dicom Element):
91 /// 0 : stands for the least detail level.
95 // the 2 following will be merged
96 virtual void PrintPubDict (std::ostream &os = std::cout);
97 virtual void PrintShaDict (std::ostream &os = std::cout);
100 gdcmDict *GetPubDict(void);
101 gdcmDict *GetShaDict(void);
102 bool SetShaDict(gdcmDict *dict);
103 bool SetShaDict(DictKey dictName);
105 // Informations contained in the parser
106 virtual bool IsReadable(void);
107 bool IsImplicitVRLittleEndianTransferSyntax(void);
108 bool IsExplicitVRLittleEndianTransferSyntax(void);
109 bool IsDeflatedExplicitVRLittleEndianTransferSyntax(void);
110 bool IsExplicitVRBigEndianTransferSyntax(void);
111 bool IsJPEGBaseLineProcess1TransferSyntax(void);
112 bool IsJPEGExtendedProcess2_4TransferSyntax(void);
113 bool IsJPEGExtendedProcess3_5TransferSyntax(void);
114 bool IsJPEGSpectralSelectionProcess6_8TransferSyntax(void);
115 bool IsRLELossLessTransferSyntax(void);
116 bool IsJPEGLossless(void);
117 bool IsJPEG2000(void);
118 bool IsDicomV3(void);
120 FileType GetFileType(void);
122 // Read (used in gdcmFile, gdcmDicomDir)
123 FILE *OpenFile(bool exception_on_error = false) throw(gdcmFileError);
124 bool CloseFile(void);
126 // Write (used in gdcmFile, gdcmDicomDir)
127 virtual bool Write(FILE *, FileType);
128 virtual void WriteEntryTagVRLength(gdcmDocEntry *tag,
129 FILE *_fp, FileType type);
130 virtual void WriteEntryValue(gdcmDocEntry *tag,FILE *_fp,FileType type);
131 virtual bool WriteEntry(gdcmDocEntry *tag,FILE *_fp,FileType type);
132 virtual bool WriteEntries(FILE *_fp,FileType type);
134 gdcmValEntry * ReplaceOrCreateByNumber(std::string Value,
135 guint16 Group, guint16 Elem);
137 gdcmBinEntry * ReplaceOrCreateByNumber(void *voidArea, int lgth,
138 guint16 Group, guint16 Elem);
139 bool ReplaceIfExistByNumber (char *Value, guint16 Group, guint16 Elem);
141 virtual void *LoadEntryVoidArea (guint16 Group, guint16 Element);
142 void LoadVLEntry (gdcmDocEntry *entry);
145 guint16 SwapShort(guint16); // needed by gdcmFile
146 guint32 SwapLong(guint32); // needed by gdcmFile
147 guint16 UnswapShort(guint16); // needed by gdcmFile
148 guint32 UnswapLong(guint32); // needed by gdcmFile
151 // Constructor and destructor are protected to forbid end user
152 // to instanciate from this class gdcmDocument (only gdcmHeader and
153 // gdcmDicomDir are meaningfull).
154 gdcmDocument(bool exception_on_error = false);
155 gdcmDocument(const char *inFilename,
156 bool exception_on_error = false,
157 bool enable_sequences = false,
158 bool ignore_shadow = false);
159 virtual ~gdcmDocument(void);
161 void gdcmDocument::Parse7FE0 (void);
163 int CheckIfEntryExistByNumber(guint16 Group, guint16 Elem ); // int !
165 virtual std::string GetEntryByName (std::string tagName);
166 virtual std::string GetEntryVRByName (std::string tagName);
167 virtual std::string GetEntryByNumber (guint16 group, guint16 element);
168 virtual std::string GetEntryVRByNumber(guint16 group, guint16 element);
169 virtual int GetEntryLengthByNumber(guint16 group, guint16 element);
171 virtual bool SetEntryByName (std::string content, std::string tagName);
172 virtual bool SetEntryByNumber(std::string content,
173 guint16 group, guint16 element);
174 virtual bool SetEntryByNumber(void *content, int lgth,
175 guint16 group, guint16 element);
176 virtual bool SetEntryLengthByNumber(guint32 length,
177 guint16 group, guint16 element);
179 virtual size_t GetEntryOffsetByNumber (guint16 Group, guint16 Elem);
180 virtual void *GetEntryVoidAreaByNumber(guint16 Group, guint16 Elem);
181 virtual bool SetEntryVoidAreaByNumber(void *a, guint16 Group, guint16 Elem);
183 virtual void UpdateShaEntries(void);
186 gdcmDocEntry *GetDocEntryByNumber (guint16 group, guint16 element);
187 gdcmDocEntry *GetDocEntryByName (std::string Name);
189 gdcmValEntry *GetValEntryByNumber (guint16 group, guint16 element);
190 gdcmBinEntry *GetBinEntryByNumber (guint16 group, guint16 element);
192 void LoadDocEntrySafe(gdcmDocEntry *);
196 long ParseDES(gdcmDocEntrySet *set, long offset, long l_max,bool delim_mode);
197 long ParseSQ(gdcmSeqEntry *seq, long offset, long l_max, bool delim_mode);
199 void LoadDocEntry (gdcmDocEntry *);
200 void FindDocEntryLength(gdcmDocEntry *);
201 void FindDocEntryVR (gdcmDocEntry *);
202 bool CheckDocEntryVR (gdcmDocEntry *, VRKey);
204 std::string GetDocEntryValue (gdcmDocEntry *);
205 std::string GetDocEntryUnvalue(gdcmDocEntry *);
207 void SkipDocEntry (gdcmDocEntry *);
208 void SkipToNextDocEntry (gdcmDocEntry *);
210 void FixDocEntryFoundLength(gdcmDocEntry *, guint32);
211 bool IsDocEntryAnInteger (gdcmDocEntry *);
213 guint32 FindDocEntryLengthOB(void);
215 guint16 ReadInt16(void);
216 guint32 ReadInt32(void);
217 void SkipBytes(guint32);
219 void Initialise(void);
220 bool CheckSwap(void);
221 void SwitchSwapToBigEndian(void);
222 void SetMaxSizeLoadEntry(long);
223 void SetMaxSizePrintEntry(long);
225 // DictEntry related utilities
227 gdcmDictEntry *GetDictEntryByName (std::string Name);
228 gdcmDictEntry *GetDictEntryByNumber(guint16, guint16);
229 gdcmDictEntry *NewVirtualDictEntry(guint16 group,
231 std::string vr = "unkn",
232 std::string fourth = "unkn",
233 std::string name = "unkn");
234 // DocEntry related utilities
235 gdcmDocEntry *ReadNextDocEntry (void);
236 gdcmDocEntry *NewDocEntryByNumber(guint16 group,
238 gdcmDocEntry *NewDocEntryByName (std::string Name);
240 gdcmValEntry *NewValEntryByNumber(guint16 group,
242 gdcmBinEntry *NewBinEntryByNumber(guint16 group,
244 guint32 GenerateFreeTagKeyInGroup(guint16 group);
248 /// Accessor to \ref printLevel
249 void SetPrintLevel(int level) { printLevel = level; };
251 /// Accessor to \ref filename
252 inline std::string GetFileName(void) {return filename;}
254 /// Accessor to \ref filename
255 inline void SetFileName(char* fileName) {filename = fileName;}
257 /// Accessor to \ref gdcmElementSet::tagHT
258 inline TagDocEntryHT &GetEntry(void) { return tagHT; };
260 /// 'Swap code' accessor (see \ref sw )
261 inline int GetSwapCode(void) { return sw; }
264 inline FILE * GetFP(void) { return fp; }
266 bool operator<(gdcmDocument &document);
270 //-----------------------------------------------------------------------------