iMSTK
Interactive Medical Simulation Toolkit
imstkAbstractDynamicalModel.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 "imstkAbstractDynamicalModel.h"
8 #include "imstkLogger.h"
9 #include "imstkTaskGraph.h"
10 
11 namespace imstk
12 {
13 AbstractDynamicalModel::AbstractDynamicalModel(DynamicalModelType type) :
14  m_type(type), m_numDof(0), m_taskGraph(std::make_shared<TaskGraph>("AbstractDynamicalModel_Source", "AbstractDynamicalModel_Sink"))
15 {
16 }
17 
18 bool
19 AbstractDynamicalModel::isGeometryValid(const std::shared_ptr<Geometry> geometry)
20 {
21  if (geometry)
22  {
23  // If no valid geometries specified all geometries work
24  if (m_validGeometryTypes.size() == 0)
25  {
26  return true;
27  }
28 
29  // If it exists in the set then it is valid geometry
30  if (m_validGeometryTypes.count(geometry->getTypeName()))
31  {
32  return true;
33  }
34  else
35  {
36  LOG(WARNING) << "The geometry is not supported!!";
37  }
38  }
39  else
40  {
41  LOG(WARNING) << "The geometry is not a valid pointer";
42  }
43 
44  return false;
45 }
46 
47 void
48 AbstractDynamicalModel::setModelGeometry(std::shared_ptr<Geometry> geometry)
49 {
50  if (isGeometryValid(geometry))
51  {
52  m_geometry = geometry;
53  }
54  else
55  {
56  LOG(WARNING) << "Invalid geometry for Model";
57  }
58 }
59 
60 void
62 {
63  m_taskGraph->clearEdges();
64  initGraphEdges(m_taskGraph->getSource(), m_taskGraph->getSink());
65 }
66 
67 void
68 AbstractDynamicalModel::initGraphEdges(std::shared_ptr<TaskNode> source, std::shared_ptr<TaskNode> sink)
69 {
70  m_taskGraph->addEdge(source, sink);
71 }
72 } // namespace imstk
bool isGeometryValid(const std::shared_ptr< Geometry > geometry)
Checks if the given geometry is a valid geometry type for the model.
Compound Geometry.
DynamicalModelType
Type of the time dependent mathematical model.
void setModelGeometry(std::shared_ptr< Geometry > geometry)
Sets the model geometry.
void initGraphEdges()
Initializes the edges of the graph.