Visual Servoing Platform  version 3.4.0
testTranslationVector.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/vpTranslationVector.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  int err = 1;
72  {
74  std::vector<double> bench(3, 0);
75  if (test("t", t, bench) == false)
76  return err;
77  }
78  {
79  vpTranslationVector t1(1, 2, 3);
80  std::vector<double> bench(3);
81  bench[0] = 1;
82  bench[1] = 2;
83  bench[2] = 3;
84  if (test("t1", t1, bench) == false)
85  return err;
86 
87  vpTranslationVector t2(4, 5, 6);
88  bench[0] = 4;
89  bench[1] = 5;
90  bench[2] = 6;
91  if (test("t2", t2, bench) == false)
92  return err;
93 
94  vpTranslationVector t3 = t1 + t2;
95  bench[0] = 5;
96  bench[1] = 7;
97  bench[2] = 9;
98  if (test("t3", t3, bench) == false)
99  return err;
100 
101  vpMatrix skew = t3.skew();
102  std::vector<double> bench1(9, 0);
103  bench1[1] = -9;
104  bench1[2] = 7;
105  bench1[3] = 9;
106  bench1[5] = -5;
107  bench1[6] = -7;
108  bench1[7] = 5;
109  if (test("skew", skew, bench1) == false)
110  return err;
111 
113  t4.set(-1, -2, -3);
114  bench[0] = -1;
115  bench[1] = -2;
116  bench[2] = -3;
117  if (test("t4", t4, bench) == false)
118  return err;
119 
120  vpTranslationVector t5 = t4 * 2;
121  bench[0] = -2;
122  bench[1] = -4;
123  bench[2] = -6;
124  if (test("t5", t5, bench) == false)
125  return err;
126 
128  bench[0] = 0;
129  bench[1] = 0;
130  bench[2] = 0;
131  if (test("t6", t6, bench) == false)
132  return err;
133  }
134  std::cout << "All tests succeed" << std::endl;
135  return 0;
136 }
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:153
static vpTranslationVector cross(const vpTranslationVector &a, const vpTranslationVector &b)
Type * data
Address of the first element of the data array.
Definition: vpArray2D.h:145
unsigned int size() const
Return the number of elements of the 2D array.
Definition: vpArray2D.h:291
unsigned int getCols() const
Definition: vpArray2D.h:279
unsigned int getRows() const
Definition: vpArray2D.h:289
void set(double tx, double ty, double tz)
Class that consider the case of a translation vector.