7 #include "gdcmCommon.h"
9 #include "gdcmException.h"
10 #include "gdcmDictSet.h"
11 #include "gdcmElValue.h"
12 #include "gdcmElValSet.h"
16 typedef map<VRKey, VRAtr> VRHT; // Value Representation Hash Table
18 /// The purpose of an instance of gdcmHeader is to act as a container of
19 /// all the DICOM elements and their corresponding values (and
20 /// additionaly the corresponding DICOM dictionary entry) of the header
23 /// The typical usage of instances of class gdcmHeader is to classify a set of
24 /// dicom files according to header information e.g. to create a file hierarchy
25 /// reflecting the Patient/Study/Serie informations, or extracting a given
26 /// SerieId. Accesing the content (image[s] or volume[s]) is beyond the
27 /// functionality of this class and belongs to gdmcFile.
28 /// \note The various entries of the explicit value representation (VR) shall
29 /// be managed within a dictionary which is shared by all gdcmHeader
31 /// \note The gdcmHeader::Set*Tag* family members cannot be defined as
32 /// protected due to Swig limitations for as Has_a dependency between
33 /// gdcmFile and gdcmHeader.
35 class GDCM_EXPORT gdcmHeader {
36 void SkipBytes(guint32);
38 /// Pointer to the Value Representation Hash Table which contains all
39 /// the VR of the DICOM version3 public dictionary.
40 gdcmVR *dicom_vr; // Not a class member for thread-safety reasons
41 /// Pointer to global dictionary container
42 gdcmDictSet* Dicts; // Not a class member for thread-safety reasons
43 /// Public dictionary used to parse this header
45 /// Optional "shadow dictionary" (private elements) used to parse this
49 /// ELement VALueS parsed with the PUBlic dictionary.
50 gdcmElValSet PubElValSet;
51 /// ELement VALueS parsed with the SHAdow dictionary.
52 gdcmElValSet ShaElValSet;
53 /// Refering underlying filename.
56 // FIXME sw should be an enum e.g.
62 /// Swap code e.g. little, big, bad-big, bad-little endian). Warning:
63 /// this code is not fixed during header parsing.
66 /// Size treshold above which an element value will NOT be loaded in
67 /// memory (to avoid loading the image/volume itself). By default,
68 /// this upper bound is fixed to 1024 bytes (which might look reasonable
69 /// when one considers the definition of the various VR contents).
70 guint32 MaxSizeLoadElementValue;
72 guint16 ReadInt16(void);
73 guint32 ReadInt32(void);
74 guint16 SwapShort(guint16);
75 guint32 SwapLong(guint32);
76 guint32 FindLengthOB(void);
77 void Initialise(void);
79 void SwitchSwapToBigEndian(void);
80 // CLEAN ME: NewManualElValToPubDict is NOT called any more.
81 gdcmElValue* NewManualElValToPubDict(string NewTagName, string VR);
82 void SetMaxSizeLoadElementValue(long);
84 gdcmDictEntry * GetDictEntryByNumber(guint16, guint16);
85 gdcmDictEntry * GetDictEntryByName(string name);
87 // ElValue related utilities
88 gdcmElValue * ReadNextElement(void);
89 gdcmElValue * NewElValueByNumber(guint16 group, guint16 element);
90 gdcmElValue * NewElValueByName(string name);
91 void FindLength(gdcmElValue *);
92 void FindVR(gdcmElValue *);
93 void LoadElementValue(gdcmElValue *);
94 void LoadElementValueSafe(gdcmElValue *);
95 void SkipElementValue(gdcmElValue *);
96 void FixFoundLength(gdcmElValue*, guint32);
97 bool IsAnInteger(gdcmElValue *);
98 void LoadElements(void);
103 bool OpenFile(bool exception_on_error = false)
104 throw(gdcmFileError);
105 bool CloseFile(void);
107 int anonymize(ostream&); // FIXME : anonymize should be a friend ?
109 bool IsReadable(void);
110 bool IsImplicitVRLittleEndianTransferSyntax(void);
111 bool IsExplicitVRLittleEndianTransferSyntax(void);
112 bool IsDeflatedExplicitVRLittleEndianTransferSyntax(void);
113 bool IsExplicitVRBigEndianTransferSyntax(void);
114 bool IsJPEGBaseLineProcess1TransferSyntax(void);
115 bool IsJPEGExtendedProcess2_4TransferSyntax(void);
116 bool IsJPEGExtendedProcess3_5TransferSyntax(void);
117 bool IsJPEGSpectralSelectionProcess6_8TransferSyntax(void);
118 bool IsJPEGLossless(void);
119 bool IsDicomV3(void);
121 virtual void ParseHeader(bool exception_on_error = false)
122 throw(gdcmFormatError);
123 gdcmHeader(const char *filename, bool exception_on_error = false);
124 virtual ~gdcmHeader();
126 size_t GetPixelOffset(void);
127 int GetSwapCode(void) { return sw; }
129 // TODO Swig int SetPubDict(string filename);
130 // When some proprietary shadow groups are disclosed, we can set up
131 // an additional specific dictionary to access extra information.
132 // TODO Swig int SetShaDict(string filename);
134 string GetPubElValByName(string TagName);
135 string GetPubElValByNumber(guint16 group, guint16 element);
136 string GetPubElValRepByName(string TagName);
137 string GetPubElValRepByNumber(guint16 group, guint16 element);
139 TagElValueHT & GetPubElVal(void) { return PubElValSet.GetTagHt(); };
140 void PrintPubElVal(ostream & os = cout);
141 void PrintPubDict (ostream & os = cout);
143 // TODO Swig string* GetShaTagNames();
144 string GetShaElValByName(string TagName);
145 string GetShaElValByNumber(guint16 group, guint16 element);
146 string GetShaElValRepByName(string TagName);
147 string GetShaElValRepByNumber(guint16 group, guint16 element);
149 string GetElValByName(string TagName);
150 string GetElValByNumber(guint16 group, guint16 element);
151 string GetElValRepByName(string TagName);
152 string GetElValRepByNumber(guint16 group, guint16 element);
154 int SetPubElValByName(string content, string TagName);
155 int SetPubElValByNumber(string content, guint16 group, guint16 element);
156 int SetShaElValByName(string content, string ShadowTagName);
157 int SetShaElValByNumber(string content, guint16 group, guint16 element);
159 int SetPubElValLengthByNumber(guint32 lgr, guint16 group, guint16 element);
160 int ReplaceOrCreateByNumber(string Value, guint16 Group, guint16 Elem);
164 string GetPixelType(void);
165 int Write(FILE *, FileType);