All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SceneElement.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, 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_FRAMEWORK_SCENEELEMENT_H
17 #define SURGSIM_FRAMEWORK_SCENEELEMENT_H
18 
19 #include <string>
20 #include <memory>
21 #include <algorithm>
22 #include <unordered_map>
23 #include <vector>
24 
26 
27 namespace YAML
28 {
29 class Node;
30 }
31 
32 namespace SurgSim
33 {
34 namespace Framework
35 {
36 
37 class Component;
38 class PoseComponent;
39 class Scene;
40 class Runtime;
41 
48 class SceneElement : public std::enable_shared_from_this<SceneElement>
49 {
50 public:
51 
54  explicit SceneElement(const std::string& name);
55 
57  virtual ~SceneElement();
58 
60  virtual std::string getClassName() const;
61 
65  bool addComponent(std::shared_ptr<Component> component);
66 
70  bool removeComponent(std::shared_ptr<Component> component);
71 
75  bool removeComponent(const std::string& name);
76 
80  std::shared_ptr<Component> getComponent(const std::string& name) const;
81 
84  std::vector<std::shared_ptr<Component> > getComponents() const;
85 
88  template <class T>
89  std::vector<std::shared_ptr<T>> getComponents() const;
90 
93  bool initialize();
94 
97  std::string getName() const;
98 
101  void setPose(const SurgSim::Math::RigidTransform3d& pose);
102 
106 
110  std::shared_ptr<PoseComponent> getPoseComponent();
111 
114  void setScene(std::weak_ptr<Scene> scene);
115 
118  std::shared_ptr<Scene> getScene();
119 
122  void setRuntime(std::weak_ptr<Runtime> runtime);
125  std::shared_ptr<Runtime> getRuntime();
126 
129  bool isInitialized() const;
130 
137  void setActive(bool val);
138 
140  bool isActive() const;
141 
144  std::shared_ptr<SceneElement> getSharedPtr();
145 
150  virtual YAML::Node encode(bool standalone) const;
151 
156  virtual bool decode(const YAML::Node& node);
157 
158 private:
162  bool initializeComponent(std::shared_ptr<SurgSim::Framework::Component> component);
163 
165  std::string m_name;
166 
167  std::shared_ptr<SurgSim::Framework::PoseComponent> m_pose;
168 
170  std::unordered_map<std::string, std::shared_ptr<Component>> m_components;
171 
173  std::weak_ptr<Scene> m_scene;
174 
176  std::weak_ptr<Runtime> m_runtime;
177 
180  virtual bool doInitialize() = 0;
181 
184  void setName(const std::string& name);
185 
188 
191 };
192 
193 }; // namespace Framework
194 }; // namespace SurgSim
195 
197 
198 #endif // SURGSIM_FRAMEWORK_SCENEELEMENT_H
bool m_isInitialized
Indicates if this SceneElement has been initialized or not.
Definition: SceneElement.h:187
std::shared_ptr< PoseComponent > getPoseComponent()
Get the PoseComponent that controls the pose all Representations in this SceneElement.
Definition: SceneElement.cpp:151
void setRuntime(std::weak_ptr< Runtime > runtime)
Sets the Runtime.
Definition: SceneElement.cpp:181
std::shared_ptr< Runtime > getRuntime()
Gets the runtime.
Definition: SceneElement.cpp:186
bool initializeComponent(std::shared_ptr< SurgSim::Framework::Component > component)
Initialize the given component.
Definition: SceneElement.cpp:130
virtual bool decode(const YAML::Node &node)
Pull data from a YAML::Node.
Definition: SceneElement.cpp:237
virtual std::string getClassName() const
Definition: SceneElement.cpp:278
const SurgSim::Math::RigidTransform3d & getPose() const
Get the pose of this SceneElement.
Definition: SceneElement.cpp:146
std::string getName() const
Return the name of this SceneElement.
Definition: SceneElement.cpp:136
void setPose(const SurgSim::Math::RigidTransform3d &pose)
Set the pose of this SceneElement.
Definition: SceneElement.cpp:141
std::shared_ptr< Component > getComponent(const std::string &name) const
Gets the component identified by name.
Definition: SceneElement.cpp:98
std::weak_ptr< Runtime > m_runtime
A (weak) back pointer to the Runtime containing this SceneElement.
Definition: SceneElement.h:176
std::string m_name
Name of this SceneElement.
Definition: SceneElement.h:165
std::shared_ptr< SceneElement > getSharedPtr()
Gets a shared pointer to this SceneElement.
Definition: SceneElement.cpp:196
std::shared_ptr< SurgSim::Framework::PoseComponent > m_pose
Definition: SceneElement.h:167
virtual YAML::Node encode(bool standalone) const
Convert to a YAML::Node.
Definition: SceneElement.cpp:215
virtual bool doInitialize()=0
Method to initialize this SceneElement.
void setName(const std::string &name)
Sets the name of this SceneElement.
Definition: SceneElement.cpp:210
bool m_isActive
Indicates if this SceneElement is active or not.
Definition: SceneElement.h:190
Definitions of 2x2 and 3x3 rigid (isometric) transforms.
bool isActive() const
Definition: SceneElement.cpp:289
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
bool isInitialized() const
Return if this SceneElement is initialized.
Definition: SceneElement.cpp:191
bool addComponent(std::shared_ptr< Component > component)
Adds a component, calls initialize() on the component, if SceneElement::isInitialized() is true...
Definition: SceneElement.cpp:46
bool removeComponent(std::shared_ptr< Component > component)
Removes a given component.
Definition: SceneElement.cpp:82
std::vector< std::shared_ptr< Component > > getComponents() const
Gets all the components of this SceneElement.
Definition: SceneElement.cpp:156
virtual ~SceneElement()
Destructor.
Definition: SceneElement.cpp:41
std::weak_ptr< Scene > m_scene
A (weak) back pointer to the Scene containing this SceneElement.
Definition: SceneElement.h:173
SceneElement is the basic part of a scene, it is a container of components.
Definition: SceneElement.h:48
void setActive(bool val)
Set this SceneElement's status (active/inactive)
Definition: SceneElement.cpp:284
std::unordered_map< std::string, std::shared_ptr< Component > > m_components
A collection of Components.
Definition: SceneElement.h:170
std::shared_ptr< Scene > getScene()
Gets the Scene.
Definition: SceneElement.cpp:176
bool initialize()
Executes the initialize operation.
Definition: SceneElement.cpp:110
SceneElement(const std::string &name)
Constructor.
Definition: SceneElement.cpp:31
void setScene(std::weak_ptr< Scene > scene)
Sets the Scene.
Definition: SceneElement.cpp:167