#include <visp3/core/vpConfig.h>
#if defined(VISP_HAVE_CATCH2) && (VISP_HAVE_DATASET_VERSION >= 0x030400)
#include <visp3/core/vpIoTools.h>
#include <visp3/mbt/vpMbGenericTracker.h>
#include <catch_amalgamated.hpp>
#ifdef ENABLE_VISP_NAMESPACE
#endif
TEST_CASE("vpMbGenericTracker load CAO model Linux line ending", "[vpMbGenericTracker CAO parsing]")
{
const bool verbose = true;
REQUIRE_NOTHROW(tracker.
loadModel(cao_filename, verbose));
std::list<vpMbtDistanceCylinder *> cylinders;
CHECK(cylinders.size() == 1);
std::list<vpMbtDistanceCircle *> circles;
CHECK(circles.size() == 1);
}
TEST_CASE("vpMbGenericTracker load CAO model Windows line ending", "[vpMbGenericTracker CAO parsing]")
{
const std::string cao_filename =
const bool verbose = true;
REQUIRE_NOTHROW(tracker.
loadModel(cao_filename, verbose));
std::list<vpMbtDistanceCylinder *> cylinders;
CHECK(cylinders.size() == 1);
std::list<vpMbtDistanceCircle *> circles;
CHECK(circles.size() == 1);
}
#if (VISP_HAVE_DATASET_VERSION >= 0x030700)
static const double margin = 1e-9;
{
std::cout <<
"Number of faces: " << faces.
size() << std::endl;
for (
unsigned int i = 0; i < faces.
size(); i++) {
std::vector<vpMbtPolygon *> &poly = faces.
getPolygon();
std::cout << "face " << i << " with index: " << poly[i]->getIndex()
<< (poly[i]->getName().empty() ? "" : (" with name: " + poly[i]->getName()))
<< " is " << (poly[i]->isVisible() ? "visible" : "not visible")
<< " and has " << poly[i]->getNbPoint() << " points"
<< " and LOD is " << (poly[i]->useLod ? "enabled" : "disabled") << std::endl;
for (unsigned int j = 0; j < poly[i]->getNbPoint(); j++) {
std::cout <<
" P obj " << j <<
": " << P.
get_oX() <<
" " << P.
get_oY() <<
" " << P.
get_oZ() << std::endl;
}
}
}
TEST_CASE("vpMbGenericTracker load CAO model [lines]", "[vpMbGenericTracker CAO parsing]")
{
const std::string cao_filename =
const bool verbose = true;
REQUIRE_NOTHROW(tracker.
loadModel(cao_filename, verbose));
std::list<vpMbtDistanceLine *> lines;
REQUIRE(lines.size() == 2);
int idx = 0;
std::vector<std::string> line_names = { "line_0", "line_1" };
for (auto line : lines) {
CHECK_THAT(line->p1->get_oX(), Catch::Matchers::WithinAbs(idx*3 + 0, margin));
CHECK_THAT(line->p1->get_oY(), Catch::Matchers::WithinAbs(idx*3 + 1, margin));
CHECK_THAT(line->p1->get_oZ(), Catch::Matchers::WithinAbs(idx*3 + 2, margin));
CHECK(line->getName() == line_names[idx]);
++idx;
}
}
TEST_CASE("vpMbGenericTracker load CAO model [face from lines]", "[vpMbGenericTracker CAO parsing]")
{
const std::string cao_filename =
const bool verbose = true;
REQUIRE_NOTHROW(tracker.
loadModel(cao_filename, verbose));
std::list<vpMbtDistanceLine *> lines;
CHECK(lines.size() == 3);
CHECK(faces.
size() == 1);
for (
unsigned int i = 0; i < faces.
size(); i++) {
const std::vector<vpMbtPolygon *> &poly = faces.
getPolygon();
CHECK(poly[i]->getNbPoint() == 4);
CHECK(poly[i]->getName() == "face_from_3D_lines");
for (unsigned int j = 0; j < poly[i]->getNbPoint(); j++) {
if (j == 3) {
CHECK_THAT(P.
get_oX(), Catch::Matchers::WithinAbs(0, margin));
CHECK_THAT(P.
get_oY(), Catch::Matchers::WithinAbs(1, margin));
CHECK_THAT(P.
get_oZ(), Catch::Matchers::WithinAbs(2, margin));
}
else {
CHECK_THAT(P.
get_oX(), Catch::Matchers::WithinAbs(j*3 + 0, margin));
CHECK_THAT(P.
get_oY(), Catch::Matchers::WithinAbs(j*3 + 1, margin));
CHECK_THAT(P.
get_oZ(), Catch::Matchers::WithinAbs(j*3 + 2, margin));
}
}
}
}
TEST_CASE("vpMbGenericTracker load CAO model [face from points]", "[vpMbGenericTracker CAO parsing]")
{
const std::string cao_filename =
const bool verbose = true;
REQUIRE_NOTHROW(tracker.
loadModel(cao_filename, verbose));
std::list<vpMbtDistanceLine *> lines;
CHECK(lines.size() == 3);
CHECK(faces.
size() == 1);
for (
unsigned int i = 0; i < faces.
size(); i++) {
const std::vector<vpMbtPolygon *> &poly = faces.
getPolygon();
CHECK(poly[i]->getNbPoint() == 3);
CHECK(poly[i]->getName() == "face_from_3D_points");
for (unsigned int j = 0; j < poly[i]->getNbPoint(); j++) {
CHECK_THAT(P.
get_oX(), Catch::Matchers::WithinAbs(j*3 + 0, margin));
CHECK_THAT(P.
get_oY(), Catch::Matchers::WithinAbs(j*3 + 1, margin));
CHECK_THAT(P.
get_oZ(), Catch::Matchers::WithinAbs(j*3 + 2, margin));
}
}
}
TEST_CASE("vpMbGenericTracker load CAO model [cylinder]", "[vpMbGenericTracker CAO parsing]")
{
const std::string cao_filename =
const bool verbose = true;
REQUIRE_NOTHROW(tracker.
loadModel(cao_filename, verbose));
std::list<vpMbtDistanceCylinder *> cylinders;
CHECK(cylinders.size() == 1);
CHECK(cylinder->
getName() ==
"cylinder");
CHECK_THAT(cylinder->
radius, Catch::Matchers::WithinAbs(0.5, margin));
CHECK_THAT(cylinder->
p1->
get_oX(), Catch::Matchers::WithinAbs(0, margin));
CHECK_THAT(cylinder->
p1->
get_oY(), Catch::Matchers::WithinAbs(1, margin));
CHECK_THAT(cylinder->
p1->
get_oZ(), Catch::Matchers::WithinAbs(2, margin));
CHECK_THAT(cylinder->
p2->
get_oX(), Catch::Matchers::WithinAbs(3, margin));
CHECK_THAT(cylinder->
p2->
get_oY(), Catch::Matchers::WithinAbs(4, margin));
CHECK_THAT(cylinder->
p2->
get_oZ(), Catch::Matchers::WithinAbs(5, margin));
CHECK(faces.
size() == 5);
printFacesInfo(faces);
}
TEST_CASE("vpMbGenericTracker load CAO model [circle]", "[vpMbGenericTracker CAO parsing]")
{
const std::string cao_filename =
const bool verbose = true;
REQUIRE_NOTHROW(tracker.
loadModel(cao_filename, verbose));
std::list<vpMbtDistanceCircle *> circles;
CHECK(circles.size() == 1);
CHECK(circle->
getName() ==
"circle");
CHECK_THAT(circle->
radius, Catch::Matchers::WithinAbs(0.5, margin));
CHECK_THAT(circle->
p1->
get_oX(), Catch::Matchers::WithinAbs(0, margin));
CHECK_THAT(circle->
p1->
get_oY(), Catch::Matchers::WithinAbs(1, margin));
CHECK_THAT(circle->
p1->
get_oZ(), Catch::Matchers::WithinAbs(2, margin));
CHECK_THAT(circle->
p2->
get_oX(), Catch::Matchers::WithinAbs(3, margin));
CHECK_THAT(circle->
p2->
get_oY(), Catch::Matchers::WithinAbs(4, margin));
CHECK_THAT(circle->
p2->
get_oZ(), Catch::Matchers::WithinAbs(5, margin));
CHECK_THAT(circle->
p3->
get_oX(), Catch::Matchers::WithinAbs(6, margin));
CHECK_THAT(circle->
p3->
get_oY(), Catch::Matchers::WithinAbs(7, margin));
CHECK_THAT(circle->
p3->
get_oZ(), Catch::Matchers::WithinAbs(8, margin));
CHECK(faces.
size() == 1);
printFacesInfo(faces);
}
TEST_CASE("vpMbGenericTracker load CAO model [hierarchical]", "[vpMbGenericTracker CAO parsing]")
{
const std::string cao_filename =
const bool verbose = true;
REQUIRE_NOTHROW(tracker.
loadModel(cao_filename, verbose));
{
std::list<vpMbtDistanceLine *> lines;
REQUIRE(lines.size() == 2);
std::vector<std::string> line_names = { "line_0", "line_1" };
int idx = 0;
for (auto line : lines) {
CHECK_THAT(line->p1->get_oX(), Catch::Matchers::WithinAbs(idx*3 + 0, margin));
CHECK_THAT(line->p1->get_oY(), Catch::Matchers::WithinAbs(idx*3 + 1, margin));
CHECK_THAT(line->p1->get_oZ(), Catch::Matchers::WithinAbs(idx*3 + 2, margin));
CHECK(line->getName() == line_names[idx]);
++idx;
}
}
{
CHECK(faces.
size() == 8);
printFacesInfo(faces);
}
{
std::list<vpMbtDistanceCylinder *> cylinders;
CHECK(cylinders.size() == 1);
CHECK(cylinder->
getName() ==
"cylinder");
CHECK_THAT(cylinder->
radius, Catch::Matchers::WithinAbs(0.5, margin));
CHECK_THAT(cylinder->
p1->
get_oX(), Catch::Matchers::WithinAbs(0, margin));
CHECK_THAT(cylinder->
p1->
get_oY(), Catch::Matchers::WithinAbs(1, margin));
CHECK_THAT(cylinder->
p1->
get_oZ(), Catch::Matchers::WithinAbs(2, margin));
CHECK_THAT(cylinder->
p2->
get_oX(), Catch::Matchers::WithinAbs(3, margin));
CHECK_THAT(cylinder->
p2->
get_oY(), Catch::Matchers::WithinAbs(4, margin));
CHECK_THAT(cylinder->
p2->
get_oZ(), Catch::Matchers::WithinAbs(5, margin));
}
{
std::list<vpMbtDistanceCircle *> circles;
CHECK(circles.size() == 1);
CHECK(circle->
getName() ==
"circle");
CHECK_THAT(circle->
radius, Catch::Matchers::WithinAbs(0.5, margin));
CHECK_THAT(circle->
p1->
get_oX(), Catch::Matchers::WithinAbs(0, margin));
CHECK_THAT(circle->
p1->
get_oY(), Catch::Matchers::WithinAbs(1, margin));
CHECK_THAT(circle->
p1->
get_oZ(), Catch::Matchers::WithinAbs(2, margin));
CHECK_THAT(circle->
p2->
get_oX(), Catch::Matchers::WithinAbs(3, margin));
CHECK_THAT(circle->
p2->
get_oY(), Catch::Matchers::WithinAbs(4, margin));
CHECK_THAT(circle->
p2->
get_oZ(), Catch::Matchers::WithinAbs(5, margin));
CHECK_THAT(circle->
p3->
get_oX(), Catch::Matchers::WithinAbs(6, margin));
CHECK_THAT(circle->
p3->
get_oY(), Catch::Matchers::WithinAbs(7, margin));
CHECK_THAT(circle->
p3->
get_oZ(), Catch::Matchers::WithinAbs(8, margin));
}
}
#endif
int main(int argc, char *argv[])
{
Catch::Session session;
session.applyCommandLine(argc, argv);
int numFailed = session.run();
return numFailed;
}
#else
#include <iostream>
int main() { return EXIT_SUCCESS; }
#endif
Real-time 6D object pose tracking using its CAD model.
virtual void getLcircle(std::list< vpMbtDistanceCircle * > &circlesList, unsigned int level=0) const
virtual void getLcylinder(std::list< vpMbtDistanceCylinder * > &cylindersList, unsigned int level=0) const
virtual void loadModel(const std::string &modelFile, bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix()) VP_OVERRIDE
virtual void getLline(std::list< vpMbtDistanceLine * > &linesList, unsigned int level=0) const
virtual vpMbHiddenFaces< vpMbtPolygon > & getFaces() VP_OVERRIDE
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.