Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/CollisionAlgorithm/operations/NeedleOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace sofa::collisionalgorithm::Operations::Needle
bool prunePointsUsingEdges(std::vector<BaseProximity::SPtr>& couplingPts,
const EdgeElement::SPtr& edge)
{
if (!edge)
if (!edge)
{
msg_warning("Needle::PrunePointsAheadOfTip")
<< "Null element pointer in prunePointsUsingEdges; returning false";
Expand All @@ -16,6 +16,12 @@ bool prunePointsUsingEdges(std::vector<BaseProximity::SPtr>& couplingPts,
const type::Vec3 tip(edge->getP1()->getPosition());
const type::Vec3 edgeDirection = tip - edgeBase;

// Only prune if the tip is retracting (moving against the insertion direction).
// NOTE: This uses the needle tip velocity only. If retraction results from needle-tissue
// relative movement, retraction is not detected.
const type::Vec3 tipVelocity = edge->getP1()->getVelocity();
if (dot(tipVelocity, edgeDirection) >= 0_sreal) return false;

const int initSize = couplingPts.size();

while(!couplingPts.empty())
Expand All @@ -26,9 +32,9 @@ bool prunePointsUsingEdges(std::vector<BaseProximity::SPtr>& couplingPts,
if(dot(tip2Pt, edgeDirection) < 0_sreal) break;
couplingPts.pop_back();
}
return (initSize == couplingPts.size());
return (couplingPts.size() < initSize);
}

int register_PrunePointsAheadOfTip_Edge =
PrunePointsAheadOfTip::register_func<EdgeElement>(&prunePointsUsingEdges);
int register_PrunePointsAheadOfTip_Edge = PrunePointsAheadOfTip::register_func<EdgeElement>(&prunePointsUsingEdges);

} // namespace sofa::collisionalgorithm::Operations::Needle
5 changes: 5 additions & 0 deletions src/CollisionAlgorithm/operations/NeedleOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class SOFA_COLLISIONALGORITHM_API PrunePointsAheadOfTip
}
};

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

Expand Down
Loading