]> Creatis software - gdcm.git/blob - src/gdcmFileHelper.h
Doxygenation
[gdcm.git] / src / gdcmFileHelper.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmFileHelper.h,v $
5   Language:  C++
6   Date:      $Date: 2005/07/08 14:36:48 $
7   Version:   $Revision: 1.18 $
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 GDCMFILEHELPER_H
20 #define GDCMFILEHELPER_H
21
22 #include <iostream>
23 #include "gdcmBase.h"
24
25 namespace gdcm 
26 {
27 class File;
28 class ValEntry;
29 class BinEntry;
30 class SeqEntry;
31 class PixelReadConvert;
32 class PixelWriteConvert;
33 class DocEntryArchive;
34 //-----------------------------------------------------------------------------
35 /**
36  * \brief In addition to Dicom header exploration, this class is designed
37  * for accessing the image/volume content. One can also use it to
38  * write Dicom/ACR-NEMA/RAW files.
39  */
40 class GDCM_EXPORT FileHelper : public Base
41 {
42 public:
43    enum FileMode
44    {
45       WMODE_RAW,
46       WMODE_RGB
47    };
48      
49 public:
50    FileHelper( );
51    FileHelper( File *header );
52    FileHelper( std::string const &filename );
53    
54    virtual ~FileHelper();
55
56    void Print(std::ostream &os = std::cout, std::string const &indent = ""); 
57
58    /// Accessor to \ref File
59    File *GetFile() { return FileInternal; }
60    
61
62    void SetLoadMode(int loadMode);
63    void SetFileName(std::string const &fileName);
64    bool Load();
65    
66    // File methods
67    bool SetValEntry(std::string const &content,
68                     uint16_t group, uint16_t elem);
69    bool SetBinEntry(uint8_t *content, int lgth,
70                     uint16_t group, uint16_t elem);
71
72    ValEntry *InsertValEntry(std::string const &content,
73                             uint16_t group, uint16_t elem);
74    BinEntry *InsertBinEntry(uint8_t *binArea, int lgth,
75                             uint16_t group, uint16_t elem);
76    SeqEntry *InsertSeqEntry(uint16_t group, uint16_t elem);
77
78    // File helpers
79    size_t GetImageDataSize();
80    size_t GetImageDataRawSize();
81
82    uint8_t *GetImageData();
83    uint8_t *GetImageDataRaw();
84    size_t GetImageDataIntoVector(void *destination, size_t maxSize);
85
86    void SetImageData(uint8_t *data, size_t expectedSize);
87
88    // User data
89    void SetUserData(uint8_t *data, size_t expectedSize);
90    uint8_t *GetUserData();
91    size_t GetUserDataSize();
92    // RBG data (from file)
93    uint8_t *GetRGBData();
94    size_t GetRGBDataSize();
95    // RAW data (from file)
96    uint8_t *GetRawData();
97    size_t GetRawDataSize();
98
99    // LUT
100    uint8_t* GetLutRGBA();
101    int GetLutItemNumber();
102    int GetLutItemSize();
103
104    // Write mode
105
106    /// \brief Tells the writer we want to keep 'Grey pixels + Palettes color'
107    ///        when possible (as opposed to convert 'Palettes color' to RGB)
108   void SetWriteModeToRaw()            { SetWriteMode(WMODE_RAW);  };
109    /// \brief Tells the writer we want to write RGB image when possible
110    ///        (as opposed to 'Grey pixels + Palettes color')
111    void SetWriteModeToRGB()           { SetWriteMode(WMODE_RGB);  };
112    /// \brief Sets the Write Mode ( )
113    void SetWriteMode(FileMode mode)   { WriteMode = mode;         };
114    /// \brief Gets the Write Mode ( )
115    FileMode GetWriteMode()            { return WriteMode;         };
116
117    // Write format
118
119    /// \brief Tells the writer we want to write as Implicit VR
120    void SetWriteTypeToDcmImplVR()     { SetWriteType(ImplicitVR); };
121    /// \brief Tells the writer we want to write as Explicit VR
122    void SetWriteTypeToDcmExplVR()     { SetWriteType(ExplicitVR); };
123    /// \brief Tells the writer we want to write as ACR-NEMA
124    void SetWriteTypeToAcr()           { SetWriteType(ACR);        };
125    /// \brief Tells the writer we want to write as LibIDO
126    void SetWriteTypeToAcrLibido()     { SetWriteType(ACR_LIBIDO); };
127    /// \brief Tells the writer which format we want to write
128    /// (ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO)
129    void SetWriteType(FileType format) { WriteType = format;       };
130    /// \brief Gets the format we talled the write we wanted to write
131    ///   (ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO)
132    FileType GetWriteType()            { return WriteType;         };
133
134    // Write pixels of ONE image on hard drive
135    // No test is made on processor "endianness"
136    // The user must call his reader correctly
137    bool WriteRawData  (std::string const &fileName);
138    bool WriteDcmImplVR(std::string const &fileName);
139    bool WriteDcmExplVR(std::string const &fileName);
140    bool WriteAcr      (std::string const &fileName);
141    bool Write         (std::string const &fileName);
142
143 protected:
144    bool CheckWriteIntegrity();
145
146    void SetWriteToRaw();
147    void SetWriteToRGB();
148    void RestoreWrite();
149
150    void SetWriteFileTypeToACR();
151    void SetWriteFileTypeToExplicitVR();
152    void SetWriteFileTypeToImplicitVR();
153    void RestoreWriteFileType();
154
155    void SetWriteToLibido();
156    void SetWriteToNoLibido();
157    void RestoreWriteOfLibido();
158
159    ValEntry *CopyValEntry(uint16_t group, uint16_t elem);
160    BinEntry *CopyBinEntry(uint16_t group, uint16_t elem, 
161                           const std::string &vr);
162    void CheckMandatoryElements();
163    void RestoreWriteMandatory();
164
165 private:
166    void Initialize();
167
168    uint8_t *GetRaw();
169
170 // members variables:
171    /// gdcm::File to use to load the file
172    File *FileInternal;
173
174    /// \brief Whether the underlying \ref gdcm::File was loaded by
175    ///  the constructor or passed to the constructor. 
176    ///  When false the destructor is in charge of deletion.
177    bool SelfHeader;
178    
179    /// Wether already parsed or not
180    bool Parsed;
181
182    // Utility pixel converter
183    /// \brief Pointer to the PixelReadConverter
184    PixelReadConvert *PixelReadConverter;
185    /// \brief Pointer to the PixelWriteConverter
186    PixelWriteConvert *PixelWriteConverter;
187
188    // Utility header archive
189    /// \brief Pointer to the DocEntryArchive (used while writting process)
190    DocEntryArchive *Archive;
191
192    // Write variables
193    /// \brief (WMODE_RAW, WMODE_RGB)
194    FileMode WriteMode;
195    /// \brief (ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO)
196    FileType WriteType;
197 };
198 } // end namespace gdcm
199
200 //-----------------------------------------------------------------------------
201 #endif