opensurgsim
OsgView.h
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 
70  SURGSIM_CLASSNAME(SurgSim::Graphics::OsgView);
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 
113  SurgSim::Math::Vector3d getManipulatorPosition();
114 
117  void setManipulatorLookAt(const SurgSim::Math::Vector3d& lookAt);
118 
120  SurgSim::Math::Vector3d getManipulatorLookAt();
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 
139  bool isKeyboardDeviceEnabled();
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 = {};
183  bool m_isWindowBorderEnabled;
184 
187  bool m_isFirstUpdate;
189  bool m_areWindowSettingsDirty;
190 
192  osg::ref_ptr<osgViewer::View> m_view;
193 
195  bool m_osgMapUniforms;
196 
197  osg::ref_ptr<OsgTrackballZoomManipulator> m_manipulator;
198  SurgSim::Math::Vector3d m_manipulatorPosition;
199  SurgSim::Math::Vector3d m_manipulatorLookat;
200 
202  bool m_keyboardEnabled;
203  std::shared_ptr<SurgSim::Devices::KeyboardDevice> m_keyboardDevice;
204 
206  bool m_mouseEnabled;
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
Base graphics view class, which defines the basic interface for all graphics views.
Definition: View.h:39
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
Definition: OsgView.h:23
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
OSG-based implementation of graphics view class.
Definition: OsgView.h:56