36 #include "Exception.hpp" 37 #include <boost/filesystem.hpp> 38 #define _BACKWARD_BACKWARD_WARNING_H 1 //Cut out the vtk deprecated warning 39 #include <vtkTIFFReader.h> 40 #include <vtkPNGReader.h> 41 #include <vtkJPEGReader.h> 42 #include <vtkBMPReader.h> 43 #include <vtkImageResize.h> 44 #include <vtkImageLuminance.h> 45 #include "ImageReader.hpp" 77 EXCEPTION(
"No image data has been set.");
98 EXCEPTION(
"Input file not specified for image reader");
100 std::string file_extension = boost::filesystem::extension(
mFilepath);
102 if(file_extension ==
".tif" or file_extension ==
".tiff" or file_extension ==
".TIF" or file_extension ==
".TIFF")
104 vtkSmartPointer<vtkTIFFReader> p_reader = vtkSmartPointer<vtkTIFFReader>::New();
105 p_reader->SetFileName(
mFilepath.c_str());
113 vtkSmartPointer<vtkImageResize> p_resize = vtkSmartPointer<vtkImageResize>::New();
114 p_resize->SetInputConnection(p_reader->GetOutputPort());
116 p_resize->SetResizeMethodToMagnificationFactors();
121 else if(file_extension ==
".png" or file_extension ==
".PNG")
123 vtkSmartPointer<vtkPNGReader> p_reader = vtkSmartPointer<vtkPNGReader>::New();
124 p_reader->SetFileName(
mFilepath.c_str());
130 vtkSmartPointer<vtkImageLuminance> p_lum = vtkSmartPointer<vtkImageLuminance>::New();
131 p_lum->SetInputConnection(p_reader->GetOutputPort());
137 vtkSmartPointer<vtkImageResize> p_resize = vtkSmartPointer<vtkImageResize>::New();
138 p_resize->SetInputConnection(p_reader->GetOutputPort());
140 p_resize->SetResizeMethodToMagnificationFactors();
144 vtkSmartPointer<vtkImageLuminance> p_lum = vtkSmartPointer<vtkImageLuminance>::New();
145 p_lum->SetInputConnection(p_resize->GetOutputPort());
150 else if(file_extension ==
".jpg" or file_extension ==
".JPG")
152 vtkSmartPointer<vtkJPEGReader> p_reader = vtkSmartPointer<vtkJPEGReader>::New();
153 p_reader->SetFileName(
mFilepath.c_str());
161 vtkSmartPointer<vtkImageResize> p_resize = vtkSmartPointer<vtkImageResize>::New();
162 p_resize->SetInputConnection(p_reader->GetOutputPort());
164 p_resize->SetResizeMethodToMagnificationFactors();
169 else if(file_extension ==
".bmp" or file_extension ==
".BMP")
171 vtkSmartPointer<vtkBMPReader> p_reader = vtkSmartPointer<vtkBMPReader>::New();
172 p_reader->SetFileName(
mFilepath.c_str());
180 vtkSmartPointer<vtkImageResize> p_resize = vtkSmartPointer<vtkImageResize>::New();
181 p_resize->SetInputConnection(p_reader->GetOutputPort());
183 p_resize->SetResizeMethodToMagnificationFactors();
190 EXCEPTION(
"Input file extension not recognized");
195 EXCEPTION(
"Image reading failed.");
vtkSmartPointer< vtkImageData > mpVtkImage
void SetFilename(const std::string &rFilename)
void SetImageResizeFactors(double factorX, double factorY=1.0, double factorZ=1.0)
static boost::shared_ptr< ImageReader > Create()
vtkSmartPointer< vtkImageData > GetImage()