Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Collision.Detection.Intersection] Rename Data #4675

Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ namespace sofa::component::collision::detection::intersection
using namespace sofa::component::collision::geometry;

BaseProximityIntersection::BaseProximityIntersection()
: alarmDistance(initData(&alarmDistance, 1.0_sreal, "alarmDistance","Proximity detection distance"))
, contactDistance(initData(&contactDistance, 0.5_sreal, "contactDistance","Distance below which a contact is created"))
: d_alarmDistance(initData(&d_alarmDistance, 1.0_sreal, "alarmDistance", "Proximity detection distance"))
, d_contactDistance(initData(&d_contactDistance, 0.5_sreal, "contactDistance", "Distance below which a contact is created"))
{
alarmDistance.setRequired(true);
contactDistance.setRequired(true);
d_alarmDistance.setRequired(true);
d_contactDistance.setRequired(true);

alarmDistance.setParent(&d_alarmDistance);
contactDistance.setParent(&d_contactDistance);
lamriaimen marked this conversation as resolved.
Show resolved Hide resolved
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,15 @@ class SOFA_COMPONENT_COLLISION_DETECTION_INTERSECTION_API BaseProximityIntersect
{
public:
SOFA_ABSTRACT_CLASS(BaseProximityIntersection,DiscreteIntersection);
Data<SReal> alarmDistance; ///< Proximity detection distance
Data<SReal> contactDistance; ///< Distance below which a contact is created
SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data<SReal> alarmDistance;

SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data<SReal> contactDistance;


Data<SReal> d_alarmDistance; ///< Proximity detection distance
Data<SReal> d_contactDistance; ///< Distance below which a contact is created
protected:
BaseProximityIntersection();
~BaseProximityIntersection() override { }
Expand All @@ -47,16 +54,16 @@ class SOFA_COMPONENT_COLLISION_DETECTION_INTERSECTION_API BaseProximityIntersect
bool useProximity() const override { return true; }

/// Returns the alarm distance (must returns 0 if useProximity() is false)
SReal getAlarmDistance() const override { return alarmDistance.getValue(); }
SReal getAlarmDistance() const override { return d_alarmDistance.getValue(); }

/// Returns the contact distance (must returns 0 if useProximity() is false)
SReal getContactDistance() const override { return contactDistance.getValue(); }
SReal getContactDistance() const override { return d_contactDistance.getValue(); }

/// Sets the alarm distance (if useProximity() is false, the alarm distance is equal to 0)
void setAlarmDistance(SReal v) override { alarmDistance.setValue(v); }
void setAlarmDistance(SReal v) override { d_alarmDistance.setValue(v); }

/// Sets the contact distance (if useProximity() is false, the contact distance is equal to 0)
void setContactDistance(SReal v) override { contactDistance.setValue(v); }
void setContactDistance(SReal v) override { d_contactDistance.setValue(v); }

/// Intersectors for cubes using proximities
bool testIntersection(collision::geometry::Cube& cube1, collision::geometry::Cube& cube2, const core::collision::Intersection* currentIntersection) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,17 @@ int LocalMinDistanceClass = core::RegisterObject("A set of methods to compute (f

LocalMinDistance::LocalMinDistance()
: BaseProximityIntersection()
, filterIntersection(initData(&filterIntersection, true, "filterIntersection","Activate LMD filter"))
, angleCone(initData(&angleCone, 0.0, "angleCone","Filtering cone extension angle"))
, coneFactor(initData(&coneFactor, 0.5, "coneFactor", "Factor for filtering cone angle computation"))
, useLMDFilters(initData(&useLMDFilters, false, "useLMDFilters", "Use external cone computation (Work in Progress)"))
, d_filterIntersection(initData(&d_filterIntersection, true, "filterIntersection", "Activate LMD filter"))
, d_angleCone(initData(&d_angleCone, 0.0, "angleCone", "Filtering cone extension angle"))
, d_coneFactor(initData(&d_coneFactor, 0.5, "coneFactor", "Factor for filtering cone angle computation"))
, d_useLMDFilters(initData(&d_useLMDFilters, false, "useLMDFilters", "Use external cone computation (Work in Progress)"))
{
filterIntersection.setParent(&d_filterIntersection);
angleCone.setParent(&d_angleCone);
coneFactor.setParent(&d_coneFactor);
useLMDFilters.setParent(&d_useLMDFilters);


}

void LocalMinDistance::init()
Expand Down Expand Up @@ -142,7 +148,7 @@ bool LocalMinDistance::testIntersection(Line& e1, Line& e2, const core::collisio
{
// filter for LMD

if (!useLMDFilters.getValue())
if (!d_useLMDFilters.getValue())
{
if (!testValidity(e1, PQ))
return false;
Expand Down Expand Up @@ -221,7 +227,7 @@ int LocalMinDistance::computeIntersection(Line& e1, Line& e2, OutputVector* cont

// filter for LMD //

if (!useLMDFilters.getValue())
if (!d_useLMDFilters.getValue())
{
if (!testValidity(e1, PQ))
{
Expand Down Expand Up @@ -321,7 +327,7 @@ bool LocalMinDistance::testIntersection(Triangle& e2, Point& e1, const core::col
if (PQ.norm2() < alarmDist*alarmDist)
{
//filter for LMD
if (!useLMDFilters.getValue())
if (!d_useLMDFilters.getValue())
{
if (!testValidity(e1, PQ))
return false;
Expand Down Expand Up @@ -382,7 +388,7 @@ int LocalMinDistance::computeIntersection(Triangle& e2, Point& e1, OutputVector*

// filter for LMD

if (!useLMDFilters.getValue())
if (!d_useLMDFilters.getValue())
{
if (!testValidity(e1, PQ))
return 0;
Expand Down Expand Up @@ -475,7 +481,7 @@ bool LocalMinDistance::testIntersection(Triangle& e2, Sphere& e1, const core::co

//filter for LMD

if (!useLMDFilters.getValue())
if (!d_useLMDFilters.getValue())
{
if (!testValidity(e1, PQ))
return false;
Expand Down Expand Up @@ -536,7 +542,7 @@ int LocalMinDistance::computeIntersection(Triangle& e2, Sphere& e1, OutputVector

// filter for LMD

if (!useLMDFilters.getValue())
if (!d_useLMDFilters.getValue())
{
if (!testValidity(e1, PQ))
return 0;
Expand Down Expand Up @@ -605,7 +611,7 @@ bool LocalMinDistance::testIntersection(Line& e2, Point& e1, const core::collisi
{
// filter for LMD

if (!useLMDFilters.getValue())
if (!d_useLMDFilters.getValue())
{
if (!testValidity(e1, PQ))
return false;
Expand Down Expand Up @@ -658,7 +664,7 @@ int LocalMinDistance::computeIntersection(Line& e2, Point& e1, OutputVector* con
const auto QP = -PQ;

// filter for LMD
if (!useLMDFilters.getValue())
if (!d_useLMDFilters.getValue())
{
if (!testValidity(e1, PQ))
return 0;
Expand Down Expand Up @@ -723,7 +729,7 @@ bool LocalMinDistance::testIntersection(Line& e2, Sphere& e1, const core::collis
{
// filter for LMD

if (!useLMDFilters.getValue())
if (!d_useLMDFilters.getValue())
{
if (!testValidity(e1, PQ))
return false;
Expand Down Expand Up @@ -772,7 +778,7 @@ int LocalMinDistance::computeIntersection(Line& e2, Sphere& e1, OutputVector* co
return 0;

// filter for LMD
if (!useLMDFilters.getValue())
if (!d_useLMDFilters.getValue())
{
if (!testValidity(e1, PQ))
return 0;
Expand Down Expand Up @@ -826,7 +832,7 @@ bool LocalMinDistance::testIntersection(Point& e1, Point& e2, const core::collis
{
// filter for LMD

if (!useLMDFilters.getValue())
if (!d_useLMDFilters.getValue())
{
if (!testValidity(e1, PQ))
return false;
Expand Down Expand Up @@ -861,7 +867,7 @@ int LocalMinDistance::computeIntersection(Point& e1, Point& e2, OutputVector* co

// filter for LMD

if (!useLMDFilters.getValue())
if (!d_useLMDFilters.getValue())
{
if (!testValidity(e1, PQ))
return 0;
Expand Down Expand Up @@ -913,7 +919,7 @@ bool LocalMinDistance::testIntersection(Sphere& e1, Point& e2, const core::colli
{
// filter for LMD

if (!useLMDFilters.getValue())
if (!d_useLMDFilters.getValue())
{
if (!testValidity(e1, PQ))
return false;
Expand Down Expand Up @@ -946,7 +952,7 @@ int LocalMinDistance::computeIntersection(Sphere& e1, Point& e2, OutputVector* c

// filter for LMD

if (!useLMDFilters.getValue())
if (!d_useLMDFilters.getValue())
{
if (!testValidity(e1, PQ))
return 0;
Expand Down Expand Up @@ -996,7 +1002,7 @@ bool LocalMinDistance::testIntersection(Sphere& e1, Sphere& e2, const core::coll
{
// filter for LMD

if (!useLMDFilters.getValue())
if (!d_useLMDFilters.getValue())
{
if (!testValidity(e1, PQ))
return false;
Expand Down Expand Up @@ -1028,7 +1034,7 @@ int LocalMinDistance::computeIntersection(Sphere& e1, Sphere& e2, OutputVector*

// filter for LMD

if (!useLMDFilters.getValue())
if (!d_useLMDFilters.getValue())
{
if (!testValidity(e1, PQ))
return 0;
Expand Down Expand Up @@ -1189,7 +1195,7 @@ int LocalMinDistance::computeIntersection(Ray &ray1, Sphere &sph2, OutputVector*

bool LocalMinDistance::testValidity(Point &p, const Vec3 &PQ) const
{
if (!filterIntersection.getValue())
if (!d_filterIntersection.getValue())
return true;

const Vec3 pt = p.p();
Expand Down Expand Up @@ -1232,7 +1238,7 @@ bool LocalMinDistance::testValidity(Point &p, const Vec3 &PQ) const
const PointCollisionModel<sofa::defaulttype::Vec3Types> *pM = p.getCollisionModel();
const bool bothSide_computation = pM->bothSide.getValue();
nMean.normalize();
if (dot(nMean, PQ) < -angleCone.getValue()*PQ.norm() && !bothSide_computation)
if (dot(nMean, PQ) < -d_angleCone.getValue() * PQ.norm() && !bothSide_computation)
{
return false;
}
Expand All @@ -1243,10 +1249,10 @@ bool LocalMinDistance::testValidity(Point &p, const Vec3 &PQ) const
const auto& ped = topology->getEdge(e);
Vec3 l = (pt - x[ped[0]]) + (pt - x[ped[1]]);
l.normalize();
double computedAngleCone = dot(nMean , l) * coneFactor.getValue();
double computedAngleCone = dot(nMean , l) * d_coneFactor.getValue();
if (computedAngleCone<0)
computedAngleCone=0.0;
computedAngleCone+=angleCone.getValue();
computedAngleCone+=d_angleCone.getValue();
if (dot(l , PQ) < -computedAngleCone*PQ.norm())
{
return false;
Expand All @@ -1258,7 +1264,7 @@ bool LocalMinDistance::testValidity(Point &p, const Vec3 &PQ) const

bool LocalMinDistance::testValidity(Line &l, const Vec3 &PQ) const
{
if (!filterIntersection.getValue())
if (!d_filterIntersection.getValue())
return true;

const LineCollisionModel<sofa::defaulttype::Vec3Types> *lM = l.getCollisionModel();
Expand Down Expand Up @@ -1313,10 +1319,10 @@ bool LocalMinDistance::testValidity(Line &l, const Vec3 &PQ) const
}

// compute the angle for the cone to filter contacts using the normal of the triangle situated on the right
double computedAngleCone = (nMean * t1) * coneFactor.getValue();
double computedAngleCone = (nMean * t1) * d_coneFactor.getValue();
if (computedAngleCone<0)
computedAngleCone=0.0;
computedAngleCone+=angleCone.getValue();
computedAngleCone+=d_angleCone.getValue();

if (t1*PQ < -computedAngleCone*PQ.norm())
{
Expand All @@ -1326,10 +1332,10 @@ bool LocalMinDistance::testValidity(Line &l, const Vec3 &PQ) const
}

// compute the angle for the cone to filter contacts using the normal of the triangle situated on the left
computedAngleCone = (nMean * t2) * coneFactor.getValue();
computedAngleCone = (nMean * t2) * d_coneFactor.getValue();
if (computedAngleCone<0)
computedAngleCone=0.0;
computedAngleCone+=angleCone.getValue();
computedAngleCone+=d_angleCone.getValue();

if (t2*PQ < -computedAngleCone*PQ.norm())
{
Expand All @@ -1344,7 +1350,7 @@ bool LocalMinDistance::testValidity(Line &l, const Vec3 &PQ) const
{
n1 = PQ;
n1.normalize();
if (fabs(dot(AB,n1)) > angleCone.getValue() + 0.0001 ) // dot(AB,n1) should be equal to 0
if (fabs(dot(AB,n1)) > d_angleCone.getValue() + 0.0001 ) // dot(AB,n1) should be equal to 0
{
// means that proximity was detected with a null determinant
// in function computeIntersection
Expand All @@ -1361,7 +1367,7 @@ bool LocalMinDistance::testValidity(Triangle &t, const Vec3 &PQ) const
const TriangleCollisionModel<sofa::defaulttype::Vec3Types> *tM = t.getCollisionModel();
const bool bothSide_computation = tM->d_bothSide.getValue();

if (!filterIntersection.getValue() || bothSide_computation)
if (!d_filterIntersection.getValue() || bothSide_computation)
return true;

const Vec3& pt1 = t.p1();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,23 @@ class SOFA_COMPONENT_COLLISION_DETECTION_INTERSECTION_API LocalMinDistance : pub

typedef core::collision::IntersectorFactory<LocalMinDistance> IntersectorFactory;

Data<bool> filterIntersection; ///< Activate LMD filter
Data<double> angleCone; ///< Filtering cone extension angle
Data<double> coneFactor; ///< Factor for filtering cone angle computation
Data<bool> useLMDFilters; ///< Use external cone computation (Work in Progress)
SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data<bool> filterIntersection;

SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data<double> angleCone;

SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data<double> coneFactor;

SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data<bool> useLMDFilters;


Data<bool> d_filterIntersection; ///< Activate LMD filter
Data<double> d_angleCone; ///< Filtering cone extension angle
Data<double> d_coneFactor; ///< Factor for filtering cone angle computation
Data<bool> d_useLMDFilters; ///< Use external cone computation (Work in Progress)

protected:
LocalMinDistance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ MeshMinProximityIntersection::MeshMinProximityIntersection(MinProximityIntersect
{
if (addSelf)
{
if (intersection->usePointPoint.getValue())
if (intersection->d_usePointPoint.getValue())
intersection->intersectors.add<PointCollisionModel<sofa::defaulttype::Vec3Types>, PointCollisionModel<sofa::defaulttype::Vec3Types>, MeshMinProximityIntersection>(this);
else
intersection->intersectors.ignore<PointCollisionModel<sofa::defaulttype::Vec3Types>, PointCollisionModel<sofa::defaulttype::Vec3Types>>();

if(intersection->useLinePoint.getValue())
if(intersection->d_useLinePoint.getValue())
intersection->intersectors.add<LineCollisionModel<sofa::defaulttype::Vec3Types>, PointCollisionModel<sofa::defaulttype::Vec3Types>, MeshMinProximityIntersection>(this);
else
intersection->intersectors.ignore<LineCollisionModel<sofa::defaulttype::Vec3Types>, PointCollisionModel<sofa::defaulttype::Vec3Types>>();

if(intersection->useLineLine.getValue())
if(intersection->d_useLineLine.getValue())
intersection->intersectors.add<LineCollisionModel<sofa::defaulttype::Vec3Types>, LineCollisionModel<sofa::defaulttype::Vec3Types>, MeshMinProximityIntersection>(this);
else
intersection->intersectors.ignore<LineCollisionModel<sofa::defaulttype::Vec3Types>, LineCollisionModel<sofa::defaulttype::Vec3Types>>();
Expand All @@ -60,7 +60,7 @@ MeshMinProximityIntersection::MeshMinProximityIntersection(MinProximityIntersect
intersection->intersectors.ignore<TriangleCollisionModel<sofa::defaulttype::Vec3Types>, LineCollisionModel<sofa::defaulttype::Vec3Types>>();
intersection->intersectors.ignore<TriangleCollisionModel<sofa::defaulttype::Vec3Types>, TriangleCollisionModel<sofa::defaulttype::Vec3Types>>();

if (intersection->useSphereTriangle.getValue())
if (intersection->d_useSphereTriangle.getValue())
{
intersection->intersectors.add<SphereCollisionModel<sofa::defaulttype::Vec3Types>, PointCollisionModel<sofa::defaulttype::Vec3Types>, MeshMinProximityIntersection>(this);
intersection->intersectors.add<RigidSphereModel, PointCollisionModel<sofa::defaulttype::Vec3Types>, MeshMinProximityIntersection>(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ int MeshNewProximityIntersection::computeIntersection(Triangle& e1, Line& e2, Ou
n += doIntersectionTrianglePoint(dist2, f1, p1, p2, p3, pn, q1, contacts, e2.getIndex(), false);
n += doIntersectionTrianglePoint(dist2, f1, p1, p2, p3, pn, q2, contacts, e2.getIndex(), false);

if (intersection->useLineLine.getValue())
if (intersection->d_useLineLine.getValue())
{
if (f1&TriangleCollisionModel<sofa::defaulttype::Vec3Types>::FLAG_E12)
n += doIntersectionLineLine(dist2, p1, p2, q1, q2, contacts, e2.getIndex());
Expand Down Expand Up @@ -303,7 +303,7 @@ int MeshNewProximityIntersection::computeIntersection(Triangle& e1, Triangle& e2
if (f2&TriangleCollisionModel<sofa::defaulttype::Vec3Types>::FLAG_P3)
n += doIntersectionTrianglePoint(dist2, f1, p1, p2, p3, pn, q3, contacts, id2+2, false, useNormal);

if (intersection->useLineLine.getValue())
if (intersection->d_useLineLine.getValue())
{
if (f1&TriangleCollisionModel<sofa::defaulttype::Vec3Types>::FLAG_E12)
{
Expand Down
Loading
Loading