Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
catchPoseVector.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#if defined(VISP_HAVE_CATCH2)
42#include <limits>
43#include <vector>
44
45#include <visp3/core/vpPoseVector.h>
46
47#include <catch_amalgamated.hpp>
48
49#ifdef ENABLE_VISP_NAMESPACE
50using namespace VISP_NAMESPACE_NAME;
51#endif
52
53namespace
54{
55void checkSize(const vpPoseVector &pose, const std::vector<double> &ref)
56{
57 REQUIRE(pose.size() == 6);
58 REQUIRE(pose.getRows() == 6);
59 REQUIRE(pose.getCols() == 1);
60 REQUIRE(pose.size() == ref.size());
61}
62
63void checkData(const vpPoseVector &pose, const std::vector<double> &ref)
64{
65 for (unsigned int i = 0; i < pose.size(); i++) {
66 REQUIRE(pose[i] == Catch::Approx(ref[i]).epsilon(std::numeric_limits<double>::epsilon()));
67 }
68}
69} // namespace
70
71TEST_CASE("vpPoseVector size", "[vpColVector]")
72{
73 vpPoseVector pose;
74 REQUIRE(pose.size() == 6);
75 REQUIRE(pose.getRows() == 6);
76 REQUIRE(pose.getCols() == 1);
77
78 for (unsigned int i = 0; i < pose.getRows(); i++) {
79 REQUIRE(pose[i] == Catch::Approx(0).epsilon(std::numeric_limits<double>::epsilon()));
80 }
81}
82
83TEST_CASE("vpPoseVector value assignment", "[vpColVector]")
84{
85 vpPoseVector pose;
86 std::vector<double> ref(6);
87 pose[0] = ref[0] = 0.1;
88 pose[1] = ref[1] = 0.2;
89 pose[2] = ref[2] = 0.3;
90 pose[3] = ref[3] = vpMath::rad(10);
91 pose[4] = ref[4] = vpMath::rad(20);
92 pose[5] = ref[5] = vpMath::rad(30);
93
94 checkSize(pose, ref);
95 checkData(pose, ref);
96}
97
98TEST_CASE("vpPoseVector constructor", "[vpColVector]")
99{
100 std::vector<double> ref(6);
101 ref[0] = 0.1;
102 ref[1] = 0.2;
103 ref[2] = 0.3;
104 ref[3] = vpMath::rad(10);
105 ref[4] = vpMath::rad(20);
106 ref[5] = vpMath::rad(30);
107
108 vpPoseVector pose(ref[0], ref[1], ref[2], ref[3], ref[4], ref[5]);
109
110 checkSize(pose, ref);
111 checkData(pose, ref);
112}
113
114TEST_CASE("vpPoseVector copy constructor", "[vpColVector]")
115{
116 std::vector<double> ref = { 0.1, 0.2, 0.3, vpMath::rad(10), vpMath::rad(20), vpMath::rad(30) };
117
118 vpPoseVector pose1(ref[0], ref[1], ref[2], ref[3], ref[4], ref[5]);
119 vpPoseVector pose2(pose1);
120
121 checkSize(pose2, ref);
122 checkData(pose2, ref);
123}
124
125TEST_CASE("vpPoseVector object assignment", "[vpColVector]")
126{
127 std::vector<double> ref = { 0.1, 0.2, 0.3, vpMath::rad(10), vpMath::rad(20), vpMath::rad(30) };
128
129 vpPoseVector pose1(ref[0], ref[1], ref[2], ref[3], ref[4], ref[5]);
130 vpPoseVector pose2 = pose1;
131
132 checkSize(pose2, ref);
133 checkData(pose2, ref);
134}
135
136TEST_CASE("vpPoseVector set", "[vpColVector]")
137{
138 std::vector<double> ref = { 0.1, 0.2, 0.3, vpMath::rad(10), vpMath::rad(20), vpMath::rad(30) };
139
140 vpPoseVector pose1(ref[0], ref[1], ref[2], ref[3], ref[4], ref[5]);
141 vpPoseVector pose2;
142 pose2.set(pose1[0], pose1[1], pose1[2], pose1[3], pose1[4], pose1[5]);
143
144 checkSize(pose2, ref);
145 checkData(pose2, ref);
146}
147
148TEST_CASE("vpPoseVector constructor t, tu", "[vpColVector]")
149{
150 std::vector<double> ref = { 0.1, 0.2, 0.3, vpMath::rad(10), vpMath::rad(20), vpMath::rad(30) };
151 vpTranslationVector t(ref[0], ref[1], ref[2]);
152 vpThetaUVector tu(ref[3], ref[4], ref[5]);
153
154 vpPoseVector pose(t, tu);
155
156 checkSize(pose, ref);
157 checkData(pose, ref);
158}
159
160TEST_CASE("vpPoseVector build t, tu", "[vpColVector]")
161{
162 std::vector<double> ref = { 0.1, 0.2, 0.3, vpMath::rad(10), vpMath::rad(20), vpMath::rad(30) };
163 vpTranslationVector t(ref[0], ref[1], ref[2]);
164 vpThetaUVector tu(ref[3], ref[4], ref[5]);
165
166 vpPoseVector pose;
167 pose.buildFrom(t, tu);
168
169 checkSize(pose, ref);
170 checkData(pose, ref);
171}
172
173TEST_CASE("vpPoseVector constructor vpHomogeneousMatrix", "[vpColVector]")
174{
175 std::vector<double> ref = { 0.1, 0.2, 0.3, vpMath::rad(10), vpMath::rad(20), vpMath::rad(30) };
176 vpTranslationVector t(ref[0], ref[1], ref[2]);
177 vpThetaUVector tu(ref[3], ref[4], ref[5]);
178 vpHomogeneousMatrix M(t, tu);
179
180 vpPoseVector pose(M);
181
182 checkSize(pose, ref);
183 checkData(pose, ref);
184}
185
186TEST_CASE("vpPoseVector build vpHomogeneousMatrix", "[vpColVector]")
187{
188 std::vector<double> ref = { 0.1, 0.2, 0.3, vpMath::rad(10), vpMath::rad(20), vpMath::rad(30) };
189 vpTranslationVector t(ref[0], ref[1], ref[2]);
190 vpThetaUVector tu(ref[3], ref[4], ref[5]);
191 vpHomogeneousMatrix M(t, tu);
192
193 vpPoseVector pose;
194 pose.buildFrom(M);
195
196 checkSize(pose, ref);
197 checkData(pose, ref);
198}
199
200TEST_CASE("vpPoseVector constructor t, R", "[vpColVector]")
201{
202 std::vector<double> ref = { 0.1, 0.2, 0.3, vpMath::rad(10), vpMath::rad(20), vpMath::rad(30) };
203 vpTranslationVector t(ref[0], ref[1], ref[2]);
204 vpThetaUVector tu(ref[3], ref[4], ref[5]);
206
207 vpPoseVector pose(t, R);
208
209 checkSize(pose, ref);
210 checkData(pose, ref);
211}
212
213TEST_CASE("vpPoseVector build t, R", "[vpColVector]")
214{
215 std::vector<double> ref = { 0.1, 0.2, 0.3, vpMath::rad(10), vpMath::rad(20), vpMath::rad(30) };
216 vpTranslationVector t(ref[0], ref[1], ref[2]);
217 vpThetaUVector tu(ref[3], ref[4], ref[5]);
219
220 vpPoseVector pose;
221 pose.buildFrom(t, R);
222
223 checkSize(pose, ref);
224 checkData(pose, ref);
225}
226
227int main(int argc, char *argv[])
228{
229 Catch::Session session;
230 session.applyCommandLine(argc, argv);
231 int numFailed = session.run();
232 return numFailed;
233}
234#else
235#include <iostream>
236
237int main() { return EXIT_SUCCESS; }
238#endif
unsigned int getCols() const
Definition vpArray2D.h:423
unsigned int size() const
Return the number of elements of the 2D array.
Definition vpArray2D.h:435
unsigned int getRows() const
Definition vpArray2D.h:433
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.
void set(double tx, double ty, double tz, double tux, double tuy, double tuz)
vpPoseVector & buildFrom(const double &tx, const double &ty, const double &tz, const double &tux, const double &tuy, const 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.