opensurgsim
OsgLight.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_OSGLIGHT_H
17 #define SURGSIM_GRAPHICS_OSGLIGHT_H
18 
19 #include <memory>
20 #include <string>
21 #include <unordered_map>
22 
23 #include "SurgSim/Graphics/OsgRepresentation.h"
24 #include "SurgSim/Graphics/Light.h"
25 
26 #include <osg/ref_ptr>
27 
28 #if defined(_MSC_VER)
29 #pragma warning(push)
30 #pragma warning(disable:4250)
31 #endif
32 
33 namespace osg
34 {
35 
36 class Uniform;
37 class StateSet;
38 class Light;
39 class LightSource;
40 
41 }
42 
43 namespace SurgSim
44 {
45 namespace Graphics
46 {
47 
48 class OsgGroup;
49 
50 SURGSIM_STATIC_REGISTRATION(OsgLight);
51 
53 class OsgLight : public OsgRepresentation, public Light
54 {
55 public:
56 
59  friend class OsgLightTests;
60 
62  explicit OsgLight(const std::string& name);
63  virtual ~OsgLight();
64 
65  SURGSIM_CLASSNAME(SurgSim::Graphics::OsgLight);
66 
67  bool setGroup(std::shared_ptr<SurgSim::Graphics::Group> group) override;
68 
69  void setLightGroupReference(const std::string& name) override;
70 
71  std::string getLightGroupReference() override;
72 
73  std::shared_ptr<SurgSim::Graphics::Group> getGroup() override;
74 
75  void setDiffuseColor(const SurgSim::Math::Vector4d& color) override;
76 
77  SurgSim::Math::Vector4d getDiffuseColor() override;
78 
79  void setSpecularColor(const SurgSim::Math::Vector4d& color) override;
80 
81  SurgSim::Math::Vector4d getSpecularColor() override;
82 
83  void setConstantAttenuation(double val) override;
84 
85  double getConstantAttenuation() override;
86 
87  void setLinearAttenuation(double val) override;
88 
89  double getLinearAttenuation() override;
90 
91  void setQuadraticAttenuation(double val) override;
92 
93  double getQuadraticAttenuation() override;
94 
95 
96 private:
97  void doUpdate(double dt) override;
98 
100  void apply(osg::ref_ptr<osg::StateSet> stateSet);
101 
103  void remove(osg::ref_ptr<osg::StateSet> stateSet);
104 
106  enum UniformType
107  {
108  POSITION = 0,
109  DIFFUSE_COLOR,
110  SPECULAR_COLOR,
111  CONSTANT_ATTENUATION,
112  LINEAR_ATTENUATION,
113  QUADRATIC_ATTENUATION
114  };
115 
117  std::shared_ptr<OsgGroup> m_group;
118 
120  std::unordered_map<int, osg::ref_ptr<osg::Uniform>> m_uniforms;
121 
122  SurgSim::Math::Vector4d m_diffuseColor;
123  SurgSim::Math::Vector4d m_specularColor;
124 
125  double m_constantAttenuation;
126  double m_linearAttenuation;
127  double m_quadraticAttenuation;
128 
131  osg::ref_ptr<osg::Light> m_light;
132  osg::ref_ptr<osg::LightSource> m_lightSource;
134 
135  std::string m_groupReference;
136 };
137 
138 #if defined(_MSC_VER)
139 #pragma warning(pop)
140 #endif
141 
142 }; // Graphics
143 }; // SurgSim
144 
145 #endif
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
Eigen::Matrix< double, 4, 1 > Vector4d
A 4D vector of doubles.
Definition: Vector.h:61
Abstract interface for a light, a light needs to be assigned to a group to be active, only the members of this group will be considered to be lit by this light.
Definition: Light.h:48
OpenScenegraph implementation for the Light interface.
Definition: OsgLight.h:53
Definition: OsgLightTests.cpp:48
Definition: OsgImGuiHandler.h:8
Base OSG implementation of a graphics representation.
Definition: OsgRepresentation.h:55