]> Creatis software - gdcm.git/blob - src/gdcmFile.h
* src/gdcmPixelWriteConvert.[h|cxx] : new class to write datas (and in the
[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 11:55:38 $
7   Version:   $Revision: 1.81 $
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 TWriteMode
40    {
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    uint8_t* GetImageData();
65    uint8_t* GetImageDataRaw();
66    size_t GetImageDataIntoVector(void* destination, size_t maxSize);
67
68    bool SetImageData (uint8_t* data, size_t expectedSize);
69
70    // Write pixels of ONE image on hard drive
71    // No test is made on processor "endianity"
72    // The user must call his reader correctly
73    bool WriteRawData  (std::string const& fileName);
74    bool WriteDcmImplVR(std::string const& fileName);
75    bool WriteDcmExplVR(std::string const& fileName);
76    bool WriteAcr      (std::string const& fileName);
77    bool Write(std::string const& fileName);
78
79    virtual bool SetEntryByNumber(std::string const& content,
80                                  uint16_t group, uint16_t element)
81    { 
82       HeaderInternal->SetEntryByNumber(content,group,element);
83       return true;
84    }
85    uint8_t* GetLutRGBA();
86
87    // Write mode
88    void SetWriteModeToDecompressed()    { SetWriteMode(WMODE_DECOMPRESSED); };
89    void SetWriteModeToRGB()             { SetWriteMode(WMODE_RGB); };
90    void SetWriteMode(unsigned int mode) { WriteMode = mode; };
91    unsigned int GetWriteMode()          { return WriteMode; };
92
93    // Write format
94    void SetWriteTypeToDcmImplVR()         { SetWriteType(WTYPE_EXPL_VR); };
95    void SetWriteTypeToDcmExplVR()         { SetWriteType(WTYPE_EXPL_VR); };
96    void SetWriteTypeToAcr()               { SetWriteType(WTYPE_ACR); };
97    void SetWriteType(unsigned int format) { WriteType = format; };
98    unsigned int GetWriteType()            { return WriteType; };
99
100 protected:
101    bool WriteBase(std::string const& fileName, FileType type);
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    unsigned int WriteMode;
149    unsigned int WriteType;
150 };
151 } // end namespace gdcm
152
153 //-----------------------------------------------------------------------------
154 #endif