43 #include <visp3/core/vpDebug.h>
45 #include <visp3/me/vpNurbs.h>
47 #include <visp3/core/vpImage.h>
48 #include <visp3/io/vpImageIo.h>
49 #include <visp3/core/vpImagePoint.h>
50 #ifdef VISP_HAVE_MODULE_GUI
51 # include <visp3/gui/vpDisplayGTK.h>
52 # include <visp3/gui/vpDisplayGDI.h>
53 # include <visp3/gui/vpDisplayOpenCV.h>
54 # include <visp3/gui/vpDisplayD3D.h>
55 # include <visp3/gui/vpDisplayX.h>
58 #include <visp3/io/vpParseArgv.h>
59 #include <visp3/core/vpIoTools.h>
61 #if defined(VISP_HAVE_DISPLAY)
64 #define GETOPTARGS "cdh"
66 void usage(
const char *name,
const char *badparam);
67 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
77 void usage(
const char *name,
const char *badparam)
80 Describe a curve thanks to a Nurbs.\n\
83 %s [-c] [-d] [-h]\n", name);
88 Disable the mouse click. Useful to automaze the \n\
89 execution of this program without humain intervention.\n\
92 Turn off the display.\n\
98 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
114 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
121 case 'c': click_allowed =
false;
break;
122 case 'd': display =
false;
break;
123 case 'h': usage(argv[0], NULL);
return false;
break;
126 usage(argv[0], optarg_);
131 if ((c == 1) || (c == -1)) {
133 usage(argv[0], NULL);
134 std::cerr <<
"ERROR: " << std::endl;
135 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
144 main(
int argc,
const char ** argv)
147 bool opt_click_allowed =
true;
148 bool opt_display =
true;
151 if (getOptions(argc, argv, opt_click_allowed,
152 opt_display) ==
false) {
164 #if defined VISP_HAVE_X11
166 #elif defined VISP_HAVE_GDI
168 #elif defined VISP_HAVE_GTK
170 #elif defined VISP_HAVE_OPENCV
176 display[0].
init(I, 100, 100,
"Points as control points") ;
182 std::list<double> knots;
195 std::list<vpImagePoint> controlPoints;
196 std::list<double> weights;
199 controlPoints.push_back(pt);
200 weights.push_back(1);
202 controlPoints.push_back(pt);
203 weights.push_back(5);
205 controlPoints.push_back(pt);
206 weights.push_back(0.2);
208 controlPoints.push_back(pt);
209 weights.push_back(10);
211 controlPoints.push_back(pt);
212 weights.push_back(1);
214 controlPoints.push_back(pt);
215 weights.push_back(2);
217 controlPoints.push_back(pt);
218 weights.push_back(3);
220 controlPoints.push_back(pt);
221 weights.push_back(1);
228 std::cout <<
"The parameters are :" <<std::endl;
229 std::cout <<
"p : " << Nurbs.
get_p() <<std::endl;
230 std::cout <<
"" <<std::endl;
231 std::cout <<
"The knot vector :" <<std::endl;
232 std::list<double> knots_cur;
234 unsigned int i_display=0;
235 for(std::list<double>::const_iterator it=knots_cur.begin(); it!=knots_cur.end(); ++it, ++i_display){
236 std::cout << i_display <<
" ---> " << *it << std::endl;
238 std::cout <<
"The control points are :" <<std::endl;
239 std::list<vpImagePoint> controlPoints_cur;
242 for(std::list<vpImagePoint>::const_iterator it=controlPoints_cur.begin(); it!=controlPoints_cur.end(); ++it, ++i_display){
243 std::cout << i_display <<
" ---> " << *it << std::endl;
245 std::cout <<
"The associated weights are :" <<std::endl;
246 std::list<double> weights_cur;
249 for(std::list<double>::const_iterator it=weights_cur.begin(); it!=weights_cur.end(); ++it, ++i_display){
250 std::cout << i_display <<
" ---> " << *it << std::endl;
253 unsigned int i = Nurbs.
findSpan(5/2.0);
254 std::cout <<
"The knot interval number for the value u = 5/2 is : " << i <<std::endl;
256 vpBasisFunction *N = NULL;
258 std::cout <<
"The nonvanishing basis functions N(u=5/2) are :" << std::endl;
259 for (
unsigned int j = 0; j < Nurbs.
get_p()+1; j++)
260 std::cout << N[j].value << std::endl;
262 vpBasisFunction **N2 = NULL;
264 std::cout <<
"The first derivatives of the basis functions N'(u=5/2) are :" << std::endl;
265 for (
unsigned int j = 0; j < Nurbs.
get_p()+1; j++)
266 std::cout << N2[1][j].value << std::endl;
268 std::cout <<
"The second derivatives of the basis functions N''(u=5/2) are :" << std::endl;
269 for (
unsigned int j = 0; j < Nurbs.
get_p()+1; j++)
270 std::cout << N2[2][j].value << std::endl;
272 if (opt_display && opt_click_allowed)
281 for(std::list<vpImagePoint>::const_iterator it=controlPoints.begin(); it!=controlPoints.end(); ++it){
292 display[1].
init(I2, 100, 100,
"Points interpolation") ;
305 if (opt_display && opt_click_allowed)
315 for(std::list<vpImagePoint>::const_iterator it=controlPoints.begin(); it!=controlPoints.end(); ++it){
326 display[2].
init(I3, 100, 100,
"Points approximation") ;
339 if (opt_display && opt_click_allowed)
349 for(std::list<vpImagePoint>::const_iterator it=controlPoints.begin(); it!=controlPoints.end(); ++it){
357 if (N != NULL)
delete[] N;
360 for (
int j = 0; j <= 2; j++)
368 std::cout <<
"Catch an exception: " << e << std::endl;
376 std::cout <<
"This example requires a video device. "
378 <<
"You should install X11, GTK, OpenCV, GDI or Direct3D"
380 <<
"to be able to execute this example."
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
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).
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
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)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
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. Thus to enable this class OpenC...
void set_p(unsigned int degree)
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
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)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
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)