37#include <visp3/core/vpConfig.h>
38#include <visp3/core/vpImagePoint.h>
39#include <visp3/core/vpPolygon.h>
40#include <visp3/io/vpParseArgv.h>
42#include <visp3/core/vpDisplay.h>
43#include <visp3/gui/vpDisplayGDI.h>
44#include <visp3/gui/vpDisplayGTK.h>
45#include <visp3/gui/vpDisplayX.h>
54#define GETOPTARGS "cdm:h"
56void usage(
const char *name,
const char *badparam);
57bool getOptions(
int argc,
const char **argv,
bool &opt_display,
bool &opt_click,
int &method);
67void usage(
const char *name,
const char *badparam)
70test the generic 2D polygons.\n\
80 Disable mouse click.\n\
86 Point in polygon test method.\n\
89 Print the help.\n\n");
92 fprintf(stderr,
"ERROR: \n");
93 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
106bool getOptions(
int argc,
const char **argv,
bool &opt_display,
bool &opt_click,
int &method)
108#ifdef ENABLE_VISP_NAMESPACE
123 method = atoi(optarg_);
126 usage(argv[0],
nullptr);
130 usage(argv[0], optarg_);
135 if ((c == 1) || (c == -1)) {
137 usage(argv[0],
nullptr);
138 std::cerr <<
"ERROR: " << std::endl;
139 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
152int main(
int argc,
const char **argv)
154#ifdef ENABLE_VISP_NAMESPACE
158 bool opt_display =
true;
159 bool opt_click =
true;
164 if (getOptions(argc, argv, opt_display, opt_click, method) ==
false) {
168 std::vector<vpImagePoint> vec1;
177 std::vector<vpImagePoint> vec2;
184 std::vector<vpImagePoint> vec3;
187#if defined(VISP_HAVE_X11)
189#elif defined(VISP_HAVE_GTK)
191#elif defined(VISP_HAVE_GDI)
197 std::cout <<
" Polygon 1 : " << std::endl;
198 std::cout <<
" area : " << p1.
getArea() << std::endl;
199 std::cout <<
" center : " << p1.
getCenter() << std::endl << std::endl;
201 std::cout <<
" Polygon 2 : " << std::endl;
202 std::cout <<
" area : " << p2.getArea() << std::endl;
203 std::cout <<
" center : " << p2.getCenter() << std::endl << std::endl;
205 std::cout <<
" Polygon 3 : " << std::endl;
206 std::cout <<
" area : " << p3.getArea() << std::endl;
207 std::cout <<
" center : " << p3.getCenter() << std::endl;
210#if (defined VISP_HAVE_X11) || (defined VISP_HAVE_GTK) || (defined VISP_HAVE_GDI)
211 display.init(I, 10, 10,
"Test vpPolygon");
234 std::cout << std::endl;
235 std::cout <<
" Polygon 4 : " << std::endl;
236 std::cout <<
" area : " << p4.
getArea() << std::endl;
237 std::cout <<
" center : " << p4.
getCenter() << std::endl;
238 std::cout <<
"Click to continue." << std::endl;
243 for (
unsigned int i =
static_cast<unsigned int>(floor(bbox.
getTop())); i <
static_cast<unsigned int>(ceil(bbox.
getBottom())); ++i) {
244 for (
unsigned int j =
static_cast<unsigned int>(floor(bbox.
getLeft())); j <
static_cast<unsigned int>(ceil(bbox.
getRight())); ++j) {
252 std::cout <<
"Click to continue." << std::endl;
254 for (
unsigned int i = 0;
i < I.getHeight(); ++
i) {
255 for (
unsigned int j = 0;
j < I.getWidth(); ++
j) {
263 std::cout <<
"Click to finish." << std::endl;
269 std::vector<vpImagePoint> corners = p4.
getCorners();
270 std::cout <<
"Nb polygon corners=" << corners.size() << std::endl;
277 for (
unsigned int i = 0;
i < I_segmentIntersection.getHeight();
i++) {
278 for (
unsigned int j = 0;
j < I_segmentIntersection.getWidth();
j++) {
280 I_segmentIntersection[
i][
j] = 255;
285 std::cout <<
"PnPolySegmentIntersection: " << t_benchmark <<
" ms" << std::endl;
288 for (
unsigned int i = 0;
i < I_rayCasting.getHeight();
i++) {
289 for (
unsigned int j = 0;
j < I_rayCasting.getWidth();
j++) {
291 I_rayCasting[
i][
j] = 255;
296 std::cout <<
"PnPolyRayCasting: " << t_benchmark <<
" ms" << std::endl;
298#if defined(VISP_HAVE_X11)
300#elif defined(VISP_HAVE_GTK)
302#elif defined(VISP_HAVE_GDI)
306#if (defined VISP_HAVE_X11) || (defined VISP_HAVE_GTK) || (defined VISP_HAVE_GDI)
307 display1.
init(I_segmentIntersection, 10, 10,
"Segment Intersection test");
308 display2.
init(I_rayCasting,
static_cast<int>(I_segmentIntersection.getWidth()) + 10, 10,
"Ray Casting test");
324 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="") 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 ...
Definition of the vpImage class member functions.
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
vpPolygon & buildFrom(const std::vector< vpImagePoint > &corners, const bool &create_convex_hull=false)
vpImagePoint getCenter() const
const std::vector< vpImagePoint > & getCorners() 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()