2 //-----------------------------------------------------------------------------
6 #include "gdcmCommon.h"
9 #include "gdcmException.h"
10 #include "gdcmDictSet.h"
11 #include "gdcmHeaderEntry.h"
14 #include <list> // for linking together *all* the Dicom Elements
16 //-----------------------------------------------------------------------------
17 typedef std::string VRKey;
18 typedef std::string VRAtr;
19 typedef std::map<VRKey, VRAtr> VRHT; // Value Representation Hash Table
21 typedef std::multimap<TagKey, gdcmHeaderEntry*> TagHeaderEntryHT;
22 typedef std::pair<TagKey, gdcmHeaderEntry*> PairHT;
23 typedef std::pair<TagHeaderEntryHT::iterator,TagHeaderEntryHT::iterator> IterHT;
25 typedef std::list<gdcmHeaderEntry*> ListTag; // for linking together the Elements
27 typedef std::string GroupKey;
28 typedef std::map<GroupKey, int> GroupHT;
30 //-----------------------------------------------------------------------------
32 * \defgroup gdcmHeader
35 class GDCM_EXPORT gdcmParser
38 gdcmParser(bool exception_on_error = false);
39 gdcmParser(const char *filename,
40 bool exception_on_error = false,
41 bool enable_sequences = false);
42 virtual ~gdcmParser(void);
47 * \brief Sets the print level for the Dicom Header
48 * \note 0 for Light Print; 1 for 'medium' Print, 2 for Heavy
50 void SetPrintLevel(int level) { printLevel = level; };
51 virtual void PrintPubEntry(std::ostream &os = std::cout);
52 virtual void PrintPubDict (std::ostream &os = std::cout);
53 virtual void PrintShaDict (std::ostream &os = std::cout);
56 inline std::string GetFileName(void) {return filename;}
59 gdcmDict *GetPubDict(void);
60 gdcmDict *GetShaDict(void);
61 bool SetShaDict(gdcmDict *dict);
62 bool SetShaDict(DictKey dictName);
64 // Informations contained in the parser
65 bool IsReadable(void);
66 bool IsImplicitVRLittleEndianTransferSyntax(void);
67 bool IsExplicitVRLittleEndianTransferSyntax(void);
68 bool IsDeflatedExplicitVRLittleEndianTransferSyntax(void);
69 bool IsExplicitVRBigEndianTransferSyntax(void);
70 FileType GetFileType(void);
75 * \brief returns a ref to the Dicom Header H table (multimap)
76 * return the Dicom Header H table
78 inline TagHeaderEntryHT &GetPubEntry(void) { return tagHT; };
82 * \brief returns a ref to the Dicom Header chained list
83 * return the Dicom Header chained list
85 inline ListTag &GetPubListEntry(void) { return listEntries; };
87 // Read (used in gdcmFile)
88 FILE *OpenFile(bool exception_on_error = false) throw(gdcmFileError);
90 virtual void Parse(bool exception_on_error = false) throw(gdcmFormatError);
92 // Write (used in gdcmFile)
93 virtual bool Write(FILE *, FileType);
95 bool ReplaceOrCreateByNumber(std::string Value, guint16 Group, guint16 Elem);
96 bool ReplaceOrCreateByNumber( char *Value, guint16 Group, guint16 Elem);
97 bool ReplaceIfExistByNumber ( char *Value, guint16 Group, guint16 Elem);
100 inline int GetSwapCode(void) { return sw; }
101 guint16 SwapShort(guint16); // needed by gdcmFile
102 guint32 SwapLong(guint32); // for JPEG Files
106 int CheckIfEntryExistByNumber(guint16 Group, guint16 Elem ); // int !
107 virtual std::string GetEntryByName (std::string tagName);
108 virtual std::string GetEntryVRByName (std::string tagName);
109 virtual std::string GetEntryByNumber (guint16 group, guint16 element);
110 virtual std::string GetEntryVRByNumber(guint16 group, guint16 element);
112 virtual bool SetEntryByName (std::string content, std::string tagName);
113 virtual bool SetEntryByNumber(std::string content, guint16 group, guint16 element);
114 virtual bool SetEntryLengthByNumber(guint32 l, guint16 group, guint16 element);
116 virtual size_t GetEntryOffsetByNumber (guint16 Group, guint16 Elem);
117 virtual void *GetEntryVoidAreaByNumber(guint16 Group, guint16 Elem);
118 virtual void *LoadEntryVoidArea (guint16 Group, guint16 Element);
119 virtual bool SetEntryVoidAreaByNumber(void *a, guint16 Group, guint16 Elem);
122 gdcmHeaderEntry *GetHeaderEntryByName (std::string Name);
123 gdcmHeaderEntry *GetHeaderEntryByNumber(guint16 group, guint16 element);
125 void LoadHeaderEntrySafe (gdcmHeaderEntry *);
127 void UpdateGroupLength(bool SkipSequence = false, FileType type = ImplicitVR);
128 void WriteEntries(FileType type, FILE *);
132 FileType filetype; // ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown
134 static const unsigned int HEADER_LENGTH_TO_READ;
135 static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
139 void LoadHeaderEntries (void);
140 void LoadHeaderEntry (gdcmHeaderEntry *);
141 void AddHeaderEntry (gdcmHeaderEntry *);
142 void FindHeaderEntryLength(gdcmHeaderEntry *);
143 void FindHeaderEntryVR (gdcmHeaderEntry *);
145 void SkipHeaderEntry (gdcmHeaderEntry *);
146 void FixHeaderEntryFoundLength(gdcmHeaderEntry *, guint32);
147 bool IsHeaderEntryAnInteger (gdcmHeaderEntry *);
149 guint32 FindHeaderEntryLengthOB(void);
151 guint16 ReadInt16(void);
152 guint32 ReadInt32(void);
153 void SkipBytes(guint32);
155 void Initialise(void);
156 void CheckSwap(void);
157 void SwitchSwapToBigEndian(void);
158 void SetMaxSizeLoadEntry(long);
161 gdcmDictEntry *GetDictEntryByName (std::string Name);
162 gdcmDictEntry *GetDictEntryByNumber(guint16, guint16);
164 // HeaderEntry related utilities
165 gdcmHeaderEntry *ReadNextHeaderEntry (void);
166 gdcmHeaderEntry *NewHeaderEntryByNumber(guint16 group, guint16 element);
167 gdcmHeaderEntry *NewHeaderEntryByName (std::string Name);
168 gdcmDictEntry *NewVirtualDictEntry(guint16 group, guint16 element,
169 std::string vr = "Unknown",
170 std::string fourth = "Unknown",
171 std::string name = "Unknown");
173 // Deprecated (Not used)
174 gdcmHeaderEntry *NewManualHeaderEntryToPubDict(std::string NewTagName,
176 guint32 GenerateFreeTagKeyInGroup(guint16 group);
178 // Refering underlying filename.
179 std::string filename;
181 // Public dictionary used to parse this header
182 gdcmDict *RefPubDict;
183 // Optional "shadow dictionary" (private elements) used to parse this header
184 gdcmDict *RefShaDict;
186 TagHeaderEntryHT tagHT; // H Table (multimap), to provide fast access
187 ListTag listEntries; // chained list, to keep the 'spacial' ordering
190 // true if a gdcmHeaderEntry was added post parsing
193 // Swap code e.g. little, big, bad-big, bad-little endian). Warning:
194 // this code is not fixed during header parsing.
197 // Size treshold above which an element value will NOT be loaded in
198 // memory (to avoid loading the image/volume itself). By default,
199 // this upper bound is fixed to 1024 bytes (which might look reasonable
200 // when one considers the definition of the various VR contents).
201 guint32 MaxSizeLoadEntry;
207 //-----------------------------------------------------------------------------