45 #include <visp/vpConfig.h>
47 #ifndef DOXYGEN_SHOULD_SKIP_THIS
54 #include <visp/vpMbtDistanceCylinder.h>
55 #include <visp/vpPlane.h>
56 #include <visp/vpMeterPixelConversion.h>
57 #include <visp/vpPixelMeterConversion.h>
58 #include <visp/vpFeatureBuilder.h>
59 #include <visp/vpFeatureEllipse.h>
63 #include <visp/vpPose.h>
68 vpMbtDistanceCylinder::vpMbtDistanceCylinder()
90 vpMbtDistanceCylinder::~vpMbtDistanceCylinder()
94 if (p1 != NULL)
delete p1 ;
95 if (p2 != NULL)
delete p2 ;
96 if (c != NULL)
delete c ;
97 if (meline1 != NULL)
delete meline1 ;
98 if (meline2 != NULL)
delete meline2 ;
99 if (cercle1 != NULL)
delete cercle1 ;
100 if (cercle2 != NULL)
delete cercle2 ;
114 cercle1->project(cMo) ;
115 cercle2->project(cMo) ;
127 vpMbtDistanceCylinder::buildFrom(
const vpPoint &_p1,
const vpPoint &_p2,
const double r)
157 cercle1->setWorldCoordinates(ABC[0],ABC[1],ABC[2],_p1.
get_oX(),_p1.
get_oY(),_p1.
get_oZ(),r);
158 cercle2->setWorldCoordinates(ABC[0],ABC[1],ABC[2],_p2.
get_oX(),_p2.
get_oY(),_p2.
get_oZ(),r);
171 vpMbtDistanceCylinder::setMovingEdge(
vpMe *_me)
195 vpMbtDistanceCylinder::getCylinderLineExtremity(
double &i,
double &j,
double rho,
double theta,
199 double px = cam.
get_px() ;
200 double py = cam.
get_py() ;
201 double u0 = cam.
get_u0() ;
202 double v0 = cam.
get_v0() ;
204 double mu11 = circle->
p[3];
205 double mu02 = circle->
p[4];
206 double mu20 = circle->
p[2];
207 double Xg = u0 + circle->
p[0]*px;
208 double Yg = v0 + circle->
p[1]*py;
213 double stheta = sin(theta);
214 double ctheta = cos(theta);
215 double sctheta = stheta*ctheta;
216 double m11yg = mu11*Yg;
218 double m02xg = mu02*Xg;
219 double m11stheta = mu11*stheta;
220 j = ((mu11*Xg*sctheta-mu20*Yg*sctheta+mu20*rho*ctheta
221 -m11yg+m11yg*ctheta2+m02xg-m02xg*ctheta2+
222 m11stheta*rho)/(mu20*ctheta2+2.0*m11stheta*ctheta
223 +mu02-mu02*ctheta2));
225 double rhom02 = rho*mu02;
226 double sctheta2 = stheta*ctheta2;
227 double ctheta3 = ctheta2*ctheta;
228 i = (-(-rho*mu11*stheta*ctheta-rhom02+rhom02*ctheta2
229 +mu11*Xg*sctheta2-mu20*Yg*sctheta2-ctheta*mu11*Yg
230 +ctheta3*mu11*Yg+ctheta*mu02*Xg-ctheta3*mu02*Xg)/
231 (mu20*ctheta2+2.0*mu11*stheta*ctheta+mu02-
232 mu02*ctheta2)/stheta);
248 p1->changeFrame(cMo);
249 p2->changeFrame(cMo);
250 cercle1->changeFrame(cMo);
251 cercle2->changeFrame(cMo);
257 cercle1->projection();
259 catch(...){std::cout<<
"Problem when projecting circle 1\n";}
261 cercle2->projection();
263 catch(...){std::cout<<
"Problem when projecting circle 2\n";}
270 meline1 =
new vpMbtMeLine ;
272 meline2 =
new vpMbtMeLine ;
276 meline1->setInitRange(0);
277 meline2->setInitRange(0);
284 double i11,i12,i21,i22,j11,j12,j21,j22;
285 getCylinderLineExtremity(i11, j11, rho1, theta1, cercle1);
286 getCylinderLineExtremity(i12, j12, rho1, theta1, cercle2);
287 getCylinderLineExtremity(i21, j21, rho2, theta2, cercle1);
288 getCylinderLineExtremity(i22, j22, rho2, theta2, cercle2);
299 if (ip11.
get_j()<ip12.
get_j()) { meline1->jmin = (int)ip11.
get_j()-marge ; meline1->jmax = (int)ip12.
get_j()+marge ; }
else{ meline1->jmin = (int)ip12.
get_j()-marge ; meline1->jmax = (int)ip11.
get_j()+marge ; }
300 if (ip11.
get_i()<ip12.
get_i()) { meline1->imin = (int)ip11.
get_i()-marge ; meline1->imax = (int)ip12.
get_i()+marge ; }
else{ meline1->imin = (int)ip12.
get_i()-marge ; meline1->imax = (int)ip11.
get_i()+marge ; }
302 if (ip21.
get_j()<ip22.
get_j()) { meline2->jmin = (int)ip21.
get_j()-marge ; meline2->jmax = (int)ip22.
get_j()+marge ; }
else{ meline2->jmin = (int)ip22.
get_j()-marge ; meline2->jmax = (int)ip21.
get_j()+marge ; }
303 if (ip21.
get_i()<ip22.
get_i()) { meline2->imin = (int)ip21.
get_i()-marge ; meline2->imax = (int)ip22.
get_i()+marge ; }
else{ meline2->imin = (int)ip22.
get_i()-marge ; meline2->imax = (int)ip21.
get_i()+marge ; }
308 meline1->initTracking(I,ip11,ip12,rho1,theta1);
312 vpTRACE(
"the line can't be initialized");
316 meline2->initTracking(I,ip21,ip22,rho2,theta2);
320 vpTRACE(
"the line can't be initialized");
341 std::cout <<
"Track meline1 failed" << std::endl;
350 std::cout <<
"Track meline2 failed" << std::endl;
355 nbFeaturel1 = meline1->getMeList().size();
356 nbFeaturel2 = meline2->getMeList().size();
357 nbFeature = meline1->getMeList().size()+meline2->getMeList().size();
371 p1->changeFrame(cMo);
372 p2->changeFrame(cMo);
373 cercle1->changeFrame(cMo);
374 cercle2->changeFrame(cMo);
380 cercle1->projection();
382 catch(...){std::cout<<
"Probleme projection cercle 1\n";}
384 cercle2->projection();
386 catch(...){std::cout<<
"Probleme projection cercle 2\n";}
398 double i11,i12,i21,i22,j11,j12,j21,j22;
400 getCylinderLineExtremity(i11, j11, rho1, theta1, cercle1);
401 getCylinderLineExtremity(i12, j12, rho1, theta1, cercle2);
403 getCylinderLineExtremity(i21, j21, rho2, theta2, cercle1);
404 getCylinderLineExtremity(i22, j22, rho2, theta2, cercle2);
415 if (ip11.
get_j()<ip12.
get_j()) { meline1->jmin = (int)ip11.
get_j()-marge ; meline1->jmax = (int)ip12.
get_j()+marge ; }
else{ meline1->jmin = (int)ip12.
get_j()-marge ; meline1->jmax = (int)ip11.
get_j()+marge ; }
416 if (ip11.
get_i()<ip12.
get_i()) { meline1->imin = (int)ip11.
get_i()-marge ; meline1->imax = (int)ip12.
get_i()+marge ; }
else{ meline1->imin = (int)ip12.
get_i()-marge ; meline1->imax = (int)ip11.
get_i()+marge ; }
418 if (ip21.
get_j()<ip22.
get_j()) { meline2->jmin = (int)ip21.
get_j()-marge ; meline2->jmax = (int)ip22.
get_j()+marge ; }
else{ meline2->jmin = (int)ip22.
get_j()-marge ; meline2->jmax = (int)ip21.
get_j()+marge ; }
419 if (ip21.
get_i()<ip22.
get_i()) { meline2->imin = (int)ip21.
get_i()-marge ; meline2->imax = (int)ip22.
get_i()+marge ; }
else{ meline2->imin = (int)ip22.
get_i()-marge ; meline2->imax = (int)ip21.
get_i()+marge ; }
424 meline1->updateParameters(I,ip11,ip12,rho1,theta1) ;
433 meline2->updateParameters(I,ip21,ip22,rho2,theta2) ;
441 nbFeaturel1 = meline1->getMeList().size();
442 nbFeaturel2 = meline2->getMeList().size();
443 nbFeature = meline1->getMeList().size()+meline2->getMeList().size();
466 initMovingEdge(I,cMo);
485 p1->changeFrame(cMo);
486 p2->changeFrame(cMo);
487 cercle1->changeFrame(cMo);
488 cercle2->changeFrame(cMo);
494 cercle1->projection();
496 catch(...){std::cout<<
"Problem projection circle 1";}
498 cercle2->projection();
500 catch(...){std::cout<<
"Problem projection circle 2";}
511 double i11,i12,i21,i22,j11,j12,j21,j22;
513 getCylinderLineExtremity(i11, j11, rho1, theta1, cercle1);
514 getCylinderLineExtremity(i12, j12, rho1, theta1, cercle2);
516 getCylinderLineExtremity(i21, j21, rho2, theta2, cercle1);
517 getCylinderLineExtremity(i22, j22, rho2, theta2, cercle2);
544 p1->changeFrame(cMo);
545 p2->changeFrame(cMo);
546 cercle1->changeFrame(cMo);
547 cercle2->changeFrame(cMo);
553 cercle1->projection();
555 catch(...){std::cout<<
"Problem projection circle 1";}
557 cercle2->projection();
559 catch(...){std::cout<<
"Problem projection circle 2";}
570 double i11,i12,i21,i22,j11,j12,j21,j22;
572 getCylinderLineExtremity(i11, j11, rho1, theta1, cercle1);
573 getCylinderLineExtremity(i12, j12, rho1, theta1, cercle2);
575 getCylinderLineExtremity(i21, j21, rho2, theta2, cercle1);
576 getCylinderLineExtremity(i22, j22, rho2, theta2, cercle2);
618 vpMbtDistanceCylinder::initInteractionMatrixError()
620 L.resize(meline1->getMeList().size()+meline2->getMeList().size(),6) ;
621 error.resize(meline1->getMeList().size()+meline2->getMeList().size()) ;
622 nbFeaturel1 = meline1->getMeList().size();
623 nbFeaturel2 = meline2->getMeList().size();
624 nbFeature = meline1->getMeList().size()+meline2->getMeList().size() ;
634 c->changeFrame(cMo) ;
636 cercle1->changeFrame(cMo) ;
637 cercle1->changeFrame(cMo) ;
639 cercle1->projection();
641 catch(...){std::cout<<
"Problem projection circle 1\n";}
643 cercle2->projection();
645 catch(...){std::cout<<
"Problem projection circle 2\n";}
655 double rho1 = featureline1.getRho() ;
656 double theta1 = featureline1.getTheta() ;
657 double rho2 = featureline2.getRho() ;
658 double theta2 = featureline2.getTheta() ;
660 double co1 = cos(theta1);
661 double si1 = sin(theta1);
662 double co2 = cos(theta2);
663 double si2 = sin(theta2);
665 double mx = 1.0/cam.
get_px() ;
666 double my = 1.0/cam.
get_py() ;
667 double xc = cam.
get_u0() ;
668 double yc = cam.
get_v0() ;
672 H1 = featureline1.interaction() ;
675 H2 = featureline2.interaction() ;
680 for(std::list<vpMeSite>::const_iterator it=meline1->getMeList().begin(); it!=meline1->getMeList().end(); ++it){
687 alpha1 = x*si1 - y*co1;
689 double *Lrho = H1[0] ;
690 double *Ltheta = H1[1] ;
692 for (
unsigned int k=0 ; k < 6 ; k++){
693 L[j][k] = (Lrho[k] + alpha1*Ltheta[k]);
695 error[j] = rho1 - ( x*co1 + y*si1) ;
702 for(std::list<vpMeSite>::const_iterator it=meline2->getMeList().begin(); it!=meline2->getMeList().end(); ++it){
709 alpha2 = x*si2 - y*co2;
711 double *Lrho = H2[0] ;
712 double *Ltheta = H2[1] ;
714 for (
unsigned int k=0 ; k < 6 ; k++){
715 L[j][k] = (Lrho[k] + alpha2*Ltheta[k]);
717 error[j] = rho2 - ( x*co2 + y*si2) ;
Definition of the vpMatrix class.
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
Performs search in a given direction(normal) for a given distance(pixels) for a given 'site'...
Class to define colors available for display functionnalities.
double get_oY() const
Get the point Y coordinate in the object frame.
Contains predetermined masks for sites and holds moving edges tracking parameters.
static void flush(const vpImage< unsigned char > &I)
Class that defines what is a point.
static const vpColor orange
void set_ij(const double i, const double j)
static double sqr(double x)
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
Generic class defining intrinsic camera parameters.
double get_oZ() const
Get the point Z coordinate in the object frame.
static void convertLine(const vpCameraParameters &cam, const double &rho_m, const double &theta_m, double &rho_p, double &theta_p)
line coordinates conversion (rho,theta)
double get_oX() const
Get the point X coordinate in the object frame.
Class that defines what is a cylinder.
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
virtual void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)=0
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
Class that defines what is a circle.