38 #include <visp3/core/vpConfig.h> 39 #include <visp3/core/vpImagePoint.h> 40 #include <visp3/core/vpPolygon.h> 41 #include <visp3/io/vpParseArgv.h> 43 #include <visp3/core/vpDisplay.h> 44 #include <visp3/gui/vpDisplayGDI.h> 45 #include <visp3/gui/vpDisplayGTK.h> 46 #include <visp3/gui/vpDisplayX.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)
120 method = atoi(optarg_);
123 usage(argv[0], NULL);
128 usage(argv[0], optarg_);
134 if ((c == 1) || (c == -1)) {
136 usage(argv[0], NULL);
137 std::cerr <<
"ERROR: " << std::endl;
138 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
151 int main(
int argc,
const char **argv)
154 bool opt_display =
true;
155 bool opt_click =
true;
160 if (getOptions(argc, argv, opt_display, opt_click, method) ==
false) {
164 std::vector<vpImagePoint> vec1;
173 std::vector<vpImagePoint> vec2;
180 std::vector<vpImagePoint> vec3;
183 #if defined VISP_HAVE_X11 185 #elif defined VISP_HAVE_GTK 187 #elif defined VISP_HAVE_GDI 193 std::cout <<
" Polygon 1 : " << std::endl;
194 std::cout <<
" area : " << p1.
getArea() << std::endl;
195 std::cout <<
" center : " << p1.
getCenter() << std::endl << std::endl;
197 std::cout <<
" Polygon 2 : " << std::endl;
198 std::cout <<
" area : " << p2.getArea() << std::endl;
199 std::cout <<
" center : " << p2.getCenter() << std::endl << std::endl;
201 std::cout <<
" Polygon 3 : " << std::endl;
202 std::cout <<
" area : " << p3.getArea() << std::endl;
203 std::cout <<
" center : " << p3.getCenter() << std::endl;
206 #if (defined VISP_HAVE_X11) || (defined VISP_HAVE_GTK) || (defined VISP_HAVE_GDI) 207 display.
init(I, 10, 10,
"Test vpPolygon");
230 std::cout << std::endl;
231 std::cout <<
" Polygon 4 : " << std::endl;
232 std::cout <<
" area : " << p4.
getArea() << std::endl;
233 std::cout <<
" center : " << p4.
getCenter() << std::endl;
234 std::cout <<
"Click to continue." << std::endl;
239 for (
unsigned int i = (
unsigned int)floor(bbox.
getTop()); i < (
unsigned int)ceil(bbox.
getBottom()); ++i) {
240 for (
unsigned int j = (
unsigned int)floor(bbox.
getLeft()); j < (
unsigned int)ceil(bbox.
getRight()); ++j) {
248 std::cout <<
"Click to continue." << std::endl;
250 for (
unsigned int i = 0; i < I.
getHeight(); ++i) {
251 for (
unsigned int j = 0; j < I.
getWidth(); ++j) {
259 std::cout <<
"Click to finish." << std::endl;
265 std::vector<vpImagePoint> corners = p4.
getCorners();
266 std::cout <<
"Nb polygon corners=" << corners.size() << std::endl;
273 for (
unsigned int i = 0; i < I_segmentIntersection.getHeight(); i++) {
274 for (
unsigned int j = 0; j < I_segmentIntersection.getWidth(); j++) {
276 I_segmentIntersection[i][j] = 255;
281 std::cout <<
"PnPolySegmentIntersection: " << t_benchmark <<
" ms" << std::endl;
284 for (
unsigned int i = 0; i < I_rayCasting.getHeight(); i++) {
285 for (
unsigned int j = 0; j < I_rayCasting.getWidth(); j++) {
287 I_rayCasting[i][j] = 255;
292 std::cout <<
"PnPolyRayCasting: " << t_benchmark <<
" ms" << std::endl;
294 #if defined VISP_HAVE_X11 296 #elif defined VISP_HAVE_GTK 298 #elif defined VISP_HAVE_GDI 302 #if (defined VISP_HAVE_X11) || (defined VISP_HAVE_GTK) || (defined VISP_HAVE_GDI) 303 display1.
init(I_segmentIntersection, 10, 10,
"Segment Intersection test");
304 display2.
init(I_rayCasting, (
int)I_segmentIntersection.getWidth() + 10, 10,
"Ray Casting test");
319 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)
void initClick(const vpImage< unsigned char > &I, unsigned int size=5, const vpColor &color=vpColor::red, unsigned int thickness=1)
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)
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