1 /*=========================================================================
4 Module: $RCSfile: gdcmFileHelper.h,v $
6 Date: $Date: 2005/07/30 18:27:00 $
7 Version: $Revision: 1.20 $
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.
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.
17 =========================================================================*/
19 #ifndef GDCMFILEHELPER_H
20 #define GDCMFILEHELPER_H
22 #include "gdcmDebug.h"
34 class PixelReadConvert;
35 class PixelWriteConvert;
36 class DocEntryArchive;
38 typedef void (*VOID_FUNCTION_PUINT8_PFILE_POINTER)(uint8_t *, File *);
40 //-----------------------------------------------------------------------------
42 * \brief In addition to Dicom header exploration, this class is designed
43 * for accessing the image/volume content. One can also use it to
44 * write Dicom/ACR-NEMA/RAW files.
46 class GDCM_EXPORT FileHelper : public Base
57 FileHelper( File *header );
58 GDCM_LEGACY(FileHelper( std::string const &filename ));
60 virtual ~FileHelper();
62 void Print(std::ostream &os = std::cout, std::string const &indent = "");
64 /// Accessor to \ref File
65 File *GetFile() { return FileInternal; }
68 void SetLoadMode(int loadMode);
69 void SetFileName(std::string const &fileName);
71 /// to allow user user to modify pixel order (Mirror, TopDown, 90°Rotate,...)
72 void SetUserFunction( VOID_FUNCTION_PUINT8_PFILE_POINTER userFunc )
73 { UserFunction = userFunc; }
75 bool SetValEntry(std::string const &content,
76 uint16_t group, uint16_t elem);
77 bool SetBinEntry(uint8_t *content, int lgth,
78 uint16_t group, uint16_t elem);
80 ValEntry *InsertValEntry(std::string const &content,
81 uint16_t group, uint16_t elem);
82 BinEntry *InsertBinEntry(uint8_t *binArea, int lgth,
83 uint16_t group, uint16_t elem);
84 SeqEntry *InsertSeqEntry(uint16_t group, uint16_t elem);
87 size_t GetImageDataSize();
88 size_t GetImageDataRawSize();
90 uint8_t *GetImageData();
91 uint8_t *GetImageDataRaw();
92 size_t GetImageDataIntoVector(void *destination, size_t maxSize);
94 void SetImageData(uint8_t *data, size_t expectedSize);
97 void SetUserData(uint8_t *data, size_t expectedSize);
98 uint8_t *GetUserData();
99 size_t GetUserDataSize();
100 // RBG data (from file)
101 uint8_t *GetRGBData();
102 size_t GetRGBDataSize();
103 // RAW data (from file)
104 uint8_t *GetRawData();
105 size_t GetRawDataSize();
108 uint8_t* GetLutRGBA();
109 int GetLutItemNumber();
110 int GetLutItemSize();
114 /// \brief Tells the writer we want to keep 'Grey pixels + Palettes color'
115 /// when possible (as opposed to convert 'Palettes color' to RGB)
116 void SetWriteModeToRaw() { SetWriteMode(WMODE_RAW); };
117 /// \brief Tells the writer we want to write RGB image when possible
118 /// (as opposed to 'Grey pixels + Palettes color')
119 void SetWriteModeToRGB() { SetWriteMode(WMODE_RGB); };
120 /// \brief Sets the Write Mode ( )
121 void SetWriteMode(FileMode mode) { WriteMode = mode; };
122 /// \brief Gets the Write Mode ( )
123 FileMode GetWriteMode() { return WriteMode; };
127 /// \brief Tells the writer we want to write as Implicit VR
128 void SetWriteTypeToDcmImplVR() { SetWriteType(ImplicitVR); };
129 /// \brief Tells the writer we want to write as Explicit VR
130 void SetWriteTypeToDcmExplVR() { SetWriteType(ExplicitVR); };
131 /// \brief Tells the writer we want to write as ACR-NEMA
132 void SetWriteTypeToAcr() { SetWriteType(ACR); };
133 /// \brief Tells the writer we want to write as LibIDO
134 void SetWriteTypeToAcrLibido() { SetWriteType(ACR_LIBIDO); };
135 /// \brief Tells the writer which format we want to write
136 /// (ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO)
137 void SetWriteType(FileType format) { WriteType = format; };
138 /// \brief Gets the format we talled the write we wanted to write
139 /// (ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO)
140 FileType GetWriteType() { return WriteType; };
142 // Write pixels of ONE image on hard drive
143 // No test is made on processor "endianness"
144 // The user must call his reader correctly
145 bool WriteRawData (std::string const &fileName);
146 bool WriteDcmImplVR(std::string const &fileName);
147 bool WriteDcmExplVR(std::string const &fileName);
148 bool WriteAcr (std::string const &fileName);
149 bool Write (std::string const &fileName);
152 bool CheckWriteIntegrity();
154 void SetWriteToRaw();
155 void SetWriteToRGB();
158 void SetWriteFileTypeToACR();
159 void SetWriteFileTypeToExplicitVR();
160 void SetWriteFileTypeToImplicitVR();
161 void RestoreWriteFileType();
163 void SetWriteToLibido();
164 void SetWriteToNoLibido();
165 void RestoreWriteOfLibido();
167 ValEntry *CopyValEntry(uint16_t group, uint16_t elem);
168 BinEntry *CopyBinEntry(uint16_t group, uint16_t elem,
169 const std::string &vr);
170 void CheckMandatoryElements();
171 void RestoreWriteMandatory();
178 // members variables:
179 /// gdcm::File to use to load the file
182 /// \brief Whether the underlying \ref gdcm::File was loaded by
183 /// the constructor or passed to the constructor.
184 /// When false the destructor is in charge of deletion.
187 /// Whether already parsed or not
190 // Utility pixel converter
191 /// \brief Pointer to the PixelReadConverter
192 PixelReadConvert *PixelReadConverter;
193 /// \brief Pointer to the PixelWriteConverter
194 PixelWriteConvert *PixelWriteConverter;
196 // Utility header archive
197 /// \brief Pointer to the DocEntryArchive (used while writting process)
198 DocEntryArchive *Archive;
201 /// \brief (WMODE_RAW, WMODE_RGB)
203 /// \brief (ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO)
205 /// Pointer to a user supplied function to allow modification of pixel order
206 /// (i.e. : Mirror, TopDown, 90°Rotation, ...)
207 /// use as : void userSuppliedMirrorFunction(uint8_t *im, gdcm::File *f)
208 /// NB : the "uint8_t *" type of first param is just for prototyping.
209 /// User will Cast it according what he founds with f->GetPixelType()
210 /// See ctkgdcmSerieViewer for an example
211 VOID_FUNCTION_PUINT8_PFILE_POINTER UserFunction;
213 } // end namespace gdcm
215 //-----------------------------------------------------------------------------