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