]> Creatis software - gdcm.git/blob - src/gdcmFile.h
* src/gdcmBinEntry.cxx, gdcmSeqEntry.cxx, gdcmSQItem.cxx, gdcmValEntry.cxx :
[gdcm.git] / src / gdcmFile.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmFile.h,v $
5   Language:  C++
6   Date:      $Date: 2004/11/24 16:39:18 $
7   Version:   $Revision: 1.75 $
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();
63    /// Accessor to \ref ImageDataSizeRaw
64    size_t GetImageDataSizeRaw();
65
66    /// Accessor to \ref PixelConverter
67    PixelConvert* GetPixelConverter() { return PixelConverter; };
68
69    uint8_t* GetImageData();
70    size_t GetImageDataIntoVector(void* destination, size_t maxSize);
71    uint8_t* GetImageDataRaw();
72
73    // see also Header::SetImageDataSize ?!?         
74    bool SetImageData (uint8_t* data, size_t expectedSize);
75
76    // Write pixels of ONE image on hard drive
77    // No test is made on processor "endianity"
78    // The user must call his reader correctly
79    bool WriteRawData  (std::string const& fileName);
80    bool WriteDcmImplVR(std::string const& fileName);
81    bool WriteDcmExplVR(std::string const& fileName);
82    bool WriteAcr      (std::string const& fileName);
83    bool Write(std::string const& fileName);
84
85    virtual bool SetEntryByNumber(std::string const& content,
86                                  uint16_t group, uint16_t element)
87    { 
88       HeaderInternal->SetEntryByNumber(content,group,element);
89       return true;
90    }
91    uint8_t* GetLutRGBA();
92
93    // Write mode
94    void SetWriteModeToNative()          { SetWriteMode(WMODE_NATIVE); };
95    void SetWriteModeToDecompressed()    { SetWriteMode(WMODE_DECOMPRESSED); };
96    void SetWriteModeToRGB()             { SetWriteMode(WMODE_RGB); };
97    void SetWriteMode(unsigned int mode) { WriteMode = mode; };
98    unsigned int GetWriteMode()          { return WriteMode; };
99
100    // Write format
101    void SetWriteTypeToDcmImplVR()         { SetWriteType(WTYPE_EXPL_VR); };
102    void SetWriteTypeToDcmExplVR()         { SetWriteType(WTYPE_EXPL_VR); };
103    void SetWriteTypeToAcr()               { SetWriteType(WTYPE_ACR); };
104    void SetWriteType(unsigned int format) { WriteType = format; };
105    unsigned int GetWriteType()            { return WriteType; };
106
107 protected:
108    bool WriteBase(std::string const& fileName, FileType type);
109
110    void SetWriteToNative();
111    void SetWriteToDecompressed();
112    void SetWriteToRGB();
113    void RestoreWrite();
114
115    void SetWriteToLibido();
116    void RestoreWriteFromLibido();
117
118    ValEntry* CopyValEntry(uint16_t group,uint16_t element);
119    BinEntry* CopyBinEntry(uint16_t group,uint16_t element);
120
121 private:
122    void Initialise();
123
124    void SaveInitialValues();    // will belong to the future PixelData class
125    uint8_t* GetDecompressed();
126    int ComputeDecompressedPixelDataSizeFromHeader();
127
128 private:
129    void SetPixelData(uint8_t* data);
130
131 // members variables:
132
133    /// Header to use to load the file
134    Header *HeaderInternal;
135
136    /// \brief Whether the underlying \ref Header was loaded by
137    ///  the constructor or passed to the constructor. When false
138    ///  the destructor is in charge of deletion.
139    bool SelfHeader;
140    
141    /// Wether already parsed or not
142    bool Parsed;
143
144    /// Utility pixel converter
145    PixelConvert* PixelConverter;
146
147    // Utility header archive
148    DocEntryArchive *Archive;
149
150    // Write variables
151    unsigned int WriteMode;
152    unsigned int WriteType;
153
154 /// FIXME
155 // --------------- Will be moved to a PixelData class
156 //
157
158    /// \brief to hold the Pixels (when read)
159    uint8_t* Pixel_Data;  // (was PixelData)
160    
161    /// \brief Size (in bytes) of required memory to hold the Gray Level pixels
162    ///        represented in this file. This is used when the user DOESN'T want
163    ///        the RGB pixels image when it's stored as a PALETTE COLOR image
164    size_t ImageDataSizeRaw;
165    
166    /// \brief Size (in bytes) of requited memory to hold the the pixels
167    ///        of this image in it's RGB convertion either from:
168    ///        - Plane R, Plane G, Plane B 
169    ///        - Grey Plane + Palette Color
170    ///        - YBR Pixels (or from RGB Pixels, as well) 
171    size_t ImageDataSize;
172        
173   /// \brief ==1  if GetImageDataRaw was used
174   ///        ==0  if GetImageData    was used
175   ///        ==-1 if ImageData never read                       
176    int PixelRead;
177
178 //
179 // --------------- end of future PixelData class
180 //  
181
182 };
183 } // end namespace gdcm
184
185 //-----------------------------------------------------------------------------
186 #endif