ViSP  2.6.2
vpAROgre.h
1 /****************************************************************************
2  *
3  * $Id: vpAROgre.h 3677 2012-04-06 13:17:57Z bdelabar $
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  *
34  * Description:
35  * Augmented Reality viewer using Ogre3D.
36  *
37  * Authors:
38  * Bertrand Delabarre
39  *
40  *****************************************************************************/
41 
52 #ifndef __VP_AROGRE__
53 #define __VP_AROGRE__
54 
55 #include <visp/vpConfig.h>
56 
57 #ifdef VISP_HAVE_OGRE
58 #include <list>
59 
60 #include <visp/vpImage.h>
61 #include <visp/vpImageConvert.h>
62 #include <visp/vpRGBa.h>
63 
64 #include <visp/vpImageTools.h>
65 #include <visp/vpHomogeneousMatrix.h>
66 #include <visp/vpRotationMatrix.h>
67 #include <visp/vpRxyzVector.h>
68 
69 #include <Ogre.h>
70 #include <OgreFrameListener.h>
71 
72 #ifdef VISP_HAVE_OIS
73 # include <OIS/OIS.h>
74 #endif
75 
90 class VISP_EXPORT vpAROgre : public Ogre::FrameListener, public Ogre::WindowEventListener
91 #ifdef VISP_HAVE_OIS
92  , public OIS::KeyListener
93 #endif
94 {
95  public:
97  unsigned int width = 640, unsigned int height = 480,
98  const char* resourcePath =
99 #ifdef VISP_HAVE_OGRE_RESOURCES_PATH
100  VISP_HAVE_OGRE_RESOURCES_PATH,
101 #else
102  ".",
103 #endif
104  const char* pluginsPath =
105 #ifdef VISP_HAVE_OGRE_PLUGINS_PATH
106  VISP_HAVE_OGRE_PLUGINS_PATH
107 #else
108  "."
109 #endif
110  );
111 
112  virtual void init(vpImage<unsigned char> &I, bool bufferedKeys=false);
113  virtual void init(vpImage<vpRGBa> &I, bool bufferedKeys=false);
114 
115  virtual ~vpAROgre(void);
116 
117  virtual bool customframeStarted(const Ogre::FrameEvent& evt);
118 
119  virtual bool customframeEnded(const Ogre::FrameEvent& evt);
120 
121 #ifdef VISP_HAVE_OIS
122 
125  virtual bool keyPressed( const OIS::KeyEvent & /*e*/) { return true; }
129  virtual bool keyReleased( const OIS::KeyEvent & /*e*/) { return true; }
130 #endif
131 
132  virtual void windowClosed(Ogre::RenderWindow* rw);
133 
134  virtual void display(const vpImage<unsigned char> &I,
135  const vpHomogeneousMatrix &cMw);
136 
137  virtual void display(const vpImage<vpRGBa> &I,
138  const vpHomogeneousMatrix &cMw);
139 
140  void setCameraParameters(const vpCameraParameters &cameraP);
141 
142  void load(const std::string &name, const std::string &model);
143 
144  void setPosition(const std::string &name,
145  const vpTranslationVector &wTo);
146  void setPosition(const std::string &name, const vpHomogeneousMatrix &wMo);
147 
148  vpTranslationVector getPosition(const std::string &name)const;
149 
150  void setRotation(const std::string &name, const vpRotationMatrix &wRo);
151 
152  void addRotation(const std::string &name, const vpRotationMatrix &wRo);
153 
154 
155  void setVisibility(const std::string &name, bool isVisible);
156 
157  void setScale(const std::string &name, const float factorx, const float factory, const float factorz);
158 
159  bool continueRendering(void);
160 
161  void getRenderingOutput(vpImage<vpRGBa> &I, vpHomogeneousMatrix &cMo);
169  inline void setImageWidth(const unsigned int width){
170  mWidth =width;
171  }
172 
180  inline void setImageHeight(const unsigned int height){
181  mHeight = height;
182  }
183 
192  inline void setShowConfigDialog(const bool showConfigDialog){
193  mshowConfigDialog = showConfigDialog;
194  }
195 
205  inline void setResourcePath(const char* resourcePath){
206  mResourcePath = resourcePath;
207  }
208 
218  inline void setPluginsPath(const char* pluginsPath){
219  mPluginsPath = pluginsPath;
220  }
221 
222 
233  inline void addResource(const std::string& resourceLocation){
234  mOptionnalResourceLocation.push_back(resourceLocation);
235  }
236 
248  inline void setWindowPosition(const unsigned int win_x, const unsigned int win_y){
249  if(mWindow == NULL){
250  throw vpException(vpException::notInitialized, "Window not initialised, cannot set its position");
251  }
252  mWindow->reposition(static_cast<int>(win_x), static_cast<int>(win_y));
253  }
254 
255  protected:
256 
257  virtual void init(bool bufferedKeys=false);
258  virtual void createCamera(void);
259 
264  virtual void createScene(void){};
265 
266  virtual void closeOIS(void);
267 
273  virtual bool updateScene(const Ogre::FrameEvent & /*evt*/) {return true;};
274 
280  virtual bool processInputEvent(const Ogre::FrameEvent & /*evt*/) {return true;};
281 
287  virtual bool destroyScene(void) {return true;};
288 
289  virtual void updateCameraProjection(void);
290 
291  virtual void updateBackgroundTexture(const vpImage<unsigned char> &I);
292 
293  virtual void updateBackgroundTexture(const vpImage<vpRGBa> &I);
294 
295  virtual void updateCameraParameters (const vpHomogeneousMatrix &cMo);
296 
297  private:
298 
299  void createBackground(vpImage<unsigned char> &I);
300  void createBackground(vpImage<vpRGBa> &I);
301 
302  bool frameStarted(const Ogre::FrameEvent& evt);
303 
304  bool frameEnded( const Ogre::FrameEvent& evt);
305 
306  bool stopTest(const Ogre::FrameEvent& evt);
307 
308  protected:
309  // Attributes
310 
311  // OGRE 3D System
312  Ogre::Root* mRoot;
313  Ogre::Camera* mCamera;
314  Ogre::SceneManager* mSceneMgr;
315  Ogre::RenderWindow* mWindow;
316  Ogre::String mResourcePath;
317  Ogre::String mPluginsPath;
319 #ifdef VISP_HAVE_OIS
320  // OIS Input manager and devices
321  OIS::InputManager* mInputManager;
322  OIS::Keyboard* mKeyboard;
323 #endif
324 
325  // ViSP AR System
326  bool keepOn;
329  Ogre::HardwarePixelBufferSharedPtr mPixelBuffer;
330  Ogre::Rectangle2D* mBackground;
331  unsigned int mHeight;
332  unsigned int mWidth;
334  // Camera calculations
339  std::list<std::string> mOptionnalResourceLocation;
341 };
342 
343 #endif // VISP_HAVE_OGRE
344 
345 #endif
bool keepOn
Definition: vpAROgre.h:326
bool mshowConfigDialog
Definition: vpAROgre.h:337
void setPluginsPath(const char *pluginsPath)
Definition: vpAROgre.h:218
Ogre::String mPluginsPath
Definition: vpAROgre.h:317
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
void setShowConfigDialog(const bool showConfigDialog)
Definition: vpAROgre.h:192
virtual bool destroyScene(void)
Definition: vpAROgre.h:287
Ogre::String mResourcePath
Definition: vpAROgre.h:316
OIS::Keyboard * mKeyboard
Definition: vpAROgre.h:322
Implementation of an augmented reality viewer.
Definition: vpAROgre.h:90
vpImage< vpRGBa > mImageRGBA
Definition: vpAROgre.h:327
Ogre::RenderWindow * mWindow
Definition: vpAROgre.h:315
OIS::InputManager * mInputManager
Definition: vpAROgre.h:321
The vpRotationMatrix considers the particular case of a rotation matrix.
vpImage< unsigned char > mImage
Definition: vpAROgre.h:328
virtual bool keyPressed(const OIS::KeyEvent &)
Definition: vpAROgre.h:125
void setImageWidth(const unsigned int width)
Definition: vpAROgre.h:169
void setWindowPosition(const unsigned int win_x, const unsigned int win_y)
Definition: vpAROgre.h:248
vpCameraParameters mcam
Definition: vpAROgre.h:335
virtual bool processInputEvent(const Ogre::FrameEvent &)
Definition: vpAROgre.h:280
void setImageHeight(const unsigned int height)
Definition: vpAROgre.h:180
Ogre::Camera * mCamera
Definition: vpAROgre.h:313
Generic class defining intrinsic camera parameters.
virtual bool updateScene(const Ogre::FrameEvent &)
Definition: vpAROgre.h:273
void setResourcePath(const char *resourcePath)
Definition: vpAROgre.h:205
Ogre::Root * mRoot
Definition: vpAROgre.h:312
unsigned int mHeight
Definition: vpAROgre.h:331
Ogre::HardwarePixelBufferSharedPtr mPixelBuffer
Definition: vpAROgre.h:329
Ogre::Rectangle2D * mBackground
Definition: vpAROgre.h:330
virtual void createScene(void)
Definition: vpAROgre.h:264
Ogre::SceneManager * mSceneMgr
Definition: vpAROgre.h:314
void addResource(const std::string &resourceLocation)
Definition: vpAROgre.h:233
unsigned int mWidth
Definition: vpAROgre.h:332
std::list< std::string > mOptionnalResourceLocation
Definition: vpAROgre.h:339
virtual bool keyReleased(const OIS::KeyEvent &)
Definition: vpAROgre.h:129
Class that consider the case of a translation vector.