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
bool m_drawAsWireFrame
Indicates if the representation is rendered as a wireframe.
Definition: OsgRepresentation.h:136
Definition: CompoundShapeToGraphics.cpp:29
osg::ref_ptr< osg::Group > m_materialProxy
Holder for attributes coming from OsgMaterial.
Definition: OsgRepresentation.h:127
osg::ref_ptr< osg::Switch > m_switch
Switch used to toggle the visibility of the representation.
Definition: OsgRepresentation.h:121
osg::ref_ptr< osg::PositionAttitudeTransform > m_transform
Transform used to pose the representation.
Definition: OsgRepresentation.h:124
std::shared_ptr< OsgUniform< SurgSim::Math::Matrix44f > > m_modelMatrixUniform
Definition: OsgRepresentation.h:138
osg::ref_ptr< TangentSpaceGenerator > m_tangentGenerator
Visitor to generate tangents.
Definition: OsgRepresentation.h:133
Base graphics representation class, which defines the interface that all graphics representations mus...
Definition: Representation.h:39
Definition: OculusView.h:25
std::shared_ptr< OsgMaterial > m_material
Material defining the visual appearance of the representation.
Definition: OsgRepresentation.h:130
Base OSG implementation of a graphics representation.
Definition: OsgRepresentation.h:55