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"
85 void usage(
const char *name,
const char *badparam)
88 Describe a curve thanks to a Nurbs.\n\
91 %s [-c] [-d] [-h]\n", name);
96 Disable the mouse click. Useful to automaze the \n\
97 execution of this program without humain intervention.\n\
100 Turn off the display.\n\
106 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
122 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
129 case 'c': click_allowed =
false;
break;
130 case 'd': display =
false;
break;
131 case 'h': usage(argv[0], NULL);
return false;
break;
134 usage(argv[0], optarg);
139 if ((c == 1) || (c == -1)) {
141 usage(argv[0], NULL);
142 std::cerr <<
"ERROR: " << std::endl;
143 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
152 main(
int argc,
const char ** argv)
154 bool opt_click_allowed =
true;
155 bool opt_display =
true;
158 if (getOptions(argc, argv, opt_click_allowed,
159 opt_display) ==
false) {
171 #if defined VISP_HAVE_X11
173 #elif defined VISP_HAVE_GDI
175 #elif defined VISP_HAVE_GTK
177 #elif defined VISP_HAVE_OPENCV
184 display[0].
init(I, 100, 100,
"Points as control points") ;
197 std::list<double> knots;
210 std::list<vpImagePoint> controlPoints;
211 std::list<double> weights;
214 controlPoints.push_back(pt);
215 weights.push_back(1);
217 controlPoints.push_back(pt);
218 weights.push_back(5);
220 controlPoints.push_back(pt);
221 weights.push_back(0.2);
223 controlPoints.push_back(pt);
224 weights.push_back(10);
226 controlPoints.push_back(pt);
227 weights.push_back(1);
229 controlPoints.push_back(pt);
230 weights.push_back(2);
232 controlPoints.push_back(pt);
233 weights.push_back(3);
235 controlPoints.push_back(pt);
236 weights.push_back(1);
243 std::cout <<
"The parameters are :" <<std::endl;
244 std::cout <<
"p : " << Nurbs.
get_p() <<std::endl;
245 std::cout <<
"" <<std::endl;
246 std::cout <<
"The knot vector :" <<std::endl;
247 std::list<double> knots_cur;
249 unsigned int i_display=0;
250 for(std::list<double>::const_iterator it=knots_cur.begin(); it!=knots_cur.end(); ++it, ++i_display){
251 std::cout << i_display <<
" ---> " << *it << std::endl;
253 std::cout <<
"The control points are :" <<std::endl;
254 std::list<vpImagePoint> controlPoints_cur;
257 for(std::list<vpImagePoint>::const_iterator it=controlPoints_cur.begin(); it!=controlPoints_cur.end(); ++it, ++i_display){
258 std::cout << i_display <<
" ---> " << *it << std::endl;
260 std::cout <<
"The associated weights are :" <<std::endl;
261 std::list<double> weights_cur;
264 for(std::list<double>::const_iterator it=weights_cur.begin(); it!=weights_cur.end(); ++it, ++i_display){
265 std::cout << i_display <<
" ---> " << *it << std::endl;
268 unsigned int i = Nurbs.
findSpan(5/2.0);
269 std::cout <<
"The knot interval number for the value u = 5/2 is : " << i <<std::endl;
271 vpBasisFunction *N = NULL;
273 std::cout <<
"The nonvanishing basis functions N(u=5/2) are :" << std::endl;
274 for (
unsigned int j = 0; j < Nurbs.
get_p()+1; j++)
275 std::cout << N[j].value << std::endl;
277 vpBasisFunction **N2 = NULL;
279 std::cout <<
"The first derivatives of the basis functions N'(u=5/2) are :" << std::endl;
280 for (
unsigned int j = 0; j < Nurbs.
get_p()+1; j++)
281 std::cout << N2[1][j].value << std::endl;
283 std::cout <<
"The second derivatives of the basis functions N''(u=5/2) are :" << std::endl;
284 for (
unsigned int j = 0; j < Nurbs.
get_p()+1; j++)
285 std::cout << N2[2][j].value << std::endl;
287 if (opt_display && opt_click_allowed)
297 for(std::list<vpImagePoint>::const_iterator it=controlPoints.begin(); it!=controlPoints.end(); ++it){
308 display[1].
init(I2, 100, 100,
"Points interpolation") ;
321 if (opt_display && opt_click_allowed)
332 for(std::list<vpImagePoint>::const_iterator it=controlPoints.begin(); it!=controlPoints.end(); ++it){
343 display[2].
init(I3, 100, 100,
"Points approximation") ;
356 if (opt_display && opt_click_allowed)
367 for(std::list<vpImagePoint>::const_iterator it=controlPoints.begin(); it!=controlPoints.end(); ++it){
375 if (N != NULL)
delete[] N;
378 for (
int j = 0; j <= 2; j++)
389 std::cout <<
"This example requires a video device. "
391 <<
"You should install X11, GTK, OpenCV, GDI or Direct3D"
393 <<
"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.
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)
void set_p(unsigned int p)
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
void set_ij(const double i, const double j)
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.
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...