Skip to content

Commit afda3a8

Browse files
committed
[algorithm] Use custom operation for point removal - avoid dynamic casts to edge element types
1 parent 30c2cd3 commit afda3a8

File tree

1 file changed

+5
-31
lines changed

1 file changed

+5
-31
lines changed

src/sofa/collisionAlgorithm/algorithm/InsertionAlgorithm.h

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <sofa/collisionAlgorithm/operations/CreateCenterProximity.h>
77
#include <sofa/collisionAlgorithm/operations/FindClosestProximity.h>
88
#include <sofa/collisionAlgorithm/operations/Project.h>
9+
#include <sofa/collisionAlgorithm/operations/NeedleOperations.h>
910
#include <sofa/collisionAlgorithm/proximity/EdgeProximity.h>
1011
#include <sofa/collisionAlgorithm/proximity/TetrahedronProximity.h>
1112
#include <sofa/component/constraint/lagrangian/solver/ConstraintSolverImpl.h>
@@ -247,38 +248,11 @@ class InsertionAlgorithm : public BaseAlgorithm
247248
}
248249
else // Don't bother with removing the point that was just added
249250
{
250-
// 2.2. Check whether coupling point should be removed
251+
// Remove coupling points that are ahead of the tip in the insertion direction
251252
ElementIterator::SPtr itShaft = l_shaftGeom->begin(l_shaftGeom->getSize() - 2);
252-
auto createShaftProximity =
253-
Operations::CreateCenterProximity::Operation::get(itShaft->getTypeInfo());
254-
const BaseProximity::SPtr shaftProx = createShaftProximity(itShaft->element());
255-
if (shaftProx)
256-
{
257-
const EdgeProximity::SPtr edgeProx =
258-
dynamic_pointer_cast<EdgeProximity>(shaftProx);
259-
if (edgeProx)
260-
{
261-
const type::Vec3 normal = (edgeProx->element()->getP1()->getPosition() -
262-
edgeProx->element()->getP0()->getPosition())
263-
.normalized();
264-
// If the (last) coupling point lies ahead of the tip (positive dot product),
265-
// the needle is retreating. Thus, that point is removed.
266-
if (dot(tip2Pt, normal) > 0_sreal)
267-
{
268-
m_couplingPts.pop_back();
269-
}
270-
}
271-
else
272-
{
273-
msg_warning() << "shaftGeom: " << l_shaftGeom->getName()
274-
<< " is not an EdgeGeometry. Point removal is disabled";
275-
}
276-
}
277-
else
278-
{
279-
msg_warning() << "Cannot create proximity from shaftGeom: "
280-
<< l_shaftGeom->getName() << " - point removal is disabled";
281-
}
253+
auto prunePointsAheadOfTip =
254+
Operations::Needle::PrunePointsAheadOfTip::get(itShaft->getTypeInfo());
255+
prunePointsAheadOfTip(m_couplingPts, itShaft->element());
282256
}
283257
}
284258

0 commit comments

Comments
 (0)