2 //-----------------------------------------------------------------------------
6 #include "gdcmCommon.h"
9 #include "gdcmException.h"
10 #include "gdcmDictSet.h"
11 #include "gdcmHeaderEntry.h"
12 #include "gdcmHeaderEntrySet.h"
15 //-----------------------------------------------------------------------------
16 typedef std::string VRKey;
17 typedef std::string VRAtr;
18 typedef std::map<VRKey, VRAtr> VRHT; // Value Representation Hash Table
20 //-----------------------------------------------------------------------------
22 * \defgroup gdcmHedaer
24 * The purpose of an instance of gdcmHeader is to act as a container of
25 * all the DICOM elements and their corresponding values (and
26 * additionaly the corresponding DICOM dictionary entry) of the header
29 * The typical usage of instances of class gdcmHeader is to classify a set of
30 * dicom files according to header information e.g. to create a file hierarchy
31 * reflecting the Patient/Study/Serie informations, or extracting a given
32 * SerieId. Accesing the content (image[s] or volume[s]) is beyond the
33 * functionality of this class and belongs to gdmcFile.
34 * \note The various entries of the explicit value representation (VR) shall
35 * be managed within a dictionary which is shared by all gdcmHeader
37 * \note The gdcmHeader::Set*Tag* family members cannot be defined as
38 * protected due to Swig limitations for as Has_a dependency between
39 * gdcmFile and gdcmHeader.
41 class GDCM_EXPORT gdcmHeader {
43 gdcmHeader(bool exception_on_error = false);
44 gdcmHeader(const char *filename,
45 bool exception_on_error = false,
46 bool enable_sequences = false);
48 virtual ~gdcmHeader();
50 // Standard values and informations contained in the header
51 inline std::string GetFileName(void) {return filename;}
53 bool IsReadable(void);
54 bool IsImplicitVRLittleEndianTransferSyntax(void);
55 bool IsExplicitVRLittleEndianTransferSyntax(void);
56 bool IsDeflatedExplicitVRLittleEndianTransferSyntax(void);
57 bool IsExplicitVRBigEndianTransferSyntax(void);
58 bool IsJPEGBaseLineProcess1TransferSyntax(void);
59 bool IsJPEGExtendedProcess2_4TransferSyntax(void);
60 bool IsJPEGExtendedProcess3_5TransferSyntax(void);
61 bool IsJPEGSpectralSelectionProcess6_8TransferSyntax(void);
62 bool IsRLELossLessTransferSyntax(void);
63 bool IsJPEGLossless(void);
64 bool IsJPEG2000(void);
66 FileType GetFileType(void);
68 // Some heuristic based accessors, end user intended
69 // (to be move to gdcmHeaderHelper?)
73 int GetBitsStored(void);
74 int GetBitsAllocated(void);
75 int GetSamplesPerPixel(void);
76 int GetPlanarConfiguration(void);
78 int GetPixelSize(void);
79 std::string GetPixelType(void);
80 size_t GetPixelOffset(void);
81 size_t GetPixelAreaLength(void);
84 int GetLUTNbits(void);
85 unsigned char * GetLUTRGBA(void);
87 std::string GetTransfertSyntaxName(void);
89 // When some proprietary shadow groups are disclosed, we can set up
90 // an additional specific dictionary to access extra information.
92 // OK : we still have *ONE* HeaderEntrySet,
93 // with both Public and Shadow Elements
94 // parsed against THE Public Dictionary and A (single) Shadow Dictionary
96 // TODO Swig int SetShaDict(std::string filename);
97 // TODO Swig int SetPubDict(std::string filename);
99 // Public element value
100 std::string GetPubEntryByName (std::string tagName);
101 std::string GetPubEntryVRByName (std::string tagName);
102 std::string GetPubEntryByNumber (guint16 group, guint16 element);
103 std::string GetPubEntryVRByNumber(guint16 group, guint16 element);
105 bool SetPubEntryByName (std::string content, std::string tagName);
106 bool SetPubEntryByNumber(std::string content, guint16 group, guint16 element);
107 bool SetPubEntryLengthByNumber(guint32 lgr, guint16 group, guint16 element);
109 inline ListTag & GetPubListEntry(void) { return PubEntrySet.GetListEntry();};
110 inline TagHeaderEntryHT & GetPubEntry(void) { return PubEntrySet.GetTagHT(); };
112 void PrintPubEntry(std::ostream & os = std::cout);
113 void PrintPubDict (std::ostream & os = std::cout);
116 std::string GetEntryByName (std::string tagName);
117 std::string GetEntryVRByName (std::string tagName);
118 std::string GetEntryByNumber (guint16 group, guint16 element);
119 std::string GetEntryVRByNumber(guint16 group, guint16 element);
121 bool SetEntryByName(std::string content,std::string tagName);
122 // bool SetEntryByNumber(std::string content,guint16 group, guint16 element);
124 // inline ListTag & GetListEntry(void) { return PubHeaderEntrySet.GetListElem();};
125 // inline TagHeaderEntryHT & GetListEntry(void) { return PubHeaderEntrySet.GetTagHt(); };
127 // Read (used in gdcmFile)
128 FILE *OpenFile(bool exception_on_error = false) throw(gdcmFileError);
129 bool CloseFile(void);
130 virtual void ParseHeader(bool exception_on_error = false) throw(gdcmFormatError);
132 // Write (used in gdcmFile)
133 bool Write(FILE *, FileType);
134 void SetImageDataSize(size_t ExpectedSize);
136 bool ReplaceOrCreateByNumber(std::string Value, guint16 Group, guint16 Elem);
137 bool ReplaceOrCreateByNumber( char * Value, guint16 Group, guint16 Elem);
138 bool ReplaceIfExistByNumber ( char * Value, guint16 Group, guint16 Elem);
141 inline int GetSwapCode(void) { return sw; }
142 guint16 SwapShort(guint16); // needed by gdcmFile
143 guint32 SwapLong(guint32); // for JPEG Files
146 bool CheckIfExistByNumber(guint16 Group, guint16 Elem );
148 gdcmHeaderEntry *GetHeaderEntryByName (std::string Name);
149 gdcmHeaderEntry *GetHeaderEntryByNumber(guint16 group, guint16 element);
151 int write(std::ostream&);
152 int anonymize(std::ostream&); // FIXME : anonymize should be a friend ?
154 size_t GetPubEntryOffsetByNumber (guint16 Group, guint16 Elem);
155 void * GetPubEntryVoidAreaByNumber(guint16 Group, guint16 Elem);
156 void * LoadEntryVoidArea (guint16 Group, guint16 Element);
161 FileType filetype; // ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown
165 void LoadHeaderEntries (void);
166 void LoadHeaderEntry (gdcmHeaderEntry *);
167 void LoadHeaderEntrySafe (gdcmHeaderEntry *);
168 void FindHeaderEntryLength(gdcmHeaderEntry *);
169 void FindHeaderEntryVR (gdcmHeaderEntry *);
171 void SkipHeaderEntry (gdcmHeaderEntry *);
172 void FixHeaderEntryFoundLength(gdcmHeaderEntry *, guint32);
173 bool IsHeaderEntryAnInteger (gdcmHeaderEntry *);
175 guint32 FindHeaderEntryLengthOB(void);
177 guint16 ReadInt16(void);
178 guint32 ReadInt32(void);
179 void SkipBytes(guint32);
181 void Initialise(void);
182 void CheckSwap(void);
183 void SwitchSwapToBigEndian(void);
184 void SetMaxSizeLoadElementValue(long);
187 gdcmDictEntry *GetDictEntryByName (std::string Name);
188 gdcmDictEntry *GetDictEntryByNumber(guint16, guint16);
190 // HeaderEntry related utilities
191 gdcmHeaderEntry *ReadNextHeaderEntry (void);
192 gdcmHeaderEntry *NewHeaderEntryByNumber(guint16 group, guint16 element);
193 gdcmHeaderEntry *NewHeaderEntryByName (std::string Name);
195 // Deprecated (Not used)
196 gdcmHeaderEntry *NewManualHeaderEntryToPubDict(std::string NewTagName,
200 // Pointer to the Value Representation Hash Table which contains all
201 // the VR of the DICOM version3 public dictionary.
202 gdcmVR *dicom_vr; // Not a class member for thread-safety reasons
204 // Pointer to the Transfert Syntax Hash Table which contains all
205 // the TS of the DICOM version3 public dictionary.
206 gdcmTS *dicom_ts; // Not a class member for thread-safety reasons
208 // Pointer to global dictionary container
209 gdcmDictSet *Dicts; // Not a class member for thread-safety reasons
211 // Public dictionary used to parse this header
212 gdcmDict *RefPubDict;
214 // Optional "shadow dictionary" (private elements) used to parse this
216 gdcmDict *RefShaDict;
218 /// ELement VALueS parsed with the PUBlic dictionary.
219 gdcmHeaderEntrySet PubEntrySet;
221 // Refering underlying filename.
222 std::string filename;
225 int wasUpdated; // true if a gdcmHeaderEntry was added post parsing
227 // FIXME sw should be an enum e.g.
233 // Swap code e.g. little, big, bad-big, bad-little endian). Warning:
234 // this code is not fixed during header parsing.
237 // Size treshold above which an element value will NOT be loaded in
238 // memory (to avoid loading the image/volume itself). By default,
239 // this upper bound is fixed to 1024 bytes (which might look reasonable
240 // when one considers the definition of the various VR contents).
241 guint32 MaxSizeLoadElementValue;
243 static const unsigned int HEADER_LENGTH_TO_READ;
244 static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
247 //-----------------------------------------------------------------------------