Visual Servoing Platform  version 3.6.1 under development (2024-10-02)
testPoseVector.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 
39 #include <visp3/core/vpConfig.h>
40 
41 #ifdef VISP_HAVE_CATCH2
42 #include <limits>
43 #include <vector>
44 
45 #include <visp3/core/vpPoseVector.h>
46 
47 #define CATCH_CONFIG_RUNNER
48 #include <catch.hpp>
49 
50 #ifdef ENABLE_VISP_NAMESPACE
51 using namespace VISP_NAMESPACE_NAME;
52 #endif
53 
54 namespace
55 {
56 void checkSize(const vpPoseVector &pose, const std::vector<double> &ref)
57 {
58  REQUIRE(pose.size() == 6);
59  REQUIRE(pose.getRows() == 6);
60  REQUIRE(pose.getCols() == 1);
61  REQUIRE(pose.size() == ref.size());
62 }
63 
64 void checkData(const vpPoseVector &pose, const std::vector<double> &ref)
65 {
66  for (unsigned int i = 0; i < pose.size(); i++) {
67  REQUIRE(pose[i] == Approx(ref[i]).epsilon(std::numeric_limits<double>::epsilon()));
68  }
69 }
70 } // namespace
71 
72 TEST_CASE("vpPoseVector size", "[vpColVector]")
73 {
74  vpPoseVector pose;
75  REQUIRE(pose.size() == 6);
76  REQUIRE(pose.getRows() == 6);
77  REQUIRE(pose.getCols() == 1);
78 
79  for (unsigned int i = 0; i < pose.getRows(); i++) {
80  REQUIRE(pose[i] == Approx(0).epsilon(std::numeric_limits<double>::epsilon()));
81  }
82 }
83 
84 TEST_CASE("vpPoseVector value assignment", "[vpColVector]")
85 {
86  vpPoseVector pose;
87  std::vector<double> ref(6);
88  pose[0] = ref[0] = 0.1;
89  pose[1] = ref[1] = 0.2;
90  pose[2] = ref[2] = 0.3;
91  pose[3] = ref[3] = vpMath::rad(10);
92  pose[4] = ref[4] = vpMath::rad(20);
93  pose[5] = ref[5] = vpMath::rad(30);
94 
95  checkSize(pose, ref);
96  checkData(pose, ref);
97 }
98 
99 TEST_CASE("vpPoseVector constructor", "[vpColVector]")
100 {
101  std::vector<double> ref(6);
102  ref[0] = 0.1;
103  ref[1] = 0.2;
104  ref[2] = 0.3;
105  ref[3] = vpMath::rad(10);
106  ref[4] = vpMath::rad(20);
107  ref[5] = vpMath::rad(30);
108 
109  vpPoseVector pose(ref[0], ref[1], ref[2], ref[3], ref[4], ref[5]);
110 
111  checkSize(pose, ref);
112  checkData(pose, ref);
113 }
114 
115 TEST_CASE("vpPoseVector copy constructor", "[vpColVector]")
116 {
117  std::vector<double> ref = { 0.1, 0.2, 0.3, vpMath::rad(10), vpMath::rad(20), vpMath::rad(30) };
118 
119  vpPoseVector pose1(ref[0], ref[1], ref[2], ref[3], ref[4], ref[5]);
120  vpPoseVector pose2(pose1);
121 
122  checkSize(pose2, ref);
123  checkData(pose2, ref);
124 }
125 
126 TEST_CASE("vpPoseVector object assignment", "[vpColVector]")
127 {
128  std::vector<double> ref = { 0.1, 0.2, 0.3, vpMath::rad(10), vpMath::rad(20), vpMath::rad(30) };
129 
130  vpPoseVector pose1(ref[0], ref[1], ref[2], ref[3], ref[4], ref[5]);
131  vpPoseVector pose2 = pose1;
132 
133  checkSize(pose2, ref);
134  checkData(pose2, ref);
135 }
136 
137 TEST_CASE("vpPoseVector set", "[vpColVector]")
138 {
139  std::vector<double> ref = { 0.1, 0.2, 0.3, vpMath::rad(10), vpMath::rad(20), vpMath::rad(30) };
140 
141  vpPoseVector pose1(ref[0], ref[1], ref[2], ref[3], ref[4], ref[5]);
142  vpPoseVector pose2;
143  pose2.set(pose1[0], pose1[1], pose1[2], pose1[3], pose1[4], pose1[5]);
144 
145  checkSize(pose2, ref);
146  checkData(pose2, ref);
147 }
148 
149 TEST_CASE("vpPoseVector constructor t, tu", "[vpColVector]")
150 {
151  std::vector<double> ref = { 0.1, 0.2, 0.3, vpMath::rad(10), vpMath::rad(20), vpMath::rad(30) };
152  vpTranslationVector t(ref[0], ref[1], ref[2]);
153  vpThetaUVector tu(ref[3], ref[4], ref[5]);
154 
155  vpPoseVector pose(t, tu);
156 
157  checkSize(pose, ref);
158  checkData(pose, ref);
159 }
160 
161 TEST_CASE("vpPoseVector build t, tu", "[vpColVector]")
162 {
163  std::vector<double> ref = { 0.1, 0.2, 0.3, vpMath::rad(10), vpMath::rad(20), vpMath::rad(30) };
164  vpTranslationVector t(ref[0], ref[1], ref[2]);
165  vpThetaUVector tu(ref[3], ref[4], ref[5]);
166 
167  vpPoseVector pose;
168  pose.build(t, tu);
169 
170  checkSize(pose, ref);
171  checkData(pose, ref);
172 }
173 
174 TEST_CASE("vpPoseVector constructor vpHomogeneousMatrix", "[vpColVector]")
175 {
176  std::vector<double> ref = { 0.1, 0.2, 0.3, vpMath::rad(10), vpMath::rad(20), vpMath::rad(30) };
177  vpTranslationVector t(ref[0], ref[1], ref[2]);
178  vpThetaUVector tu(ref[3], ref[4], ref[5]);
179  vpHomogeneousMatrix M(t, tu);
180 
181  vpPoseVector pose(M);
182 
183  checkSize(pose, ref);
184  checkData(pose, ref);
185 }
186 
187 TEST_CASE("vpPoseVector build vpHomogeneousMatrix", "[vpColVector]")
188 {
189  std::vector<double> ref = { 0.1, 0.2, 0.3, vpMath::rad(10), vpMath::rad(20), vpMath::rad(30) };
190  vpTranslationVector t(ref[0], ref[1], ref[2]);
191  vpThetaUVector tu(ref[3], ref[4], ref[5]);
192  vpHomogeneousMatrix M(t, tu);
193 
194  vpPoseVector pose;
195  pose.build(M);
196 
197  checkSize(pose, ref);
198  checkData(pose, ref);
199 }
200 
201 TEST_CASE("vpPoseVector constructor t, R", "[vpColVector]")
202 {
203  std::vector<double> ref = { 0.1, 0.2, 0.3, vpMath::rad(10), vpMath::rad(20), vpMath::rad(30) };
204  vpTranslationVector t(ref[0], ref[1], ref[2]);
205  vpThetaUVector tu(ref[3], ref[4], ref[5]);
206  vpRotationMatrix R(tu);
207 
208  vpPoseVector pose(t, R);
209 
210  checkSize(pose, ref);
211  checkData(pose, ref);
212 }
213 
214 TEST_CASE("vpPoseVector build t, R", "[vpColVector]")
215 {
216  std::vector<double> ref = { 0.1, 0.2, 0.3, vpMath::rad(10), vpMath::rad(20), vpMath::rad(30) };
217  vpTranslationVector t(ref[0], ref[1], ref[2]);
218  vpThetaUVector tu(ref[3], ref[4], ref[5]);
219  vpRotationMatrix R(tu);
220 
221  vpPoseVector pose;
222  pose.build(t, R);
223 
224  checkSize(pose, ref);
225  checkData(pose, ref);
226 }
227 
228 int main(int argc, char *argv[])
229 {
230  Catch::Session session; // There must be exactly one instance
231 
232  // Let Catch (using Clara) parse the command line
233  session.applyCommandLine(argc, argv);
234 
235  int numFailed = session.run();
236 
237  // numFailed is clamped to 255 as some unices only use the lower 8 bits.
238  // This clamping has already been applied, so just return it here
239  // You can also do any post run clean-up here
240  return numFailed;
241 }
242 #else
243 #include <iostream>
244 
245 int main() { return EXIT_SUCCESS; }
246 #endif
unsigned int getCols() const
Definition: vpArray2D.h:337
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 an homogeneous matrix and operations on such kind of matrices.
static double rad(double deg)
Definition: vpMath.h:129
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:203
vpPoseVector & build(const double &tx, const double &ty, const double &tz, const double &tux, const double &tuy, const double &tuz)
void set(double tx, double ty, double tz, double tux, double tuy, double tuz)
Implementation of a rotation matrix and operations on such kind of matrices.
Implementation of a rotation vector as axis-angle minimal representation.
Class that consider the case of a translation vector.