1 // $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.h,v 1.47 2004/01/13 11:32:30 jpr Exp $
6 #include "gdcmCommon.h"
9 #include "gdcmException.h"
10 #include "gdcmDictSet.h"
11 #include "gdcmElValue.h"
12 #include "gdcmElValSet.h"
15 typedef std::string VRKey;
16 typedef std::string VRAtr;
17 typedef std::map<VRKey, VRAtr> VRHT; // Value Representation Hash Table
20 * The purpose of an instance of gdcmHeader is to act as a container of
21 * all the DICOM elements and their corresponding values (and
22 * additionaly the corresponding DICOM dictionary entry) of the header
25 * The typical usage of instances of class gdcmHeader is to classify a set of
26 * dicom files according to header information e.g. to create a file hierarchy
27 * reflecting the Patient/Study/Serie informations, or extracting a given
28 * SerieId. Accesing the content (image[s] or volume[s]) is beyond the
29 * functionality of this class and belongs to gdmcFile.
30 * \note The various entries of the explicit value representation (VR) shall
31 * be managed within a dictionary which is shared by all gdcmHeader
33 * \note The gdcmHeader::Set*Tag* family members cannot be defined as
34 * protected due to Swig limitations for as Has_a dependency between
35 * gdcmFile and gdcmHeader.
37 class GDCM_EXPORT gdcmHeader {
39 /// Pointer to the Value Representation Hash Table which contains all
40 /// the VR of the DICOM version3 public dictionary.
41 gdcmVR *dicom_vr; // Not a class member for thread-safety reasons
43 /// Pointer to the Transfert Syntax Hash Table which contains all
44 /// the TS of the DICOM version3 public dictionary.
45 gdcmTS *dicom_ts; // Not a class member for thread-safety reasons
47 /// Pointer to global dictionary container
48 gdcmDictSet *Dicts; // Not a class member for thread-safety reasons
50 /// Public dictionary used to parse this header
53 /// Optional "shadow dictionary" (private elements) used to parse this
57 /// ELement VALueS parsed with the PUBlic dictionary.
58 gdcmElValSet PubElValSet;
60 /// Refering underlying filename.
65 // FIXME sw should be an enum e.g.
71 /// Swap code e.g. little, big, bad-big, bad-little endian). Warning:
72 /// this code is not fixed during header parsing.
75 /// Size treshold above which an element value will NOT be loaded in
76 /// memory (to avoid loading the image/volume itself). By default,
77 /// this upper bound is fixed to 1024 bytes (which might look reasonable
78 /// when one considers the definition of the various VR contents).
79 guint32 MaxSizeLoadElementValue;
81 guint16 ReadInt16(void);
82 guint32 ReadInt32(void);
83 guint32 FindLengthOB(void);
84 void Initialise(void);
86 void SwitchSwapToBigEndian(void);
87 // CLEAN ME: NewManualElValToPubDict is NOT called any more.
88 gdcmElValue *NewManualElValToPubDict(std::string NewTagName,
90 void SetMaxSizeLoadElementValue(long);
92 gdcmDictEntry *GetDictEntryByNumber(guint16, guint16);
93 gdcmDictEntry *GetDictEntryByName (std::string Name);
95 // ElValue related utilities
96 gdcmElValue *ReadNextElement(void);
97 gdcmElValue *NewElValueByNumber(guint16 group, guint16 element);
98 gdcmElValue *NewElValueByName (std::string Name);
100 gdcmElValue* GetElementByName (std::string Name);
101 // moved from gdcmElValSet
103 void FindLength (gdcmElValue *);
104 void FindVR (gdcmElValue *);
105 void LoadElementValue (gdcmElValue *);
106 void LoadElementValueSafe(gdcmElValue *);
107 void SkipElementValue (gdcmElValue *);
108 void FixFoundLength (gdcmElValue *, guint32);
109 bool IsAnInteger (gdcmElValue *);
110 void LoadElements(void);
111 void SkipBytes(guint32);
115 FileType filetype; // ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown
117 gdcmElValue * GetElValueByNumber(guint16 group, guint16 element);
118 bool CheckIfExistByNumber(guint16 Group, guint16 Elem );
120 int write(std::ostream&);
121 int anonymize(std::ostream&); // FIXME : anonymize should be a friend ?
124 FILE *OpenFile(bool exception_on_error = false)
125 throw(gdcmFileError);
126 bool CloseFile(void);
127 FileType GetFileType(void);
129 bool IsReadable(void);
130 bool IsImplicitVRLittleEndianTransferSyntax(void);
131 bool IsExplicitVRLittleEndianTransferSyntax(void);
132 bool IsDeflatedExplicitVRLittleEndianTransferSyntax(void);
133 bool IsExplicitVRBigEndianTransferSyntax(void);
134 bool IsJPEGBaseLineProcess1TransferSyntax(void);
135 bool IsJPEGExtendedProcess2_4TransferSyntax(void);
136 bool IsJPEGExtendedProcess3_5TransferSyntax(void);
137 bool IsJPEGSpectralSelectionProcess6_8TransferSyntax(void);
138 bool IsRLELossLessTransferSyntax(void);
139 bool IsJPEGLossless(void);
140 bool IsJPEG2000(void);
141 bool IsDicomV3(void);
143 virtual void ParseHeader(bool exception_on_error = false)
144 throw(gdcmFormatError);
146 gdcmHeader(bool exception_on_error = false);
147 gdcmHeader(const char *filename,
148 bool exception_on_error = false,
149 bool enable_sequences = false);
151 virtual ~gdcmHeader();
153 inline std::string GetFileName(void) {return filename;}
155 size_t GetPixelOffset(void);
156 size_t GetPixelAreaLength(void);
158 inline int GetSwapCode(void) { return sw; }
160 // When some proprietary shadow groups are disclosed, we can set up
161 // an additional specific dictionary to access extra information.
163 // OK : we still have *ONE* ElValSet,
164 // with both Public and Shadow Elements
165 // parsed against THE Public Dictionary and A (single) Shadow Dictionary
167 // TODO Swig int SetShaDict(std::string filename);
168 // TODO Swig int SetPubDict(std::string filename);
170 std::string GetPubElValByName (std::string tagName);
171 std::string GetPubElValRepByName (std::string tagName);
172 std::string GetPubElValByNumber (guint16 group, guint16 element);
173 std::string GetPubElValRepByNumber(guint16 group, guint16 element);
175 size_t GetPubElValOffsetByNumber (guint16 Group, guint16 Elem);
176 void * GetPubElValVoidAreaByNumber(guint16 Group, guint16 Elem);
177 void * LoadElementVoidArea (guint16 Group, guint16 Element);
179 inline ListTag & GetListElem(void) { return PubElValSet.GetListElem();};
180 inline TagElValueHT & GetPubElVal(void) { return PubElValSet.GetTagHt(); };
182 void PrintPubElVal(std::ostream & os = std::cout);
183 void PrintPubDict (std::ostream & os = std::cout);
185 bool SetPubElValByName (std::string content, std::string tagName);
186 bool SetPubElValByNumber(std::string content, guint16 group, guint16 element);
187 bool SetPubElValLengthByNumber(guint32 lgr, guint16 group, guint16 element);
189 std::string GetElValByName (std::string tagName);
190 std::string GetElValRepByName (std::string tagName);
191 std::string GetElValByNumber (guint16 group, guint16 element);
192 std::string GetElValRepByNumber(guint16 group, guint16 element);
194 bool SetElValueByName(std::string content,std::string tagName);
195 // moved from ElValSet
197 bool ReplaceOrCreateByNumber(std::string Value, guint16 Group, guint16 Elem);
198 bool ReplaceOrCreateByNumber( char * Value, guint16 Group, guint16 Elem);
199 bool ReplaceIfExistByNumber ( char * Value, guint16 Group, guint16 Elem);
201 bool Write(FILE *, FileType);
203 // Some heuristic based accessors, end user intended
204 // (to be move to gdcmHeaderHelper?)
209 int GetBitsStored(void);
210 int GetBitsAllocated(void);
211 int GetSamplesPerPixel(void);
212 int GetPlanarConfiguration(void);
213 int GetPixelSize(void);
215 std::string GetPixelType(void);
217 std::string GetTransferSyntaxName(void);
219 int GetLUTNbits(void);
220 unsigned char * GetLUTRGBA(void);
222 // voir gdcmFile::SetImageData ?!?
223 void SetImageDataSize (size_t ExpectedSize);
226 guint16 SwapShort(guint16); // needed by gdcmFile
227 guint32 SwapLong(guint32); // for JPEG Files