qt_ogre_render_window.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 #ifndef QT_OGRE_RENDER_WINDOW_OGRE_RENDER_WINDOW_H_
30 #define QT_OGRE_RENDER_WINDOW_OGRE_RENDER_WINDOW_H_
31 
32 #include <boost/function.hpp>
33 
34 #include "render_widget.h"
35 
36 #include <OgreColourValue.h>
37 #include <OgreRenderTargetListener.h>
38 
39 namespace Ogre
40 {
41 class Root;
42 class RenderWindow;
43 class Viewport;
44 class Camera;
45 } // namespace Ogre
46 
47 namespace rviz
48 {
54 class QtOgreRenderWindow : public RenderWidget, public Ogre::RenderTargetListener
55 {
56 public:
60  QtOgreRenderWindow(QWidget* parent = nullptr);
61 
63  ~QtOgreRenderWindow() override;
64 
69  virtual void setPreRenderCallback(boost::function<void()> func);
74  virtual void setPostRenderCallback(boost::function<void()> func);
75 
80  QSize sizeHint() const override
81  {
82  return QSize(320, 240);
83  }
84 
91  Ogre::Viewport* getViewport() const;
92 
95  void setCamera(Ogre::Camera* camera);
96 
97  Ogre::Camera* getCamera() const
98  {
99  return camera_;
100  }
101 
106  void setOrthoScale(float scale);
107 
112  bool enableStereo(bool enable);
113 
115  void setupStereo();
116 
117  void setAutoRender(bool auto_render)
118  {
119  auto_render_ = auto_render;
120  }
121 
124  void setOverlaysEnabled(bool overlays_enabled);
125  void setBackgroundColor(Ogre::ColourValue color);
126 
127 protected:
128  void paintEvent(QPaintEvent* e) override;
129  void resizeEvent(QResizeEvent* event) override;
130 
131  // When stereo is enabled, these are called before/after rendering each
132  // viewport.
133  void preViewportUpdate(const Ogre::RenderTargetViewportEvent& evt) override;
134  void postViewportUpdate(const Ogre::RenderTargetViewportEvent& evt) override;
135 
139  void setCameraAspectRatio();
140 
145  void prepareStereoViewport(Ogre::Viewport*);
146 
147 
148  Ogre::Viewport* viewport_;
149 
150  Ogre::Root* ogre_root_;
151 
152  boost::function<void()> pre_render_callback_;
153  boost::function<void()> post_render_callback_;
154 
157 
158  Ogre::Camera* camera_;
160  Ogre::ColourValue background_color_;
161 
162  // stereo rendering
163  bool stereo_enabled_; // true if we were asked to render stereo
164  bool rendering_stereo_; // true if we are actually rendering stereo
165  Ogre::Camera* left_camera_;
166  Ogre::Camera* right_camera_;
167  Ogre::Viewport* right_viewport_;
168 };
169 
170 } // namespace rviz
171 
172 #endif // QT_OGRE_RENDER_WINDOW_OGRE_RENDER_WINDOW_H_
rviz::QtOgreRenderWindow::QtOgreRenderWindow
QtOgreRenderWindow(QWidget *parent=nullptr)
Definition: qt_ogre_render_window.cpp:55
rviz::QtOgreRenderWindow::left_camera_
Ogre::Camera * left_camera_
Definition: qt_ogre_render_window.h:165
Ogre
Definition: axes_display.h:35
rviz::QtOgreRenderWindow::prepareStereoViewport
void prepareStereoViewport(Ogre::Viewport *)
rviz::QtOgreRenderWindow::ortho_scale_
float ortho_scale_
Definition: qt_ogre_render_window.h:155
rviz::QtOgreRenderWindow::getCamera
Ogre::Camera * getCamera() const
Definition: qt_ogre_render_window.h:97
rviz::RenderWidget
Definition: render_widget.h:44
rviz::QtOgreRenderWindow::sizeHint
QSize sizeHint() const override
Definition: qt_ogre_render_window.h:80
rviz::QtOgreRenderWindow
Definition: qt_ogre_render_window.h:54
rviz::QtOgreRenderWindow::viewport_
Ogre::Viewport * viewport_
Definition: qt_ogre_render_window.h:148
rviz::QtOgreRenderWindow::post_render_callback_
boost::function< void()> post_render_callback_
Functor which is called after each render.
Definition: qt_ogre_render_window.h:153
rviz::QtOgreRenderWindow::setPreRenderCallback
virtual void setPreRenderCallback(boost::function< void()> func)
Definition: qt_ogre_render_window.cpp:289
rviz::QtOgreRenderWindow::overlays_enabled_
bool overlays_enabled_
Definition: qt_ogre_render_window.h:159
rviz::QtOgreRenderWindow::setupStereo
void setupStereo()
Prepare to render in stereo if enabled and supported.
Definition: qt_ogre_render_window.cpp:99
rviz::QtOgreRenderWindow::enableStereo
bool enableStereo(bool enable)
Enable or disable stereo rendering If stereo is not supported this is ignored.
Definition: qt_ogre_render_window.cpp:91
rviz::QtOgreRenderWindow::camera_
Ogre::Camera * camera_
Definition: qt_ogre_render_window.h:158
rviz::QtOgreRenderWindow::rendering_stereo_
bool rendering_stereo_
Definition: qt_ogre_render_window.h:164
rviz
Definition: add_display_dialog.cpp:54
rviz::QtOgreRenderWindow::setCameraAspectRatio
void setCameraAspectRatio()
Definition: qt_ogre_render_window.cpp:261
rviz::QtOgreRenderWindow::stereo_enabled_
bool stereo_enabled_
Definition: qt_ogre_render_window.h:163
rviz::QtOgreRenderWindow::setBackgroundColor
void setBackgroundColor(Ogre::ColourValue color)
Definition: qt_ogre_render_window.cpp:251
rviz::QtOgreRenderWindow::postViewportUpdate
void postViewportUpdate(const Ogre::RenderTargetViewportEvent &evt) override
Definition: qt_ogre_render_window.cpp:189
rviz::QtOgreRenderWindow::setOrthoScale
void setOrthoScale(float scale)
Set the scale of the orthographic window. Only valid for an orthographic camera.
Definition: qt_ogre_render_window.cpp:282
rviz::QtOgreRenderWindow::pre_render_callback_
boost::function< void()> pre_render_callback_
Functor which is called before each render.
Definition: qt_ogre_render_window.h:152
rviz::QtOgreRenderWindow::preViewportUpdate
void preViewportUpdate(const Ogre::RenderTargetViewportEvent &evt) override
Definition: qt_ogre_render_window.cpp:144
rviz::QtOgreRenderWindow::paintEvent
void paintEvent(QPaintEvent *e) override
Definition: qt_ogre_render_window.cpp:300
render_widget.h
rviz::QtOgreRenderWindow::resizeEvent
void resizeEvent(QResizeEvent *event) override
Definition: qt_ogre_render_window.cpp:326
rviz::QtOgreRenderWindow::setCamera
void setCamera(Ogre::Camera *camera)
Definition: qt_ogre_render_window.cpp:219
rviz::QtOgreRenderWindow::auto_render_
bool auto_render_
Definition: qt_ogre_render_window.h:156
rviz::QtOgreRenderWindow::~QtOgreRenderWindow
~QtOgreRenderWindow() override
Definition: qt_ogre_render_window.cpp:85
rviz::QtOgreRenderWindow::setPostRenderCallback
virtual void setPostRenderCallback(boost::function< void()> func)
Definition: qt_ogre_render_window.cpp:294
rviz::QtOgreRenderWindow::setAutoRender
void setAutoRender(bool auto_render)
Definition: qt_ogre_render_window.h:117
rviz::QtOgreRenderWindow::ogre_root_
Ogre::Root * ogre_root_
Definition: qt_ogre_render_window.h:150
rviz::QtOgreRenderWindow::setOverlaysEnabled
void setOverlaysEnabled(bool overlays_enabled)
Definition: qt_ogre_render_window.cpp:241
rviz::QtOgreRenderWindow::right_viewport_
Ogre::Viewport * right_viewport_
Definition: qt_ogre_render_window.h:167
rviz::QtOgreRenderWindow::getViewport
Ogre::Viewport * getViewport() const
Definition: qt_ogre_render_window.cpp:214
rviz::QtOgreRenderWindow::right_camera_
Ogre::Camera * right_camera_
Definition: qt_ogre_render_window.h:166
rviz::QtOgreRenderWindow::background_color_
Ogre::ColourValue background_color_
Definition: qt_ogre_render_window.h:160


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Fri Dec 13 2024 03:31:02