Visual Servoing Platform  version 3.5.0 under development (2022-02-15)
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, float factorx, float factory, float factorz);
248 
258  inline void setShowConfigDialog(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(unsigned int win_x, 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 
328  mSceneMgr->destroyAllCameras();
329  mSceneMgr->clearScene();
330  mRoot->destroySceneManager(mSceneMgr);
331  return true;
332  }
333 
334  virtual void updateCameraParameters(const vpHomogeneousMatrix &cMo);
335 
336  virtual void updateCameraProjection(void);
337 
338  virtual void updateBackgroundTexture(const vpImage<unsigned char> &I);
339 
340  virtual void updateBackgroundTexture(const vpImage<vpRGBa> &I);
341 
342 private:
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;
375  Ogre::HardwarePixelBufferSharedPtr mPixelBuffer;
376  Ogre::Rectangle2D *mBackground;
377  unsigned int mBackgroundHeight;
378  unsigned int mBackgroundWidth;
379  unsigned int mWindowHeight;
380  unsigned int mWindowWidth;
383  // Camera calculations
384  double mNearClipping;
385  double mFarClipping;
391  std::list<std::string> mOptionnalResourceLocation;
393 };
394 
395 #endif // VISP_HAVE_OGRE
396 
397 #endif
void setWindowName(const Ogre::String &n)
Definition: vpAROgre.h:269
bool keepOn
Definition: vpAROgre.h:371
bool mshowConfigDialog
Definition: vpAROgre.h:388
void setPluginsPath(const char *pluginsPath)
Definition: vpAROgre.h:227
Ogre::String name
Definition: vpAROgre.h:354
unsigned int mWindowWidth
Definition: vpAROgre.h:380
Ogre::String mPluginsPath
Definition: vpAROgre.h:362
void setNearClippingDistance(const double &dist)
Definition: vpAROgre.h:210
unsigned int mBackgroundWidth
Definition: vpAROgre.h:378
Ogre::Camera * getCamera()
Definition: vpAROgre.h:143
Implementation of an homogeneous matrix and operations on such kind of matrices.
void setWindowPosition(unsigned int win_x, unsigned int win_y)
Definition: vpAROgre.h:281
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:71
OIS::Keyboard * mKeyboard
Definition: vpAROgre.h:367
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
vpImage< vpRGBa > mImageRGBA
Definition: vpAROgre.h:373
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:374
virtual bool keyPressed(const OIS::KeyEvent &)
Definition: vpAROgre.h:179
vpCameraParameters mcam
Definition: vpAROgre.h:386
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:379
void setResourcePath(const char *resourcePath)
Definition: vpAROgre.h:243
bool windowHidden
Definition: vpAROgre.h:381
void setShowConfigDialog(bool showConfigDialog)
Definition: vpAROgre.h:258
unsigned int mBackgroundHeight
Definition: vpAROgre.h:377
Ogre::Root * mRoot
Definition: vpAROgre.h:357
double mFarClipping
Definition: vpAROgre.h:385
Ogre::HardwarePixelBufferSharedPtr mPixelBuffer
Definition: vpAROgre.h:375
double getNearClippingDistance() const
Definition: vpAROgre.h:157
Ogre::Rectangle2D * mBackground
Definition: vpAROgre.h:376
virtual void createScene(void)
Definition: vpAROgre.h:299
Ogre::SceneManager * mSceneMgr
Definition: vpAROgre.h:359
double getFarClippingDistance() const
Definition: vpAROgre.h:150
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:384
std::list< std::string > mOptionnalResourceLocation
Definition: vpAROgre.h:391
virtual bool keyReleased(const OIS::KeyEvent &)
Definition: vpAROgre.h:183
Class that consider the case of a translation vector.