iMSTK
Interactive Medical Simulation Toolkit
imstkSimulationManager.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 "imstkModuleDriver.h"
10 
11 #include <unordered_map>
12 
13 namespace imstk
14 {
15 class Viewer;
16 
31 {
32 public:
33  // Generally STL is better for less interruption
34  enum class ThreadingType
35  {
36  TBB,
37  STL
38  };
39 
40  SimulationManager() = default;
41  ~SimulationManager() override = default;
42 
43  // *INDENT-OFF*
47  SIGNAL(SimulationManager, starting);
48 
52  SIGNAL(SimulationManager, ending);
53  // *INDENT-ON*
54 
55  void start() override;
56 
61  void addModule(std::shared_ptr<Module> module) override;
62 
66  void clearModules() override;
67 
73  void setDesiredDt(const double dt)
74  {
75  m_desiredDt = dt;
76  }
77 
78  double getDesiredDt() const
79  {
80  return m_desiredDt;
81  }
82 
86  double getDt() const
87  {
88  return m_dt;
89  }
90 
94  void setThreadType(ThreadingType threadType)
95  {
96  m_threadType = threadType;
97  }
98 
105  void setUseRemainderTimeDivide(const bool useRemainderTimeDivide) { m_useRemainderTimeDivide = useRemainderTimeDivide; }
106  bool getUseRemainderTimeDivide() const { return m_useRemainderTimeDivide; }
108 
109 protected:
110  void requestStop(Event* e);
111 
112  void runModuleParallel(std::shared_ptr<Module> module);
113 
114  std::vector<std::shared_ptr<Viewer>> m_viewers;
115 
116  std::unordered_map<Module*, bool> m_running;
117 
118  std::vector<std::shared_ptr<Module>> m_syncModules;
119  std::vector<std::shared_ptr<Module>> m_asyncModules;
120  std::vector<std::shared_ptr<Module>> m_adaptiveModules;
121 
122  ThreadingType m_threadType = ThreadingType::STL;
123  double m_desiredDt = 0.003;
124  double m_dt = 0.0;
125  int m_numSteps = 0;
127 };
128 }; // namespace imstk
double m_desiredDt
Desired timestep.
void setDesiredDt(const double dt)
Sets the target fixed timestep (may violate), seconds This ultimately effects the number of iteration...
void setThreadType(ThreadingType threadType)
Set the thread type to run the parallel modules with.
Defines a sequential substepping approach to driving the modules and rendering. The user provides a d...
Base class for events which contain a type, priority, and data priority defaults to 0 and uses a grea...
void setUseRemainderTimeDivide(const bool useRemainderTimeDivide)
The number of substeps is computed as N = (accumulated time / desiredDt). This leaves a remainder...
Compound Geometry.
void addModule(std::shared_ptr< Module > module) override
Add a module to run.
std::vector< std::shared_ptr< Module > > m_adaptiveModules
Modules that update adpatively to keep up with real time.
std::vector< std::shared_ptr< Module > > m_asyncModules
Modules that run on completely other threads without restraint.
std::vector< std::shared_ptr< Module > > m_syncModules
Modules called once per update.
bool m_useRemainderTimeDivide
Whether to divide out remainder time or not.
double m_dt
Actual timestep.
Base class for viewer that manages render window and the renderers /// Creates backend-specific rende...
SIGNAL(SimulationManager, starting)
Called after initialization but before starting the loop.
void clearModules() override
Remove all modules.
Defines the control of modules.
double getDt() const
Get the current actual timestep.