]> Creatis software - gdcm.git/blob - src/gdcmHeader.h
Add protected method : gdcmElValue * GetElValueByNumber(guint16 group, guint16...
[gdcm.git] / src / gdcmHeader.h
1 // $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.h,v 1.22 2003/05/06 15:52:13 jpr Exp $
2
3 #ifndef GDCMHEADER_H
4 #define GDCMHEADER_H
5
6 #include <map>
7 #include "gdcmCommon.h"
8 #include "gdcmUtil.h"
9 #include "gdcmException.h"
10 #include "gdcmDictSet.h"
11 #include "gdcmElValue.h"
12 #include "gdcmElValSet.h"
13
14 typedef string VRKey;
15 typedef string VRAtr;
16 typedef map<VRKey, VRAtr> VRHT;    // Value Representation Hash Table
17
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
21 /// of a DICOM file.
22 ///
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
30 ///        instances.
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.
34
35 class GDCM_EXPORT gdcmHeader {
36    void SkipBytes(guint32);
37 private:
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
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    
56    // FIXME sw should be an enum e.g.
57    //enum EndianType {
58       //LittleEndian, 
59       //BadLittleEndian,
60       //BigEndian, 
61       //BadBigEndian};
62    /// Swap code e.g. little, big, bad-big, bad-little endian). Warning:
63    /// this code is not fixed during header parsing.
64    int sw;
65
66    /// Size treshold above which an element value will NOT be loaded in 
67    /// memory (to avoid loading the image/volume itself). By default,
68    /// this upper bound is fixed to 1024 bytes (which might look reasonable
69    /// when one considers the definition of the various VR contents).
70    guint32 MaxSizeLoadElementValue;
71
72    guint16 ReadInt16(void);
73    guint32 ReadInt32(void);
74    guint32 FindLengthOB(void);
75    void Initialise(void);
76    void CheckSwap(void);
77    void SwitchSwapToBigEndian(void);
78    // CLEAN ME: NewManualElValToPubDict is NOT called any more.
79    gdcmElValue*  NewManualElValToPubDict(string NewTagName, string VR);
80    void SetMaxSizeLoadElementValue(long);
81
82    gdcmDictEntry * GetDictEntryByNumber(guint16, guint16);
83    gdcmDictEntry * GetDictEntryByName(string name);
84
85    // ElValue related utilities
86    gdcmElValue * ReadNextElement(void);
87    gdcmElValue * NewElValueByNumber(guint16 group, guint16 element);
88    gdcmElValue * NewElValueByName(string name);
89
90    void FindLength(gdcmElValue *);
91    void FindVR(gdcmElValue *);
92    void LoadElementValue(gdcmElValue *);
93    void LoadElementValueSafe(gdcmElValue *);
94    void SkipElementValue(gdcmElValue *);
95    void FixFoundLength(gdcmElValue*, guint32);
96    bool IsAnInteger(gdcmElValue *);
97    void LoadElements(void);
98    
99 protected:
100    FILE * fp;
101    FileType filetype;
102    
103    gdcmElValue * GetElValueByNumber(guint16 group, guint16 element);
104
105    guint16 SwapShort(guint16); // needed by gdcmFile
106    guint32 SwapLong(guint32);  // for JPEG Files :-(
107    bool OpenFile(bool exception_on_error = false)
108      throw(gdcmFileError);
109    bool CloseFile(void);
110    int write(ostream&);   
111    int anonymize(ostream&);  // FIXME : anonymize should be a friend ?
112 public:
113    bool IsReadable(void);
114    bool IsImplicitVRLittleEndianTransferSyntax(void);
115    bool IsExplicitVRLittleEndianTransferSyntax(void);
116    bool IsDeflatedExplicitVRLittleEndianTransferSyntax(void);
117    bool IsExplicitVRBigEndianTransferSyntax(void);
118    bool IsJPEGBaseLineProcess1TransferSyntax(void);
119    bool IsJPEGExtendedProcess2_4TransferSyntax(void); 
120    bool IsJPEGExtendedProcess3_5TransferSyntax(void);
121    bool IsJPEGSpectralSelectionProcess6_8TransferSyntax(void); 
122    bool IsJPEGLossless(void); 
123    bool IsDicomV3(void); 
124       
125    virtual void ParseHeader(bool exception_on_error = false)
126      throw(gdcmFormatError);
127    gdcmHeader(const char *filename, bool exception_on_error = false);
128    virtual ~gdcmHeader();
129    
130    size_t GetPixelOffset(void);
131    int    GetSwapCode(void) { return sw; }
132
133    // TODO Swig int SetPubDict(string filename);
134    // When some proprietary shadow groups are disclosed, we can set up
135    // an additional specific dictionary to access extra information.
136    // TODO Swig int SetShaDict(string filename);
137
138    string GetPubElValByName(string TagName);
139    string GetPubElValByNumber(guint16 group, guint16 element);
140    string GetPubElValRepByName(string TagName);
141    string GetPubElValRepByNumber(guint16 group, guint16 element);
142
143    TagElValueHT & GetPubElVal(void) { return PubElValSet.GetTagHt(); };
144    void   PrintPubElVal(ostream & os = cout);
145    void   PrintPubDict (ostream & os = cout);
146      
147    // TODO Swig string* GetShaTagNames(); 
148    string GetShaElValByName(string TagName);
149    string GetShaElValByNumber(guint16 group, guint16 element);
150    string GetShaElValRepByName(string TagName);
151    string GetShaElValRepByNumber(guint16 group, guint16 element);
152
153    string GetElValByName(string TagName);
154    string GetElValByNumber(guint16 group, guint16 element);
155    string GetElValRepByName(string TagName);
156    string GetElValRepByNumber(guint16 group, guint16 element);
157
158    int SetPubElValByName(string content, string TagName);
159    int SetPubElValByNumber(string content, guint16 group, guint16 element);
160    int SetShaElValByName(string content, string ShadowTagName);
161    int SetShaElValByNumber(string content, guint16 group, guint16 element);
162    
163    int SetPubElValLengthByNumber(guint32 lgr, guint16 group, guint16 element);                                   
164    int ReplaceOrCreateByNumber(string Value, guint16 Group, guint16 Elem);                                
165    int GetXSize(void);  
166    int GetYSize(void);
167    int GetZSize(void);       
168    string GetPixelType(void);  
169    int Write(FILE *, FileType);
170    
171 };
172
173 #endif