Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpAROgre.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 https://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
42
43#ifndef VP_AR_OGRE_H
44#define VP_AR_OGRE_H
45
46#include <visp3/core/vpConfig.h>
47
48#ifdef VISP_HAVE_OGRE
49#include <list>
50
51#include <visp3/core/vpImage.h>
52#include <visp3/core/vpImageConvert.h>
53#include <visp3/core/vpRGBa.h>
54
55#include <visp3/core/vpHomogeneousMatrix.h>
56#include <visp3/core/vpImageTools.h>
57#include <visp3/core/vpRotationMatrix.h>
58#include <visp3/core/vpRxyzVector.h>
59
60#include <Ogre.h>
61#include <OgreFrameListener.h>
62
63#if (VISP_HAVE_OGRE_VERSION >= (1<<16 | 10 <<8 | 0))
64#include <Bites/OgreBitesConfigDialog.h>
65#endif
66
67#if (VISP_HAVE_OGRE_VERSION >= (1<<16 | 11<<8 | 0))
68#include <Bites/OgreWindowEventUtilities.h>
69#endif
70
71#if (VISP_HAVE_OGRE_VERSION >= (1<<16 | 12 <<8 | 0))
72#include <OgreComponents.h>
73#elif (VISP_HAVE_OGRE_VERSION >= (1<<16 | 10 <<8 | 0))
74#include <OgreBuildSettings.h>
75#endif
76
77#if defined(OGRE_BUILD_COMPONENT_RTSHADERSYSTEM) & (VISP_HAVE_OGRE_VERSION >= (1<<16 | 10 <<8 | 0))
78#include <RTShaderSystem/OgreShaderGenerator.h>
79#include <Bites/OgreSGTechniqueResolverListener.h>
80#endif // INCLUDE_RTSHADER_SYSTEM
81
82#ifdef VISP_HAVE_OIS
83#include <ois/OIS.h>
84#endif
85
111class VISP_EXPORT vpAROgre : public Ogre::FrameListener,
112#if (VISP_HAVE_OGRE_VERSION >= (1<<16 | 11 <<8 | 0))
113 public OgreBites::WindowEventListener
114#else
115 public Ogre::WindowEventListener
116#endif
117#ifdef VISP_HAVE_OIS
118 ,
119 public OIS::KeyListener
120#endif
121{
122public:
123 vpAROgre(const vpCameraParameters &cam = vpCameraParameters(), unsigned int width = 0, unsigned int height = 0,
124 const char *resourcePath =
125#ifdef VISP_HAVE_OGRE_RESOURCES_PATH
126 VISP_HAVE_OGRE_RESOURCES_PATH,
127#else
128 ".",
129#endif
130 const char *pluginsPath =
131#ifdef VISP_HAVE_OGRE_PLUGINS_PATH
132 VISP_HAVE_OGRE_PLUGINS_PATH
133#else
134 "."
135#endif
136 );
137
138 virtual ~vpAROgre(void);
139
151 inline void addResource(const std::string &resourceLocation)
152 {
153 mOptionalResourceLocation.push_back(resourceLocation);
154 }
155
156 void addRotation(const std::string &sceneName, const vpRotationMatrix &wRo);
157
158 bool continueRendering(void);
159
160 virtual bool customframeStarted(const Ogre::FrameEvent &evt);
161
162 virtual bool customframeEnded(const Ogre::FrameEvent &evt);
163
164 virtual void display(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMw);
165
166 virtual void display(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMw);
167
168 inline Ogre::Camera *getCamera() { return mCamera; }
169
175 inline double getFarClippingDistance() const { return mFarClipping; }
176
182 inline double getNearClippingDistance() const { return mNearClipping; }
183
184 vpTranslationVector getPosition(const std::string &sceneName) const;
185
186 void getRenderingOutput(vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo);
187
188 inline Ogre::SceneManager *getSceneManager() { return mSceneMgr; }
189
190 virtual void init(vpImage<unsigned char> &I, bool bufferedKeys = false, bool hidden = false);
191 virtual void init(vpImage<vpRGBa> &I, bool bufferedKeys = false, bool hidden = false);
192
198 bool isWindowHidden() { return windowHidden; }
199
200#ifdef VISP_HAVE_OIS
204 virtual bool keyPressed(const OIS::KeyEvent & /*e*/) { return true; }
208 virtual bool keyReleased(const OIS::KeyEvent & /*e*/) { return true; }
209#endif
210
211 void load(const std::string &entityName, const std::string &model);
212
213 bool renderOneFrame(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMw);
214
215 bool renderOneFrame(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMw);
216
217 void setCameraParameters(const vpCameraParameters &cameraP);
218
224 void setFarClippingDistance(const double &dist)
225 {
226 mFarClipping = dist;
228 }
229
230 void setMaterial(const std::string &entityName, const std::string &materialName);
231
237 void setNearClippingDistance(const double &dist)
238 {
239 mNearClipping = dist;
241 }
242
254 inline void setPluginsPath(const char *pluginsPath) { mPluginsPath = pluginsPath; }
255
256 void setPosition(const std::string &sceneName, const vpTranslationVector &wTo);
257 void setPosition(const std::string &sceneName, const vpHomogeneousMatrix &wMo);
258
270 inline void setResourcePath(const char *resourcePath) { mResourcePath = resourcePath; }
271
272 void setRotation(const std::string &sceneName, const vpRotationMatrix &wRo);
273
274 void setScale(const std::string &sceneName, float factorx, float factory, float factorz);
275
285 inline void setShowConfigDialog(bool showConfigDialog) { mshowConfigDialog = showConfigDialog; }
286
287 void setVisibility(const std::string &sceneName, bool isVisible);
288
296 inline void setWindowName(const Ogre::String &n) { name = n; }
297
308 inline void setWindowPosition(unsigned int win_x, unsigned int win_y)
309 {
310 if (mWindow == nullptr) {
311 throw vpException(vpException::notInitialized, "Window not initialised, cannot set its position");
312 }
313 mWindow->reposition(static_cast<int>(win_x), static_cast<int>(win_y));
314 }
315
316 virtual bool windowClosing(Ogre::RenderWindow *rw) VP_OVERRIDE;
317
318 virtual void windowClosed(Ogre::RenderWindow *rw) VP_OVERRIDE;
319
320protected:
321 virtual void init(bool bufferedKeys = false, bool hidden = false);
322 virtual void createCamera(void);
323
328 virtual void createScene(void) { }
329
330 virtual void closeOIS(void);
331
337 virtual bool updateScene(const Ogre::FrameEvent & /*evt*/) { return true; }
338
344 virtual bool processInputEvent(const Ogre::FrameEvent & /*evt*/) { return true; }
345
351 virtual bool destroyScene(void)
352 {
353 if (!mSceneMgr) {
354 return false;
355 }
356
357 mSceneMgr->destroyAllCameras();
358 mSceneMgr->clearScene();
359 mRoot->destroySceneManager(mSceneMgr);
360 return true;
361 }
362
363 virtual void updateCameraParameters(const vpHomogeneousMatrix &cMo);
364
365 virtual void updateCameraProjection(void);
366
367 virtual void updateBackgroundTexture(const vpImage<unsigned char> &I);
368
369 virtual void updateBackgroundTexture(const vpImage<vpRGBa> &I);
370
371private:
372 void createBackground(vpImage<unsigned char> &I);
373 void createBackground(vpImage<vpRGBa> &I);
374
375 bool frameStarted(const Ogre::FrameEvent &evt) VP_OVERRIDE;
376
377 bool frameEnded(const Ogre::FrameEvent &evt) VP_OVERRIDE;
378
379 bool stopTest(const Ogre::FrameEvent &evt);
380
381 bool initialiseRTShaderSystem();
382
383 void destroyRTShaderSystem();
384
385protected:
386 static unsigned int sID;
387 static unsigned int sRTSSUsers;
388 // Attributes
389 Ogre::String name;
391
392 // OGRE 3D System
393 Ogre::Root *mRoot;
394 Ogre::Camera *mCamera;
395 Ogre::String mSceneManagerName;
396 Ogre::SceneManager *mSceneMgr;
397 Ogre::RenderWindow *mWindow;
398 Ogre::String mResourcePath;
399 Ogre::String mPluginsPath;
400
401#ifdef VISP_HAVE_OIS
402 // OIS Input manager and devices
403 OIS::InputManager *mInputManager;
404 OIS::Keyboard *mKeyboard;
405#endif
406
407#if defined(OGRE_BUILD_COMPONENT_RTSHADERSYSTEM) & (VISP_HAVE_OGRE_VERSION >= (1<<16 | 10 <<8 | 0))
408 Ogre::RTShader::ShaderGenerator *mShaderGenerator; // The Shader generator instance.
409 OgreBites::SGTechniqueResolverListener *mMaterialMgrListener; // Shader generator material manager listener.
410#endif // INCLUDE_RTSHADER_SYSTEM
411
412 // ViSP AR System
413 bool keepOn;
417 Ogre::HardwarePixelBufferSharedPtr mPixelBuffer;
418 Ogre::Rectangle2D *mBackground;
419 unsigned int mBackgroundHeight;
420 unsigned int mBackgroundWidth;
421 unsigned int mWindowHeight;
422 unsigned int mWindowWidth;
424
425 // Camera calculations
429
432
433 std::list<std::string> mOptionalResourceLocation;
435};
436END_VISP_NAMESPACE
437#endif // VISP_HAVE_OGRE
438
439#endif
OIS::InputManager * mInputManager
Definition vpAROgre.h:403
double getNearClippingDistance() const
Definition vpAROgre.h:182
Ogre::SceneManager * getSceneManager()
Definition vpAROgre.h:188
virtual bool updateScene(const Ogre::FrameEvent &)
Definition vpAROgre.h:337
OIS::Keyboard * mKeyboard
Definition vpAROgre.h:404
bool keepOn
Definition vpAROgre.h:413
void setWindowName(const Ogre::String &n)
Definition vpAROgre.h:296
virtual bool processInputEvent(const Ogre::FrameEvent &)
Definition vpAROgre.h:344
virtual bool keyReleased(const OIS::KeyEvent &)
Definition vpAROgre.h:208
unsigned int mBackgroundWidth
Definition vpAROgre.h:420
void setShowConfigDialog(bool showConfigDialog)
Definition vpAROgre.h:285
vpImage< vpRGBa > mImageRGBA
Definition vpAROgre.h:415
vpCameraParameters mcam
Definition vpAROgre.h:428
vpImage< unsigned char > mImage
Definition vpAROgre.h:416
vpAROgre(const vpCameraParameters &cam=vpCameraParameters(), unsigned int width=0, unsigned int height=0, const char *resourcePath=VISP_HAVE_OGRE_RESOURCES_PATH, const char *pluginsPath=VISP_HAVE_OGRE_PLUGINS_PATH)
Definition vpAROgre.cpp:80
bool windowHidden
Definition vpAROgre.h:423
void setFarClippingDistance(const double &dist)
Definition vpAROgre.h:224
Ogre::Camera * getCamera()
Definition vpAROgre.h:168
void setNearClippingDistance(const double &dist)
Definition vpAROgre.h:237
double mNearClipping
Definition vpAROgre.h:426
Ogre::Root * mRoot
Definition vpAROgre.h:393
Ogre::String name
Definition vpAROgre.h:389
Ogre::String mSceneManagerName
Definition vpAROgre.h:395
virtual bool keyPressed(const OIS::KeyEvent &)
Definition vpAROgre.h:204
void setWindowPosition(unsigned int win_x, unsigned int win_y)
Definition vpAROgre.h:308
virtual bool destroyScene(void)
Definition vpAROgre.h:351
virtual void updateCameraProjection(void)
Ogre::Camera * mCamera
Definition vpAROgre.h:394
static unsigned int sRTSSUsers
Definition vpAROgre.h:387
bool isWindowHidden()
Definition vpAROgre.h:198
unsigned int mBackgroundHeight
Definition vpAROgre.h:419
bool mInitialized
Definition vpAROgre.h:390
void addResource(const std::string &resourceLocation)
Definition vpAROgre.h:151
Ogre::String mPluginsPath
Definition vpAROgre.h:399
Ogre::Rectangle2D * mBackground
Definition vpAROgre.h:418
double mFarClipping
Definition vpAROgre.h:427
virtual void createScene(void)
Definition vpAROgre.h:328
unsigned int mWindowHeight
Definition vpAROgre.h:421
void setPluginsPath(const char *pluginsPath)
Definition vpAROgre.h:254
double getFarClippingDistance() const
Definition vpAROgre.h:175
std::list< std::string > mOptionalResourceLocation
Definition vpAROgre.h:433
Ogre::SceneManager * mSceneMgr
Definition vpAROgre.h:396
Ogre::HardwarePixelBufferSharedPtr mPixelBuffer
Definition vpAROgre.h:417
bool mshowConfigDialog
Definition vpAROgre.h:430
static unsigned int sID
Definition vpAROgre.h:386
Ogre::String mResourcePath
Definition vpAROgre.h:398
Ogre::RenderWindow * mWindow
Definition vpAROgre.h:397
void setResourcePath(const char *resourcePath)
Definition vpAROgre.h:270
unsigned int mWindowWidth
Definition vpAROgre.h:422
Generic class defining intrinsic camera parameters.
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ notInitialized
Used to indicate that a parameter is not initialized.
Definition vpException.h:74
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition of the vpImage class member functions.
Definition vpImage.h:131
Implementation of a rotation matrix and operations on such kind of matrices.
Class that consider the case of a translation vector.