39 #include <visp3/core/vpConfig.h> 40 #include <visp3/core/vpPolygon.h> 41 #include <visp3/io/vpParseArgv.h> 42 #include <visp3/core/vpImagePoint.h> 44 #include <visp3/core/vpDisplay.h> 45 #include <visp3/gui/vpDisplayX.h> 46 #include <visp3/gui/vpDisplayGTK.h> 47 #include <visp3/gui/vpDisplayGDI.h> 57 #define GETOPTARGS "cdh" 59 void usage(
const char *name,
const char *badparam);
60 bool getOptions(
int argc,
const char **argv,
bool& opt_display,
bool& opt_click);
70 void usage(
const char *name,
const char *badparam)
73 test the generic 2D polygons.\n\ 82 Disable mouse click.\n\ 88 Print the help.\n\n");
91 fprintf(stderr,
"ERROR: \n" );
92 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
105 bool getOptions(
int argc,
const char **argv,
bool& opt_display,
bool& opt_click)
112 case 'c': opt_click =
false;
break;
113 case 'd': opt_display =
false;
break;
114 case 'h': usage(argv[0], NULL);
return false;
break;
117 usage(argv[0], optarg_);
return false;
break;
121 if ((c == 1) || (c == -1)) {
123 usage(argv[0], NULL);
124 std::cerr <<
"ERROR: " << std::endl;
125 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;
147 if (getOptions(argc, argv, opt_display, opt_click) ==
false) {
151 std::vector <vpImagePoint> vec1;
160 std::vector <vpImagePoint> vec2;
168 std::vector <vpImagePoint> vec3;
171 #if defined VISP_HAVE_X11 173 #elif defined VISP_HAVE_GTK 175 #elif defined VISP_HAVE_GDI 181 std::cout <<
" Polygon 1 : " << std::endl;
182 std::cout <<
" area : " << p1.
getArea() << std::endl;
183 std::cout <<
" center : " << p1.
getCenter() << std::endl << std::endl;
185 std::cout <<
" Polygon 2 : " << std::endl;
186 std::cout <<
" area : " << p2.getArea() << std::endl;
187 std::cout <<
" center : " << p2.getCenter() << std::endl << std::endl;
189 std::cout <<
" Polygon 3 : " << std::endl;
190 std::cout <<
" area : " << p3.getArea() << std::endl;
191 std::cout <<
" center : " << p3.getCenter() << std::endl;
195 #if (defined VISP_HAVE_X11) || (defined VISP_HAVE_GTK) || (defined VISP_HAVE_GDI) 196 display.
init(I, 10, 10,
"Test vpPolygon");
220 std::cout << std::endl;
221 std::cout <<
" Polygon 4 : " << std::endl;
222 std::cout <<
" area : " << p4.
getArea() << std::endl;
223 std::cout <<
" center : " << p4.
getCenter() << std::endl;
224 std::cout <<
"Click to continue." << std::endl;
229 for(
unsigned int i= (
unsigned int)floor(bbox.
getTop()); i<(
unsigned int)ceil(bbox.
getBottom()); ++i){
230 for(
unsigned int j=(
unsigned int)floor(bbox.
getLeft()); j<(
unsigned int)ceil(bbox.
getRight()); ++j){
237 std::cout <<
"Click to finish." << std::endl;
246 std::cout <<
"Catch an exception: " << e << std::endl;
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)
Define the X11 console to display images.
error that can be emited by ViSP classes.
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
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
void display(const vpImage< unsigned char > &I, const vpColor &color, unsigned int thickness=1) const