iMSTK
Interactive Medical Simulation Toolkit
imstkSceneManager.h
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #pragma once
8 
9 #include "imstkModule.h"
10 #include "imstkMacros.h"
11 
12 #include <unordered_map>
13 #include <thread>
14 
15 namespace imstk
16 {
17 class Scene;
18 
24 class SceneManager : public Module
25 {
26 public:
27  enum class Mode
28  {
29  Simulation,
30  Debug
31  };
32 
33  SceneManager(std::string name = "SceneManager");
34  ~SceneManager() override = default;
35 
36  IMSTK_TYPE_NAME(SceneManager)
37 
38 
39  std::shared_ptr<Scene> getActiveScene() const { return m_activeScene; }
42 
46  std::shared_ptr<Scene> getScene(std::string name) const
47  {
48  if (containsScene(name))
49  {
50  return m_sceneMap.at(name);
51  }
52  else
53  {
54  return nullptr;
55  }
56  }
57 
61  Mode getMode() const { return m_mode; }
62 
67  void setMode(Mode mode);
68 
72  bool containsScene(std::string name) const;
73 
77  void setActiveScene(std::string newSceneName);
78 
82  void setActiveScene(std::shared_ptr<Scene> scene);
83 
87  void addScene(std::shared_ptr<Scene> scene);
88 
92  void removeScene(std::string name);
93 
97  bool initModule() override;
98 
102  void updateModule() override;
103 
104 protected:
105  std::shared_ptr<Scene> m_activeScene;
106  std::unordered_map<std::string, std::shared_ptr<Scene>> m_sceneMap; // used in backend mode where m_sceneManagerMap is not used
107  Mode m_mode;
108  std::string m_prevCamName;
109 };
110 } // namespace imstk
std::shared_ptr< Scene > getActiveScene() const
Get the scene that the scene manager is managing.
std::shared_ptr< Scene > m_activeScene
Scene that is being managed.
void updateModule() override
Run the thread.
Compound Geometry.
Mode getMode() const
Get the current mode.
void removeScene(std::string name)
Remove a scene from the manager.
std::shared_ptr< Scene > getScene(std::string name) const
Search for scene by name, returns nullptr if not found.
void setMode(Mode mode)
Switches the mode of the scene manager This alters the active scene.
void addScene(std::shared_ptr< Scene > scene)
Adds scene to the manager.
Scene manager module manages multiple scenes and runs the active one.
bool initModule() override
Initialize the thread.
void setActiveScene(std::string newSceneName)
Sets the currently updating scene.
bool containsScene(std::string name) const
Returns if the SceneManager contains the scene or not.
Base class for imstk module system. A module defines something that is updated, and can be paused/res...
Definition: imstkModule.h:21