Visual Servoing Platform  version 3.2.0 under development (2019-01-22)
testPoseVector.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Test some vpColVector functionalities.
33  *
34  * Authors:
35  * Eric Marchand
36  *
37  *****************************************************************************/
38 
45 #include <cmath>
46 #include <limits>
47 #include <vector>
48 
49 #include <visp3/core/vpPoseVector.h>
50 
51 bool test(const std::string &s, const vpArray2D<double> &A, const std::vector<double> &bench)
52 {
53  static unsigned int cpt = 0;
54  std::cout << "** Test " << ++cpt << std::endl;
55  std::cout << s << "(" << A.getRows() << "," << A.getCols() << ") =" << A << std::endl;
56  if (bench.size() != A.size()) {
57  std::cout << "Test fails: bad size wrt bench" << std::endl;
58  return false;
59  }
60  for (unsigned int i = 0; i < A.size(); i++) {
61  if (std::fabs(A.data[i] - bench[i]) > std::fabs(A.data[i]) * std::numeric_limits<double>::epsilon()) {
62  std::cout << "Test fails: bad content" << std::endl;
63  return false;
64  }
65  }
66 
67  return true;
68 }
69 int main()
70 {
71  {
72  vpPoseVector p;
73  std::vector<double> bench(6, 0);
74  int err = 1;
75  if (test("p", p, bench) == false)
76  return err;
77  p[0] = bench[0] = 0.1;
78  p[1] = bench[1] = 0.2;
79  p[2] = bench[2] = 0.3;
80  p[3] = bench[3] = vpMath::rad(10);
81  p[4] = bench[4] = vpMath::rad(20);
82  p[5] = bench[5] = vpMath::rad(30);
83 
84  if (test("p", p, bench) == false)
85  return err;
86 
87  vpPoseVector p1(p[0], p[1], p[2], p[3], p[4], p[5]);
88  if (test("p1", p1, bench) == false)
89  return err;
90  vpPoseVector p2(p1);
91  if (test("p2", p2, bench) == false)
92  return err;
93  vpPoseVector p3 = p1;
94  if (test("p3", p3, bench) == false)
95  return err;
96  vpPoseVector p4;
97  p4.set(p[0], p[1], p[2], p[3], p[4], p[5]);
98  if (test("p4", p4, bench) == false)
99  return err;
100 
101  vpTranslationVector t(p[0], p[1], p[2]);
102  vpThetaUVector tu(p[3], p[4], p[5]);
103  vpPoseVector p5(t, tu);
104  if (test("p5", p5, bench) == false)
105  return err;
106  vpPoseVector p6;
107  p6.buildFrom(t, tu);
108  if (test("p6", p6, bench) == false)
109  return err;
110 
111  vpHomogeneousMatrix M(t, tu);
112  vpPoseVector p7(M);
113  if (test("p7", p7, bench) == false)
114  return err;
115  vpPoseVector p8;
116  p8.buildFrom(M);
117  if (test("p8", p8, bench) == false)
118  return err;
119 
120  vpRotationMatrix R(tu);
121  vpPoseVector p9(t, R);
122  if (test("p9", p9, bench) == false)
123  return err;
124  vpPoseVector p10;
125  p10.buildFrom(t, R);
126  if (test("p10", p10, bench) == false)
127  return err;
128  }
129  std::cout << "All tests succeed" << std::endl;
130  return 0;
131 }
Implementation of an homogeneous matrix and operations on such kind of matrices.
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:158
unsigned int getCols() const
Definition: vpArray2D.h:146
Implementation of a rotation matrix and operations on such kind of matrices.
void set(const double tx, const double ty, const double tz, const double tux, const double tuy, const double tuz)
unsigned int getRows() const
Definition: vpArray2D.h:156
static double rad(double deg)
Definition: vpMath.h:102
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:92
vpPoseVector buildFrom(const double tx, const double ty, const double tz, const double tux, const double tuy, const double tuz)
Class that consider the case of a translation vector.
Implementation of a rotation vector as axis-angle minimal representation.