iMSTK
Interactive Medical Simulation Toolkit
imstkAbstractDynamicalModel.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 "imstkGeometry.h"
10 
11 #include <set>
12 
13 namespace imstk
14 {
15 class TaskGraph;
16 class TaskNode;
17 
22 {
23  RigidBodyDynamics,
24  ElastoDynamics,
25  PositionBasedDynamics,
26  SmoothedParticleHydrodynamics,
27  Physiology,
28  None
29 };
30 
34 enum class TimeSteppingType
35 {
36  RealTime,
37  Fixed
38 };
39 
46 {
47 public:
51  enum class StateUpdateType
52  {
53  Displacement,
54  Velocity,
55  DeltaDisplacement,
56  DeltaVelocity,
57  None
58  };
59 
60 protected:
61  AbstractDynamicalModel(DynamicalModelType type = DynamicalModelType::None);
62 
63 public:
64  virtual ~AbstractDynamicalModel() = default;
65 
69  virtual void resetToInitialState() = 0;
70 
74  std::size_t getNumDegreeOfFreedom() const { return m_numDof; }
75  void setNumDegreeOfFreedom(const size_t nDof) { m_numDof = nDof; }
77 
78  std::shared_ptr<TaskGraph> getTaskGraph() const { return m_taskGraph; }
79 
83  const DynamicalModelType& getType() const { return m_type; }
84 
88  virtual void updatePhysicsGeometry() { }
89 
93  virtual void setTimeStep(const double timeStep) = 0;
94 
98  void setModelGeometry(std::shared_ptr<Geometry> geometry);
99 
103  bool isGeometryValid(const std::shared_ptr<Geometry> geometry);
104 
108  std::shared_ptr<Geometry> getModelGeometry() const { return m_geometry; }
109 
113  virtual double getTimeStep() const = 0;
114 
118  virtual bool initialize() = 0;
119 
123  void initGraphEdges();
124 
128  virtual void setTimeStepSizeType(const TimeSteppingType type) { m_timeStepSizeType = type; }
129  TimeSteppingType getTimeStepSizeType() const { return m_timeStepSizeType; }
131 
132 protected:
136  virtual void initGraphEdges(std::shared_ptr<TaskNode> source, std::shared_ptr<TaskNode> sink);
137 
139 
140  std::size_t m_numDof;
141 
142  std::shared_ptr<Geometry> m_geometry = nullptr;
143  std::set<std::string> m_validGeometryTypes;
144 
145  TimeSteppingType m_timeStepSizeType = TimeSteppingType::Fixed;
146 
147  std::shared_ptr<TaskGraph> m_taskGraph = nullptr;
148 };
149 } // namespace imstk
std::size_t m_numDof
Total number of degree of freedom.
std::size_t getNumDegreeOfFreedom() const
Get/Set the number of degrees of freedom.
std::shared_ptr< Geometry > getModelGeometry() const
Gets the model geometry.
virtual void setTimeStepSizeType(const TimeSteppingType type)
Get/Set the type of approach used to update the time step size after every frame. ...
Compound Geometry.
Abstract class for mathematical model of the physics governing the dynamic object.
DynamicalModelType
Type of the time dependent mathematical model.
std::set< std::string > m_validGeometryTypes
Valid geometry types of this model.
virtual void updatePhysicsGeometry()
Update the geometry of the model.
StateUpdateType
Type of the update of the state of the body.
DynamicalModelType m_type
Mathematical model type.
TimeSteppingType
Type of the update of the state of the body.
const DynamicalModelType & getType() const
Get the type of the object.