ViSP  2.10.0
vpAROgre.h
1 /****************************************************************************
2  *
3  * $Id: vpAROgre.h 4931 2014-10-09 14:02:52Z ayol $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 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 
149  inline double getFarClippingDistance() const { return mFarClipping; }
150 
156  inline double getNearClippingDistance() const { return mNearClipping; }
157 
158  vpTranslationVector getPosition(const std::string &name)const;
159 
160  void getRenderingOutput(vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo);
161 
162  inline Ogre::SceneManager* getSceneManager(){ return mSceneMgr; }
163 
164  virtual void init(vpImage<unsigned char> &I, bool bufferedKeys=false, bool hidden=false);
165  virtual void init(vpImage<vpRGBa> &I, bool bufferedKeys=false, bool hidden=false);
166 
172  bool isWindowHidden(){ return windowHidden; }
173 
174 #ifdef VISP_HAVE_OIS
175 
178  virtual bool keyPressed( const OIS::KeyEvent & /*e*/) { return true; }
182  virtual bool keyReleased( const OIS::KeyEvent & /*e*/) { return true; }
183 #endif
184 
185  void load(const std::string &name, const std::string &model);
186 
187  bool renderOneFrame(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMw);
188 
189  bool renderOneFrame(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMw);
190 
191  void setCameraParameters(const vpCameraParameters &cameraP);
192 
198  void setFarClippingDistance(const double &dist){
199  mFarClipping = dist;
200  updateCameraProjection();
201  }
202 
208  void setNearClippingDistance(const double &dist){
209  mNearClipping = dist;
210  updateCameraProjection();
211  }
212 
222  inline void setPluginsPath(const char* pluginsPath){
223  mPluginsPath = pluginsPath;
224  }
225 
226  void setPosition(const std::string &name,
227  const vpTranslationVector &wTo);
228  void setPosition(const std::string &name, const vpHomogeneousMatrix &wMo);
229 
239  inline void setResourcePath(const char* resourcePath){
240  mResourcePath = resourcePath;
241  }
242 
243  void setRotation(const std::string &name, const vpRotationMatrix &wRo);
244 
245  void setScale(const std::string &name, const float factorx, const float factory, const float factorz);
246 
255  inline void setShowConfigDialog(const bool showConfigDialog){
256  mshowConfigDialog = showConfigDialog;
257  }
258 
259  void setVisibility(const std::string &name, bool isVisible);
260 
268  inline void setWindowName(const Ogre::String &n){
269  name = n;
270  }
271 
283  inline void setWindowPosition(const unsigned int win_x, const unsigned int win_y){
284  if(mWindow == NULL){
285  throw vpException(vpException::notInitialized, "Window not initialised, cannot set its position");
286  }
287  mWindow->reposition(static_cast<int>(win_x), static_cast<int>(win_y));
288  }
289 
290  virtual void windowClosed(Ogre::RenderWindow* rw);
291 
292  protected:
293 
294  virtual void init(bool bufferedKeys=false, bool hidden=false);
295  virtual void createCamera(void);
296 
301  virtual void createScene(void){};
302 
303  virtual void closeOIS(void);
304 
310  virtual bool updateScene(const Ogre::FrameEvent & /*evt*/) {return true;};
311 
317  virtual bool processInputEvent(const Ogre::FrameEvent & /*evt*/) {return true;};
318 
324  virtual bool destroyScene(void) {
325  if(!mSceneMgr)
326  return false;
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 
343  private:
344 
345  void createBackground(vpImage<unsigned char> &I);
346  void createBackground(vpImage<vpRGBa> &I);
347 
348  bool frameStarted(const Ogre::FrameEvent& evt);
349 
350  bool frameEnded( const Ogre::FrameEvent& evt);
351 
352  bool stopTest(const Ogre::FrameEvent& evt);
353 
354  protected:
355  // Attributes
356  Ogre::String name;
358  // OGRE 3D System
359  Ogre::Root* mRoot;
360  Ogre::Camera* mCamera;
361  Ogre::SceneManager* mSceneMgr;
362  Ogre::RenderWindow* mWindow;
363  Ogre::String mResourcePath;
364  Ogre::String mPluginsPath;
366 #ifdef VISP_HAVE_OIS
367  // OIS Input manager and devices
368  OIS::InputManager* mInputManager;
369  OIS::Keyboard* mKeyboard;
370 #endif
371 
372  // ViSP AR System
373  bool keepOn;
376  Ogre::HardwarePixelBufferSharedPtr mPixelBuffer;
377  Ogre::Rectangle2D* mBackground;
378  unsigned int mBackgroundHeight;
379  unsigned int mBackgroundWidth;
380  unsigned int mWindowHeight;
381  unsigned int mWindowWidth;
384  // Camera calculations
385  double mNearClipping;
386  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:268
bool keepOn
Definition: vpAROgre.h:373
bool mshowConfigDialog
Definition: vpAROgre.h:389
void setPluginsPath(const char *pluginsPath)
Definition: vpAROgre.h:222
Ogre::String name
Definition: vpAROgre.h:356
unsigned int mWindowWidth
Definition: vpAROgre.h:381
Ogre::String mPluginsPath
Definition: vpAROgre.h:364
void setNearClippingDistance(const double &dist)
Definition: vpAROgre.h:208
unsigned int mBackgroundWidth
Definition: vpAROgre.h:379
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:255
virtual bool destroyScene(void)
Definition: vpAROgre.h:324
Ogre::String mResourcePath
Definition: vpAROgre.h:363
error that can be emited by ViSP classes.
Definition: vpException.h:76
OIS::Keyboard * mKeyboard
Definition: vpAROgre.h:369
Implementation of an augmented reality viewer.
Definition: vpAROgre.h:90
Ogre::SceneManager * getSceneManager()
Definition: vpAROgre.h:162
void setFarClippingDistance(const double &dist)
Definition: vpAROgre.h:198
double getNearClippingDistance() const
Definition: vpAROgre.h:156
vpImage< vpRGBa > mImageRGBA
Definition: vpAROgre.h:374
Ogre::RenderWindow * mWindow
Definition: vpAROgre.h:362
OIS::InputManager * mInputManager
Definition: vpAROgre.h:368
The vpRotationMatrix considers the particular case of a rotation matrix.
vpImage< unsigned char > mImage
Definition: vpAROgre.h:375
virtual bool keyPressed(const OIS::KeyEvent &)
Definition: vpAROgre.h:178
void setWindowPosition(const unsigned int win_x, const unsigned int win_y)
Definition: vpAROgre.h:283
vpCameraParameters mcam
Definition: vpAROgre.h:387
virtual bool processInputEvent(const Ogre::FrameEvent &)
Definition: vpAROgre.h:317
Ogre::Camera * mCamera
Definition: vpAROgre.h:360
Generic class defining intrinsic camera parameters.
virtual bool updateScene(const Ogre::FrameEvent &)
Definition: vpAROgre.h:310
unsigned int mWindowHeight
Definition: vpAROgre.h:380
void setResourcePath(const char *resourcePath)
Definition: vpAROgre.h:239
double getFarClippingDistance() const
Definition: vpAROgre.h:149
bool windowHidden
Definition: vpAROgre.h:382
unsigned int mBackgroundHeight
Definition: vpAROgre.h:378
Ogre::Root * mRoot
Definition: vpAROgre.h:359
double mFarClipping
Definition: vpAROgre.h:386
Ogre::HardwarePixelBufferSharedPtr mPixelBuffer
Definition: vpAROgre.h:376
Ogre::Rectangle2D * mBackground
Definition: vpAROgre.h:377
virtual void createScene(void)
Definition: vpAROgre.h:301
Ogre::SceneManager * mSceneMgr
Definition: vpAROgre.h:361
bool isWindowHidden()
Definition: vpAROgre.h:172
void addResource(const std::string &resourceLocation)
Definition: vpAROgre.h:124
double mNearClipping
Definition: vpAROgre.h:385
std::list< std::string > mOptionnalResourceLocation
Definition: vpAROgre.h:391
virtual bool keyReleased(const OIS::KeyEvent &)
Definition: vpAROgre.h:182
Class that consider the case of a translation vector.