Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
catchGenericTrackerCAOParsing.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 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 MBT CAO parsing.
32 */
33
37
38#include <visp3/core/vpConfig.h>
39
40#if defined(VISP_HAVE_CATCH2) && (VISP_HAVE_DATASET_VERSION >= 0x030400)
41
42#include <visp3/core/vpIoTools.h>
43#include <visp3/mbt/vpMbGenericTracker.h>
44
45#include <catch_amalgamated.hpp>
46
47#ifdef ENABLE_VISP_NAMESPACE
48using namespace VISP_NAMESPACE_NAME;
49#endif
50
51VP_ATTRIBUTE_NO_DESTROY static std::string ipath = vpIoTools::getViSPImagesDataPath();
52
53TEST_CASE("vpMbGenericTracker load CAO model Linux line ending", "[vpMbGenericTracker CAO parsing]")
54{
55 const std::string cao_filename = vpIoTools::createFilePath(ipath, "mbt-cao/cylinder_cao_model_linux_line_ending.cao");
57 const bool verbose = true;
58 REQUIRE_NOTHROW(tracker.loadModel(cao_filename, verbose));
59
60 std::list<vpMbtDistanceCylinder *> cylinders;
61 tracker.getLcylinder(cylinders);
62 CHECK(cylinders.size() == 1);
63
64 std::list<vpMbtDistanceCircle *> circles;
65 tracker.getLcircle(circles);
66 CHECK(circles.size() == 1);
67}
68
69TEST_CASE("vpMbGenericTracker load CAO model Windows line ending", "[vpMbGenericTracker CAO parsing]")
70{
71 const std::string cao_filename =
72 vpIoTools::createFilePath(ipath, "mbt-cao/cylinder_cao_model_windows_line_ending.cao");
74 const bool verbose = true;
75 REQUIRE_NOTHROW(tracker.loadModel(cao_filename, verbose));
76
77 std::list<vpMbtDistanceCylinder *> cylinders;
78 tracker.getLcylinder(cylinders);
79 CHECK(cylinders.size() == 1);
80
81 std::list<vpMbtDistanceCircle *> circles;
82 tracker.getLcircle(circles);
83 CHECK(circles.size() == 1);
84}
85
86#if (VISP_HAVE_DATASET_VERSION >= 0x030700)
87static const double margin = 1e-9;
88
89static void printFacesInfo(vpMbHiddenFaces<vpMbtPolygon> &faces)
90{
91 std::cout << "Number of faces: " << faces.size() << std::endl;
92
93 for (unsigned int i = 0; i < faces.size(); i++) {
94 std::vector<vpMbtPolygon *> &poly = faces.getPolygon();
95 std::cout << "face " << i << " with index: " << poly[i]->getIndex()
96 << (poly[i]->getName().empty() ? "" : (" with name: " + poly[i]->getName()))
97 << " is " << (poly[i]->isVisible() ? "visible" : "not visible")
98 << " and has " << poly[i]->getNbPoint() << " points"
99 << " and LOD is " << (poly[i]->useLod ? "enabled" : "disabled") << std::endl;
100
101 for (unsigned int j = 0; j < poly[i]->getNbPoint(); j++) {
102 vpPoint P = poly[i]->getPoint(j);
103 std::cout << " P obj " << j << ": " << P.get_oX() << " " << P.get_oY() << " " << P.get_oZ() << std::endl;
104 }
105 }
106}
107
108TEST_CASE("vpMbGenericTracker load CAO model [lines]", "[vpMbGenericTracker CAO parsing]")
109{
110 const std::string cao_filename =
111 vpIoTools::createFilePath(ipath, "mbt-cao/line_model.cao");
113 const bool verbose = true;
114 REQUIRE_NOTHROW(tracker.loadModel(cao_filename, verbose));
115
116 std::list<vpMbtDistanceLine *> lines;
117 tracker.getLline(lines);
118 REQUIRE(lines.size() == 2);
119
120 int idx = 0;
121 std::vector<std::string> line_names = { "line_0", "line_1" };
122 for (auto line : lines) {
123 CHECK_THAT(line->p1->get_oX(), Catch::Matchers::WithinAbs(idx*3 + 0, margin));
124 CHECK_THAT(line->p1->get_oY(), Catch::Matchers::WithinAbs(idx*3 + 1, margin));
125 CHECK_THAT(line->p1->get_oZ(), Catch::Matchers::WithinAbs(idx*3 + 2, margin));
126 CHECK(line->getName() == line_names[idx]);
127 ++idx;
128 }
129}
130
131TEST_CASE("vpMbGenericTracker load CAO model [face from lines]", "[vpMbGenericTracker CAO parsing]")
132{
133 const std::string cao_filename =
134 vpIoTools::createFilePath(ipath, "mbt-cao/face_from_lines_model.cao");
136 const bool verbose = true;
137 REQUIRE_NOTHROW(tracker.loadModel(cao_filename, verbose));
138
139 std::list<vpMbtDistanceLine *> lines;
140 tracker.getLline(lines);
141 CHECK(lines.size() == 3);
142
143 vpMbHiddenFaces<vpMbtPolygon> &faces = tracker.getFaces();
144 CHECK(faces.size() == 1);
145
146 for (unsigned int i = 0; i < faces.size(); i++) {
147 const std::vector<vpMbtPolygon *> &poly = faces.getPolygon();
148 CHECK(poly[i]->getNbPoint() == 4);
149 CHECK(poly[i]->getName() == "face_from_3D_lines");
150
151 for (unsigned int j = 0; j < poly[i]->getNbPoint(); j++) {
152 vpPoint P = poly[i]->getPoint(j);
153 if (j == 3) {
154 CHECK_THAT(P.get_oX(), Catch::Matchers::WithinAbs(0, margin));
155 CHECK_THAT(P.get_oY(), Catch::Matchers::WithinAbs(1, margin));
156 CHECK_THAT(P.get_oZ(), Catch::Matchers::WithinAbs(2, margin));
157 }
158 else {
159 CHECK_THAT(P.get_oX(), Catch::Matchers::WithinAbs(j*3 + 0, margin));
160 CHECK_THAT(P.get_oY(), Catch::Matchers::WithinAbs(j*3 + 1, margin));
161 CHECK_THAT(P.get_oZ(), Catch::Matchers::WithinAbs(j*3 + 2, margin));
162 }
163 }
164 }
165}
166
167TEST_CASE("vpMbGenericTracker load CAO model [face from points]", "[vpMbGenericTracker CAO parsing]")
168{
169 const std::string cao_filename =
170 vpIoTools::createFilePath(ipath, "mbt-cao/face_from_points_model.cao");
172 const bool verbose = true;
173 REQUIRE_NOTHROW(tracker.loadModel(cao_filename, verbose));
174
175 std::list<vpMbtDistanceLine *> lines;
176 tracker.getLline(lines);
177 CHECK(lines.size() == 3);
178
179 vpMbHiddenFaces<vpMbtPolygon> &faces = tracker.getFaces();
180 CHECK(faces.size() == 1);
181
182 for (unsigned int i = 0; i < faces.size(); i++) {
183 const std::vector<vpMbtPolygon *> &poly = faces.getPolygon();
184 CHECK(poly[i]->getNbPoint() == 3);
185 CHECK(poly[i]->getName() == "face_from_3D_points");
186
187 for (unsigned int j = 0; j < poly[i]->getNbPoint(); j++) {
188 vpPoint P = poly[i]->getPoint(j);
189 CHECK_THAT(P.get_oX(), Catch::Matchers::WithinAbs(j*3 + 0, margin));
190 CHECK_THAT(P.get_oY(), Catch::Matchers::WithinAbs(j*3 + 1, margin));
191 CHECK_THAT(P.get_oZ(), Catch::Matchers::WithinAbs(j*3 + 2, margin));
192 }
193 }
194}
195
196TEST_CASE("vpMbGenericTracker load CAO model [cylinder]", "[vpMbGenericTracker CAO parsing]")
197{
198 const std::string cao_filename =
199 vpIoTools::createFilePath(ipath, "mbt-cao/cylinder_model.cao");
201 const bool verbose = true;
202 REQUIRE_NOTHROW(tracker.loadModel(cao_filename, verbose));
203
204 std::list<vpMbtDistanceCylinder *> cylinders;
205 tracker.getLcylinder(cylinders);
206 CHECK(cylinders.size() == 1);
207
208 vpMbtDistanceCylinder *cylinder = cylinders.front();
209 CHECK(cylinder->getName() == "cylinder");
210 CHECK_THAT(cylinder->radius, Catch::Matchers::WithinAbs(0.5, margin));
211
212 CHECK_THAT(cylinder->p1->get_oX(), Catch::Matchers::WithinAbs(0, margin));
213 CHECK_THAT(cylinder->p1->get_oY(), Catch::Matchers::WithinAbs(1, margin));
214 CHECK_THAT(cylinder->p1->get_oZ(), Catch::Matchers::WithinAbs(2, margin));
215
216 CHECK_THAT(cylinder->p2->get_oX(), Catch::Matchers::WithinAbs(3, margin));
217 CHECK_THAT(cylinder->p2->get_oY(), Catch::Matchers::WithinAbs(4, margin));
218 CHECK_THAT(cylinder->p2->get_oZ(), Catch::Matchers::WithinAbs(5, margin));
219
220 vpMbHiddenFaces<vpMbtPolygon> &faces = tracker.getFaces();
221 CHECK(faces.size() == 5);
222 printFacesInfo(faces);
223}
224
225TEST_CASE("vpMbGenericTracker load CAO model [circle]", "[vpMbGenericTracker CAO parsing]")
226{
227 const std::string cao_filename =
228 vpIoTools::createFilePath(ipath, "mbt-cao/circle_model.cao");
230 const bool verbose = true;
231 REQUIRE_NOTHROW(tracker.loadModel(cao_filename, verbose));
232
233 std::list<vpMbtDistanceCircle *> circles;
234 tracker.getLcircle(circles);
235 CHECK(circles.size() == 1);
236
237 vpMbtDistanceCircle *circle = circles.front();
238 CHECK(circle->getName() == "circle");
239 CHECK_THAT(circle->radius, Catch::Matchers::WithinAbs(0.5, margin));
240
241 CHECK_THAT(circle->p1->get_oX(), Catch::Matchers::WithinAbs(0, margin));
242 CHECK_THAT(circle->p1->get_oY(), Catch::Matchers::WithinAbs(1, margin));
243 CHECK_THAT(circle->p1->get_oZ(), Catch::Matchers::WithinAbs(2, margin));
244
245 CHECK_THAT(circle->p2->get_oX(), Catch::Matchers::WithinAbs(3, margin));
246 CHECK_THAT(circle->p2->get_oY(), Catch::Matchers::WithinAbs(4, margin));
247 CHECK_THAT(circle->p2->get_oZ(), Catch::Matchers::WithinAbs(5, margin));
248
249 CHECK_THAT(circle->p3->get_oX(), Catch::Matchers::WithinAbs(6, margin));
250 CHECK_THAT(circle->p3->get_oY(), Catch::Matchers::WithinAbs(7, margin));
251 CHECK_THAT(circle->p3->get_oZ(), Catch::Matchers::WithinAbs(8, margin));
252
253 vpMbHiddenFaces<vpMbtPolygon> &faces = tracker.getFaces();
254 CHECK(faces.size() == 1);
255 printFacesInfo(faces);
256}
257
258TEST_CASE("vpMbGenericTracker load CAO model [hierarchical]", "[vpMbGenericTracker CAO parsing]")
259{
260 const std::string cao_filename =
261 vpIoTools::createFilePath(ipath, "mbt-cao/hierarchical_model.cao");
263 const bool verbose = true;
264 REQUIRE_NOTHROW(tracker.loadModel(cao_filename, verbose));
265
266 // Lines
267 {
268 std::list<vpMbtDistanceLine *> lines;
269 tracker.getLline(lines);
270 REQUIRE(lines.size() == 2);
271 std::vector<std::string> line_names = { "line_0", "line_1" };
272
273 int idx = 0;
274 for (auto line : lines) {
275 CHECK_THAT(line->p1->get_oX(), Catch::Matchers::WithinAbs(idx*3 + 0, margin));
276 CHECK_THAT(line->p1->get_oY(), Catch::Matchers::WithinAbs(idx*3 + 1, margin));
277 CHECK_THAT(line->p1->get_oZ(), Catch::Matchers::WithinAbs(idx*3 + 2, margin));
278 CHECK(line->getName() == line_names[idx]);
279 ++idx;
280 }
281 }
282
283 // Face from points
284 {
285 vpMbHiddenFaces<vpMbtPolygon> &faces = tracker.getFaces();
286 // vpMbtDistanceLine --> 2 faces
287 // vpMbtDistanceCylinder --> 1 + 4 faces
288 // vpMbtDistanceCircle --> 1 face
289 CHECK(faces.size() == 8);
290 printFacesInfo(faces);
291 }
292
293 // Cylinder
294 {
295 std::list<vpMbtDistanceCylinder *> cylinders;
296 tracker.getLcylinder(cylinders);
297 CHECK(cylinders.size() == 1);
298
299 vpMbtDistanceCylinder *cylinder = cylinders.front();
300 CHECK(cylinder->getName() == "cylinder");
301 CHECK_THAT(cylinder->radius, Catch::Matchers::WithinAbs(0.5, margin));
302
303 CHECK_THAT(cylinder->p1->get_oX(), Catch::Matchers::WithinAbs(0, margin));
304 CHECK_THAT(cylinder->p1->get_oY(), Catch::Matchers::WithinAbs(1, margin));
305 CHECK_THAT(cylinder->p1->get_oZ(), Catch::Matchers::WithinAbs(2, margin));
306
307 CHECK_THAT(cylinder->p2->get_oX(), Catch::Matchers::WithinAbs(3, margin));
308 CHECK_THAT(cylinder->p2->get_oY(), Catch::Matchers::WithinAbs(4, margin));
309 CHECK_THAT(cylinder->p2->get_oZ(), Catch::Matchers::WithinAbs(5, margin));
310 }
311
312 // Circle
313 {
314 std::list<vpMbtDistanceCircle *> circles;
315 tracker.getLcircle(circles);
316 CHECK(circles.size() == 1);
317
318 vpMbtDistanceCircle *circle = circles.front();
319 CHECK(circle->getName() == "circle");
320 CHECK_THAT(circle->radius, Catch::Matchers::WithinAbs(0.5, margin));
321
322 CHECK_THAT(circle->p1->get_oX(), Catch::Matchers::WithinAbs(0, margin));
323 CHECK_THAT(circle->p1->get_oY(), Catch::Matchers::WithinAbs(1, margin));
324 CHECK_THAT(circle->p1->get_oZ(), Catch::Matchers::WithinAbs(2, margin));
325
326 CHECK_THAT(circle->p2->get_oX(), Catch::Matchers::WithinAbs(3, margin));
327 CHECK_THAT(circle->p2->get_oY(), Catch::Matchers::WithinAbs(4, margin));
328 CHECK_THAT(circle->p2->get_oZ(), Catch::Matchers::WithinAbs(5, margin));
329
330 CHECK_THAT(circle->p3->get_oX(), Catch::Matchers::WithinAbs(6, margin));
331 CHECK_THAT(circle->p3->get_oY(), Catch::Matchers::WithinAbs(7, margin));
332 CHECK_THAT(circle->p3->get_oZ(), Catch::Matchers::WithinAbs(8, margin));
333 }
334}
335
336#endif
337
338int main(int argc, char *argv[])
339{
340 Catch::Session session;
341 session.applyCommandLine(argc, argv);
342 int numFailed = session.run();
343 return numFailed;
344}
345
346#else
347#include <iostream>
348
349int main() { return EXIT_SUCCESS; }
350#endif
static std::string getViSPImagesDataPath()
static std::string createFilePath(const std::string &parent, const std::string &child)
Real-time 6D object pose tracking using its CAD model.
Implementation of the polygons management for the model-based trackers.
unsigned int size() const
std::vector< PolygonType * > & getPolygon()
Manage a circle used in the model-based tracker.
vpPoint * p1
The center of the circle.
std::string getName() const
vpPoint * p2
A point on the plane containing the circle.
double radius
The radius of the circle.
vpPoint * p3
An other point on the plane containing the circle.
Manage a cylinder used in the model-based tracker.
vpPoint * p2
The second extremity on the axe.
double radius
The radius of the cylinder.
std::string getName() const
vpPoint * p1
The first extremity on the axe.
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition vpPoint.h:79
double get_oX() const
Get the point oX coordinate in the object frame.
Definition vpPoint.cpp:418
double get_oZ() const
Get the point oZ coordinate in the object frame.
Definition vpPoint.cpp:422
double get_oY() const
Get the point oY coordinate in the object frame.
Definition vpPoint.cpp:420