18 #include "vtkImageCanvasSource2D.h"
19 #include "vtkImageReader2.h"
20 #include "vtkJPEGReader.h"
21 #include "vtkTIFFReader.h"
22 #include "vtkPNGReader.h"
23 #include "vtkImageWriter.h"
24 #include "vtkJPEGWriter.h"
25 #include "vtkTIFFWriter.h"
26 #include "vtkPNGWriter.h"
27 #include "vtkPointData.h"
28 #include "vtkUnsignedCharArray.h"
32 int cmp_nocase(
const std::string& s,
const std::string& s2)
34 std::string::const_iterator p = s.begin();
35 std::string::const_iterator p2 = s2.begin();
36 while (p != s.end() && p2 != s2.end())
38 if (toupper(*p) != toupper(*p2))
39 return (toupper(*p) < toupper(*p2)) ? -1 : 1;
43 return (s2.size() == s.size()) ? 0 : (s.size() < s2.size()) ? -1 : 1;
48 std::string ext =
name.substr(
name.find_last_of(
'.')+1,
name.size());
51 in = (vtkImageReader2 *)vtkTIFFReader::New();
53 in = (vtkImageReader2 *)vtkJPEGReader::New();
55 in = (vtkImageReader2 *)vtkPNGReader::New();
57 in->SetFileName(
name.c_str());
59 in_ =
in->GetOutput();
67 std::string ext =
name.substr(
name.find_last_of(
'.')+1,
name.size());
68 vtkImageWriter * writer;
70 writer = vtkTIFFWriter::New();
72 writer = vtkJPEGWriter::New();
74 writer = vtkPNGWriter::New();
75 writer->SetFileName(
name.c_str());
76 writer->SetInputData(
out_);
103 int xn = int(
round(xn0));
104 int yn = int(
round(yn0));
110 xn = int(
round(xn0));
111 yn = int(
round(yn0));
121 int xn = int(
round(xn0));
122 int yn = int(
round(yn0));
128 xn = int(
round(xn0));
129 yn = int(
round(yn0));
141 vtkImageCanvasSource2D * out = vtkImageCanvasSource2D::New();
142 out->SetScalarTypeToUnsignedChar();
143 out->SetNumberOfScalarComponents(3);
144 out->SetExtent(0,maxx,0,maxy,0,0);
145 out->SetDrawColor(0,0,0);
146 out->FillBox(0,(
int)maxx,0,(
int)maxy);
147 out_ = out->GetOutput();
159 vtkUnsignedCharArray * scal_in = (vtkUnsignedCharArray *)(
in_->GetPointData()->GetScalars());
160 vtkUnsignedCharArray * scal_out = (vtkUnsignedCharArray *)(
out_->GetPointData()->GetScalars());
162 for (
int c = 0; c < 3; c++)
174 int v1 = (int)scal_in->GetComponent(tix+tiy*(
box_in_[1]+1),c);
175 int v2 = (int)scal_in->GetComponent(tix+1+tiy*(
box_in_[1]+1),c);
176 int v3 = (int)scal_in->GetComponent(tix+(tiy+1)*(
box_in_[1]+1),c);
177 int v4 = (int)scal_in->GetComponent(tix+1+(tiy+1)*(
box_in_[1]+1),c);
178 double val0 = v1+(v2-v1)*dx+(v3-v1)*dy+(v1+v4-v2-v3)*dx*dy;
179 int val= int(val0+.5);
180 int ref = (int)(x-
xm)+((int)(y-
ym))*((
int)maxx+1);
181 scal_out->InsertComponent(ref,c,(
unsigned char)val);
int cmp_nocase(const std::string &s, const std::string &s2)
void box_out_reset()
reset the value of the bounding box
virtual bool old_coordinates(double xn, double yn, double &xo, double &yo)=0
gives the pixel coordinates in the input image in function of the pixel coordinates in the output ima...
void yM(const int val)
impose the size of the output bounding box
void xm(const int val)
impose the size of the output bounding box
void write(const std::string &name)
write the processed image to a file
void deform()
deform the image
void xM(const int val)
impose the size of the output bounding box
virtual void new_coordinates(double xo, double yo, double &xn, double &yn)=0
gives the pixel coordinates in the output image in function of the pixel coordinates in the input ima...
virtual void read(const std::string &name)
read the image to be processed
virtual void box_out()
compute the bounding box of the new image
void ym(const int val)
impose the size of the output bounding box