Skip to content
Merged
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
32 changes: 26 additions & 6 deletions src/sofa/collisionAlgorithm/algorithm/InsertionAlgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,11 @@ class InsertionAlgorithm : public BaseAlgorithm
d_projective(initData(
&d_projective, false, "projective",
"Projection of closest detected proximity back onto the needle tip element.")),
d_punctureForceThreshold(initData(&d_punctureForceThreshold,
std::numeric_limits<double>::max(),
d_punctureForceThreshold(initData(&d_punctureForceThreshold, -1_sreal,
"punctureForceThreshold",
"Threshold for the force applied to the needle tip. "
"Once exceeded, puncture is initiated.")),
d_tipDistThreshold(initData(&d_tipDistThreshold, std::numeric_limits<double>::min(),
"tipDistThreshold",
d_tipDistThreshold(initData(&d_tipDistThreshold, -1_sreal, "tipDistThreshold",
"Threshold for the distance advanced by the needle tip since "
"the last proximity detection. Once exceeded, a new "
"proximity pair is added for the needle-volume coupling.")),
Expand All @@ -72,6 +70,24 @@ class InsertionAlgorithm : public BaseAlgorithm
{
BaseAlgorithm::init();
this->getContext()->get<ConstraintSolver>(m_constraintSolver);
msg_warning_when(!m_constraintSolver)
<< "No constraint solver found in context. Insertion algorithm is disabled.";

if (d_punctureForceThreshold.getValue() < 0)
{
msg_warning() << d_punctureForceThreshold.getName() +
" parameter not defined or set to negative value." msgendl
<< "Puncture will not function properly; provide a positive value";
d_punctureForceThreshold.setValue(std::numeric_limits<double>::max());
}

if (d_tipDistThreshold.getValue() < 0)
{
msg_warning() << d_tipDistThreshold.getName() +
" parameter not defined or set to negative value." msgendl
<< "Needle-volume coupling is disabled; provide a positive value";
d_tipDistThreshold.setValue(std::numeric_limits<double>::max());
}
}

void draw(const core::visual::VisualParams* vparams)
Expand Down Expand Up @@ -106,14 +122,18 @@ class InsertionAlgorithm : public BaseAlgorithm
auto& collisionOutput = *d_collisionOutput.beginEdit();
auto& insertionOutput = *d_insertionOutput.beginEdit();

if (insertionOutput.size() == 0)
if (m_couplingPts.empty())
{
const MechStateTipType::SPtr mstate = l_tipGeom->getContext()->get<MechStateTipType>();
if (m_constraintSolver)
{
const auto& lambda =
m_constraintSolver->getLambda()[mstate.get()].read()->getValue();
if (lambda[0].norm() > d_punctureForceThreshold.getValue())
SReal norm{0_sreal};
for (const auto& l : lambda) {
norm += l.norm();
}
if (norm > d_punctureForceThreshold.getValue())
{
auto findClosestProxOnShaft =
Operations::FindClosestProximity::Operation::get(l_shaftGeom);
Expand Down