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"
56 void usage(
const char *name,
const char *badparam);
57 bool getOptions(
int argc,
const char **argv,
bool &opt_display,
bool &opt_click,
int &method);
67 void usage(
const char *name,
const char *badparam)
70 test 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);
106 bool 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);
131 usage(argv[0], optarg_);
137 if ((c == 1) || (c == -1)) {
139 usage(argv[0],
nullptr);
140 std::cerr <<
"ERROR: " << std::endl;
141 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
154 int main(
int argc,
const char **argv)
156 #ifdef ENABLE_VISP_NAMESPACE
160 bool opt_display =
true;
161 bool opt_click =
true;
166 if (getOptions(argc, argv, opt_display, opt_click, method) ==
false) {
170 std::vector<vpImagePoint> vec1;
179 std::vector<vpImagePoint> vec2;
186 std::vector<vpImagePoint> vec3;
189 #if defined(VISP_HAVE_X11)
191 #elif defined(VISP_HAVE_GTK)
193 #elif defined(VISP_HAVE_GDI)
199 std::cout <<
" Polygon 1 : " << std::endl;
200 std::cout <<
" area : " << p1.
getArea() << std::endl;
201 std::cout <<
" center : " << p1.
getCenter() << std::endl << std::endl;
203 std::cout <<
" Polygon 2 : " << std::endl;
204 std::cout <<
" area : " << p2.getArea() << std::endl;
205 std::cout <<
" center : " << p2.getCenter() << std::endl << std::endl;
207 std::cout <<
" Polygon 3 : " << std::endl;
208 std::cout <<
" area : " << p3.getArea() << std::endl;
209 std::cout <<
" center : " << p3.getCenter() << std::endl;
212 #if (defined VISP_HAVE_X11) || (defined VISP_HAVE_GTK) || (defined VISP_HAVE_GDI)
213 display.init(I, 10, 10,
"Test vpPolygon");
236 std::cout << std::endl;
237 std::cout <<
" Polygon 4 : " << std::endl;
238 std::cout <<
" area : " << p4.
getArea() << std::endl;
239 std::cout <<
" center : " << p4.
getCenter() << std::endl;
240 std::cout <<
"Click to continue." << std::endl;
245 for (
unsigned int i = (
unsigned int)floor(bbox.
getTop()); i < (
unsigned int)ceil(bbox.
getBottom()); ++i) {
246 for (
unsigned int j = (
unsigned int)floor(bbox.
getLeft()); j < (
unsigned int)ceil(bbox.
getRight()); ++j) {
254 std::cout <<
"Click to continue." << std::endl;
256 for (
unsigned int i = 0; i < I.
getHeight(); ++i) {
257 for (
unsigned int j = 0; j < I.
getWidth(); ++j) {
265 std::cout <<
"Click to finish." << std::endl;
271 std::vector<vpImagePoint> corners = p4.
getCorners();
272 std::cout <<
"Nb polygon corners=" << corners.size() << std::endl;
279 for (
unsigned int i = 0; i < I_segmentIntersection.getHeight(); i++) {
280 for (
unsigned int j = 0; j < I_segmentIntersection.getWidth(); j++) {
282 I_segmentIntersection[i][j] = 255;
287 std::cout <<
"PnPolySegmentIntersection: " << t_benchmark <<
" ms" << std::endl;
290 for (
unsigned int i = 0; i < I_rayCasting.getHeight(); i++) {
291 for (
unsigned int j = 0; j < I_rayCasting.getWidth(); j++) {
293 I_rayCasting[i][j] = 255;
298 std::cout <<
"PnPolyRayCasting: " << t_benchmark <<
" ms" << std::endl;
300 #if defined(VISP_HAVE_X11)
302 #elif defined(VISP_HAVE_GTK)
304 #elif defined(VISP_HAVE_GDI)
308 #if (defined VISP_HAVE_X11) || (defined VISP_HAVE_GTK) || (defined VISP_HAVE_GDI)
309 display1.
init(I_segmentIntersection, 10, 10,
"Segment Intersection test");
310 display2.
init(I_rayCasting, (
int)I_segmentIntersection.getWidth() + 10, 10,
"Ray Casting test");
326 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 ...
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()