]> Creatis software - gdcm.git/blob - src/gdcmFile.h
ENH: Get rid of -Wall / -W / -pedantic if present this should get rid of the warnings...
[gdcm.git] / src / gdcmFile.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmFile.h,v $
5   Language:  C++
6   Date:      $Date: 2004/12/03 14:22:40 $
7   Version:   $Revision: 1.82 $
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 "gdcmPixelReadConvert.h"
25 #include "gdcmPixelWriteConvert.h"
26 #include "gdcmDocEntryArchive.h"
27
28 namespace gdcm 
29 {
30 //-----------------------------------------------------------------------------
31 /*
32  * In addition to Dicom header exploration, this class is designed
33  * for accessing the image/volume content. One can also use it to
34  * write Dicom/ACR-NEMA/RAW files.
35  */
36 class GDCM_EXPORT File
37 {
38 public:
39    enum WriteMode
40    {
41       WMODE_DECOMPRESSED,
42       WMODE_RGB
43    };
44      
45 public:
46    File( Header* header );
47    File( std::string const& filename );
48  
49    virtual ~File();
50
51    /// Accessor to \ref Header
52    Header* GetHeader() { return HeaderInternal; }
53
54    size_t GetImageDataSize();
55    size_t GetImageDataRawSize();
56
57    uint8_t* GetImageData();
58    uint8_t* GetImageDataRaw();
59    size_t GetImageDataIntoVector(void* destination, size_t maxSize);
60
61    bool SetImageData (uint8_t* data, size_t expectedSize);
62
63    // Write pixels of ONE image on hard drive
64    // No test is made on processor "endianity"
65    // The user must call his reader correctly
66    bool WriteRawData  (std::string const& fileName);
67    bool WriteDcmImplVR(std::string const& fileName);
68    bool WriteDcmExplVR(std::string const& fileName);
69    bool WriteAcr      (std::string const& fileName);
70    bool Write(std::string const& fileName);
71
72    virtual bool SetEntryByNumber(std::string const& content,
73                                  uint16_t group, uint16_t element)
74    { 
75       HeaderInternal->SetEntryByNumber(content,group,element);
76       return true;
77    }
78    uint8_t* GetLutRGBA();
79
80    // Write mode
81    void SetWriteModeToDecompressed() { SetWriteMode(WMODE_DECOMPRESSED); };
82    void SetWriteModeToRGB()          { SetWriteMode(WMODE_RGB); };
83    void SetWriteMode(WriteMode mode) { WriteMode = mode; };
84    WriteMode GetWriteMode()          { return WriteMode; };
85
86    // Write format
87    void SetWriteTypeToDcmImplVR()     { SetWriteType(ImplicitVR); };
88    void SetWriteTypeToDcmExplVR()     { SetWriteType(ExplicitVR); };
89    void SetWriteTypeToAcr()           { SetWriteType(ACR); };
90    void SetWriteTypeToAcrLibido()     { SetWriteType(ACR_LIBIDO); };
91    void SetWriteType(FileType format) { WriteType = format; };
92    FileType GetWriteType()            { return WriteType; };
93
94 protected:
95    bool WriteBase(std::string const& fileName);
96    bool CheckWriteIntegrity();
97
98    void SetWriteToDecompressed();
99    void SetWriteToRGB();
100    void RestoreWrite();
101
102    void SetWriteFileTypeToACR();
103    void SetWriteFileTypeToExplicitVR();
104    void SetWriteFileTypeToImplicitVR();
105    void RestoreWriteFileType();
106
107    void SetWriteToLibido();
108    void SetWriteToNoLibido();
109    void RestoreWriteOfLibido();
110
111    ValEntry* CopyValEntry(uint16_t group,uint16_t element);
112    BinEntry* CopyBinEntry(uint16_t group,uint16_t element);
113
114 private:
115    void Initialise();
116
117    uint8_t* GetDecompressed();
118    int ComputeDecompressedPixelDataSizeFromHeader();
119
120 private:
121 // members variables:
122
123    /// Header to use to load the file
124    Header *HeaderInternal;
125
126    /// \brief Whether the underlying \ref Header was loaded by
127    ///  the constructor or passed to the constructor. When false
128    ///  the destructor is in charge of deletion.
129    bool SelfHeader;
130    
131    /// Wether already parsed or not
132    bool Parsed;
133
134    /// Utility pixel converter
135    PixelReadConvert* PixelReadConverter;
136    PixelWriteConvert* PixelWriteConverter;
137
138    // Utility header archive
139    DocEntryArchive *Archive;
140
141    // Write variables
142    WriteMode WriteMode;
143    FileType WriteType;
144 };
145 } // end namespace gdcm
146
147 //-----------------------------------------------------------------------------
148 #endif