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;