55 #include <visp/vpDebug.h>
57 #include <visp/vpNurbs.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>
71 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_D3D9)
74 #define GETOPTARGS "cdh"
76 void usage(
const char *name,
const char *badparam);
77 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
87 void usage(
const char *name,
const char *badparam)
90 Describe a curve thanks to a Nurbs.\n\
93 %s [-c] [-d] [-h]\n", name);
98 Disable the mouse click. Useful to automaze the \n\
99 execution of this program without humain intervention.\n\
102 Turn off the display.\n\
108 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
124 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
131 case 'c': click_allowed =
false;
break;
132 case 'd': display =
false;
break;
133 case 'h': usage(argv[0], NULL);
return false;
break;
136 usage(argv[0], optarg_);
141 if ((c == 1) || (c == -1)) {
143 usage(argv[0], NULL);
144 std::cerr <<
"ERROR: " << std::endl;
145 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
154 main(
int argc,
const char ** argv)
157 bool opt_click_allowed =
true;
158 bool opt_display =
true;
161 if (getOptions(argc, argv, opt_click_allowed,
162 opt_display) ==
false) {
174 #if defined VISP_HAVE_X11
176 #elif defined VISP_HAVE_GDI
178 #elif defined VISP_HAVE_GTK
180 #elif defined VISP_HAVE_OPENCV
186 display[0].
init(I, 100, 100,
"Points as control points") ;
192 std::list<double> knots;
205 std::list<vpImagePoint> controlPoints;
206 std::list<double> weights;
209 controlPoints.push_back(pt);
210 weights.push_back(1);
212 controlPoints.push_back(pt);
213 weights.push_back(5);
215 controlPoints.push_back(pt);
216 weights.push_back(0.2);
218 controlPoints.push_back(pt);
219 weights.push_back(10);
221 controlPoints.push_back(pt);
222 weights.push_back(1);
224 controlPoints.push_back(pt);
225 weights.push_back(2);
227 controlPoints.push_back(pt);
228 weights.push_back(3);
230 controlPoints.push_back(pt);
231 weights.push_back(1);
238 std::cout <<
"The parameters are :" <<std::endl;
239 std::cout <<
"p : " << Nurbs.
get_p() <<std::endl;
240 std::cout <<
"" <<std::endl;
241 std::cout <<
"The knot vector :" <<std::endl;
242 std::list<double> knots_cur;
244 unsigned int i_display=0;
245 for(std::list<double>::const_iterator it=knots_cur.begin(); it!=knots_cur.end(); ++it, ++i_display){
246 std::cout << i_display <<
" ---> " << *it << std::endl;
248 std::cout <<
"The control points are :" <<std::endl;
249 std::list<vpImagePoint> controlPoints_cur;
252 for(std::list<vpImagePoint>::const_iterator it=controlPoints_cur.begin(); it!=controlPoints_cur.end(); ++it, ++i_display){
253 std::cout << i_display <<
" ---> " << *it << std::endl;
255 std::cout <<
"The associated weights are :" <<std::endl;
256 std::list<double> weights_cur;
259 for(std::list<double>::const_iterator it=weights_cur.begin(); it!=weights_cur.end(); ++it, ++i_display){
260 std::cout << i_display <<
" ---> " << *it << std::endl;
263 unsigned int i = Nurbs.
findSpan(5/2.0);
264 std::cout <<
"The knot interval number for the value u = 5/2 is : " << i <<std::endl;
266 vpBasisFunction *N = NULL;
268 std::cout <<
"The nonvanishing basis functions N(u=5/2) are :" << std::endl;
269 for (
unsigned int j = 0; j < Nurbs.
get_p()+1; j++)
270 std::cout << N[j].value << std::endl;
272 vpBasisFunction **N2 = NULL;
274 std::cout <<
"The first derivatives of the basis functions N'(u=5/2) are :" << std::endl;
275 for (
unsigned int j = 0; j < Nurbs.
get_p()+1; j++)
276 std::cout << N2[1][j].value << std::endl;
278 std::cout <<
"The second derivatives of the basis functions N''(u=5/2) are :" << std::endl;
279 for (
unsigned int j = 0; j < Nurbs.
get_p()+1; j++)
280 std::cout << N2[2][j].value << std::endl;
282 if (opt_display && opt_click_allowed)
291 for(std::list<vpImagePoint>::const_iterator it=controlPoints.begin(); it!=controlPoints.end(); ++it){
302 display[1].
init(I2, 100, 100,
"Points interpolation") ;
315 if (opt_display && opt_click_allowed)
325 for(std::list<vpImagePoint>::const_iterator it=controlPoints.begin(); it!=controlPoints.end(); ++it){
336 display[2].
init(I3, 100, 100,
"Points approximation") ;
349 if (opt_display && opt_click_allowed)
359 for(std::list<vpImagePoint>::const_iterator it=controlPoints.begin(); it!=controlPoints.end(); ++it){
367 if (N != NULL)
delete[] N;
370 for (
int j = 0; j <= 2; j++)
379 std::cout <<
"Catch an exception: " << e << std::endl;
387 std::cout <<
"This example requires a video device. "
389 <<
"You should install X11, GTK, OpenCV, GDI or Direct3D"
391 <<
"to be able to execute this example."
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
void get_controlPoints(std::list< vpImagePoint > &list) const
static vpImagePoint computeCurvePoint(double l_u, unsigned int l_i, unsigned int l_p, std::vector< double > &l_knots, std::vector< vpImagePoint > &l_controlPoints, std::vector< double > &l_weights)
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 void globalCurveInterp(std::vector< vpImagePoint > &l_crossingPoints, unsigned int l_p, std::vector< double > &l_knots, std::vector< vpImagePoint > &l_controlPoints, std::vector< double > &l_weights)
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)
void get_weights(std::list< double > &list) const
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)
static void globalCurveApprox(std::vector< vpImagePoint > &l_crossingPoints, unsigned int l_p, unsigned int l_n, std::vector< double > &l_knots, std::vector< vpImagePoint > &l_controlPoints, std::vector< double > &l_weights)
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 set_weights(const std::list< double > &list)
void get_knots(std::list< double > &list) const
void set_knots(const std::list< double > &list)
Class that provides tools to compute and manipulate a Non Uniform Rational B-Spline curve...
void set_ij(const double ii, const double jj)