1 /*=========================================================================
4 Module: $RCSfile: gdcmFileHelper.h,v $
6 Date: $Date: 2007/09/04 13:14:33 $
7 Version: $Revision: 1.54 $
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; }
65 /// \brief Tells gdcm wether we want to keep ACR-NEMA-like overlays or not.
66 void SetKeepOverlays(bool k) { KeepOverlays =k; }
67 bool GetKeepOverlays( ) { return KeepOverlays; }
69 void SetLoadMode(int loadMode);
70 void SetFileName(std::string const &fileName);
72 /// to allow user to modify pixel order (e.g. Mirror, UpsideDown,...)
73 void SetUserFunction( VOID_FUNCTION_PUINT8_PFILE_POINTER userFunc )
74 { UserFunction = userFunc; }
76 bool SetEntryString(std::string const &content,
77 uint16_t group, uint16_t elem);
78 bool SetEntryBinArea(uint8_t *content, int lgth,
79 uint16_t group, uint16_t elem);
81 DataEntry *InsertEntryString(std::string const &content,
82 uint16_t group, uint16_t elem, const VRKey &vr);
83 DataEntry *InsertEntryBinArea(uint8_t *binArea, int lgth,
84 uint16_t group, uint16_t elem, const VRKey &vr);
85 SeqEntry *InsertSeqEntry(uint16_t group, uint16_t elem);
88 size_t GetImageDataSize();
89 size_t GetImageDataRawSize();
91 uint8_t *GetImageData();
92 uint8_t *GetImageDataRaw();
94 // GDCM_LEGACY(size_t GetImageDataIntoVector(void *destination,size_t maxSize))
96 void SetImageData(uint8_t *data, size_t expectedSize);
99 void SetUserData(uint8_t *data, size_t expectedSize);
100 uint8_t *GetUserData();
101 size_t GetUserDataSize();
102 // RBG data (from file)
103 uint8_t *GetRGBData();
104 size_t GetRGBDataSize();
105 // RAW data (from file)
106 uint8_t *GetRawData();
107 size_t GetRawDataSize();
109 void ConvertFixGreyLevels(uint8_t *data, size_t size);
112 uint8_t* GetLutRGBA();
113 int GetLutItemNumber();
114 int GetLutItemSize();
118 /// \brief Tells the writer we want to keep 'Grey pixels + Palettes color'
119 /// when possible (as opposed to convert 'Palettes color' to RGB)
120 void SetWriteModeToRaw() { SetWriteMode(WMODE_RAW); }
121 /// \brief Tells the writer we want to write RGB image when possible
122 /// (as opposed to 'Grey pixels + Palettes color')
123 void SetWriteModeToRGB() { SetWriteMode(WMODE_RGB); }
124 /// \brief Sets the Write Mode ( )
125 void SetWriteMode(FileMode mode) { WriteMode = mode; }
126 /// \brief Gets the Write Mode ( )
127 FileMode GetWriteMode() { return WriteMode; }
131 /// \brief Tells the writer we want to write as Implicit VR
132 void SetWriteTypeToDcmImplVR() { SetWriteType(ImplicitVR); }
133 /// \brief Tells the writer we want to write as Explicit VR
134 void SetWriteTypeToDcmExplVR() { SetWriteType(ExplicitVR); }
135 /// \brief Tells the writer we want to write as ACR-NEMA
136 void SetWriteTypeToAcr() { SetWriteType(ACR); }
137 /// \brief Tells the writer we want to write as LibIDO
138 void SetWriteTypeToAcrLibido() { SetWriteType(ACR_LIBIDO); }
139 /// \brief Tells the writer we want to write as JPEG
140 void SetWriteTypeToJPEG() { SetWriteType(JPEG); }
141 /// \brief Tells the writer we want to write as JPEG2000
142 void SetWriteTypeToJPEG2000() { SetWriteType(JPEG2000); }
143 /// \brief Tells the writer which format we want to write
144 /// (ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO)
145 void SetWriteType(FileType format) { WriteType = format; }
146 /// \brief Gets the format we talled the write we wanted to write
147 /// (ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO)
148 FileType GetWriteType() { return WriteType; }
149 /// \brief 1 : white=0, black=high value
150 void SetPhotometricInterpretationToMonochrome1() {
151 PhotometricInterpretation = 1;}
152 /// \brief 2 : black=0, white=high value (default)
153 void SetPhotometricInterpretationToMonochrome2() {
154 PhotometricInterpretation = 2;}
155 /// \brief 1 : white=0, black=high value
156 int GetPhotometricInterpretation() {
157 return PhotometricInterpretation; }
159 // Write pixels of ONE image on hard drive
160 // No test is made on processor "endianness"
161 // The user must call his reader correctly
162 bool WriteRawData (std::string const &fileName);
163 bool WriteDcmImplVR(std::string const &fileName);
164 bool WriteDcmExplVR(std::string const &fileName);
165 bool WriteAcr (std::string const &fileName);
166 bool Write (std::string const &fileName);
168 /// \brief We have to deal with 4 *very* different cases :
169 /// -1) user created ex nihilo his own image and wants to write it as a Dicom image.
171 /// -2) user modified the pixels of an existing image.
173 /// -3) user created a new image, using existing images (eg MIP, MPR, cartography image)
175 /// -4) user modified/added some tags *without processing* the pixels (anonymization...
176 /// UNMODIFIED_PIXELS_IMAGE
178 void SetContentType (ImageContentType c) { ContentType = c; }
179 // no GetContentType() method, on purpose!
181 void CallStartMethod();
182 void CallProgressMethod();
183 void CallEndMethod();
187 FileHelper( File *header );
190 /// \todo move all those 'protected' methods to 'private'
191 /// since FileHelper is not derived in anything!
192 bool CheckWriteIntegrity();
194 void SetWriteToRaw();
195 void SetWriteToRGB();
198 void SetWriteFileTypeToACR();
199 void SetWriteFileTypeToJPEG();
200 void SetWriteFileTypeToJPEG2000();
201 void SetWriteFileTypeToExplicitVR();
202 void SetWriteFileTypeToImplicitVR();
203 void RestoreWriteFileType();
205 void SetWriteToLibido();
206 void SetWriteToNoLibido();
207 void RestoreWriteOfLibido();
209 DataEntry *CopyDataEntry(uint16_t group, uint16_t elem,
210 const VRKey &vr = GDCM_VRUNKNOWN);
211 void CheckMandatoryElements();
212 void CheckMandatoryEntry(uint16_t group, uint16_t elem, std::string value,
213 const VRKey &vr = GDCM_VRUNKNOWN);
214 void SetMandatoryEntry(uint16_t group, uint16_t elem, std::string value,
215 const VRKey &vr = GDCM_VRUNKNOWN);
216 void CopyMandatoryEntry(uint16_t group, uint16_t elem, std::string value,
217 const VRKey &vr = GDCM_VRUNKNOWN);
218 void RestoreWriteMandatory();
225 // members variables:
227 /// value of the ??? for any progress bar
233 /// gdcm::File to use to load the file
236 /// Whether already parsed or not
239 // Utility pixel converter
241 /// \brief Pointer to the PixelReadConverter
242 PixelReadConvert *PixelReadConverter;
244 /// \brief Pointer to the PixelWriteConverter
245 PixelWriteConvert *PixelWriteConverter;
247 // Utility header archive
248 /// \brief Pointer to the DocEntryArchive (used while writting process)
249 DocEntryArchive *Archive;
252 /// \brief (WMODE_RAW, WMODE_RGB)
255 /// \brief (ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO)
258 /// \brief Pointer to a user supplied function to allow modification
259 /// of pixel order (e.g. : Mirror, UpsideDown, 90°Rotation, ...)
260 /// use as : void userSuppliedFunction(uint8_t *im, gdcm::File *f)
261 /// NB : the "uint8_t *" type of first param is just for prototyping.
262 /// User will Cast it according what he founds with f->GetPixelType()
263 /// See vtkgdcmSerieViewer for an example
264 VOID_FUNCTION_PUINT8_PFILE_POINTER UserFunction;
266 /// \brief only user knows what he did before asking the image to be written
267 /// - he created ex nihilo his own image
268 /// - he just applied a mathematical process on the pixels
269 /// - he created a new image, using existing images (eg MIP, MPR,cartography)
270 /// - he anonymized and image (*no* modif on the pixels)
271 ImageContentType ContentType;
273 /// \brief 1 : white=0, black=high value
274 /// 2 : black=0, white=high value (default)
275 int PhotometricInterpretation;
277 /// \brief wether we want to keep ACR-NEMA-like overlays or not.
281 } // end namespace gdcm
283 //-----------------------------------------------------------------------------