iMSTK
Interactive Medical Simulation Toolkit
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
NeedleEmbedder.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 "imstkSurfaceMesh.h"
10 
11 #include <unordered_map>
12 
13 namespace imstk
14 {
15 class CollisionData;
17 class LineMesh;
18 class PbdConstraint;
19 class PbdObject;
20 class Puncturable;
21 class StraightNeedle;
22 class TaskNode;
23 class TetrahedralMesh;
24 } // namespace imstk
25 
26 using namespace imstk;
27 
31 struct TissueData
32 {
33  std::shared_ptr<PbdObject> obj;
34 
35  TissueData(std::shared_ptr<PbdObject> obj);
36 
37  std::shared_ptr<TetrahedralMesh> geom;
38  std::shared_ptr<VecDataArray<double, 3>> verticesPtr;
39  VecDataArray<double, 3>& vertices;
40  std::shared_ptr<VecDataArray<int, 4>> indicesPtr;
41  VecDataArray<int, 4>& indices;
42 };
43 struct NeedleData
44 {
45  std::shared_ptr<PbdObject> obj;
46 
47  NeedleData(std::shared_ptr<PbdObject> obj);
48 
49  std::shared_ptr<StraightNeedle> needle;
50  std::shared_ptr<VecDataArray<double, 3>> verticesPtr;
51  VecDataArray<double, 3>& vertices;
52  std::shared_ptr<VecDataArray<int, 2>> cellsPtr;
53  VecDataArray<int, 2>& cells;
54 };
55 
63 {
64 public:
65  void setTissueObject(std::shared_ptr<PbdObject> tissueObject) { m_tissueObject = tissueObject; }
66  std::shared_ptr<PbdObject> getTissueObject() const { return m_tissueObject; }
67  void setNeedleObject(std::shared_ptr<PbdObject> needleObject) { m_needleObject = needleObject; }
68  std::shared_ptr<PbdObject> getNeedleObject() const { return m_needleObject; }
69 
70  void setCollisionData(std::shared_ptr<CollisionData> cdData) { m_cdData = cdData; }
71  void setCollisionHandleNode(std::shared_ptr<TaskNode> pbdCHNode) { m_pbdCHNode = pbdCHNode; }
72 
73  void setFriction(const double friction) { m_friction = friction; }
74  double getFriction() const { return m_friction; }
75 
76  void setCompliance(const double compliance) { m_compliance = compliance; }
77  double getCompliance() const { return m_compliance; }
78 
79  void setStaticFrictionForceThreshold(const double force) { m_staticFrictionForceThreshold = force; }
80  const double getStaticFrictionForceThreshold() const { return m_staticFrictionForceThreshold; }
81 
82  void setPunctureForceThreshold(const double forceThreshold) { m_forceThreshold = forceThreshold; }
83  const double getPunctureForceThreshold() const { return m_forceThreshold; }
84 
89  void update();
90 
91 protected:
95  virtual void addFaceEmbeddingConstraint(
96  TissueData& tissueData,
97  NeedleData& needleData,
98  int v1, int v2, int v3,
99  const Vec3d& iPt);
100 
101 protected:
102  std::shared_ptr<PbdObject> m_tissueObject = nullptr;
103  std::shared_ptr<PbdObject> m_needleObject = nullptr;
104 
105  std::shared_ptr<TaskNode> m_pbdCHNode = nullptr;
106  std::shared_ptr<CollisionData> m_cdData = nullptr;
107 
108  // TriCell takes care of duplicate faces
109  std::unordered_map<TriCell, std::shared_ptr<EmbeddingConstraint>> m_faceConstraints;
110  std::vector<PbdConstraint*> m_constraints;
111 
112  double m_friction = 0.0;
113  double m_compliance = 0.000001;
114  double m_staticFrictionForceThreshold = 0.0;
115  double m_forceThreshold = 10.0;
116 
117  VecDataArray<double, 3> tissuePrevVertices;
118  VecDataArray<double, 3> needlePrevVertices;
119 
120 public:
121  std::vector<Vec3d> m_debugEmbeddingPoints;
122  std::vector<Vec3i> m_debugEmbeddedTriangles;
123 };
Base class for TaskGraph nodes.
Definition: imstkTaskNode.h:20
Place this on an object to make it puncturable by a needle. This allows puncturables to know they&#39;ve ...
Compound Geometry.
Definition of straight, single segment needle.
std::vector< PbdConstraint * > m_constraints
List of PBD constraints.
Implements PBD embedded tissue handling for when the needle is embedded in the tissue.
Represents a set of tetrahedrons & vertices via an array of Vec3d double vertices & Vec4i integer ind...
Base class for all volume mesh types.
Definition: imstkLineMesh.h:18
Base class for scene objects that move and/or deform under position based dynamics formulation...
Constrains a rigid body line segment defined via p and q to a "puncture" point defined via barycentri...
Base Constraint class for Position based dynamics constraints.
Describes the contact manifold between two geometries.
std::vector< Vec3d > m_debugEmbeddingPoints
Used for debug visualization.
Flattened out with reference members.