35#include <visp3/core/vpConfig.h>
36#include <visp3/core/vpImagePoint.h>
37#include <visp3/core/vpPolygon.h>
38#include <visp3/io/vpParseArgv.h>
40#include <visp3/core/vpDisplay.h>
41#include <visp3/gui/vpDisplayGDI.h>
42#include <visp3/gui/vpDisplayGTK.h>
43#include <visp3/gui/vpDisplayX.h>
52#define GETOPTARGS "cdm:h"
54void usage(
const char *name,
const char *badparam);
55bool getOptions(
int argc,
const char **argv,
bool &opt_display,
bool &opt_click,
int &method);
65void usage(
const char *name,
const char *badparam)
68test the generic 2D polygons.\n\
78 Disable mouse click.\n\
84 Point in polygon test method.\n\
87 Print the help.\n\n");
90 fprintf(stderr,
"ERROR: \n");
91 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
104bool getOptions(
int argc,
const char **argv,
bool &opt_display,
bool &opt_click,
int &method)
118 method = atoi(optarg_);
121 usage(argv[0], NULL);
126 usage(argv[0], optarg_);
132 if ((c == 1) || (c == -1)) {
134 usage(argv[0], NULL);
135 std::cerr <<
"ERROR: " << std::endl;
136 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
149int main(
int argc,
const char **argv)
152 bool opt_display =
true;
153 bool opt_click =
true;
158 if (getOptions(argc, argv, opt_display, opt_click, method) ==
false) {
162 std::vector<vpImagePoint> vec1;
171 std::vector<vpImagePoint> vec2;
178 std::vector<vpImagePoint> vec3;
181#if defined(VISP_HAVE_X11)
183#elif defined(VISP_HAVE_GTK)
185#elif defined(VISP_HAVE_GDI)
191 std::cout <<
" Polygon 1 : " << std::endl;
192 std::cout <<
" area : " << p1.
getArea() << std::endl;
193 std::cout <<
" center : " << p1.
getCenter() << std::endl << std::endl;
195 std::cout <<
" Polygon 2 : " << std::endl;
196 std::cout <<
" area : " << p2.getArea() << std::endl;
197 std::cout <<
" center : " << p2.getCenter() << std::endl << std::endl;
199 std::cout <<
" Polygon 3 : " << std::endl;
200 std::cout <<
" area : " << p3.getArea() << std::endl;
201 std::cout <<
" center : " << p3.getCenter() << std::endl;
204#if (defined VISP_HAVE_X11) || (defined VISP_HAVE_GTK) || (defined VISP_HAVE_GDI)
205 display.init(I, 10, 10,
"Test vpPolygon");
228 std::cout << std::endl;
229 std::cout <<
" Polygon 4 : " << std::endl;
230 std::cout <<
" area : " << p4.
getArea() << std::endl;
231 std::cout <<
" center : " << p4.
getCenter() << std::endl;
232 std::cout <<
"Click to continue." << std::endl;
237 for (
unsigned int i = (
unsigned int)floor(bbox.
getTop()); i < (
unsigned int)ceil(bbox.
getBottom()); ++i) {
238 for (
unsigned int j = (
unsigned int)floor(bbox.
getLeft()); j < (
unsigned int)ceil(bbox.
getRight()); ++j) {
246 std::cout <<
"Click to continue." << std::endl;
248 for (
unsigned int i = 0; i < I.
getHeight(); ++i) {
249 for (
unsigned int j = 0; j < I.
getWidth(); ++j) {
257 std::cout <<
"Click to finish." << std::endl;
263 std::vector<vpImagePoint> corners = p4.
getCorners();
264 std::cout <<
"Nb polygon corners=" << corners.size() << std::endl;
271 for (
unsigned int i = 0; i < I_segmentIntersection.getHeight(); i++) {
272 for (
unsigned int j = 0; j < I_segmentIntersection.getWidth(); j++) {
274 I_segmentIntersection[i][j] = 255;
279 std::cout <<
"PnPolySegmentIntersection: " << t_benchmark <<
" ms" << std::endl;
282 for (
unsigned int i = 0; i < I_rayCasting.getHeight(); i++) {
283 for (
unsigned int j = 0; j < I_rayCasting.getWidth(); j++) {
285 I_rayCasting[i][j] = 255;
290 std::cout <<
"PnPolyRayCasting: " << t_benchmark <<
" ms" << std::endl;
292#if defined(VISP_HAVE_X11)
294#elif defined(VISP_HAVE_GTK)
296#elif defined(VISP_HAVE_GDI)
300#if (defined VISP_HAVE_X11) || (defined VISP_HAVE_GTK) || (defined VISP_HAVE_GDI)
301 display1.
init(I_segmentIntersection, 10, 10,
"Segment Intersection test");
302 display2.
init(I_rayCasting, (
int)I_segmentIntersection.getWidth() + 10, 10,
"Ray Casting test");
318 std::cout <<
"Catch an exception: " << e << std::endl;
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...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
void init(vpImage< unsigned char > &I, int win_x=-1, int win_y=-1, const std::string &win_title="")
static void close(vpImage< unsigned char > &I)
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 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 ...
Definition of the vpImage class member functions.
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.
void display(const vpImage< unsigned char > &I, const vpColor &color, unsigned int thickness=1) const
vpRect getBoundingBox() const
vpImagePoint getCenter() const
const std::vector< vpImagePoint > & getCorners() const
@ PnPolySegmentIntersection
void buildFrom(const std::vector< vpImagePoint > &corners, const bool create_convex_hull=false)
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()