Skip to content

Commit 6b82724

Browse files
committed
[algorithm] Enabled addition of coupling points even if the spacing is smaller than the edge length
1 parent 3104014 commit 6b82724

File tree

2 files changed

+41
-35
lines changed

2 files changed

+41
-35
lines changed

scenes/NeedleInsertion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def createScene(root):
190190
shaftGeom="@Needle/bodyCollision/geom_body",
191191
volGeom="@Volume/geom_tetra",
192192
punctureForceThreshold=20,
193-
tipDistThreshold=0.005,
193+
tipDistThreshold=0.003,
194194
drawcollision=True,
195195
drawPointsScale=0.0001
196196
)

src/sofa/collisionAlgorithm/algorithm/InsertionAlgorithm.h

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -249,41 +249,47 @@ class InsertionAlgorithm : public BaseAlgorithm
249249
// Skip if last CP lies after edge end point
250250
if (dot(shaftEdgeDir, lastCPToP1) < 0_sreal) continue;
251251

252-
// Candidate coupling point along shaft segment
253-
const type::Vec3 candidateCP = lastCP + tipDistThreshold * shaftEdgeDir;
254-
255-
// Project candidate CP onto the edge element and compute scalar coordinate
256-
// along segment
257-
const SReal edgeSegmentLength = (p1 - p0).norm();
258-
const type::Vec3 p0ToCandidateCP = candidateCP - p0;
259-
const SReal projPtOnEdge = dot(p0ToCandidateCP, shaftEdgeDir);
260-
261-
// Skip if candidate CP is outside current edge segment
262-
if (projPtOnEdge < 0_sreal || projPtOnEdge > edgeSegmentLength) continue;
263-
264-
// Project candidate CP onto shaft geometry and then find nearest volume
265-
// proximity
266-
shaftProx = projectOnShaft(candidateCP, itShaft->element()).prox;
267-
const BaseProximity::SPtr volProx = findClosestProxOnVol(
268-
shaftProx, l_volGeom.get(), projectOnVol, getFilterFunc());
269-
if (!volProx) continue;
270-
271-
TetrahedronProximity::SPtr tetProx =
272-
dynamic_pointer_cast<TetrahedronProximity>(volProx);
273-
if (!tetProx) continue;
274-
275-
double f0(tetProx->f0()), f1(tetProx->f1()), f2(tetProx->f2()),
276-
f3(tetProx->f3());
277-
bool isInTetra = toolbox::TetrahedronToolBox::isInTetra(
278-
shaftProx->getPosition(), tetProx->element()->getTetrahedronInfo(), f0, f1,
279-
f2, f3);
280-
281-
// Ensure candidate CP lies inside tetrahedron
282-
if (isInTetra)
252+
const int numCPs = floor(lastCPToP1.norm() / tipDistThreshold);
253+
254+
for(int idCP = 0 ; idCP < numCPs ; idCP++)
283255
{
284-
volProx->normalize();
285-
m_CPs.push_back(volProx);
286-
lastCP = volProx->getPosition();
256+
// Candidate coupling point along shaft segment
257+
const type::Vec3 candidateCP = lastCP + tipDistThreshold * shaftEdgeDir;
258+
259+
// Project candidate CP onto the edge element and compute scalar coordinate
260+
// along segment
261+
const SReal edgeSegmentLength = (p1 - p0).norm();
262+
const type::Vec3 p0ToCandidateCP = candidateCP - p0;
263+
const SReal projPtOnEdge = dot(p0ToCandidateCP, shaftEdgeDir);
264+
265+
// Skip if candidate CP is outside current edge segment
266+
if (projPtOnEdge < 0_sreal || projPtOnEdge > edgeSegmentLength) break;
267+
268+
// Project candidate CP onto shaft geometry and then find nearest volume
269+
// proximity
270+
shaftProx = projectOnShaft(candidateCP, itShaft->element()).prox;
271+
if (!shaftProx) continue;
272+
const BaseProximity::SPtr volProx = findClosestProxOnVol(
273+
shaftProx, l_volGeom.get(), projectOnVol, getFilterFunc());
274+
if (!volProx) continue;
275+
276+
TetrahedronProximity::SPtr tetProx =
277+
dynamic_pointer_cast<TetrahedronProximity>(volProx);
278+
if (!tetProx) continue;
279+
280+
double f0(tetProx->f0()), f1(tetProx->f1()), f2(tetProx->f2()),
281+
f3(tetProx->f3());
282+
bool isInTetra = toolbox::TetrahedronToolBox::isInTetra(
283+
shaftProx->getPosition(), tetProx->element()->getTetrahedronInfo(), f0,
284+
f1, f2, f3);
285+
286+
// Ensure candidate CP lies inside tetrahedron
287+
if (isInTetra)
288+
{
289+
volProx->normalize();
290+
m_CPs.push_back(volProx);
291+
lastCP = volProx->getPosition();
292+
}
287293
}
288294
}
289295
}

0 commit comments

Comments
 (0)