Visual Servoing Platform  version 3.6.1 under development (2024-04-16)
testTranslationVector.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 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 https://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 *****************************************************************************/
35 
42 #include <cmath>
43 #include <limits>
44 #include <vector>
45 
46 #include <visp3/core/vpTranslationVector.h>
47 
48 bool test(const std::string &s, const vpArray2D<double> &A, const std::vector<double> &bench)
49 {
50  static unsigned int cpt = 0;
51  std::cout << "** Test " << ++cpt << std::endl;
52  std::cout << s << "(" << A.getRows() << "," << A.getCols() << ") =" << A << std::endl;
53  if (bench.size() != A.size()) {
54  std::cout << "Test fails: bad size wrt bench" << std::endl;
55  return false;
56  }
57  for (unsigned int i = 0; i < A.size(); i++) {
58  if (std::fabs(A.data[i] - bench[i]) > std::fabs(A.data[i]) * std::numeric_limits<double>::epsilon()) {
59  std::cout << "Test fails: bad content" << std::endl;
60  return false;
61  }
62  }
63 
64  return true;
65 }
66 int main()
67 {
68  int err = 1;
69  {
71  std::vector<double> bench(3, 0);
72  if (test("t", t, bench) == false)
73  return err;
74  }
75  {
76  vpTranslationVector t1(1, 2, 3);
77  std::vector<double> bench(3);
78  bench[0] = 1;
79  bench[1] = 2;
80  bench[2] = 3;
81  if (test("t1", t1, bench) == false)
82  return err;
83 
84  vpTranslationVector t2(4, 5, 6);
85  bench[0] = 4;
86  bench[1] = 5;
87  bench[2] = 6;
88  if (test("t2", t2, bench) == false)
89  return err;
90 
91  vpTranslationVector t3 = t1 + t2;
92  bench[0] = 5;
93  bench[1] = 7;
94  bench[2] = 9;
95  if (test("t3", t3, bench) == false)
96  return err;
97 
98  vpMatrix skew = t3.skew();
99  std::vector<double> bench1(9, 0);
100  bench1[1] = -9;
101  bench1[2] = 7;
102  bench1[3] = 9;
103  bench1[5] = -5;
104  bench1[6] = -7;
105  bench1[7] = 5;
106  if (test("skew", skew, bench1) == false)
107  return err;
108 
110  t4.set(-1, -2, -3);
111  bench[0] = -1;
112  bench[1] = -2;
113  bench[2] = -3;
114  if (test("t4", t4, bench) == false)
115  return err;
116 
117  vpTranslationVector t5 = t4 * 2;
118  bench[0] = -2;
119  bench[1] = -4;
120  bench[2] = -6;
121  if (test("t5", t5, bench) == false)
122  return err;
123 
125  bench[0] = 0;
126  bench[1] = 0;
127  bench[2] = 0;
128  if (test("t6", t6, bench) == false)
129  return err;
130  }
131  std::cout << "All tests succeed" << std::endl;
132  return EXIT_SUCCESS;
133 }
unsigned int getCols() const
Definition: vpArray2D.h:314
Type * data
Address of the first element of the data array.
Definition: vpArray2D.h:139
unsigned int size() const
Return the number of elements of the 2D array.
Definition: vpArray2D.h:326
unsigned int getRows() const
Definition: vpArray2D.h:324
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:146
Class that consider the case of a translation vector.
void set(double tx, double ty, double tz)
static vpTranslationVector cross(const vpTranslationVector &a, const vpTranslationVector &b)