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 * The purpose of an instance of gdcmHeader is to act as a container of
23 * all the DICOM elements and their corresponding values (and
24 * additionaly the corresponding DICOM dictionary entry) of the header
27 * The typical usage of instances of class gdcmHeader is to classify a set of
28 * dicom files according to header information e.g. to create a file hierarchy
29 * reflecting the Patient/Study/Serie informations, or extracting a given
30 * SerieId. Accesing the content (image[s] or volume[s]) is beyond the
31 * functionality of this class and belongs to gdmcFile.
32 * \note The various entries of the explicit value representation (VR) shall
33 * be managed within a dictionary which is shared by all gdcmHeader
35 * \note The gdcmHeader::Set*Tag* family members cannot be defined as
36 * protected due to Swig limitations for as Has_a dependency between
37 * gdcmFile and gdcmHeader.
39 class GDCM_EXPORT gdcmHeader {
41 gdcmHeader(bool exception_on_error = false);
42 gdcmHeader(const char *filename,
43 bool exception_on_error = false,
44 bool enable_sequences = false);
46 virtual ~gdcmHeader();
48 // Standard values and informations contained in the header
49 inline std::string GetFileName(void) {return filename;}
51 bool IsReadable(void);
52 bool IsImplicitVRLittleEndianTransferSyntax(void);
53 bool IsExplicitVRLittleEndianTransferSyntax(void);
54 bool IsDeflatedExplicitVRLittleEndianTransferSyntax(void);
55 bool IsExplicitVRBigEndianTransferSyntax(void);
56 bool IsJPEGBaseLineProcess1TransferSyntax(void);
57 bool IsJPEGExtendedProcess2_4TransferSyntax(void);
58 bool IsJPEGExtendedProcess3_5TransferSyntax(void);
59 bool IsJPEGSpectralSelectionProcess6_8TransferSyntax(void);
60 bool IsRLELossLessTransferSyntax(void);
61 bool IsJPEGLossless(void);
62 bool IsJPEG2000(void);
64 FileType GetFileType(void);
66 // Some heuristic based accessors, end user intended
67 // (to be move to gdcmHeaderHelper?)
71 int GetBitsStored(void);
72 int GetBitsAllocated(void);
73 int GetSamplesPerPixel(void);
74 int GetPlanarConfiguration(void);
76 int GetPixelSize(void);
77 std::string GetPixelType(void);
78 size_t GetPixelOffset(void);
79 size_t GetPixelAreaLength(void);
82 int GetLUTNbits(void);
83 unsigned char * GetLUTRGBA(void);
85 std::string GetTransfertSyntaxName(void);
87 // When some proprietary shadow groups are disclosed, we can set up
88 // an additional specific dictionary to access extra information.
90 // OK : we still have *ONE* HeaderEntrySet,
91 // with both Public and Shadow Elements
92 // parsed against THE Public Dictionary and A (single) Shadow Dictionary
94 // TODO Swig int SetShaDict(std::string filename);
95 // TODO Swig int SetPubDict(std::string filename);
97 // Public element value
98 std::string GetPubEntryByName (std::string tagName);
99 std::string GetPubEntryVRByName (std::string tagName);
100 std::string GetPubEntryByNumber (guint16 group, guint16 element);
101 std::string GetPubEntryVRByNumber(guint16 group, guint16 element);
103 bool SetPubEntryByName (std::string content, std::string tagName);
104 bool SetPubEntryByNumber(std::string content, guint16 group, guint16 element);
105 bool SetPubEntryLengthByNumber(guint32 lgr, guint16 group, guint16 element);
107 inline ListTag & GetPubListEntry(void) { return PubEntrySet.GetListEntry();};
108 inline TagHeaderEntryHT & GetPubEntry(void) { return PubEntrySet.GetTagHT(); };
110 void PrintPubEntry(std::ostream & os = std::cout);
111 void PrintPubDict (std::ostream & os = std::cout);
114 std::string GetEntryByName (std::string tagName);
115 std::string GetEntryVRByName (std::string tagName);
116 std::string GetEntryByNumber (guint16 group, guint16 element);
117 std::string GetEntryVRByNumber(guint16 group, guint16 element);
119 bool SetEntryByName(std::string content,std::string tagName);
120 // bool SetEntryByNumber(std::string content,guint16 group, guint16 element);
122 // inline ListTag & GetListElem(void) { return PubHeaderEntrySet.GetListElem();};
123 // inline TagHeaderEntryHT & GetElVal(void) { return PubHeaderEntrySet.GetTagHt(); };
125 // Read (used in gdcmFile)
126 FILE *OpenFile(bool exception_on_error = false) throw(gdcmFileError);
127 bool CloseFile(void);
128 virtual void ParseHeader(bool exception_on_error = false) throw(gdcmFormatError);
130 // Write (used in gdcmFile)
131 bool Write(FILE *, FileType);
132 void SetImageDataSize(size_t ExpectedSize);
134 bool ReplaceOrCreateByNumber(std::string Value, guint16 Group, guint16 Elem);
135 bool ReplaceOrCreateByNumber( char * Value, guint16 Group, guint16 Elem);
136 bool ReplaceIfExistByNumber ( char * Value, guint16 Group, guint16 Elem);
139 inline int GetSwapCode(void) { return sw; }
140 guint16 SwapShort(guint16); // needed by gdcmFile
141 guint32 SwapLong(guint32); // for JPEG Files
144 bool CheckIfExistByNumber(guint16 Group, guint16 Elem );
146 gdcmHeaderEntry *GetHeaderEntryByName (std::string Name);
147 gdcmHeaderEntry *GetHeaderEntryByNumber(guint16 group, guint16 element);
149 int write(std::ostream&);
150 int anonymize(std::ostream&); // FIXME : anonymize should be a friend ?
152 size_t GetPubEntryOffsetByNumber (guint16 Group, guint16 Elem);
153 void * GetPubEntryVoidAreaByNumber(guint16 Group, guint16 Elem);
154 void * LoadEntryVoidArea (guint16 Group, guint16 Element);
159 FileType filetype; // ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown
163 void LoadHeaderEntries (void);
164 void LoadHeaderEntry (gdcmHeaderEntry *);
165 void LoadHeaderEntrySafe (gdcmHeaderEntry *);
166 void FindHeaderEntryLength(gdcmHeaderEntry *);
167 void FindHeaderEntryVR (gdcmHeaderEntry *);
169 void SkipHeaderEntry (gdcmHeaderEntry *);
170 void FixHeaderEntryFoundLength(gdcmHeaderEntry *, guint32);
171 bool IsHeaderEntryAnInteger (gdcmHeaderEntry *);
173 guint32 FindHeaderEntryLengthOB(void);
175 guint16 ReadInt16(void);
176 guint32 ReadInt32(void);
177 void SkipBytes(guint32);
179 void Initialise(void);
180 void CheckSwap(void);
181 void SwitchSwapToBigEndian(void);
182 void SetMaxSizeLoadElementValue(long);
185 gdcmDictEntry *GetDictEntryByName (std::string Name);
186 gdcmDictEntry *GetDictEntryByNumber(guint16, guint16);
188 // HeaderEntry related utilities
189 gdcmHeaderEntry *ReadNextHeaderEntry (void);
190 gdcmHeaderEntry *NewHeaderEntryByNumber(guint16 group, guint16 element);
191 gdcmHeaderEntry *NewHeaderEntryByName (std::string Name);
193 // Deprecated (Not used)
194 gdcmHeaderEntry *NewManualHeaderEntryToPubDict(std::string NewTagName,
198 // Pointer to the Value Representation Hash Table which contains all
199 // the VR of the DICOM version3 public dictionary.
200 gdcmVR *dicom_vr; // Not a class member for thread-safety reasons
202 // Pointer to the Transfert Syntax Hash Table which contains all
203 // the TS of the DICOM version3 public dictionary.
204 gdcmTS *dicom_ts; // Not a class member for thread-safety reasons
206 // Pointer to global dictionary container
207 gdcmDictSet *Dicts; // Not a class member for thread-safety reasons
209 // Public dictionary used to parse this header
210 gdcmDict *RefPubDict;
212 // Optional "shadow dictionary" (private elements) used to parse this
214 gdcmDict *RefShaDict;
216 /// ELement VALueS parsed with the PUBlic dictionary.
217 gdcmHeaderEntrySet PubEntrySet;
219 // Refering underlying filename.
220 std::string filename;
224 // FIXME sw should be an enum e.g.
230 // Swap code e.g. little, big, bad-big, bad-little endian). Warning:
231 // this code is not fixed during header parsing.
234 // Size treshold above which an element value will NOT be loaded in
235 // memory (to avoid loading the image/volume itself). By default,
236 // this upper bound is fixed to 1024 bytes (which might look reasonable
237 // when one considers the definition of the various VR contents).
238 guint32 MaxSizeLoadElementValue;
240 static const unsigned int HEADER_LENGTH_TO_READ;
241 static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
244 //-----------------------------------------------------------------------------