Scene.h
Go to the documentation of this file.
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_SCENE_H
17 #define SURGSIM_FRAMEWORK_SCENE_H
18 
19 #include <boost/thread/mutex.hpp>
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
26 
27 
28 namespace YAML
29 {
30 class Node;
31 }
32 
33 namespace SurgSim
34 {
35 namespace Framework
36 {
37 
38 class Logger;
39 class Runtime;
40 
42 class Scene : public std::enable_shared_from_this<Scene>
43 {
44 public:
45 
48  explicit Scene(std::weak_ptr<Runtime> runtime);
49 
51  ~Scene();
52 
55  void addSceneElement(std::shared_ptr<SceneElement> element);
56 
59  void removeSceneElement(std::shared_ptr<SceneElement> element);
60 
63  void addSceneElements(std::vector<std::shared_ptr<SceneElement>> elements);
64 
67  const std::vector<std::shared_ptr<SceneElement>>& getSceneElements() const;
68 
71  const std::shared_ptr<SceneElement> getSceneElement(const std::string& name) const;
72 
77  std::shared_ptr<Component> getComponent(const std::string& elementName, const std::string& componentName) const;
78 
81  std::shared_ptr<Runtime> getRuntime();
82 
85  YAML::Node encode() const;
86 
90  bool decode(const YAML::Node& node);
91 
94 
95 private:
96 
99  std::shared_ptr<Scene> getSharedPtr();
100  std::weak_ptr<Runtime> m_runtime;
101 
102  std::vector<std::shared_ptr<SceneElement>> m_elements;
103 
104  // Used in a const function, need to declare mutable
105  mutable boost::mutex m_sceneElementsMutex;
106 
108 
109  std::shared_ptr<Framework::Logger> m_logger;
110 };
111 
112 }; // namespace Framework
113 }; // namespace SurgSim
114 
115 #endif // SURGSIM_FRAMEWORK_SCENE_H
SurgSim::DataStructures::Groups
Class to wrap grouping operations, gives access to the members of a group and the groups of members.
Definition: Groups.h:37
SurgSim::Framework::Scene::removeSceneElement
void removeSceneElement(std::shared_ptr< SceneElement > element)
Removes a scene element from the Scene.
Definition: Scene.cpp:68
SurgSim::Framework::Scene::getSceneElement
const std::shared_ptr< SceneElement > getSceneElement(const std::string &name) const
Retrieve a SceneElement for this scene with the given name.
Definition: Scene.cpp:104
SurgSim::Framework::Scene::m_elements
std::vector< std::shared_ptr< SceneElement > > m_elements
Definition: Scene.h:102
Groups.h
SurgSim::Framework::Scene::m_runtime
std::weak_ptr< Runtime > m_runtime
Definition: Scene.h:100
SurgSim::Framework::Scene::~Scene
~Scene()
Destructor.
Definition: Scene.cpp:43
SurgSim::Framework::Scene::addSceneElement
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:48
SurgSim::Framework::Scene::Scene
Scene(std::weak_ptr< Runtime > runtime)
Constructor.
Definition: Scene.cpp:36
SurgSim::Framework::Scene::addSceneElements
void addSceneElements(std::vector< std::shared_ptr< SceneElement >> elements)
Invokes addSceneElement() for each element in the list.
Definition: Scene.cpp:86
SurgSim::Framework::Scene::m_sceneElementsMutex
boost::mutex m_sceneElementsMutex
Definition: Scene.h:105
YAML
Definition: DataStructuresConvert.h:28
SceneElement.h
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Framework::Scene::encode
YAML::Node encode() const
Convert to a YAML::Node.
Definition: Scene.cpp:133
SurgSim::Framework::Scene::getSharedPtr
std::shared_ptr< Scene > getSharedPtr()
Get a shared pointer to Scene.
Definition: Scene.cpp:119
SurgSim::Framework::Scene::decode
bool decode(const YAML::Node &node)
Pull data from a YAML::Node.
Definition: Scene.cpp:147
SurgSim::Framework::Scene::getSceneElements
const std::vector< std::shared_ptr< SceneElement > > & getSceneElements() const
Gets all the scene elements in the scene.
Definition: Scene.cpp:99
SurgSim::Framework::Scene::getComponent
std::shared_ptr< Component > getComponent(const std::string &elementName, const std::string &componentName) const
Look through the scene to find a component of a named element.
Definition: Scene.cpp:174
SurgSim::Framework::Scene::m_groups
SurgSim::DataStructures::Groups< std::string, std::shared_ptr< SceneElement > > m_groups
Definition: Scene.h:107
SurgSim::Framework::Scene::getRuntime
std::shared_ptr< Runtime > getRuntime()
Gets the runtime.
Definition: Scene.cpp:94
SurgSim::Framework::Scene::m_logger
std::shared_ptr< Framework::Logger > m_logger
Definition: Scene.h:109
SurgSim::Framework::Scene
Scene. Basic Container for SceneElements.
Definition: Scene.h:42
SurgSim::Framework::Scene::getGroups
SurgSim::DataStructures::Groups< std::string, std::shared_ptr< SceneElement > > & getGroups()
Definition: Scene.cpp:169