All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OsgLight.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_OSGLIGHT_H
17 #define SURGSIM_GRAPHICS_OSGLIGHT_H
18 
19 #include <memory>
20 #include <string>
21 #include <unordered_map>
22 
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 
51 class OsgLight : public OsgRepresentation, public Light
52 {
53 public:
54 
57  friend class OsgLightTests;
58 
60  explicit OsgLight(const std::string& name);
61  virtual ~OsgLight();
62 
63  virtual bool setGroup(std::shared_ptr<SurgSim::Graphics::Group> group) override;
64 
65  virtual void setLightGroupReference(const std::string& name) override;
66 
67  virtual std::string getLightGroupReference() override;
68 
69  virtual std::shared_ptr<SurgSim::Graphics::Group> getGroup() override;
70 
71  virtual void setDiffuseColor(const SurgSim::Math::Vector4d& color) override;
72 
73  virtual SurgSim::Math::Vector4d getDiffuseColor() override;
74 
75  virtual void setSpecularColor(const SurgSim::Math::Vector4d& color) override;
76 
77  virtual SurgSim::Math::Vector4d getSpecularColor() override;
78 
79  virtual void setConstantAttenuation(double val) override;
80 
81  virtual double getConstantAttenuation() override;
82 
83  virtual void setLinearAttenuation(double val) override;
84 
85  virtual double getLinearAttenuation() override;
86 
87  virtual void setQuadraticAttenuation(double val) override;
88 
89  virtual double getQuadraticAttenuation() override;
90 
91 
92 private:
93  virtual void doUpdate(double dt) override;
94 
96  void apply(osg::ref_ptr<osg::StateSet> stateSet);
97 
99  void remove(osg::ref_ptr<osg::StateSet> stateSet);
100 
103  {
104  POSITION = 0,
110  };
111 
113  std::shared_ptr<OsgGroup> m_group;
114 
116  std::unordered_map<int, osg::ref_ptr<osg::Uniform>> m_uniforms;
117 
120 
124 
127  osg::ref_ptr<osg::Light> m_light;
128  osg::ref_ptr<osg::LightSource> m_lightSource;
130 
131  std::string m_groupReference;
132 };
133 
134 #if defined(_MSC_VER)
135 #pragma warning(pop)
136 #endif
137 
138 }; // Graphics
139 }; // SurgSim
140 
141 #endif
virtual ~OsgLight()
Definition: OsgLight.cpp:91
SurgSim::Math::Vector4d m_specularColor
The actual specular color that was set.
Definition: OsgLight.h:119
friend class OsgLightTests
If we use the uniforms map, to check for all the uniforms that should be set in the stateset...
Definition: OsgLight.h:57
virtual bool setGroup(std::shared_ptr< SurgSim::Graphics::Group > group) override
Sets the group for this light, setting nullptr here will remove the light from its current group...
Definition: OsgLight.cpp:98
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:47
virtual void setDiffuseColor(const SurgSim::Math::Vector4d &color) override
Sets diffuse color of this light.
Definition: OsgLight.cpp:134
OpenScenegraph implementation for the Light interface.
Definition: OsgLight.h:51
virtual void setQuadraticAttenuation(double val) override
Sets quadratic attenuation.
Definition: OsgLight.cpp:186
virtual void setLinearAttenuation(double val) override
Sets linear attenuation.
Definition: OsgLight.cpp:174
std::string m_groupReference
Name of the group that this light should shine on...
Definition: OsgLight.h:131
virtual double getQuadraticAttenuation() override
Gets quadratic attenuation.
Definition: OsgLight.cpp:193
void apply(osg::ref_ptr< osg::StateSet > stateSet)
Applies all the lights variables to the given StateSet.
Definition: OsgLight.cpp:206
std::shared_ptr< OsgGroup > m_group
The group for this light.
Definition: OsgLight.h:113
Definition: OsgLight.h:104
virtual std::string getLightGroupReference() override
Gets the name of the group this light should operate on.
Definition: OsgLight.cpp:228
double m_constantAttenuation
The actual constant attenuation value that was set.
Definition: OsgLight.h:121
UniformType
Internal for managing uniforms.
Definition: OsgLight.h:102
double m_quadraticAttenuation
The actual quadratic attenuation value that was set.
Definition: OsgLight.h:123
virtual SurgSim::Math::Vector4d getDiffuseColor() override
Gets diffuse color.
Definition: OsgLight.cpp:143
double m_linearAttenuation
The actual linear attenuation value that was set.
Definition: OsgLight.h:122
virtual double getLinearAttenuation() override
Gets linear attenuation.
Definition: OsgLight.cpp:181
osg::ref_ptr< osg::LightSource > m_lightSource
Definition: OsgLight.h:128
virtual void doUpdate(double dt) override
Definition: OsgLight.cpp:198
virtual double getConstantAttenuation() override
Gets constant attenuation.
Definition: OsgLight.cpp:169
virtual void setConstantAttenuation(double val) override
Sets constant attenuation.
Definition: OsgLight.cpp:162
virtual void setSpecularColor(const SurgSim::Math::Vector4d &color) override
Sets specular color of this light.
Definition: OsgLight.cpp:148
std::unordered_map< int, osg::ref_ptr< osg::Uniform > > m_uniforms
Map for managing all uniforms that this object owns.
Definition: OsgLight.h:116
OsgLight(const std::string &name)
Constructor.
Definition: OsgLight.cpp:48
virtual SurgSim::Math::Vector4d getSpecularColor() override
Gets specular color.
Definition: OsgLight.cpp:157
Eigen::Matrix< double, 4, 1 > Vector4d
A 4D vector of doubles.
Definition: Vector.h:60
Base OSG implementation of a graphics representation.
Definition: OsgRepresentation.h:42
virtual std::shared_ptr< SurgSim::Graphics::Group > getGroup() override
Gets the group that this light has been assigned to.
Definition: OsgLight.cpp:129
virtual void setLightGroupReference(const std::string &name) override
Sets the name of the group that this light should work on.
Definition: OsgLight.cpp:222
osg::ref_ptr< osg::Light > m_light
Definition: OsgLight.h:127
SurgSim::Math::Vector4d m_diffuseColor
The actual diffuse color that was set.
Definition: OsgLight.h:118