@@ -6,7 +6,7 @@ namespace sofa::collisionalgorithm::Operations::Needle
66bool 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
0 commit comments