iMSTK
Interactive Medical Simulation Toolkit
NeedlePbdCH.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 "imstkNeedle.h"
10 #include "imstkPbdCollisionHandling.h"
11 #include "imstkPbdObject.h"
12 #include "imstkPuncturable.h"
13 
14 using namespace imstk;
15 
22 {
23 public:
24  NeedlePbdCH() = default;
25  ~NeedlePbdCH() override = default;
26 
27  IMSTK_TYPE_NAME(NeedlePbdCH)
28 
29 protected:
30  void handle(
31  const std::vector<CollisionElement>& elementsA,
32  const std::vector<CollisionElement>& elementsB) override
33  {
34  auto puncturable = getInputObjectA()->getComponent<Puncturable>();
35  auto needle = getInputObjectB()->getComponent<Needle>();
36 
37  const PunctureId punctureId = getPunctureId(needle, puncturable);
38  if ((elementsA.size() > 0 || elementsB.size() > 0)
39  && needle->getState(punctureId) == Puncture::State::REMOVED)
40  {
41  needle->setState(punctureId, Puncture::State::TOUCHING);
42  puncturable->setPuncture(punctureId, needle->getPuncture(punctureId));
43  }
44 
45  // Don't handle collision data when punctured
46  if (needle->getState(punctureId) == Puncture::State::TOUCHING)
47  {
48  PbdCollisionHandling::handle(elementsA, elementsB);
49  }
50  }
51 };
Implements PBD based collision handling. Given an input PbdObject and CollisionData it creates & adds...
PunctureId getPunctureId(std::shared_ptr< Needle > needle, std::shared_ptr< Puncturable > puncturable, const int supportId)
Get puncture id between needle and puncturable.
Place this on an object to make it puncturable by a needle. This allows puncturables to know they&#39;ve ...
Compound Geometry.
void handle(const std::vector< CollisionElement > &elementsA, const std::vector< CollisionElement > &elementsB) override
Add collision constraints based off contact data.
void handle(const std::vector< CollisionElement > &elementsA, const std::vector< CollisionElement > &elementsB) override
Handle the input collision data. Elements will be flipped (if needed) such that elementsA corresponds...
Definition: NeedlePbdCH.h:30
Base for all needles in imstk it supports global puncture state, per object puncture state...
Definition: imstkNeedle.h:20
std::shared_ptr< CollidingObject > getInputObjectA() const
Get the input objects.
void setPuncture(const PunctureId &id, std::shared_ptr< Puncture > data)
Get/Set puncture data.
Handles penetration constraints for the needle and the thread by creating a set of puncture points th...
std::tuple< int, int, int > PunctureId
Punctures are identified via three ints. The needle id, the puncturable id, and a local id that allow...
Definition: imstkPuncture.h:21