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 
105  const SurgSim::Math::RigidTransform3d& getPose() const;
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 
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
Definition: DriveElementFromInputBehavior.cpp:27
bool m_isInitialized
Indicates if this SceneElement has been initialized or not.
Definition: SceneElement.h:187
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< SurgSim::Framework::PoseComponent > m_pose
Definition: SceneElement.h:167
string(TOUPPER ${DEVICE}DEVICE_UPPER_CASE) option(BUILD_DEVICE_ $
Definition: CMakeLists.txt:35
bool m_isActive
Indicates if this SceneElement is active or not.
Definition: SceneElement.h:190
Definitions of 2x2 and 3x3 rigid (isometric) transforms.
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
Definition: DataStructuresConvert.h:28
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
std::unordered_map< std::string, std::shared_ptr< Component > > m_components
A collection of Components.
Definition: SceneElement.h:170