Visual Servoing Platform  version 3.6.1 under development (2024-12-06)
testDisplacement.cpp

Tests transformation within various representations of rotation

/*
* ViSP, open source Visual Servoing Platform software.
* Copyright (C) 2005 - 2024 by Inria. All rights reserved.
*
* This software is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* See the file LICENSE.txt at the root directory of this source
* distribution for additional information about the GNU GPL.
*
* For using ViSP with software that can not be combined with the GNU
* GPL, please contact Inria about acquiring a ViSP Professional
* Edition License.
*
* See https://visp.inria.fr for more information.
*
* This software was developed at:
* Inria Rennes - Bretagne Atlantique
* Campus Universitaire de Beaulieu
* 35042 Rennes Cedex
* France
*
* If you have questions regarding the use of this file, please contact
* Inria at visp@inria.fr
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Description:
* Tests transformation within various representations of rotation.
*/
#include <stdio.h>
#include <stdlib.h>
#include <visp3/core/vpDebug.h>
#include <visp3/core/vpMath.h>
#include <visp3/core/vpRotationMatrix.h>
#include <visp3/core/vpThetaUVector.h>
#include <visp3/vision/vpHomography.h>
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
bool test(const std::string &s, const vpHomography &H, const std::vector<double> &bench)
{
static unsigned int cpt = 0;
std::cout << "** Test " << ++cpt << std::endl;
std::cout << s << "(" << H.getRows() << "," << H.getCols() << ") = \n[" << H << "]" << std::endl;
if (bench.size() != H.size()) {
std::cout << "Test fails: bad size wrt bench" << std::endl;
return false;
}
for (unsigned int i = 0; i < H.size(); i++) {
if (std::fabs(H.data[i] - bench[i]) > std::fabs(H.data[i]) * std::numeric_limits<double>::epsilon()) {
std::cout << "Test fails: bad content" << std::endl;
return false;
}
}
return true;
}
int main()
{
#if (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
try {
{
H.eye();
std::vector<double> bench(9, 0);
bench[0] = bench[4] = bench[8] = 1.;
int err = 1;
if (test("H", H, bench) == false)
return err;
if (test("H", H / H[2][2], bench) == false)
return err;
}
{
std::cout << "Initialization " << std::endl;
// std::cout << tu << std::endl ;
std::cout << "From vpThetaUVector to vpRotationMatrix " << std::endl;
// pure rotation
M.insert(R);
std::cout << "M" << std::endl << M << std::endl;
vpPlane p(0, 0, 1, 1);
vpHomography H(M, p);
std::cout << "H" << std::endl << H << std::endl;
H.computeDisplacement(R, T, n);
std::cout << "R" << std::endl << R;
std::cout << "T" << std::endl << T.t() << std::endl;
std::cout << "n" << std::endl << n.t() << std::endl;
}
std::cout << "------------------------------------------------------" << std::endl;
{
std::cout << "Initialization " << std::endl;
// std::cout << tu << std::endl ;
std::cout << "From vpThetaUVector to vpRotationMatrix " << std::endl;
// pure rotation
M.insert(R);
M[0][3] = 0.21;
M[1][3] = 0.31;
M[2][3] = 0.5;
std::cout << "M" << std::endl << M << std::endl;
vpPlane p(0, 0, 1, 1);
vpHomography H(M, p);
std::cout << "H" << std::endl << H << std::endl;
H.computeDisplacement(R, T, n);
std::cout << "R" << std::endl << R;
std::cout << "T" << std::endl << T.t() << std::endl;
std::cout << "n" << std::endl << n.t() << std::endl;
}
std::cout << "------------------------------------------------------" << std::endl;
{
// pure rotation
M.insert(R);
M[0][3] = 0.21;
M[1][3] = -0.31;
M[2][3] = 0.5;
std::cout << "M" << std::endl << M << std::endl;
vpPlane p(0.4, -0.5, 0.5, 1);
vpHomography H(M, p);
std::cout << "H" << std::endl << H << std::endl;
H.computeDisplacement(R, T, n);
std::cout << "R" << std::endl << R;
std::cout << "T" << std::endl << T.t() << std::endl;
std::cout << "n" << std::endl << n.t() << std::endl;
vpPlane p1(n[0], n[1], n[2], 1.0);
H.buildFrom(R, T, p1);
std::cout << "H" << std::endl << H << std::endl;
}
std::cout << "All tests succeed" << std::endl;
return EXIT_SUCCESS;
}
catch (const vpException &e) {
std::cout << "Catch an exception: " << e << std::endl;
return EXIT_FAILURE;
}
#else
std::cout << "Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
return EXIT_SUCCESS;
#endif
}
unsigned int getCols() const
Definition: vpArray2D.h:337
Type * data
Address of the first element of the data array.
Definition: vpArray2D.h:148
unsigned int size() const
Return the number of elements of the 2D array.
Definition: vpArray2D.h:349
unsigned int getRows() const
Definition: vpArray2D.h:347
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
vpRowVector t() const
error that can be emitted by ViSP classes.
Definition: vpException.h:60
Implementation of an homogeneous matrix and operations on such kind of matrices.
void insert(const vpRotationMatrix &R)
Implementation of an homography and operations on homographies.
Definition: vpHomography.h:174
void computeDisplacement(vpRotationMatrix &aRb, vpTranslationVector &atb, vpColVector &n)
vpHomography & buildFrom(const vpRotationMatrix &aRb, const vpTranslationVector &atb, const vpPlane &bP)
Construction from translation and rotation and a plane.
static double rad(double deg)
Definition: vpMath.h:129
This class defines the container for a plane geometrical structure.
Definition: vpPlane.h:57
Implementation of a rotation matrix and operations on such kind of matrices.
Implementation of a rotation vector as axis-angle minimal representation.
Class that consider the case of a translation vector.
vpRowVector t() const