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 Device
38 {
39 class KeyboardDevice;
40 class MouseDevice;
41 }
42 
43 namespace Graphics
44 {
45 
46 class OsgCamera;
47 class OsgTrackballZoomManipulator;
48 
50 
56 class OsgView : public View
57 {
58 public:
65  explicit OsgView(const std::string& name);
66 
68  ~OsgView();
69 
71 
72  virtual void setPosition(const std::array<int, 2>& position) override;
73 
74  virtual std::array<int, 2> getPosition() const override;
75 
76  virtual void setDimensions(const std::array<int, 2>& dimensions) override;
77 
78  virtual std::array<int, 2> getDimensions() const override;
79 
80  virtual void setWindowBorderEnabled(bool enabled) override;
81 
82  virtual bool isWindowBorderEnabled() const override;
83 
88  virtual void setCamera(std::shared_ptr<SurgSim::Framework::Component> camera) override;
89 
93  void enableManipulator(bool val);
94 
96  bool isManipulatorEnabled();
97 
102  void setManipulatorParameters(const SurgSim::Math::Vector3d& position, const SurgSim::Math::Vector3d& lookat);
103 
106  void setManipulatorPosition(const SurgSim::Math::Vector3d& position);
107 
110 
113  void setManipulatorLookAt(const SurgSim::Math::Vector3d& lookAt);
114 
117 
121  void setOsgMapsUniforms(bool val);
122 
124  bool getOsgMapsUniforms();
125 
128  std::shared_ptr<SurgSim::Input::CommonDevice> getKeyboardDevice();
129 
132  void enableKeyboardDevice(bool val);
133 
136 
139  std::shared_ptr<SurgSim::Input::CommonDevice> getMouseDevice();
140 
143  void enableMouseDevice(bool val);
144 
146  bool isMouseDeviceEnabled();
147 
148  virtual void update(double dt) override;
149 
151  osg::ref_ptr<osgViewer::View> getOsgView() const;
152 
153 protected:
156  virtual bool doInitialize() override;
157 
159  virtual bool doWakeUp() override;
160 private:
161 
164  void fixupStatsHandler(osgViewer::StatsHandler* statsHandler);
165 
167  std::array<int, 2> m_position;
169  std::array<int, 2> m_dimensions;
172 
178 
180  osg::ref_ptr<osgViewer::View> m_view;
181 
184 
185  osg::ref_ptr<OsgTrackballZoomManipulator> m_manipulator;
188 
191  std::shared_ptr<SurgSim::Device::KeyboardDevice> m_keyboardDevice;
192 
195  std::shared_ptr<SurgSim::Device::MouseDevice> m_mouseDevice;
196 };
197 
198 }; // namespace Graphics
199 
200 }; // namespace SurgSim
201 
202 #endif // SURGSIM_GRAPHICS_OSGVIEW_H
Base graphics view class, which defines the basic interface for all graphics views.
Definition: View.h:39
void setManipulatorPosition(const SurgSim::Math::Vector3d &position)
Set the camera manipulator position.
Definition: OsgView.cpp:433
osg::ref_ptr< OsgTrackballZoomManipulator > m_manipulator
Definition: OsgView.h:185
Definition: DriveElementFromInputBehavior.cpp:27
virtual void setPosition(const std::array< int, 2 > &position) override
Set the position of this view.
Definition: OsgView.cpp:112
void enableKeyboardDevice(bool val)
Turn on/off the keyboard device to be used.
Definition: OsgView.cpp:335
bool m_osgMapUniforms
Wether to enable osg uniform mapping.
Definition: OsgView.h:183
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:180
std::shared_ptr< SurgSim::Device::MouseDevice > m_mouseDevice
Definition: OsgView.h:195
SurgSim::Math::Vector3d m_manipulatorPosition
Definition: OsgView.h:186
SURGSIM_STATIC_REGISTRATION(OsgBoxRepresentation)
virtual std::array< int, 2 > getDimensions() const override
Get the dimensions of this view.
Definition: OsgView.cpp:135
void setManipulatorLookAt(const SurgSim::Math::Vector3d &lookAt)
Set the camera manipulator lookAt.
Definition: OsgView.cpp:443
virtual void update(double dt) override
Updates the view.
Definition: OsgView.cpp:160
~OsgView()
Destructor.
Definition: OsgView.cpp:105
Definition: OsgView.h:23
bool m_mouseEnabled
Indicate if a mouse device is enabled.
Definition: OsgView.h:194
void setOsgMapsUniforms(bool val)
Enable osg modelview uniforms mapping, in this mode osg replaces the gl builtins with osg_* names...
Definition: OsgView.cpp:292
bool m_isWindowBorderEnabled
Whether the view window has a border.
Definition: OsgView.h:171
virtual bool doInitialize() override
Initialize the view.
Definition: OsgView.cpp:179
virtual bool isWindowBorderEnabled() const override
Returns whether the view window has a border.
Definition: OsgView.cpp:146
std::shared_ptr< SurgSim::Input::CommonDevice > getMouseDevice()
Return the mouse to be used with this view.
Definition: OsgView.cpp:404
std::array< int, 2 > m_position
Position of the view on the screen (in pixels)
Definition: OsgView.h:167
void enableManipulator(bool val)
Enables a camera manipulator, implemented via a trackball, this is a temporary solution as it uses th...
Definition: OsgView.cpp:308
SurgSim::Math::Vector3d getManipulatorLookAt()
Definition: OsgView.cpp:448
virtual void setDimensions(const std::array< int, 2 > &dimensions) override
Set the dimensions of this view.
Definition: OsgView.cpp:126
virtual void setCamera(std::shared_ptr< SurgSim::Framework::Component > camera) override
Sets the camera which provides the viewpoint in the scene Only allows OsgCamera components, any other will not be set and it will return false.
Definition: OsgView.cpp:151
std::shared_ptr< SurgSim::Device::KeyboardDevice > m_keyboardDevice
Definition: OsgView.h:191
virtual void setWindowBorderEnabled(bool enabled) override
Sets whether the view window has a border.
Definition: OsgView.cpp:140
OsgView(const std::string &name)
Constructor.
Definition: OsgView.cpp:73
bool isMouseDeviceEnabled()
Definition: OsgView.cpp:399
virtual bool doWakeUp() override
Wake up the view.
Definition: OsgView.cpp:184
std::shared_ptr< SurgSim::Input::CommonDevice > getKeyboardDevice()
Return the keyboard to be used with this view.
Definition: OsgView.cpp:363
osg::ref_ptr< osgViewer::View > getOsgView() const
Definition: OsgView.cpp:303
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:418
SURGSIM_CLASSNAME(SurgSim::Graphics::OsgView)
bool getOsgMapsUniforms()
Definition: OsgView.cpp:298
std::array< int, 2 > m_dimensions
Dimensions of the view on the screen (in pixels)
Definition: OsgView.h:169
SurgSim::Math::Vector3d m_manipulatorLookat
Definition: OsgView.h:187
bool isKeyboardDeviceEnabled()
Definition: OsgView.cpp:358
void fixupStatsHandler(osgViewer::StatsHandler *statsHandler)
Patch the StatsHandler rendering.
Definition: OsgView.cpp:243
bool m_isFirstUpdate
Whether the next update will be the first time the view has been updated On the first update...
Definition: OsgView.h:175
bool isManipulatorEnabled()
Definition: OsgView.cpp:330
virtual std::array< int, 2 > getPosition() const override
Get the position of this view.
Definition: OsgView.cpp:121
void enableMouseDevice(bool val)
Turn on/off the mouse device to be used.
Definition: OsgView.cpp:376
bool m_areWindowSettingsDirty
Whether the settings have been changed and the window needs to be updated.
Definition: OsgView.h:177
SurgSim::Math::Vector3d getManipulatorPosition()
Definition: OsgView.cpp:438
bool m_keyboardEnabled
Indicate if a keyboard device is enabled.
Definition: OsgView.h:190
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:56
OSG-based implementation of graphics view class.
Definition: OsgView.h:56