OsgRepresentation.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013-2016, 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_OSGREPRESENTATION_H
17 #define SURGSIM_GRAPHICS_OSGREPRESENTATION_H
18 
19 #include <memory>
20 
21 #include <osg/ref_ptr>
22 
25 
26 namespace osg
27 {
28 class Group;
29 class Node;
30 class PositionAttitudeTransform;
31 class Switch;
32 }
33 
34 namespace SurgSim
35 {
36 namespace Graphics
37 {
38 
39 class OsgMaterial;
40 class TangentSpaceGenerator;
41 class UniformBase;
42 
45 static const int TANGENT_VERTEX_ATTRIBUTE_ID = 6;
46 static const int BITANGENT_VERTEX_ATTRIBUTE_ID = 7;
47 static const int DIFFUSE_TEXTURE_UNIT = 0;
48 static const int NORMAL_TEXTURE_UNIT = 1;
49 static const int SHADOW_TEXTURE_UNIT = 8;
51 
55 class OsgRepresentation : public virtual Representation
56 {
57 public:
59  explicit OsgRepresentation(const std::string& name);
61  virtual ~OsgRepresentation();
62 
64  osg::ref_ptr<osg::Node> getOsgNode() const;
65 
70  bool setMaterial(std::shared_ptr<SurgSim::Framework::Component> material) override;
71 
74  std::shared_ptr<Material> getMaterial() const override;
75 
77  void clearMaterial() override;
78 
79  void setDrawAsWireFrame(bool val) override;
80 
81  bool getDrawAsWireFrame() const override;
82 
91  void setGenerateTangents(bool value) override;
92 
93  bool isGeneratingTangents() const override;
94 
97  void update(double dt) override;
98 
101  void addUniform(std::shared_ptr<SurgSim::Graphics::UniformBase> uniform);
102 
107  void addUniform(const std::string& type, const std::string& name, const boost::any& value);
108 
109 protected:
110  virtual void doUpdate(double dt);
111 
114  void setVisible(bool val);
115 
118  void updateTangents();
119 
121  osg::ref_ptr<osg::Switch> m_switch;
122 
124  osg::ref_ptr<osg::PositionAttitudeTransform> m_transform;
125 
127  osg::ref_ptr<osg::Group> m_materialProxy;
128 
130  std::shared_ptr<OsgMaterial> m_material;
131 
133  osg::ref_ptr<TangentSpaceGenerator> m_tangentGenerator;
134 
137 
138  std::shared_ptr<OsgUniform<SurgSim::Math::Matrix44f>> m_modelMatrixUniform;
139 
140 };
141 
142 }; // Graphics
143 }; // SurgSim
144 
145 #endif // SURGSIM_GRAPHICS_OSGREPRESENTATION_H
SurgSim::Graphics::OsgRepresentation::setDrawAsWireFrame
void setDrawAsWireFrame(bool val) override
Sets the representation to render as a wire frame.
Definition: OsgRepresentation.cpp:118
OsgUniform.h
SurgSim::Graphics::OsgRepresentation::isGeneratingTangents
bool isGeneratingTangents() const override
Definition: OsgRepresentation.cpp:162
SurgSim::Graphics::OsgRepresentation::addUniform
void addUniform(std::shared_ptr< SurgSim::Graphics::UniformBase > uniform)
Adds a uniform to this representation.
Definition: OsgRepresentation.cpp:175
osg
Definition: OculusView.h:25
SurgSim::Graphics::OsgRepresentation::getDrawAsWireFrame
bool getDrawAsWireFrame() const override
Return if the representation is rendered as a wire frame.
Definition: OsgRepresentation.cpp:136
Representation.h
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Graphics::OsgRepresentation::doUpdate
virtual void doUpdate(double dt)
Definition: OsgRepresentation.cpp:113
SurgSim::Graphics::OsgRepresentation::updateTangents
void updateTangents()
Causes the tangents to be recalculated if tangent generation is enabled Subclasses should call this w...
Definition: OsgRepresentation.cpp:167
SurgSim::Graphics::OsgRepresentation::OsgRepresentation
OsgRepresentation(const std::string &name)
Constructor.
Definition: OsgRepresentation.cpp:39
SurgSim::Graphics::OsgRepresentation::~OsgRepresentation
virtual ~OsgRepresentation()
Destructor.
Definition: OsgRepresentation.cpp:60
SurgSim::Graphics::OsgRepresentation::m_material
std::shared_ptr< OsgMaterial > m_material
Material defining the visual appearance of the representation.
Definition: OsgRepresentation.h:130
SurgSim::Graphics::OsgRepresentation::update
void update(double dt) override
Updates the representation.
Definition: OsgRepresentation.cpp:65
SurgSim::Graphics::OsgRepresentation::getMaterial
std::shared_ptr< Material > getMaterial() const override
Gets the material that defines the visual appearance of the representation.
Definition: OsgRepresentation.cpp:97
SurgSim::Graphics::OsgRepresentation::clearMaterial
void clearMaterial() override
Removes the material from the representation.
Definition: OsgRepresentation.cpp:102
SurgSim::Graphics::OsgRepresentation::m_transform
osg::ref_ptr< osg::PositionAttitudeTransform > m_transform
Transform used to pose the representation.
Definition: OsgRepresentation.h:124
SurgSim::Graphics::OsgRepresentation::m_drawAsWireFrame
bool m_drawAsWireFrame
Indicates if the representation is rendered as a wireframe.
Definition: OsgRepresentation.h:136
SurgSim::Graphics::OsgRepresentation::m_materialProxy
osg::ref_ptr< osg::Group > m_materialProxy
Holder for attributes coming from OsgMaterial.
Definition: OsgRepresentation.h:127
SurgSim::Graphics::OsgRepresentation::setVisible
void setVisible(bool val)
Set the visibility of this representation.
Definition: OsgRepresentation.cpp:141
SurgSim::Graphics::OsgRepresentation::m_modelMatrixUniform
std::shared_ptr< OsgUniform< SurgSim::Math::Matrix44f > > m_modelMatrixUniform
Definition: OsgRepresentation.h:138
SurgSim::Graphics::OsgRepresentation::getOsgNode
osg::ref_ptr< osg::Node > getOsgNode() const
Returns the root OSG Node for this representations portion of the scene graph.
Definition: OsgRepresentation.cpp:108
SurgSim::Graphics::OsgRepresentation::m_switch
osg::ref_ptr< osg::Switch > m_switch
Switch used to toggle the visibility of the representation.
Definition: OsgRepresentation.h:121
SurgSim::Graphics::OsgRepresentation::m_tangentGenerator
osg::ref_ptr< TangentSpaceGenerator > m_tangentGenerator
Visitor to generate tangents.
Definition: OsgRepresentation.h:133
SurgSim::Graphics::Representation
Base graphics representation class, which defines the interface that all graphics representations mus...
Definition: Representation.h:39
string
string(TOUPPER ${DEVICE} DEVICE_UPPER_CASE) option(BUILD_DEVICE_$
Definition: CMakeLists.txt:38
SurgSim::Graphics::OsgRepresentation::setMaterial
bool setMaterial(std::shared_ptr< SurgSim::Framework::Component > material) override
Sets the material that defines the visual appearance of the representation.
Definition: OsgRepresentation.cpp:83
SurgSim::Graphics::OsgRepresentation
Base OSG implementation of a graphics representation.
Definition: OsgRepresentation.h:55
SurgSim::Graphics::OsgRepresentation::setGenerateTangents
void setGenerateTangents(bool value) override
Enable the generation of tangents When enabled it is up to the subclasses responsibility to react to ...
Definition: OsgRepresentation.cpp:148