2 //-----------------------------------------------------------------------------
6 #include "gdcmCommon.h"
10 #include "gdcmException.h"
11 #include "gdcmDictSet.h"
12 #include "gdcmDocEntry.h"
16 #include "gdcmDocEntrySet.h"
17 #include "gdcmElementSet.h"
22 //-----------------------------------------------------------------------------
23 typedef std::string VRKey;
24 typedef std::string VRAtr;
25 typedef std::map<VRKey, VRAtr> VRHT; // Value Representation Hash Table
27 //-----------------------------------------------------------------------------
29 * \brief used by both gdcmHeader and gdcmDicomDir
31 class GDCM_EXPORT gdcmDocument : public gdcmElementSet
34 /// Public dictionary used to parse this header
37 /// \brief Optional "shadow dictionary" (private elements) used to parse
41 /// \brief Equals =1 if user wants to skip shadow groups while parsing
45 /// \brief Size threshold above which an element value will NOT be loaded
46 /// in memory (to avoid loading the image/volume itself). By default,
47 /// this upper bound is fixed to 1024 bytes (which might look reasonable
48 /// when one considers the definition of the various VR contents).
49 guint32 MaxSizeLoadEntry;
51 /// \brief Size threshold above which an element value will NOT be *printed*
52 /// in order no to polute the screen output. By default, this upper bound
53 /// is fixed to 64 bytes.
54 guint32 MaxSizePrintEntry;
57 /// Refering underlying filename.
60 /// \brief SWap code (e.g. Big Endian, Little Endian, Bad Big Endian,
61 /// Bad Little Endian) according to the processor Endianity and
62 /// what is written on disc.
65 /// File Pointer, opened during Header parsing.
68 /// ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown
71 /// After opening the file, we read HEADER_LENGTH_TO_READ bytes.
72 static const unsigned int HEADER_LENGTH_TO_READ;
74 /// \brief Elements whose value is longer than MAX_SIZE_LOAD_ELEMENT_VALUE
76 static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
78 /// \brief Elements whose value is longer than MAX_SIZE_PRINT_ELEMENT_VALUE
80 /// \todo Currently not used since collides with #define in
81 /// \ref gdcmDocEntry.cxx. See also
82 /// \ref gdcmDocument::SetMaxSizePrintEntry()
83 static const unsigned int MAX_SIZE_PRINT_ELEMENT_VALUE;
85 /// Will be set 1 if user asks to 'go inside' the 'sequences' (VR = "SQ")
88 /// \brief Amount of printed details for each Header Entry (Dicom Element):
89 /// 0 : stands for the least detail level.
96 // Canonical Printing method (see also gdcmDocument::SetPrintLevel)
97 // virtual void Print (std::ostream &os = std::cout);
100 // no more Print method for gdcmDocument (inherits from gdcmElementSet
101 // virtual void PrintEntry (std::ostream &os = std::cout)
102 // { return Print(os);};
104 // the 2 following will be merged
105 virtual void PrintPubDict (std::ostream &os = std::cout);
106 virtual void PrintShaDict (std::ostream &os = std::cout);
109 gdcmDict *GetPubDict(void);
110 gdcmDict *GetShaDict(void);
111 bool SetShaDict(gdcmDict *dict);
112 bool SetShaDict(DictKey dictName);
114 // Informations contained in the parser
115 virtual bool IsReadable(void);
116 bool IsImplicitVRLittleEndianTransferSyntax(void);
117 bool IsExplicitVRLittleEndianTransferSyntax(void);
118 bool IsDeflatedExplicitVRLittleEndianTransferSyntax(void);
119 bool IsExplicitVRBigEndianTransferSyntax(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 gdcmDocEntry * ReplaceOrCreateByNumber(std::string Value,
135 guint16 Group, guint16 Elem);
136 bool ReplaceIfExistByNumber (char *Value, guint16 Group, guint16 Elem);
138 virtual void *LoadEntryVoidArea (guint16 Group, guint16 Element);
139 void LoadVLEntry (gdcmDocEntry *entry);
142 guint16 SwapShort(guint16); // needed by gdcmFile
143 guint32 SwapLong(guint32); // needed by gdcmFile
144 guint16 UnswapShort(guint16); // needed by gdcmFile
145 guint32 UnswapLong(guint32); // needed by gdcmFile
148 // Constructor and destructor are protected to forbid end user
149 // to instanciate from this class gdcmDocument (only gdcmHeader and
150 // gdcmDicomDir are meaningfull).
151 gdcmDocument(bool exception_on_error = false);
152 gdcmDocument(const char *inFilename,
153 bool exception_on_error = false,
154 bool enable_sequences = false,
155 bool ignore_shadow = false);
156 virtual ~gdcmDocument(void);
158 void gdcmDocument::Parse7FE0 (void);
160 int CheckIfEntryExistByNumber(guint16 Group, guint16 Elem ); // int !
161 virtual std::string GetEntryByName (std::string tagName);
162 virtual std::string GetEntryVRByName (std::string tagName);
163 virtual std::string GetEntryByNumber (guint16 group, guint16 element);
164 virtual std::string GetEntryVRByNumber(guint16 group, guint16 element);
165 virtual int GetEntryLengthByNumber(guint16 group, guint16 element);
167 virtual bool SetEntryByName (std::string content, std::string tagName);
168 virtual bool SetEntryByNumber(std::string content,
169 guint16 group, guint16 element);
170 virtual bool SetEntryLengthByNumber(guint32 length,
171 guint16 group, guint16 element);
173 virtual size_t GetEntryOffsetByNumber (guint16 Group, guint16 Elem);
174 virtual void *GetEntryVoidAreaByNumber(guint16 Group, guint16 Elem);
175 virtual bool SetEntryVoidAreaByNumber(void *a, guint16 Group, guint16 Elem);
177 virtual void UpdateShaEntries(void);
180 gdcmDocEntry *GetDocEntryByNumber (guint16 group, guint16 element);
181 gdcmDocEntry *GetDocEntryByName (std::string Name);
183 void LoadDocEntrySafe(gdcmDocEntry *);
186 //void UpdateGroupLength(bool SkipSequence = false,
187 // FileType type = ImplicitVR);
189 //void AddDocEntry (gdcmDocEntry *);
194 //bool LoadHeaderEntries(bool exception_on_error = false) throw(gdcmFormatError);
195 // remplacé par ParseDES.
196 // What about exception_on_error ?
198 long ParseDES(gdcmDocEntrySet *set, long offset, long l_max, bool delim_mode);
199 // long ParseSQ(gdcmDocEntrySet *set, long offset, long l_max, bool delim_mode);
200 long ParseSQ(gdcmSeqEntry *seq, long offset, long l_max, bool delim_mode);
202 void LoadDocEntry (gdcmDocEntry *);
203 void FindDocEntryLength(gdcmDocEntry *);
204 void FindDocEntryVR (gdcmDocEntry *);
205 bool CheckDocEntryVR (gdcmDocEntry *, VRKey);
207 std::string GetDocEntryValue (gdcmDocEntry *);
208 std::string GetDocEntryUnvalue(gdcmDocEntry *);
210 void SkipDocEntry (gdcmDocEntry *);
211 void SkipToNextDocEntry (gdcmDocEntry *);
213 void FixDocEntryFoundLength(gdcmDocEntry *, guint32);
214 bool IsDocEntryAnInteger (gdcmDocEntry *);
216 guint32 FindDocEntryLengthOB(void);
218 guint16 ReadInt16(void);
219 guint32 ReadInt32(void);
220 void SkipBytes(guint32);
222 void Initialise(void);
223 bool CheckSwap(void);
224 void SwitchSwapToBigEndian(void);
225 void SetMaxSizeLoadEntry(long);
226 void SetMaxSizePrintEntry(long);
228 // DictEntry related utilities
230 gdcmDictEntry *GetDictEntryByName (std::string Name);
231 gdcmDictEntry *GetDictEntryByNumber(guint16, guint16);
232 gdcmDictEntry *NewVirtualDictEntry(guint16 group,
234 std::string vr = "unkn",
235 std::string fourth = "unkn",
236 std::string name = "unkn");
237 //gdcmDictEntry *NewVirtualDictEntry(gdcmDocEntry *); // never defined
239 // DocEntry related utilities
241 gdcmDocEntry *ReadNextDocEntry (void);
242 gdcmDocEntry *NewDocEntryByNumber(guint16 group,
244 gdcmDocEntry *NewDocEntryByName (std::string Name);
246 // Deprecated (Not used) --> commented out
247 //gdcmDocEntry *NewManualDocEntryToPubDict(std::string NewTagName,
250 guint32 GenerateFreeTagKeyInGroup(guint16 group);
254 /// Accessor to \ref printLevel
255 void SetPrintLevel(int level) { printLevel = level; };
257 /// Accessor to \ref filename
258 inline std::string GetFileName(void) {return filename;}
260 /// Accessor to \ref filename
261 inline void SetFileName(char* fileName) {filename = fileName;}
263 /// Accessor to \ref gdcmDocument::tagHT
264 inline TagDocEntryHT &GetEntry(void) { return tagHT; };
266 /// Accessor to \ref gdcmDocument::listEntries
267 //inline ListTag &GetListEntry(void) { return listEntries; };
269 /// 'Swap code' accessor (see \ref sw )
270 inline int GetSwapCode(void) { return sw; }
273 inline FILE * GetFP(void) { return fp; }
277 //-----------------------------------------------------------------------------