opensurgsim
SceneElement.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_FRAMEWORK_SCENEELEMENT_H
17 #define SURGSIM_FRAMEWORK_SCENEELEMENT_H
18 
19 #include <algorithm>
20 #include <boost/any.hpp>
21 #include <memory>
22 #include <string>
23 #include <unordered_map>
24 #include <unordered_set>
25 #include <vector>
26 
28 
29 
30 namespace YAML
31 {
32 class Node;
33 }
34 
35 namespace SurgSim
36 {
37 namespace Framework
38 {
39 
40 class Component;
41 class PoseComponent;
42 class Scene;
43 class Runtime;
44 
51 class SceneElement : public std::enable_shared_from_this<SceneElement>
52 {
53 public:
54 
57  explicit SceneElement(const std::string& name);
58 
60  virtual ~SceneElement();
61 
63  virtual std::string getClassName() const;
64 
68  bool addComponent(std::shared_ptr<Component> component);
69 
73  bool removeComponent(std::shared_ptr<Component> component);
74 
78  bool removeComponent(const std::string& name);
79 
81  void removeComponents();
82 
86  std::shared_ptr<Component> getComponent(const std::string& name) const;
87 
90  std::vector<std::shared_ptr<Component>> getComponents() const;
91 
94  template <class T>
95  std::vector<std::shared_ptr<T>> getComponents() const;
96 
103  template <class T>
104  T getValue(const std::string& component, const std::string& property) const;
105 
111  boost::any getValue(const std::string& component, const std::string& property) const;
112 
120  template <class T>
121  bool getValue(const std::string& component, const std::string& property, T* value) const;
122 
128  void setValue(const std::string& component, const std::string& property, const boost::any& value);
129 
132  void addToGroup(const std::string& group);
133 
136  void removeFromGroup(const std::string& group);
137 
140  void setGroups(const std::vector<std::string>& groups);
141 
143  std::vector<std::string> getGroups() const;
144 
148  bool inGroup(const std::string& name);
149 
152  bool initialize();
153 
156  std::string getName() const;
157 
160  void setPose(const SurgSim::Math::RigidTransform3d& pose);
161 
164  const SurgSim::Math::RigidTransform3d& getPose() const;
165 
169  std::shared_ptr<PoseComponent> getPoseComponent();
170 
173  void setScene(std::weak_ptr<Scene> scene);
174 
177  std::shared_ptr<Scene> getScene();
178 
181  void setRuntime(std::weak_ptr<Runtime> runtime);
184  std::shared_ptr<Runtime> getRuntime();
185 
188  bool isInitialized() const;
189 
196  void setActive(bool val);
197 
199  bool isActive() const;
200 
203  std::shared_ptr<SceneElement> getSharedPtr();
204 
209  virtual YAML::Node encode(bool standalone) const;
210 
215  virtual bool decode(const YAML::Node& node);
216 
217 private:
221  bool initializeComponent(std::shared_ptr<SurgSim::Framework::Component> component);
222 
224  std::string m_name;
225 
226  std::shared_ptr<SurgSim::Framework::PoseComponent> m_pose;
227 
229  std::unordered_map<std::string, std::shared_ptr<Component>> m_components;
230 
232  std::weak_ptr<Scene> m_scene;
233 
235  std::weak_ptr<Runtime> m_runtime;
236 
238  std::unordered_set<std::string> m_groups;
239 
242  virtual bool doInitialize() = 0;
243 
246  void setName(const std::string& name);
247 
249  bool m_isInitialized;
250 
252  bool m_isActive;
253 };
254 
255 }; // namespace Framework
256 }; // namespace SurgSim
257 
258 #include "SurgSim/Framework/SceneElement-inl.h"
259 
260 #endif // SURGSIM_FRAMEWORK_SCENEELEMENT_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
Definitions of 2x2 and 3x3 rigid (isometric) transforms.
Definition: DataStructuresConvert.h:28
SceneElement is the basic part of a scene, it is a container of components.
Definition: SceneElement.h:51