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 void usage(
const char *name,
const char *badparam);
63 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
73 void usage(
const char *name,
const char *badparam)
76 Describe a curve thanks to a Nurbs.\n\
85 Disable the mouse click. Useful to automate the \n\
86 execution of this program without human intervention.\n\
89 Turn off the display.\n\
95 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
110 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
118 click_allowed =
false;
124 usage(argv[0],
nullptr);
129 usage(argv[0], optarg_);
135 if ((c == 1) || (c == -1)) {
137 usage(argv[0],
nullptr);
138 std::cerr <<
"ERROR: " << std::endl;
139 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
146 int main(
int argc,
const char **argv)
149 bool opt_click_allowed =
true;
150 bool opt_display =
true;
153 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
165 #if defined(VISP_HAVE_X11)
167 #elif defined(VISP_HAVE_GDI)
169 #elif defined(VISP_HAVE_GTK)
171 #elif defined(HAVE_OPENCV_HIGHGUI)
177 display[0].init(I, 100, 100,
"Points as control points");
183 std::list<double> knots;
196 std::list<vpImagePoint> controlPoints;
197 std::list<double> weights;
200 controlPoints.push_back(pt);
201 weights.push_back(1);
203 controlPoints.push_back(pt);
204 weights.push_back(5);
206 controlPoints.push_back(pt);
207 weights.push_back(0.2);
209 controlPoints.push_back(pt);
210 weights.push_back(10);
212 controlPoints.push_back(pt);
213 weights.push_back(1);
215 controlPoints.push_back(pt);
216 weights.push_back(2);
218 controlPoints.push_back(pt);
219 weights.push_back(3);
221 controlPoints.push_back(pt);
222 weights.push_back(1);
229 std::cout <<
"The parameters are :" << std::endl;
230 std::cout <<
"p : " << Nurbs.
get_p() << std::endl;
231 std::cout <<
"" << std::endl;
232 std::cout <<
"The knot vector :" << std::endl;
233 std::list<double> knots_cur;
235 unsigned int i_display = 0;
236 for (std::list<double>::const_iterator it = knots_cur.begin(); it != knots_cur.end(); ++it, ++i_display) {
237 std::cout << i_display <<
" ---> " << *it << std::endl;
239 std::cout <<
"The control points are :" << std::endl;
240 std::list<vpImagePoint> controlPoints_cur;
243 for (std::list<vpImagePoint>::const_iterator it = controlPoints_cur.begin(); it != controlPoints_cur.end();
245 std::cout << i_display <<
" ---> " << *it << std::endl;
247 std::cout <<
"The associated weights are :" << std::endl;
248 std::list<double> weights_cur;
251 for (std::list<double>::const_iterator it = weights_cur.begin(); it != weights_cur.end(); ++it, ++i_display) {
252 std::cout << i_display <<
" ---> " << *it << std::endl;
255 unsigned int i = Nurbs.
findSpan(5 / 2.0);
256 std::cout <<
"The knot interval number for the value u = 5/2 is : " << i << std::endl;
258 vpBasisFunction *N =
nullptr;
260 std::cout <<
"The nonvanishing basis functions N(u=5/2) are :" << std::endl;
261 for (
unsigned int j = 0; j < Nurbs.
get_p() + 1; j++)
262 std::cout << N[j].value << std::endl;
264 vpBasisFunction **N2 =
nullptr;
266 std::cout <<
"The first derivatives of the basis functions N'(u=5/2) are :" << std::endl;
267 for (
unsigned int j = 0; j < Nurbs.
get_p() + 1; j++)
268 std::cout << N2[1][j].value << std::endl;
270 std::cout <<
"The second 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[2][j].value << std::endl;
274 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");
303 if (opt_display && opt_click_allowed) {
311 for (std::list<vpImagePoint>::const_iterator it = controlPoints.begin(); it != controlPoints.end(); ++it) {
321 display[2].init(I3, 100, 100,
"Points approximation");
332 if (opt_display && opt_click_allowed) {
340 for (std::list<vpImagePoint>::const_iterator it = controlPoints.begin(); it != controlPoints.end(); ++it) {
351 for (
int j = 0; j <= 2; j++)
358 std::cout <<
"Catch an exception: " << e << std::endl;
363 #elif !(defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
366 std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
372 std::cout <<
"This example requires a video device. " << std::endl
373 <<
"You should install X11, GTK, OpenCV, GDI or Direct3D" << std::endl
374 <<
"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)
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)
void display(vpImage< unsigned char > &I, const std::string &title)
Display a gray-scale image.