50 #include <visp/vpConfig.h>
53 #if defined(VISP_HAVE_OGRE) && defined(VISP_HAVE_DISPLAY)
55 #if defined(VISP_HAVE_X11) && ! defined(APPLE)
60 # include <visp/vpDisplayX.h>
62 #include <visp/vpDisplayGTK.h>
63 #include <visp/vpDisplayGDI.h>
64 #include <visp/vpDisplayOpenCV.h>
65 #include <visp/vpDisplayD3D.h>
66 #include <visp/vpPose.h>
67 #include <visp/vpPoint.h>
68 #include <visp/vpImagePoint.h>
69 #include <visp/vpDot2.h>
70 #include <visp/vpPixelMeterConversion.h>
71 #include <visp/vpVideoReader.h>
72 #include <visp/vpParseArgv.h>
73 #include <visp/vpIoTools.h>
74 #include <visp/vpDebug.h>
75 #include <visp/vpAROgre.h>
78 #define GETOPTARGS "ci:p:h"
91 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath)
94 Test augmented reality using the vpAROgre class.\n\
97 %s [-i <test image path>] [-p <personal image path>]\n\
102 -i <input image path> %s\n\
103 Set image input path.\n\
104 From this path read images \n\
105 \"ViSP-images/mire-2/image.%%04d.pgm\". These \n\
106 images come from ViSP-images-x.y.z.tar.gz available \n\
107 on the ViSP website.\n\
108 Setting the VISP_INPUT_IMAGE_PATH environment\n\
109 variable produces the same behaviour than using\n\
112 -p <personal image path> %s\n\
113 Specify a personal sequence containing images \n\
115 By image sequence, we mean one file per image.\n\
116 The following image file formats PNM (PGM P5, PPM P6)\n\
117 are supported. The format is selected by analysing \n\
118 the filename extension.\n\
119 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\
120 %%04d is for the image numbering.\n\
123 Disable the mouse click. Useful to automaze the \n\
124 execution of this program without humain intervention.\n\
128 ipath.c_str(), ppath.c_str());
131 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
146 bool getOptions(
int argc,
const char **argv, std::string &ipath,
147 std::string &ppath,
bool &click_allowed)
154 case 'c': click_allowed =
false;
break;
155 case 'i': ipath = optarg;
break;
156 case 'p': ppath = optarg;
break;
157 case 'h': usage(argv[0], NULL, ipath, ppath);
161 usage(argv[0], optarg, ipath, ppath);
166 if ((c == 1) || (c == -1)) {
168 usage(argv[0], NULL, ipath, ppath);
169 std::cerr <<
"ERROR: " << std::endl;
170 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
178 #ifndef DOXYGEN_SHOULD_SKIP_THIS
180 class vpAROgreExample :
public vpAROgre
185 unsigned int width = 640,
unsigned int height = 480,
186 const char *resourcePath=NULL)
189 if (resourcePath) mResourcePath = resourcePath;
190 std::cout <<
"mResourcePath: " << mResourcePath<< std::endl;
191 vecDevant = Ogre::Vector3(0,-1,0);
198 Ogre::Vector3 vecDevant;
200 Ogre::AnimationState * mAnimationState;
208 mSceneMgr->setAmbientLight(Ogre::ColourValue((
float)0.6,(
float)0.6,(
float)0.6));
209 Ogre::Light * light = mSceneMgr->createLight();
210 light->setDiffuseColour(1.0,1.0,1.0);
211 light->setSpecularColour(1.0,1.0,1.0);
213 light->setPosition(-5, -5, 10);
214 light->setType(Ogre::Light::LT_POINT);
215 light->setAttenuation((Ogre::Real)100, (Ogre::Real)1.0, (Ogre::Real)0.045, (Ogre::Real)0.0075);
217 light->setCastShadows(
true);
220 robot = mSceneMgr->createEntity(
"Robot",
"robot.mesh");
222 Ogre::SceneNode* RobotNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(
"Robot");
223 RobotNode->attachObject(robot);
224 RobotNode->scale((Ogre::Real)0.001,(Ogre::Real)0.001,(Ogre::Real)0.001);
225 RobotNode->pitch(Ogre::Degree(90));
226 RobotNode->yaw(Ogre::Degree(-90));
227 robot->setCastShadows(
true);
228 mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_MODULATIVE);
232 mAnimationState = robot->getAnimationState(
"Idle" );
234 mAnimationState->setLoop(
true );
236 mAnimationState->setEnabled(
true );
241 plan.normal = Ogre::Vector3::UNIT_Z;
242 Ogre::MeshManager::getSingleton().createPlane(
"sol",Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plan, (Ogre::Real)0.22, (Ogre::Real)0.16, 10, 10,
true, 1, 1, 1);
243 Ogre::Entity* ent = mSceneMgr->createEntity(
"Entitesol",
"sol");
244 Ogre::SceneNode* PlaneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(
"Entitesol");
245 PlaneNode->attachObject(ent);
246 ent->setMaterialName(
"Examples/GrassFloor");
252 mAnimationState->addTime( evt.timeSinceLastFrame );
258 mKeyboard->capture();
260 double angle = -M_PI/8;
261 if(mKeyboard->isKeyDown(OIS::KC_ESCAPE))
267 if(mKeyboard->isKeyDown(OIS::KC_Z) || mKeyboard->isKeyDown(OIS::KC_UP)){
268 mSceneMgr->getSceneNode(
"Robot")->setPosition(mSceneMgr->getSceneNode(
"Robot")->getPosition()+(Ogre::Real)0.003*vecDevant);
271 if(mKeyboard->isKeyDown(OIS::KC_S) || mKeyboard->isKeyDown(OIS::KC_DOWN)){
272 mSceneMgr->getSceneNode(
"Robot")->setPosition(mSceneMgr->getSceneNode(
"Robot")->getPosition()-(Ogre::Real)0.003*vecDevant);
275 if(mKeyboard->isKeyDown(OIS::KC_Q) || mKeyboard->isKeyDown(OIS::KC_LEFT)){
276 rotmy = Ogre::Matrix3((Ogre::Real)cos(-angle), (Ogre::Real)sin(-angle), 0,
277 (Ogre::Real)(-sin(-angle)), (Ogre::Real)cos(-angle),0,
279 vecDevant=vecDevant*rotmy;
280 mSceneMgr->getSceneNode(
"Robot")->yaw(Ogre::Radian((Ogre::Real)(-angle)));
283 if(mKeyboard->isKeyDown(OIS::KC_D) || mKeyboard->isKeyDown(OIS::KC_RIGHT)){
284 rotmy = Ogre::Matrix3((Ogre::Real)cos(angle), (Ogre::Real)sin(angle), 0,
285 (Ogre::Real)(-sin(angle)), (Ogre::Real)cos(angle),0,
287 vecDevant=vecDevant*rotmy;
288 mSceneMgr->getSceneNode(
"Robot")->yaw(Ogre::Radian((Ogre::Real)angle));
294 mAnimationState = robot->getAnimationState(
"Walk");
296 else mAnimationState = robot->getAnimationState(
"Idle" );
299 mAnimationState->setLoop(
true );
301 mAnimationState->setEnabled(
true );
315 const bool &opt_click_allowed)
320 bool opt_display =
true;
322 #if defined(VISP_HAVE_X11) && ! defined(APPLE)
328 #elif defined VISP_HAVE_GTK
330 #elif defined VISP_HAVE_GDI
332 #elif defined VISP_HAVE_OPENCV
334 #elif defined VISP_HAVE_D3D9
338 for (
unsigned int i=0 ; i < 4 ; i++)
351 display.
init(I,100,100,
"Preliminary Pose Calculation");
369 std::cout<<
"************************************************************************************"<<std::endl;
370 std::cout<<
"*************************** Preliminary Pose Calculation ***************************"<<std::endl;
371 std::cout<<
"****************************** Click on the 4 dots *******************************"<<std::endl;
372 std::cout<<
"********Dot1 : (-x,-y,0), Dot2 : (x,-y,0), Dot3 : (x,y,0), Dot4 : (-x,y,0)**********"<<std::endl;
373 std::cout<<
"************************************************************************************"<<std::endl;
377 if (! opt_click_allowed) {
387 for(
unsigned int i=0;i<4;i++) {
397 for(
unsigned int j = 0;j<i;j++)
403 if (opt_click_allowed)
447 for (
unsigned int i=0 ; i < 4 ; i++)
470 for (
unsigned int i=0 ; i < 4 ; i++)
486 for (
unsigned int i=0 ; i < 4 ; i++)
512 int main(
int argc,
const char **argv)
514 std::string env_ipath;
515 std::string opt_ipath;
517 std::string opt_ppath;
519 std::string filename;
520 bool opt_click_allowed =
true;
523 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
528 if (! env_ipath.empty())
533 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_click_allowed) ==
false) {
538 if (!opt_ipath.empty())
543 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
544 if (ipath != env_ipath) {
545 std::cout << std::endl
546 <<
"WARNING: " << std::endl;
547 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
548 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
549 <<
" we skip the environment variable." << std::endl;
554 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty() ){
555 usage(argv[0], NULL, ipath, opt_ppath);
556 std::cerr << std::endl
557 <<
"ERROR:" << std::endl;
558 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
560 <<
" environment variable to specify the location of the " << std::endl
561 <<
" image path where test images are located." << std::endl
562 <<
" Use -p <personal image path> option if you want to "<<std::endl
563 <<
" use personal images." << std::endl
569 std::ostringstream s;
571 if (opt_ppath.empty()){
577 s.setf(std::ios::right, std::ios::adjustfield);
578 s <<
"image.%04d.pgm";
579 filename = dirname + s.str();
582 filename = opt_ppath;
615 vpCTRACE <<
"Load: " << filename << std::endl;
616 grabber.
open(Idisplay);
620 computeInitialPose(&mcamTmp, Idisplay, &mPose, md, mcog, &cmo, mP,
635 std::cerr << std::endl
636 <<
"ERROR:" << std::endl;
637 std::cerr <<
" Cannot read " << filename << std::endl;
638 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
639 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
645 vpAROgreExample ogre(mcam, (
unsigned int)grabber.
getWidth(), (
unsigned int)grabber.
getHeight());
652 while(ogre.continueRendering()){
665 for (
int i=0 ; i < 4 ; i++)
668 md[i].
track(I, mcog[i]) ;
694 ogre.display(IC,cmo);
702 catch (Ogre::Exception& e)
704 std::cerr <<
"Exception:\n";
705 std::cerr << e.getFullDescription().c_str() <<
"\n";
710 std::cerr <<
"Exception: " <<
"\n";
716 #else // VISP_HAVE_OGRE && VISP_HAVE_DISPLAY
720 std::cout <<
"You should install Ogre3D to run this example..." << std::endl;