Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
testTranslationVector.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
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 https://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  * Test some vpColVector functionalities.
32  */
33 
40 #include <cmath>
41 #include <vector>
42 
43 #include <visp3/core/vpTranslationVector.h>
44 
45 #ifdef ENABLE_VISP_NAMESPACE
46 using namespace VISP_NAMESPACE_NAME;
47 #endif
48 
49 bool test(const std::string &s, const vpArray2D<double> &A, const std::vector<double> &bench)
50 {
51  static unsigned int cpt = 0;
52  std::cout << "** Test " << ++cpt << std::endl;
53  std::cout << s << "(" << A.getRows() << "," << A.getCols() << ") =" << A << std::endl;
54  if (bench.size() != A.size()) {
55  std::cout << "Test fails: bad size wrt bench" << std::endl;
56  return false;
57  }
58  for (unsigned int i = 0; i < A.size(); i++) {
59  if (std::fabs(A.data[i] - bench[i]) > std::fabs(A.data[i]) * std::numeric_limits<double>::epsilon()) {
60  std::cout << "Test fails: bad content" << std::endl;
61  return false;
62  }
63  }
64 
65  return true;
66 }
67 int main()
68 {
69  int err = 1;
70  {
72  std::vector<double> bench(3, 0);
73  if (test("t", t, bench) == false)
74  return err;
75  }
76  {
77  vpTranslationVector t1(1, 2, 3);
78  std::vector<double> bench(3);
79  bench[0] = 1;
80  bench[1] = 2;
81  bench[2] = 3;
82  if (test("t1", t1, bench) == false)
83  return err;
84 
85  vpTranslationVector t2(4, 5, 6);
86  bench[0] = 4;
87  bench[1] = 5;
88  bench[2] = 6;
89  if (test("t2", t2, bench) == false)
90  return err;
91 
92  vpTranslationVector t3 = t1 + t2;
93  bench[0] = 5;
94  bench[1] = 7;
95  bench[2] = 9;
96  if (test("t3", t3, bench) == false)
97  return err;
98 
99  vpMatrix skew = t3.skew();
100  std::vector<double> bench1(9, 0);
101  bench1[1] = -9;
102  bench1[2] = 7;
103  bench1[3] = 9;
104  bench1[5] = -5;
105  bench1[6] = -7;
106  bench1[7] = 5;
107  if (test("skew", skew, bench1) == false)
108  return err;
109 
111  t4.set(-1, -2, -3);
112  bench[0] = -1;
113  bench[1] = -2;
114  bench[2] = -3;
115  if (test("t4", t4, bench) == false)
116  return err;
117 
118  vpTranslationVector t5 = t4 * 2;
119  bench[0] = -2;
120  bench[1] = -4;
121  bench[2] = -6;
122  if (test("t5", t5, bench) == false)
123  return err;
124 
126  bench[0] = 0;
127  bench[1] = 0;
128  bench[2] = 0;
129  if (test("t6", t6, bench) == false)
130  return err;
131  }
132  std::cout << "All tests succeed" << std::endl;
133  return EXIT_SUCCESS;
134 }
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 a matrix and operations on matrices.
Definition: vpMatrix.h:169
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)