iMSTK
Interactive Medical Simulation Toolkit
Docs/Collision/Collision_Handling.md
1 Collision Handling
2 ==================
3 
4 :code:`CollisionHandling` classes in iMSTK defines methods for handling collisions. They take input objects (often two) and input collision data. When updated they will consume the collision data to produce appropriate responses. Normally this is a response in a dynamical system. This may either be an instant response at the time of handling or something (such as a constraint) added to the system to solve and produce the response later.
5 
6 CollisionHandlers and CollisionDetection is normally setup by an interaction through the scene such that the user doesn't have to mess with them unless they want to change parameters of a handler/detection or even subclass them for custom functionalities.
7 
8 LevelSetCH
9 --------------------------------
10 
11 The levelSetCH consumes PointDirection data from a collision detection method to produce impulses/movement in a LevelSet using gaussian kernels. One can alter this kernel size, gaussian sigma. If one chooses to use proportional velocity, then the force of the rigid object is considered in how fast the level set is moved.
12 
13 While the handler is standalone and can be used in other contexts, it finds its main use in the RigidObjectLevelSetCollision interaction which may be used like so:
14 
15 ::
16 
17  imstkNew<RigidObjectLevelSetCollision> interaction(rbdObj, femurObj);
18  scene->getCollisionGraph()->addInteraction(interaction);
19 
20 Should more control be needed one can access the underlying handlers like so:
21 
22 ::
23 
24  auto colHandlerA = std::dynamic_pointer_cast<RigidBodyCH>(interaction->getCollisionHandlingA());
25  colHandlerA->setUseFriction(false);
26  colHandlerA->setBeta(0.05); // inelastic collision
27 
28  auto colHandlerB = std::dynamic_pointer_cast<LevelSetCH>(interaction->getCollisionHandlingB());
29  colHandlerB->setLevelSetVelocityScaling(0.01);
30  colHandlerB->setKernel(3, 1.0);
31  colHandlerB->setUseProportionalVelocity(true);
32 
33 PBDCollisionHandling
34 --------------------------------
35 
36 Given two input objects (pbd vs pbd or pbd vs colliding/static) and input collision data it will produce collision constraints in a solver to then be solved later. One of the more complex handlers in iMSTK and handles many cases:
37 
38 The implementation of this handler is broken into two functions:
39 
40 * Mesh-Non-Mesh Interactions: The PbdObject is garunteed to be a mesh, but the CollidingObject could be mesh, a primitive, an implicit geometry, etc. The following CD data's are handled:
41 
42  * PointIndexDirection-None: Moves the vertex of the mesh (given by index) in the direction and depth specified by the element.
43  * Triangle-Vertex/PointDirection: Moves the triangle to the vertex.
44  * Edge-Vertex/PointDirection: Moves the edge to the vertex.
45 
46 * Mesh-Mesh Interactions: In the case both are a mesh the following CD data's are handled:
47 
48  * Vertex-Triangle/Triangle-Vertex: Moves the vertex and triangle to just touching.
49  * Edge-Edge: Moves the two edges to just touching.
50  * Edge-Vertex/Vertex-Edge: Moves the vertex and edge to just touching.
51 
52 Whats supported then:
53 
54 * PbdObject vs PbdObject mesh collisions.
55 * PbdObject vs CollidingObject mesh collisions.
56 * PbdObject vs CollidingObject primitive collisions.
57 * PbdObject vs CollidingObject implicit geometry collisions.
58 
59 The PbdCollisionHandling can be used through the PbdObjectCollision interaction like so:
60 
61 ::
62 
63  // Add collision between the two objects with the following collision strategy
64  imstkNew<PbdObjectCollision> myCollision(tissueObj, toolObj, "ClosedSurfaceMeshToMeshCD");
65  scene->getCollisionGraph()->addInteraction(myCollision);
66 
67 If more control is needed that is not available in the PbdObjectCollision, you may attain the handler like so:
68 
69 ::
70 
71  auto pbdHandler = std::dynamic_pointer_cast<PbdCollisionHandling>(myCollision->getCollisionHandlingA());
72 
73 When subclassing one may override the base class handling function which is called to consume the collision data or you may override the constraint addition functions. Such functions are useful when custom response (say constraints) is needed upon contact. See PbdTissueSurfaceNeedleContact example for subclassing.
74 
75 
76 PBDPickingCH
77 --------------------------------
78 
79 The PbdPickingCH consumes CD data to constrain PbdObject vertices in contact with an analytical geometry. It constraints them such that their relative positions to the analytical geometry origin and orientation are maintained. It may only be used with PbdObject vs CollidingObject that has an analytical geometry.
80 
81 The user can call beginPick or endPick to constrain or unconstrain the PbdObject vertices.
82 
83 The PbdPickingCH can be used through the PbdObjectPicking interaction like so:
84 
85 ::
86 
87  // Add picking interaction between a clothObj (PbdObject) and toolObj (with capsule analytical geometry)
88  imstkNew<PbdObjectPicking> objectPicking(clothObj, toolObj, "PointSetToCapsuleCD");
89  scene->getCollisionGraph()->addInteraction(objectPicking);
90 
91 PenaltyCH
92 --------------------------------
93 
94 The PenaltyCH uses a penalty response method between a FEM simulated and rigid body object. It consumes CD data between the geometries and produces forces in both models. It currently only works with PointDirection data, of which only primtive collision detection supports. So it is currently limited to implicit and primitive shapes only.
95 
96 RigidBodyCH
97 --------------------------------
98 
99 The RigidBodyCH handles collisions between two RigidObject2's or a RigidObject2 and a CollidingObject (where CollidingObject is static/immovable by the rigid object). Currently it only handles mesh to primitive+implicit and primitive to primitive rigid body shapes. It can be used through the RigidObjectCollision interaction like so:
100 
101 ::
102 
103  // Create an interaction between a rigid object with a sphere and CollidingObject with plane geometry, resolves undirectionally (always above the plane normal)
104  auto rbdInteraction = std::make_shared<RigidObjectCollision>(rbdObjSphere, planeObj, "UnidirectionalPlaneToSphereCD");
105  rbdInteraction->setFriction(0.0);
106  rbdInteraction->setStiffness(0.0001);
107  scene->getCollisionGraph()->addInteraction(rbdInteraction);
108 
109 Another example using between a rigid OBB and an implicit/SDF geometry:
110 
111 ::
112 
113  // Create an interaction between a rigid object with a OBB geometry and CollidingObject with an SignedDistanceField geometry (great for static curved surfaces)
114  auto rbdInteraction = std::make_shared<RigidObjectCollision>(cubeObj, planeObj, "ImplicitGeometryToPointSetCD");
115  rbdInteraction->setFriction(0.0); // Don't use friction
116  rbdInteraction->setStiffness(0.05);
117  scene->getCollisionGraph()->addInteraction(rbdInteraction);
118 
119 SPHCollisionHandling
120 --------------------------------
121 
122 The SPHCollisionHandling moves SPH particles out of collision with an object and applies boundary friction to the velocity of the particle. It currently only works with PointDirection data, of which only primtive collision detection supports. So it is currently limited to implicit and primitive shapes only.
123 
124 One may use it through the SPHCollision interaction like so:
125 
126 ::
127 
128  // Add collision between the two objects (fluidObj is SPHObject and solidObj is a CollidingObject with primitive geometry)
129  imstkNew<SphObjectCollision> myCollision(fluidObj, solidObj);
130  scene->getCollisionGraph()->addInteraction(myCollision);