]> Creatis software - gdcm.git/blob - src/gdcmHeader.h
7a518912cd2023870761f5b75bd1f2b59cb6606a
[gdcm.git] / src / gdcmHeader.h
1 // $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.h,v 1.40 2003/10/21 12:19:43 jpr Exp $
2
3 #ifndef GDCMHEADER_H
4 #define GDCMHEADER_H
5
6 #include "gdcmCommon.h"
7 #include "gdcmVR.h"
8 #include "gdcmTS.h"
9 #include "gdcmException.h"
10 #include "gdcmDictSet.h"
11 #include "gdcmElValue.h"
12 #include "gdcmElValSet.h"
13 #include <map>
14
15 typedef std::string VRKey;
16 typedef std::string VRAtr;
17 typedef std::map<VRKey, VRAtr> VRHT;    // Value Representation Hash Table
18
19 /// The purpose of an instance of gdcmHeader is to act as a container of
20 /// all the DICOM elements and their corresponding values (and
21 /// additionaly the corresponding DICOM dictionary entry) of the header
22 /// of a DICOM file.
23 ///
24 /// The typical usage of instances of class gdcmHeader is to classify a set of
25 /// dicom files according to header information e.g. to create a file hierarchy
26 /// reflecting the Patient/Study/Serie informations, or extracting a given
27 /// SerieId. Accesing the content (image[s] or volume[s]) is beyond the
28 /// functionality of this class and belongs to gdmcFile.
29 /// \note  The various entries of the explicit value representation (VR) shall
30 ///        be managed within a dictionary which is shared by all gdcmHeader
31 ///        instances.
32 /// \note  The gdcmHeader::Set*Tag* family members cannot be defined as
33 ///        protected due to Swig limitations for as Has_a dependency between
34 ///        gdcmFile and gdcmHeader.
35
36 class GDCM_EXPORT gdcmHeader {
37    void SkipBytes(guint32);
38 private:
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
42    /// Pointer to global dictionary container
43    gdcmDictSet *Dicts;   // Not a class member for thread-safety reasons
44    /// Public dictionary used to parse this header
45    gdcmDict *RefPubDict;
46    /// Optional "shadow dictionary" (private elements) used to parse this
47    /// header
48    gdcmDict *RefShaDict;
49    /// Pointer to the Transfert Syntax Hash Table which contains all
50    /// the TS of the DICOM version3 public dictionary. 
51    gdcmTS *dicom_ts;     // Not a class member for thread-safety reasons
52
53    /// ELement VALueS parsed with the PUBlic dictionary.
54    gdcmElValSet PubElValSet;
55    /// ELement VALueS parsed with the SHAdow dictionary.
56    gdcmElValSet ShaElValSet;
57    /// Refering underlying filename.
58    std::string filename; 
59    
60    // FIXME sw should be an enum e.g.
61    //enum EndianType {
62       //LittleEndian, 
63       //BadLittleEndian,
64       //BigEndian, 
65       //BadBigEndian};
66    /// Swap code e.g. little, big, bad-big, bad-little endian). Warning:
67    /// this code is not fixed during header parsing.
68    int sw;
69
70    /// Size treshold above which an element value will NOT be loaded in 
71    /// memory (to avoid loading the image/volume itself). By default,
72    /// this upper bound is fixed to 1024 bytes (which might look reasonable
73    /// when one considers the definition of the various VR contents).
74    guint32 MaxSizeLoadElementValue;
75
76    guint16 ReadInt16(void);
77    guint32 ReadInt32(void);
78    guint32 FindLengthOB(void);
79    void Initialise(void);
80    void CheckSwap(void);
81    void SwitchSwapToBigEndian(void);
82    // CLEAN ME: NewManualElValToPubDict is NOT called any more.
83    gdcmElValue*  NewManualElValToPubDict(std::string NewTagName,
84                                          std::string VR);
85    void SetMaxSizeLoadElementValue(long);
86
87    gdcmDictEntry * GetDictEntryByNumber(guint16, guint16);
88    gdcmDictEntry * GetDictEntryByName(std::string Name);
89
90    // ElValue related utilities
91    gdcmElValue * ReadNextElement(void);
92    gdcmElValue * NewElValueByNumber(guint16 group, guint16 element);
93    gdcmElValue * NewElValueByName(std::string Name);
94
95    void FindLength(gdcmElValue *);
96    void FindVR(gdcmElValue *);
97    void LoadElementValue(gdcmElValue *);
98    void LoadElementValueSafe(gdcmElValue *);
99    void SkipElementValue(gdcmElValue *);
100    void FixFoundLength(gdcmElValue*, guint32);
101    bool IsAnInteger(gdcmElValue *);
102    void LoadElements(void);
103    
104 protected:
105    FILE * fp;
106    FileType filetype;
107    
108    gdcmElValue * GetElValueByNumber(guint16 group, guint16 element);
109    int CheckIfExistByNumber(guint16 Group, guint16 Elem );
110
111    guint16 SwapShort(guint16); // needed by gdcmFile
112    guint32 SwapLong(guint32);  // for JPEG Files :-(
113    bool OpenFile(bool exception_on_error = false)
114      throw(gdcmFileError);
115    bool CloseFile(void);
116    int write(std::ostream&);   
117    int anonymize(std::ostream&);  // FIXME : anonymize should be a friend ?
118 public:
119    bool IsReadable(void);
120    bool IsImplicitVRLittleEndianTransferSyntax(void);
121    bool IsExplicitVRLittleEndianTransferSyntax(void);
122    bool IsDeflatedExplicitVRLittleEndianTransferSyntax(void);
123    bool IsExplicitVRBigEndianTransferSyntax(void);
124    bool IsJPEGBaseLineProcess1TransferSyntax(void);
125    bool IsJPEGExtendedProcess2_4TransferSyntax(void); 
126    bool IsJPEGExtendedProcess3_5TransferSyntax(void);
127    bool IsJPEGSpectralSelectionProcess6_8TransferSyntax(void); 
128    bool IsRLELossLessTransferSyntax(void); 
129    bool IsJPEGLossless(void); 
130    bool IsJPEG2000(void); 
131    bool IsDicomV3(void); 
132       
133    virtual void ParseHeader(bool exception_on_error = false)
134      throw(gdcmFormatError);
135    gdcmHeader(const char *filename, bool exception_on_error = false);
136    gdcmHeader( bool exception_on_error = false);
137    virtual ~gdcmHeader();
138
139    std::string GetFileName(void) {return filename;}
140    
141    size_t GetPixelOffset(void);
142    int    GetSwapCode(void) { return sw; }
143
144    // TODO Swig int SetPubDict(std::string filename);
145    // When some proprietary shadow groups are disclosed, we can set up
146    // an additional specific dictionary to access extra information.
147    // TODO Swig int SetShaDict(std::string filename);
148
149    std::string GetPubElValByName     (std::string TagName);
150    std::string GetPubElValRepByName  (std::string TagName);
151    std::string GetPubElValByNumber   (guint16 group, guint16 element);
152    std::string GetPubElValRepByNumber(guint16 group, guint16 element);
153    
154    size_t GetPubElValOffsetByNumber(guint16 Group, guint16 Elem);
155    void * GetPubElValVoidAreaByNumber(guint16 Group, guint16 Elem);   
156    void * LoadElementVoidArea(guint16 Group, guint16 Element);
157    
158    TagElValueHT & GetPubElVal(void) { return PubElValSet.GetTagHt(); };
159    void   PrintPubElVal(std::ostream & os = std::cout);
160    void   PrintPubDict (std::ostream & os = std::cout);
161      
162    // TODO Swig std::string* GetShaTagNames(); 
163    std::string GetShaElValByName     (std::string TagName);
164    std::string GetShaElValRepByName  (std::string TagName);
165    std::string GetShaElValByNumber   (guint16 group, guint16 element);
166    std::string GetShaElValRepByNumber(guint16 group, guint16 element);
167
168    std::string GetElValByName     (std::string TagName);
169    std::string GetElValRepByName  (std::string TagName);
170    std::string GetElValByNumber   (guint16 group, guint16 element);
171    std::string GetElValRepByNumber(guint16 group, guint16 element);
172
173    int SetPubElValByName  (std::string content, std::string TagName);
174    int SetShaElValByName  (std::string content, std::string ShadowTagName);
175    
176    int SetPubElValByNumber(std::string content, guint16 group, guint16 element);
177    int SetShaElValByNumber(std::string content, guint16 group, guint16 element);
178    
179    int SetPubElValLengthByNumber(guint32 lgr, guint16 group, guint16 element);                                   
180
181    int ReplaceOrCreateByNumber(std::string Value, guint16 Group, guint16 Elem); 
182    int ReplaceOrCreateByNumber(     char * Value, guint16 Group, guint16 Elem);                                
183    int ReplaceIfExistByNumber (     char * Value, guint16 Group, guint16 Elem);
184                                   
185    int Write(FILE *, FileType);
186    
187  // Some heuristic based accessors, end user intended 
188   
189    int GetXSize(void);  
190    int GetYSize(void);
191    int GetZSize(void);
192    int GetBitsStored(void);
193    int GetBitsAllocated(void);
194    int GetSamplesPerPixel(void);
195    
196    int GetPlanarConfiguration(void);
197
198    int GetPixelSize(void);       
199    std::string GetPixelType(void);  
200    
201    std::string GetTransferSyntaxName(void);
202    int    GetLUTLength(void);
203    int    GetLUTNbits(void);
204    void * GetLUTRed(void);
205    void * GetLUTGreen(void);
206    void * GetLUTBlue(void);
207    void * GetLUTRGB(void);
208            
209
210 };
211
212 #endif