iMSTK
Interactive Medical Simulation Toolkit
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
imstk::SimulationManager Class Reference

Defines a sequential substepping approach to driving the modules and rendering. The user provides a desired timestep and as it runs it accumulates time. It then determines how many simulation steps before every render (simply accumulated time / timestep = substeps). The remainder is divided out over the substeps. This is the preferred driver. todo: Timestep smoothening. More...

#include <imstkSimulationManager.h>

Inheritance diagram for imstk::SimulationManager:
Inheritance graph
[legend]
Collaboration diagram for imstk::SimulationManager:
Collaboration graph
[legend]

Public Types

enum  ThreadingType { TBB, STL }
 
- Public Types inherited from imstk::EventObject
using Observer = std::tuple< bool, std::weak_ptr< EventObject >, std::function< void(Event *)> >
 

Public Member Functions

 SIGNAL (SimulationManager, starting)
 Called after initialization but before starting the loop.
 
 SIGNAL (SimulationManager, ending)
 Called after ending, but before un initialization.
 
void start () override
 
void addModule (std::shared_ptr< Module > module) override
 Add a module to run. More...
 
void clearModules () override
 Remove all modules.
 
void setDesiredDt (const double dt)
 Sets the target fixed timestep (may violate), seconds This ultimately effects the number of iterations done default 0.003.
 
double getDesiredDt () const
 
double getDt () const
 Get the current actual timestep.
 
void setThreadType (ThreadingType threadType)
 Set the thread type to run the parallel modules with.
 
void setUseRemainderTimeDivide (const bool useRemainderTimeDivide)
 The number of substeps is computed as N = (accumulated time / desiredDt). This leaves a remainder. Off gives a completely fixed timestep, on provides semi-fixed timestep. When off, the remainder is accumulated for later iterations, causing extra iterations now and then (possible stutter). When on, the remainder time is divided out over the N substeps.
 
bool getUseRemainderTimeDivide () const
 
- Public Member Functions inherited from imstk::ModuleDriver
void requestStatus (ModuleDriverStatus status)
 
ModuleDriverStatus getStatus () const
 
std::vector< std::shared_ptr< Module > > & getModules ()
 
void waitForInit ()
 Wait for all modules to init.
 
- Public Member Functions inherited from imstk::EventObject
template<typename T >
void postEvent (const T &e)
 Emits the event Direct observers will be immediately called, in sync Queued observers will receive the Command in their queue for later execution, reciever must implement doEvent.
 
template<typename T >
void queueEvent (const T &e)
 Queues event directly to this.
 
void doEvent ()
 Do an event, if none exists return.
 
void doAllEvents ()
 Do all the events in the event queue.
 
void foreachEvent (std::function< void(Command cmd)> func)
 Thread safe loop over all event commands, one can implement a custom handler.
 
void rforeachEvent (std::function< void(Command cmd)> func)
 thread safe reverse loop over all event commands, one can implement a custom handler
 
void clearEvents ()
 Removes all events from queue cleans up copies of the event.
 

Protected Member Functions

void requestStop (Event *e)
 
void runModuleParallel (std::shared_ptr< Module > module)
 

Protected Attributes

std::vector< std::shared_ptr< Viewer > > m_viewers
 
std::unordered_map< Module *, bool > m_running
 
std::vector< std::shared_ptr< Module > > m_syncModules
 Modules called once per update.
 
std::vector< std::shared_ptr< Module > > m_asyncModules
 Modules that run on completely other threads without restraint.
 
std::vector< std::shared_ptr< Module > > m_adaptiveModules
 Modules that update adpatively to keep up with real time.
 
ThreadingType m_threadType = ThreadingType::STL
 
double m_desiredDt = 0.003
 Desired timestep.
 
double m_dt = 0.0
 Actual timestep.
 
int m_numSteps = 0
 
bool m_useRemainderTimeDivide = true
 Whether to divide out remainder time or not.
 
- Protected Attributes inherited from imstk::ModuleDriver
std::vector< std::shared_ptr< Module > > m_modules
 
std::atomic< ModuleDriverStatus > simState = { ModuleDriverRunning }
 
- Protected Attributes inherited from imstk::EventObject
ParallelUtils::SpinLock eventQueueLock
 
std::deque< CommandeventQueue
 
std::vector< std::pair< std::string, std::vector< Observer > > > queuedObservers
 
std::vector< std::pair< std::string, std::vector< Observer > > > directObservers
 

Detailed Description

Defines a sequential substepping approach to driving the modules and rendering. The user provides a desired timestep and as it runs it accumulates time. It then determines how many simulation steps before every render (simply accumulated time / timestep = substeps). The remainder is divided out over the substeps. This is the preferred driver. todo: Timestep smoothening.

Events: Posts EventType::Start just before the beginning of the loop, posts EventType::Stop just after the processing loops is being exited

Definition at line 30 of file imstkSimulationManager.h.

Member Function Documentation

◆ addModule()

void imstk::SimulationManager::addModule ( std::shared_ptr< Module module)
overridevirtual

Add a module to run.

Parameters
Themodule to run

Reimplemented from imstk::ModuleDriver.

Definition at line 193 of file imstkSimulationManager.cpp.

Here is the call graph for this function:

The documentation for this class was generated from the following files: