]> Creatis software - gdcm.git/blob - src/gdcmFile.h
COMP: Try to get read of the float issues
[gdcm.git] / src / gdcmFile.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmFile.h,v $
5   Language:  C++
6   Date:      $Date: 2005/07/24 02:14:43 $
7   Version:   $Revision: 1.114 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18
19 #ifndef GDCMFILE_H
20 #define GDCMFILE_H
21
22 #include "gdcmDebug.h"
23 #include "gdcmDocument.h"
24
25
26
27 namespace gdcm 
28 {
29
30 typedef struct
31 {
32    double x;
33    double y;
34    double z;
35 } vector3D;
36
37 typedef std::pair<double, double> Res;
38
39 class RLEFramesInfo;
40 class JPEGFragmentsInfo;
41
42 //-----------------------------------------------------------------------------
43 // Dicom Part 3.3 Compliant
44 enum ModalityType {
45    Unknow,
46    AU,       // Voice Audio
47    AS,       // Angioscopy
48    BI,       // Biomagnetic Imaging
49    CF,       // Cinefluorography
50    CP,       // Culposcopy
51    CR,       // Computed Radiography
52    CS,       // Cystoscopy
53    CT,       // Computed Tomography
54    DD,       // Duplex Dopler
55    DF,       // Digital Fluoroscopy
56    DG,       // Diaphanography
57    DM,       // Digital Microscopy
58    DS,       // Digital Substraction Angiography
59    DX,       // Digital Radiography
60    ECG,      // Echocardiography
61    EPS,      // Basic Cardiac EP
62    ES,       // Endoscopy
63    FA,       // Fluorescein Angiography
64    FS,       // Fundoscopy
65    HC,       // Hard Copy
66    HD,       // Hemodynamic
67    LP,       // Laparoscopy
68    LS,       // Laser Surface Scan
69    MA,       // Magnetic Resonance Angiography
70    MR,       // Magnetic Resonance
71    NM,       // Nuclear Medicine
72    OT,       // Other
73    PT,       // Positron Emission Tomography
74    RF,       // Radio Fluoroscopy
75    RG,       // Radiographic Imaging
76    RTDOSE,   // Radiotherapy Dose
77    RTIMAGE,  // Radiotherapy Image
78    RTPLAN,   // Radiotherapy Plan
79    RTSTRUCT, // Radiotherapy Structure Set
80    SM,       // Microscopic Imaging
81    ST,       // Single-photon Emission Computed Tomography
82    TG,       // Thermography
83    US,       // Ultrasound
84    VF,       // Videofluorography
85    XA,       // X-Ray Angiography
86    XC        // Photographic Imaging
87 };
88
89 //-----------------------------------------------------------------------------
90
91 /**
92  * \brief DICOM elements and their corresponding values (and
93  * additionaly the corresponding DICOM dictionary entry) of the header
94  * of a DICOM file.
95  *
96  * The typical usage of instances of class File is to classify a set of
97  * dicom files according to header information e.g. to create a file hierarchy
98  * reflecting the Patient/Study/Serie informations, or extracting a given
99  * SerieId. Accessing the content (image[s] or volume[s]) is beyond the
100  * functionality of this class and belongs to gdcm::FileHelper.
101  * \note  The various entries of the explicit value representation (VR) shall
102  *        be managed within a dictionary which is shared by all File
103  *        instances.
104  * \note  The File::Set*Tag* family members cannot be defined as
105  *        protected due to Swig limitations for as Has_a dependency between
106  *        File and FileHelper.
107  */
108 class GDCM_EXPORT File : public Document
109 {
110 public:
111    File();
112    GDCM_LEGACY(File( std::string const &filename ));
113    ~File();
114
115    // Loading
116    GDCM_LEGACY(bool Load( std::string const &filename ));
117    bool Load(); 
118    // Standard values and informations contained in the header
119    bool IsReadable();
120
121    // Some heuristic based accessors, end user intended 
122    int GetImageNumber();
123    ModalityType GetModality();
124
125    int GetXSize();
126    int GetYSize();
127    int GetZSize();
128
129    float GetXSpacing();
130    float GetYSpacing();
131    float GetZSpacing();
132
133    float GetXOrigin();
134    float GetYOrigin();
135    float GetZOrigin();
136
137    bool GetImageOrientationPatient( float iop[6] );
138
139    int GetBitsStored();
140    int GetBitsAllocated();
141    int GetHighBitPosition();
142    int GetSamplesPerPixel();
143    int GetPlanarConfiguration();
144    int GetPixelSize();
145    std::string GetPixelType();
146    bool IsSignedPixelData();
147    bool IsMonochrome();
148    bool IsMonochrome1();
149    bool IsPaletteColor();
150    bool IsYBRFull();
151
152    bool HasLUT();
153    int GetLUTNbits();
154
155    // For rescaling graylevel:
156    float GetRescaleIntercept();
157    float GetRescaleSlope();
158
159    int GetNumberOfScalarComponents();
160    int GetNumberOfScalarComponentsRaw();
161
162    /// Accessor to \ref File::GrPixel
163    uint16_t GetGrPixel()  { return GrPixel; }
164    /// Accessor to \ref File::NumPixel
165    uint16_t GetNumPixel() { return NumPixel; }
166
167    size_t GetPixelOffset();
168    size_t GetPixelAreaLength();
169
170    /// returns the RLE info
171    RLEFramesInfo *GetRLEInfo() { return RLEInfo; }
172    /// Returns the JPEG Fragments info
173    JPEGFragmentsInfo *GetJPEGInfo() { return JPEGInfo; }
174
175 // Anonymization process
176    void AddAnonymizeElement (uint16_t group, uint16_t elem, 
177                              std::string const &value);
178    /// Clears the list of elements to be anonymized
179    void ClearAnonymizeList() { AnonymizeList.clear(); }      
180    void AnonymizeNoLoad();
181    /// Replace patient's own information by info from the Anonymization list
182    bool AnonymizeFile();
183
184    bool Write(std::string fileName, FileType filetype);
185
186    double TypeOrientation( );
187
188 protected:
189  
190    /// Store the RLE frames info obtained during parsing of pixels.
191    RLEFramesInfo *RLEInfo;
192    /// Store the JPEG fragments info obtained during parsing of pixels.
193    JPEGFragmentsInfo *JPEGInfo;
194
195    /// \brief In some cases (e.g. for some ACR-NEMA images) the Entry Element
196    /// Number of the 'Pixel Element' is *not* found at 0x0010. In order to
197    /// make things easier the parser shall store the proper value in
198    /// NumPixel to provide a unique access facility. 
199    uint16_t NumPixel;
200    /// \brief In some cases (e.g. for some ACR-NEMA images) the header entry for
201    /// the group of pixels is *not* found at 0x7fe0. 
202    /// In order to make things easier the parser shall store the proper value
203    /// in GrPixel to provide a unique access facility.
204    uint16_t GrPixel;
205
206 private:
207    bool DoTheLoadingJob();
208    void ComputeRLEInfo();
209    void ComputeJPEGFragmentInfo();
210    bool     ReadTag(uint16_t, uint16_t);
211    uint32_t ReadTagLength(uint16_t, uint16_t);
212    void ReadAndSkipEncapsulatedBasicOffsetTable();
213
214    Res VerfCriterion(int typeCriterion, double criterionNew, Res const & res);
215    double CalculLikelyhood2Vec(vector3D const & refA, vector3D const & refB, 
216                               vector3D const & ori1, vector3D const & ori2);
217    vector3D ProductVectorial(vector3D const & vec1, vector3D const & vec2);
218 };
219 } // end namespace gdcm
220
221 //-----------------------------------------------------------------------------
222 #endif