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: 16 additions & 16 deletions src/sofa/collisionAlgorithm/algorithm/InsertionAlgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,22 +188,8 @@ class InsertionAlgorithm : public BaseAlgorithm
Operations::CreateCenterProximity::Operation::get(itTip->getTypeInfo());
const BaseProximity::SPtr tipProx = createTipProximity(itTip->element());

ElementIterator::SPtr itShaft = l_shaftGeom->begin(l_shaftGeom->getSize() - 2);
auto createShaftProximity =
Operations::CreateCenterProximity::Operation::get(itShaft->getTypeInfo());
const BaseProximity::SPtr shaftProx = createShaftProximity(itShaft->element());
const EdgeProximity::SPtr edgeProx = dynamic_pointer_cast<EdgeProximity>(shaftProx);
const type::Vec3 normal = (edgeProx->element()->getP1()->getPosition() -
edgeProx->element()->getP0()->getPosition())
.normalized();
const type::Vec3 ab = m_couplingPts.back()->getPosition() - tipProx->getPosition();
const SReal dotProd = dot(ab, normal);
if (dotProd > 0.0) {
m_couplingPts.pop_back();
}

const SReal dist = ab.norm();
if (dist > d_tipDistThreshold.getValue())
const type::Vec3 tip2Pt = m_couplingPts.back()->getPosition() - tipProx->getPosition();
if (tip2Pt.norm() > d_tipDistThreshold.getValue())
Copy link
Contributor

@epernod epernod Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked in the full method code, this is not the case here, but just FYI, if possible, .getValue() should not be called inside a for loop because they imply some memory access that the compilator can't optimize (due to the Data container code etc...)

So it is better to do:

const auto& data = d_data.getValue();
for (;;)
{
   mycheck(value, data);
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, that rings a bell. I'll actually adjust this in the next PR 'cause it's a good tip.

{
auto findClosestProxOnVol =
Operations::FindClosestProximity::Operation::get(l_volGeom);
Expand All @@ -216,6 +202,20 @@ class InsertionAlgorithm : public BaseAlgorithm
m_couplingPts.push_back(volProx);
}
}
else // Don't bother with removing the point that was just added
{
ElementIterator::SPtr itShaft = l_shaftGeom->begin(l_shaftGeom->getSize() - 2);
auto createShaftProximity =
Operations::CreateCenterProximity::Operation::get(itShaft->getTypeInfo());
const BaseProximity::SPtr shaftProx = createShaftProximity(itShaft->element());
const EdgeProximity::SPtr edgeProx = dynamic_pointer_cast<EdgeProximity>(shaftProx);
const type::Vec3 normal = (edgeProx->element()->getP1()->getPosition() -
edgeProx->element()->getP0()->getPosition())
.normalized();
if (dot(tip2Pt, normal) > 0_sreal) {
m_couplingPts.pop_back();
}
}

auto findClosestProxOnShaft =
Operations::FindClosestProximity::Operation::get(l_shaftGeom);
Expand Down