ViSP  2.8.0
HelloWorldOgreAdvanced.cpp
1 /****************************************************************************
2  *
3  * $Id: HelloWorldOgreAdvanced.cpp 4111 2013-02-06 17:27:14Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  * Description:
34  * Ogre example.
35  *
36  * Authors:
37  * Bertrand Delabarre
38  *
39  *****************************************************************************/
47 #include <iostream>
48 
49 #include <visp/vpOpenCVGrabber.h>
50 #include <visp/vpV4l2Grabber.h>
51 #include <visp/vp1394TwoGrabber.h>
52 #include <visp/vpDirectShowGrabber.h>
53 #include <visp/vpHomogeneousMatrix.h>
54 #include <visp/vpImage.h>
55 #include <visp/vpCameraParameters.h>
56 #include <visp/vpAROgre.h>
57 
58 #if defined(VISP_HAVE_OGRE)
59 
60 #ifndef DOXYGEN_SHOULD_SKIP_THIS
61 
62 class vpAROgreAdvanced : public vpAROgre
63 {
64 private:
65  // Animation attribute
66  Ogre::AnimationState * mAnimationState;
67 
68 public:
69  vpAROgreAdvanced(const vpCameraParameters &cam = vpCameraParameters(),
70  unsigned int width = 640, unsigned int height = 480)
71  : vpAROgre(cam, width, height)
72  {
73  }
74 
75 protected:
76  void createScene()
77  {
78  // Create the Entity
79  Ogre::Entity* robot = mSceneMgr->createEntity("Robot", "robot.mesh");
80  // Attach robot to scene graph
81  Ogre::SceneNode* RobotNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("Robot");
82  RobotNode->setPosition(0.0, 0.05f, 0.5);
83  RobotNode->attachObject(robot);
84  RobotNode->scale(0.001f,0.001f,0.001f);
85  RobotNode->pitch(Ogre::Degree(180));
86  RobotNode->yaw(Ogre::Degree(-90));
87 
88  // The animation
89  // Set the good animation
90  mAnimationState = robot->getAnimationState( "Idle" );
91  // Start over when finished
92  mAnimationState->setLoop( true );
93  // Animation enabled
94  mAnimationState->setEnabled( true );
95  }
96 
97  bool customframeEnded( const Ogre::FrameEvent& evt)
98  {
99  // Update animation
100  // To move, we add it the time since last frame
101  mAnimationState->addTime( evt.timeSinceLastFrame );
102  return true;
103  }
104 };// End of vpAROgreAdvanced class definition
105 #endif
106 
107 #endif
108 
109 int main()
110 {
111 #if defined(VISP_HAVE_OGRE)
112 #if defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394_2) || defined(VISP_HAVE_DIRECTSHOW) || defined(VISP_HAVE_OPENCV)
113 
114  // Now we try to find an available framegrabber
115 #if defined(VISP_HAVE_V4L2)
116  // Video for linux 2 grabber
117  vpV4l2Grabber grabber;
118 #elif defined(VISP_HAVE_DC1394_2)
119  // libdc1394-2
120  vp1394TwoGrabber grabber;
121 #elif defined(VISP_HAVE_DIRECTSHOW)
122  // OpenCV to gather images
123  vpOpenCVGrabber grabber;
124 #elif defined(VISP_HAVE_OPENCV)
125  // OpenCV to gather images
126  vpOpenCVGrabber grabber;
127 #endif
128 
129  // Image to store gathered data
130  // Here we acquire a grey level image. The consequence will be that
131  // the background texture used in Ogre renderer will be also in grey
132  // level.
134  // Open frame grabber
135  // Here we acquire an image from an available framegrabber to update
136  // the image size
137  grabber.open(I);
138  // Parameters of our camera
139  double px = 565;
140  double py = 565;
141  double u0 = grabber.getWidth() / 2;
142  double v0 = grabber.getHeight() / 2;
143  vpCameraParameters cam(px,py,u0,v0);
144  // The matrix with our pose
146 
147  // Our object
148  vpAROgreAdvanced ogre(cam, (unsigned int)grabber.getWidth(), (unsigned int)grabber.getHeight());
149  // Initialisation
150  ogre.init(I);
151 
152  // Rendering loop
153  while(ogre.continueRendering()){
154  // Image Acquisition
155  grabber.acquire(I);
156  // Pose computation
157  // ...
158  // cMo updated
159  // Display with vpAROgre
160  ogre.display(I, cMo);
161  }
162  // Release video device
163  grabber.close();
164 #else
165  std::cout << "You need an available framegrabber to run this example" << std::endl;
166 #endif
167 #else
168  std::cout << "You Ogre3D to run this example" << std::endl;
169 #endif
170 }
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
virtual bool customframeEnded(const Ogre::FrameEvent &evt)
Definition: vpAROgre.cpp:538
void setPosition(const vpHomogeneousMatrix &cMw)
Implementation of an augmented reality viewer.
Definition: vpAROgre.h:90
unsigned int getWidth() const
Return the number of columns in the image.
Generic class defining intrinsic camera parameters.
Class for the Video4Linux2 video device.
virtual void createScene(void)
Definition: vpAROgre.h:267
void init()
Basic initialisation (identity).
void acquire(vpImage< unsigned char > &I)
Class for firewire ieee1394 video devices using libdc1394-2.x api.
unsigned int getHeight() const
Return the number of rows in the image.
Class for cameras video capture using OpenCV library.