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