opensurgsim
OsgRepresentation.h
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 
23 #include "SurgSim/Graphics/Representation.h"
24 #include "SurgSim/Graphics/OsgUniform.h"
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 
99  void addUniform(std::shared_ptr<UniformBase> uniform) override;
100 
101  void addUniform(const std::string& type, const std::string& name, const boost::any& value) override;
102 
103  void setUniforms(const std::vector<std::shared_ptr<UniformBase>>& uniforms) override;
104 
105  std::vector<std::shared_ptr<UniformBase>> getUniforms() const override;
106 
107 protected:
108  void doRetire() override;
109 
110  virtual void doUpdate(double dt);
111 
114  void setVisible(bool val);
115 
118  void updateTangents();
119 
122  void setOsgUniforms(const std::vector<std::shared_ptr<Graphics::OsgUniformBase>>& uniforms);
123 
125  std::vector<std::shared_ptr<Graphics::OsgUniformBase>> getOsgUniforms() const;
126 
128  osg::ref_ptr<osg::Switch> m_switch;
129 
131  osg::ref_ptr<osg::PositionAttitudeTransform> m_transform;
132 
134  osg::ref_ptr<osg::Group> m_materialProxy;
135 
137  std::shared_ptr<OsgMaterial> m_material;
138 
140  osg::ref_ptr<TangentSpaceGenerator> m_tangentGenerator;
141 
144 
145  std::shared_ptr<OsgUniform<SurgSim::Math::Matrix44f>> m_modelMatrixUniform;
146 
147  std::vector<std::shared_ptr<OsgUniformBase>> m_uniforms;
148 };
149 
150 }; // Graphics
151 }; // SurgSim
152 
153 #endif // SURGSIM_GRAPHICS_OSGREPRESENTATION_H
bool m_drawAsWireFrame
Indicates if the representation is rendered as a wireframe.
Definition: OsgRepresentation.h:143
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
osg::ref_ptr< osg::Group > m_materialProxy
Holder for attributes coming from OsgMaterial.
Definition: OsgRepresentation.h:134
osg::ref_ptr< osg::Switch > m_switch
Switch used to toggle the visibility of the representation.
Definition: OsgRepresentation.h:128
osg::ref_ptr< osg::PositionAttitudeTransform > m_transform
Transform used to pose the representation.
Definition: OsgRepresentation.h:131
osg::ref_ptr< TangentSpaceGenerator > m_tangentGenerator
Visitor to generate tangents.
Definition: OsgRepresentation.h:140
Base graphics representation class, which defines the interface that all graphics representations mus...
Definition: Representation.h:40
Definition: OsgImGuiHandler.h:8
std::shared_ptr< OsgMaterial > m_material
Material defining the visual appearance of the representation.
Definition: OsgRepresentation.h:137
Base OSG implementation of a graphics representation.
Definition: OsgRepresentation.h:55