From d04ef4b50c52d85aa3cd0525dfdbb7676881d5b6 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Wed, 27 Dec 2023 13:14:33 +0100 Subject: [PATCH] [Topology.Container.Dynamic] GeometryAlgorithms: support generic State (#4362) --- .../DynamicSparseGridGeometryAlgorithms.h | 3 +-- .../dynamic/PointSetGeometryAlgorithms.h | 16 +++++++++------- .../dynamic/PointSetGeometryAlgorithms.inl | 7 +++---- .../dynamic/TriangleSetGeometryAlgorithms.inl | 2 +- .../utility/TopologicalChangeProcessor.cpp | 7 ++++--- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/DynamicSparseGridGeometryAlgorithms.h b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/DynamicSparseGridGeometryAlgorithms.h index 3aea8ce9a7f..8b557aebee7 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/DynamicSparseGridGeometryAlgorithms.h +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/DynamicSparseGridGeometryAlgorithms.h @@ -25,7 +25,6 @@ #include #include -#include namespace sofa::component::topology::container::dynamic { @@ -42,7 +41,7 @@ class DynamicSparseGridGeometryAlgorithms : public HexahedronSetGeometryAlgorith typedef typename DataTypes::VecCoord VecCoord; typedef typename DataTypes::Real Real; typedef typename DataTypes::Coord Coord; - typedef sofa::core::behavior::MechanicalState MObject; + typedef sofa::core::State MObject; protected: DynamicSparseGridGeometryAlgorithms() : HexahedronSetGeometryAlgorithms() diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/PointSetGeometryAlgorithms.h b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/PointSetGeometryAlgorithms.h index bb8e4fd7105..1be126bdaa8 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/PointSetGeometryAlgorithms.h +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/PointSetGeometryAlgorithms.h @@ -24,10 +24,12 @@ #include #include -#include +#include + #include #include + namespace sofa::component::topology::container::dynamic { @@ -84,8 +86,8 @@ class PointSetGeometryAlgorithms : public core::topology::GeometryAlgorithms const Coord& getPointRestPosition(const PointID pointId) const; - /** \brief Returns the object where the mechanical DOFs are stored */ - sofa::core::behavior::MechanicalState *getDOF() const { return object; } + /** \brief Returns the object where the DOFs are stored */ + sofa::core::State *getDOF() const { return object; } //float PointIndicesScale; float getIndicesScale() const; @@ -93,16 +95,16 @@ class PointSetGeometryAlgorithms : public core::topology::GeometryAlgorithms template static bool canCreate(T*& obj, core::objectmodel::BaseContext* context, core::objectmodel::BaseObjectDescription* arg) { - if (context->getMechanicalState() && dynamic_cast*>(context->getMechanicalState()) == nullptr) + if (context->getState() && dynamic_cast*>(context->getState()) == nullptr) { - arg->logError(std::string("No mechanical state with the datatype '") + DataTypes::Name() + + arg->logError(std::string("No state with the datatype '") + DataTypes::Name() + "' found in the context node."); return false; } return BaseObject::canCreate(obj, context, arg); } - /** \brief Called by the MechanicalObject state change callback to initialize added + /** \brief Called by the state change callback to initialize added * points according to the topology (topology element & local coordinates) */ void initPointsAdded(const type::vector< sofa::Index > &indices, const type::vector< core::topology::PointAncestorElem > &ancestorElems @@ -114,7 +116,7 @@ class PointSetGeometryAlgorithms : public core::topology::GeometryAlgorithms protected: /** the object where the mechanical DOFs are stored */ - sofa::core::behavior::MechanicalState *object; + sofa::core::State *object; sofa::core::topology::BaseMeshTopology* m_topology; Data d_showIndicesScale; ///< Debug : scale for view topology indices Data d_showPointIndices; ///< Debug : view Point indices diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/PointSetGeometryAlgorithms.inl b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/PointSetGeometryAlgorithms.inl index e5664ddd632..d3abf8ff63f 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/PointSetGeometryAlgorithms.inl +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/PointSetGeometryAlgorithms.inl @@ -22,7 +22,6 @@ #pragma once #include #include -#include #include #include #include @@ -48,9 +47,9 @@ void PointSetGeometryAlgorithms< DataTypes >::init() this->d_componentState.setValue(ComponentState::Invalid); if ( this->d_tagMechanics.getValue().size()>0) { const sofa::core::objectmodel::Tag mechanicalTag(this->d_tagMechanics.getValue()); - object = this->getContext()->core::objectmodel::BaseContext::template get< core::behavior::MechanicalState< DataTypes > >(mechanicalTag,sofa::core::objectmodel::BaseContext::SearchUp); + object = this->getContext()->core::objectmodel::BaseContext::template get< core::State< DataTypes > >(mechanicalTag,sofa::core::objectmodel::BaseContext::SearchUp); } else { - object = this->getContext()->core::objectmodel::BaseContext::template get< core::behavior::MechanicalState< DataTypes > >(); + object = this->getContext()->core::objectmodel::BaseContext::template get< core::State< DataTypes > >(); } core::topology::GeometryAlgorithms::init(); @@ -72,7 +71,7 @@ void PointSetGeometryAlgorithms< DataTypes >::init() if(this->object ==nullptr) { - msg_error() << "Unable to get a valid mechanical object from the context"; + msg_error() << "Unable to get a valid state from the context"; return; } this->d_componentState.setValue(ComponentState::Valid); diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.inl b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.inl index 2061c94a1a1..9da33c5bf4f 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.inl +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.inl @@ -2646,7 +2646,7 @@ bool TriangleSetGeometryAlgorithms< DataTypes >::Suture2Points(TriangleID ind_ta x_created.push_back((Real)point_created[1]); x_created.push_back((Real)point_created[2]); - core::behavior::MechanicalState* state = this->getDOF(); + auto* state = this->getDOF(); sofa::helper::WriteAccessor< Data > x_wA = *state->write(core::VecCoordId::position()); sofa::helper::WriteAccessor< Data > v_wA = *state->write(core::VecDerivId::velocity()); diff --git a/Sofa/Component/Topology/Utility/src/sofa/component/topology/utility/TopologicalChangeProcessor.cpp b/Sofa/Component/Topology/Utility/src/sofa/component/topology/utility/TopologicalChangeProcessor.cpp index 942d50f3d66..955e923c041 100644 --- a/Sofa/Component/Topology/Utility/src/sofa/component/topology/utility/TopologicalChangeProcessor.cpp +++ b/Sofa/Component/Topology/Utility/src/sofa/component/topology/utility/TopologicalChangeProcessor.cpp @@ -20,11 +20,13 @@ * Contact information: contact@sofa-framework.org * ******************************************************************************/ #include + #include #include - -#include #include +#include +#include +#include #include #include @@ -33,7 +35,6 @@ #include #include #include -#include #include