1 /*=========================================================================
4 Module: $RCSfile: gdcmFileHelper.h,v $
6 Date: $Date: 2005/10/18 18:39:49 $
7 Version: $Revision: 1.25 $
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"
31 class PixelReadConvert;
32 class PixelWriteConvert;
33 class DocEntryArchive;
35 typedef void (*VOID_FUNCTION_PUINT8_PFILE_POINTER)(uint8_t *, File *);
37 //-----------------------------------------------------------------------------
39 * \brief In addition to Dicom header exploration, this class is designed
40 * for accessing the image/volume content. One can also use it to
41 * write Dicom/ACR-NEMA/RAW files.
43 class GDCM_EXPORT FileHelper : public Base
54 FileHelper( File *header );
55 GDCM_LEGACY(FileHelper( std::string const &filename ));
57 virtual ~FileHelper();
59 void Print(std::ostream &os = std::cout, std::string const &indent = "");
61 /// Accessor to \ref File
62 File *GetFile() { return FileInternal; }
65 void SetLoadMode(int loadMode);
66 void SetFileName(std::string const &fileName);
68 /// to allow user to modify pixel order (e.g. Mirror, TopDown,...)
69 void SetUserFunction( VOID_FUNCTION_PUINT8_PFILE_POINTER userFunc )
70 { UserFunction = userFunc; }
72 bool SetEntryString(std::string const &content,
73 uint16_t group, uint16_t elem);
74 bool SetEntryBinArea(uint8_t *content, int lgth,
75 uint16_t group, uint16_t elem);
77 DataEntry *InsertEntryString(std::string const &content,
78 uint16_t group, uint16_t elem);
79 DataEntry *InsertEntryBinArea(uint8_t *binArea, int lgth,
80 uint16_t group, uint16_t elem);
81 SeqEntry *InsertSeqEntry(uint16_t group, uint16_t elem);
84 size_t GetImageDataSize();
85 size_t GetImageDataRawSize();
87 uint8_t *GetImageData();
88 uint8_t *GetImageDataRaw();
90 GDCM_LEGACY(size_t GetImageDataIntoVector(void *destination,size_t maxSize));
92 void SetImageData(uint8_t *data, size_t expectedSize);
95 void SetUserData(uint8_t *data, size_t expectedSize);
96 uint8_t *GetUserData();
97 size_t GetUserDataSize();
98 // RBG data (from file)
99 uint8_t *GetRGBData();
100 size_t GetRGBDataSize();
101 // RAW data (from file)
102 uint8_t *GetRawData();
103 size_t GetRawDataSize();
106 uint8_t* GetLutRGBA();
107 int GetLutItemNumber();
108 int GetLutItemSize();
112 /// \brief Tells the writer we want to keep 'Grey pixels + Palettes color'
113 /// when possible (as opposed to convert 'Palettes color' to RGB)
114 void SetWriteModeToRaw() { SetWriteMode(WMODE_RAW); }
115 /// \brief Tells the writer we want to write RGB image when possible
116 /// (as opposed to 'Grey pixels + Palettes color')
117 void SetWriteModeToRGB() { SetWriteMode(WMODE_RGB); }
118 /// \brief Sets the Write Mode ( )
119 void SetWriteMode(FileMode mode) { WriteMode = mode; }
120 /// \brief Gets the Write Mode ( )
121 FileMode GetWriteMode() { return WriteMode; }
125 /// \brief Tells the writer we want to write as Implicit VR
126 void SetWriteTypeToDcmImplVR() { SetWriteType(ImplicitVR); }
127 /// \brief Tells the writer we want to write as Explicit VR
128 void SetWriteTypeToDcmExplVR() { SetWriteType(ExplicitVR); }
129 /// \brief Tells the writer we want to write as ACR-NEMA
130 void SetWriteTypeToAcr() { SetWriteType(ACR); }
131 /// \brief Tells the writer we want to write as LibIDO
132 void SetWriteTypeToAcrLibido() { SetWriteType(ACR_LIBIDO); }
133 void SetWriteTypeToJPEG() { SetWriteType(JPEG); }
134 /// \brief Tells the writer which format we want to write
135 /// (ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO)
136 void SetWriteType(FileType format) { WriteType = format; }
137 /// \brief Gets the format we talled the write we wanted to write
138 /// (ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO)
139 FileType GetWriteType() { return WriteType; }
141 // Write pixels of ONE image on hard drive
142 // No test is made on processor "endianness"
143 // The user must call his reader correctly
144 bool WriteRawData (std::string const &fileName);
145 bool WriteDcmImplVR(std::string const &fileName);
146 bool WriteDcmExplVR(std::string const &fileName);
147 bool WriteAcr (std::string const &fileName);
148 bool Write (std::string const &fileName);
151 bool CheckWriteIntegrity();
153 void SetWriteToRaw();
154 void SetWriteToRGB();
157 void SetWriteFileTypeToACR();
158 void SetWriteFileTypeToExplicitVR();
159 void SetWriteFileTypeToImplicitVR();
160 void RestoreWriteFileType();
162 void SetWriteToLibido();
163 void SetWriteToNoLibido();
164 void RestoreWriteOfLibido();
166 DataEntry *CopyDataEntry(uint16_t group, uint16_t elem,
167 const TagName &vr = GDCM_VRUNKNOWN);
168 void CheckMandatoryElements();
169 void CheckMandatoryEntry(uint16_t group,uint16_t elem,std::string value);
170 void SetMandatoryEntry(uint16_t group,uint16_t elem,std::string value);
171 void CopyMandatoryEntry(uint16_t group,uint16_t elem,std::string value);
172 void RestoreWriteMandatory();
179 // members variables:
180 /// gdcm::File to use to load the file
183 /// \brief Whether the underlying \ref gdcm::File was loaded by
184 /// the constructor or passed to the constructor.
185 /// When false the destructor is in charge of deletion.
188 /// Whether already parsed or not
191 // Utility pixel converter
192 /// \brief Pointer to the PixelReadConverter
193 PixelReadConvert *PixelReadConverter;
194 /// \brief Pointer to the PixelWriteConverter
195 PixelWriteConvert *PixelWriteConverter;
197 // Utility header archive
198 /// \brief Pointer to the DocEntryArchive (used while writting process)
199 DocEntryArchive *Archive;
202 /// \brief (WMODE_RAW, WMODE_RGB)
204 /// \brief (ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO)
206 /// Pointer to a user supplied function to allow modification of pixel order
207 /// (i.e. : Mirror, TopDown, 90°Rotation, ...)
208 /// use as : void userSuppliedFunction(uint8_t *im, gdcm::File *f)
209 /// NB : the "uint8_t *" type of first param is just for prototyping.
210 /// User will Cast it according what he founds with f->GetPixelType()
211 /// See vtkgdcmSerieViewer for an example
212 VOID_FUNCTION_PUINT8_PFILE_POINTER UserFunction;
214 } // end namespace gdcm
216 //-----------------------------------------------------------------------------