iMSTK
Interactive Medical Simulation Toolkit
imstkDynamicObject.cpp
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 #include "imstkDynamicObject.h"
8 #include "imstkAbstractDynamicalModel.h"
9 #include "imstkGeometryMap.h"
10 #include "imstkLogger.h"
11 #include "imstkTaskGraph.h"
12 #include "imstkVisualModel.h"
13 
14 namespace imstk
15 {
16 size_t
18 {
19  if (!m_dynamicalModel)
20  {
21  LOG(WARNING) << "Cannot get the degree of freedom since the dynamical model is not initialized! returning 0";
22  return 0;
23  }
24 
25  return m_dynamicalModel->getNumDegreeOfFreedom();
26 }
27 
28 void
30 {
32 
35  {
37  m_physicsToCollidingGeomMap->getChildGeometry()->postModified();
38  }
39 
41  {
42  m_physicsToVisualGeomMap->update();
43  m_physicsToVisualGeomMap->getChildGeometry()->postModified();
44  }
45 }
46 
47 void
49 {
50  m_dynamicalModel->updatePhysicsGeometry();
51  if (m_physicsGeometry != nullptr)
52  {
53  m_physicsGeometry->postModified();
54  }
55 }
56 
57 bool
59 {
61  {
62  CHECK(m_physicsGeometry != nullptr) << "DynamicObject \"" << m_name
63  << "\" expects a physics geometry at start, none was provided";
64 
66  {
67  m_physicsToCollidingGeomMap->compute();
68  }
69 
71  {
72  m_physicsToVisualGeomMap->compute();
73  }
74 
75  return true;
76  }
77  else
78  {
79  return false;
80  }
81 }
82 
83 void
84 DynamicObject::initGraphEdges(std::shared_ptr<TaskNode> source, std::shared_ptr<TaskNode> sink)
85 {
86  // Copy, sum, and connect the model graph to nest within this graph
87  m_taskGraph->addEdge(source, getUpdateNode());
88  if (m_dynamicalModel != nullptr)
89  {
90  m_dynamicalModel->initGraphEdges();
91  m_taskGraph->nestGraph(m_dynamicalModel->getTaskGraph(), getUpdateNode(), getUpdateGeometryNode());
92  }
93  else
94  {
96  }
97  m_taskGraph->addEdge(getUpdateGeometryNode(), sink);
98 }
99 
100 void
102 {
103  m_dynamicalModel->resetToInitialState();
105  postModifiedAll();
106 }
107 
108 void
110 {
111  if (m_physicsGeometry != nullptr)
112  {
113  m_physicsGeometry->postModified();
114  }
116 }
117 } // namespace imstk
void reset() override
Reset the dynamic object by reseting the respective DynamicalModel and Geometry.
void updateGeometries() override
Updates the geometries from the maps (if defined)
void postModifiedAll() override
Posts modified for all geometries.
std::shared_ptr< TaskNode > getUpdateNode() const
Returns the computational node for updating.
void postModifiedAll() override
Posts modified for all geometries.
Compound Geometry.
std::shared_ptr< TaskNode > getUpdateGeometryNode() const
Returns the computational node for updating geometry.
size_t getNumOfDOF() const
Returns the number of degree of freedom.
virtual void updatePhysicsGeometry()
Update only the physics geometry and apply collision map.
bool initialize() override
Initialize the scene object.
std::shared_ptr< AbstractDynamicalModel > m_dynamicalModel
Dynamical model.
bool initialize() override
Initialize the scene object.
std::shared_ptr< GeometryMap > m_physicsToVisualGeomMap
Maps from Physics to visual geometry.
void updateGeometries() final
Update the physics geometry and the apply the maps (if defined)
std::shared_ptr< GeometryMap > m_physicsToCollidingGeomMap
Maps from Physics to collision geometry.
std::shared_ptr< TaskGraph > m_taskGraph
Computational Graph.
std::string m_name
Not unique name.
Definition: imstkEntity.h:157
std::shared_ptr< Geometry > m_physicsGeometry
Geometry used for Physics.
void initGraphEdges()
Initializes the edges of the SceneObject&#39;s computational graph.