Skip to content

Commit 0c15a9e

Browse files
committed
[operations] Robustify retraction detection check using tip velocity
1 parent 78da808 commit 0c15a9e

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/CollisionAlgorithm/operations/NeedleOperations.cpp

Lines changed: 7 additions & 1 deletion
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 true;
24+
1925
const int initSize = couplingPts.size();
2026

2127
while(!couplingPts.empty())

0 commit comments

Comments
 (0)