1 // $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.h,v 1.28 2003/06/20 14:17:47 jpr Exp $
7 #include "gdcmCommon.h"
9 #include "gdcmException.h"
10 #include "gdcmDictSet.h"
11 #include "gdcmElValue.h"
12 #include "gdcmElValSet.h"
14 typedef std::string VRKey;
15 typedef std::string VRAtr;
16 typedef std::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
48 /// Pointer to the Transfert Syntax Hash Table which contains all
49 /// the TS of the DICOM version3 public dictionary.
50 gdcmTS *dicom_ts; // Not a class member for thread-safety reasons
52 /// ELement VALueS parsed with the PUBlic dictionary.
53 gdcmElValSet PubElValSet;
54 /// ELement VALueS parsed with the SHAdow dictionary.
55 gdcmElValSet ShaElValSet;
56 /// Refering underlying filename.
59 // FIXME sw should be an enum e.g.
65 /// Swap code e.g. little, big, bad-big, bad-little endian). Warning:
66 /// this code is not fixed during header parsing.
69 /// Size treshold above which an element value will NOT be loaded in
70 /// memory (to avoid loading the image/volume itself). By default,
71 /// this upper bound is fixed to 1024 bytes (which might look reasonable
72 /// when one considers the definition of the various VR contents).
73 guint32 MaxSizeLoadElementValue;
75 guint16 ReadInt16(void);
76 guint32 ReadInt32(void);
77 guint32 FindLengthOB(void);
78 void Initialise(void);
80 void SwitchSwapToBigEndian(void);
81 // CLEAN ME: NewManualElValToPubDict is NOT called any more.
82 gdcmElValue* NewManualElValToPubDict(std::string NewTagName,
84 void SetMaxSizeLoadElementValue(long);
86 gdcmDictEntry * GetDictEntryByNumber(guint16, guint16);
87 gdcmDictEntry * GetDictEntryByName(std::string Name);
89 // ElValue related utilities
90 gdcmElValue * ReadNextElement(void);
91 gdcmElValue * NewElValueByNumber(guint16 group, guint16 element);
92 gdcmElValue * NewElValueByName(std::string Name);
94 void FindLength(gdcmElValue *);
95 void FindVR(gdcmElValue *);
96 void LoadElementValue(gdcmElValue *);
97 void LoadElementValueSafe(gdcmElValue *);
98 void SkipElementValue(gdcmElValue *);
99 void FixFoundLength(gdcmElValue*, guint32);
100 bool IsAnInteger(gdcmElValue *);
101 void LoadElements(void);
107 gdcmElValue * GetElValueByNumber(guint16 group, guint16 element);
109 guint16 SwapShort(guint16); // needed by gdcmFile
110 guint32 SwapLong(guint32); // for JPEG Files :-(
111 bool OpenFile(bool exception_on_error = false)
112 throw(gdcmFileError);
113 bool CloseFile(void);
114 int write(std::ostream&);
115 int anonymize(std::ostream&); // FIXME : anonymize should be a friend ?
117 bool IsReadable(void);
118 bool IsImplicitVRLittleEndianTransferSyntax(void);
119 bool IsExplicitVRLittleEndianTransferSyntax(void);
120 bool IsDeflatedExplicitVRLittleEndianTransferSyntax(void);
121 bool IsExplicitVRBigEndianTransferSyntax(void);
122 bool IsJPEGBaseLineProcess1TransferSyntax(void);
123 bool IsJPEGExtendedProcess2_4TransferSyntax(void);
124 bool IsJPEGExtendedProcess3_5TransferSyntax(void);
125 bool IsJPEGSpectralSelectionProcess6_8TransferSyntax(void);
126 bool IsJPEGLossless(void);
127 bool IsDicomV3(void);
129 virtual void ParseHeader(bool exception_on_error = false)
130 throw(gdcmFormatError);
131 gdcmHeader(const char *filename, bool exception_on_error = false);
132 gdcmHeader( bool exception_on_error = false);
133 virtual ~gdcmHeader();
135 size_t GetPixelOffset(void);
136 int GetSwapCode(void) { return sw; }
138 // TODO Swig int SetPubDict(std::string filename);
139 // When some proprietary shadow groups are disclosed, we can set up
140 // an additional specific dictionary to access extra information.
141 // TODO Swig int SetShaDict(std::string filename);
143 std::string GetPubElValByName (std::string TagName);
144 std::string GetPubElValRepByName (std::string TagName);
145 std::string GetPubElValByNumber (guint16 group, guint16 element);
146 std::string GetPubElValRepByNumber(guint16 group, guint16 element);
148 TagElValueHT & GetPubElVal(void) { return PubElValSet.GetTagHt(); };
149 void PrintPubElVal(std::ostream & os = std::cout);
150 void PrintPubDict (std::ostream & os = std::cout);
152 // TODO Swig std::string* GetShaTagNames();
153 std::string GetShaElValByName (std::string TagName);
154 std::string GetShaElValRepByName (std::string TagName);
155 std::string GetShaElValByNumber (guint16 group, guint16 element);
156 std::string GetShaElValRepByNumber(guint16 group, guint16 element);
158 std::string GetElValByName (std::string TagName);
159 std::string GetElValRepByName (std::string TagName);
160 std::string GetElValByNumber (guint16 group, guint16 element);
161 std::string GetElValRepByNumber(guint16 group, guint16 element);
163 int SetPubElValByName (std::string content, std::string TagName);
164 int SetShaElValByName (std::string content, std::string ShadowTagName);
165 int SetPubElValByNumber(std::string content, guint16 group, guint16 element);
167 int SetShaElValByNumber(std::string content, guint16 group, guint16 element);
169 int SetPubElValLengthByNumber(guint32 lgr, guint16 group, guint16 element);
171 int ReplaceOrCreateByNumber(std::string Value, guint16 Group, guint16 Elem);
172 int ReplaceOrCreateByNumber(char * Value, guint16 Group, guint16 Elem);
177 int GetBitsStored(void);
178 int GetSamplesPerPixel(void);
179 int GetPixelSize(void);
180 std::string GetPixelType(void);
182 float GetXSpacing(void);
183 float GetYSpacing(void);
184 float GetZSpacing(void);
186 float GetXImagePosition(void);
187 float GetYImagePosition(void);
188 float GetZImagePosition(void);
190 int Write(FILE *, FileType);