37 #include <visp3/core/vpConfig.h>
38 #include <visp3/core/vpPolygon.h>
39 #include <visp3/io/vpParseArgv.h>
40 #include <visp3/core/vpImagePoint.h>
42 #include <visp3/core/vpDisplay.h>
43 #include <visp3/gui/vpDisplayX.h>
44 #include <visp3/gui/vpDisplayGTK.h>
45 #include <visp3/gui/vpDisplayGDI.h>
55 #define GETOPTARGS "cdm:h"
57 void usage(
const char *name,
const char *badparam);
58 bool getOptions(
int argc,
const char **argv,
bool& opt_display,
bool& opt_click,
int &method);
68 void usage(
const char *name,
const char *badparam)
71 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)
113 case 'c': opt_click =
false;
break;
114 case 'd': opt_display =
false;
break;
115 case 'm': method = atoi(optarg_);
break;
116 case 'h': usage(argv[0], NULL);
return false;
break;
119 usage(argv[0], optarg_);
return false;
break;
123 if ((c == 1) || (c == -1)) {
125 usage(argv[0], NULL);
126 std::cerr <<
"ERROR: " << std::endl;
127 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
139 main(
int argc,
const char** argv)
142 bool opt_display =
true;
143 bool opt_click =
true;
148 if (getOptions(argc, argv, opt_display, opt_click, method) ==
false) {
152 std::vector <vpImagePoint> vec1;
161 std::vector <vpImagePoint> vec2;
169 std::vector <vpImagePoint> vec3;
172 #if defined VISP_HAVE_X11
174 #elif defined VISP_HAVE_GTK
176 #elif defined VISP_HAVE_GDI
182 std::cout <<
" Polygon 1 : " << std::endl;
183 std::cout <<
" area : " << p1.
getArea() << std::endl;
184 std::cout <<
" center : " << p1.
getCenter() << std::endl << std::endl;
186 std::cout <<
" Polygon 2 : " << std::endl;
187 std::cout <<
" area : " << p2.getArea() << std::endl;
188 std::cout <<
" center : " << p2.getCenter() << std::endl << std::endl;
190 std::cout <<
" Polygon 3 : " << std::endl;
191 std::cout <<
" area : " << p3.getArea() << std::endl;
192 std::cout <<
" center : " << p3.getCenter() << std::endl;
196 #if (defined VISP_HAVE_X11) || (defined VISP_HAVE_GTK) || (defined VISP_HAVE_GDI)
197 display.
init(I, 10, 10,
"Test vpPolygon");
221 std::cout << std::endl;
222 std::cout <<
" Polygon 4 : " << std::endl;
223 std::cout <<
" area : " << p4.
getArea() << std::endl;
224 std::cout <<
" center : " << p4.
getCenter() << std::endl;
225 std::cout <<
"Click to continue." << std::endl;
230 for(
unsigned int i= (
unsigned int)floor(bbox.
getTop()); i<(
unsigned int)ceil(bbox.
getBottom()); ++i){
231 for(
unsigned int j=(
unsigned int)floor(bbox.
getLeft()); j<(
unsigned int)ceil(bbox.
getRight()); ++j){
239 std::cout <<
"Click to continue." << std::endl;
241 for(
unsigned int i= 0; i<I.
getHeight(); ++i){
242 for(
unsigned int j=0; j<I.
getWidth(); ++j){
250 std::cout <<
"Click to finish." << std::endl;
256 std::vector<vpImagePoint> corners = p4.
getCorners();
257 std::cout <<
"Nb polygon corners=" << corners.size() << std::endl;
264 for (
unsigned int i = 0; i < I_segmentIntersection.getHeight(); i++) {
265 for (
unsigned int j = 0; j < I_segmentIntersection.getWidth(); j++) {
267 I_segmentIntersection[i][j] = 255;
272 std::cout <<
"PnPolySegmentIntersection: " << t_benchmark <<
" ms" << std::endl;
275 for (
unsigned int i = 0; i < I_rayCasting.getHeight(); i++) {
276 for (
unsigned int j = 0; j < I_rayCasting.getWidth(); j++) {
278 I_rayCasting[i][j] = 255;
283 std::cout <<
"PnPolyRayCasting: " << t_benchmark <<
" ms" << std::endl;
285 #if defined VISP_HAVE_X11
287 #elif defined VISP_HAVE_GTK
289 #elif defined VISP_HAVE_GDI
293 #if (defined VISP_HAVE_X11) || (defined VISP_HAVE_GTK) || (defined VISP_HAVE_GDI)
294 display1.
init(I_segmentIntersection, 10, 10,
"Segment Intersection test");
295 display2.
init(I_rayCasting, (
int)I_segmentIntersection.getWidth() + 10, 10,
"Ray Casting test");
311 std::cout <<
"Catch an exception: " << e << std::endl;
const std::vector< vpImagePoint > & getCorners() const
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void close(vpImage< unsigned char > &I)
unsigned int getWidth() const
Display for windows using GDI (available on any windows 32 platform).
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
error that can be emited by ViSP classes.
static void displayPoint(const vpImage< unsigned char > &I, const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1)
static const vpColor green
static void flush(const vpImage< unsigned char > &I)
VISP_EXPORT double measureTimeMs()
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
static const vpColor orange
bool isInside(const vpImagePoint &iP, const PointInPolygonMethod &method=PnPolyRayCasting) const
Defines a generic 2D polygon.
vpRect getBoundingBox() const
static void display(const vpImage< unsigned char > &I)
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
vpImagePoint getCenter() const
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
void initClick(const vpImage< unsigned char > &I)
unsigned int getHeight() const
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
Defines a rectangle in the plane.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static const vpColor lightBlue
void buildFrom(const std::vector< vpImagePoint > &corners)
static const vpColor blue
void display(const vpImage< unsigned char > &I, const vpColor &color, unsigned int thickness=1) const