]> Creatis software - gdcm.git/blob - src/gdcmFile.h
* vtk/vtkGdcmWriter.[h|cxx] : add a first version of vtkGdcmWriter
[gdcm.git] / src / gdcmFile.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmFile.h,v $
5   Language:  C++
6   Date:      $Date: 2004/12/07 17:28:50 $
7   Version:   $Revision: 1.85 $
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( );
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    bool SetImageData (uint8_t* data, size_t expectedSize);
65
66    // Write pixels of ONE image on hard drive
67    // No test is made on processor "endianity"
68    // The user must call his reader correctly
69    bool WriteRawData  (std::string const& fileName);
70    bool WriteDcmImplVR(std::string const& fileName);
71    bool WriteDcmExplVR(std::string const& fileName);
72    bool WriteAcr      (std::string const& fileName);
73    bool Write(std::string const& fileName);
74
75    bool SetEntryByNumber(std::string const& content,
76                          uint16_t group, uint16_t element);
77    bool SetEntryByNumber(uint8_t* content, int lgth,
78                          uint16_t group, uint16_t element);
79    bool ReplaceOrCreateByNumber(std::string const& content,
80                                 uint16_t group, uint16_t element);
81    bool ReplaceOrCreateByNumber(uint8_t* binArea, int lgth,
82                                 uint16_t group, uint16_t elem);
83
84    uint8_t* GetLutRGBA();
85
86    // Write mode
87    void SetWriteModeToDecompressed() { SetWriteMode(WMODE_DECOMPRESSED); };
88    void SetWriteModeToRGB()          { SetWriteMode(WMODE_RGB); };
89    void SetWriteMode(FileMode mode)  { WriteMode = mode; };
90    FileMode GetWriteMode()           { return WriteMode; };
91
92    // Write format
93    void SetWriteTypeToDcmImplVR()     { SetWriteType(ImplicitVR); };
94    void SetWriteTypeToDcmExplVR()     { SetWriteType(ExplicitVR); };
95    void SetWriteTypeToAcr()           { SetWriteType(ACR); };
96    void SetWriteTypeToAcrLibido()     { SetWriteType(ACR_LIBIDO); };
97    void SetWriteType(FileType format) { WriteType = format; };
98    FileType GetWriteType()            { return WriteType; };
99
100 protected:
101    bool WriteBase(std::string const& fileName);
102    bool CheckWriteIntegrity();
103
104    void SetWriteToDecompressed();
105    void SetWriteToRGB();
106    void RestoreWrite();
107
108    void SetWriteFileTypeToACR();
109    void SetWriteFileTypeToExplicitVR();
110    void SetWriteFileTypeToImplicitVR();
111    void RestoreWriteFileType();
112
113    void SetWriteToLibido();
114    void SetWriteToNoLibido();
115    void RestoreWriteOfLibido();
116
117    ValEntry* CopyValEntry(uint16_t group,uint16_t element);
118    BinEntry* CopyBinEntry(uint16_t group,uint16_t element);
119
120 private:
121    void Initialise();
122
123    uint8_t* GetDecompressed();
124    int ComputeDecompressedPixelDataSizeFromHeader();
125
126 private:
127 // members variables:
128
129    /// Header to use to load the file
130    Header *HeaderInternal;
131
132    /// \brief Whether the underlying \ref Header was loaded by
133    ///  the constructor or passed to the constructor. When false
134    ///  the destructor is in charge of deletion.
135    bool SelfHeader;
136    
137    /// Wether already parsed or not
138    bool Parsed;
139
140    /// Utility pixel converter
141    PixelReadConvert* PixelReadConverter;
142    PixelWriteConvert* PixelWriteConverter;
143
144    // Utility header archive
145    DocEntryArchive *Archive;
146
147    // Write variables
148    FileMode WriteMode;
149    FileType WriteType;
150 };
151 } // end namespace gdcm
152
153 //-----------------------------------------------------------------------------
154 #endif