43 #include <visp/vpConfig.h>
44 #include <visp/vpPolygon.h>
45 #include <visp/vpParseArgv.h>
46 #include <visp/vpImagePoint.h>
48 #include <visp/vpDisplay.h>
49 #include <visp/vpDisplayX.h>
50 #include <visp/vpDisplayGTK.h>
51 #include <visp/vpDisplayGDI.h>
61 #define GETOPTARGS "cdh"
71 void usage(
const char *name,
const char *badparam)
74 test the generic 2D polygons.\n\
83 Disable mouse click.\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,
107 bool& opt_display,
bool& opt_click)
114 case 'c': opt_click =
false;
break;
115 case 'd': opt_display =
false;
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;
141 main(
int argc,
const char** argv)
143 bool opt_display =
true;
144 bool opt_click =
true;
148 if (getOptions(argc, argv, opt_display, opt_click) ==
false) {
152 std::vector <vpImagePoint> vec1;
161 std::vector <vpImagePoint> vec2;
169 std::vector <vpImagePoint> vec3;
175 #if defined VISP_HAVE_X11
177 #elif defined VISP_HAVE_GTK
179 #elif defined VISP_HAVE_GDI
185 std::cout <<
" Polygon 1 : " << std::endl;
186 std::cout <<
" area : " << p1.
getArea() << std::endl;
187 std::cout <<
" center : " << p1.
getCenter() << std::endl << std::endl;
189 std::cout <<
" Polygon 2 : " << std::endl;
190 std::cout <<
" area : " << p2.getArea() << std::endl;
191 std::cout <<
" center : " << p2.getCenter() << std::endl << std::endl;
193 std::cout <<
" Polygon 3 : " << std::endl;
194 std::cout <<
" area : " << p3.getArea() << std::endl;
195 std::cout <<
" center : " << p3.getCenter() << std::endl;
199 #if (defined VISP_HAVE_X11) || (defined VISP_HAVE_GTK) || (defined VISP_HAVE_GDI)
200 display.
init(I, 10, 10,
"Test vpPolygon");
224 std::cout << std::endl;
225 std::cout <<
" Polygon 4 : " << std::endl;
226 std::cout <<
" area : " << p4.
getArea() << std::endl;
227 std::cout <<
" center : " << p4.
getCenter() << std::endl;
228 std::cout <<
"Click to continue." << std::endl;
233 for(
unsigned int i= (
unsigned int)floor(bbox.
getTop()); i<(
unsigned int)ceil(bbox.
getBottom()); ++i){
234 for(
unsigned int j=(
unsigned int)floor(bbox.
getLeft()); j<(
unsigned int)ceil(bbox.
getRight()); ++j){
241 std::cout <<
"Click to finish." << std::endl;
Display for windows using GDI (available on any windows 32 platform).
Define the X11 console to display images.
void display(const vpImage< unsigned char > &I, const vpColor &color, unsigned int thickness=1)
static const vpColor green
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
static const vpColor orange
bool isInside(const vpImagePoint &iP)
Defines a generic 2D polygon.
vpRect getBoundingBox() const
static void display(const vpImage< unsigned char > &I)
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
vpImagePoint getCenter() const
virtual void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color=vpColor::green)=0
void initClick(const vpImage< unsigned char > &I)
Defines a rectangle in the plane.
virtual bool getClick(bool blocking=true)=0
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static const vpColor lightBlue
virtual void displayPoint(const vpImagePoint &ip, const vpColor &color)=0
void buildFrom(const std::vector< vpImagePoint > &corners)
static const vpColor blue