34 #include <visp3/vision/vpPose.h>
36 #define DEBUG_LEVEL1 0
37 #define DEBUG_LEVEL2 0
46 static void calculTranslation(
vpMatrix &a,
vpMatrix &b,
unsigned int nl,
unsigned int nc1,
unsigned int nc3,
54 for (i = 0; i < 3; i++) {
55 for (j = 0; j < nl; j++)
56 ct[i][j] = b[j][i + nc3];
75 std::cout <<
"ctc " << std::endl << ctc;
76 std::cout <<
"cta " << std::endl << cta;
77 std::cout <<
"ctb " << std::endl << ctb;
83 for (i = 0; i < nc1; i++) {
84 for (j = 0; j < nc3; j++)
85 CTB[i][j] = ctb[i][j];
88 for (j = 0; j < nc3; j++)
92 sv = cta * x1 + CTB * X2;
95 std::cout <<
"sv " << sv.
t();
102 std::cout <<
"x3 " << X3.
t();
105 for (i = 0; i < nc1; i++)
129 std::cout <<
"begin (CLagrange.cc)Lagrange(...) " << std::endl;
133 unsigned int i, imin;
179 std::cout <<
" BTB1 * BTB : " << std::endl << btb1 * btb << std::endl;
180 std::cout <<
" BTB * BTB1 : " << std::endl << btb * btb1 << std::endl;
188 e = -(a.
t() * b) * r;
194 std::cout <<
" E :" << std::endl << e << std::endl;
212 for (i = 0; i < x1.
getRows(); i++)
213 if (x1[i] < x1[imin])
218 printf(
"SV(E) : %.15lf %.15lf %.15lf\n", x1[0], x1[1], x1[2]);
219 std::cout <<
" i_min " << imin << std::endl;
222 for (i = 0; i < x1.
getRows(); i++)
223 x1[i] = ata[i][imin];
229 std::cout <<
" X1 : " << x1.
t() << std::endl;
230 std::cout <<
" V : " << std::endl << ata << std::endl;
238 std::cout <<
"end (CLagrange.cc)Lagrange(...) " << std::endl;
258 std::cout <<
"begin vpPose::PoseLagrangePlan(...) " << std::endl;
264 if((p_isPlan != NULL) && (p_a != NULL) && (p_b != NULL) && (p_c != NULL) && (p_d != NULL))
277 throw vpException(
vpException::fatalError,
"Called vpPose::poseLagrangePlan but the call to vpPose::coplanar done outside the method indicated that the points are not coplanar");
284 bool areCoplanar =
coplanar(coplanarType, &a, &b, &c, &d);
299 double n = 1.0 / sqrt(a * a + b * b + c * c);
312 double n1 = sqrt(1.0 - a * a);
313 double n2 = sqrt(1.0 - b * b);
330 for (
unsigned int i = 0; i < 3; i++) {
335 fMo[0][3] = fMo[1][3] = 0.0;
341 unsigned int nl =
npt * 2;
347 for (std::list<vpPoint>::const_iterator it =
listP.begin(); it !=
listP.end(); ++it) {
361 A[k][2] = Xf[0] * P.
get_x();
364 A[k + 1][1] = -Xf[0];
365 A[k + 1][2] = Xf[0] * P.
get_y();
369 B[k][2] = Xf[1] * P.
get_x();
375 B[k + 1][1] = -Xf[1];
376 B[k + 1][2] = Xf[1] * P.
get_y();
379 B[k + 1][5] = P.
get_y();
388 std::cout <<
"A " << std::endl << A << std::endl;
389 std::cout <<
"B " << std::endl << B << std::endl;
393 lagrange(A, B, X1, X2);
397 std::cout <<
"A X1+B X2 (should be 0): " << (A * X1 + B * X2).t() << std::endl;
398 std::cout <<
" X1 norm: " << X1.
sumSquare() << std::endl;
403 for (
unsigned int i = 0; i < 3; i++)
405 for (
unsigned int i = 0; i < 6; i++)
409 for (
unsigned int i = 0; i < 3; i++) {
410 s += (X1[i] * X2[i]);
412 for (
unsigned int i = 0; i < 3; i++) {
413 X2[i] -= (s * X1[i]);
418 s = X2[0] * X2[0] + X2[1] * X2[1] + X2[2] * X2[2];
431 "(planar plane case)"));
435 for (
unsigned int i = 0; i < 3; i++) {
439 calculTranslation(A, B, nl, 3, 3, X1, X2);
449 cMf[0][2] = (X1[1] * X2[2]) - (X1[2] * X2[1]);
450 cMf[1][2] = (X1[2] * X2[0]) - (X1[0] * X2[2]);
451 cMf[2][2] = (X1[0] * X2[1]) - (X1[1] * X2[0]);
453 for (
unsigned int i = 0; i < 3; i++) {
456 cMf[i][3] = X2[i + 3];
464 std::cout <<
"end vpCalculPose::PoseLagrangePlan(...) " << std::endl;
473 std::cout <<
"begin CPose::PoseLagrangeNonPlan(...) " << std::endl;
480 unsigned int nl =
npt * 2;
484 "Lagrange, non planar case, insufficient number of points %d < 6\n",
npt));
493 for (std::list<vpPoint>::const_iterator it =
listP.begin(); it !=
listP.end(); ++it) {
500 a[k + 1][1] = -P.
get_oX();
516 b[k + 1][1] = -P.
get_oY();
520 b[k + 1][4] = -P.
get_oZ();
525 b[k + 1][8] = P.
get_y();
534 std::cout <<
"a " << a << std::endl;
535 std::cout <<
"b " << b << std::endl;
539 lagrange(a, b, X1, X2);
549 std::cout <<
"ax1+bx2 (devrait etre 0) " << (a * X1 + b * X2).t() << std::endl;
550 std::cout <<
"norme X1 " << X1.
sumSquare() << std::endl;
559 for (i = 0; i < 3; i++) {
560 s += (X1[i] * X2[i]);
562 for (i = 0; i < 3; i++) {
563 X2[i] -= (s * X1[i]);
568 s = X2[0] * X2[0] + X2[1] * X2[1] + X2[2] * X2[2];
582 "planar plane case)"));
586 for (i = 0; i < 3; i++) {
590 X2[3] = (X1[1] * X2[2]) - (X1[2] * X2[1]);
591 X2[4] = (X1[2] * X2[0]) - (X1[0] * X2[2]);
592 X2[5] = (X1[0] * X2[1]) - (X1[1] * X2[0]);
594 calculTranslation(a, b, nl, 3, 6, X1, X2);
596 for (i = 0; i < 3; i++) {
599 cMo[i][2] = X2[i + 3];
600 cMo[i][3] = X2[i + 6];
608 std::cout <<
"end vpCalculPose::PoseLagrangeNonPlan(...) " << std::endl;
unsigned int getCols() const
unsigned int getRows() const
Implementation of column vector and the associated operations.
static vpColVector crossProd(const vpColVector &a, const vpColVector &b)
error that can be emitted by ViSP classes.
@ dimensionError
Bad dimension.
@ divideByZeroError
Division by zero.
Implementation of an homogeneous matrix and operations on such kind of matrices.
Implementation of a matrix and operations on matrices.
vpMatrix inverseByLU() const
void svd(vpColVector &w, vpMatrix &V)
vpMatrix pseudoInverse(double svThreshold=1e-6) const
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
double get_oX() const
Get the point oX coordinate in the object frame.
double get_y() const
Get the point y coordinate in the image plane.
double get_oZ() const
Get the point oZ coordinate in the object frame.
double get_x() const
Get the point x coordinate in the image plane.
double get_oY() const
Get the point oY coordinate in the object frame.
unsigned int npt
Number of point used in pose computation.
void poseLagrangePlan(vpHomogeneousMatrix &cMo, bool *p_isPlan=NULL, double *p_a=NULL, double *p_b=NULL, double *p_c=NULL, double *p_d=NULL)
Compute the pose of a planar object using Lagrange approach.
std::list< vpPoint > listP
Array of point (use here class vpPoint)
void poseLagrangeNonPlan(vpHomogeneousMatrix &cMo)
bool coplanar(int &coplanar_plane_type, double *p_a=NULL, double *p_b=NULL, double *p_c=NULL, double *p_d=NULL)