Skip to content

Commit 17e4fd2

Browse files
th-skamepernod
andauthored
[operations] Robustify retraction detection check using tip velocity (#117)
* [operations] Robustify retraction detection check using tip velocity * [operations] Invert bool return from pruning operations * Put method description into header file --------- Co-authored-by: epernod <erik.pernod@gmail.com>
1 parent e532b38 commit 17e4fd2

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/CollisionAlgorithm/operations/NeedleOperations.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace sofa::collisionalgorithm::Operations::Needle
66
bool prunePointsUsingEdges(std::vector<BaseProximity::SPtr>& couplingPts,
77
const EdgeElement::SPtr& edge)
88
{
9-
if (!edge)
9+
if (!edge)
1010
{
1111
msg_warning("Needle::PrunePointsAheadOfTip")
1212
<< "Null element pointer in prunePointsUsingEdges; returning false";
@@ -16,6 +16,12 @@ bool prunePointsUsingEdges(std::vector<BaseProximity::SPtr>& couplingPts,
1616
const type::Vec3 tip(edge->getP1()->getPosition());
1717
const type::Vec3 edgeDirection = tip - edgeBase;
1818

19+
// Only prune if the tip is retracting (moving against the insertion direction).
20+
// NOTE: This uses the needle tip velocity only. If retraction results from needle-tissue
21+
// relative movement, retraction is not detected.
22+
const type::Vec3 tipVelocity = edge->getP1()->getVelocity();
23+
if (dot(tipVelocity, edgeDirection) >= 0_sreal) return false;
24+
1925
const int initSize = couplingPts.size();
2026

2127
while(!couplingPts.empty())
@@ -26,9 +32,9 @@ bool prunePointsUsingEdges(std::vector<BaseProximity::SPtr>& couplingPts,
2632
if(dot(tip2Pt, edgeDirection) < 0_sreal) break;
2733
couplingPts.pop_back();
2834
}
29-
return (initSize == couplingPts.size());
35+
return (couplingPts.size() < initSize);
3036
}
3137

32-
int register_PrunePointsAheadOfTip_Edge =
33-
PrunePointsAheadOfTip::register_func<EdgeElement>(&prunePointsUsingEdges);
38+
int register_PrunePointsAheadOfTip_Edge = PrunePointsAheadOfTip::register_func<EdgeElement>(&prunePointsUsingEdges);
39+
3440
} // namespace sofa::collisionalgorithm::Operations::Needle

src/CollisionAlgorithm/operations/NeedleOperations.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ class SOFA_COLLISIONALGORITHM_API PrunePointsAheadOfTip
2929
}
3030
};
3131

32+
/**
33+
* Returns true when at least one coupling point was popped from the back,
34+
* false when the set was left unchanged (including the null-edge error path
35+
* and the non-retracting early-exit).
36+
*/
3237
bool prunePointsUsingEdges(std::vector<BaseProximity::SPtr>& couplingPts,
3338
const EdgeElement::SPtr& edgeProx);
3439

0 commit comments

Comments
 (0)