7 #include "gdcmCommon.h"
8 #include "gdcmException.h"
9 #include "gdcmDictSet.h"
10 #include "gdcmElValue.h"
11 #include "gdcmElValSet.h"
13 ////////////////////////////////////////////////////////////////////////////
14 // The purpous of an instance of gdcmHeader is to act as a container of
15 // all the elements and their corresponding values (and additionaly the
16 // corresponding DICOM dictionary entry) of the header of a DICOM file.
18 // The typical usage of instances of class gdcmHeader is to classify a set of
19 // dicom files according to header information e.g. to create a file hierarchy
20 // reflecting the Patient/Study/Serie informations, or extracting a given
21 // SerieId. Accesing the content (image[s] or volume[s]) is beyond the
22 // functionality of this class and belong to gdmcFile (see below).
24 // * the various entries of the explicit value representation (VR) shall
25 // be managed within a dictionary which is shared by all gdcmHeader instances
26 // * the gdcmHeader::Set*Tag* family members cannot be defined as protected
27 // (Swig limitations for as Has_a dependency between gdcmFile and gdcmHeader)
31 typedef map<VRKey, VRAtr> VRHT; // Value Representation Hash Table
33 class GDCM_EXPORT gdcmHeader {
34 void SkipBytes(guint32);
36 static VRHT *dicom_vr;
37 // Dictionaries of data elements:
39 gdcmDictSet* Dicts; // global dictionary container
40 gdcmDict* RefPubDict; // public dictionary
41 gdcmDict* RefShaDict; // shadow dictionary (optional)
42 // Parsed element values:
43 ElValSet PubElVals; // parsed with Public Dictionary
44 ElValSet ShaElVals; // parsed with Shadow Dictionary
45 string filename; // refering underlying file
49 // Ne faudrait-il pas une indication sur la presence ou non
50 // du 'groupe des pixels' dans l'entete?
51 // (voir pb du DICOMDIR)
53 // Swap code (little, big, bad-big, bad-little endian): this code is not fixed
54 // during parsing.FIXME sw should be an enum e.g.
62 // Only the elements whose size is below this bound will be loaded.
63 // By default, this upper bound is limited to 1024 (which looks reasonable
64 // when one considers the definition of the various VR contents).
65 guint32 MaxSizeLoadElementValue;
67 guint16 ReadInt16(void);
68 guint32 ReadInt32(void);
69 guint16 SwapShort(guint16);
70 guint32 SwapLong(guint32);
71 guint32 FindLengthOB(void);
72 void Initialise(void);
74 void InitVRDict(void);
75 void SwitchSwapToBigEndian(void);
76 void AddAndDefaultElements(void);
77 void SetMaxSizeLoadElementValue(long);
79 gdcmDictEntry * GetDictEntryByKey(guint16, guint16);
80 gdcmDictEntry * GetDictEntryByName(string name);
82 // ElValue related utilities
83 ElValue * ReadNextElement(void);
84 ElValue * NewElValueByKey(guint16 group, guint16 element);
85 ElValue * NewElValueByName(string name);
86 void FindLength(ElValue *);
87 void FindVR(ElValue *);
88 void LoadElementValue(ElValue *);
89 void LoadElementValueSafe(ElValue *);
90 void SkipElementValue(ElValue *);
91 void FixFoundLength(ElValue*, guint32);
92 bool IsAnInteger(ElValue *);
94 bool IsImplicitVRLittleEndianTransferSyntax(void);
95 bool IsExplicitVRLittleEndianTransferSyntax(void);
96 bool IsDeflatedExplicitVRLittleEndianTransferSyntax(void);
97 bool IsExplicitVRBigEndianTransferSyntax(void);
98 bool IsJPEGBaseLineProcess1TransferSyntax(void);
99 bool IsJPEGExtendedProcess2_4TransferSyntax(void);
100 bool IsJPEGExtendedProcess3_5TransferSyntax(void);
101 bool IsJPEGSpectralSelectionProcess6_8TransferSyntax(void);
110 ACR_LIBIDO}; // CLEANME
113 int anonymize(ostream&); // FIXME : anonymize should be a friend ?
115 void LoadElements(void);
116 virtual void ParseHeader(bool exception_on_error = false)
117 throw(gdcmFormatError);
118 gdcmHeader(const char *filename, bool exception_on_error = false)
119 throw(gdcmFileError);
120 virtual ~gdcmHeader();
122 size_t GetPixelOffset(void);
123 void GetPixels(size_t, void *);
124 int GetSwapCode(void) { return sw; }
126 // TODO Swig int SetPubDict(string filename);
127 // When some proprietary shadow groups are disclosed, we can set up
128 // an additional specific dictionary to access extra information.
129 // TODO Swig int SetShaDict(string filename);
131 // Get the element values themselves:
132 string GetPubElValByName(string TagName);
133 string GetPubElValByNumber(guint16 group, guint16 element);
135 // Getting the element value representation (VR) might be needed by caller
136 // to convert the string typed content to caller's native type
137 // (think of C/C++ vs Python).
139 string GetPubElValRepByName(string TagName);
140 string GetPubElValRepByNumber(guint16 group, guint16 element);
142 TagElValueHT & GetPubElVal(void) { return PubElVals.GetTagHt(); };
143 void PrintPubElVal(ostream & os = cout);
144 void PrintPubDict(ostream & os = cout);
146 // Same thing with the shadow :
147 // TODO Swig string* GetShaTagNames();
148 string GetShaElValByName(string TagName);
149 string GetShaElValByNumber(guint16 group, guint16 element);
150 string GetShaElValRepByName(string TagName);
151 string GetShaElValRepByNumber(guint16 group, guint16 element);
153 // Wrappers of the above (public is privileged over shadow) to avoid
154 // bugging the caller with knowing if ElVal is from the public or shadow
156 string GetElValByName(string TagName);
157 string GetElValByNumber(guint16 group, guint16 element);
158 string GetElValRepByName(string TagName);
159 string GetElValRepByNumber(guint16 group, guint16 element);
161 int SetPubElValByName(string content, string TagName);
162 int SetPubElValByNumber(string content, guint16 group, guint16 element);
163 int SetShaElValByName(string content, string ShadowTagName);
164 int SetShaElValByNumber(string content, guint16 group, guint16 element);
166 ElValSet GetPubElVals() { return(PubElVals); }