]> Creatis software - gdcm.git/blob - src/gdcmHeader.h
Brutal commit. Changelog to come.... Frog
[gdcm.git] / src / gdcmHeader.h
1 // gdcmHeader.h
2
3 #ifndef GDCMHEADER_H
4 #define GDCMHEADER_H
5
6 #include <map>
7 #include "gdcmCommon.h"
8 #include "gdcmException.h"
9 #include "gdcmDictSet.h"
10 #include "gdcmElValue.h"
11 #include "gdcmElValSet.h"
12
13 typedef string VRKey;
14 typedef string VRAtr;
15 typedef map<VRKey, VRAtr> VRHT;    // Value Representation Hash Table
16
17 /// The purpose of an instance of gdcmHeader is to act as a container of
18 /// all the DICOM elements and their corresponding values (and
19 /// additionaly the corresponding DICOM dictionary entry) of the header
20 /// of a DICOM file.
21 ///
22 /// The typical usage of instances of class gdcmHeader is to classify a set of
23 /// dicom files according to header information e.g. to create a file hierarchy
24 /// reflecting the Patient/Study/Serie informations, or extracting a given
25 /// SerieId. Accesing the content (image[s] or volume[s]) is beyond the
26 /// functionality of this class and belongs to gdmcFile.
27 /// \note  The various entries of the explicit value representation (VR) shall
28 ///        be managed within a dictionary which is shared by all gdcmHeader
29 ///        instances.
30 /// \note  The gdcmHeader::Set*Tag* family members cannot be defined as
31 ///        protected due to Swig limitations for as Has_a dependency between
32 ///        gdcmFile and gdcmHeader.
33
34 class GDCM_EXPORT gdcmHeader {
35    void SkipBytes(guint32);
36 private:
37    /// Pointer to the Value Representation Hash Table which contains all
38    /// the VR of the DICOM version3 public dictionary. 
39    static VRHT *dicom_vr;
40  
41    /// Global dictionary container
42    gdcmDictSet* Dicts;
43    /// Public dictionary used to parse this header
44    gdcmDict* RefPubDict;
45    /// Optional "shadow dictionary" (private elements) used to parse this
46    /// header
47    gdcmDict* RefShaDict;
48
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.
54    string filename; 
55    FILE * fp;
56    
57    // FIXME sw should be an enum e.g.
58    //enum EndianType {
59       //LittleEndian, 
60       //BadLittleEndian,
61       //BigEndian, 
62       //BadBigEndian};
63    /// Swap code e.g. little, big, bad-big, bad-little endian). Warning:
64    /// this code is not fixed during header parsing.
65    int sw;
66
67    /// Size treshold above which an element value will NOT be loaded in 
68    /// memory (to avoid loading the image/volume itself). By default,
69    /// this upper bound is fixed to 1024 bytes (which might look reasonable
70    /// when one considers the definition of the various VR contents).
71    guint32 MaxSizeLoadElementValue;
72
73    guint16 ReadInt16(void);
74    guint32 ReadInt32(void);
75    guint16 SwapShort(guint16);
76    guint32 SwapLong(guint32);
77    guint32 FindLengthOB(void);
78    void Initialise(void);
79    void CheckSwap(void);
80    void InitVRDict(void);
81    void SwitchSwapToBigEndian(void);
82    // CLEAN ME: NewManualElValToPubDict is NOT called any more.
83    gdcmElValue*  NewManualElValToPubDict(string NewTagName, string VR);
84    void SetMaxSizeLoadElementValue(long);
85
86    gdcmDictEntry * GetDictEntryByKey(guint16, guint16);
87    gdcmDictEntry * GetDictEntryByName(string name);
88
89    // ElValue related utilities
90    gdcmElValue * ReadNextElement(void);
91    gdcmElValue * NewElValueByKey(guint16 group, guint16 element);
92    gdcmElValue * NewElValueByName(string name);
93    void FindLength(gdcmElValue *);
94    void FindVR(gdcmElValue *);
95    void LoadElementValue(gdcmElValue *);
96    void LoadElementValueSafe(gdcmElValue *);
97    void SkipElementValue(gdcmElValue *);
98    void FixFoundLength(gdcmElValue*, guint32);
99    bool IsAnInteger(gdcmElValue *);
100    void LoadElements(void);
101    
102    bool IsImplicitVRLittleEndianTransferSyntax(void);
103    bool IsExplicitVRLittleEndianTransferSyntax(void);
104    bool IsDeflatedExplicitVRLittleEndianTransferSyntax(void);
105    bool IsExplicitVRBigEndianTransferSyntax(void);
106    bool IsJPEGBaseLineProcess1TransferSyntax(void);
107    bool IsJPEGExtendedProcess2_4TransferSyntax(void); 
108    bool IsJPEGExtendedProcess3_5TransferSyntax(void);
109    bool IsJPEGSpectralSelectionProcess6_8TransferSyntax(void); 
110    
111    bool IsJPEGLossless(void); 
112    bool IsDicomV3(void); 
113       
114 protected:
115    // FIXME: is this enum still necessary ??
116    enum FileType {
117       Unknown = 0,
118       TrueDicom,
119       ExplicitVR,
120       ImplicitVR,
121       ACR,
122       ACR_LIBIDO};  // CLEANME
123    FileType filetype;
124    int write(ostream&);   
125    int anonymize(ostream&);  // FIXME : anonymize should be a friend ?
126 public:
127    bool IsReadable(void);
128    virtual void ParseHeader(bool exception_on_error = false)
129      throw(gdcmFormatError);
130    gdcmHeader(const char *filename, bool exception_on_error = false)
131      throw(gdcmFileError);
132    virtual ~gdcmHeader();
133    
134    size_t GetPixelOffset(void);
135    void   GetPixels(size_t, void *);
136    int    GetSwapCode(void) { return sw; }
137
138    // TODO Swig int SetPubDict(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(string filename);
142
143    string GetPubElValByName(string TagName);
144    string GetPubElValByNumber(guint16 group, guint16 element);
145    string GetPubElValRepByName(string TagName);
146    string GetPubElValRepByNumber(guint16 group, guint16 element);
147
148    TagElValueHT & GetPubElVal(void) { return PubElValSet.GetTagHt(); };
149    void   PrintPubElVal(ostream & os = cout);
150    void   PrintPubDict (ostream & os = cout);
151      
152    // TODO Swig string* GetShaTagNames(); 
153    string GetShaElValByName(string TagName);
154    string GetShaElValByNumber(guint16 group, guint16 element);
155    string GetShaElValRepByName(string TagName);
156    string GetShaElValRepByNumber(guint16 group, guint16 element);
157
158    string GetElValByName(string TagName);
159    string GetElValByNumber(guint16 group, guint16 element);
160    string GetElValRepByName(string TagName);
161    string GetElValRepByNumber(guint16 group, guint16 element);
162
163    int SetPubElValByName(string content, string TagName);
164    int SetPubElValByNumber(string content, guint16 group, guint16 element);
165    int SetShaElValByName(string content, string ShadowTagName);
166    int SetShaElValByNumber(string content, guint16 group, guint16 element);
167    
168    int SetPubElValLengthByNumber(guint32 lgr, guint16 group, guint16 element);                                   
169    int ReplaceOrCreateByNumber(guint16 Group, guint16 Elem, string Value);                                
170
171    gdcmElValSet GetPubElValSet() { return(PubElValSet); }
172    
173    int GetXSize(void);  
174    int GetYSize(void);
175    int GetZSize(void);       
176    string GetPixelType(void);  
177    
178 };
179
180 #endif