Skip to content

Commit 7e8e91a

Browse files
committed
[Needle][algorithm] Modified scene and algorithm to allow for the EdgeNormalHandler to operate
The moment the first coupling point is created (right after the puncture), it is important to reproject the first proximity back on the needle. This will create an EdgeProximity type and will allow the EdgeNormalHandler to operate. Otherwise, a MechanicalProximity is used for which there are no specialized functions.
1 parent 357954f commit 7e8e91a

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

scenes/NeedleInsertion.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,15 @@ def createScene(root):
9494
needleBodyCollision = needle.addChild("bodyCollision")
9595
needleBodyCollision.addObject("EdgeSetTopologyContainer", name="Container_body", src="@../Container")
9696
needleBodyCollision.addObject("MechanicalObject",name="mstate_body", template="Vec3d",)
97-
needleBodyCollision.addObject("EdgeGeometry",name="geom",mstate="@mstate_body", topology="@Container_body")
97+
needleBodyCollision.addObject("EdgeGeometry",name="geom_body",mstate="@mstate_body", topology="@Container_body")
98+
needleBodyCollision.addObject("EdgeNormalHandler", name="NeedleBeams", geometry="@geom_body")
9899

99100
needleBodyCollision.addObject("IdentityMapping")
100101

101102

102103
needleTipCollision = needle.addChild("tipCollision")
103104
needleTipCollision.addObject("MechanicalObject",name="mstate_tip",position=[g_needleLength+g_needleBaseOffset[0], g_needleBaseOffset[1], g_needleBaseOffset[2]],template="Vec3d",)
104-
needleTipCollision.addObject("PointGeometry",name="geom",mstate="@mstate_tip")
105+
needleTipCollision.addObject("PointGeometry",name="geom_tip",mstate="@mstate_tip")
105106
needleTipCollision.addObject("RigidMapping",globalToLocalCoords=True,index=g_needleNumberOfElems)
106107

107108

@@ -177,21 +178,21 @@ def createScene(root):
177178

178179

179180
root.addObject("InsertionAlgorithm", name="InsertionAlgo",
180-
fromGeom="@Needle/tipCollision/geom",
181+
fromGeom="@Needle/tipCollision/geom_tip",
181182
destGeom="@Volume/collision/geom_tri",
182-
fromVol="@Needle/bodyCollision/geom",
183+
fromVol="@Needle/bodyCollision/geom_body",
183184
destVol="@Volume/geom_tetra",
184-
punctureThreshold=0.1,
185-
slideDistance=0.005
185+
punctureThreshold=0.05,
186+
slideDistance=0.005,
187+
drawcollision=True,
188+
sphereRadius=0.0001
186189
#projective=True
187190
)
188191
root.addObject("DistanceFilter",algo="@InsertionAlgo",distance=0.01)
189192
root.addObject("SecondDirection",name="punctureDirection",handler="@Volume/collision/SurfaceTriangles")
190193
root.addObject("ConstraintUnilateral",input="@InsertionAlgo.output",directions="@punctureDirection",draw_scale="0.001")#, mu="0.001")
191194

195+
root.addObject("FirstDirection",name="bindDirection", handler="@Needle/bodyCollision/NeedleBeams")
196+
root.addObject("ConstraintInsertion",input="@InsertionAlgo.outputList", directions="@bindDirection",draw_scale="0.005")#, mu="0.001")
192197

193-
#root.addObject("InsertionAlgorithm",name="InsertionAlgo",fromGeom="@Needle/tipCollision/geom", destGeom="@Volume/tri_geom")
194-
#root.addObject("DistanceFilter",algo="@InsertionAlgo",distance=0.005)
195-
#root.addObject("BindDirection",name="insertionDirection")#,handler="@Volume/InternalTriangles")
196-
#root.addObject("ConstraintBilateral",input="@InsertionAlgo.output",directions="@punctureDirection",draw_scale="0.001")
197198

src/sofa/collisionAlgorithm/algorithm/InsertionAlgorithm.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ class InsertionAlgorithm : public BaseAlgorithm {
8787

8888
if (outputList.size() == 0)
8989
{
90-
const sofa::component::statecontainer::MechanicalObject<defaulttype::Vec3Types>* mstate
91-
= l_from->getContext()->get<sofa::component::statecontainer::MechanicalObject<defaulttype::Vec3Types>>();
90+
const sofa::core::behavior::MechanicalState<defaulttype::Vec3Types>* mstate
91+
= l_from->getContext()->get<sofa::core::behavior::MechanicalState<defaulttype::Vec3Types>>();
9292
if (mstate->getSize() > 1) {
9393
msg_warning() << "Requested MechanicalObject, corresponding to the tip of the needle in the InsertionAlgorithm, has a size greater than 1. "
9494
<< "The algorithm is designed to work with a single point. Only the first element will be used.";
@@ -99,11 +99,15 @@ class InsertionAlgorithm : public BaseAlgorithm {
9999
m_constraintSolver->getLambda()[mstate].read()->getValue();
100100
if (lambda[0].norm() > d_punctureThreshold.getValue())
101101
{
102+
auto findClosestProxOp_needle = Operations::FindClosestProximity::Operation::get(l_fromVol);
103+
auto projectOp_needle = Operations::Project::Operation::get(l_fromVol);
102104
for (const auto& dpair : output)
103105
{
104-
outputList.add(dpair.first->copy(), dpair.second->copy());
105-
m_needlePts.push_back(dpair.first->copy());
106+
// Reproject onto the needle to create an EdgeProximity - The EdgeHandler requires this
107+
auto pfromVol = findClosestProxOp_needle(dpair.second, l_fromVol.get(), projectOp_needle, getFilterFunc());
108+
m_needlePts.push_back(pfromVol);
106109
m_couplingPts.push_back(dpair.second->copy());
110+
outputList.add(pfromVol, dpair.second->copy());
107111
}
108112
output.clear();
109113
return;

0 commit comments

Comments
 (0)