Visual Servoing Platform  version 3.2.1 under development (2019-05-20)
vpAROgre.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Augmented Reality viewer using Ogre3D.
33  *
34  * Authors:
35  * Bertrand Delabarre
36  *
37  *****************************************************************************/
38 
49 #ifndef _vpAROgre_h_
50 #define _vpAROgre_h_
51 
52 #include <visp3/core/vpConfig.h>
53 
54 #ifdef VISP_HAVE_OGRE
55 #include <list>
56 
57 #include <visp3/core/vpImage.h>
58 #include <visp3/core/vpImageConvert.h>
59 #include <visp3/core/vpRGBa.h>
60 
61 #include <visp3/core/vpHomogeneousMatrix.h>
62 #include <visp3/core/vpImageTools.h>
63 #include <visp3/core/vpRotationMatrix.h>
64 #include <visp3/core/vpRxyzVector.h>
65 
66 #include <Ogre.h>
67 #include <OgreFrameListener.h>
68 
69 #ifdef VISP_HAVE_OIS
70 #include <OIS.h>
71 #endif
72 
90 class VISP_EXPORT vpAROgre : public Ogre::FrameListener,
91  public Ogre::WindowEventListener
92 #ifdef VISP_HAVE_OIS
93  ,
94  public OIS::KeyListener
95 #endif
96 {
97 public:
98  vpAROgre(const vpCameraParameters &cam = vpCameraParameters(), unsigned int width = 0, unsigned int height = 0,
99  const char *resourcePath =
100 #ifdef VISP_HAVE_OGRE_RESOURCES_PATH
101  VISP_HAVE_OGRE_RESOURCES_PATH,
102 #else
103  ".",
104 #endif
105  const char *pluginsPath =
106 #ifdef VISP_HAVE_OGRE_PLUGINS_PATH
107  VISP_HAVE_OGRE_PLUGINS_PATH
108 #else
109  "."
110 #endif
111  );
112 
113  virtual ~vpAROgre(void);
114 
126  inline void addResource(const std::string &resourceLocation)
127  {
128  mOptionnalResourceLocation.push_back(resourceLocation);
129  }
130 
131  void addRotation(const std::string &sceneName, const vpRotationMatrix &wRo);
132 
133  bool continueRendering(void);
134 
135  virtual bool customframeStarted(const Ogre::FrameEvent &evt);
136 
137  virtual bool customframeEnded(const Ogre::FrameEvent &evt);
138 
139  virtual void display(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMw);
140 
141  virtual void display(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMw);
142 
143  inline Ogre::Camera *getCamera() { return mCamera; }
144 
150  inline double getFarClippingDistance() const { return mFarClipping; }
151 
157  inline double getNearClippingDistance() const { return mNearClipping; }
158 
159  vpTranslationVector getPosition(const std::string &sceneName) const;
160 
161  void getRenderingOutput(vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo);
162 
163  inline Ogre::SceneManager *getSceneManager() { return mSceneMgr; }
164 
165  virtual void init(vpImage<unsigned char> &I, bool bufferedKeys = false, bool hidden = false);
166  virtual void init(vpImage<vpRGBa> &I, bool bufferedKeys = false, bool hidden = false);
167 
173  bool isWindowHidden() { return windowHidden; }
174 
175 #ifdef VISP_HAVE_OIS
176 
179  virtual bool keyPressed(const OIS::KeyEvent & /*e*/) { return true; }
183  virtual bool keyReleased(const OIS::KeyEvent & /*e*/) { return true; }
184 #endif
185 
186  void load(const std::string &entityName, const std::string &model);
187 
188  bool renderOneFrame(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMw);
189 
190  bool renderOneFrame(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMw);
191 
192  void setCameraParameters(const vpCameraParameters &cameraP);
193 
199  void setFarClippingDistance(const double &dist)
200  {
201  mFarClipping = dist;
202  updateCameraProjection();
203  }
204 
210  void setNearClippingDistance(const double &dist)
211  {
212  mNearClipping = dist;
213  updateCameraProjection();
214  }
215 
227  inline void setPluginsPath(const char *pluginsPath) { mPluginsPath = pluginsPath; }
228 
229  void setPosition(const std::string &sceneName, const vpTranslationVector &wTo);
230  void setPosition(const std::string &sceneName, const vpHomogeneousMatrix &wMo);
231 
243  inline void setResourcePath(const char *resourcePath) { mResourcePath = resourcePath; }
244 
245  void setRotation(const std::string &sceneName, const vpRotationMatrix &wRo);
246 
247  void setScale(const std::string &sceneName, const float factorx, const float factory, const float factorz);
248 
258  inline void setShowConfigDialog(const bool showConfigDialog) { mshowConfigDialog = showConfigDialog; }
259 
260  void setVisibility(const std::string &sceneName, bool isVisible);
261 
269  inline void setWindowName(const Ogre::String &n) { name = n; }
270 
281  inline void setWindowPosition(const unsigned int win_x, const unsigned int win_y)
282  {
283  if (mWindow == NULL) {
284  throw vpException(vpException::notInitialized, "Window not initialised, cannot set its position");
285  }
286  mWindow->reposition(static_cast<int>(win_x), static_cast<int>(win_y));
287  }
288 
289  virtual void windowClosed(Ogre::RenderWindow *rw);
290 
291 protected:
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  {
324  if (!mSceneMgr)
325  return false;
326 
327  mSceneMgr->destroyAllCameras();
328  mSceneMgr->clearScene();
329  mRoot->destroySceneManager(mSceneMgr);
330  return true;
331  }
332 
333  virtual void updateCameraParameters(const vpHomogeneousMatrix &cMo);
334 
335  virtual void updateCameraProjection(void);
336 
337  virtual void updateBackgroundTexture(const vpImage<unsigned char> &I);
338 
339  virtual void updateBackgroundTexture(const vpImage<vpRGBa> &I);
340 
341 private:
342  void createBackground(vpImage<unsigned char> &I);
343  void createBackground(vpImage<vpRGBa> &I);
344 
345  bool frameStarted(const Ogre::FrameEvent &evt);
346 
347  bool frameEnded(const Ogre::FrameEvent &evt);
348 
349  bool stopTest(const Ogre::FrameEvent &evt);
350 
351 protected:
352  // Attributes
353  Ogre::String name;
355  // OGRE 3D System
356  Ogre::Root *mRoot;
357  Ogre::Camera *mCamera;
358  Ogre::SceneManager *mSceneMgr;
359  Ogre::RenderWindow *mWindow;
360  Ogre::String mResourcePath;
361  Ogre::String mPluginsPath;
363 #ifdef VISP_HAVE_OIS
364  // OIS Input manager and devices
365  OIS::InputManager *mInputManager;
366  OIS::Keyboard *mKeyboard;
367 #endif
368 
369  // ViSP AR System
370  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;
390  std::list<std::string> mOptionnalResourceLocation;
392 };
393 
394 #endif // VISP_HAVE_OGRE
395 
396 #endif
void setWindowName(const Ogre::String &n)
Definition: vpAROgre.h:269
bool keepOn
Definition: vpAROgre.h:370
bool mshowConfigDialog
Definition: vpAROgre.h:387
void setPluginsPath(const char *pluginsPath)
Definition: vpAROgre.h:227
Ogre::String name
Definition: vpAROgre.h:353
unsigned int mWindowWidth
Definition: vpAROgre.h:379
Ogre::String mPluginsPath
Definition: vpAROgre.h:361
void setNearClippingDistance(const double &dist)
Definition: vpAROgre.h:210
unsigned int mBackgroundWidth
Definition: vpAROgre.h:377
Ogre::Camera * getCamera()
Definition: vpAROgre.h:143
Implementation of an homogeneous matrix and operations on such kind of matrices.
void setShowConfigDialog(const bool showConfigDialog)
Definition: vpAROgre.h:258
virtual bool destroyScene(void)
Definition: vpAROgre.h:322
Ogre::String mResourcePath
Definition: vpAROgre.h:360
error that can be emited by ViSP classes.
Definition: vpException.h:71
OIS::Keyboard * mKeyboard
Definition: vpAROgre.h:366
Implementation of an augmented reality viewer using Ogre3D 3rd party.
Definition: vpAROgre.h:90
Ogre::SceneManager * getSceneManager()
Definition: vpAROgre.h:163
void setFarClippingDistance(const double &dist)
Definition: vpAROgre.h:199
double getNearClippingDistance() const
Definition: vpAROgre.h:157
vpImage< vpRGBa > mImageRGBA
Definition: vpAROgre.h:372
Ogre::RenderWindow * mWindow
Definition: vpAROgre.h:359
OIS::InputManager * mInputManager
Definition: vpAROgre.h:365
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:179
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:357
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:243
double getFarClippingDistance() const
Definition: vpAROgre.h:150
bool windowHidden
Definition: vpAROgre.h:380
unsigned int mBackgroundHeight
Definition: vpAROgre.h:376
Ogre::Root * mRoot
Definition: vpAROgre.h:356
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:358
Used to indicate that a parameter is not initialized.
Definition: vpException.h:98
bool isWindowHidden()
Definition: vpAROgre.h:173
void addResource(const std::string &resourceLocation)
Definition: vpAROgre.h:126
double mNearClipping
Definition: vpAROgre.h:383
std::list< std::string > mOptionnalResourceLocation
Definition: vpAROgre.h:390
virtual bool keyReleased(const OIS::KeyEvent &)
Definition: vpAROgre.h:183
Class that consider the case of a translation vector.