]> Creatis software - gdcm.git/blob - src/gdcmFile.h
* src/gdcmDocEntryArchive.cxx : complete the print function, that prints
[gdcm.git] / src / gdcmFile.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmFile.h,v $
5   Language:  C++
6   Date:      $Date: 2004/11/23 11:14:13 $
7   Version:   $Revision: 1.73 $
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 "gdcmCommon.h"
23 #include "gdcmHeader.h"
24 #include "gdcmPixelConvert.h"
25 #include "gdcmDocEntryArchive.h"
26
27 namespace gdcm 
28 {
29 //-----------------------------------------------------------------------------
30 /*
31  * In addition to Dicom header exploration, this class is designed
32  * for accessing the image/volume content. One can also use it to
33  * write Dicom/ACR-NEMA/RAW files.
34  */
35 class GDCM_EXPORT File
36 {
37 public:
38    enum TWriteMode
39    {
40       WMODE_NATIVE,
41       WMODE_DECOMPRESSED,
42       WMODE_RGB
43    };
44      
45    enum TWriteType
46    {
47       WTYPE_IMPL_VR,
48       WTYPE_EXPL_VR,
49       WTYPE_ACR
50    };
51      
52 public:
53    File( Header* header );
54    File( std::string const& filename );
55  
56    virtual ~File();
57
58    /// Accessor to \ref Header
59    Header* GetHeader() { return HeaderInternal; }
60
61    /// Accessor to \ref ImageDataSize
62    size_t GetImageDataSize() { return ImageDataSize; };
63
64    /// Accessor to \ref ImageDataSizeRaw
65    size_t GetImageDataSizeRaw() { return ImageDataSizeRaw; };
66
67    /// Accessor to \ref PixelConverter
68    PixelConvert* GetPixelConverter() { return PixelConverter; };
69
70    uint8_t* GetImageData();
71    size_t GetImageDataIntoVector(void* destination, size_t maxSize);
72    uint8_t* GetImageDataRaw();
73
74    // see also Header::SetImageDataSize ?!?         
75    bool SetImageData (uint8_t* data, size_t expectedSize);
76
77    // Write pixels of ONE image on hard drive
78    // No test is made on processor "endianity"
79    // The user must call his reader correctly
80    bool WriteRawData  (std::string const& fileName);
81    bool WriteDcmImplVR(std::string const& fileName);
82    bool WriteDcmExplVR(std::string const& fileName);
83    bool WriteAcr      (std::string const& fileName);
84    bool Write(std::string const& fileName);
85
86    virtual bool SetEntryByNumber(std::string const& content,
87                                  uint16_t group, uint16_t element)
88    { 
89       HeaderInternal->SetEntryByNumber(content,group,element);
90       return true;
91    }
92    uint8_t* GetLutRGBA();
93
94    // Write mode
95    void SetWriteModeToNative()          { SetWriteMode(WMODE_NATIVE); };
96    void SetWriteModeToDecompressed()    { SetWriteMode(WMODE_DECOMPRESSED); };
97    void SetWriteModeToRGB()             { SetWriteMode(WMODE_RGB); };
98    void SetWriteMode(unsigned int mode) { WriteMode = mode; };
99    unsigned int GetWriteMode()          { return WriteMode; };
100
101    // Write format
102    void SetWriteTypeToDcmImplVR()         { SetWriteType(WTYPE_EXPL_VR); };
103    void SetWriteTypeToDcmExplVR()         { SetWriteType(WTYPE_EXPL_VR); };
104    void SetWriteTypeToAcr()               { SetWriteType(WTYPE_ACR); };
105    void SetWriteType(unsigned int format) { WriteType = format; };
106    unsigned int GetWriteType()            { return WriteType; };
107
108 protected:
109    bool WriteBase(std::string const& fileName, FileType type);
110
111    void SetWriteToNative();
112    void SetWriteToDecompressed();
113    void SetWriteToRGB();
114    void RestoreWrite();
115
116    void SetWriteToLibido();
117    void RestoreWriteFromLibido();
118
119    ValEntry* CopyValEntry(uint16_t group,uint16_t element);
120    BinEntry* CopyBinEntry(uint16_t group,uint16_t element);
121
122 private:
123    void Initialise();
124
125    void SaveInitialValues();    // will belong to the future PixelData class
126    void RestoreInitialValues(); // will belong to the future PixelData class
127    void DeleteInitialValues();  // will belong to the future PixelData class 
128    uint8_t* GetDecompressed();
129    int ComputeDecompressedPixelDataSizeFromHeader();
130
131 private:
132    void SetPixelData(uint8_t* data);
133
134 // members variables:
135
136    /// Header to use to load the file
137    Header *HeaderInternal;
138
139    /// \brief Whether the underlying \ref Header was loaded by
140    ///  the constructor or passed to the constructor. When false
141    ///  the destructor is in charge of deletion.
142    bool SelfHeader;
143    
144    /// Wether already parsed or not
145    bool Parsed;
146
147    /// Utility pixel converter
148    PixelConvert* PixelConverter;
149
150    // Utility header archive
151    DocEntryArchive *Archive;
152
153    // Write variables
154    unsigned int WriteMode;
155    unsigned int WriteType;
156
157 /// FIXME
158 // --------------- Will be moved to a PixelData class
159 //
160
161    /// \brief to hold the Pixels (when read)
162    uint8_t* Pixel_Data;  // (was PixelData)
163    
164    /// \brief Size (in bytes) of required memory to hold the Gray Level pixels
165    ///        represented in this file. This is used when the user DOESN'T want
166    ///        the RGB pixels image when it's stored as a PALETTE COLOR image
167    size_t ImageDataSizeRaw;
168    
169    /// \brief Size (in bytes) of requited memory to hold the the pixels
170    ///        of this image in it's RGB convertion either from:
171    ///        - Plane R, Plane G, Plane B 
172    ///        - Grey Plane + Palette Color
173    ///        - YBR Pixels (or from RGB Pixels, as well) 
174    size_t ImageDataSize;
175        
176   /// \brief ==1  if GetImageDataRaw was used
177   ///        ==0  if GetImageData    was used
178   ///        ==-1 if ImageData never read                       
179    int PixelRead;
180
181   /// \brief length of the last allocated area devoided to receive Pixels
182   ///        ( to allow us not to (free + new) if un necessary )     
183    size_t LastAllocatedPixelDataLength; 
184
185   // Initial values of some fields that can be modified during reading process
186   // if user asked to transform gray level + LUT image into RGB image
187      
188   /// \brief Samples Per Pixel           (0x0028,0x0002), as found on disk
189    std::string InitialSpp;
190   /// \brief Photometric Interpretation  (0x0028,0x0004), as found on disk
191    std::string InitialPhotInt;
192   /// \brief Planar Configuration        (0x0028,0x0006), as found on disk   
193    std::string InitialPlanConfig;
194     
195   // Initial values of some fields that can be modified during reading process
196   // if the image was a 'strange' ACR-NEMA 
197   // (Bits Allocated=12, High Bit not equal to Bits stored +1) 
198   /// \brief Bits Allocated              (0x0028,0x0100), as found on disk
199    std::string InitialBitsAllocated;
200   /// \brief High Bit                    (0x0028,0x0102), as found on disk
201    std::string InitialHighBit;
202   
203   // some DocEntry that can be moved out of the H table during reading process
204   // if user asked to transform gray level + LUT image into RGB image
205   // We keep a pointer on them for a future use.
206      
207   /// \brief Red Palette Color Lookup Table Descriptor   0028 1101 as read
208   DocEntry* InitialRedLUTDescr;  
209   /// \brief Green Palette Color Lookup Table Descriptor 0028 1102 as read
210   DocEntry* InitialGreenLUTDescr;
211   /// \brief Blue Palette Color Lookup Table Descriptor  0028 1103 as read
212   DocEntry* InitialBlueLUTDescr;
213   
214   /// \brief Red Palette Color Lookup Table Data         0028 1201 as read
215   DocEntry* InitialRedLUTData;  
216   /// \brief Green Palette Color Lookup Table Data       0028 1202 as read
217   DocEntry* InitialGreenLUTData;
218   /// \brief Blue Palette Color Lookup Table Data        0028 1203 as read
219   DocEntry* InitialBlueLUTData;
220   
221 //
222 // --------------- end of future PixelData class
223 //  
224
225 };
226 } // end namespace gdcm
227
228 //-----------------------------------------------------------------------------
229 #endif