#include <visp3/core/vpConfig.h>
#include <visp3/core/vpImagePoint.h>
#include <visp3/core/vpPolygon.h>
#include <visp3/io/vpParseArgv.h>
#include <visp3/core/vpDisplay.h>
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/gui/vpDisplayGTK.h>
#include <visp3/gui/vpDisplayX.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#define GETOPTARGS "cdm:h"
void usage(const char *name, const char *badparam);
bool getOptions(int argc, const char **argv, bool &opt_display, bool &opt_click, int &method);
void usage(const char *name, const char *badparam)
{
fprintf(stdout, "\n\
test the generic 2D polygons.\n\
\n\
SYNOPSIS\n\
%s [-c] [-d] [-h]\n\
",
name);
fprintf(stdout, "\n\
OPTIONS: \n\
-c \n\
Disable mouse click.\n\
\n\
-d \n\
Turn off display.\n\
\n\
-m \n\
Point in polygon test method.\n\
\n\
-h\n\
Print the help.\n\n");
if (badparam) {
fprintf(stderr, "ERROR: \n");
fprintf(stderr, "\nBad parameter [%s]\n", badparam);
}
}
bool getOptions(int argc, const char **argv, bool &opt_display, bool &opt_click, int &method)
{
#ifdef ENABLE_VISP_NAMESPACE
#endif
const char *optarg_;
int c;
switch (c) {
case 'c':
opt_click = false;
break;
case 'd':
opt_display = false;
break;
case 'm':
method = atoi(optarg_);
break;
case 'h':
usage(argv[0], nullptr);
return false;
break;
default:
usage(argv[0], optarg_);
return false;
break;
}
}
if ((c == 1) || (c == -1)) {
usage(argv[0], nullptr);
std::cerr << "ERROR: " << std::endl;
std::cerr << " Bad argument " << optarg_ << std::endl << std::endl;
return false;
}
return true;
}
int main(int argc, const char **argv)
{
#ifdef ENABLE_VISP_NAMESPACE
#endif
try {
bool opt_display = true;
bool opt_click = true;
if (getOptions(argc, argv, opt_display, opt_click, method) == false) {
return EXIT_FAILURE;
}
std::vector<vpImagePoint> vec1;
std::vector<vpImagePoint> vec2;
std::vector<vpImagePoint> vec3;
#if defined(VISP_HAVE_X11)
vpDisplayX display;
#elif defined(VISP_HAVE_GTK)
#elif defined(VISP_HAVE_GDI)
#else
opt_display = false;
#endif
std::cout << " Polygon 1 : " << std::endl;
std::cout <<
" area : " << p1.
getArea() << std::endl;
std::cout <<
" center : " << p1.
getCenter() << std::endl << std::endl;
std::cout << " Polygon 2 : " << std::endl;
std::cout << " area : " << p2.getArea() << std::endl;
std::cout << " center : " << p2.getCenter() << std::endl << std::endl;
std::cout << " Polygon 3 : " << std::endl;
std::cout << " area : " << p3.getArea() << std::endl;
std::cout << " center : " << p3.getCenter() << std::endl;
if (opt_display) {
#if (defined VISP_HAVE_X11) || (defined VISP_HAVE_GTK) || (defined VISP_HAVE_GDI)
display.init(I, 10, 10, "Test vpPolygon");
#endif
if (opt_click)
if (opt_click) {
std::cout << std::endl;
std::cout << " Polygon 4 : " << std::endl;
std::cout <<
" area : " << p4.
getArea() << std::endl;
std::cout <<
" center : " << p4.
getCenter() << std::endl;
std::cout << "Click to continue." << std::endl;
for (
unsigned int i = (
unsigned int)floor(bbox.
getTop()); i < (
unsigned int)ceil(bbox.
getBottom()); ++i) {
for (
unsigned int j = (
unsigned int)floor(bbox.
getLeft()); j < (
unsigned int)ceil(bbox.
getRight()); ++j) {
}
}
}
std::cout << "Click to continue." << std::endl;
for (
unsigned int i = 0; i < I.
getHeight(); ++i) {
for (
unsigned int j = 0; j < I.
getWidth(); ++j) {
}
}
}
std::cout << "Click to finish." << std::endl;
std::vector<vpImagePoint> corners = p4.
getCorners();
std::cout << "Nb polygon corners=" << corners.size() << std::endl;
for (unsigned int i = 0; i < I_segmentIntersection.getHeight(); i++) {
for (unsigned int j = 0; j < I_segmentIntersection.getWidth(); j++) {
I_segmentIntersection[i][j] = 255;
}
}
}
std::cout << "PnPolySegmentIntersection: " << t_benchmark << " ms" << std::endl;
for (unsigned int i = 0; i < I_rayCasting.getHeight(); i++) {
for (unsigned int j = 0; j < I_rayCasting.getWidth(); j++) {
I_rayCasting[i][j] = 255;
}
}
}
std::cout << "PnPolyRayCasting: " << t_benchmark << " ms" << std::endl;
#if defined(VISP_HAVE_X11)
vpDisplayX display1, display2;
#elif defined(VISP_HAVE_GTK)
#elif defined(VISP_HAVE_GDI)
#endif
#if (defined VISP_HAVE_X11) || (defined VISP_HAVE_GTK) || (defined VISP_HAVE_GDI)
display1.
init(I_segmentIntersection, 10, 10,
"Segment Intersection test");
display2.init(I_rayCasting, (int)I_segmentIntersection.getWidth() + 10, 10, "Ray Casting test");
#endif
}
}
return EXIT_SUCCESS;
}
std::cout << "Catch an exception: " << e << std::endl;
return EXIT_FAILURE;
}
}
static const vpColor orange
static const vpColor blue
static const vpColor lightBlue
static const vpColor green
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="") VP_OVERRIDE
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static void close(vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
static void displayPoint(const vpImage< unsigned char > &I, const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emitted by ViSP classes.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
unsigned int getWidth() const
unsigned int getHeight() const
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Defines a generic 2D polygon.
const std::vector< vpImagePoint > & getCorners() const
void display(const vpImage< unsigned char > &I, const vpColor &color, unsigned int thickness=1) const
vpRect getBoundingBox() const
vpPolygon & buildFrom(const std::vector< vpImagePoint > &corners, const bool &create_convex_hull=false)
vpImagePoint getCenter() const
@ PnPolySegmentIntersection
void initClick(const vpImage< unsigned char > &I, unsigned int size=5, const vpColor &color=vpColor::red, unsigned int thickness=1)
bool isInside(const vpImagePoint &iP, const PointInPolygonMethod &method=PnPolyRayCasting) const
Defines a rectangle in the plane.
VISP_EXPORT double measureTimeMs()