34 #include <Base/Common/BIASpragma.hh>
40 #include "MathAlgo/Interpolator.hh"
41 #include "Base/Image/Image.hh"
42 #include "Base/ImageUtils/ImageDraw.hh"
43 #include "Gui/GuiWX.hh"
50 std::vector<double> listT;
51 std::vector<double> listX;
52 std::vector<double> listY;
53 std::vector<Vector2<double> > listControlPoints;
58 t=0; vec[0]=1; vec[1]=599;
59 listT.push_back(t); listControlPoints.push_back(vec);
60 t=50; vec[0]=100; vec[1]=450;
61 listT.push_back(t); listControlPoints.push_back(vec);
62 t=100;vec[0]=200; vec[1]=400;
63 listT.push_back(t); listControlPoints.push_back(vec);
64 t=200; vec[0]=300;vec[1]=400;
65 listT.push_back(t); listControlPoints.push_back(vec);
66 t=300;vec[0]=400;vec[1]=400;
67 listT.push_back(t); listControlPoints.push_back(vec);
68 t=400;vec[0]=500;vec[1]=200;
69 listT.push_back(t); listControlPoints.push_back(vec);
70 t=500;vec[0]=600;vec[1]=100;
71 listT.push_back(t); listControlPoints.push_back(vec);
72 t=600;vec[0]=700; vec[1]=100;
73 listT.push_back(t); listControlPoints.push_back(vec);
74 t=700;vec[0]=600;vec[1]=200;
75 listT.push_back(t); listControlPoints.push_back(vec);
76 t=800;vec[0]=500;vec[1]=400;
77 listT.push_back(t); listControlPoints.push_back(vec);
78 t=900;vec[0]=200;vec[1]=200;
79 listT.push_back(t); listControlPoints.push_back(vec);
91 listT.push_back(t); listY.push_back(y);
93 listT.push_back(t); listY.push_back(y);
95 listT.push_back(t); listY.push_back(y);
97 listT.push_back(t); listY.push_back(y);
99 listT.push_back(t); listY.push_back(y);
101 listT.push_back(t); listY.push_back(y);
103 listT.push_back(t); listY.push_back(y);
105 listT.push_back(t); listY.push_back(y);
107 listT.push_back(t); listY.push_back(y);
109 listT.push_back(t); listY.push_back(y);
111 listT.push_back(t); listY.push_back(y);
181 int main (
int argc,
char **argv)
191 for (
unsigned int i=0;i<listT.size()-1;i++){
193 if(listT[i]>=0 && 600-listY[i]>=0 && listT[i+1]<img.
GetWidth() && 600-listY[i+1]<img.
GetHeight())
195 (
unsigned int)listT[i],
196 600-(
unsigned int)listY[i],
197 (
unsigned int)listT[i+1],
198 600-(
unsigned int)listY[i+1],
201 window.
SetTitle(
string(
"Interpolation Test"));
203 int x0=0, y0=0, x1=0, y1=0, k=3;
207 double startTang=-10000,endTang=-10000;
208 cerr<<
"Press h for help."<<endl;
214 if (startTang==-10000) {
218 cout<<
"startTang:"<<startTang<<endl;
219 cout<<
"endTang:"<<endTang<<endl;
222 if (startTang==-10000) {
226 cout<<
"startTang:"<<startTang<<endl;
227 cout<<
"endTang:"<<endTang<<endl;
231 cout<<
"startTang:"<<startTang<<endl;
232 cout<<
"endTang:"<<endTang<<endl;
235 if (endTang==-10000) {
239 cout<<
"startTang:"<<startTang<<endl;
240 cout<<
"endTang:"<<endTang<<endl;
243 if (endTang==-10000) {
247 cout<<
"startTang:"<<startTang<<endl;
248 cout<<
"endTang:"<<endTang<<endl;
252 cout<<
"startTang:"<<startTang<<endl;
253 cout<<
"endTang:"<<endTang<<endl;
261 cout <<
"showing Bezier" << endl;
264 cout <<
"showing Spline" << endl;
269 cerr<<
"keys: "<<endl;
270 cerr<<
"w,s: change startTangent"<<endl;
271 cerr<<
"a: relaxed start condition"<<endl;
272 cerr<<
"i,k: change endTangent"<<endl;
273 cerr<<
"j: relaxed end condition"<<endl;
274 cerr<<
"1,2,3: change degree of interpolation"<<endl;
275 cerr<<
"4: use akima-spline"<<endl;
276 cerr<<
"b : switch Spline and Bezier"<<endl;
277 cerr<<
"q : quits"<<endl;
284 for (
int j=1;j<=2;j++) {
288 for (
int i=0;i<700;i++) {
289 if (useSpline || j==1) {
290 interpolator.
Spline(pos,dt,deg);
294 x1=(
unsigned int)dt;y1=600-(
unsigned int)pos;
302 if(x0>=0 && y0>=0 && (
unsigned int)x1<img.
GetWidth() && (
unsigned int)y1<img.
GetHeight()&&
303 (
unsigned int)x0<img.
GetWidth() && (
unsigned int)y0<img.
GetHeight() && x1>0 && y1 >0)
int Bezier3(double &res, double t)
these functions do the bezier interpolation as described in David Salomon 4...
virtual char WaitForKeyEvent()
waits until a key is pressed and returns it tested
void InitSpline()
call this for restart at t= first knot point initiates recalculation of all polynom coefficients at f...
virtual void SetTitle(std::string const &Title)
simple wxWindow to display an image.
void SetKnotPoints(const std::vector< double > &kPnt)
set the additional knot points, if you want nonuniform interpolation.
void InitBezier(int dim_of_CP)
here the calculation of all coefficients for the bezier interpolation is done and the nmatrix is set ...
void SetStartTangent(double startTangent)
unsigned int GetWidth() const
this class interpolates a function y=f(t) between given control points (the y-values) ...
int Spline(double &res, double t, unsigned int k=3)
these functions do the Spline interpolation which reaches each control point.
unsigned int GetHeight() const
void FillImageWithConstValue(StorageType Value)
fill grey images
void SetControlPoints(const std::vector< double > &cPnt1)
set the control points, which control the interpolating curve
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
drawing simple entities into the image like rectangles or lines As all functions are static they have...
virtual int ShowImage(ImageBase &image, float min=0.0, float max=255.0)
shows/updates the image shown in window.
void SetEndTangent(double endTangent)