Skip to content
Merged
Changes from 4 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
19 changes: 13 additions & 6 deletions src/sofa/collisionAlgorithm/algorithm/InsertionAlgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class InsertionAlgorithm : public BaseAlgorithm
auto createTipProximity =
Operations::CreateCenterProximity::Operation::get(itTip->getTypeInfo());
const BaseProximity::SPtr tipProx = createTipProximity(itTip->element());
if(!tipProx) return;

// 2.1 Check whether coupling point should be added
const type::Vec3 tip2Pt = m_couplingPts.back()->getPosition() - tipProx->getPosition();
Expand All @@ -234,11 +235,14 @@ class InsertionAlgorithm : public BaseAlgorithm
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();
if(edgeProx)
{
const type::Vec3 normal = (edgeProx->element()->getP1()->getPosition() -
edgeProx->element()->getP0()->getPosition())
.normalized();
if (dot(tip2Pt, normal) > 0_sreal) {
m_couplingPts.pop_back();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

what if edgeProx is null? should we sent a warning? or exit the loop?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I placed 2 warnings eventually.

  1. Notifies when shaftProx is null. It's unlikely because the CreateCenterProximity operations are straightforward.
  2. Notifies when edgeProx is null. With a valid shaftProx, this will happen if l_shaftGeom is not an EdgeGeometry.

If the two repos were merged into one, we could use the normal handler from the ConstraintGeometry repo. It could help avoid this downcasting.

}
}
Expand All @@ -253,7 +257,10 @@ class InsertionAlgorithm : public BaseAlgorithm
{
const BaseProximity::SPtr shaftProx = findClosestProxOnShaft(
m_couplingPts[i], l_shaftGeom.get(), projectOnShaft, getFilterFunc());
insertionOutput.add(shaftProx, m_couplingPts[i]);
if(shaftProx) {
shaftProx->normalize();
insertionOutput.add(shaftProx, m_couplingPts[i]);
}
}
}

Expand Down
Loading