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"
63 void usage(
const char *name,
const char *badparam);
64 bool getOptions(
int argc,
const char **argv,
bool& opt_display,
bool& opt_click);
74 void usage(
const char *name,
const char *badparam)
77 test the generic 2D polygons.\n\
86 Disable mouse click.\n\
92 Print the help.\n\n");
95 fprintf(stderr,
"ERROR: \n" );
96 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
109 bool getOptions(
int argc,
const char **argv,
bool& opt_display,
bool& opt_click)
116 case 'c': opt_click =
false;
break;
117 case 'd': opt_display =
false;
break;
118 case 'h': usage(argv[0], NULL);
return false;
break;
121 usage(argv[0], optarg_);
return false;
break;
125 if ((c == 1) || (c == -1)) {
127 usage(argv[0], NULL);
128 std::cerr <<
"ERROR: " << std::endl;
129 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
143 main(
int argc,
const char** argv)
146 bool opt_display =
true;
147 bool opt_click =
true;
151 if (getOptions(argc, argv, opt_display, opt_click) ==
false) {
155 std::vector <vpImagePoint> vec1;
164 std::vector <vpImagePoint> vec2;
172 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;
250 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.
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
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