]> Creatis software - gdcm.git/blob - src/gdcmFile.h
ENH: const'ify gdcmFile thus remove double signature with const char*
[gdcm.git] / src / gdcmFile.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmFile.h,v $
5   Language:  C++
6   Date:      $Date: 2004/06/21 04:52:08 $
7   Version:   $Revision: 1.31 $
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.htm 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
25 //-----------------------------------------------------------------------------
26 /*
27  * In addition to Dicom header exploration, this class is designed
28  * for accessing the image/volume content. One can also use it to
29  * write Dicom/ACR-NEMA/RAW files.
30  */
31 class GDCM_EXPORT gdcmFile
32 {
33 public:
34    gdcmFile(gdcmHeader *header);
35    gdcmFile(std::string const & filename, 
36               bool  exception_on_error = false, 
37               bool  enable_sequences   = false,
38               bool  skip_shadow        = false);
39  
40    virtual ~gdcmFile(void);
41         
42    gdcmHeader *GetHeader(void);
43
44         // For promotion (performs a deepcopy of pointed header object)
45         // TODO Swig gdcmFile(gdcmHeader* header);
46         // TODO Swig ~gdcmFile();
47
48         // On writing purposes. When instance was created through
49         // gdcmFile(std::string filename) then the filename argument MUST be
50         // different from the constructor's one (no overwriting allowed).
51         // TODO Swig int SetFileName(std::string filename);
52
53    void   SetPixelDataSizeFromHeader(void);
54    size_t GetImageDataSize();
55    size_t GetImageDataSizeRaw();
56
57    void * GetImageData();
58    size_t GetImageDataIntoVector(void* destination, size_t MaxSize);
59    void * GetImageDataRaw();
60    size_t GetImageDataIntoVectorRaw(void* destination, size_t MaxSize);
61         
62       // Allocates ExpectedSize bytes of memory at this->Data and copies the
63       // pointed data to it. Copying the image might look useless but
64       // the caller might destroy it's image (without knowing it: think
65       // of a complicated interface where display is done with a library
66       // e.g. VTK) before calling the Write
67       
68    // voir gdcmHeader::SetImageDataSize ?!?         
69    bool SetImageData     (void * Data, size_t ExpectedSize);
70       // When the caller is aware we simply point to the data:
71       // TODO int SetImageDataNoCopy (void * Data, size_t ExpectedSize);
72         
73         // Push to disk.
74         // A NE PAS OUBLIER : que fait-on en cas de Transfert Syntax (dans l'entete)
75         // incohérente avec l'ordre des octets en mémoire ? 
76         // TODO Swig int Write();
77         
78    // Write pixels of ONE image on hard drive
79    // No test is made on processor "endianity"
80    // The user must call his reader correctly
81    bool WriteRawData  (std::string fileName);
82    bool WriteDcmImplVR(std::string fileName);
83    bool WriteDcmImplVR(const char * fileName);
84    bool WriteDcmExplVR(std::string fileName);
85    bool WriteAcr      (std::string fileName);
86
87    // Body in file gdcmParse.cxx
88    bool ParsePixelData(void);
89
90    inline virtual bool SetEntryByNumber(std::string content,
91                                         guint16 group, guint16 element)
92       { GetHeader()->SetEntryByNumber(content,group,element); }
93
94      
95 protected:
96    bool WriteBase(std::string FileName, FileType type);
97
98 private:
99    void SwapZone(void* im, int swap, int lgr, int nb);
100    
101    bool ReadPixelData(void * destination);
102    
103    // For JPEG 8 Bits, body in file gdcmJpeg.cxx
104    bool gdcm_read_JPEG_file     (FILE *fp,void * image_buffer); 
105    static int gdcm_read_RLE_fragment(char **areaToRead, long lengthToDecode, 
106                                      long uncompressedSegmentSize,FILE *fp);
107    // For JPEG 12 Bits, body in file gdcmJpeg12.cxx
108    bool gdcm_read_JPEG_file12   (FILE *fp,void * image_buffer);
109    // For JPEG 2000, body in file gdcmJpeg2000.cxx
110    bool gdcm_read_JPEG2000_file (FILE *fp,void * image_buffer);
111
112    // For Run Length Encoding (TOCHECK)
113    bool gdcm_read_RLE_file      (FILE *fp,void * image_buffer); 
114
115 // Variables
116
117    /// \brief Header to use to load the file
118    gdcmHeader *Header;
119         
120         /// \brief Whether the underlying \ref gdcmHeader was loaded by
121    ///  the constructor or passed to the constructor. When false
122    ///  the destructor is in charge of deletion.
123    bool SelfHeader;
124
125    /// \brief to hold the Pixels (when read)
126    void* PixelData;
127    
128    /// \brief Area length to receive the pixels
129    size_t lgrTotaleRaw;
130    
131    /// \brief Area length to receive the RGB pixels
132    /// from Grey Plane + Palette Color  
133    size_t lgrTotale; 
134        
135   /// \brief ==1  if GetImageDataRaw was used
136   ///        ==0  if GetImageData    was used
137   ///        ==-1 if ImageData never read                       
138    int PixelRead;     
139
140    /// weather already parsed 
141    int Parsed;
142    
143    /// To avoid file overwrite              
144    std::string OrigFileName;    
145 };
146
147 //-----------------------------------------------------------------------------
148 #endif