opensurgsim
Representation.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_REPRESENTATION_H
17 #define SURGSIM_GRAPHICS_REPRESENTATION_H
18 
19 #include "SurgSim/Framework/Representation.h"
20 
22 
23 #include <unordered_set>
24 
25 namespace SurgSim
26 {
27 
28 namespace Graphics
29 {
30 
31 class Manager;
32 class Material;
33 class UniformBase;
34 
41 {
42 public:
43 
44  static const std::string DefaultGroupName;
45  static const std::string DefaultHudGroupName;
46 
49  explicit Representation(const std::string& name);
50 
52  virtual ~Representation();
53 
57  virtual bool setMaterial(std::shared_ptr<SurgSim::Framework::Component> material) = 0;
58 
61  virtual std::shared_ptr<Material> getMaterial() const = 0;
62 
63  void setMaterialReference(const std::string& materialName);
64 
65  std::string getMaterialReference() const;
66 
68  virtual void clearMaterial() = 0;
69 
72  virtual void setDrawAsWireFrame(bool val) = 0;
73 
76  virtual bool getDrawAsWireFrame() const = 0;
77 
80  virtual void setGenerateTangents(bool value) = 0;
81 
83  virtual bool isGeneratingTangents() const = 0;
84 
87  virtual void update(double dt) = 0;
88 
93  virtual bool addGroupReference(const std::string& name);
94 
95 
98  void addGroupReferences(const std::vector<std::string>& groups);
99 
102  void setGroupReferences(const std::vector<std::string>& groups);
103 
107  void setGroupReference(const std::string& group);
108 
111  std::vector<std::string> getGroupReferences() const;
112 
116  bool removeGroupReference(const std::string& group);
117 
119  void clearGroupReferences();
120 
123  virtual void addUniform(std::shared_ptr<UniformBase> uniform) = 0;
124 
129  virtual void addUniform(const std::string& type, const std::string& name, const boost::any& value) = 0;
130 
133  virtual void setUniforms(const std::vector<std::shared_ptr<UniformBase>>& uniforms) = 0;
134 
136  virtual std::vector<std::shared_ptr<UniformBase>> getUniforms() const = 0;
137 
138  bool doWakeUp() override;
139 
140 private:
142  std::unordered_set<std::string> m_groups;
143 
147  bool checkAwake(const std::string& functionName);
148 
150  std::string m_materialReference;
151 };
152 
153 }; // namespace Graphics
154 }; // namespace SurgSim
155 
156 #endif // SURGSIM_GRAPHICS_REPRESENTATION_H
virtual ~Representation()
Destructor.
Definition: Representation.cpp:152
virtual void addUniform(std::shared_ptr< UniformBase > uniform)=0
Adds a uniform to this representation.
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
Representation(const std::string &name)
Constructor.
Definition: Representation.cpp:34
void setGroupReference(const std::string &group)
Helper functions, this clears all the references and sets, only the reference given in the parameter...
Definition: Representation.cpp:132
void clearGroupReferences()
Clear all the Group references.
Definition: Representation.cpp:88
virtual std::shared_ptr< Material > getMaterial() const =0
Gets the material that defines the visual appearance of the representation.
virtual std::vector< std::shared_ptr< UniformBase > > getUniforms() const =0
bool doWakeUp() override
Interface to be implemented by derived classes.
Definition: Representation.cpp:96
virtual void setDrawAsWireFrame(bool val)=0
Sets the representation to render as a wire frame.
virtual void setUniforms(const std::vector< std::shared_ptr< UniformBase >> &uniforms)=0
Sets a set of uniforms for this representation.
virtual bool getDrawAsWireFrame() const =0
Return if the representation is rendered as a wire frame.
Base graphics representation class, which defines the interface that all graphics representations mus...
Definition: Representation.h:40
std::vector< std::string > getGroupReferences() const
Gets group references.
Definition: Representation.cpp:83
Definitions of 2x2 and 3x3 rigid (isometric) transforms.
virtual void setGenerateTangents(bool value)=0
Enable or disable the generation of tangents.
void addGroupReferences(const std::vector< std::string > &groups)
Adds a list of group references.
Definition: Representation.cpp:60
virtual bool setMaterial(std::shared_ptr< SurgSim::Framework::Component > material)=0
Sets the material that defines the visual appearance of the representation.
virtual void update(double dt)=0
Updates the representation.
virtual bool addGroupReference(const std::string &name)
Add a reference to a group, this will eventual add this representation to the group with the the same...
Definition: Representation.cpp:49
Representations are manifestations of a SceneElement.
Definition: Representation.h:33
virtual void clearMaterial()=0
Removes the material from the representation.
virtual bool isGeneratingTangents() const =0
void setGroupReferences(const std::vector< std::string > &groups)
Sets the list of group references.
Definition: Representation.cpp:71
bool removeGroupReference(const std::string &group)
Function to remove an unwanted reference.
Definition: Representation.cpp:122