2 //-----------------------------------------------------------------------------
6 #include "gdcmCommon.h"
10 #include "gdcmException.h"
11 #include "gdcmDictSet.h"
12 #include "gdcmDocEntry.h"
13 //#include "gdcmSeqEntry.h"
15 #include "gdcmDocEntrySet.h"
16 #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 typedef std::map<TagKey, gdcmDocEntry *> TagDocEntryHT;
29 //-----------------------------------------------------------------------------
31 * \brief used by both gdcmHeader and gdcmDicomDir
33 class GDCM_EXPORT gdcmDocument : public gdcmElementSet
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.
98 // Canonical Printing method (see also gdcmDocument::SetPrintLevel)
99 // virtual void Print (std::ostream &os = std::cout);
100 // {PrintEntry(os);};
102 // no more Print method for gdcmDocument (inherits from gdcmElementSet
103 // virtual void PrintEntry (std::ostream &os = std::cout)
104 // { return Print(os);};
106 // the 2 following will be merged
107 virtual void PrintPubDict (std::ostream &os = std::cout);
108 virtual void PrintShaDict (std::ostream &os = std::cout);
111 gdcmDict *GetPubDict(void);
112 gdcmDict *GetShaDict(void);
113 bool SetShaDict(gdcmDict *dict);
114 bool SetShaDict(DictKey dictName);
116 // Informations contained in the parser
117 virtual bool IsReadable(void);
118 bool IsImplicitVRLittleEndianTransferSyntax(void);
119 bool IsExplicitVRLittleEndianTransferSyntax(void);
120 bool IsDeflatedExplicitVRLittleEndianTransferSyntax(void);
121 bool IsExplicitVRBigEndianTransferSyntax(void);
122 FileType GetFileType(void);
124 // Read (used in gdcmFile, gdcmDicomDir)
125 FILE *OpenFile(bool exception_on_error = false) throw(gdcmFileError);
126 bool CloseFile(void);
128 // Write (used in gdcmFile, gdcmDicomDir)
129 virtual bool Write(FILE *, FileType);
130 virtual void WriteEntryTagVRLength(gdcmDocEntry *tag,
131 FILE *_fp, FileType type);
132 virtual void WriteEntryValue(gdcmDocEntry *tag,FILE *_fp,FileType type);
133 virtual bool WriteEntry(gdcmDocEntry *tag,FILE *_fp,FileType type);
134 virtual bool WriteEntries(FILE *_fp,FileType type);
136 gdcmDocEntry * ReplaceOrCreateByNumber(std::string Value,
137 guint16 Group, guint16 Elem);
138 bool ReplaceIfExistByNumber (char *Value, guint16 Group, guint16 Elem);
140 virtual void *LoadEntryVoidArea (guint16 Group, guint16 Element);
141 void LoadVLEntry (gdcmDocEntry *entry);
144 guint16 SwapShort(guint16); // needed by gdcmFile
145 guint32 SwapLong(guint32); // needed by gdcmFile
146 guint16 UnswapShort(guint16); // needed by gdcmFile
147 guint32 UnswapLong(guint32); // needed by gdcmFile
150 // Constructor and destructor are protected to forbid end user
151 // to instanciate from this class gdcmDocument (only gdcmHeader and
152 // gdcmDicomDir are meaningfull).
153 gdcmDocument(bool exception_on_error = false);
154 gdcmDocument(const char *inFilename,
155 bool exception_on_error = false,
156 bool enable_sequences = false,
157 bool ignore_shadow = false);
158 virtual ~gdcmDocument(void);
160 void gdcmDocument::Parse7FE0 (void);
162 int CheckIfEntryExistByNumber(guint16 Group, guint16 Elem ); // int !
163 virtual std::string GetEntryByName (std::string tagName);
164 virtual std::string GetEntryVRByName (std::string tagName);
165 virtual std::string GetEntryByNumber (guint16 group, guint16 element);
166 virtual std::string GetEntryVRByNumber(guint16 group, guint16 element);
167 virtual int GetEntryLengthByNumber(guint16 group, guint16 element);
169 virtual bool SetEntryByName (std::string content, std::string tagName);
170 virtual bool SetEntryByNumber(std::string content,
171 guint16 group, guint16 element);
172 virtual bool SetEntryLengthByNumber(guint32 length,
173 guint16 group, guint16 element);
175 virtual size_t GetEntryOffsetByNumber (guint16 Group, guint16 Elem);
176 virtual void *GetEntryVoidAreaByNumber(guint16 Group, guint16 Elem);
177 virtual bool SetEntryVoidAreaByNumber(void *a, guint16 Group, guint16 Elem);
179 virtual void UpdateShaEntries(void);
182 gdcmDocEntry *GetDocEntryByNumber (guint16 group, guint16 element);
183 gdcmDocEntry *GetDocEntryByName (std::string Name);
185 void LoadDocEntrySafe(gdcmDocEntry *);
188 //void UpdateGroupLength(bool SkipSequence = false,
189 // FileType type = ImplicitVR);
191 //void AddDocEntry (gdcmDocEntry *);
196 //bool LoadHeaderEntries(bool exception_on_error = false) throw(gdcmFormatError);
197 // remplacé par ParseDES.
198 // What about exception_on_error ?
200 long ParseDES(gdcmDocEntrySet *set, long offset, long l_max, bool delim_mode);
201 // long ParseSQ(gdcmDocEntrySet *set, long offset, long l_max, bool delim_mode);
202 long ParseSQ(gdcmSeqEntry *seq, long offset, long l_max, bool delim_mode);
204 void LoadDocEntry (gdcmDocEntry *);
205 void FindDocEntryLength(gdcmDocEntry *);
206 void FindDocEntryVR (gdcmDocEntry *);
207 bool CheckDocEntryVR (gdcmDocEntry *, VRKey);
209 std::string GetDocEntryValue (gdcmDocEntry *);
210 std::string GetDocEntryUnvalue(gdcmDocEntry *);
212 void SkipDocEntry (gdcmDocEntry *);
213 void SkipToNextDocEntry (gdcmDocEntry *);
215 void FixDocEntryFoundLength(gdcmDocEntry *, guint32);
216 bool IsDocEntryAnInteger (gdcmDocEntry *);
218 guint32 FindDocEntryLengthOB(void);
220 guint16 ReadInt16(void);
221 guint32 ReadInt32(void);
222 void SkipBytes(guint32);
224 void Initialise(void);
225 bool CheckSwap(void);
226 void SwitchSwapToBigEndian(void);
227 void SetMaxSizeLoadEntry(long);
228 void SetMaxSizePrintEntry(long);
230 // DictEntry related utilities
232 gdcmDictEntry *GetDictEntryByName (std::string Name);
233 gdcmDictEntry *GetDictEntryByNumber(guint16, guint16);
234 gdcmDictEntry *NewVirtualDictEntry(guint16 group,
236 std::string vr = "unkn",
237 std::string fourth = "unkn",
238 std::string name = "unkn");
239 //gdcmDictEntry *NewVirtualDictEntry(gdcmDocEntry *); // never defined
241 // DocEntry related utilities
243 gdcmDocEntry *ReadNextDocEntry (void);
244 gdcmDocEntry *NewDocEntryByNumber(guint16 group,
246 gdcmDocEntry *NewDocEntryByName (std::string Name);
248 // Deprecated (Not used) --> commented out
249 //gdcmDocEntry *NewManualDocEntryToPubDict(std::string NewTagName,
252 guint32 GenerateFreeTagKeyInGroup(guint16 group);
256 /// Accessor to \ref printLevel
257 void SetPrintLevel(int level) { printLevel = level; };
259 /// Accessor to \ref filename
260 inline std::string GetFileName(void) {return filename;}
262 /// Accessor to \ref filename
263 inline void SetFileName(char* fileName) {filename = fileName;}
265 /// Accessor to \ref gdcmDocument::tagHT
266 inline TagDocEntryHT &GetEntry(void) { return tagHT; };
268 /// Accessor to \ref gdcmDocument::listEntries
269 //inline ListTag &GetListEntry(void) { return listEntries; };
271 /// 'Swap code' accessor (see \ref sw )
272 inline int GetSwapCode(void) { return sw; }
275 inline FILE * GetFP(void) { return fp; }
279 //-----------------------------------------------------------------------------