45 #include <visp/vpPose.h>
46 #include <visp/vpMath.h>
48 #define DEBUG_LEVEL1 0
49 #define DEBUG_LEVEL2 0
50 #define DEBUG_LEVEL3 0
68 double normI = 0., normJ = 0.;
77 for (std::list<vpPoint>::const_iterator it =
listP.begin(); it !=
listP.end(); ++it)
96 for (
unsigned int i=0 ; i <
npt ; i++)
98 a[i][0]=c3d[i].get_oX();
99 a[i][1]=c3d[i].get_oY();
100 a[i][2]=c3d[i].get_oZ();
117 std::cout <<
"a" << std::endl <<a<<std::endl ;
118 std::cout <<
"ata" << std::endl <<ata<<std::endl ;
119 std::cout <<
"ata1" << std::endl <<ata1<<std::endl ;
120 std::cout<<
" ata*ata1" << std::endl << ata*ata1 ;
121 std::cout<<
" b" << std::endl << (a*ata1).t() ;
166 for (
unsigned int i=0;i<
npt;i++)
168 xprim[i]=(1+ eps[i])*c3d[i].get_x() - c3d[0].get_x();
169 yprim[i]=(1+ eps[i])*c3d[i].get_y() - c3d[0].get_y();
178 if (normI+normJ < 1e-10)
182 "division by zero ")) ;
186 Z0=2*f/(normI+normJ);
187 cpt=cpt+1; seuil=0.0;
188 for (
unsigned int i=0; i<
npt; i++)
190 double epsi_1 = eps[i] ;
191 eps[i]=(c3d[i].get_oX()*k[0]+c3d[i].get_oY()*k[1]+c3d[i].get_oZ()*k[2])/Z0;
192 seuil+=fabs(eps[i]-epsi_1);
198 "division by zero ")) ;
209 cMo[0][3]=c3d[0].get_x()*2/(normI+normJ);
214 cMo[1][3]=c3d[0].get_y()*2/(normI+normJ);
228 #define EPS 0.0000001
229 #define EPS_DEM 0.001
232 calculRTheta(
double s,
double c,
double &r,
double &theta)
234 if ((fabs(c) > EPS_DEM) || (fabs(s) > EPS_DEM))
236 r = sqrt(sqrt(s*s+c*c));
237 theta = atan2(s,c)/2.0;
241 if (fabs(c) > fabs(s))
261 void calculSolutionDementhon(
double xi0,
double yi0,
267 std::cout <<
"begin (Dementhon.cc)CalculSolutionDementhon() " << std::endl;
270 double normI, normJ, normk, Z0;
283 Z0=2.0/(normI+normJ);
285 normk = sqrt(k.sumSquare()) ;
308 std::cout <<
"end (Dementhon.cc)CalculSolutionDementhon() " << std::endl;
319 std::cout <<
"begin vpPose::CalculArbreDementhon() " << std::endl;
326 double smin,smin_old, s1,s2;
330 unsigned int iter_max = 20;
335 for(i = 0; i <
npt; i++)
338 z = cMo[2][0]*c3d[i].get_oX()+cMo[2][1]*c3d[i].get_oY()+cMo[2][2]*c3d[i].get_oZ() + cMo[2][3];
339 if (z <= 0.0) erreur = -1;
350 for(i = 0; i <
npt; i++)
352 xi[k] = c3d[i].get_x();
353 yi[k] = c3d[i].get_y();
357 eps[0][k] = (cMo[2][0]*c3d[i].get_oX() +
358 cMo[2][1]*c3d[i].get_oY() +
359 cMo[2][2]*c3d[i].get_oZ())/cMo[2][3];
373 while ((cpt<20) && (smin_old > 0.01) && (smin <= smin_old))
377 std::cout <<
"cpt " << cpt << std::endl ;
378 std::cout <<
"smin_old " << smin_old << std::endl ;
379 std::cout <<
"smin " << smin << std::endl ;
391 s = (1.0+eps[cpt][i])*xi[i] - xi[0];
392 I0[0] += b[0][i-1] * s;
393 I0[1] += b[1][i-1] * s;
394 I0[2] += b[2][i-1] * s;
395 s = (1.0+eps[cpt][i])*yi[i] - yi[0];
396 J0[0] += b[0][i-1] * s;
397 J0[1] += b[1][i-1] * s;
398 J0[2] += b[2][i-1] * s;
404 calculRTheta(s,c,r,theta);
414 std::cout <<
"I " << I.
t() ;
415 std::cout <<
"J " << J.
t() ;
419 calculSolutionDementhon(xi[0],yi[0],I,J,cMo1);
422 std::cout <<
"cMo1 "<< std::endl << cMo1 << std::endl ;
430 std::cout <<
"I " << I.
t() ;
431 std::cout <<
"J " << J.
t() ;
435 calculSolutionDementhon(xi[0],yi[0],I,J,cMo2);
438 std::cout <<
"cMo2 "<< std::endl << cMo2 << std::endl ;
446 for(i = 0; i <
npt; i++)
449 eps[cpt][k] = (cMo1[2][0]*c3d[i].get_oX() + cMo1[2][1]*c3d[i].get_oY()
450 + cMo1[2][2]*c3d[i].get_oZ())/cMo1[2][3];
460 for(i = 0; i <
npt; i++)
463 eps[cpt][k] = (cMo2[2][0]*c3d[i].get_oX() + cMo2[2][1]*c3d[i].get_oY()
464 + cMo2[2][2]*c3d[i].get_oZ())/cMo2[2][3];
474 std::cout <<
"Divergence " << std::endl ;
481 std::cout <<
"s1 = " << s1 << std::endl ;
482 std::cout <<
"s2 = " << s2 << std::endl ;
483 std::cout <<
"smin = " << smin << std::endl ;
484 std::cout <<
"smin_old = " << smin_old << std::endl ;
490 std::cout <<
"end vpPose::CalculArbreDementhon() return "<< erreur << std::endl;
508 std::cout <<
"begin CCalculPose::PoseDementhonPlan()" << std::endl ;
517 for (std::list<vpPoint>::const_iterator it =
listP.begin(); it !=
listP.end(); ++it)
538 for (i=1 ; i <
npt ; i++)
540 a[i-1][0]=c3d[i].get_oX();
541 a[i-1][1]=c3d[i].get_oY();
542 a[i-1][2]=c3d[i].get_oZ();
563 std::cout <<
"a" << std::endl <<a<<std::endl ;
564 std::cout <<
"ata" << std::endl <<ata<<std::endl ;
573 unsigned int imin = 0;
579 unsigned int nc = sv.getRows() ;
580 for (i=0; i < nc ; i++)
581 if (sv[i] > s) s = sv[i];
586 if (sv[i] > s ) irank++;
589 for (i = 0; i < nc; i++)
590 if (sv[i] < svm) { imin = i; svm = sv[i]; }
594 std::cout <<
"rang: " << irank << std::endl ;;
595 std::cout <<
"imin = " << imin << std::endl ;
596 std::cout <<
"sv " << sv.t() << std::endl ;
600 for (i=0 ; i < ata.
getRows() ; i++)
601 for (j=0 ; j < ata.
getCols() ; j++)
604 for (k=0 ; k < nc ; k++)
606 ata1[i][j] += ((v[i][k]*ata[j][k])/sv[k]);
620 std::cout <<
"a" << std::endl <<a<<std::endl ;
621 std::cout <<
"ata" << std::endl <<ata_sav<<std::endl ;
622 std::cout <<
"ata1" << std::endl <<ata1<<std::endl ;
623 std::cout <<
"ata1*ata" << std::endl << ata1*ata_sav ;
624 std::cout <<
"b" << std::endl << b ;
625 std::cout <<
"U " << U.
t() << std::endl ;
632 for (i = 0; i <
npt; i++)
634 xi[i] = c3d[i].get_x() ;
635 yi[i] = c3d[i].get_y() ;
646 I0[0] += b[0][i-1] * (xi[i]-xi[0]);
647 I0[1] += b[1][i-1] * (xi[i]-xi[0]);
648 I0[2] += b[2][i-1] * (xi[i]-xi[0]);
650 J0[0] += b[0][i-1] * (yi[i]-yi[0]);
651 J0[1] += b[1][i-1] * (yi[i]-yi[0]);
652 J0[2] += b[2][i-1] * (yi[i]-yi[0]);
658 std::cout <<
"I0 "<<I0.
t() ;
659 std::cout <<
"J0 "<<J0.
t() ;
666 double r,theta,si,co ;
667 calculRTheta(s, c, r, theta);
676 calculSolutionDementhon(xi[0], yi[0], I, J, cMo1f);
686 calculSolutionDementhon(xi[0], yi[0], I, J, cMo2f);
690 if ((erreur1 == 0) && (erreur2 == -1)) cMo = cMo1f ;
691 if ((erreur1 == -1) && (erreur2 == 0)) cMo = cMo2f ;
692 if ((erreur1 == 0) && (erreur2 == 0))
697 if (s1<=s2) cMo = cMo1f ;
else cMo = cMo2f ;
705 std::cout <<
"end CCalculPose::PoseDementhonPlan()" << std::endl ;
724 double residual_ = 0 ;
727 for (
unsigned int i =0 ; i <
npt ; i++)
730 double X = c3d[i].get_oX()*cMo[0][0]+c3d[i].get_oY()*cMo[0][1]+c3d[i].get_oZ()*cMo[0][2] + cMo[0][3];
731 double Y = c3d[i].get_oX()*cMo[1][0]+c3d[i].get_oY()*cMo[1][1]+c3d[i].get_oZ()*cMo[1][2] + cMo[1][3];
732 double Z = c3d[i].get_oX()*cMo[2][0]+c3d[i].get_oY()*cMo[2][1]+c3d[i].get_oZ()*cMo[2][2] + cMo[2][3];
int calculArbreDementhon(vpMatrix &b, vpColVector &U, vpHomogeneousMatrix &cMo)
Definition of the vpMatrix class.
void resize(const unsigned int nrows, const unsigned int ncols, const bool nullify=true)
static vpColVector cross(const vpColVector &a, const vpColVector &b)
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
double get_oY() const
Get the point Y coordinate in the object frame.
error that can be emited by ViSP classes.
double sumSquare() const
return sum of the Aij^2 (for all i, for all j)
std::list< vpPoint > listP
array of point (use here class vpPoint)
void set_oX(const double X)
Set the point X coordinate in the object frame.
vpColVector column(const unsigned int j)
Column extraction.
Class that defines what is a point.
void set_oZ(const double Z)
Set the point Z coordinate in the object frame.
void svd(vpColVector &w, vpMatrix &v)
static double sqr(double x)
vpRowVector t() const
transpose of Vector
double get_oZ() const
Get the point Z coordinate in the object frame.
unsigned int npt
number of point used in pose computation
double get_oX() const
Get the point X coordinate in the object frame.
void poseDementhonPlan(vpHomogeneousMatrix &cMo)
compute the pose using Dementhon approach (planar object)
void poseDementhonNonPlan(vpHomogeneousMatrix &cMo)
compute the pose using Dementhon approach (non planar object)
Class that provides a data structure for the column vectors as well as a set of operations on these v...
unsigned int getCols() const
Return the number of columns of the matrix.
static double dotProd(const vpColVector &a, const vpColVector &b)
Dot Product.
vpMatrix pseudoInverse(double svThreshold=1e-6) const
Compute the pseudo inverse of the matrix using the SVD.
unsigned int getRows() const
Return the number of rows of the matrix.
vpColVector & normalize()
normalise the vector
double computeResidualDementhon(const vpHomogeneousMatrix &cMo)
Compute and return the residual expressed in meter for the pose matrix 'pose'.
void set_oY(const double Y)
Set the point Y coordinate in the object frame.
void resize(const unsigned int i, const bool flagNullify=true)