ViSP  2.8.0
vpAROgre.h
1 /****************************************************************************
2  *
3  * $Id: vpAROgre.h 4317 2013-07-17 09:40:17Z 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  *
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.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 = 0, unsigned int height = 0,
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 ~vpAROgre(void);
113 
124  inline void addResource(const std::string& resourceLocation){
125  mOptionnalResourceLocation.push_back(resourceLocation);
126  }
127 
128  void addRotation(const std::string &name, const vpRotationMatrix &wRo);
129 
130  bool continueRendering(void);
131 
132  virtual bool customframeStarted(const Ogre::FrameEvent& evt);
133 
134  virtual bool customframeEnded(const Ogre::FrameEvent& evt);
135 
136  virtual void display(const vpImage<unsigned char> &I,
137  const vpHomogeneousMatrix &cMw);
138 
139  virtual void display(const vpImage<vpRGBa> &I,
140  const vpHomogeneousMatrix &cMw);
141 
142  inline Ogre::Camera* getCamera(){ return mCamera; }
143 
144  vpTranslationVector getPosition(const std::string &name)const;
145 
146  void getRenderingOutput(vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo);
147 
148  inline Ogre::SceneManager* getSceneManager(){ return mSceneMgr; }
149 
150  virtual void init(vpImage<unsigned char> &I, bool bufferedKeys=false, bool hidden=false);
151  virtual void init(vpImage<vpRGBa> &I, bool bufferedKeys=false, bool hidden=false);
152 
158  bool isWindowHidden(){ return windowHidden; }
159 
160 #ifdef VISP_HAVE_OIS
161 
164  virtual bool keyPressed( const OIS::KeyEvent & /*e*/) { return true; }
168  virtual bool keyReleased( const OIS::KeyEvent & /*e*/) { return true; }
169 #endif
170 
171  void load(const std::string &name, const std::string &model);
172 
173  bool renderOneFrame(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMw);
174 
175  bool renderOneFrame(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMw);
176 
177  void setCameraParameters(const vpCameraParameters &cameraP);
178 
188  inline void setPluginsPath(const char* pluginsPath){
189  mPluginsPath = pluginsPath;
190  }
191 
192  void setPosition(const std::string &name,
193  const vpTranslationVector &wTo);
194  void setPosition(const std::string &name, const vpHomogeneousMatrix &wMo);
195 
205  inline void setResourcePath(const char* resourcePath){
206  mResourcePath = resourcePath;
207  }
208 
209  void setRotation(const std::string &name, const vpRotationMatrix &wRo);
210 
211  void setScale(const std::string &name, const float factorx, const float factory, const float factorz);
212 
221  inline void setShowConfigDialog(const bool showConfigDialog){
222  mshowConfigDialog = showConfigDialog;
223  }
224 
225  void setVisibility(const std::string &name, bool isVisible);
226 
234  inline void setWindowName(const Ogre::String &n){
235  name = n;
236  }
237 
249  inline void setWindowPosition(const unsigned int win_x, const unsigned int win_y){
250  if(mWindow == NULL){
251  throw vpException(vpException::notInitialized, "Window not initialised, cannot set its position");
252  }
253  mWindow->reposition(static_cast<int>(win_x), static_cast<int>(win_y));
254  }
255 
256  virtual void windowClosed(Ogre::RenderWindow* rw);
257 
258  protected:
259 
260  virtual void init(bool bufferedKeys=false, bool hidden=false);
261  virtual void createCamera(void);
262 
267  virtual void createScene(void){};
268 
269  virtual void closeOIS(void);
270 
276  virtual bool updateScene(const Ogre::FrameEvent & /*evt*/) {return true;};
277 
283  virtual bool processInputEvent(const Ogre::FrameEvent & /*evt*/) {return true;};
284 
290  virtual bool destroyScene(void) {return true;};
291 
292  virtual void updateCameraParameters (const vpHomogeneousMatrix &cMo);
293 
294  virtual void updateCameraProjection(void);
295 
296  virtual void updateBackgroundTexture(const vpImage<unsigned char> &I);
297 
298  virtual void updateBackgroundTexture(const vpImage<vpRGBa> &I);
299 
300 
301  private:
302 
303  void createBackground(vpImage<unsigned char> &I);
304  void createBackground(vpImage<vpRGBa> &I);
305 
306  bool frameStarted(const Ogre::FrameEvent& evt);
307 
308  bool frameEnded( const Ogre::FrameEvent& evt);
309 
310  bool stopTest(const Ogre::FrameEvent& evt);
311 
312  protected:
313  // Attributes
314  Ogre::String name;
316  // OGRE 3D System
317  Ogre::Root* mRoot;
318  Ogre::Camera* mCamera;
319  Ogre::SceneManager* mSceneMgr;
320  Ogre::RenderWindow* mWindow;
321  Ogre::String mResourcePath;
322  Ogre::String mPluginsPath;
324 #ifdef VISP_HAVE_OIS
325  // OIS Input manager and devices
326  OIS::InputManager* mInputManager;
327  OIS::Keyboard* mKeyboard;
328 #endif
329 
330  // ViSP AR System
331  bool keepOn;
334  Ogre::HardwarePixelBufferSharedPtr mPixelBuffer;
335  Ogre::Rectangle2D* mBackground;
336  unsigned int mBackgroundHeight;
337  unsigned int mBackgroundWidth;
338  unsigned int mWindowHeight;
339  unsigned int mWindowWidth;
342  // Camera calculations
347  std::list<std::string> mOptionnalResourceLocation;
349 };
350 
351 #endif // VISP_HAVE_OGRE
352 
353 #endif
void setWindowName(const Ogre::String &n)
Definition: vpAROgre.h:234
bool keepOn
Definition: vpAROgre.h:331
bool mshowConfigDialog
Definition: vpAROgre.h:345
void setPluginsPath(const char *pluginsPath)
Definition: vpAROgre.h:188
Ogre::String name
Definition: vpAROgre.h:314
unsigned int mWindowWidth
Definition: vpAROgre.h:339
Ogre::String mPluginsPath
Definition: vpAROgre.h:322
unsigned int mBackgroundWidth
Definition: vpAROgre.h:337
Ogre::Camera * getCamera()
Definition: vpAROgre.h:142
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:221
virtual bool destroyScene(void)
Definition: vpAROgre.h:290
Ogre::String mResourcePath
Definition: vpAROgre.h:321
error that can be emited by ViSP classes.
Definition: vpException.h:75
OIS::Keyboard * mKeyboard
Definition: vpAROgre.h:327
Implementation of an augmented reality viewer.
Definition: vpAROgre.h:90
Ogre::SceneManager * getSceneManager()
Definition: vpAROgre.h:148
vpImage< vpRGBa > mImageRGBA
Definition: vpAROgre.h:332
Ogre::RenderWindow * mWindow
Definition: vpAROgre.h:320
OIS::InputManager * mInputManager
Definition: vpAROgre.h:326
The vpRotationMatrix considers the particular case of a rotation matrix.
vpImage< unsigned char > mImage
Definition: vpAROgre.h:333
virtual bool keyPressed(const OIS::KeyEvent &)
Definition: vpAROgre.h:164
void setWindowPosition(const unsigned int win_x, const unsigned int win_y)
Definition: vpAROgre.h:249
vpCameraParameters mcam
Definition: vpAROgre.h:343
virtual bool processInputEvent(const Ogre::FrameEvent &)
Definition: vpAROgre.h:283
Ogre::Camera * mCamera
Definition: vpAROgre.h:318
Generic class defining intrinsic camera parameters.
virtual bool updateScene(const Ogre::FrameEvent &)
Definition: vpAROgre.h:276
unsigned int mWindowHeight
Definition: vpAROgre.h:338
void setResourcePath(const char *resourcePath)
Definition: vpAROgre.h:205
bool windowHidden
Definition: vpAROgre.h:340
unsigned int mBackgroundHeight
Definition: vpAROgre.h:336
Ogre::Root * mRoot
Definition: vpAROgre.h:317
Ogre::HardwarePixelBufferSharedPtr mPixelBuffer
Definition: vpAROgre.h:334
Ogre::Rectangle2D * mBackground
Definition: vpAROgre.h:335
virtual void createScene(void)
Definition: vpAROgre.h:267
Ogre::SceneManager * mSceneMgr
Definition: vpAROgre.h:319
bool isWindowHidden()
Definition: vpAROgre.h:158
void addResource(const std::string &resourceLocation)
Definition: vpAROgre.h:124
std::list< std::string > mOptionnalResourceLocation
Definition: vpAROgre.h:347
virtual bool keyReleased(const OIS::KeyEvent &)
Definition: vpAROgre.h:168
Class that consider the case of a translation vector.