39#include <visp3/core/vpDebug.h>
41#include <visp3/me/vpNurbs.h>
43#include <visp3/core/vpImage.h>
44#include <visp3/core/vpImagePoint.h>
45#include <visp3/io/vpImageIo.h>
46#ifdef VISP_HAVE_MODULE_GUI
47#include <visp3/gui/vpDisplayD3D.h>
48#include <visp3/gui/vpDisplayGDI.h>
49#include <visp3/gui/vpDisplayGTK.h>
50#include <visp3/gui/vpDisplayOpenCV.h>
51#include <visp3/gui/vpDisplayX.h>
55#include <visp3/core/vpIoTools.h>
56#include <visp3/io/vpParseArgv.h>
57#if defined(VISP_HAVE_DISPLAY) && (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
60#define GETOPTARGS "cdh"
62#ifdef ENABLE_VISP_NAMESPACE
66void usage(
const char *name,
const char *badparam);
67bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
77void usage(
const char *name,
const char *badparam)
80Describe a curve thanks to a Nurbs.\n\
89 Disable the mouse click. Useful to automate the \n\
90 execution of this program without human intervention.\n\
93 Turn off the display.\n\
99 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
114bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
122 click_allowed =
false;
128 usage(argv[0],
nullptr);
132 usage(argv[0], optarg_);
137 if ((c == 1) || (c == -1)) {
139 usage(argv[0],
nullptr);
140 std::cerr <<
"ERROR: " << std::endl;
141 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
148int main(
int argc,
const char **argv)
151 bool opt_click_allowed =
true;
152 bool opt_display =
true;
155 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
167#if defined(VISP_HAVE_X11)
169#elif defined(VISP_HAVE_GDI)
171#elif defined(VISP_HAVE_GTK)
173#elif defined(HAVE_OPENCV_HIGHGUI)
179 display[0].init(I, 100, 100,
"Points as control points");
185 std::list<double> knots;
198 std::list<vpImagePoint> controlPoints;
199 std::list<double> weights;
202 controlPoints.push_back(pt);
203 weights.push_back(1);
205 controlPoints.push_back(pt);
206 weights.push_back(5);
208 controlPoints.push_back(pt);
209 weights.push_back(0.2);
211 controlPoints.push_back(pt);
212 weights.push_back(10);
214 controlPoints.push_back(pt);
215 weights.push_back(1);
217 controlPoints.push_back(pt);
218 weights.push_back(2);
220 controlPoints.push_back(pt);
221 weights.push_back(3);
223 controlPoints.push_back(pt);
224 weights.push_back(1);
231 std::cout <<
"The parameters are :" << std::endl;
232 std::cout <<
"p : " << Nurbs.
get_p() << std::endl;
233 std::cout <<
"" << std::endl;
234 std::cout <<
"The knot vector :" << std::endl;
235 std::list<double> knots_cur;
237 unsigned int i_display = 0;
238 for (std::list<double>::const_iterator it = knots_cur.begin(); it != knots_cur.end(); ++it, ++i_display) {
239 std::cout << i_display <<
" ---> " << *it << std::endl;
241 std::cout <<
"The control points are :" << std::endl;
242 std::list<vpImagePoint> controlPoints_cur;
245 for (std::list<vpImagePoint>::const_iterator it = controlPoints_cur.begin(); it != controlPoints_cur.end();
247 std::cout << i_display <<
" ---> " << *it << std::endl;
249 std::cout <<
"The associated weights are :" << std::endl;
250 std::list<double> weights_cur;
253 for (std::list<double>::const_iterator it = weights_cur.begin(); it != weights_cur.end(); ++it, ++i_display) {
254 std::cout << i_display <<
" ---> " << *it << std::endl;
257 unsigned int i = Nurbs.
findSpan(5 / 2.0);
258 std::cout <<
"The knot interval number for the value u = 5/2 is : " <<
i << std::endl;
260 vpBasisFunction *N =
nullptr;
262 std::cout <<
"The nonvanishing basis functions N(u=5/2) are :" << std::endl;
263 for (
unsigned int j = 0;
j < Nurbs.
get_p() + 1;
j++)
264 std::cout << N[j].value << std::endl;
266 vpBasisFunction **N2 =
nullptr;
268 std::cout <<
"The first 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[1][j].value << std::endl;
272 std::cout <<
"The second derivatives of the basis functions N''(u=5/2) are :" << std::endl;
273 for (
unsigned int j = 0;
j < Nurbs.
get_p() + 1;
j++)
274 std::cout << N2[2][j].value << std::endl;
276 if (opt_display && opt_click_allowed) {
283 for (std::list<vpImagePoint>::const_iterator it = controlPoints.begin(); it != controlPoints.end(); ++it) {
294 display[1].init(I2, 100, 100,
"Points interpolation");
306 if (opt_display && opt_click_allowed) {
314 for (std::list<vpImagePoint>::const_iterator it = controlPoints.begin(); it != controlPoints.end(); ++it) {
324 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++)
363 std::cout <<
"Catch an exception: " <<
e << std::endl;
368#elif !(defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
371 std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
377 std::cout <<
"This example requires a video device. " << std::endl
378 <<
"You should install X11, GTK, OpenCV, GDI or Direct3D" << std::endl
379 <<
"to be able to execute this example." << std::endl;
void get_controlPoints(std::list< vpImagePoint > &list) const
void set_p(unsigned int degree)
static unsigned int findSpan(double l_u, unsigned int l_p, const std::vector< double > &l_knots)
unsigned int get_p() const
static vpBasisFunction ** computeDersBasisFuns(double l_u, unsigned int l_i, unsigned int l_p, unsigned int l_der, const std::vector< double > &l_knots)
void set_controlPoints(const std::list< vpImagePoint > &list)
void get_knots(std::list< double > &list) const
void set_knots(const std::list< double > &list)
static vpBasisFunction * computeBasisFuns(double l_u, unsigned int l_i, unsigned int l_p, const std::vector< double > &l_knots)
static const vpColor green
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static void flush(const vpImage< unsigned char > &I)
error that can be emitted by ViSP classes.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void set_ij(double ii, double jj)
Definition of the vpImage class member functions.
Class that provides tools to compute and manipulate a Non Uniform Rational B-Spline curve.
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 get_weights(std::list< double > &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)
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)
void set_weights(const std::list< double > &list)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)