iMSTK
Interactive Medical Simulation Toolkit
imstkNeedleInteraction.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 "imstkNeedleInteraction.h"
8 #include "imstkCollisionDetectionAlgorithm.h"
9 #include "imstkLineMesh.h"
10 #include "imstkNeedle.h"
11 #include "imstkPbdObject.h"
12 #include "imstkPuncturable.h"
13 #include "imstkNeedlePbdCH.h"
14 
15 namespace imstk
16 {
17 NeedleInteraction::NeedleInteraction(std::shared_ptr<PbdObject> tissueObj,
18  std::shared_ptr<PbdObject> needleObj,
19  std::shared_ptr<PbdObject> threadObj)
20  : PbdObjectCollision(tissueObj, needleObj)
21 {
22  // Check inputs
23  CHECK(threadObj != nullptr) << "NeedleInteraction: Thread object cannot be null";
24  CHECK(tissueObj != nullptr) << "NeedleInteraction: Tissue object cannot be null";
25  CHECK(needleObj != nullptr) << "NeedleInteraction: Needle object cannot be null";
26 
27  if (!needleObj->containsComponent<Needle>())
28  {
29  needleObj->addComponent<Needle>();
30  LOG(INFO) << "NeedleInteraction: Needle component added to needle object";
31  }
32 
33  if (!tissueObj->containsComponent<Puncturable>())
34  {
35  tissueObj->addComponent<Puncturable>();
36  LOG(INFO) << "NeedleInteraction: Puncturable component added to tissue object";
37  }
38 
39  CHECK(std::dynamic_pointer_cast<SurfaceMesh>(tissueObj->getCollidingGeometry()) != nullptr) <<
40  "NeedleInteraction only works with SufraceMesh collision geometry on the tissue object";
41  CHECK(std::dynamic_pointer_cast<LineMesh>(needleObj->getCollidingGeometry()) != nullptr) <<
42  "NeedleInteraction only works with LineMesh collision geometry on NeedleObject";
43 
44  CHECK(threadObj->getPbdModel() == tissueObj->getPbdModel()
45  && threadObj->getPbdModel() == needleObj->getPbdModel())
46  << "Tissue, thread, and needle must share a PbdModel";
47 
48  // Add collision handler for the PBD reaction
49  auto needlePbdCH = std::make_shared<NeedlePbdCH>();
50  needlePbdCH->setInputObjectA(tissueObj);
51  needlePbdCH->setInputObjectB(needleObj);
52  needlePbdCH->setInputCollisionData(getCollisionDetection()->getCollisionData());
53  needlePbdCH->init(threadObj);
54  setCollisionHandlingAB(needlePbdCH);
55 }
56 
57 void
58 NeedleInteraction::stitch()
59 {
60  auto CH = std::dynamic_pointer_cast<NeedlePbdCH>(this->getCollisionHandlingAB());
61  CH->stitch();
62 }
63 
64 const NeedlePbdCH::PunctureData&
65 NeedleInteraction::getPunctureData()
66 {
67  auto CH = std::dynamic_pointer_cast<NeedlePbdCH>(this->getCollisionHandlingAB());
68  return CH->getPunctureData();
69 }
70 } // namespace imstk
Place this on an object to make it puncturable by a needle. This allows puncturables to know they&#39;ve ...
Compound Geometry.
void stitch()
Create stitching constraints on button press for four or more puncture points.
Base for all needles in imstk it supports global puncture state, per object puncture state...
Definition: imstkNeedle.h:20
This class defines a collision interaction between two PbdObjects or PbdObject & CollidingObject.
Handles penetration constraints for the needle and the thread by creating a set of puncture points th...