]> Creatis software - gdcm.git/blob - src/gdcmFile.h
First stage of name normalisation : gdcm::File replace by gdcm::FileHelper
[gdcm.git] / src / gdcmFile.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmFile.h,v $
5   Language:  C++
6   Date:      $Date: 2005/01/20 16:17:00 $
7   Version:   $Revision: 1.96 $
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 <iostream>
23 #include "gdcmBase.h"
24
25 namespace gdcm 
26 {
27 class Header;
28 class ValEntry;
29 class BinEntry;
30 class PixelReadConvert;
31 class PixelWriteConvert;
32 class DocEntryArchive;
33 //-----------------------------------------------------------------------------
34 /**
35  * \brief In addition to Dicom Header exploration, this class is designed
36  * for accessing the image/volume content. One can also use it to
37  * write Dicom/ACR-NEMA/RAW files.
38  */
39 class GDCM_EXPORT FileHelper : public Base
40 {
41 public:
42    enum FileMode
43    {
44       WMODE_RAW,
45       WMODE_RGB
46    };
47      
48 public:
49    FileHelper( );
50    FileHelper( Header *header );
51    FileHelper( std::string const &filename );
52  
53    virtual ~FileHelper();
54
55    void Print(std::ostream &os = std::cout, std::string const & indent = ""); 
56
57    /// Accessor to \ref Header
58    Header *GetHeader() { return HeaderInternal; }
59
60    size_t GetImageDataSize();
61    size_t GetImageDataRawSize();
62
63    uint8_t *GetImageData();
64    uint8_t *GetImageDataRaw();
65    size_t GetImageDataIntoVector(void *destination, size_t maxSize);
66
67    void SetImageData(uint8_t *data, size_t expectedSize);
68
69    // User datas
70    void SetUserData(uint8_t *data, size_t expectedSize);
71    uint8_t* GetUserData();
72    size_t GetUserDataSize();
73    // RBG datas (from file
74    uint8_t* GetRGBData();
75    size_t GetRGBDataSize();
76    // RAW datas (from file
77    uint8_t* GetRawData();
78    size_t GetRawDataSize();
79
80    // Write pixels of ONE image on hard drive
81    // No test is made on processor "endianity"
82    // The user must call his reader correctly
83    bool WriteRawData  (std::string const &fileName);
84    bool WriteDcmImplVR(std::string const &fileName);
85    bool WriteDcmExplVR(std::string const &fileName);
86    bool WriteAcr      (std::string const &fileName);
87    bool Write         (std::string const &fileName);
88
89    bool SetEntry(std::string const &content,
90                  uint16_t group, uint16_t elem);
91    bool SetEntry(uint8_t *content, int lgth,
92                  uint16_t group, uint16_t elem);
93    bool ReplaceOrCreate(std::string const &content,
94                         uint16_t group, uint16_t elem);
95    bool ReplaceOrCreate(uint8_t *binArea, int lgth,
96                         uint16_t group, uint16_t elem);
97
98    uint8_t* GetLutRGBA();
99
100    // Write mode
101    void SetWriteModeToRaw() { SetWriteMode(WMODE_RAW); };
102    void SetWriteModeToRGB()          { SetWriteMode(WMODE_RGB); };
103    void SetWriteMode(FileMode mode)  { WriteMode = mode; };
104    FileMode GetWriteMode()           { return WriteMode; };
105
106    // Write format
107    void SetWriteTypeToDcmImplVR()     { SetWriteType(ImplicitVR); };
108    void SetWriteTypeToDcmExplVR()     { SetWriteType(ExplicitVR); };
109    void SetWriteTypeToAcr()           { SetWriteType(ACR); };
110    void SetWriteTypeToAcrLibido()     { SetWriteType(ACR_LIBIDO); };
111    void SetWriteType(FileType format) { WriteType = format; };
112    FileType GetWriteType()            { return WriteType; };
113
114 protected:
115    bool CheckWriteIntegrity();
116
117    void SetWriteToRaw();
118    void SetWriteToRGB();
119    void RestoreWrite();
120
121    void SetWriteFileTypeToACR();
122    void SetWriteFileTypeToExplicitVR();
123    void SetWriteFileTypeToImplicitVR();
124    void RestoreWriteFileType();
125
126    void SetWriteToLibido();
127    void SetWriteToNoLibido();
128    void RestoreWriteOfLibido();
129
130    ValEntry *CopyValEntry(uint16_t group,uint16_t elem);
131    BinEntry *CopyBinEntry(uint16_t group,uint16_t elem);
132
133 private:
134    void Initialise();
135
136    uint8_t *GetRaw();
137
138 // members variables:
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