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);
55 // Standard values and informations contained in the header
56 inline std::string GetFileName(void) {return filename;}
58 bool IsReadable(void);
59 bool IsImplicitVRLittleEndianTransferSyntax(void);
60 bool IsExplicitVRLittleEndianTransferSyntax(void);
61 bool IsDeflatedExplicitVRLittleEndianTransferSyntax(void);
62 bool IsExplicitVRBigEndianTransferSyntax(void);
63 FileType GetFileType(void);
68 * \brief returns a ref to the Dicom Header H table (multimap)
69 * return the Dicom Header H table
71 inline TagHeaderEntryHT &GetPubEntry(void) { return tagHT; };
75 * \brief returns a ref to the Dicom Header chained list
76 * return the Dicom Header chained list
78 inline ListTag &GetPubListEntry(void) { return listEntries; };
80 // Read (used in gdcmFile)
81 FILE *OpenFile(bool exception_on_error = false) throw(gdcmFileError);
83 virtual void Parse(bool exception_on_error = false) throw(gdcmFormatError);
85 // Write (used in gdcmFile)
86 virtual bool Write(FILE *, FileType);
88 bool ReplaceOrCreateByNumber(std::string Value, guint16 Group, guint16 Elem);
89 bool ReplaceOrCreateByNumber( char *Value, guint16 Group, guint16 Elem);
90 bool ReplaceIfExistByNumber ( char *Value, guint16 Group, guint16 Elem);
93 inline int GetSwapCode(void) { return sw; }
94 guint16 SwapShort(guint16); // needed by gdcmFile
95 guint32 SwapLong(guint32); // for JPEG Files
99 int CheckIfEntryExistByNumber(guint16 Group, guint16 Elem ); // int !
100 virtual std::string GetEntryByName (std::string tagName);
101 virtual std::string GetEntryVRByName (std::string tagName);
102 virtual std::string GetEntryByNumber (guint16 group, guint16 element);
103 virtual std::string GetEntryVRByNumber(guint16 group, guint16 element);
105 virtual bool SetEntryByName (std::string content, std::string tagName);
106 virtual bool SetEntryByNumber(std::string content, guint16 group, guint16 element);
107 virtual bool SetEntryLengthByNumber(guint32 l, guint16 group, guint16 element);
109 virtual size_t GetEntryOffsetByNumber (guint16 Group, guint16 Elem);
110 virtual void *GetEntryVoidAreaByNumber(guint16 Group, guint16 Elem);
111 virtual void *LoadEntryVoidArea (guint16 Group, guint16 Element);
112 virtual bool SetEntryVoidAreaByNumber(void *a, guint16 Group, guint16 Elem);
115 gdcmHeaderEntry *GetHeaderEntryByName (std::string Name);
116 gdcmHeaderEntry *GetHeaderEntryByNumber(guint16 group, guint16 element);
118 void LoadHeaderEntrySafe (gdcmHeaderEntry *);
120 void UpdateGroupLength(bool SkipSequence = false, FileType type = ImplicitVR);
121 void WriteEntries(FileType type, FILE *);
125 FileType filetype; // ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown
127 static const unsigned int HEADER_LENGTH_TO_READ;
128 static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
132 void LoadHeaderEntries (void);
133 void LoadHeaderEntry (gdcmHeaderEntry *);
134 void AddHeaderEntry (gdcmHeaderEntry *);
135 void FindHeaderEntryLength(gdcmHeaderEntry *);
136 void FindHeaderEntryVR (gdcmHeaderEntry *);
138 void SkipHeaderEntry (gdcmHeaderEntry *);
139 void FixHeaderEntryFoundLength(gdcmHeaderEntry *, guint32);
140 bool IsHeaderEntryAnInteger (gdcmHeaderEntry *);
142 guint32 FindHeaderEntryLengthOB(void);
144 guint16 ReadInt16(void);
145 guint32 ReadInt32(void);
146 void SkipBytes(guint32);
148 void Initialise(void);
149 void CheckSwap(void);
150 void SwitchSwapToBigEndian(void);
151 void SetMaxSizeLoadEntry(long);
154 gdcmDictEntry *GetDictEntryByName (std::string Name);
155 gdcmDictEntry *GetDictEntryByNumber(guint16, guint16);
157 // HeaderEntry related utilities
158 gdcmHeaderEntry *ReadNextHeaderEntry (void);
159 gdcmHeaderEntry *NewHeaderEntryByNumber(guint16 group, guint16 element);
160 gdcmHeaderEntry *NewHeaderEntryByName (std::string Name);
162 // Deprecated (Not used)
163 gdcmHeaderEntry *NewManualHeaderEntryToPubDict(std::string NewTagName,
165 guint32 GenerateFreeTagKeyInGroup(guint16 group);
167 // Refering underlying filename.
168 std::string filename;
170 // Pointer to the Value Representation Hash Table which contains all
171 // the VR of the DICOM version3 public dictionary.
172 gdcmVR *dicom_vr; // Not a class member for thread-safety reasons
174 // Pointer to the Transfert Syntax Hash Table which contains all
175 // the TS of the DICOM version3 public dictionary.
176 gdcmTS *dicom_ts; // Not a class member for thread-safety reasons
178 // Pointer to global dictionary container
179 gdcmDictSet *Dicts; // Not a class member for thread-safety reasons
181 // Public dictionary used to parse this header
182 gdcmDict *RefPubDict;
184 // Optional "shadow dictionary" (private elements) used to parse this
186 gdcmDict *RefShaDict;
188 TagHeaderEntryHT tagHT; // H Table (multimap), to provide fast access
189 ListTag listEntries; // chained list, to keep the 'spacial' ordering
191 // true if a gdcmHeaderEntry was added post parsing
198 // Swap code e.g. little, big, bad-big, bad-little endian). Warning:
199 // this code is not fixed during header parsing.
202 // Size treshold above which an element value will NOT be loaded in
203 // memory (to avoid loading the image/volume itself). By default,
204 // this upper bound is fixed to 1024 bytes (which might look reasonable
205 // when one considers the definition of the various VR contents).
206 guint32 MaxSizeLoadEntry;
209 //-----------------------------------------------------------------------------