50 #include <visp/vpConfig.h>
52 #if defined(VISP_HAVE_OGRE) && defined(VISP_HAVE_DISPLAY)
54 #if defined(VISP_HAVE_X11) && ! defined(APPLE)
59 # include <visp/vpDisplayX.h>
61 #include <visp/vpDisplayGTK.h>
62 #include <visp/vpDisplayGDI.h>
63 #include <visp/vpDisplayOpenCV.h>
64 #include <visp/vpDisplayD3D.h>
65 #include <visp/vpPose.h>
66 #include <visp/vpPoint.h>
67 #include <visp/vpImagePoint.h>
68 #include <visp/vpDot2.h>
69 #include <visp/vpPixelMeterConversion.h>
70 #include <visp/vpVideoReader.h>
71 #include <visp/vpParseArgv.h>
72 #include <visp/vpIoTools.h>
73 #include <visp/vpDebug.h>
74 #include <visp/vpAROgre.h>
77 #define GETOPTARGS "ci:p:h"
89 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath)
92 Test augmented reality using the vpAROgre class.\n\
95 %s [-i <test image path>] [-p <personal image path>]\n\
100 -i <input image path> %s\n\
101 Set image input path.\n\
102 From this path read images \n\
103 \"ViSP-images/mire-2/image.%%04d.pgm\". These \n\
104 images come from ViSP-images-x.y.z.tar.gz available \n\
105 on the ViSP website.\n\
106 Setting the VISP_INPUT_IMAGE_PATH environment\n\
107 variable produces the same behaviour than using\n\
110 -p <personal image path> %s\n\
111 Specify a personal sequence containing images \n\
113 By image sequence, we mean one file per image.\n\
114 The following image file formats PNM (PGM P5, PPM P6)\n\
115 are supported. The format is selected by analysing \n\
116 the filename extension.\n\
117 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\
118 %%04d is for the image numbering.\n\
121 Disable the mouse click. Useful to automaze the \n\
122 execution of this program without humain intervention.\n\
126 ipath.c_str(), ppath.c_str());
129 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
144 bool getOptions(
int argc,
const char **argv, std::string &ipath,
145 std::string &ppath,
bool &click_allowed)
152 case 'c': click_allowed =
false;
break;
153 case 'i': ipath = optarg;
break;
154 case 'p': ppath = optarg;
break;
155 case 'h': usage(argv[0], NULL, ipath, ppath);
159 usage(argv[0], optarg, ipath, ppath);
164 if ((c == 1) || (c == -1)) {
166 usage(argv[0], NULL, ipath, ppath);
167 std::cerr <<
"ERROR: " << std::endl;
168 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
182 const bool &opt_click_allowed)
187 bool opt_display =
true;
189 #if defined(VISP_HAVE_X11) && ! defined(APPLE)
195 #elif defined VISP_HAVE_GTK
197 #elif defined VISP_HAVE_GDI
199 #elif defined VISP_HAVE_OPENCV
201 #elif defined VISP_HAVE_D3D9
205 for (
unsigned int i=0 ; i < 4 ; i++)
218 display.
init(I,100,100,
"Preliminary Pose Calculation");
236 std::cout<<
"************************************************************************************"<<std::endl;
237 std::cout<<
"*************************** Preliminary Pose Calculation ***************************"<<std::endl;
238 std::cout<<
"****************************** Click on the 4 dots *******************************"<<std::endl;
239 std::cout<<
"********Dot1 : (-x,-y,0), Dot2 : (x,-y,0), Dot3 : (x,y,0), Dot4 : (-x,y,0)**********"<<std::endl;
240 std::cout<<
"************************************************************************************"<<std::endl;
244 if (! opt_click_allowed) {
255 for(
unsigned int i=0;i<4;i++) {
265 for(
unsigned int j = 0;j<i;j++)
271 if (opt_click_allowed) {
318 for (
unsigned int i=0 ; i < 4 ; i++)
341 for (
unsigned int i=0 ; i < 4 ; i++)
357 for (
unsigned int i=0 ; i < 4 ; i++)
382 int main(
int argc,
const char **argv)
384 std::string env_ipath;
385 std::string opt_ipath;
387 std::string opt_ppath;
389 std::string filename;
390 bool opt_click_allowed =
true;
393 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
398 if (! env_ipath.empty())
403 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_click_allowed) ==
false) {
408 if (!opt_ipath.empty())
413 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
414 if (ipath != env_ipath) {
415 std::cout << std::endl
416 <<
"WARNING: " << std::endl;
417 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
418 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
419 <<
" we skip the environment variable." << std::endl;
424 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty() ){
425 usage(argv[0], NULL, ipath, opt_ppath);
426 std::cerr << std::endl
427 <<
"ERROR:" << std::endl;
428 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
430 <<
" environment variable to specify the location of the " << std::endl
431 <<
" image path where test images are located." << std::endl
432 <<
" Use -p <personal image path> option if you want to "<<std::endl
433 <<
" use personal images." << std::endl
445 std::ostringstream s;
448 if (opt_ppath.empty()){
454 s.setf(std::ios::right, std::ios::adjustfield);
455 s <<
"image.%04d.pgm";
456 filename = dirname + s.str();
459 filename = opt_ppath;
492 vpCTRACE <<
"Load: " << filename << std::endl;
493 grabber.
open(Idisplay);
497 computeInitialPose(&mcamTmp, Idisplay, &mPose, md, mcog, &cmo, mP,
512 std::cerr << std::endl
513 <<
"ERROR:" << std::endl;
514 std::cerr <<
" Cannot read " << filename << std::endl;
515 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
516 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
525 ogre.load(
"Robot",
"robot.mesh");
526 ogre.setScale(
"Robot", 0.001f,0.001f,0.001f);
532 while(ogre.continueRendering()){
545 for (
int i=0 ; i < 4 ; i++)
548 md[i].
track(I, mcog[i]) ;
574 ogre.display(IC,cmo);
582 catch (Ogre::Exception& e)
584 std::cerr <<
"Exception:\n";
585 std::cerr << e.getFullDescription().c_str() <<
"\n";
590 std::cerr <<
"Exception: " <<
"\n";
596 #else // VISP_HAVE_OGRE && VISP_HAVE_DISPLAY
600 std::cout <<
"You should install Ogre3D to run this example..." << std::endl;