46#include <visp3/core/vpConfig.h>
47#include <visp3/core/vpDebug.h>
49#include <visp3/core/vpBSpline.h>
51#include <visp3/core/vpDisplay.h>
52#include <visp3/core/vpImage.h>
53#include <visp3/core/vpImagePoint.h>
54#include <visp3/io/vpImageIo.h>
55#ifdef VISP_HAVE_MODULE_GUI
56#include <visp3/gui/vpDisplayFactory.h>
61#include <visp3/core/vpIoTools.h>
62#include <visp3/io/vpParseArgv.h>
64#if defined(VISP_HAVE_DISPLAY)
67#define GETOPTARGS "cdh"
69#ifdef ENABLE_VISP_NAMESPACE
73void usage(
const char *name,
const char *badparam);
74bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
84void usage(
const char *name,
const char *badparam)
87Describe a curve thanks to a BSpline.\n\
96 Disable the mouse click. Useful to automate the \n\
97 execution of this program without human intervention.\n\
100 Turn off the display.\n\
106 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
121bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
129 click_allowed =
false;
135 usage(argv[0],
nullptr);
139 usage(argv[0], optarg_);
144 if ((c == 1) || (c == -1)) {
146 usage(argv[0],
nullptr);
147 std::cerr <<
"ERROR: " << std::endl;
148 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
155int main(
int argc,
const char **argv)
158#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
159 std::shared_ptr<vpDisplay> display;
164 bool opt_click_allowed =
true;
165 bool opt_display =
true;
168 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
178#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
186 display->init(I, 100, 100,
"Display image");
192 std::list<double> knots;
205 std::list<vpImagePoint> controlPoints;
208 controlPoints.push_back(pt);
210 controlPoints.push_back(pt);
212 controlPoints.push_back(pt);
214 controlPoints.push_back(pt);
216 controlPoints.push_back(pt);
218 controlPoints.push_back(pt);
220 controlPoints.push_back(pt);
222 controlPoints.push_back(pt);
228 std::cout <<
"The parameters are :" << std::endl;
229 std::cout <<
"p : " << bSpline.
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();
244 std::cout << i_display <<
" ---> " << *it << std::endl;
247 unsigned int i = bSpline.
findSpan(5 / 2.0);
248 std::cout <<
"The knot interval number for the value u = 5/2 is : " <<
i << std::endl;
250 vpBasisFunction *N =
nullptr;
252 std::cout <<
"The nonvanishing basis functions N(u=5/2) are :" << std::endl;
253 for (
unsigned int j = 0;
j < bSpline.
get_p() + 1;
j++)
254 std::cout << N[j].value << std::endl;
256 vpBasisFunction **N2 =
nullptr;
258 std::cout <<
"The first derivatives of the basis functions N'(u=5/2) are :" << std::endl;
259 for (
unsigned int j = 0;
j < bSpline.
get_p() + 1;
j++)
260 std::cout << N2[1][j].value << std::endl;
262 std::cout <<
"The second derivatives of the basis functions N''(u=5/2) are :" << std::endl;
263 for (
unsigned int j = 0;
j < bSpline.
get_p() + 1;
j++)
264 std::cout << N2[2][j].value << std::endl;
266 if (opt_display && opt_click_allowed) {
273 for (std::list<vpImagePoint>::const_iterator it = controlPoints.begin(); it != controlPoints.end(); ++it) {
283 for (
unsigned int j = 0;
j <= 2;
j++)
288#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
289 if (display !=
nullptr) {
296 std::cout <<
"Catch an exception: " <<
e << std::endl;
297#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
298 if (display !=
nullptr) {
310 <<
"You do not have X11, GTK, or OpenCV, or GDI (Graphical Device Interface) functionalities to display images..."
312 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
313 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
314 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
315 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
Class that provides tools to compute and manipulate a B-Spline curve.
static vpImagePoint computeCurvePoint(double l_u, unsigned int l_i, unsigned int l_p, const std::vector< double > &l_knots, const std::vector< vpImagePoint > &l_controlPoints)
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
Class that defines generic functionalities for display.
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.
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.