Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testTranslationVector.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  * Test some vpColVector functionalities.
32  *
33  * Authors:
34  * Eric Marchand
35  *
36  *****************************************************************************/
37 
44 #include <cmath>
45 #include <vector>
46 #include <limits>
47 
48 #include <visp3/core/vpTranslationVector.h>
49 
50 bool test(const std::string &s, const vpArray2D<double> &A, const std::vector<double> &bench)
51 {
52  static unsigned int cpt = 0;
53  std::cout << "** Test " << ++cpt << std::endl;
54  std::cout << s << "(" << A.getRows() << "," << A.getCols() << ") =" << A << std::endl;
55  if(bench.size() != A.size()) {
56  std::cout << "Test fails: bad size wrt bench" << std::endl;
57  return false;
58  }
59  for (unsigned int i=0; i<A.size(); i++) {
60  if (std::fabs(A.data[i]-bench[i]) > std::fabs(A.data[i])*std::numeric_limits<double>::epsilon()) {
61  std::cout << "Test fails: bad content" << std::endl;
62  return false;
63  }
64  }
65 
66  return true;
67 }
68 int main()
69 {
70  int err = 1;
71  {
73  std::vector<double> bench(3,0);
74  if (test("t", t, bench) == false)
75  return err;
76  }
77  {
78  vpTranslationVector t1(1, 2, 3);
79  std::vector<double> bench(3);
80  bench[0] = 1;
81  bench[1] = 2;
82  bench[2] = 3;
83  if (test("t1", t1, bench) == false)
84  return err;
85 
86  vpTranslationVector t2(4, 5, 6);
87  bench[0] = 4;
88  bench[1] = 5;
89  bench[2] = 6;
90  if (test("t2", t2, bench) == false)
91  return err;
92 
93  vpTranslationVector t3 = t1 + t2;
94  bench[0] = 5;
95  bench[1] = 7;
96  bench[2] = 9;
97  if (test("t3", t3, bench) == false)
98  return err;
99 
100  vpMatrix skew = t3.skew();
101  std::vector<double> bench1(9, 0);
102  bench1[1] = -9;
103  bench1[2] = 7;
104  bench1[3] = 9;
105  bench1[5] = -5;
106  bench1[6] = -7;
107  bench1[7] = 5;
108  if (test("skew", skew, bench1) == false)
109  return err;
110 
112  t4.set(-1, -2, -3);
113  bench[0] = -1;
114  bench[1] = -2;
115  bench[2] = -3;
116  if (test("t4", t4, bench) == false)
117  return err;
118 
119  vpTranslationVector t5 = t4 * 2;
120  bench[0] = -2;
121  bench[1] = -4;
122  bench[2] = -6;
123  if (test("t5", t5, bench) == false)
124  return err;
125 
127  bench[0] = 0;
128  bench[1] = 0;
129  bench[2] = 0;
130  if (test("t6", t6, bench) == false)
131  return err;
132  }
133  std::cout << "All tests succeed" << std::endl;
134  return 0;
135 }
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:97
static vpTranslationVector cross(const vpTranslationVector &a, const vpTranslationVector &b)
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
unsigned int getRows() const
Return the number of rows of the 2D array.
Definition: vpArray2D.h:152
void set(const double tx, const double ty, const double tz)
Class that consider the case of a translation vector.