iMSTK
Interactive Medical Simulation Toolkit
Docs/Needles.md
1 # Needles
2 
3 Needles have physics approximations in iMSTK. There are currently many examples within iMSTK that do implement needles to check out. Amongst others, `PBDTissueSurfaceNeedleContact`, `PBDTissueVolumeNeedleContact`.
4 
5 <p align="center">
6  <img src="media/needleTissue.gif" alt="pbd needle puncture volume"/>
7 </p>
8 
9 ## Needle
10 
11 iMSTK currently contains two types of needle definitions.
12  - StraigthNeedle: A single line segment needle.
13  - ArcNeedle: Define with an arc. Also provides a LineMesh for collision.
14 
15  To setup a PBD simulated `StraightNeedle` that is also controlled with a `PbdObjectController` one can do:
16 
17  ```cpp
18  auto toolObj = std::make_shared<PbdObject>();
19 
20 auto toolGeometry = std::make_shared<LineMesh>();
21 auto verticesPtr = std::make_shared<VecDataArray<double, 3>>(2);
22 (*verticesPtr)[0] = Vec3d(0.0, 0.0, 0.0);
23 (*verticesPtr)[1] = Vec3d(0.0, 0.0, 0.25);
24 auto indicesPtr = std::make_shared<VecDataArray<int, 2>>(1);
25 (*indicesPtr)[0] = Vec2i(0, 1);
26 toolGeometry->initialize(verticesPtr, indicesPtr);
27 
28 toolObj->setVisualGeometry(toolGeometry);
29 toolObj->setCollidingGeometry(toolGeometry);
30 toolObj->setPhysicsGeometry(toolGeometry);
31 toolObj->setDynamicalModel(model);
32 toolObj->getPbdBody()->setRigid(
33  Vec3d(0.0, 1.0, 0.0), // Position
34  1.0, // Mass
35  Quatd::Identity(), // Orientation
36  Mat3d::Identity() * 10000.0); // Inertia
37 
38 // Add a component for controlling via another device
39 auto controller = toolObj->addComponent<PbdObjectController>();
40 controller->setControlledObject(toolObj);
41 controller->setLinearKs(20000.0);
42 controller->setAngularKs(8000000.0);
43 controller->setUseCritDamping(true);
44 controller->setForceScaling(0.05);
45 controller->setSmoothingKernelSize(15);
46 controller->setUseForceSmoothening(true);
47  ```
48 
49 Add the needle component:
50 
51 ```cpp
52 // Add a component for needle puncturing
53 auto needle = toolObj->addComponent<StraightNeedle>();
54 needle->setNeedleGeometry(toolGeometry);
55 ```
56 
57 ## Punctureable
58 
59 Needles work in junction with Puncturables. Puncturable exists to keep track of the punctures on a tissue. To define something as puncturable add the component to the `toolObj`.
60 
61 ```cpp
62 toolObj->addComponent<Puncturable>();
63 ```
64 
65 ## PunctureMap
66 
67 Both Needle and Puncturable contain a PunctureMap which is a map of the objects punctures. It's assumed:
68  - A needle can puncture N different tissues.
69  - A needle can puncture the same tissue multiple times.
70  - A tissue can be punctured by N needles.
71  - A tissue can be punctured multiple times.
72 
73 ### Puncture
74 
75 A puncture is defined as having a state `REMOVED`, `TOUCHING`, or `INSERTED`. This holds true for all needles. Though sometimes instant puncture needles are desirable, in which case `TOUCHING` would not be used. A puncture also contains a `UserData`. This is not used by iMSTK but tends to be useful in user code. It contains the ids of the puncturable, ids of the cell punctured, and barycentric weights. When puncture occurs a `Puncture` is added to both the `Puncturable` and the `Needle`'s `PunctureMap`. This way each can keep track of what punctures it has. ie: `PunctureMap` is not shared, but individual `Puncture`'s are shared.
76 
77 ## NeedleInteraction
78 
79 As mentioned `NeedleInteraction` is not yet available in iMSTK but is defined in many iMSTK examples. See [PBDTissueVolumeNeedleContact](Examples/PBDTissueVolumeNeedleContact.md) for one such example. Though the internals differ the user facing API is mostly the same.
80 
81 ```cpp
82 auto needleInteraction = std::make_shared<NeedleInteraction>(tissueObj, needleToolObj);
83 ...
84 scene->addSceneObject(needleInteraction);
85 ```
86 
87 <p align="center">
88  <img src="media/needles.png" alt="pbd needle puncture volume"/>
89 </p>
90 
91 ## Suturing
92 
93 Suturing is not yet in iMSTK but has been prototyped in an example.
94 
95 ![type:video](./media/pbdSuturing.mp4)