OsgLight.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_GRAPHICS_OSGLIGHT_H
#define SURGSIM_GRAPHICS_OSGLIGHT_H
#include <memory>
#include <string>
#include <unordered_map>
#include "SurgSim/Graphics/OsgRepresentation.h"
#include "SurgSim/Graphics/Light.h"
#include <osg/ref_ptr>
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4250)
#endif
namespace osg
{
class Uniform;
class StateSet;
class Light;
class LightSource;
}
namespace SurgSim
{
namespace Graphics
{
class OsgGroup;
SURGSIM_STATIC_REGISTRATION(OsgLight);
class OsgLight : public OsgRepresentation, public Light
{
public:
friend class OsgLightTests;
explicit OsgLight(const std::string& name);
virtual ~OsgLight();
SURGSIM_CLASSNAME(SurgSim::Graphics::OsgLight);
bool setGroup(std::shared_ptr<SurgSim::Graphics::Group> group) override;
void setLightGroupReference(const std::string& name) override;
std::string getLightGroupReference() override;
std::shared_ptr<SurgSim::Graphics::Group> getGroup() override;
void setDiffuseColor(const SurgSim::Math::Vector4d& color) override;
SurgSim::Math::Vector4d getDiffuseColor() override;
void setSpecularColor(const SurgSim::Math::Vector4d& color) override;
SurgSim::Math::Vector4d getSpecularColor() override;
void setConstantAttenuation(double val) override;
double getConstantAttenuation() override;
void setLinearAttenuation(double val) override;
double getLinearAttenuation() override;
void setQuadraticAttenuation(double val) override;
double getQuadraticAttenuation() override;
private:
void doUpdate(double dt) override;
void apply(osg::ref_ptr<osg::StateSet> stateSet);
void remove(osg::ref_ptr<osg::StateSet> stateSet);
enum UniformType
{
POSITION = 0,
DIFFUSE_COLOR,
SPECULAR_COLOR,
CONSTANT_ATTENUATION,
LINEAR_ATTENUATION,
QUADRATIC_ATTENUATION
};
std::shared_ptr<OsgGroup> m_group;
std::unordered_map<int, osg::ref_ptr<osg::Uniform>> m_uniforms;
SurgSim::Math::Vector4d m_diffuseColor;
SurgSim::Math::Vector4d m_specularColor;
double m_constantAttenuation;
double m_linearAttenuation;
double m_quadraticAttenuation;
osg::ref_ptr<osg::Light> m_light;
osg::ref_ptr<osg::LightSource> m_lightSource;
std::string m_groupReference;
};
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
}; // Graphics
}; // SurgSim
#endif
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Graphics::OsgLight::m_specularColor
SurgSim::Math::Vector4d m_specularColor
The actual specular color that was set.
Definition: OsgLight.h:123
SurgSim::Graphics::Light
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
SurgSim::Graphics::OsgLight
OpenScenegraph implementation for the Light interface.
Definition: OsgLight.h:53
SurgSim::Graphics::OsgLight::m_groupReference
std::string m_groupReference
Name of the group that this light should shine on...
Definition: OsgLight.h:135
SurgSim::Graphics::OsgLight::m_group
std::shared_ptr< OsgGroup > m_group
The group for this light.
Definition: OsgLight.h:117
Light.h
SURGSIM_CLASSNAME
#define SURGSIM_CLASSNAME(ClassName)
Declare the class name of a class with the appropriate function header, do not use quotes...
Definition: Macros.h:21
SurgSim::Graphics::OsgLight::m_constantAttenuation
double m_constantAttenuation
The actual constant attenuation value that was set.
Definition: OsgLight.h:125
SurgSim::Graphics::OsgLight::UniformType
UniformType
Internal for managing uniforms.
Definition: OsgLight.h:106
SurgSim::Graphics::OsgLight::m_quadraticAttenuation
double m_quadraticAttenuation
The actual quadratic attenuation value that was set.
Definition: OsgLight.h:127
SurgSim::Graphics::OsgLight::m_linearAttenuation
double m_linearAttenuation
The actual linear attenuation value that was set.
Definition: OsgLight.h:126
SurgSim::Graphics::OsgLight::m_lightSource
osg::ref_ptr< osg::LightSource > m_lightSource
Definition: OsgLight.h:132
SurgSim::Graphics::OsgLight::CONSTANT_ATTENUATION
Definition: OsgLight.h:111
osg
Definition: OculusView.h:25
OsgRepresentation.h
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::OsgLight::LINEAR_ATTENUATION
Definition: OsgLight.h:112
SurgSim::Math::Vector4d
Eigen::Matrix< double, 4, 1 > Vector4d
A 4D vector of doubles.
Definition: Vector.h:61
SurgSim::Graphics::OsgRepresentation
Base OSG implementation of a graphics representation.
Definition: OsgRepresentation.h:55
SurgSim::Graphics::OsgLight::SPECULAR_COLOR
Definition: OsgLight.h:110
SurgSim::Graphics::OsgLight::m_light
osg::ref_ptr< osg::Light > m_light
Definition: OsgLight.h:131
SurgSim::Graphics::OsgLight::m_diffuseColor
SurgSim::Math::Vector4d m_diffuseColor
The actual diffuse color that was set.
Definition: OsgLight.h:122
SurgSim::Graphics::OsgLight::DIFFUSE_COLOR
Definition: OsgLight.h:109