50 #include <visp3/core/vpDebug.h> 52 #include <visp3/core/vpBSpline.h> 54 #include <visp3/core/vpDisplay.h> 55 #include <visp3/core/vpImage.h> 56 #include <visp3/core/vpImagePoint.h> 57 #include <visp3/io/vpImageIo.h> 58 #ifdef VISP_HAVE_MODULE_GUI 59 #include <visp3/gui/vpDisplayD3D.h> 60 #include <visp3/gui/vpDisplayGDI.h> 61 #include <visp3/gui/vpDisplayGTK.h> 62 #include <visp3/gui/vpDisplayOpenCV.h> 63 #include <visp3/gui/vpDisplayX.h> 68 #include <visp3/core/vpIoTools.h> 69 #include <visp3/io/vpParseArgv.h> 71 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV) || \ 72 defined(VISP_HAVE_D3D9) 75 #define GETOPTARGS "cdh" 77 void usage(
const char *name,
const char *badparam);
78 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
88 void usage(
const char *name,
const char *badparam)
91 Describe a curve thanks to a BSpline.\n\ 94 %s [-c] [-d] [-h]\n", name);
99 Disable the mouse click. Useful to automaze the \n\ 100 execution of this program without humain intervention.\n\ 103 Turn off the display.\n\ 109 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
124 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
132 click_allowed =
false;
138 usage(argv[0], NULL);
143 usage(argv[0], optarg_);
149 if ((c == 1) || (c == -1)) {
151 usage(argv[0], NULL);
152 std::cerr <<
"ERROR: " << std::endl;
153 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
160 int main(
int argc,
const char **argv)
163 bool opt_click_allowed =
true;
164 bool opt_display =
true;
167 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
178 #ifdef VISP_HAVE_MODULE_GUI 179 #if defined VISP_HAVE_X11 181 #elif defined VISP_HAVE_GTK 183 #elif defined VISP_HAVE_GDI 185 #elif defined VISP_HAVE_OPENCV 187 #elif defined VISP_HAVE_D3D9 193 display.
init(I, 100, 100,
"Display image");
200 std::list<double> knots;
213 std::list<vpImagePoint> controlPoints;
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);
230 controlPoints.push_back(pt);
236 std::cout <<
"The parameters are :" << std::endl;
237 std::cout <<
"p : " << bSpline.
get_p() << std::endl;
238 std::cout <<
"" << std::endl;
239 std::cout <<
"The knot vector :" << std::endl;
240 std::list<double> knots_cur;
242 unsigned int i_display = 0;
243 for (std::list<double>::const_iterator it = knots_cur.begin(); it != knots_cur.end(); ++it, ++i_display) {
244 std::cout << i_display <<
" ---> " << *it << std::endl;
246 std::cout <<
"The control points are :" << std::endl;
247 std::list<vpImagePoint> controlPoints_cur;
250 for (std::list<vpImagePoint>::const_iterator it = controlPoints_cur.begin(); it != controlPoints_cur.end();
252 std::cout << i_display <<
" ---> " << *it << std::endl;
255 unsigned int i = bSpline.
findSpan(5 / 2.0);
256 std::cout <<
"The knot interval number for the value u = 5/2 is : " << i << std::endl;
258 vpBasisFunction *N = NULL;
260 std::cout <<
"The nonvanishing basis functions N(u=5/2) are :" << std::endl;
261 for (
unsigned int j = 0; j < bSpline.
get_p() + 1; j++)
262 std::cout << N[j].value << std::endl;
264 vpBasisFunction **N2 = NULL;
266 std::cout <<
"The first derivatives of the basis functions N'(u=5/2) are :" << std::endl;
267 for (
unsigned int j = 0; j < bSpline.
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 < bSpline.
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) {
291 for (
unsigned int j = 0; j <= 2; j++)
298 std::cout <<
"Catch an exception: " << e << std::endl;
306 std::cout <<
"You do not have X11, GTK, or OpenCV, or GDI (Graphical Device Interface) functionalities to display images..." << std::endl;
307 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
308 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
309 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
310 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
void get_controlPoints(std::list< vpImagePoint > &list) const
Display for windows using GDI (available on any windows 32 platform).
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
error that can be emited by ViSP classes.
static const vpColor green
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
static vpBasisFunction ** computeDersBasisFuns(double l_u, unsigned int l_i, unsigned int l_p, unsigned int l_der, std::vector< double > &l_knots)
static unsigned int findSpan(double l_u, unsigned int l_p, std::vector< double > &l_knots)
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed...
static void display(const vpImage< unsigned char > &I)
static vpBasisFunction * computeBasisFuns(double l_u, unsigned int l_i, unsigned int l_p, std::vector< double > &l_knots)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
void set_p(unsigned int degree)
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
unsigned int get_p() const
void set_controlPoints(const std::list< vpImagePoint > &list)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
Class that provides tools to compute and manipulate a B-Spline curve.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void get_knots(std::list< double > &list) const
void set_knots(const std::list< double > &list)
void set_ij(const double ii, const double jj)
static vpImagePoint computeCurvePoint(double l_u, unsigned int l_i, unsigned int l_p, std::vector< double > &l_knots, std::vector< vpImagePoint > &l_controlPoints)