44 #include <visp3/core/vpDebug.h>
46 #include <visp3/me/vpNurbs.h>
48 #include <visp3/core/vpImage.h>
49 #include <visp3/core/vpImagePoint.h>
50 #include <visp3/io/vpImageIo.h>
51 #ifdef VISP_HAVE_MODULE_GUI
52 #include <visp3/gui/vpDisplayD3D.h>
53 #include <visp3/gui/vpDisplayGDI.h>
54 #include <visp3/gui/vpDisplayGTK.h>
55 #include <visp3/gui/vpDisplayOpenCV.h>
56 #include <visp3/gui/vpDisplayX.h>
60 #include <visp3/core/vpIoTools.h>
61 #include <visp3/io/vpParseArgv.h>
62 #if defined(VISP_HAVE_DISPLAY)
65 #define GETOPTARGS "cdh"
67 void usage(
const char *name,
const char *badparam);
68 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
78 void usage(
const char *name,
const char *badparam)
81 Describe a curve thanks to a Nurbs.\n\
84 %s [-c] [-d] [-h]\n", name);
89 Disable the mouse click. Useful to automaze the \n\
90 execution of this program without humain intervention.\n\
93 Turn off the display.\n\
99 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
114 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
122 click_allowed =
false;
128 usage(argv[0], NULL);
133 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;
150 int main(
int argc,
const char **argv)
153 bool opt_click_allowed =
true;
154 bool opt_display =
true;
157 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
169 #if defined VISP_HAVE_X11
171 #elif defined VISP_HAVE_GDI
173 #elif defined VISP_HAVE_GTK
175 #elif defined VISP_HAVE_OPENCV
181 display[0].init(I, 100, 100,
"Points as control points");
187 std::list<double> knots;
200 std::list<vpImagePoint> controlPoints;
201 std::list<double> weights;
204 controlPoints.push_back(pt);
205 weights.push_back(1);
207 controlPoints.push_back(pt);
208 weights.push_back(5);
210 controlPoints.push_back(pt);
211 weights.push_back(0.2);
213 controlPoints.push_back(pt);
214 weights.push_back(10);
216 controlPoints.push_back(pt);
217 weights.push_back(1);
219 controlPoints.push_back(pt);
220 weights.push_back(2);
222 controlPoints.push_back(pt);
223 weights.push_back(3);
225 controlPoints.push_back(pt);
226 weights.push_back(1);
233 std::cout <<
"The parameters are :" << std::endl;
234 std::cout <<
"p : " << Nurbs.
get_p() << std::endl;
235 std::cout <<
"" << std::endl;
236 std::cout <<
"The knot vector :" << std::endl;
237 std::list<double> knots_cur;
239 unsigned int i_display = 0;
240 for (std::list<double>::const_iterator it = knots_cur.begin(); it != knots_cur.end(); ++it, ++i_display) {
241 std::cout << i_display <<
" ---> " << *it << std::endl;
243 std::cout <<
"The control points are :" << std::endl;
244 std::list<vpImagePoint> controlPoints_cur;
247 for (std::list<vpImagePoint>::const_iterator it = controlPoints_cur.begin(); it != controlPoints_cur.end();
249 std::cout << i_display <<
" ---> " << *it << std::endl;
251 std::cout <<
"The associated weights are :" << std::endl;
252 std::list<double> weights_cur;
255 for (std::list<double>::const_iterator it = weights_cur.begin(); it != weights_cur.end(); ++it, ++i_display) {
256 std::cout << i_display <<
" ---> " << *it << std::endl;
259 unsigned int i = Nurbs.
findSpan(5 / 2.0);
260 std::cout <<
"The knot interval number for the value u = 5/2 is : " << i << std::endl;
262 vpBasisFunction *N = NULL;
264 std::cout <<
"The nonvanishing basis functions N(u=5/2) are :" << std::endl;
265 for (
unsigned int j = 0; j < Nurbs.
get_p() + 1; j++)
266 std::cout << N[j].value << std::endl;
268 vpBasisFunction **N2 = NULL;
270 std::cout <<
"The first derivatives of the basis functions N'(u=5/2) are :" << std::endl;
271 for (
unsigned int j = 0; j < Nurbs.
get_p() + 1; j++)
272 std::cout << N2[1][j].value << std::endl;
274 std::cout <<
"The second 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[2][j].value << std::endl;
278 if (opt_display && opt_click_allowed) {
285 for (std::list<vpImagePoint>::const_iterator it = controlPoints.begin(); it != controlPoints.end(); ++it) {
296 display[1].init(I2, 100, 100,
"Points interpolation");
307 if (opt_display && opt_click_allowed) {
315 for (std::list<vpImagePoint>::const_iterator it = controlPoints.begin(); it != controlPoints.end(); ++it) {
325 display[2].init(I3, 100, 100,
"Points approximation");
336 if (opt_display && opt_click_allowed) {
344 for (std::list<vpImagePoint>::const_iterator it = controlPoints.begin(); it != controlPoints.end(); ++it) {
355 for (
int j = 0; j <= 2; j++)
362 std::cout <<
"Catch an exception: " << e << std::endl;
370 std::cout <<
"This example requires a video device. " << std::endl
371 <<
"You should install X11, GTK, OpenCV, GDI or Direct3D" << std::endl
372 <<
"to be able to execute this example." << std::endl;