55 #include <visp/vpDebug.h>
57 #include <visp/vpBSpline.h>
59 #include <visp/vpImage.h>
60 #include <visp/vpImageIo.h>
61 #include <visp/vpImagePoint.h>
62 #include <visp/vpDisplayGTK.h>
63 #include <visp/vpDisplayGDI.h>
64 #include <visp/vpDisplayOpenCV.h>
65 #include <visp/vpDisplayD3D.h>
66 #include <visp/vpDisplayX.h>
68 #include <visp/vpParseArgv.h>
69 #include <visp/vpIoTools.h>
73 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_D3D9)
76 #define GETOPTARGS "cdh"
78 void usage(
const char *name,
const char *badparam);
79 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
89 void usage(
const char *name,
const char *badparam)
92 Describe a curve thanks to a BSpline.\n\
95 %s [-c] [-d] [-h]\n", name);
100 Disable the mouse click. Useful to automaze the \n\
101 execution of this program without humain intervention.\n\
104 Turn off the display.\n\
110 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
126 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
133 case 'c': click_allowed =
false;
break;
134 case 'd': display =
false;
break;
135 case 'h': usage(argv[0], NULL);
return false;
break;
138 usage(argv[0], optarg_);
143 if ((c == 1) || (c == -1)) {
145 usage(argv[0], NULL);
146 std::cerr <<
"ERROR: " << std::endl;
147 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
156 main(
int argc,
const char ** argv)
159 bool opt_click_allowed =
true;
160 bool opt_display =
true;
163 if (getOptions(argc, argv, opt_click_allowed,
164 opt_display) ==
false) {
174 #if defined VISP_HAVE_X11
176 #elif defined VISP_HAVE_GTK
178 #elif defined VISP_HAVE_GDI
180 #elif defined VISP_HAVE_OPENCV
182 #elif defined VISP_HAVE_D3D9
188 display.
init(I, 100, 100,
"Display image") ;
194 std::list<double> knots;
207 std::list<vpImagePoint> controlPoints;
210 controlPoints.push_back(pt);
212 controlPoints.push_back(pt);
214 controlPoints.push_back(pt);
216 controlPoints.push_back(pt);
218 controlPoints.push_back(pt);
220 controlPoints.push_back(pt);
222 controlPoints.push_back(pt);
224 controlPoints.push_back(pt);
230 std::cout <<
"The parameters are :" <<std::endl;
231 std::cout <<
"p : " << bSpline.
get_p() <<std::endl;
232 std::cout <<
"" <<std::endl;
233 std::cout <<
"The knot vector :" <<std::endl;
234 std::list<double> knots_cur;
236 unsigned int i_display=0;
237 for(std::list<double>::const_iterator it=knots_cur.begin(); it!=knots_cur.end(); ++it, ++i_display){
238 std::cout << i_display <<
" ---> " << *it << std::endl;
240 std::cout <<
"The control points are :" <<std::endl;
241 std::list<vpImagePoint> controlPoints_cur;
244 for(std::list<vpImagePoint>::const_iterator it=controlPoints_cur.begin(); it!=controlPoints_cur.end(); ++it, ++i_display){
245 std::cout << i_display <<
" ---> " << *it << std::endl;
248 unsigned int i = bSpline.
findSpan(5/2.0);
249 std::cout <<
"The knot interval number for the value u = 5/2 is : " << i <<std::endl;
251 vpBasisFunction *N = NULL;
253 std::cout <<
"The nonvanishing basis functions N(u=5/2) are :" << std::endl;
254 for (
unsigned int j = 0; j < bSpline.
get_p()+1; j++)
255 std::cout << N[j].value << std::endl;
257 vpBasisFunction **N2 = NULL;
259 std::cout <<
"The first derivatives of the basis functions N'(u=5/2) are :" << std::endl;
260 for (
unsigned int j = 0; j < bSpline.
get_p()+1; j++)
261 std::cout << N2[1][j].value << std::endl;
263 std::cout <<
"The second derivatives of the basis functions N''(u=5/2) are :" << std::endl;
264 for (
unsigned int j = 0; j < bSpline.
get_p()+1; j++)
265 std::cout << N2[2][j].value << std::endl;
267 if (opt_display && opt_click_allowed)
276 for(std::list<vpImagePoint>::const_iterator it=controlPoints.begin(); it!= controlPoints.end(); ++it){
283 if (N != NULL)
delete[] N;
286 for (
unsigned int j = 0; j <= 2; j++)
294 std::cout <<
"Catch an exception: " << e << std::endl;
302 std::cout <<
"This example requires a video device. "
304 <<
"You should install X11, GTK, OpenCV, GDI or Direct3D"
306 <<
"to be able to execute this example."
void get_controlPoints(std::list< vpImagePoint > &list) const
Display for windows using GDI (available on any windows 32 platform).
Define the X11 console to display images.
error that can be emited by ViSP classes.
static const vpColor green
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
static vpBasisFunction ** computeDersBasisFuns(double l_u, unsigned int l_i, unsigned int l_p, unsigned int l_der, std::vector< double > &l_knots)
static unsigned int findSpan(double l_u, unsigned int l_p, std::vector< double > &l_knots)
Display for windows using Direct3D.
static void display(const vpImage< unsigned char > &I)
static vpBasisFunction * computeBasisFuns(double l_u, unsigned int l_i, unsigned int l_p, std::vector< double > &l_knots)
The vpDisplayOpenCV allows to display image using the opencv library.
void set_p(unsigned int degree)
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
unsigned int get_p() const
void set_controlPoints(const std::list< vpImagePoint > &list)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
Class that provides tools to compute and manipulate a B-Spline curve.
virtual bool getClick(bool blocking=true)=0
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void get_knots(std::list< double > &list) const
void set_knots(const std::list< double > &list)
void set_ij(const double ii, const double jj)
static vpImagePoint computeCurvePoint(double l_u, unsigned int l_i, unsigned int l_p, std::vector< double > &l_knots, std::vector< vpImagePoint > &l_controlPoints)