#include <visp3/core/vpPolygon.h>
#include <visp3/core/vpConfig.h>
#include <visp3/core/vpRect.h>
#ifdef VISP_HAVE_CATCH2
#define CATCH_CONFIG_RUNNER
#include <catch.hpp>
#ifdef ENABLE_VISP_NAMESPACE
#endif
#ifdef VISP_HAVE_OPENCV
TEST_CASE("Check OpenCV-bsed convex hull")
{
SECTION("From vpRect")
{
const vpRect rect { 0, 0, 200, 400 };
const std::vector<vpImagePoint> rect_corners { rect.
getTopLeft(), rect.getTopRight(), rect.getBottomRight(),
rect.getBottomLeft() };
poly.
build(rect_corners,
true);
#if ((__cplusplus >= 201402L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201402L)))
for (const auto &poly_corner : poly.getCorners()) {
REQUIRE(std::find(cbegin(rect_corners), cend(rect_corners), poly_corner) != cend(rect_corners));
}
#else
for (const auto &poly_corner : poly.getCorners()) {
REQUIRE(std::find(begin(rect_corners), end(rect_corners), poly_corner) != end(rect_corners));
}
#endif
}
}
#endif
int main(int argc, char *argv[])
{
Catch::Session session;
session.applyCommandLine(argc, argv);
return session.run();
}
#else
bool testConvexHull()
{
#ifdef VISP_HAVE_OPENCV
const vpRect rect(0, 0, 200, 400);
std::vector<vpImagePoint> rect_corners;
rect_corners.push_back(rect.getTopLeft());
rect_corners.push_back(rect.getTopRight());
rect_corners.push_back(rect.getBottomRight());
rect_corners.push_back(rect.getBottomLeft());
poly.
build(rect_corners,
true);
#if ((__cplusplus >= 201402L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201402L)))
for (
const auto &poly_corner : poly.
getCorners()) {
if (std::find(cbegin(rect_corners), cend(rect_corners), poly_corner) == cend(rect_corners)) {
return false;
}
}
#else
for (
const auto &poly_corner : poly.
getCorners()) {
if (std::find(begin(rect_corners), end(rect_corners), poly_corner) == end(rect_corners)) {
return false;
}
}
#endif
#endif
return true;
}
int main()
{
if (!testConvexHull()) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
#endif
Defines a generic 2D polygon.
const std::vector< vpImagePoint > & getCorners() const
vpPolygon & build(const std::vector< vpImagePoint > &corners, const bool &create_convex_hull=false)
Defines a rectangle in the plane.
vpImagePoint getTopLeft() const