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