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 
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 
66 
67  bool setGroup(std::shared_ptr<SurgSim::Graphics::Group> group) override;
68 
69  void setLightGroupReference(const std::string& name) override;
70 
72 
73  std::shared_ptr<SurgSim::Graphics::Group> getGroup() override;
74 
75  void setDiffuseColor(const SurgSim::Math::Vector4d& color) override;
76 
78 
79  void setSpecularColor(const SurgSim::Math::Vector4d& color) override;
80 
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 
107  {
108  POSITION = 0,
114  };
115 
117  std::shared_ptr<OsgGroup> m_group;
118 
120  std::unordered_map<int, osg::ref_ptr<osg::Uniform>> m_uniforms;
121 
124 
128 
131  osg::ref_ptr<osg::Light> m_light;
132  osg::ref_ptr<osg::LightSource> m_lightSource;
134 
136 };
137 
138 #if defined(_MSC_VER)
139 #pragma warning(pop)
140 #endif
141 
142 }; // Graphics
143 }; // SurgSim
144 
145 #endif
SurgSim::Graphics::OsgLight::m_diffuseColor
SurgSim::Math::Vector4d m_diffuseColor
The actual diffuse color that was set.
Definition: OsgLight.h:122
SurgSim::Graphics::OsgLight::~OsgLight
virtual ~OsgLight()
Definition: OsgLight.cpp:93
SurgSim::Graphics::OsgLight::CONSTANT_ATTENUATION
@ CONSTANT_ATTENUATION
Definition: OsgLight.h:111
SurgSim::Graphics::OsgLight::getDiffuseColor
SurgSim::Math::Vector4d getDiffuseColor() override
Gets diffuse color.
Definition: OsgLight.cpp:145
SurgSim::Graphics::OsgLight::m_specularColor
SurgSim::Math::Vector4d m_specularColor
The actual specular color that was set.
Definition: OsgLight.h:123
SurgSim::Graphics::OsgLight::getSpecularColor
SurgSim::Math::Vector4d getSpecularColor() override
Gets specular color.
Definition: OsgLight.cpp:159
SurgSim::Graphics::OsgLight::m_linearAttenuation
double m_linearAttenuation
The actual linear attenuation value that was set.
Definition: OsgLight.h:126
SurgSim::Graphics::OsgLight::SURGSIM_CLASSNAME
SURGSIM_CLASSNAME(SurgSim::Graphics::OsgLight)
SurgSim::Graphics::OsgLight::OsgLightTests
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:59
osg
Definition: OculusView.h:26
SurgSim::Graphics::OsgLight::m_group
std::shared_ptr< OsgGroup > m_group
The group for this light.
Definition: OsgLight.h:117
SurgSim::Graphics::OsgLight::doUpdate
void doUpdate(double dt) override
Definition: OsgLight.cpp:200
SurgSim::Graphics::OsgLight::m_uniforms
std::unordered_map< int, osg::ref_ptr< osg::Uniform > > m_uniforms
Map for managing all uniforms that this object owns.
Definition: OsgLight.h:120
SurgSim::Graphics::Light
Abstract interface for a light, a light needs to be assigned to a group to be active,...
Definition: Light.h:49
SurgSim::Graphics::OsgLight::setGroup
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:100
SurgSim
Definition: CompoundShapeToGraphics.cpp:30
Light.h
SurgSim::Graphics::OsgLight::DIFFUSE_COLOR
@ DIFFUSE_COLOR
Definition: OsgLight.h:109
SurgSim::Graphics::OsgLight::getQuadraticAttenuation
double getQuadraticAttenuation() override
Gets quadratic attenuation.
Definition: OsgLight.cpp:195
SurgSim::Graphics::OsgLight::apply
void apply(osg::ref_ptr< osg::StateSet > stateSet)
Applies all the lights variables to the given StateSet.
Definition: OsgLight.cpp:208
SurgSim::Graphics::OsgLight::SPECULAR_COLOR
@ SPECULAR_COLOR
Definition: OsgLight.h:110
SurgSim::Graphics::OsgLight::LINEAR_ATTENUATION
@ LINEAR_ATTENUATION
Definition: OsgLight.h:112
SurgSim::Graphics::OsgLight::getConstantAttenuation
double getConstantAttenuation() override
Gets constant attenuation.
Definition: OsgLight.cpp:171
SurgSim::Graphics::OsgLight::OsgLight
OsgLight(const std::string &name)
Constructor.
Definition: OsgLight.cpp:50
SurgSim::Graphics::OsgLight
OpenScenegraph implementation for the Light interface.
Definition: OsgLight.h:54
SurgSim::Graphics::OsgLight::m_groupReference
std::string m_groupReference
Name of the group that this light should shine on...
Definition: OsgLight.h:135
SurgSim::Math::Vector4d
Eigen::Matrix< double, 4, 1 > Vector4d
A 4D vector of doubles.
Definition: Vector.h:61
SurgSim::Graphics::OsgLight::getLinearAttenuation
double getLinearAttenuation() override
Gets linear attenuation.
Definition: OsgLight.cpp:183
SurgSim::Graphics::OsgLight::m_light
osg::ref_ptr< osg::Light > m_light
Definition: OsgLight.h:131
SurgSim::Graphics::OsgLight::remove
void remove(osg::ref_ptr< osg::StateSet > stateSet)
Removes all the lights variable from the given StateSet.
Definition: OsgLight.cpp:216
SurgSim::Graphics::OsgLight::getGroup
std::shared_ptr< SurgSim::Graphics::Group > getGroup() override
Gets the group that this light has been assigned to.
Definition: OsgLight.cpp:131
SurgSim::Graphics::OsgLight::m_quadraticAttenuation
double m_quadraticAttenuation
The actual quadratic attenuation value that was set.
Definition: OsgLight.h:127
SurgSim::Graphics::OsgLight::setSpecularColor
void setSpecularColor(const SurgSim::Math::Vector4d &color) override
Sets specular color of this light.
Definition: OsgLight.cpp:150
SurgSim::Graphics::OsgLight::setDiffuseColor
void setDiffuseColor(const SurgSim::Math::Vector4d &color) override
Sets diffuse color of this light.
Definition: OsgLight.cpp:136
SurgSim::Graphics::OsgLight::m_lightSource
osg::ref_ptr< osg::LightSource > m_lightSource
Definition: OsgLight.h:132
SurgSim::Graphics::OsgLight::getLightGroupReference
std::string getLightGroupReference() override
Gets the name of the group this light should operate on.
Definition: OsgLight.cpp:230
SurgSim::Graphics::OsgLight::setLightGroupReference
void setLightGroupReference(const std::string &name) override
Sets the name of the group that this light should work on.
Definition: OsgLight.cpp:224
string
string(TOUPPER ${DEVICE} DEVICE_UPPER_CASE) option(BUILD_DEVICE_$
Definition: CMakeLists.txt:38
SurgSim::Graphics::OsgLight::POSITION
@ POSITION
Definition: OsgLight.h:108
SurgSim::Graphics::OsgLight::setConstantAttenuation
void setConstantAttenuation(double val) override
Sets constant attenuation.
Definition: OsgLight.cpp:164
SurgSim::Graphics::OsgLight::QUADRATIC_ATTENUATION
@ QUADRATIC_ATTENUATION
Definition: OsgLight.h:113
SurgSim::Graphics::OsgLight::setQuadraticAttenuation
void setQuadraticAttenuation(double val) override
Sets quadratic attenuation.
Definition: OsgLight.cpp:188
SurgSim::Graphics::OsgLight::UniformType
UniformType
Internal for managing uniforms.
Definition: OsgLight.h:107
OsgRepresentation.h
SurgSim::Graphics::OsgLight::m_constantAttenuation
double m_constantAttenuation
The actual constant attenuation value that was set.
Definition: OsgLight.h:125
SurgSim::Graphics::OsgRepresentation
Base OSG implementation of a graphics representation.
Definition: OsgRepresentation.h:56
SurgSim::Graphics::OsgLight::setLinearAttenuation
void setLinearAttenuation(double val) override
Sets linear attenuation.
Definition: OsgLight.cpp:176