Skip to content

Commit

Permalink
[Collision.Geometry+Response] Rename Data (sofa-framework#4676)
Browse files Browse the repository at this point in the history
* [Collision.Geometry+Response] Rename Data

* [Collision.Geometry+Response] Add missed link to parent

* Update Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/CollisionResponse.cpp

Co-authored-by: Alex Bilger <[email protected]>

* Update Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/CollisionResponse.cpp

Co-authored-by: Alex Bilger <[email protected]>

* [Geometry] Adding description to variable and fixing bug

* [Collision.Geometry+Response] Rename Data of Inl files

* Update Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/CylinderModel.inl

Co-authored-by: Alex Bilger <[email protected]>

* Update Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/RayModel.h

Co-authored-by: Alex Bilger <[email protected]>

* Fix typos

* Update Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/FrictionContact.inl

Co-authored-by: Alex Bilger <[email protected]>

---------

Co-authored-by: Alex Bilger <[email protected]>
Co-authored-by: Frederick Roy <[email protected]>
  • Loading branch information
3 people authored May 13, 2024
1 parent 05a1485 commit 425a748
Show file tree
Hide file tree
Showing 24 changed files with 163 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ bool LocalMinDistance::testValidity(Point &p, const Vec3 &PQ) const
{
/// validity test with nMean, except if bothSide
const PointCollisionModel<sofa::defaulttype::Vec3Types> *pM = p.getCollisionModel();
const bool bothSide_computation = pM->bothSide.getValue();
const bool bothSide_computation = pM->d_bothSide.getValue();
nMean.normalize();
if (dot(nMean, PQ) < -d_angleCone.getValue() * PQ.norm() && !bothSide_computation)
{
Expand Down Expand Up @@ -1268,7 +1268,7 @@ bool LocalMinDistance::testValidity(Line &l, const Vec3 &PQ) const
return true;

const LineCollisionModel<sofa::defaulttype::Vec3Types> *lM = l.getCollisionModel();
const bool bothSide_computation = lM->bothSide.getValue();
const bool bothSide_computation = lM->d_bothSide.getValue();

Vec3 n1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ public :

int getLineFlags(sofa::Index i);

Data<bool> bothSide; ///< to activate collision on both-side of the both side of the line model (when surface normals are defined on these lines)
SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data<bool> bothSide;


Data<bool> d_bothSide; ///< to activate collision on both-side of the both side of the line model (when surface normals are defined on these lines)

/// Pre-construction check method called by ObjectFactory.
/// Check that DataTypes matches the MechanicalState.
Expand All @@ -164,7 +168,11 @@ public :

void computeBBox(const core::ExecParams* params, bool onlyVisible) override;

Data<bool> m_displayFreePosition; ///< Display Collision Model Points free position(in green)
SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data<bool> m_displayFreePosition;


Data<bool> d_displayFreePosition; ///< Display Collision Model Points free position(in green)

/// Link to be set to the topology container in the component graph.
SingleLink<LineCollisionModel<DataTypes>, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ using core::topology::BaseMeshTopology;

template<class DataTypes>
LineCollisionModel<DataTypes>::LineCollisionModel()
: bothSide(initData(&bothSide, false, "bothSide", "activate collision on both side of the line model (when surface normals are defined on these lines)") )
, m_displayFreePosition(initData(&m_displayFreePosition, false, "displayFreePosition", "Display Collision Model Points free position(in green)") )
: d_bothSide(initData(&d_bothSide, false, "bothSide", "activate collision on both side of the line model (when surface normals are defined on these lines)") )
, d_displayFreePosition(initData(&d_displayFreePosition, false, "displayFreePosition", "Display Collision Model Points free position(in green)") )
, l_topology(initLink("topology", "link to the topology container"))
, mstate(nullptr), topology(nullptr), meshRevision(-1)
{
enum_type = LINE_TYPE;

bothSide.setParent(&d_bothSide);
m_displayFreePosition.setParent(&d_displayFreePosition);
}


Expand Down Expand Up @@ -330,7 +333,7 @@ void LineCollisionModel<DataTypes>::draw(const core::visual::VisualParams* vpara
const auto c = getColor4f();
vparams->drawTool()->drawLines(points, 1, sofa::type::RGBAColor(c[0], c[1], c[2], c[3]));

if (m_displayFreePosition.getValue())
if (d_displayFreePosition.getValue())
{
std::vector< type::Vec3 > pointsFree;
for (sofa::Size i=0; i<size; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ class PointCollisionModel : public core::CollisionModel

const Deriv& velocity(sofa::Index index) const;

Data<bool> bothSide; ///< to activate collision on both side of the point model (when surface normals are defined on these points)
SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data<bool> bothSide;


Data<bool> d_bothSide; ///< to activate collision on both side of the point model (when surface normals are defined on these points)

/// Pre-construction check method called by ObjectFactory.
/// Check that DataTypes matches the MechanicalState.
Expand Down Expand Up @@ -129,11 +133,17 @@ class PointCollisionModel : public core::CollisionModel

core::behavior::MechanicalState<DataTypes>* mstate;

Data<bool> computeNormals; ///< activate computation of normal vectors (required for some collision detection algorithms)
SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data<bool> computeNormals;

SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data<bool> m_displayFreePosition;

Data<bool> d_computeNormals; ///< activate computation of normal vectors (required for some collision detection algorithms)

VecDeriv normals;

Data<bool> m_displayFreePosition; ///< Display Collision Model Points free position(in green)
Data<bool> d_displayFreePosition; ///< Display Collision Model Points free position(in green)

/// Link to be set to the topology container in the component graph.
SingleLink<PointCollisionModel<DataTypes>, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ namespace sofa::component::collision::geometry

template<class DataTypes>
PointCollisionModel<DataTypes>::PointCollisionModel()
: bothSide(initData(&bothSide, false, "bothSide", "activate collision on both side of the point model (when surface normals are defined on these points)") )
: d_bothSide(initData(&d_bothSide, false, "bothSide", "activate collision on both side of the point model (when surface normals are defined on these points)") )
, mstate(nullptr)
, computeNormals( initData(&computeNormals, false, "computeNormals", "activate computation of normal vectors (required for some collision detection algorithms)") )
, m_displayFreePosition(initData(&m_displayFreePosition, false, "displayFreePosition", "Display Collision Model Points free position(in green)") )
, d_computeNormals(initData(&d_computeNormals, false, "computeNormals", "activate computation of normal vectors (required for some collision detection algorithms)") )
, d_displayFreePosition(initData(&d_displayFreePosition, false, "displayFreePosition", "Display Collision Model Points free position(in green)") )
, l_topology(initLink("topology", "link to the topology container"))
{
enum_type = POINT_TYPE;

bothSide.setParent(&d_bothSide);
computeNormals.setParent(&d_computeNormals);
m_displayFreePosition.setParent(&d_displayFreePosition);
}

template<class DataTypes>
Expand Down Expand Up @@ -69,7 +73,7 @@ void PointCollisionModel<DataTypes>::init()

const int npoints = mstate->getSize();
resize(npoints);
if (computeNormals.getValue()) updateNormals();
if (d_computeNormals.getValue()) updateNormals();
}


Expand Down Expand Up @@ -125,7 +129,7 @@ void PointCollisionModel<DataTypes>::computeBoundingTree(int maxDepth)
if (updated) cubeModel->resize(0);
if (!isMoving() && !cubeModel->empty() && !updated) return; // No need to recompute BBox if immobile

if (computeNormals.getValue()) updateNormals();
if (d_computeNormals.getValue()) updateNormals();

cubeModel->resize(size);
if (!empty())
Expand Down Expand Up @@ -155,7 +159,7 @@ void PointCollisionModel<DataTypes>::computeContinuousBoundingTree(SReal dt, int
}
if (!isMoving() && !cubeModel->empty() && !updated) return; // No need to recompute BBox if immobile

if (computeNormals.getValue()) updateNormals();
if (d_computeNormals.getValue()) updateNormals();

type::Vec3 minElem, maxElem;

Expand Down Expand Up @@ -362,7 +366,7 @@ void PointCollisionModel<DataTypes>::draw(const core::visual::VisualParams* vpar
vparams->drawTool()->drawPoints(pointsP, 3, sofa::type::RGBAColor(c[0], c[1], c[2], c[3]));
vparams->drawTool()->drawLines(pointsL, 1, sofa::type::RGBAColor(c[0], c[1], c[2], c[3]));

if (m_displayFreePosition.getValue())
if (d_displayFreePosition.getValue())
{
std::vector< type::Vec3 > pointsPFree;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ using namespace sofa::type;
using namespace sofa::defaulttype;

RayCollisionModel::RayCollisionModel(SReal length)
: defaultLength(initData(&defaultLength, length, "", "TODO"))
: d_defaultLength(initData(&d_defaultLength, length, "defaultLength", "The default length for all rays in this collision model"))
{
this->contactResponse.setValue("RayContact"); // use RayContact response class
defaultLength.setParent(&d_defaultLength);
}

void RayCollisionModel::resize(sofa::Size size)
Expand All @@ -50,7 +51,7 @@ void RayCollisionModel::resize(sofa::Size size)
{
length.reserve(size);
while (length.size() < size)
length.push_back(defaultLength.getValue());
length.push_back(d_defaultLength.getValue());
direction.reserve(size);
while (direction.size() < size)
direction.push_back(Vec3());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ class SOFA_COMPONENT_COLLISION_GEOMETRY_API RayCollisionModel : public core::Col
sofa::type::vector<SReal> length;
sofa::type::vector<type::Vec3> direction;

Data<SReal> defaultLength; ///< TODO
SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data<SReal> defaultLength;




Data<SReal> d_defaultLength;

std::set<response::contact::BaseRayContact*> contacts;
core::behavior::MechanicalState<defaulttype::Vec3Types>* mstate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class SphereCollisionModel : public core::CollisionModel

core::behavior::MechanicalState<DataTypes>* getMechanicalState() { return mstate; }

const VecReal& getR() const { return this->radius.getValue(); }
const VecReal& getR() const { return this->d_radius.getValue(); }

Real getRadius(const sofa::Index i) const;

Expand Down Expand Up @@ -158,9 +158,14 @@ class SphereCollisionModel : public core::CollisionModel
return obj;
}

//TODO(dmarchal) guideline de sofa.
Data< VecReal > radius; ///< Radius of each sphere
Data< SReal > defaultRadius; ///< Default Radius
SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data< VecReal > radius;

SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data<SReal> defaultRadius;

Data< VecReal > d_radius; ///< Radius of each sphere
Data< SReal > d_defaultRadius; ///< Default Radius
Data< bool > d_showImpostors; ///< Draw spheres as impostors instead of "real" spheres


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,21 @@ namespace sofa::component::collision::geometry

template<class DataTypes>
SphereCollisionModel<DataTypes>::SphereCollisionModel()
: radius(initData(&radius, "listRadius","Radius of each sphere"))
, defaultRadius(initData(&defaultRadius,(SReal)(1.0), "radius","Default Radius"))
: d_radius(initData(&d_radius, "listRadius", "Radius of each sphere"))
, d_defaultRadius(initData(&d_defaultRadius, (SReal)(1.0), "radius", "Default Radius"))
, d_showImpostors(initData(&d_showImpostors, true, "showImpostors", "Draw spheres as impostors instead of \"real\" spheres"))
, mstate(nullptr)
{
enum_type = SPHERE_TYPE;

radius.setParent(&d_radius);
defaultRadius.setParent(&d_defaultRadius);
}

template<class DataTypes>
SphereCollisionModel<DataTypes>::SphereCollisionModel(core::behavior::MechanicalState<DataTypes>* _mstate )
: radius(initData(&radius, "listRadius","Radius of each sphere"))
, defaultRadius(initData(&defaultRadius,(SReal)(1.0), "radius","Default Radius. (default=1.0)"))
: d_radius(initData(&d_radius, "listRadius", "Radius of each sphere"))
, d_defaultRadius(initData(&d_defaultRadius, (SReal)(1.0), "radius", "Default Radius. (default=1.0)"))
, d_showImpostors(initData(&d_showImpostors, true, "showImpostors", "Draw spheres as impostors instead of \"real\" spheres"))
, mstate(_mstate)
{
Expand All @@ -57,13 +60,13 @@ void SphereCollisionModel<DataTypes>::resize(sofa::Size size)
{
this->core::CollisionModel::resize(size);

helper::WriteAccessor< Data<VecReal> > r = radius;
helper::WriteAccessor< Data<VecReal> > r = d_radius;

if (r.size() < size)
{
r.reserve(size);
while (r.size() < size)
r.push_back((Real)defaultRadius.getValue());
r.push_back((Real)d_defaultRadius.getValue());
}
else
{
Expand Down Expand Up @@ -249,10 +252,10 @@ void SphereCollisionModel<DataTypes>::computeContinuousBoundingTree(SReal dt, in
template <class DataTypes>
typename SphereCollisionModel<DataTypes>::Real SphereCollisionModel<DataTypes>::getRadius(const sofa::Index i) const
{
if(i < this->radius.getValue().size())
return radius.getValue()[i];
if(i < this->d_radius.getValue().size())
return d_radius.getValue()[i];
else
return (Real) defaultRadius.getValue();
return (Real) d_defaultRadius.getValue();
}

template<class DataTypes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@ namespace sofa::component::collision::geometry
constexpr const char* MODULE_NAME = "@PROJECT_NAME@";
constexpr const char* MODULE_VERSION = "@PROJECT_VERSION@";
} // namespace sofa::component::collision::geometry

#ifdef SOFA_BUILD_SOFA_COMPONENT_COLLISION_GEOMETRY
#define SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
#else
#define SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA() \
SOFA_ATTRIBUTE_DEPRECATED("v24.06", "v24.12", \
"Data renamed according to the guidelines")
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ class BarycentricStickContact : public core::collision::Contact
void setInteractionTags(MechanicalState1* mstate1, MechanicalState2* mstate2);

public:
Data<bool> f_keepAlive; ///< set to true to keep this contact alive even after collisions are no longer detected

SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA()
Data<bool> f_keepAlive;

Data<bool> d_keepAlive; ///< set to true to keep this contact alive even after collisions are no longer detected

void cleanup() override;

Expand All @@ -84,10 +88,10 @@ class BarycentricStickContact : public core::collision::Contact
void removeResponse() override;

/// Return true if this contact should be kept alive, even if objects are no longer in collision
bool keepAlive() override { return f_keepAlive.getValue(); }
bool keepAlive() override { return d_keepAlive.getValue(); }

/// Control the keepAlive flag of the contact.
void setKeepAlive(bool val) override { f_keepAlive.setValue(val); }
void setKeepAlive(bool val) override { d_keepAlive.setValue(val); }

void draw(const core::visual::VisualParams* vparams) override;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ namespace sofa::component::collision::response::contact
template < class TCollisionModel1, class TCollisionModel2, class ResponseDataTypes >
BarycentricStickContact<TCollisionModel1,TCollisionModel2,ResponseDataTypes>::BarycentricStickContact(CollisionModel1* model1, CollisionModel2* model2, Intersection* intersectionMethod)
: model1(model1), model2(model2), intersectionMethod(intersectionMethod), ff(nullptr), parent(nullptr)
, f_keepAlive(initData(&f_keepAlive, true, "keepAlive", "set to true to keep this contact alive even after collisions are no longer detected"))
, d_keepAlive(initData(&d_keepAlive, true, "keepAlive", "set to true to keep this contact alive even after collisions are no longer detected"))
{
mapper1.setCollisionModel(model1);
mapper2.setCollisionModel(model2);

f_keepAlive.setParent(&d_keepAlive);
}

template < class TCollisionModel1, class TCollisionModel2, class ResponseDataTypes >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ int CollisionResponseClass = core::RegisterObject("Default class to create react
;

CollisionResponse::CollisionResponse()
: response(initData(&response, "response", "contact response class"))
, responseParams(initData(&responseParams, "responseParams", "contact response parameters (syntax: name1=value1&name2=value2&...)"))
: d_response(initData(&d_response, "response", "contact response class"))
, d_responseParams(initData(&d_responseParams, "responseParams", "contact response parameters (syntax: name1=value1&name2=value2&...)"))
{
response.setParent(&d_response);
responseParams.setParent(&d_responseParams);
}

sofa::helper::OptionsGroup CollisionResponse::initializeResponseOptions(sofa::core::objectmodel::BaseContext *context)
Expand Down Expand Up @@ -70,9 +72,9 @@ sofa::helper::OptionsGroup CollisionResponse::initializeResponseOptions(sofa::co
void CollisionResponse::init()
{
Inherit1::init();
if (response.getValue().size() == 0)
if (d_response.getValue().size() == 0)
{
response.setValue(initializeResponseOptions(getContext()));
d_response.setValue(initializeResponseOptions(getContext()));
}
}

Expand All @@ -96,17 +98,17 @@ void CollisionResponse::reset()

void CollisionResponse::setDefaultResponseType(const std::string &responseT)
{
if (response.getValue().size() == 0)
if (d_response.getValue().size() == 0)
{
const type::vector<std::string> listResponse(1,responseT);
const sofa::helper::OptionsGroup responseOptions(listResponse);
response.setValue(responseOptions);
d_response.setValue(responseOptions);
}
else
{
sofa::helper::OptionsGroup* options = response.beginEdit();
sofa::helper::OptionsGroup* options = d_response.beginEdit();
options->setSelectedItem(responseT);
response.endEdit();
d_response.endEdit();
}
}

Expand Down Expand Up @@ -287,8 +289,8 @@ void CollisionResponse::setNumberOfContacts() const

std::string CollisionResponse::getContactResponse(core::CollisionModel* model1, core::CollisionModel* model2)
{
std::string responseUsed = response.getValue().getSelectedItem();
const std::string params = responseParams.getValue();
std::string responseUsed = d_response.getValue().getSelectedItem();
const std::string params = d_responseParams.getValue();
if (!params.empty())
{
responseUsed += '?';
Expand Down
Loading

0 comments on commit 425a748

Please sign in to comment.