]> Creatis software - gdcm.git/blob - src/gdcmFile.h
* src/gdcmFile.[h|cxx] : add the Print method
[gdcm.git] / src / gdcmFile.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmFile.h,v $
5   Language:  C++
6   Date:      $Date: 2004/12/16 11:37:03 $
7   Version:   $Revision: 1.88 $
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 "gdcmCommon.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  * 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 File
40 {
41 public:
42    enum FileMode
43    {
44       WMODE_RAW,
45       WMODE_RGB
46    };
47      
48 public:
49    File( );
50    File( Header* header );
51    File( std::string const& filename );
52  
53    virtual ~File();
54
55    void Print(std::ostream &os = std::cout); 
56    /// Accessor to \ref PrintLevel
57    void SetPrintLevel(int level) { PrintLevel = level; }
58
59    /// Accessor to \ref Header
60    Header* GetHeader() { return HeaderInternal; }
61
62    size_t GetImageDataSize();
63    size_t GetImageDataRawSize();
64
65    uint8_t* GetImageData();
66    uint8_t* GetImageDataRaw();
67    size_t GetImageDataIntoVector(void* destination, size_t maxSize);
68
69    void SetImageData(uint8_t* data, size_t expectedSize);
70
71    // User datas
72    void SetUserData(uint8_t* data, size_t expectedSize);
73    uint8_t* GetUserData();
74    size_t GetUserDataSize();
75    // RBG datas (from file
76    uint8_t* GetRGBData();
77    size_t GetRGBDataSize();
78    // RAW datas (from file
79    uint8_t* GetRawData();
80    size_t GetRawDataSize();
81
82    // Write pixels of ONE image on hard drive
83    // No test is made on processor "endianity"
84    // The user must call his reader correctly
85    bool WriteRawData  (std::string const& fileName);
86    bool WriteDcmImplVR(std::string const& fileName);
87    bool WriteDcmExplVR(std::string const& fileName);
88    bool WriteAcr      (std::string const& fileName);
89    bool Write(std::string const& fileName);
90
91    bool SetEntryByNumber(std::string const& content,
92                          uint16_t group, uint16_t element);
93    bool SetEntryByNumber(uint8_t* content, int lgth,
94                          uint16_t group, uint16_t element);
95    bool ReplaceOrCreateByNumber(std::string const& content,
96                                 uint16_t group, uint16_t element);
97    bool ReplaceOrCreateByNumber(uint8_t* binArea, int lgth,
98                                 uint16_t group, uint16_t element);
99
100    uint8_t* GetLutRGBA();
101
102    // Write mode
103    void SetWriteModeToRaw() { SetWriteMode(WMODE_RAW); };
104    void SetWriteModeToRGB()          { SetWriteMode(WMODE_RGB); };
105    void SetWriteMode(FileMode mode)  { WriteMode = mode; };
106    FileMode GetWriteMode()           { return WriteMode; };
107
108    // Write format
109    void SetWriteTypeToDcmImplVR()     { SetWriteType(ImplicitVR); };
110    void SetWriteTypeToDcmExplVR()     { SetWriteType(ExplicitVR); };
111    void SetWriteTypeToAcr()           { SetWriteType(ACR); };
112    void SetWriteTypeToAcrLibido()     { SetWriteType(ACR_LIBIDO); };
113    void SetWriteType(FileType format) { WriteType = format; };
114    FileType GetWriteType()            { return WriteType; };
115
116 protected:
117    bool WriteBase(std::string const& fileName);
118    bool CheckWriteIntegrity();
119
120    void SetWriteToRaw();
121    void SetWriteToRGB();
122    void RestoreWrite();
123
124    void SetWriteFileTypeToACR();
125    void SetWriteFileTypeToExplicitVR();
126    void SetWriteFileTypeToImplicitVR();
127    void RestoreWriteFileType();
128
129    void SetWriteToLibido();
130    void SetWriteToNoLibido();
131    void RestoreWriteOfLibido();
132
133    ValEntry* CopyValEntry(uint16_t group,uint16_t element);
134    BinEntry* CopyBinEntry(uint16_t group,uint16_t element);
135
136    /// \brief Amount of printed details for each Header Entry (Dicom Element):
137    /// 0 : stands for the least detail level.
138    int PrintLevel;
139
140 private:
141    void Initialise();
142
143    uint8_t* GetRaw();
144
145 // members variables:
146    /// Header to use to load the file
147    Header *HeaderInternal;
148
149    /// \brief Whether the underlying \ref Header was loaded by
150    ///  the constructor or passed to the constructor. When false
151    ///  the destructor is in charge of deletion.
152    bool SelfHeader;
153    
154    /// Wether already parsed or not
155    bool Parsed;
156
157    /// Utility pixel converter
158    PixelReadConvert* PixelReadConverter;
159    PixelWriteConvert* PixelWriteConverter;
160
161    // Utility header archive
162    DocEntryArchive *Archive;
163
164    // Write variables
165    FileMode WriteMode;
166    FileType WriteType;
167 };
168 } // end namespace gdcm
169
170 //-----------------------------------------------------------------------------
171 #endif