Visual Servoing Platform  version 3.0.0
vpAROgre.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Augmented Reality viewer using Ogre3D.
32  *
33  * Authors:
34  * Bertrand Delabarre
35  *
36  *****************************************************************************/
37 
48 #ifndef __VP_AROGRE__
49 #define __VP_AROGRE__
50 
51 #include <visp3/core/vpConfig.h>
52 
53 #ifdef VISP_HAVE_OGRE
54 #include <list>
55 
56 #include <visp3/core/vpImage.h>
57 #include <visp3/core/vpImageConvert.h>
58 #include <visp3/core/vpRGBa.h>
59 
60 #include <visp3/core/vpImageTools.h>
61 #include <visp3/core/vpHomogeneousMatrix.h>
62 #include <visp3/core/vpRotationMatrix.h>
63 #include <visp3/core/vpRxyzVector.h>
64 
65 #include <Ogre.h>
66 #include <OgreFrameListener.h>
67 
68 #ifdef VISP_HAVE_OIS
69 # include <OIS.h>
70 #endif
71 
86 class VISP_EXPORT vpAROgre : public Ogre::FrameListener, public Ogre::WindowEventListener
87 #ifdef VISP_HAVE_OIS
88  , public OIS::KeyListener
89 #endif
90 {
91  public:
93  unsigned int width = 0, unsigned int height = 0,
94  const char* resourcePath =
95 #ifdef VISP_HAVE_OGRE_RESOURCES_PATH
96  VISP_HAVE_OGRE_RESOURCES_PATH,
97 #else
98  ".",
99 #endif
100  const char* pluginsPath =
101 #ifdef VISP_HAVE_OGRE_PLUGINS_PATH
102  VISP_HAVE_OGRE_PLUGINS_PATH
103 #else
104  "."
105 #endif
106  );
107 
108  virtual ~vpAROgre(void);
109 
120  inline void addResource(const std::string& resourceLocation){
121  mOptionnalResourceLocation.push_back(resourceLocation);
122  }
123 
124  void addRotation(const std::string &sceneName, const vpRotationMatrix &wRo);
125 
126  bool continueRendering(void);
127 
128  virtual bool customframeStarted(const Ogre::FrameEvent& evt);
129 
130  virtual bool customframeEnded(const Ogre::FrameEvent& evt);
131 
132  virtual void display(const vpImage<unsigned char> &I,
133  const vpHomogeneousMatrix &cMw);
134 
135  virtual void display(const vpImage<vpRGBa> &I,
136  const vpHomogeneousMatrix &cMw);
137 
138  inline Ogre::Camera* getCamera(){ return mCamera; }
139 
145  inline double getFarClippingDistance() const { return mFarClipping; }
146 
152  inline double getNearClippingDistance() const { return mNearClipping; }
153 
154  vpTranslationVector getPosition(const std::string &sceneName)const;
155 
156  void getRenderingOutput(vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo);
157 
158  inline Ogre::SceneManager* getSceneManager(){ return mSceneMgr; }
159 
160  virtual void init(vpImage<unsigned char> &I, bool bufferedKeys=false, bool hidden=false);
161  virtual void init(vpImage<vpRGBa> &I, bool bufferedKeys=false, bool hidden=false);
162 
168  bool isWindowHidden(){ return windowHidden; }
169 
170 #ifdef VISP_HAVE_OIS
171 
174  virtual bool keyPressed( const OIS::KeyEvent & /*e*/) { return true; }
178  virtual bool keyReleased( const OIS::KeyEvent & /*e*/) { return true; }
179 #endif
180 
181  void load(const std::string &entityName, const std::string &model);
182 
183  bool renderOneFrame(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMw);
184 
185  bool renderOneFrame(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMw);
186 
187  void setCameraParameters(const vpCameraParameters &cameraP);
188 
194  void setFarClippingDistance(const double &dist){
195  mFarClipping = dist;
196  updateCameraProjection();
197  }
198 
204  void setNearClippingDistance(const double &dist){
205  mNearClipping = dist;
206  updateCameraProjection();
207  }
208 
218  inline void setPluginsPath(const char* pluginsPath){
219  mPluginsPath = pluginsPath;
220  }
221 
222  void setPosition(const std::string &sceneName, const vpTranslationVector &wTo);
223  void setPosition(const std::string &sceneName, const vpHomogeneousMatrix &wMo);
224 
234  inline void setResourcePath(const char* resourcePath){
235  mResourcePath = resourcePath;
236  }
237 
238  void setRotation(const std::string &sceneName, const vpRotationMatrix &wRo);
239 
240  void setScale(const std::string &sceneName, const float factorx, const float factory, const float factorz);
241 
250  inline void setShowConfigDialog(const bool showConfigDialog){
251  mshowConfigDialog = showConfigDialog;
252  }
253 
254  void setVisibility(const std::string &sceneName, bool isVisible);
255 
263  inline void setWindowName(const Ogre::String &n){
264  name = n;
265  }
266 
278  inline void setWindowPosition(const unsigned int win_x, const unsigned int win_y){
279  if(mWindow == NULL){
280  throw vpException(vpException::notInitialized, "Window not initialised, cannot set its position");
281  }
282  mWindow->reposition(static_cast<int>(win_x), static_cast<int>(win_y));
283  }
284 
285  virtual void windowClosed(Ogre::RenderWindow* rw);
286 
287  protected:
288 
289  virtual void init(bool bufferedKeys=false, bool hidden=false);
290  virtual void createCamera(void);
291 
296  virtual void createScene(void){};
297 
298  virtual void closeOIS(void);
299 
305  virtual bool updateScene(const Ogre::FrameEvent & /*evt*/) {return true;};
306 
312  virtual bool processInputEvent(const Ogre::FrameEvent & /*evt*/) {return true;};
313 
319  virtual bool destroyScene(void) {
320  if(!mSceneMgr)
321  return false;
322 
323  mSceneMgr->destroyAllCameras ();
324  mSceneMgr->clearScene();
325  mRoot->destroySceneManager(mSceneMgr);
326  return true;
327  }
328 
329  virtual void updateCameraParameters (const vpHomogeneousMatrix &cMo);
330 
331  virtual void updateCameraProjection(void);
332 
333  virtual void updateBackgroundTexture(const vpImage<unsigned char> &I);
334 
335  virtual void updateBackgroundTexture(const vpImage<vpRGBa> &I);
336 
337 
338  private:
339 
340  void createBackground(vpImage<unsigned char> &I);
341  void createBackground(vpImage<vpRGBa> &I);
342 
343  bool frameStarted(const Ogre::FrameEvent& evt);
344 
345  bool frameEnded( const Ogre::FrameEvent& evt);
346 
347  bool stopTest(const Ogre::FrameEvent& evt);
348 
349  protected:
350  // Attributes
351  Ogre::String name;
353  // OGRE 3D System
354  Ogre::Root* mRoot;
355  Ogre::Camera* mCamera;
356  Ogre::SceneManager* mSceneMgr;
357  Ogre::RenderWindow* mWindow;
358  Ogre::String mResourcePath;
359  Ogre::String mPluginsPath;
361 #ifdef VISP_HAVE_OIS
362  // OIS Input manager and devices
363  OIS::InputManager* mInputManager;
364  OIS::Keyboard* mKeyboard;
365 #endif
366 
367  // ViSP AR System
368  bool keepOn;
371  Ogre::HardwarePixelBufferSharedPtr mPixelBuffer;
372  Ogre::Rectangle2D* mBackground;
373  unsigned int mBackgroundHeight;
374  unsigned int mBackgroundWidth;
375  unsigned int mWindowHeight;
376  unsigned int mWindowWidth;
379  // Camera calculations
380  double mNearClipping;
381  double mFarClipping;
386  std::list<std::string> mOptionnalResourceLocation;
388 };
389 
390 #endif // VISP_HAVE_OGRE
391 
392 #endif
void setWindowName(const Ogre::String &n)
Definition: vpAROgre.h:263
bool keepOn
Definition: vpAROgre.h:368
bool mshowConfigDialog
Definition: vpAROgre.h:384
void setPluginsPath(const char *pluginsPath)
Definition: vpAROgre.h:218
Ogre::String name
Definition: vpAROgre.h:351
unsigned int mWindowWidth
Definition: vpAROgre.h:376
Ogre::String mPluginsPath
Definition: vpAROgre.h:359
void setNearClippingDistance(const double &dist)
Definition: vpAROgre.h:204
unsigned int mBackgroundWidth
Definition: vpAROgre.h:374
Ogre::Camera * getCamera()
Definition: vpAROgre.h:138
Implementation of an homogeneous matrix and operations on such kind of matrices.
void setShowConfigDialog(const bool showConfigDialog)
Definition: vpAROgre.h:250
virtual bool destroyScene(void)
Definition: vpAROgre.h:319
Ogre::String mResourcePath
Definition: vpAROgre.h:358
error that can be emited by ViSP classes.
Definition: vpException.h:73
OIS::Keyboard * mKeyboard
Definition: vpAROgre.h:364
Implementation of an augmented reality viewer.
Definition: vpAROgre.h:86
Ogre::SceneManager * getSceneManager()
Definition: vpAROgre.h:158
void setFarClippingDistance(const double &dist)
Definition: vpAROgre.h:194
double getNearClippingDistance() const
Definition: vpAROgre.h:152
vpImage< vpRGBa > mImageRGBA
Definition: vpAROgre.h:369
Ogre::RenderWindow * mWindow
Definition: vpAROgre.h:357
OIS::InputManager * mInputManager
Definition: vpAROgre.h:363
Implementation of a rotation matrix and operations on such kind of matrices.
vpImage< unsigned char > mImage
Definition: vpAROgre.h:370
virtual bool keyPressed(const OIS::KeyEvent &)
Definition: vpAROgre.h:174
void setWindowPosition(const unsigned int win_x, const unsigned int win_y)
Definition: vpAROgre.h:278
vpCameraParameters mcam
Definition: vpAROgre.h:382
virtual bool processInputEvent(const Ogre::FrameEvent &)
Definition: vpAROgre.h:312
Ogre::Camera * mCamera
Definition: vpAROgre.h:355
Generic class defining intrinsic camera parameters.
virtual bool updateScene(const Ogre::FrameEvent &)
Definition: vpAROgre.h:305
unsigned int mWindowHeight
Definition: vpAROgre.h:375
void setResourcePath(const char *resourcePath)
Definition: vpAROgre.h:234
double getFarClippingDistance() const
Definition: vpAROgre.h:145
bool windowHidden
Definition: vpAROgre.h:377
unsigned int mBackgroundHeight
Definition: vpAROgre.h:373
Ogre::Root * mRoot
Definition: vpAROgre.h:354
double mFarClipping
Definition: vpAROgre.h:381
Ogre::HardwarePixelBufferSharedPtr mPixelBuffer
Definition: vpAROgre.h:371
Ogre::Rectangle2D * mBackground
Definition: vpAROgre.h:372
virtual void createScene(void)
Definition: vpAROgre.h:296
Ogre::SceneManager * mSceneMgr
Definition: vpAROgre.h:356
bool isWindowHidden()
Definition: vpAROgre.h:168
void addResource(const std::string &resourceLocation)
Definition: vpAROgre.h:120
double mNearClipping
Definition: vpAROgre.h:380
std::list< std::string > mOptionnalResourceLocation
Definition: vpAROgre.h:386
virtual bool keyReleased(const OIS::KeyEvent &)
Definition: vpAROgre.h:178
Class that consider the case of a translation vector.