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