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