1 /*=========================================================================
4 Module: $RCSfile: gdcmFileHelper.h,v $
6 Date: $Date: 2007/05/23 14:18:10 $
7 Version: $Revision: 1.47 $
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"
23 #include "gdcmRefCounter.h"
24 #include "gdcmVRKey.h"
27 namespace GDCM_NAME_SPACE
32 class PixelReadConvert;
33 class PixelWriteConvert;
34 class DocEntryArchive;
36 typedef void (*VOID_FUNCTION_PUINT8_PFILE_POINTER)(uint8_t *, File *);
38 //-----------------------------------------------------------------------------
40 * \brief In addition to Dicom header exploration, this class is designed
41 * for accessing the image/volume content. One can also use it to
42 * write Dicom/ACR-NEMA/RAW files.
44 class GDCM_EXPORT FileHelper : public RefCounter
46 gdcmTypeMacro(FileHelper);
55 /// \brief Constructs a FileHelper with a RefCounter
56 static FileHelper *New() {return new FileHelper();}
57 /// \brief Constructs a FileHelper with a RefCounter from a fileHelper
58 static FileHelper *New(File *header) {return new FileHelper(header);}
60 void Print(std::ostream &os = std::cout, std::string const &indent = "");
62 /// Accessor to \ref File
63 File *GetFile() { return FileInternal; }
66 void SetLoadMode(int loadMode);
67 void SetFileName(std::string const &fileName);
69 /// to allow user to modify pixel order (e.g. Mirror, UpsideDown,...)
70 void SetUserFunction( VOID_FUNCTION_PUINT8_PFILE_POINTER userFunc )
71 { UserFunction = userFunc; }
73 bool SetEntryString(std::string const &content,
74 uint16_t group, uint16_t elem);
75 bool SetEntryBinArea(uint8_t *content, int lgth,
76 uint16_t group, uint16_t elem);
78 DataEntry *InsertEntryString(std::string const &content,
79 uint16_t group, uint16_t elem, const VRKey &vr);
80 DataEntry *InsertEntryBinArea(uint8_t *binArea, int lgth,
81 uint16_t group, uint16_t elem, const VRKey &vr);
82 SeqEntry *InsertSeqEntry(uint16_t group, uint16_t elem);
85 size_t GetImageDataSize();
86 size_t GetImageDataRawSize();
88 uint8_t *GetImageData();
89 uint8_t *GetImageDataRaw();
91 // GDCM_LEGACY(size_t GetImageDataIntoVector(void *destination,size_t maxSize))
93 void SetImageData(uint8_t *data, size_t expectedSize);
96 void SetUserData(uint8_t *data, size_t expectedSize);
97 uint8_t *GetUserData();
98 size_t GetUserDataSize();
99 // RBG data (from file)
100 uint8_t *GetRGBData();
101 size_t GetRGBDataSize();
102 // RAW data (from file)
103 uint8_t *GetRawData();
104 size_t GetRawDataSize();
107 uint8_t* GetLutRGBA();
108 int GetLutItemNumber();
109 int GetLutItemSize();
113 /// \brief Tells the writer we want to keep 'Grey pixels + Palettes color'
114 /// when possible (as opposed to convert 'Palettes color' to RGB)
115 void SetWriteModeToRaw() { SetWriteMode(WMODE_RAW); }
116 /// \brief Tells the writer we want to write RGB image when possible
117 /// (as opposed to 'Grey pixels + Palettes color')
118 void SetWriteModeToRGB() { SetWriteMode(WMODE_RGB); }
119 /// \brief Sets the Write Mode ( )
120 void SetWriteMode(FileMode mode) {
122 // Deal with Samples per Pixel
123 //if (mode == WMODE_RGB) FileInternal->InsertEntryString("3",0x0028,0x0002);
125 /// \brief Gets the Write Mode ( )
126 FileMode GetWriteMode() { return WriteMode; }
130 /// \brief Tells the writer we want to write as Implicit VR
131 void SetWriteTypeToDcmImplVR() { SetWriteType(ImplicitVR); }
132 /// \brief Tells the writer we want to write as Explicit VR
133 void SetWriteTypeToDcmExplVR() { SetWriteType(ExplicitVR); }
134 /// \brief Tells the writer we want to write as ACR-NEMA
135 void SetWriteTypeToAcr() { SetWriteType(ACR); }
136 /// \brief Tells the writer we want to write as LibIDO
137 void SetWriteTypeToAcrLibido() { SetWriteType(ACR_LIBIDO); }
138 /// \brief Tells the writer we want to write as JPEG
139 void SetWriteTypeToJPEG() { SetWriteType(JPEG); }
140 /// \brief Tells the writer we want to write as JPEG2000
141 void SetWriteTypeToJPEG2000() { SetWriteType(JPEG2000); }
142 /// \brief Tells the writer which format we want to write
143 /// (ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO)
144 void SetWriteType(FileType format) { WriteType = format; }
145 /// \brief Gets the format we talled the write we wanted to write
146 /// (ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO)
147 FileType GetWriteType() { return WriteType; }
149 // Write pixels of ONE image on hard drive
150 // No test is made on processor "endianness"
151 // The user must call his reader correctly
152 bool WriteRawData (std::string const &fileName);
153 bool WriteDcmImplVR(std::string const &fileName);
154 bool WriteDcmExplVR(std::string const &fileName);
155 bool WriteAcr (std::string const &fileName);
156 bool Write (std::string const &fileName);
158 /// \brief We have to deal with 4 *very* different cases :
159 /// -1) user created ex nihilo his own image and wants to write it as a Dicom image.
161 /// -2) user modified the pixels of an existing image.
163 /// -3) user created a new image, using existing images (eg MIP, MPR, cartography image)
165 /// -4) user modified/added some tags *without processing* the pixels (anonymization...
166 /// UNMODIFIED_PIXELS_IMAGE
168 void SetContentType (ImageContentType c) { ContentType = c; }
169 // no GetContentType() method, on purpose!
171 void CallStartMethod();
172 void CallProgressMethod();
173 void CallEndMethod();
177 FileHelper( File *header );
180 bool CheckWriteIntegrity();
182 void SetWriteToRaw();
183 void SetWriteToRGB();
186 void SetWriteFileTypeToACR();
187 void SetWriteFileTypeToJPEG();
188 void SetWriteFileTypeToJPEG2000();
189 void SetWriteFileTypeToExplicitVR();
190 void SetWriteFileTypeToImplicitVR();
191 void RestoreWriteFileType();
193 void SetWriteToLibido();
194 void SetWriteToNoLibido();
195 void RestoreWriteOfLibido();
197 DataEntry *CopyDataEntry(uint16_t group, uint16_t elem,
198 const VRKey &vr = GDCM_VRUNKNOWN);
199 void CheckMandatoryElements();
200 void CheckMandatoryEntry(uint16_t group, uint16_t elem, std::string value,
201 const VRKey &vr = GDCM_VRUNKNOWN);
202 void SetMandatoryEntry(uint16_t group, uint16_t elem, std::string value,
203 const VRKey &vr = GDCM_VRUNKNOWN);
204 void CopyMandatoryEntry(uint16_t group, uint16_t elem, std::string value,
205 const VRKey &vr = GDCM_VRUNKNOWN);
206 void RestoreWriteMandatory();
213 // members variables:
215 /// value of the ??? for any progress bar
221 /// gdcm::File to use to load the file
224 /// Whether already parsed or not
227 // Utility pixel converter
228 /// \brief Pointer to the PixelReadConverter
229 PixelReadConvert *PixelReadConverter;
230 /// \brief Pointer to the PixelWriteConverter
231 PixelWriteConvert *PixelWriteConverter;
233 // Utility header archive
234 /// \brief Pointer to the DocEntryArchive (used while writting process)
235 DocEntryArchive *Archive;
238 /// \brief (WMODE_RAW, WMODE_RGB)
241 /// \brief (ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO)
244 /// \brief Pointer to a user supplied function to allow modification
245 /// of pixel order (e.g. : Mirror, UpsideDown, 90°Rotation, ...)
246 /// use as : void userSuppliedFunction(uint8_t *im, gdcm::File *f)
247 /// NB : the "uint8_t *" type of first param is just for prototyping.
248 /// User will Cast it according what he founds with f->GetPixelType()
249 /// See vtkgdcmSerieViewer for an example
250 VOID_FUNCTION_PUINT8_PFILE_POINTER UserFunction;
252 /// \brief only user knows what he did before asking the image to be written
253 /// - he created ex nihilo his own image
254 /// - he just applied a mathematical process on the pixels
255 /// - he created a new image, using existing images (eg MIP, MPR,cartography)
256 /// - he anonymized and image (*no* modif on the pixels)
257 ImageContentType ContentType;
260 } // end namespace gdcm
262 //-----------------------------------------------------------------------------