ViSP  2.6.2
HelloWorldOgreAdvanced.cpp
1 /****************************************************************************
2  *
3  * $Id: HelloWorldOgreAdvanced.cpp 3619 2012-03-09 17:28:57Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2012 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 <visp/vpOpenCVGrabber.h>
48 #include <visp/vpV4l2Grabber.h>
49 #include <visp/vp1394TwoGrabber.h>
50 #include <visp/vpDirectShowGrabber.h>
51 #include <visp/vpHomogeneousMatrix.h>
52 #include <visp/vpImage.h>
53 #include <visp/vpCameraParameters.h>
54 #include <visp/vpAROgre.h>
55 
56 #if defined(VISP_HAVE_OGRE)
57 
58 #ifndef DOXYGEN_SHOULD_SKIP_THIS
59 
60 class vpAROgreAdvanced : public vpAROgre
61 {
62 private:
63  // Animation attribute
64  Ogre::AnimationState * mAnimationState;
65 
66 public:
67  vpAROgreAdvanced(const vpCameraParameters &cam = vpCameraParameters(),
68  unsigned int width = 640, unsigned int height = 480)
69  : vpAROgre(cam, width, height)
70  {
71  }
72 
73 protected:
74  void createScene()
75  {
76  // Create the Entity
77  Ogre::Entity* robot = mSceneMgr->createEntity("Robot", "robot.mesh");
78  // Attach robot to scene graph
79  Ogre::SceneNode* RobotNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("Robot");
80  RobotNode->setPosition(0.0, 0.05f, 0.5);
81  RobotNode->attachObject(robot);
82  RobotNode->scale(0.001f,0.001f,0.001f);
83  RobotNode->pitch(Ogre::Degree(180));
84  RobotNode->yaw(Ogre::Degree(-90));
85 
86  // The animation
87  // Set the good animation
88  mAnimationState = robot->getAnimationState( "Idle" );
89  // Start over when finished
90  mAnimationState->setLoop( true );
91  // Animation enabled
92  mAnimationState->setEnabled( true );
93  }
94 
95  bool customframeEnded( const Ogre::FrameEvent& evt)
96  {
97  // Update animation
98  // To move, we add it the time since last frame
99  mAnimationState->addTime( evt.timeSinceLastFrame );
100  return true;
101  }
102 };// End of vpAROgreAdvanced class definition
103 #endif
104 
105 #endif
106 
107 int main()
108 {
109 #if defined(VISP_HAVE_OGRE)
110 
111  // Now we try to find an available framegrabber
112 #if defined(VISP_HAVE_V4L2)
113  // Video for linux 2 grabber
114  vpV4l2Grabber grabber;
115 #elif defined(VISP_HAVE_DC1394_2)
116  // libdc1394-2
117  vp1394TwoGrabber grabber;
118 #elif defined(VISP_HAVE_DIRECTSHOW)
119  // OpenCV to gather images
120  vpOpenCVGrabber grabber;
121 #elif defined(VISP_HAVE_OPENCV)
122  // OpenCV to gather images
123  vpOpenCVGrabber grabber;
124 #else
125 # error "You need an available framegrabber to run this example"
126 #endif
127 
128  // Image to store gathered data
129  // Here we acquire a grey level image. The consequence will be that
130  // the background texture used in Ogre renderer will be also in grey
131  // level.
133  // Open frame grabber
134  // Here we acquire an image from an available framegrabber to update
135  // the image size
136  grabber.open(I);
137  // Parameters of our camera
138  double px = 565;
139  double py = 565;
140  double u0 = grabber.getWidth() / 2;
141  double v0 = grabber.getHeight() / 2;
142  vpCameraParameters cam(px,py,u0,v0);
143  // The matrix with our pose
145 
146  // Our object
147  vpAROgreAdvanced ogre(cam, (unsigned int)grabber.getWidth(), (unsigned int)grabber.getHeight());
148  // Initialisation
149  ogre.init(I);
150 
151  // Rendering loop
152  while(ogre.continueRendering()){
153  // Image Acquisition
154  grabber.acquire(I);
155  // Pose computation
156  // ...
157  // cMo updated
158  // Display with vpAROgre
159  ogre.display(I, cMo);
160  }
161  // Release video device
162  grabber.close();
163 #endif
164 }
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:442
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.
void setPosition(const vpRobot::vpControlFrameType, const vpColVector &)
Set a displacement (frame has to be specified) in position control.
Class for the Video4Linux2 video device.
virtual void createScene(void)
Definition: vpAROgre.h:264
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.