]> Creatis software - gdcm.git/blob - src/gdcmHeader.h
* src/gdcmParser.[cxx|h] and gdcmHeader.[cxx.h]: gdcmHeader::Write split
[gdcm.git] / src / gdcmHeader.h
1 // gdcmHeader.h
2 //-----------------------------------------------------------------------------
3 #ifndef GDCMHEADER_H
4 #define GDCMHEADER_H
5
6 #include "gdcmCommon.h"
7 #include "gdcmParser.h"
8
9 //-----------------------------------------------------------------------------
10 /**
11  * \brief
12  * The purpose of an instance of gdcmHeader is to act as a container of
13  * all the DICOM elements and their corresponding values (and
14  * additionaly the corresponding DICOM dictionary entry) of the header
15  * of a DICOM file.
16  *
17  * The typical usage of instances of class gdcmHeader is to classify a set of
18  * dicom files according to header information e.g. to create a file hierarchy
19  * reflecting the Patient/Study/Serie informations, or extracting a given
20  * SerieId. Accessing the content (image[s] or volume[s]) is beyond the
21  * functionality of this class and belongs to gdmcFile.
22  * \note  The various entries of the explicit value representation (VR) shall
23  *        be managed within a dictionary which is shared by all gdcmHeader
24  *        instances.
25  * \note  The gdcmHeader::Set*Tag* family members cannot be defined as
26  *        protected due to Swig limitations for as Has_a dependency between
27  *        gdcmFile and gdcmHeader.
28  */
29 class GDCM_EXPORT gdcmHeader : public gdcmParser
30 {
31 protected:
32    /// In some cases (e.g. for some ACR-NEMA images) the Header Entry Element
33    /// Number of the 'Pixel Element' is *not* found at 0x0010. In order to
34    /// make things easier the parser shall store the proper value in
35    /// NumPixel to provide a unique access facility. See also the constructor
36    /// \ref gdcmHeader::gdcmHeader
37    guint16 NumPixel;
38    /// In some cases (e.g. for some ACR-NEMA images) the header entry for
39    /// the group of pixels is *not* found at 0x7fe0. In order to
40    /// make things easier the parser shall store the proper value in
41    /// GrPixel to provide a unique access facility. See also the constructor
42    /// \ref gdcmHeader::gdcmHeader
43    guint16 GrPixel;
44    /// Some DICOM files may contain several images (e.g. a icon, followd by
45    /// the image itself. Hence the tag (GrPixel,NumPixel) might appear
46    /// several times. countGrPixel is the number of occurences of the 
47    /// tag of pixels (i.e. (GrPixel,NumPixel)) contained in the header.
48    int countGrPixel;
49 public:
50    gdcmHeader(bool exception_on_error = false);
51    gdcmHeader(const char *filename, 
52               bool  exception_on_error = false, 
53               bool  enable_sequences   = false,
54               bool  skip_shadow        = false);
55  
56    virtual ~gdcmHeader();
57
58    // Standard values and informations contained in the header
59    virtual bool IsReadable(void);
60    bool IsJPEGBaseLineProcess1TransferSyntax(void);
61    bool IsJPEGExtendedProcess2_4TransferSyntax(void); 
62    bool IsJPEGExtendedProcess3_5TransferSyntax(void);
63    bool IsJPEGSpectralSelectionProcess6_8TransferSyntax(void); 
64    bool IsRLELossLessTransferSyntax(void); 
65    bool IsJPEGLossless(void); 
66    bool IsJPEG2000(void); 
67    bool IsDicomV3(void); 
68
69    // Some heuristic based accessors, end user intended 
70    // (to be moved to gdcmHeaderHelper?) 
71    int GetXSize(void);
72    int GetYSize(void);
73    int GetZSize(void);
74    int GetBitsStored(void);
75    int GetBitsAllocated(void);
76    int GetSamplesPerPixel(void);   
77    int GetPlanarConfiguration(void);
78
79    int GetPixelSize(void);   
80    std::string GetPixelType(void);  
81    size_t GetPixelOffset(void);
82    size_t GetPixelAreaLength(void);
83
84    bool   HasLUT(void);
85    int    GetLUTNbits(void);
86    unsigned char * GetLUTRGBA(void);
87
88    std::string GetTransfertSyntaxName(void);
89
90    // When some proprietary shadow groups are disclosed, we can set up
91    // an additional specific dictionary to access extra information.
92    
93    // OK : we still have *ONE* HeaderEntrySet, 
94    // with both Public and Shadow Elements
95    // parsed against THE Public Dictionary and A (single) Shadow Dictionary
96    
97    // TODO Swig int SetShaDict(std::string filename);
98    // TODO Swig int SetPubDict(std::string filename);
99    
100    /// Accessor to \ref gdcmHeader::GrPixel
101    guint16 GetGrPixel(void)  {return GrPixel;}
102    
103    /// Accessor to \ref gdcmHeader::NumPixel
104    guint16 GetNumPixel(void) {return NumPixel;}
105
106 // Entry
107
108    inline virtual std::string GetEntryByNumber  (guint16 group, guint16 element)
109       { return(gdcmParser::GetEntryByNumber(group,element)); }
110       
111    inline virtual std::string GetEntryVRByNumber(guint16 group, guint16 element)
112       { return(gdcmParser::GetEntryVRByNumber(group,element)); }
113       
114    inline virtual int GetEntryLengthByNumber(guint16 group, guint16 element)
115       { return(gdcmParser::GetEntryLengthByNumber(group,element)); }
116       
117    inline virtual std::string GetEntryByName    (std::string tagName) 
118       { return(gdcmParser::GetEntryByName(tagName)); }
119       
120    inline virtual std::string GetEntryVRByName  (std::string tagName)
121       { return(gdcmParser::GetEntryVRByName(tagName)); }
122       
123    inline virtual bool SetEntryByNumber(std::string content,
124                                         guint16 group, guint16 element)
125       { return(gdcmParser::SetEntryByNumber(content,group,element)); }
126       
127    inline virtual bool SetEntryByName(std::string content,std::string tagName)
128       { return(gdcmParser::SetEntryByName(content,tagName)); }
129
130   inline virtual bool SetEntryLengthByNumber(guint32 l,
131                                              guint16 group, guint16 element)
132       { return(gdcmParser::SetEntryLengthByNumber(l,group,element)); }
133
134    inline virtual void UpdateShaEntries(void)
135       { gdcmParser::UpdateShaEntries(); }
136
137    /// Read (used in gdcmFile)
138    void SetImageDataSize(size_t ExpectedSize);
139
140    bool operator<(gdcmHeader &header);
141
142    bool WriteEntry(gdcmHeaderEntry *tag,FILE *_fp,FileType type);
143
144
145 protected:
146    //CLEANME int write(std::ostream&);   
147    //CLEANME int anonymize(std::ostream&);//FIXME: anonymize should be a friend
148    bool anonymizeHeader(void);
149 private:
150
151 };
152
153 //-----------------------------------------------------------------------------
154 #endif