Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testDisplacement.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Tests transformation within various representations of rotation.
32  *
33  * Authors:
34  * Eric Marchand
35  *
36  *****************************************************************************/
37 
38 
48 #include <visp3/core/vpMath.h>
49 #include <visp3/core/vpRotationMatrix.h>
50 #include <visp3/vision/vpHomography.h>
51 #include <visp3/core/vpDebug.h>
52 #include <visp3/core/vpThetaUVector.h>
53 #include <stdlib.h>
54 #include <stdio.h>
55 
56 bool test(const std::string &s, const vpHomography &H, const std::vector<double> &bench)
57 {
58  static unsigned int cpt = 0;
59  std::cout << "** Test " << ++cpt << std::endl;
60  std::cout << s << "(" << H.getRows() << "," << H.getCols() << ") = \n[" << H << "]" << std::endl;
61  if(bench.size() != H.size()) {
62  std::cout << "Test fails: bad size wrt bench" << std::endl;
63  return false;
64  }
65  for (unsigned int i=0; i<H.size(); i++) {
66  if (std::fabs(H.data[i]-bench[i]) > std::fabs(H.data[i])*std::numeric_limits<double>::epsilon()) {
67  std::cout << "Test fails: bad content" << std::endl;
68  return false;
69  }
70  }
71 
72  return true;
73 }
74 
75 int main()
76 {
77  try {
78  {
79  vpHomography H;
80  H.eye();
81  std::vector<double> bench(9, 0);
82  bench[0] = bench[4] = bench[8] = 1.;
83  int err = 1;
84  if (test("H", H, bench) == false)
85  return err;
86  if (test("H", H/H[2][2], bench) == false)
87  return err;
88  }
89  {
91 
92  std::cout << "Initialization " <<std::endl ;
93  // std::cout << tu << std::endl ;
94 
95  std::cout << "From vpThetaUVector to vpRotationMatrix " << std::endl ;
96  vpRotationMatrix R(tu) ;
97 
98  // pure rotation
100  M.insert(R) ;
101 
102  std::cout << "M" <<std::endl <<M << std::endl ;
103  vpPlane p(0,0,1,1) ;
104 
105  vpHomography H(M,p) ;
106 
107  std::cout << "H" <<std::endl <<H << std::endl ;
108 
109  vpColVector n ;
111 
112  H.computeDisplacement(R,T,n) ;
113 
114  std::cout << "R" <<std::endl << R ;
115  std::cout << "T" <<std::endl << T.t() << std::endl;
116  std::cout << "n" <<std::endl << n.t() << std::endl;
117  }
118  std::cout <<"------------------------------------------------------" << std::endl ;
119 
120  {
122 
123  std::cout << "Initialization " << std::endl ;
124  // std::cout << tu << std::endl ;
125 
126  std::cout << "From vpThetaUVector to vpRotationMatrix " << std::endl ;
127  vpRotationMatrix R(tu) ;
128 
129  // pure rotation
131  M.insert(R) ;
132 
133  M[0][3] = 0.21 ;
134  M[1][3] = 0.31 ;
135  M[2][3] = 0.5 ;
136 
137  std::cout << "M" << std::endl << M << std::endl ;
138  vpPlane p(0,0,1,1) ;
139 
140  vpHomography H(M,p) ;
141 
142  std::cout << "H" << std::endl << H << std::endl ;
143 
144  vpColVector n ;
146 
147  H.computeDisplacement(R,T,n) ;
148 
149  std::cout << "R" <<std::endl << R ;
150  std::cout << "T" <<std::endl << T.t() << std::endl;
151  std::cout << "n" <<std::endl << n.t() << std::endl;
152  }
153 
154  std::cout <<"------------------------------------------------------" << std::endl ;
155  {
156  vpThetaUVector tu(vpMath::rad(-190), vpMath::rad(12), vpMath::rad(-45)) ;
157 
158  vpRotationMatrix R(tu) ;
159 
160  // pure rotation
162  M.insert(R) ;
163 
164  M[0][3] = 0.21 ;
165  M[1][3] = -0.31 ;
166  M[2][3] = 0.5 ;
167 
168  std::cout << "M" << std::endl << M << std::endl ;
169  vpPlane p(0.4,-0.5,0.5,1) ;
170 
171  vpHomography H(M,p) ;
172 
173  std::cout << "H" << std::endl << H << std::endl ;
174 
175  vpColVector n ;
177  H.computeDisplacement(R,T,n) ;
178 
179  std::cout << "R" <<std::endl << R ;
180  std::cout << "T" <<std::endl << T.t() << std::endl;
181  std::cout << "n" <<std::endl << n.t() << std::endl;
182 
183  vpPlane p1(n[0],n[1],n[2],1.0) ;
184  H.buildFrom(R,T,p1) ;
185  std::cout << "H" << std::endl << H << std::endl ;
186  }
187  std::cout << "All tests succeed" << std::endl;
188  return 0;
189  }
190  catch(vpException &e) {
191  std::cout << "Catch an exception: " << e << std::endl;
192  return 1;
193  }
194 }
void buildFrom(const vpRotationMatrix &aRb, const vpTranslationVector &atb, const vpPlane &bP)
Construction from Translation and rotation and a plane.
Implementation of an homogeneous matrix and operations on such kind of matrices.
error that can be emited by ViSP classes.
Definition: vpException.h:73
Type * data
Address of the first element of the data array.
Definition: vpArray2D.h:84
unsigned int size() const
Return the number of elements of the 2D array.
Definition: vpArray2D.h:156
unsigned int getCols() const
Return the number of columns of the 2D array.
Definition: vpArray2D.h:154
void computeDisplacement(vpRotationMatrix &aRb, vpTranslationVector &atb, vpColVector &n)
Implementation of a rotation matrix and operations on such kind of matrices.
void insert(const vpRotationMatrix &R)
Implementation of an homography and operations on homographies.
Definition: vpHomography.h:179
vpRowVector t() const
vpRowVector t() const
unsigned int getRows() const
Return the number of rows of the 2D array.
Definition: vpArray2D.h:152
static double rad(double deg)
Definition: vpMath.h:104
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
This class defines the container for a plane geometrical structure.
Definition: vpPlane.h:58
Class that consider the case of a translation vector.
Implementation of a rotation vector as axis-angle minimal representation.