Scene.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_SCENE_H
17 #define SURGSIM_FRAMEWORK_SCENE_H
18 
19 #include <vector>
20 #include <memory>
21 #include <string>
22 #include <boost/thread/mutex.hpp>
23 
25 
26 namespace YAML
27 {
28 class Node;
29 }
30 
31 namespace SurgSim
32 {
33 namespace Framework
34 {
35 
36 class Runtime;
37 
39 class Scene : public std::enable_shared_from_this<Scene>
40 {
41 public:
42 
45  explicit Scene(std::weak_ptr<Runtime> runtime);
46 
48  ~Scene();
49 
52  void addSceneElement(std::shared_ptr<SceneElement> element);
53 
56  const std::vector<std::shared_ptr<SceneElement>>& getSceneElements() const;
57 
60  const std::shared_ptr<SceneElement> getSceneElement(const std::string& name) const;
61 
64  std::shared_ptr<Runtime> getRuntime();
65 
68  YAML::Node encode() const;
69 
73  bool decode(const YAML::Node& node);
74 
75 private:
76 
79  std::shared_ptr<Scene> getSharedPtr();
80 
81  std::weak_ptr<Runtime> m_runtime;
82 
83  std::vector<std::shared_ptr<SceneElement>> m_elements;
84 
85  // Used in a const function, need to declare mutable
86  mutable boost::mutex m_sceneElementsMutex;
87 };
88 
89 }; // namespace Framework
90 }; // namespace SurgSim
91 
92 #endif // SURGSIM_FRAMEWORK_SCENE_H
Definition: DriveElementFromInputBehavior.cpp:27
bool decode(const YAML::Node &node)
Pull data from a YAML::Node.
Definition: Scene.cpp:121
void addSceneElement(std::shared_ptr< SceneElement > element)
Adds a scene element to the Scene, the SceneElement will have its initialize() function called...
Definition: Scene.cpp:47
Scene. Basic Container for SceneElements.
Definition: Scene.h:39
boost::mutex m_sceneElementsMutex
Definition: Scene.h:86
std::shared_ptr< Runtime > getRuntime()
Gets the runtime.
Definition: Scene.cpp:68
std::shared_ptr< Scene > getSharedPtr()
Get a shared pointer to Scene.
Definition: Scene.cpp:93
YAML::Node encode() const
Convert to a YAML::Node.
Definition: Scene.cpp:107
std::vector< std::shared_ptr< SceneElement > > m_elements
Definition: Scene.h:83
const std::vector< std::shared_ptr< SceneElement > > & getSceneElements() const
Gets all the scene elements in the scene.
Definition: Scene.cpp:73
const std::shared_ptr< SceneElement > getSceneElement(const std::string &name) const
Retrieve a SceneElement for this scene with the given name.
Definition: Scene.cpp:78
Definition: DataStructuresConvert.h:28
std::weak_ptr< Runtime > m_runtime
Definition: Scene.h:81
~Scene()
Destructor.
Definition: Scene.cpp:42
Scene(std::weak_ptr< Runtime > runtime)
Constructor.
Definition: Scene.cpp:36