OsgView.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_GRAPHICS_OSGVIEW_H
17 #define SURGSIM_GRAPHICS_OSGVIEW_H
18 
19 #include <osgViewer/Viewer>
20 
21 #include "SurgSim/Graphics/View.h"
22 
23 namespace osgViewer
24 {
25 class StatsHandler;
26 class DisplaySettings;
27 }
28 
29 namespace SurgSim
30 {
31 
32 namespace Input
33 {
34 class CommonDevice;
35 }
36 
37 namespace Devices
38 {
39 class KeyboardDevice;
40 class MouseDevice;
41 }
42 
43 namespace Graphics
44 {
45 
46 class OsgCamera;
47 class OsgTrackballZoomManipulator;
48 
49 SURGSIM_STATIC_REGISTRATION(OsgView);
50 
56 class OsgView : public View
57 {
58 public:
65  explicit OsgView(const std::string& name);
66 
68  ~OsgView();
69 
71 
72  void setPosition(const std::array<int, 2>& position) override;
73 
74  std::array<int, 2> getPosition() const override;
75 
76  void setDimensions(const std::array<int, 2>& dimensions) override;
77 
78  std::array<int, 2> getDimensions() const override;
79 
80  void setDimensionsDouble(const std::array<double, 2>& dimensions) override;
81 
82  std::array<double, 2> getDimensionsDouble() const override;
83 
84  void setWindowBorderEnabled(bool enabled) override;
85 
86  bool isWindowBorderEnabled() const override;
87 
92  void setCamera(std::shared_ptr<SurgSim::Framework::Component> camera) override;
93 
97  void enableManipulator(bool val);
98 
100  bool isManipulatorEnabled();
101 
106  void setManipulatorParameters(const SurgSim::Math::Vector3d& position, const SurgSim::Math::Vector3d& lookat);
107 
110  void setManipulatorPosition(const SurgSim::Math::Vector3d& position);
111 
114 
117  void setManipulatorLookAt(const SurgSim::Math::Vector3d& lookAt);
118 
121 
125  void setOsgMapsUniforms(bool val);
126 
128  bool getOsgMapsUniforms();
129 
132  std::shared_ptr<SurgSim::Input::CommonDevice> getKeyboardDevice();
133 
136  void enableKeyboardDevice(bool val);
137 
140 
143  std::shared_ptr<SurgSim::Input::CommonDevice> getMouseDevice();
144 
147  void enableMouseDevice(bool val);
148 
150  bool isMouseDeviceEnabled();
151 
152  void update(double dt) override;
153 
155  osg::ref_ptr<osgViewer::View> getOsgView() const;
156 
157 protected:
160  bool doInitialize() override;
161 
163  bool doWakeUp() override;
164 
166  int doSetTargetScreen(int val) override;
167 
168 
170  virtual osg::ref_ptr<osg::DisplaySettings> createDisplaySettings() const;
171 private:
172 
175  void fixupStatsHandler(osgViewer::StatsHandler* statsHandler);
176 
178  std::array<int, 2> m_position;
180  std::array<int, 2> m_dimensions;
181  std::array<int, 2> m_screenDimensions;
184 
190 
192  osg::ref_ptr<osgViewer::View> m_view;
193 
196 
197  osg::ref_ptr<OsgTrackballZoomManipulator> m_manipulator;
200 
203  std::shared_ptr<SurgSim::Devices::KeyboardDevice> m_keyboardDevice;
204 
207  std::shared_ptr<SurgSim::Devices::MouseDevice> m_mouseDevice;
208 };
209 
210 }; // namespace Graphics
211 
212 }; // namespace SurgSim
213 
214 #endif // SURGSIM_GRAPHICS_OSGVIEW_H
SurgSim::Graphics::OsgView::setDimensions
void setDimensions(const std::array< int, 2 > &dimensions) override
Set the dimensions of this view.
Definition: OsgView.cpp:128
SurgSim::Graphics::OsgView::createDisplaySettings
virtual osg::ref_ptr< osg::DisplaySettings > createDisplaySettings() const
Definition: OsgView.cpp:279
SurgSim::Graphics::OsgView::setWindowBorderEnabled
void setWindowBorderEnabled(bool enabled) override
Sets whether the view window has a border.
Definition: OsgView.cpp:167
SurgSim::Graphics::OsgView::m_keyboardEnabled
bool m_keyboardEnabled
Indicate if a keyboard device is enabled.
Definition: OsgView.h:202
SurgSim::Graphics::OsgView::m_isWindowBorderEnabled
bool m_isWindowBorderEnabled
Whether the view window has a border.
Definition: OsgView.h:183
SurgSim::Graphics::OsgView::getManipulatorPosition
SurgSim::Math::Vector3d getManipulatorPosition()
Definition: OsgView.cpp:521
SurgSim::Graphics::OsgView::doInitialize
bool doInitialize() override
Initialize the view.
Definition: OsgView.cpp:230
SurgSim::Graphics::OsgView::isMouseDeviceEnabled
bool isMouseDeviceEnabled()
Definition: OsgView.cpp:484
SurgSim::Graphics::OsgView::doWakeUp
bool doWakeUp() override
Wake up the view.
Definition: OsgView.cpp:235
SurgSim::Graphics::OsgView
OSG-based implementation of graphics view class.
Definition: OsgView.h:56
SurgSim::Graphics::OsgView::fixupStatsHandler
void fixupStatsHandler(osgViewer::StatsHandler *statsHandler)
Patch the StatsHandler rendering.
Definition: OsgView.cpp:298
SurgSim::Graphics::OsgView::m_keyboardDevice
std::shared_ptr< SurgSim::Devices::KeyboardDevice > m_keyboardDevice
Definition: OsgView.h:203
SurgSim::Graphics::OsgView::setManipulatorLookAt
void setManipulatorLookAt(const SurgSim::Math::Vector3d &lookAt)
Set the camera manipulator lookAt.
Definition: OsgView.cpp:526
SurgSim::Graphics::OsgView::enableMouseDevice
void enableMouseDevice(bool val)
Turn on/off the mouse device to be used.
Definition: OsgView.cpp:461
SurgSim::Graphics::OsgView::isManipulatorEnabled
bool isManipulatorEnabled()
Definition: OsgView.cpp:415
SurgSim::Math::Vector3d
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
SurgSim::Graphics::OsgView::m_isFirstUpdate
bool m_isFirstUpdate
Whether the next update will be the first time the view has been updated On the first update,...
Definition: OsgView.h:187
SurgSim::Graphics::OsgView::getOsgView
osg::ref_ptr< osgViewer::View > getOsgView() const
Definition: OsgView.cpp:390
SurgSim::Graphics::OsgView::~OsgView
~OsgView()
Destructor.
Definition: OsgView.cpp:107
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Graphics::OsgView::setCamera
void setCamera(std::shared_ptr< SurgSim::Framework::Component > camera) override
Sets the camera which provides the viewpoint in the scene Only allows OsgCamera components,...
Definition: OsgView.cpp:178
SurgSim::Graphics::OsgView::getPosition
std::array< int, 2 > getPosition() const override
Get the position of this view.
Definition: OsgView.cpp:123
SurgSim::Graphics::OsgView::setOsgMapsUniforms
void setOsgMapsUniforms(bool val)
Enable osg modelview uniforms mapping, in this mode osg replaces the gl builtins with osg_* names,...
Definition: OsgView.cpp:379
SurgSim::Graphics::OsgView::OsgView
OsgView(const std::string &name)
Constructor.
Definition: OsgView.cpp:73
SurgSim::Graphics::OsgView::isWindowBorderEnabled
bool isWindowBorderEnabled() const override
Returns whether the view window has a border.
Definition: OsgView.cpp:173
SurgSim::Graphics::OsgView::m_osgMapUniforms
bool m_osgMapUniforms
Wether to enable osg uniform mapping.
Definition: OsgView.h:195
SurgSim::Graphics::OsgView::m_dimensions
std::array< int, 2 > m_dimensions
Dimensions of the view on the screen (in pixels)
Definition: OsgView.h:180
SurgSim::Graphics::OsgView::setPosition
void setPosition(const std::array< int, 2 > &position) override
Set the position of this view.
Definition: OsgView.cpp:114
SurgSim::Graphics::OsgView::setManipulatorParameters
void setManipulatorParameters(const SurgSim::Math::Vector3d &position, const SurgSim::Math::Vector3d &lookat)
As the camera is not accessible from here and as it cannot be controlled from the outside any more we...
Definition: OsgView.cpp:503
SurgSim::Graphics::OsgView::m_manipulator
osg::ref_ptr< OsgTrackballZoomManipulator > m_manipulator
Definition: OsgView.h:197
SurgSim::Graphics::OsgView::m_view
osg::ref_ptr< osgViewer::View > m_view
OSG view which performs the actual work involved in setting up and rendering to a window.
Definition: OsgView.h:192
SurgSim::Graphics::OsgView::m_manipulatorLookat
SurgSim::Math::Vector3d m_manipulatorLookat
Definition: OsgView.h:199
SurgSim::Graphics::OsgView::m_screenDimensions
std::array< int, 2 > m_screenDimensions
Definition: OsgView.h:181
SurgSim::Graphics::OsgView::m_manipulatorPosition
SurgSim::Math::Vector3d m_manipulatorPosition
Definition: OsgView.h:198
SurgSim::Graphics::OsgView::m_areWindowSettingsDirty
bool m_areWindowSettingsDirty
Whether the settings have been changed and the window needs to be updated.
Definition: OsgView.h:189
SurgSim::Graphics::OsgView::getDimensions
std::array< int, 2 > getDimensions() const override
Get the dimensions of this view.
Definition: OsgView.cpp:137
SurgSim::Graphics::OsgView::update
void update(double dt) override
Updates the view.
Definition: OsgView.cpp:187
SurgSim::Graphics::OsgView::m_mouseEnabled
bool m_mouseEnabled
Indicate if a mouse device is enabled.
Definition: OsgView.h:206
SurgSim::Graphics::View
Base graphics view class, which defines the basic interface for all graphics views.
Definition: View.h:39
MouseDevice
MouseDevice
Definition: CMakeLists.txt:35
SurgSim::Graphics::OsgView::setManipulatorPosition
void setManipulatorPosition(const SurgSim::Math::Vector3d &position)
Set the camera manipulator position.
Definition: OsgView.cpp:516
SurgSim::Graphics::OsgView::doSetTargetScreen
int doSetTargetScreen(int val) override
Determine Screen Size.
Definition: OsgView.cpp:347
SurgSim::Graphics::OsgView::SURGSIM_CLASSNAME
SURGSIM_CLASSNAME(SurgSim::Graphics::OsgView)
SurgSim::Graphics::OsgView::getKeyboardDevice
std::shared_ptr< SurgSim::Input::CommonDevice > getKeyboardDevice()
Return the keyboard to be used with this view.
Definition: OsgView.cpp:448
string
string(TOUPPER ${DEVICE} DEVICE_UPPER_CASE) option(BUILD_DEVICE_$
Definition: CMakeLists.txt:38
SurgSim::Graphics::OsgView::enableManipulator
void enableManipulator(bool val)
Enables a camera manipulator, implemented via a trackball, this is a temporary solution as it uses th...
Definition: OsgView.cpp:395
SurgSim::Graphics::OsgView::enableKeyboardDevice
void enableKeyboardDevice(bool val)
Turn on/off the keyboard device to be used.
Definition: OsgView.cpp:420
View.h
SurgSim::Graphics::OsgView::getOsgMapsUniforms
bool getOsgMapsUniforms()
Definition: OsgView.cpp:385
SurgSim::Graphics::OsgView::getDimensionsDouble
std::array< double, 2 > getDimensionsDouble() const override
Get the dimensions of this view in doubles.
Definition: OsgView.cpp:159
SurgSim::Graphics::OsgView::isKeyboardDeviceEnabled
bool isKeyboardDeviceEnabled()
Definition: OsgView.cpp:443
SurgSim::Graphics::OsgView::m_mouseDevice
std::shared_ptr< SurgSim::Devices::MouseDevice > m_mouseDevice
Definition: OsgView.h:207
SurgSim::Graphics::OsgView::getManipulatorLookAt
SurgSim::Math::Vector3d getManipulatorLookAt()
Definition: OsgView.cpp:531
KeyboardDevice
KeyboardDevice
Definition: CMakeLists.txt:35
SurgSim::Graphics::OsgView::getMouseDevice
std::shared_ptr< SurgSim::Input::CommonDevice > getMouseDevice()
Return the mouse to be used with this view.
Definition: OsgView.cpp:489
SurgSim::Graphics::OsgView::m_position
std::array< int, 2 > m_position
Position of the view on the screen (in pixels)
Definition: OsgView.h:178
osgViewer
Definition: OsgView.h:23
SurgSim::Graphics::OsgView::setDimensionsDouble
void setDimensionsDouble(const std::array< double, 2 > &dimensions) override
Set the dimensions of this view in doubles.
Definition: OsgView.cpp:149