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/vpDisplayD3D.h>
57 #include <visp3/gui/vpDisplayGDI.h>
58 #include <visp3/gui/vpDisplayGTK.h>
59 #include <visp3/gui/vpDisplayOpenCV.h>
60 #include <visp3/gui/vpDisplayX.h>
65 #include <visp3/core/vpIoTools.h>
66 #include <visp3/io/vpParseArgv.h>
68 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV) || \
69 defined(VISP_HAVE_D3D9)
72 #define GETOPTARGS "cdh"
74 void usage(
const char *name,
const char *badparam);
75 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
85 void usage(
const char *name,
const char *badparam)
88 Describe a curve thanks to a BSpline.\n\
97 Disable the mouse click. Useful to automate the \n\
98 execution of this program without human intervention.\n\
101 Turn off the display.\n\
107 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
122 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
130 click_allowed =
false;
136 usage(argv[0],
nullptr);
141 usage(argv[0], optarg_);
147 if ((c == 1) || (c == -1)) {
149 usage(argv[0],
nullptr);
150 std::cerr <<
"ERROR: " << std::endl;
151 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
158 int main(
int argc,
const char **argv)
161 bool opt_click_allowed =
true;
162 bool opt_display =
true;
165 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
176 #ifdef VISP_HAVE_MODULE_GUI
177 #if defined(VISP_HAVE_X11)
179 #elif defined(VISP_HAVE_GTK)
181 #elif defined(VISP_HAVE_GDI)
183 #elif defined(HAVE_OPENCV_HIGHGUI)
185 #elif defined(VISP_HAVE_D3D9)
191 display.init(I, 100, 100,
"Display image");
198 std::list<double> knots;
211 std::list<vpImagePoint> controlPoints;
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);
224 controlPoints.push_back(pt);
226 controlPoints.push_back(pt);
228 controlPoints.push_back(pt);
234 std::cout <<
"The parameters are :" << std::endl;
235 std::cout <<
"p : " << bSpline.
get_p() << std::endl;
236 std::cout <<
"" << std::endl;
237 std::cout <<
"The knot vector :" << std::endl;
238 std::list<double> knots_cur;
240 unsigned int i_display = 0;
241 for (std::list<double>::const_iterator it = knots_cur.begin(); it != knots_cur.end(); ++it, ++i_display) {
242 std::cout << i_display <<
" ---> " << *it << std::endl;
244 std::cout <<
"The control points are :" << std::endl;
245 std::list<vpImagePoint> controlPoints_cur;
248 for (std::list<vpImagePoint>::const_iterator it = controlPoints_cur.begin(); it != controlPoints_cur.end();
250 std::cout << i_display <<
" ---> " << *it << std::endl;
253 unsigned int i = bSpline.
findSpan(5 / 2.0);
254 std::cout <<
"The knot interval number for the value u = 5/2 is : " << i << std::endl;
256 vpBasisFunction *N =
nullptr;
258 std::cout <<
"The nonvanishing basis functions N(u=5/2) are :" << std::endl;
259 for (
unsigned int j = 0; j < bSpline.
get_p() + 1; j++)
260 std::cout << N[j].value << std::endl;
262 vpBasisFunction **N2 =
nullptr;
264 std::cout <<
"The first derivatives of the basis functions N'(u=5/2) are :" << std::endl;
265 for (
unsigned int j = 0; j < bSpline.
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 < bSpline.
get_p() + 1; j++)
270 std::cout << N2[2][j].value << std::endl;
272 if (opt_display && opt_click_allowed) {
279 for (std::list<vpImagePoint>::const_iterator it = controlPoints.begin(); it != controlPoints.end(); ++it) {
289 for (
unsigned int j = 0; j <= 2; j++)
297 std::cout <<
"Catch an exception: " << e << std::endl;
306 <<
"You do not have X11, GTK, or OpenCV, or GDI (Graphical Device Interface) functionalities to display images..."
308 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
309 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
310 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
311 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
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed....
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)
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.