iMSTK
Interactive Medical Simulation Toolkit
imstkSphObjectCollision.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 "imstkSphObjectCollision.h"
8 #include "imstkCDObjectFactory.h"
9 #include "imstkCollisionData.h"
10 #include "imstkImplicitGeometryToPointSetCD.h"
11 #include "imstkSphCollisionHandling.h"
12 #include "imstkSphModel.h"
13 #include "imstkSphObject.h"
14 #include "imstkTaskGraph.h"
15 
16 namespace imstk
17 {
18 // Pbd Collision will be tested before any step of pbd, then resolved after the solve steps of the two objects
19 SphObjectCollision::SphObjectCollision(std::shared_ptr<SphObject> obj1, std::shared_ptr<CollidingObject> obj2,
20  std::string cdType) :
21  CollisionInteraction("SphObjectCollision_" + obj1->getName() + "_vs_" + obj2->getName(), obj1, obj2, cdType)
22 {
23  // Setup the handler
24  std::shared_ptr<SphCollisionHandling> ch = std::make_shared<SphCollisionHandling>();
25  ch->setInputObjectA(obj1);
26  ch->setInputCollisionData(m_colDetect->getCollisionData());
27  ch->setDetection(m_colDetect);
28  setCollisionHandlingA(ch);
29 
30  // Collision should happen after positions and velocities are computed
31  m_taskGraph->addNode(obj1->getUpdateGeometryNode());
32  m_taskGraph->addNode(obj2->getUpdateGeometryNode());
33 
34  m_taskGraph->addNode(obj1->getTaskGraph()->getSink());
35  m_taskGraph->addNode(obj2->getTaskGraph()->getSink());
36 }
37 
38 void
39 SphObjectCollision::initGraphEdges(std::shared_ptr<TaskNode> source, std::shared_ptr<TaskNode> sink)
40 {
42 
43  auto sphObj1 = std::dynamic_pointer_cast<SphObject>(m_objA);
44 
45  //
46  // ...Sph steps...
47  // Update Geometry A Update Geometry B
48  // Collision Detection
49  // Collision Handling A
50  // objA Sink objB Sink
51  //
52  m_taskGraph->addEdge(sphObj1->getUpdateGeometryNode(), m_collisionDetectionNode);
53  m_taskGraph->addEdge(m_objB->getUpdateGeometryNode(), m_collisionDetectionNode);
54 
55  m_taskGraph->addEdge(m_collisionDetectionNode, m_collisionHandleANode);
56 
57  m_taskGraph->addEdge(m_collisionHandleANode, sphObj1->getTaskGraph()->getSink());
58  m_taskGraph->addEdge(m_collisionHandleANode, m_objB->getTaskGraph()->getSink());
59 }
60 } // namespace imstk
Compound Geometry.
Base class for scene objects that move and/or deform under smooth particle hydrodynamics.
std::shared_ptr< TaskGraph > m_taskGraph
Computational graph.
Definition: imstkScene.h:287
void initGraphEdges()
Initializes the edges of the SceneObject&#39;s computational graph.