38#include <visp3/core/vpConfig.h>
40#if defined(VISP_HAVE_CATCH2) && (VISP_HAVE_DATASET_VERSION >= 0x030400)
42#include <visp3/core/vpIoTools.h>
43#include <visp3/mbt/vpMbGenericTracker.h>
45#include <catch_amalgamated.hpp>
47#ifdef ENABLE_VISP_NAMESPACE
53TEST_CASE(
"vpMbGenericTracker load CAO model Linux line ending",
"[vpMbGenericTracker CAO parsing]")
57 const bool verbose =
true;
58 REQUIRE_NOTHROW(
tracker.loadModel(cao_filename, verbose));
60 std::list<vpMbtDistanceCylinder *> cylinders;
61 tracker.getLcylinder(cylinders);
62 CHECK(cylinders.size() == 1);
64 std::list<vpMbtDistanceCircle *> circles;
66 CHECK(circles.size() == 1);
69TEST_CASE(
"vpMbGenericTracker load CAO model Windows line ending",
"[vpMbGenericTracker CAO parsing]")
71 const std::string cao_filename =
74 const bool verbose =
true;
75 REQUIRE_NOTHROW(
tracker.loadModel(cao_filename, verbose));
77 std::list<vpMbtDistanceCylinder *> cylinders;
78 tracker.getLcylinder(cylinders);
79 CHECK(cylinders.size() == 1);
81 std::list<vpMbtDistanceCircle *> circles;
83 CHECK(circles.size() == 1);
86#if (VISP_HAVE_DATASET_VERSION >= 0x030700)
87static const double margin = 1
e-9;
91 std::cout <<
"Number of faces: " << faces.
size() << std::endl;
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;
101 for (
unsigned int j = 0;
j < poly[
i]->getNbPoint();
j++) {
103 std::cout <<
" P obj " <<
j <<
": " << P.
get_oX() <<
" " << P.
get_oY() <<
" " << P.
get_oZ() << std::endl;
108TEST_CASE(
"vpMbGenericTracker load CAO model [lines]",
"[vpMbGenericTracker CAO parsing]")
110 const std::string cao_filename =
113 const bool verbose =
true;
114 REQUIRE_NOTHROW(
tracker.loadModel(cao_filename, verbose));
116 std::list<vpMbtDistanceLine *> lines;
118 REQUIRE(lines.size() == 2);
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]);
131TEST_CASE(
"vpMbGenericTracker load CAO model [face from lines]",
"[vpMbGenericTracker CAO parsing]")
133 const std::string cao_filename =
136 const bool verbose =
true;
137 REQUIRE_NOTHROW(
tracker.loadModel(cao_filename, verbose));
139 std::list<vpMbtDistanceLine *> lines;
141 CHECK(lines.size() == 3);
144 CHECK(faces.
size() == 1);
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");
151 for (
unsigned int j = 0;
j < poly[
i]->getNbPoint();
j++) {
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));
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));
167TEST_CASE(
"vpMbGenericTracker load CAO model [face from points]",
"[vpMbGenericTracker CAO parsing]")
169 const std::string cao_filename =
172 const bool verbose =
true;
173 REQUIRE_NOTHROW(
tracker.loadModel(cao_filename, verbose));
175 std::list<vpMbtDistanceLine *> lines;
177 CHECK(lines.size() == 3);
180 CHECK(faces.
size() == 1);
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");
187 for (
unsigned int j = 0;
j < poly[
i]->getNbPoint();
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));
196TEST_CASE(
"vpMbGenericTracker load CAO model [cylinder]",
"[vpMbGenericTracker CAO parsing]")
198 const std::string cao_filename =
201 const bool verbose =
true;
202 REQUIRE_NOTHROW(
tracker.loadModel(cao_filename, verbose));
204 std::list<vpMbtDistanceCylinder *> cylinders;
205 tracker.getLcylinder(cylinders);
206 CHECK(cylinders.size() == 1);
209 CHECK(cylinder->
getName() ==
"cylinder");
210 CHECK_THAT(cylinder->
radius, Catch::Matchers::WithinAbs(0.5, margin));
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));
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));
221 CHECK(faces.
size() == 5);
222 printFacesInfo(faces);
225TEST_CASE(
"vpMbGenericTracker load CAO model [circle]",
"[vpMbGenericTracker CAO parsing]")
227 const std::string cao_filename =
230 const bool verbose =
true;
231 REQUIRE_NOTHROW(
tracker.loadModel(cao_filename, verbose));
233 std::list<vpMbtDistanceCircle *> circles;
235 CHECK(circles.size() == 1);
238 CHECK(circle->
getName() ==
"circle");
239 CHECK_THAT(circle->
radius, Catch::Matchers::WithinAbs(0.5, margin));
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));
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));
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));
254 CHECK(faces.
size() == 1);
255 printFacesInfo(faces);
258TEST_CASE(
"vpMbGenericTracker load CAO model [hierarchical]",
"[vpMbGenericTracker CAO parsing]")
260 const std::string cao_filename =
263 const bool verbose =
true;
264 REQUIRE_NOTHROW(
tracker.loadModel(cao_filename, verbose));
268 std::list<vpMbtDistanceLine *> lines;
270 REQUIRE(lines.size() == 2);
271 std::vector<std::string> line_names = {
"line_0",
"line_1" };
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]);
289 CHECK(faces.
size() == 8);
290 printFacesInfo(faces);
295 std::list<vpMbtDistanceCylinder *> cylinders;
296 tracker.getLcylinder(cylinders);
297 CHECK(cylinders.size() == 1);
300 CHECK(cylinder->
getName() ==
"cylinder");
301 CHECK_THAT(cylinder->
radius, Catch::Matchers::WithinAbs(0.5, margin));
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));
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));
314 std::list<vpMbtDistanceCircle *> circles;
316 CHECK(circles.size() == 1);
319 CHECK(circle->
getName() ==
"circle");
320 CHECK_THAT(circle->
radius, Catch::Matchers::WithinAbs(0.5, margin));
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));
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));
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));
338int main(
int argc,
char *argv[])
340 Catch::Session session;
341 session.applyCommandLine(argc, argv);
342 int numFailed = session.run();
349int main() {
return EXIT_SUCCESS; }
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 ...
double get_oX() const
Get the point oX coordinate in the object frame.
double get_oZ() const
Get the point oZ coordinate in the object frame.
double get_oY() const
Get the point oY coordinate in the object frame.