iMSTK
Interactive Medical Simulation Toolkit
imstkModule.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 "imstkTimer.h"
10 #include "imstkEventObject.h"
11 
12 namespace imstk
13 {
21 class Module : public EventObject
22 {
23 public:
28  enum class ExecutionType
29  {
30  SEQUENTIAL, // Should run in sync with other sequential modules
31  PARALLEL, // Should run in parallel
32  ADAPTIVE // Runs governed by module
33  };
34 
35  Module() = default;
36  ~Module() override = default;
37 
41  virtual const std::string getTypeName() const = 0;
42 
43  // *INDENT-OFF*
47  SIGNAL(Module, preUpdate);
48 
52  SIGNAL(Module, postUpdate);
53 
57  SIGNAL(Module, end);
58  // *INDENT-ON*
59 
63  double getDt() const { return m_dt; }
64  void setDt(const double dt) { m_dt = dt; }
65 
69  bool getInit() const { return m_init; }
70 
74  bool getPaused() const { return m_paused; }
75  void setPaused(const bool paused) { m_paused = paused; }
76 
80  void setMuteUpdateEvents(const bool mute) { m_muteUpdateEvents = mute; }
81  bool getMuteUpdateEvents() const { return m_muteUpdateEvents; }
82 
86  ExecutionType getExecutionType() const { return m_executionType; }
87  void setExecutionType(const ExecutionType type) { m_executionType = type; }
88 
89  void setSleepDelay(const double ms);
90  double getSleepDelay() const { return m_sleepDelay; }
91 
92  void pause() { m_paused = true; }
93  void resume() { m_paused = false; }
94 
95  void init() { m_init = initModule(); }
96 
97  void update();
98 
99  void uninit();
100 
101  virtual bool initModule() = 0;
102 
103  virtual void updateModule() = 0;
104 
105  virtual void uninitModule() { }
106 
107 protected:
108  std::atomic<bool> m_init = ATOMIC_VAR_INIT(false);
109  std::atomic<bool> m_paused = ATOMIC_VAR_INIT(false);
110  double m_dt = 0.0;
111  ExecutionType m_executionType = ExecutionType::PARALLEL; // Defaults to parallel, subclass and set
112  bool m_muteUpdateEvents = false; // Avoid posting pre/post update, useful when running modules at extremely fast rates
113  double m_sleepDelay = 0.0; // ms sleep for the module, useful for throttling some modules
114 };
115 } // namespace imstk
virtual const std::string getTypeName() const =0
Returns collision detection type string name.
ExecutionType
Currently 3 execution types are provided. These inform the driver on how it should run...
Definition: imstkModule.h:28
bool getPaused() const
Set/Get whether the module is currently paused.
Definition: imstkModule.h:74
ExecutionType getExecutionType() const
Set/Get the execution type (see imstk::ExecutionType)
Definition: imstkModule.h:86
Compound Geometry.
bool getInit() const
Get whether the module is initialized yet.
Definition: imstkModule.h:69
double getDt() const
Get/Set the time step.
Definition: imstkModule.h:63
void setMuteUpdateEvents(const bool mute)
Set/Get whether the module should post pre/post update events.
Definition: imstkModule.h:80
EventObject is the base class for all objects in iMSTK that can receive and emit events. It supports direct and queued observer functions. Direct observers receive events immediately on the same thread This can either be posted on an object or be a function pointer Queued observers receive events within their queue which they can process whenever they like. These can be connected with the connect/queuedConnect/disconnect functions Lambda recievers cannot be disconnected unless all receivers to a signal are removed.
SIGNAL(Module, preUpdate)
Posted before updateModule is called.
Base class for imstk module system. A module defines something that is updated, and can be paused/res...
Definition: imstkModule.h:21