Skip to content

Commit 30c2cd3

Browse files
committed
[operations] Implemented a custom function for removing points based on edge direction
1 parent 4d0eee0 commit 30c2cd3

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed
Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
#include <sofa/collisionAlgorithm/operations/NeedleOperations.h>
22

3-
namespace sofa::collisionAlgorithm::Operations::Needle {
3+
namespace sofa::collisionAlgorithm::Operations::Needle
4+
{
45

5-
//int register_Project_Edge = Operation::register_func<EdgeProximity>(&toolbox::EdgeToolBox::project);
6+
bool prunePointsUsingEdges(std::vector<BaseProximity::SPtr>& couplingPts,
7+
const EdgeElement::SPtr& edge)
8+
{
9+
const type::Vec3 edgeBase(edge->getP0()->getPosition());
10+
const type::Vec3 tip(edge->getP1()->getPosition());
611

12+
const type::Vec3 edgeDirection = tip - edgeBase;
13+
const type::Vec3 tip2Pt = couplingPts.back()->getPosition() - tip;
14+
15+
// Positive dot product means the point is ahead of the tip
16+
if (dot(tip2Pt, edgeDirection) > 0_sreal) couplingPts.pop_back();
17+
18+
return true;
719
}
820

21+
int register_PrunePointsAheadOfTip_Edge =
22+
PrunePointsAheadOfTip::register_func<EdgeElement>(&prunePointsUsingEdges);
23+
} // namespace sofa::collisionAlgorithm::Operations::Needle

src/sofa/collisionAlgorithm/operations/NeedleOperations.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <sofa/collisionAlgorithm/BaseOperation.h>
44
#include <sofa/collisionAlgorithm/BaseProximity.h>
5+
#include <sofa/collisionAlgorithm/elements/EdgeElement.h>
56

67
namespace sofa::collisionAlgorithm::Operations::Needle
78
{
@@ -10,11 +11,11 @@ class PrunePointsAheadOfTip
1011
: public GenericOperation<PrunePointsAheadOfTip, // Type of the operation
1112
bool, // Default return type
1213
std::vector<BaseProximity::SPtr>&,
13-
const BaseProximity::SPtr& // Parameters
14+
const BaseElement::SPtr& // Parameters
1415
>
1516
{
1617
public:
17-
bool defaultFunc(std::vector<BaseProximity::SPtr>&, const BaseProximity::SPtr&) const override
18+
bool defaultFunc(std::vector<BaseProximity::SPtr>&, const BaseElement::SPtr&) const override
1819
{
1920
return false;
2021
}
@@ -27,4 +28,7 @@ class PrunePointsAheadOfTip
2728
}
2829
};
2930

31+
bool prunePointsUsingEdges(std::vector<BaseProximity::SPtr>& couplingPts,
32+
const EdgeElement::SPtr& edgeProx);
33+
3034
} // namespace sofa::collisionAlgorithm::Operations::Needle

0 commit comments

Comments
 (0)