2 //-----------------------------------------------------------------------------
6 #include "gdcmCommon.h"
10 #include "gdcmException.h"
11 #include "gdcmDictSet.h"
12 #include "gdcmDocEntry.h"
13 #include "gdcmDocEntrySet.h"
14 #include "gdcmElementSet.h"
21 //-----------------------------------------------------------------------------
22 typedef std::string VRKey;
23 typedef std::string VRAtr;
24 typedef std::map<VRKey, VRAtr> VRHT; // Value Representation Hash Table
26 typedef std::map<TagKey, gdcmDocEntry *> TagDocEntryHT;
27 typedef std::pair<TagKey, gdcmDocEntry *> PairHT;
28 typedef std::pair<TagDocEntryHT::iterator,TagDocEntryHT::iterator> IterHT;
29 /// for linking together the Elements
30 typedef std::list<gdcmDocEntry *> ListTag;
32 typedef std::string GroupKey;
33 typedef std::map<GroupKey, int> GroupHT;
35 //-----------------------------------------------------------------------------
37 * \brief used by both gdcmHeader and gdcmDicomDir
39 class GDCM_EXPORT gdcmDocument : public gdcmElementSet
42 /// Public dictionary used to parse this header
45 /// \brief Optional "shadow dictionary" (private elements) used to parse
49 /// \brief Equals =1 if user wants to skip shadow groups while parsing
53 /// \brief Size threshold above which an element value will NOT be loaded
54 /// in memory (to avoid loading the image/volume itself). By default,
55 /// this upper bound is fixed to 1024 bytes (which might look reasonable
56 /// when one considers the definition of the various VR contents).
57 guint32 MaxSizeLoadEntry;
59 /// \brief Size threshold above which an element value will NOT be *printed*
60 /// in order no to polute the screen output. By default, this upper bound
61 /// is fixed to 64 bytes.
62 guint32 MaxSizePrintEntry;
67 /// Refering underlying filename.
70 /// \brief SWap code (e.g. Big Endian, Little Endian, Bad Big Endian,
71 /// Bad Little Endian) according to the processor Endianity and
72 /// what is written on disc.
75 /// File Pointer, opened during Header parsing.
78 /// ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown
81 /// After opening the file, we read HEADER_LENGTH_TO_READ bytes.
82 static const unsigned int HEADER_LENGTH_TO_READ;
84 /// \brief Elements whose value is longer than MAX_SIZE_LOAD_ELEMENT_VALUE
86 static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
88 /// \brief Elements whose value is longer than MAX_SIZE_PRINT_ELEMENT_VALUE
90 /// \todo Currently not used since collides with #define in
91 /// \ref gdcmDocEntry.cxx. See also
92 /// \ref gdcmDocument::SetMaxSizePrintEntry()
93 static const unsigned int MAX_SIZE_PRINT_ELEMENT_VALUE;
95 /// Hash Table (multimap), to provide fast access
98 /// Chained list, to keep the 'spacial' ordering
101 /// Will be set 1 if user asks to 'go inside' the 'sequences' (VR = "SQ")
104 /// \brief Amount of printed details for each Header Entry (Dicom Element):
105 /// 0 : stands for the least detail level.
112 // Canonical Printing method (see also gdcmDocument::SetPrintLevel)
113 // virtual void Print (std::ostream &os = std::cout);
114 // {PrintEntry(os);};
116 // no more Print method for gdcmDocument (inherits from gdcmElementSet
117 // virtual void PrintEntry (std::ostream &os = std::cout)
118 // { return Print(os);};
120 // the 2 following will be merged
121 virtual void PrintPubDict (std::ostream &os = std::cout);
122 virtual void PrintShaDict (std::ostream &os = std::cout);
125 gdcmDict *GetPubDict(void);
126 gdcmDict *GetShaDict(void);
127 bool SetShaDict(gdcmDict *dict);
128 bool SetShaDict(DictKey dictName);
130 // Informations contained in the parser
131 virtual bool IsReadable(void);
132 bool IsImplicitVRLittleEndianTransferSyntax(void);
133 bool IsExplicitVRLittleEndianTransferSyntax(void);
134 bool IsDeflatedExplicitVRLittleEndianTransferSyntax(void);
135 bool IsExplicitVRBigEndianTransferSyntax(void);
136 FileType GetFileType(void);
138 // Read (used in gdcmFile, gdcmDicomDir)
139 FILE *OpenFile(bool exception_on_error = false) throw(gdcmFileError);
140 bool CloseFile(void);
142 // Write (used in gdcmFile, gdcmDicomDir)
143 virtual bool Write(FILE *, FileType);
144 virtual void WriteEntryTagVRLength(gdcmDocEntry *tag,
145 FILE *_fp, FileType type);
146 virtual void WriteEntryValue(gdcmDocEntry *tag,FILE *_fp,FileType type);
147 virtual bool WriteEntry(gdcmDocEntry *tag,FILE *_fp,FileType type);
148 virtual bool WriteEntries(FILE *_fp,FileType type);
149 void WriteEntriesDeprecated(FILE *_fp,FileType type); // JPR
151 gdcmDocEntry * ReplaceOrCreateByNumber(std::string Value,
152 guint16 Group, guint16 Elem);
153 bool ReplaceIfExistByNumber (char *Value, guint16 Group, guint16 Elem);
155 virtual void *LoadEntryVoidArea (guint16 Group, guint16 Element);
156 void LoadVLEntry (gdcmDocEntry *entry);
159 guint16 SwapShort(guint16); // needed by gdcmFile
160 guint32 SwapLong(guint32); // needed by gdcmFile
161 guint16 UnswapShort(guint16); // needed by gdcmFile
162 guint32 UnswapLong(guint32); // needed by gdcmFile
165 // Constructor and destructor are protected to forbid end user
166 // to instanciate from this class gdcmDocument (only gdcmHeader and
167 // gdcmDicomDir are meaningfull).
168 gdcmDocument(bool exception_on_error = false);
169 gdcmDocument(const char *inFilename,
170 bool exception_on_error = false,
171 bool enable_sequences = false,
172 bool ignore_shadow = false);
173 virtual ~gdcmDocument(void);
175 int CheckIfEntryExistByNumber(guint16 Group, guint16 Elem ); // int !
176 virtual std::string GetEntryByName (std::string tagName);
177 virtual std::string GetEntryVRByName (std::string tagName);
178 virtual std::string GetEntryByNumber (guint16 group, guint16 element);
179 virtual std::string GetEntryVRByNumber(guint16 group, guint16 element);
180 virtual int GetEntryLengthByNumber(guint16 group, guint16 element);
182 virtual bool SetEntryByName (std::string content, std::string tagName);
183 virtual bool SetEntryByNumber(std::string content,
184 guint16 group, guint16 element);
185 virtual bool SetEntryLengthByNumber(guint32 length,
186 guint16 group, guint16 element);
188 virtual size_t GetEntryOffsetByNumber (guint16 Group, guint16 Elem);
189 virtual void *GetEntryVoidAreaByNumber(guint16 Group, guint16 Elem);
190 virtual bool SetEntryVoidAreaByNumber(void *a, guint16 Group, guint16 Elem);
192 virtual void UpdateShaEntries(void);
195 gdcmDocEntry *GetDocEntryByNumber (guint16 group, guint16 element);
196 gdcmDocEntry *GetDocEntryByName (std::string Name);
197 IterHT GetDocEntrySameNumber(guint16 group, guint16 element);
198 // IterHT GetDocEntrySameName (std::string Name);
200 void LoadDocEntrySafe(gdcmDocEntry *);
203 //void UpdateGroupLength(bool SkipSequence = false,
204 // FileType type = ImplicitVR);
206 //void AddDocEntry (gdcmDocEntry *);
211 //bool LoadHeaderEntries(bool exception_on_error = false) throw(gdcmFormatError);
212 // remplacé par ParseDES.
213 // What about exception_on_error ?
215 long ParseDES(gdcmDocEntrySet *set, long offset, long l_max, bool delim_mode);
216 long ParseSQ(gdcmDocEntrySet *set, long offset, long l_max, bool delim_mode);
219 void LoadDocEntry (gdcmDocEntry *);
220 void FindDocEntryLength(gdcmDocEntry *);
221 void FindDocEntryVR (gdcmDocEntry *);
222 bool CheckDocEntryVR (gdcmDocEntry *, VRKey);
224 std::string GetDocEntryValue (gdcmDocEntry *);
225 std::string GetDocEntryUnvalue(gdcmDocEntry *);
227 void SkipDocEntry (gdcmDocEntry *);
228 void SkipToNextDocEntry (gdcmDocEntry *);
230 void FixDocEntryFoundLength(gdcmDocEntry *, guint32);
231 bool IsDocEntryAnInteger (gdcmDocEntry *);
233 guint32 FindDocEntryLengthOB(void);
235 guint16 ReadInt16(void);
236 guint32 ReadInt32(void);
237 void SkipBytes(guint32);
239 void Initialise(void);
240 bool CheckSwap(void);
241 void SwitchSwapToBigEndian(void);
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 //gdcmDictEntry *NewVirtualDictEntry(gdcmDocEntry *); // never defined
256 // DocEntry related utilities
258 gdcmDocEntry *ReadNextDocEntry (void);
259 gdcmDocEntry *NewDocEntryByNumber(guint16 group,
261 gdcmDocEntry *NewDocEntryByName (std::string Name);
263 // Deprecated (Not used) --> commented out
264 //gdcmDocEntry *NewManualDocEntryToPubDict(std::string NewTagName,
267 guint32 GenerateFreeTagKeyInGroup(guint16 group);
271 /// Accessor to \ref printLevel
272 void SetPrintLevel(int level) { printLevel = level; };
274 /// Accessor to \ref filename
275 inline std::string GetFileName(void) {return filename;}
277 /// Accessor to \ref filename
278 inline void SetFileName(char* fileName) {filename = fileName;}
280 /// Accessor to \ref gdcmDocument::tagHT
281 inline TagDocEntryHT &GetEntry(void) { return tagHT; };
283 /// Accessor to \ref gdcmDocument::listEntries
284 inline ListTag &GetListEntry(void) { return listEntries; };
286 /// 'Swap code' accessor (see \ref sw )
287 inline int GetSwapCode(void) { return sw; }
290 inline FILE * GetFP(void) { return fp; }
294 //-----------------------------------------------------------------------------