]> Creatis software - gdcm.git/blob - src/gdcmFile.h
* src/gdcmFile.cxx : Add the code of ReplaceOrCreateByNumber to not have
[gdcm.git] / src / gdcmFile.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmFile.h,v $
5   Language:  C++
6   Date:      $Date: 2004/12/16 10:51:49 $
7   Version:   $Revision: 1.87 $
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_RAW,
44       WMODE_RGB
45    };
46      
47 public:
48    File( );
49    File( Header* header );
50    File( std::string const& filename );
51  
52    virtual ~File();
53
54    /// Accessor to \ref Header
55    Header* GetHeader() { return HeaderInternal; }
56
57    size_t GetImageDataSize();
58    size_t GetImageDataRawSize();
59
60    uint8_t* GetImageData();
61    uint8_t* GetImageDataRaw();
62    size_t GetImageDataIntoVector(void* destination, size_t maxSize);
63
64    void SetImageData(uint8_t* data, size_t expectedSize);
65
66    // User datas
67    void SetUserData(uint8_t* data, size_t expectedSize);
68    uint8_t* GetUserData();
69    size_t GetUserDataSize();
70    // RBG datas (from file
71    uint8_t* GetRGBData();
72    size_t GetRGBDataSize();
73    // RAW datas (from file
74    uint8_t* GetRawData();
75    size_t GetRawDataSize();
76
77    // Write pixels of ONE image on hard drive
78    // No test is made on processor "endianity"
79    // The user must call his reader correctly
80    bool WriteRawData  (std::string const& fileName);
81    bool WriteDcmImplVR(std::string const& fileName);
82    bool WriteDcmExplVR(std::string const& fileName);
83    bool WriteAcr      (std::string const& fileName);
84    bool Write(std::string const& fileName);
85
86    bool SetEntryByNumber(std::string const& content,
87                          uint16_t group, uint16_t element);
88    bool SetEntryByNumber(uint8_t* content, int lgth,
89                          uint16_t group, uint16_t element);
90    bool ReplaceOrCreateByNumber(std::string const& content,
91                                 uint16_t group, uint16_t element);
92    bool ReplaceOrCreateByNumber(uint8_t* binArea, int lgth,
93                                 uint16_t group, uint16_t element);
94
95    uint8_t* GetLutRGBA();
96
97    // Write mode
98    void SetWriteModeToRaw() { SetWriteMode(WMODE_RAW); };
99    void SetWriteModeToRGB()          { SetWriteMode(WMODE_RGB); };
100    void SetWriteMode(FileMode mode)  { WriteMode = mode; };
101    FileMode GetWriteMode()           { return WriteMode; };
102
103    // Write format
104    void SetWriteTypeToDcmImplVR()     { SetWriteType(ImplicitVR); };
105    void SetWriteTypeToDcmExplVR()     { SetWriteType(ExplicitVR); };
106    void SetWriteTypeToAcr()           { SetWriteType(ACR); };
107    void SetWriteTypeToAcrLibido()     { SetWriteType(ACR_LIBIDO); };
108    void SetWriteType(FileType format) { WriteType = format; };
109    FileType GetWriteType()            { return WriteType; };
110
111 protected:
112    bool WriteBase(std::string const& fileName);
113    bool CheckWriteIntegrity();
114
115    void SetWriteToRaw();
116    void SetWriteToRGB();
117    void RestoreWrite();
118
119    void SetWriteFileTypeToACR();
120    void SetWriteFileTypeToExplicitVR();
121    void SetWriteFileTypeToImplicitVR();
122    void RestoreWriteFileType();
123
124    void SetWriteToLibido();
125    void SetWriteToNoLibido();
126    void RestoreWriteOfLibido();
127
128    ValEntry* CopyValEntry(uint16_t group,uint16_t element);
129    BinEntry* CopyBinEntry(uint16_t group,uint16_t element);
130
131 private:
132    void Initialise();
133
134    uint8_t* GetRaw();
135
136 private:
137 // members variables:
138
139    /// Header to use to load the file
140    Header *HeaderInternal;
141
142    /// \brief Whether the underlying \ref Header was loaded by
143    ///  the constructor or passed to the constructor. When false
144    ///  the destructor is in charge of deletion.
145    bool SelfHeader;
146    
147    /// Wether already parsed or not
148    bool Parsed;
149
150    /// Utility pixel converter
151    PixelReadConvert* PixelReadConverter;
152    PixelWriteConvert* PixelWriteConverter;
153
154    // Utility header archive
155    DocEntryArchive *Archive;
156
157    // Write variables
158    FileMode WriteMode;
159    FileType WriteType;
160 };
161 } // end namespace gdcm
162
163 //-----------------------------------------------------------------------------
164 #endif