Skip to content

Commit 990551d

Browse files
authored
Merge branch 'master' into operations-containsPoint
2 parents cd8a5e1 + 57df238 commit 990551d

File tree

3 files changed

+70
-31
lines changed

3 files changed

+70
-31
lines changed

src/sofa/collisionAlgorithm/algorithm/InsertionAlgorithm.h

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <sofa/collisionAlgorithm/operations/NeedleOperations.h>
2+
3+
namespace sofa::collisionAlgorithm::Operations::Needle
4+
{
5+
6+
bool prunePointsUsingEdges(std::vector<BaseProximity::SPtr>& couplingPts,
7+
const EdgeElement::SPtr& edge)
8+
{
9+
if (!edge)
10+
{
11+
msg_warning("Needle::PrunePointsAheadOfTip")
12+
<< "Null element pointer in prunePointsUsingEdges; returning false";
13+
return false;
14+
}
15+
const type::Vec3 edgeBase(edge->getP0()->getPosition());
16+
const type::Vec3 tip(edge->getP1()->getPosition());
17+
18+
const type::Vec3 edgeDirection = tip - edgeBase;
19+
20+
if (couplingPts.empty()) return true;
21+
const type::Vec3 tip2Pt = couplingPts.back()->getPosition() - tip;
22+
23+
// Positive dot product means the point is ahead of the tip
24+
if (dot(tip2Pt, edgeDirection) > 0_sreal) couplingPts.pop_back();
25+
26+
return true;
27+
}
28+
29+
int register_PrunePointsAheadOfTip_Edge =
30+
PrunePointsAheadOfTip::register_func<EdgeElement>(&prunePointsUsingEdges);
31+
} // namespace sofa::collisionAlgorithm::Operations::Needle
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#pragma once
2+
3+
#include <sofa/collisionAlgorithm/BaseOperation.h>
4+
#include <sofa/collisionAlgorithm/BaseProximity.h>
5+
#include <sofa/collisionAlgorithm/elements/EdgeElement.h>
6+
7+
namespace sofa::collisionAlgorithm::Operations::Needle
8+
{
9+
10+
class PrunePointsAheadOfTip
11+
: public GenericOperation<PrunePointsAheadOfTip, // Type of the operation
12+
bool, // Default return type
13+
std::vector<BaseProximity::SPtr>&,
14+
const BaseElement::SPtr& // Parameters
15+
>
16+
{
17+
public:
18+
bool defaultFunc(std::vector<BaseProximity::SPtr>&, const BaseElement::SPtr&) const override
19+
{
20+
return false;
21+
}
22+
23+
void notFound(const std::type_info& id) const override
24+
{
25+
msg_error("Needle::PrunePointsAheadOfTip")
26+
<< "The operation PrunePointsAheadOfTipOperation is not registered with for type = "
27+
<< sofa::helper::NameDecoder::decodeFullName(id);
28+
}
29+
};
30+
31+
bool prunePointsUsingEdges(std::vector<BaseProximity::SPtr>& couplingPts,
32+
const EdgeElement::SPtr& edgeProx);
33+
34+
} // namespace sofa::collisionAlgorithm::Operations::Needle

0 commit comments

Comments
 (0)