Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpAROgre.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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 
89 class VISP_EXPORT vpAROgre : public Ogre::FrameListener, public Ogre::WindowEventListener
90 #ifdef VISP_HAVE_OIS
91  , public OIS::KeyListener
92 #endif
93 {
94  public:
96  unsigned int width = 0, unsigned int height = 0,
97  const char* resourcePath =
98 #ifdef VISP_HAVE_OGRE_RESOURCES_PATH
99  VISP_HAVE_OGRE_RESOURCES_PATH,
100 #else
101  ".",
102 #endif
103  const char* pluginsPath =
104 #ifdef VISP_HAVE_OGRE_PLUGINS_PATH
105  VISP_HAVE_OGRE_PLUGINS_PATH
106 #else
107  "."
108 #endif
109  );
110 
111  virtual ~vpAROgre(void);
112 
123  inline void addResource(const std::string& resourceLocation){
124  mOptionnalResourceLocation.push_back(resourceLocation);
125  }
126 
127  void addRotation(const std::string &sceneName, const vpRotationMatrix &wRo);
128 
129  bool continueRendering(void);
130 
131  virtual bool customframeStarted(const Ogre::FrameEvent& evt);
132 
133  virtual bool customframeEnded(const Ogre::FrameEvent& evt);
134 
135  virtual void display(const vpImage<unsigned char> &I,
136  const vpHomogeneousMatrix &cMw);
137 
138  virtual void display(const vpImage<vpRGBa> &I,
139  const vpHomogeneousMatrix &cMw);
140 
141  inline Ogre::Camera* getCamera(){ return mCamera; }
142 
148  inline double getFarClippingDistance() const { return mFarClipping; }
149 
155  inline double getNearClippingDistance() const { return mNearClipping; }
156 
157  vpTranslationVector getPosition(const std::string &sceneName)const;
158 
159  void getRenderingOutput(vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo);
160 
161  inline Ogre::SceneManager* getSceneManager(){ return mSceneMgr; }
162 
163  virtual void init(vpImage<unsigned char> &I, bool bufferedKeys=false, bool hidden=false);
164  virtual void init(vpImage<vpRGBa> &I, bool bufferedKeys=false, bool hidden=false);
165 
171  bool isWindowHidden(){ return windowHidden; }
172 
173 #ifdef VISP_HAVE_OIS
174 
177  virtual bool keyPressed( const OIS::KeyEvent & /*e*/) { return true; }
181  virtual bool keyReleased( const OIS::KeyEvent & /*e*/) { return true; }
182 #endif
183 
184  void load(const std::string &entityName, const std::string &model);
185 
186  bool renderOneFrame(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMw);
187 
188  bool renderOneFrame(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMw);
189 
190  void setCameraParameters(const vpCameraParameters &cameraP);
191 
197  void setFarClippingDistance(const double &dist){
198  mFarClipping = dist;
199  updateCameraProjection();
200  }
201 
207  void setNearClippingDistance(const double &dist){
208  mNearClipping = dist;
209  updateCameraProjection();
210  }
211 
221  inline void setPluginsPath(const char* pluginsPath){
222  mPluginsPath = pluginsPath;
223  }
224 
225  void setPosition(const std::string &sceneName, const vpTranslationVector &wTo);
226  void setPosition(const std::string &sceneName, const vpHomogeneousMatrix &wMo);
227 
237  inline void setResourcePath(const char* resourcePath){
238  mResourcePath = resourcePath;
239  }
240 
241  void setRotation(const std::string &sceneName, const vpRotationMatrix &wRo);
242 
243  void setScale(const std::string &sceneName, const float factorx, const float factory, const float factorz);
244 
253  inline void setShowConfigDialog(const bool showConfigDialog){
254  mshowConfigDialog = showConfigDialog;
255  }
256 
257  void setVisibility(const std::string &sceneName, bool isVisible);
258 
266  inline void setWindowName(const Ogre::String &n){
267  name = n;
268  }
269 
281  inline void setWindowPosition(const unsigned int win_x, const unsigned int win_y){
282  if(mWindow == NULL){
283  throw vpException(vpException::notInitialized, "Window not initialised, cannot set its position");
284  }
285  mWindow->reposition(static_cast<int>(win_x), static_cast<int>(win_y));
286  }
287 
288  virtual void windowClosed(Ogre::RenderWindow* rw);
289 
290  protected:
291 
292  virtual void init(bool bufferedKeys=false, bool hidden=false);
293  virtual void createCamera(void);
294 
299  virtual void createScene(void){};
300 
301  virtual void closeOIS(void);
302 
308  virtual bool updateScene(const Ogre::FrameEvent & /*evt*/) {return true;};
309 
315  virtual bool processInputEvent(const Ogre::FrameEvent & /*evt*/) {return true;};
316 
322  virtual bool destroyScene(void) {
323  if(!mSceneMgr)
324  return false;
325 
326  mSceneMgr->destroyAllCameras ();
327  mSceneMgr->clearScene();
328  mRoot->destroySceneManager(mSceneMgr);
329  return true;
330  }
331 
332  virtual void updateCameraParameters (const vpHomogeneousMatrix &cMo);
333 
334  virtual void updateCameraProjection(void);
335 
336  virtual void updateBackgroundTexture(const vpImage<unsigned char> &I);
337 
338  virtual void updateBackgroundTexture(const vpImage<vpRGBa> &I);
339 
340 
341  private:
342 
343  void createBackground(vpImage<unsigned char> &I);
344  void createBackground(vpImage<vpRGBa> &I);
345 
346  bool frameStarted(const Ogre::FrameEvent& evt);
347 
348  bool frameEnded( const Ogre::FrameEvent& evt);
349 
350  bool stopTest(const Ogre::FrameEvent& evt);
351 
352  protected:
353  // Attributes
354  Ogre::String name;
356  // OGRE 3D System
357  Ogre::Root* mRoot;
358  Ogre::Camera* mCamera;
359  Ogre::SceneManager* mSceneMgr;
360  Ogre::RenderWindow* mWindow;
361  Ogre::String mResourcePath;
362  Ogre::String mPluginsPath;
364 #ifdef VISP_HAVE_OIS
365  // OIS Input manager and devices
366  OIS::InputManager* mInputManager;
367  OIS::Keyboard* mKeyboard;
368 #endif
369 
370  // ViSP AR System
371  bool keepOn;
374  Ogre::HardwarePixelBufferSharedPtr mPixelBuffer;
375  Ogre::Rectangle2D* mBackground;
376  unsigned int mBackgroundHeight;
377  unsigned int mBackgroundWidth;
378  unsigned int mWindowHeight;
379  unsigned int mWindowWidth;
382  // Camera calculations
383  double mNearClipping;
384  double mFarClipping;
389  std::list<std::string> mOptionnalResourceLocation;
391 };
392 
393 #endif // VISP_HAVE_OGRE
394 
395 #endif
void setWindowName(const Ogre::String &n)
Definition: vpAROgre.h:266
bool keepOn
Definition: vpAROgre.h:371
bool mshowConfigDialog
Definition: vpAROgre.h:387
void setPluginsPath(const char *pluginsPath)
Definition: vpAROgre.h:221
Ogre::String name
Definition: vpAROgre.h:354
unsigned int mWindowWidth
Definition: vpAROgre.h:379
Ogre::String mPluginsPath
Definition: vpAROgre.h:362
void setNearClippingDistance(const double &dist)
Definition: vpAROgre.h:207
unsigned int mBackgroundWidth
Definition: vpAROgre.h:377
Ogre::Camera * getCamera()
Definition: vpAROgre.h:141
Implementation of an homogeneous matrix and operations on such kind of matrices.
void setShowConfigDialog(const bool showConfigDialog)
Definition: vpAROgre.h:253
virtual bool destroyScene(void)
Definition: vpAROgre.h:322
Ogre::String mResourcePath
Definition: vpAROgre.h:361
error that can be emited by ViSP classes.
Definition: vpException.h:73
OIS::Keyboard * mKeyboard
Definition: vpAROgre.h:367
Implementation of an augmented reality viewer using Ogre3D 3rd party.
Definition: vpAROgre.h:89
Ogre::SceneManager * getSceneManager()
Definition: vpAROgre.h:161
void setFarClippingDistance(const double &dist)
Definition: vpAROgre.h:197
double getNearClippingDistance() const
Definition: vpAROgre.h:155
vpImage< vpRGBa > mImageRGBA
Definition: vpAROgre.h:372
Ogre::RenderWindow * mWindow
Definition: vpAROgre.h:360
OIS::InputManager * mInputManager
Definition: vpAROgre.h:366
Implementation of a rotation matrix and operations on such kind of matrices.
vpImage< unsigned char > mImage
Definition: vpAROgre.h:373
virtual bool keyPressed(const OIS::KeyEvent &)
Definition: vpAROgre.h:177
void setWindowPosition(const unsigned int win_x, const unsigned int win_y)
Definition: vpAROgre.h:281
vpCameraParameters mcam
Definition: vpAROgre.h:385
virtual bool processInputEvent(const Ogre::FrameEvent &)
Definition: vpAROgre.h:315
Ogre::Camera * mCamera
Definition: vpAROgre.h:358
Generic class defining intrinsic camera parameters.
virtual bool updateScene(const Ogre::FrameEvent &)
Definition: vpAROgre.h:308
unsigned int mWindowHeight
Definition: vpAROgre.h:378
void setResourcePath(const char *resourcePath)
Definition: vpAROgre.h:237
double getFarClippingDistance() const
Definition: vpAROgre.h:148
bool windowHidden
Definition: vpAROgre.h:380
unsigned int mBackgroundHeight
Definition: vpAROgre.h:376
Ogre::Root * mRoot
Definition: vpAROgre.h:357
double mFarClipping
Definition: vpAROgre.h:384
Ogre::HardwarePixelBufferSharedPtr mPixelBuffer
Definition: vpAROgre.h:374
Ogre::Rectangle2D * mBackground
Definition: vpAROgre.h:375
virtual void createScene(void)
Definition: vpAROgre.h:299
Ogre::SceneManager * mSceneMgr
Definition: vpAROgre.h:359
bool isWindowHidden()
Definition: vpAROgre.h:171
void addResource(const std::string &resourceLocation)
Definition: vpAROgre.h:123
double mNearClipping
Definition: vpAROgre.h:383
std::list< std::string > mOptionnalResourceLocation
Definition: vpAROgre.h:389
virtual bool keyReleased(const OIS::KeyEvent &)
Definition: vpAROgre.h:181
Class that consider the case of a translation vector.