Skip to content

Commit

Permalink
[Topology.Container.Dynamic] GeometryAlgorithms: support generic State (
Browse files Browse the repository at this point in the history
  • Loading branch information
fredroy authored Dec 27, 2023
1 parent a624001 commit d04ef4b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

#include <sofa/component/topology/container/dynamic/HexahedronSetGeometryAlgorithms.h>
#include <sofa/component/topology/container/dynamic/DynamicSparseGridTopologyContainer.h>
#include <sofa/core/behavior/MechanicalState.h>

namespace sofa::component::topology::container::dynamic
{
Expand All @@ -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<DataTypes> MObject;
typedef sofa::core::State<DataTypes> MObject;
protected:
DynamicSparseGridGeometryAlgorithms()
: HexahedronSetGeometryAlgorithms<DataTypes>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@

#include <sofa/core/topology/BaseTopology.h>
#include <sofa/core/topology/BaseMeshTopology.h>
#include <sofa/core/behavior/MechanicalState.h>
#include <sofa/core/State.h>

#include <sofa/defaulttype/VecTypes.h>
#include <sofa/defaulttype/RigidTypes.h>


namespace sofa::component::topology::container::dynamic
{

Expand Down Expand Up @@ -84,25 +86,25 @@ 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<DataTypes> *getDOF() const { return object; }
/** \brief Returns the object where the DOFs are stored */
sofa::core::State<DataTypes> *getDOF() const { return object; }

//float PointIndicesScale;
float getIndicesScale() const;

template<class T>
static bool canCreate(T*& obj, core::objectmodel::BaseContext* context, core::objectmodel::BaseObjectDescription* arg)
{
if (context->getMechanicalState() && dynamic_cast<sofa::core::behavior::MechanicalState<DataTypes>*>(context->getMechanicalState()) == nullptr)
if (context->getState() && dynamic_cast<sofa::core::State<DataTypes>*>(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
Expand All @@ -114,7 +116,7 @@ class PointSetGeometryAlgorithms : public core::topology::GeometryAlgorithms

protected:
/** the object where the mechanical DOFs are stored */
sofa::core::behavior::MechanicalState<DataTypes> *object;
sofa::core::State<DataTypes> *object;
sofa::core::topology::BaseMeshTopology* m_topology;
Data<float> d_showIndicesScale; ///< Debug : scale for view topology indices
Data<bool> d_showPointIndices; ///< Debug : view Point indices
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#pragma once
#include <sofa/component/topology/container/dynamic/PointSetGeometryAlgorithms.h>
#include <sofa/core/visual/VisualParams.h>
#include <sofa/core/behavior/MechanicalState.h>
#include <sofa/core/objectmodel/Tag.h>
#include <sofa/simulation/fwd.h>
#include <sofa/simulation/Simulation.h>
Expand All @@ -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();

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataTypes>* state = this->getDOF();
auto* state = this->getDOF();

sofa::helper::WriteAccessor< Data<VecCoord> > x_wA = *state->write(core::VecCoordId::position());
sofa::helper::WriteAccessor< Data<VecDeriv> > v_wA = *state->write(core::VecDerivId::velocity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
* Contact information: [email protected] *
******************************************************************************/
#include <sofa/component/topology/utility/TopologicalChangeProcessor.h>

#include <sofa/core/visual/VisualParams.h>
#include <sofa/core/ObjectFactory.h>

#include <sofa/simulation/Node.h>
#include <sofa/core/objectmodel/DataFileName.h>
#include <sofa/core/behavior/MechanicalState.h>
#include <sofa/simulation/Node.h>
#include <sofa/simulation/Simulation.h>

#include <sofa/component/topology/container/dynamic/TriangleSetTopologyModifier.h>
#include <sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.h>
Expand All @@ -33,7 +35,6 @@
#include <sofa/component/topology/container/dynamic/TetrahedronSetTopologyModifier.h>
#include <sofa/component/topology/container/dynamic/HexahedronSetTopologyModifier.h>
#include <sofa/component/topology/container/dynamic/PointSetTopologyModifier.h>
#include <sofa/simulation/Simulation.h>

#include <ctime>

Expand Down

0 comments on commit d04ef4b

Please sign in to comment.