Describe a curve thanks to a BSpline.
#include <visp/vpDebug.h>
#include <visp/vpNurbs.h>
#include <visp/vpImage.h>
#include <visp/vpImageIo.h>
#include <visp/vpImagePoint.h>
#include <visp/vpDisplayGTK.h>
#include <visp/vpDisplayGDI.h>
#include <visp/vpDisplayOpenCV.h>
#include <visp/vpDisplayD3D.h>
#include <visp/vpDisplayX.h>
#include <visp/vpParseArgv.h>
#include <visp/vpIoTools.h>
#include <cstdlib>
#if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_D3D9)
#define GETOPTARGS "cdh"
void usage(const char *name, const char *badparam)
{
fprintf(stdout, "\n\
Describe a curve thanks to a Nurbs.\n\
\n\
SYNOPSIS\n\
%s [-c] [-d] [-h]\n", name);
fprintf(stdout, "\n\
OPTIONS: Default\n\
-c\n\
Disable the mouse click. Useful to automaze the \n\
execution of this program without humain intervention.\n\
\n\
-d \n\
Turn off the display.\n\
\n\
-h\n\
Print the help.\n");
if (badparam)
fprintf(stdout, "\nERROR: Bad parameter [%s]\n", badparam);
}
bool getOptions(int argc, const char **argv, bool &click_allowed, bool &display)
{
const char *optarg;
int c;
switch (c) {
case 'c': click_allowed = false; break;
case 'd': display = false; break;
case 'h': usage(argv[0], NULL); return false; break;
default:
usage(argv[0], optarg);
return false; break;
}
}
if ((c == 1) || (c == -1)) {
usage(argv[0], NULL);
std::cerr << "ERROR: " << std::endl;
std::cerr << " Bad argument " << optarg << std::endl << std::endl;
return false;
}
return true;
}
int
main(int argc, const char ** argv)
{
bool opt_click_allowed = true;
bool opt_display = true;
if (getOptions(argc, argv, opt_click_allowed,
opt_display) == false) {
exit (-1);
}
#if defined VISP_HAVE_X11
#elif defined VISP_HAVE_GDI
#elif defined VISP_HAVE_GTK
#elif defined VISP_HAVE_OPENCV
#endif
if (opt_display) {
try{
display[0].
init(I, 100, 100,
"Points as control points") ;
}
catch(...)
{
exit(-1);
}
}
std::list<double> knots;
knots.push_back(0);
knots.push_back(0);
knots.push_back(0);
knots.push_back(1);
knots.push_back(2);
knots.push_back(3);
knots.push_back(4);
knots.push_back(4);
knots.push_back(5);
knots.push_back(5);
knots.push_back(5);
std::list<vpImagePoint> controlPoints;
std::list<double> weights;
controlPoints.push_back(pt);
weights.push_back(1);
controlPoints.push_back(pt);
weights.push_back(5);
controlPoints.push_back(pt);
weights.push_back(0.2);
controlPoints.push_back(pt);
weights.push_back(10);
controlPoints.push_back(pt);
weights.push_back(1);
controlPoints.push_back(pt);
weights.push_back(2);
controlPoints.push_back(pt);
weights.push_back(3);
controlPoints.push_back(pt);
weights.push_back(1);
std::cout << "The parameters are :" <<std::endl;
std::cout <<
"p : " << Nurbs.
get_p() <<std::endl;
std::cout << "" <<std::endl;
std::cout << "The knot vector :" <<std::endl;
std::list<double> knots_cur;
unsigned int i_display=0;
for(std::list<double>::const_iterator it=knots_cur.begin(); it!=knots_cur.end(); ++it, ++i_display){
std::cout << i_display << " ---> " << *it << std::endl;
}
std::cout << "The control points are :" <<std::endl;
std::list<vpImagePoint> controlPoints_cur;
i_display=0;
for(std::list<vpImagePoint>::const_iterator it=controlPoints_cur.begin(); it!=controlPoints_cur.end(); ++it, ++i_display){
std::cout << i_display << " ---> " << *it << std::endl;
}
std::cout << "The associated weights are :" <<std::endl;
std::list<double> weights_cur;
i_display=0;
for(std::list<double>::const_iterator it=weights_cur.begin(); it!=weights_cur.end(); ++it, ++i_display){
std::cout << i_display << " ---> " << *it << std::endl;
}
std::cout << "The knot interval number for the value u = 5/2 is : " << i <<std::endl;
vpBasisFunction *N = NULL;
std::cout << "The nonvanishing basis functions N(u=5/2) are :" << std::endl;
for (
unsigned int j = 0; j < Nurbs.
get_p()+1; j++)
std::cout << N[j].value << std::endl;
vpBasisFunction **N2 = NULL;
std::cout << "The first derivatives of the basis functions N'(u=5/2) are :" << std::endl;
for (
unsigned int j = 0; j < Nurbs.
get_p()+1; j++)
std::cout << N2[1][j].value << std::endl;
std::cout << "The second derivatives of the basis functions N''(u=5/2) are :" << std::endl;
for (
unsigned int j = 0; j < Nurbs.
get_p()+1; j++)
std::cout << N2[2][j].value << std::endl;
if (opt_display && opt_click_allowed)
{
double u = 0.0;
while (u <= 5)
{
u+=0.01;
}
for(std::list<vpImagePoint>::const_iterator it=controlPoints.begin(); it!=controlPoints.end(); ++it){
}
}
if (opt_display) {
try{
display[1].
init(I2, 100, 100,
"Points interpolation") ;
}
catch(...)
{
exit(-1);
}
}
if (opt_display && opt_click_allowed)
{
double u = 0.0;
while (u <= 1)
{
u+=0.01;
}
for(std::list<vpImagePoint>::const_iterator it=controlPoints.begin(); it!=controlPoints.end(); ++it){
}
}
if (opt_display) {
try{
display[2].
init(I3, 100, 100,
"Points approximation") ;
}
catch(...)
{
exit(-1);
}
}
if (opt_display && opt_click_allowed)
{
double u = 0.0;
while (u <= 1)
{
u+=0.01;
}
for(std::list<vpImagePoint>::const_iterator it=controlPoints.begin(); it!=controlPoints.end(); ++it){
}
}
if (N != NULL) delete[] N;
if (N2 != NULL)
{
for (int j = 0; j <= 2; j++)
delete[] N2[j];
delete[] N2;
}
return 0;
}
#else
int main()
{
std::cout << "This example requires a video device. "
<< std::endl
<< "You should install X11, GTK, OpenCV, GDI or Direct3D"
<< std::endl
<< "to be able to execute this example."
<< std::endl;
return 0;
}
#endif