Skip to content

Commit

Permalink
[Constraints] Remove TopologyDataHandler in constraints as they were …
Browse files Browse the repository at this point in the history
…only redefining a Data resize operation. This is already done directly inside the TopologyData. The destroyFunction should be only overriden if a complex behavior is needed.

(cherry picked from commit 6750256)
  • Loading branch information
epernod committed Jun 7, 2021
1 parent bbf79a1 commit afa90a3
Show file tree
Hide file tree
Showing 28 changed files with 37 additions and 492 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,13 @@ class DOFBlockerLMConstraint : public core::behavior::LMConstraint<DataTypes,Da
, f_indices(core::objectmodel::Base::initData(&f_indices, "indices", "List of the index of particles to be fixed"))
, showSizeAxis(core::objectmodel::Base::initData(&showSizeAxis, 1.0f, "showSizeAxis", "size of the vector used to display the constrained axis"))
, l_topology(initLink("topology", "link to the topology container"))
, m_pointHandler(nullptr)
{

}

~DOFBlockerLMConstraint()
{
if (m_pointHandler)
delete m_pointHandler;

}

public:
Expand Down Expand Up @@ -117,25 +115,8 @@ class DOFBlockerLMConstraint : public core::behavior::LMConstraint<DataTypes,Da
/// Link to be set to the topology container in the component graph.
SingleLink<DOFBlockerLMConstraint<DataTypes>, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology;

class FCTPointHandler : public sofa::component::topology::TopologyDataHandler<core::topology::BaseMeshTopology::Point, helper::vector<Index> >
{
public:
FCTPointHandler(DOFBlockerLMConstraint<DataTypes>* _fc, sofa::component::topology::PointSubsetData<helper::vector<Index> >* _data)
: sofa::component::topology::TopologyDataHandler<core::topology::BaseMeshTopology::Point, sofa::helper::vector<Index> >(_data), fc(_fc) {}



void applyDestroyFunction(Index /*index*/, value_type& /*T*/);


protected:
DOFBlockerLMConstraint<DataTypes> *fc;
};

protected :
sofa::helper::vector<SetIndexArray> idxEquations;

FCTPointHandler* m_pointHandler;
};

#if !defined(SOFA_COMPONENT_CONSTRAINTSET_DOFBLOCKERLMCONSTRAINT_CPP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,6 @@
namespace sofa::component::constraintset
{

// Define RemovalFunction
template< class DataTypes>
void DOFBlockerLMConstraint<DataTypes>::FCTPointHandler::applyDestroyFunction(Index pointIndex, value_type &)
{
if (fc)
{
fc->removeConstraint((Index) pointIndex);
}
return;
}

template <class DataTypes>
void DOFBlockerLMConstraint<DataTypes>::clearConstraints()
{
Expand Down Expand Up @@ -81,9 +70,8 @@ void DOFBlockerLMConstraint<DataTypes>::init()
{
msg_info() << "Topology path used: '" << l_topology.getLinkedPath() << "'";

// Initialize functions and parameters
m_pointHandler = new FCTPointHandler(this, &f_indices);
f_indices.createTopologyHandler(_topology, m_pointHandler);
// Initialize topological change handling
f_indices.createTopologyHandler(_topology);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ class FixedLMConstraint : public core::behavior::LMConstraint<DataTypes,DataTyp

~FixedLMConstraint()
{
if (m_pointHandler)
delete m_pointHandler;

}

public:
Expand Down Expand Up @@ -101,30 +100,11 @@ class FixedLMConstraint : public core::behavior::LMConstraint<DataTypes,DataTyp
/// Link to be set to the topology container in the component graph.
SingleLink<FixedLMConstraint<DataTypes>, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology;

class FCPointHandler : public sofa::component::topology::TopologyDataHandler<core::topology::BaseMeshTopology::Point, SetIndexArray >
{
public:
typedef typename FixedLMConstraint<DataTypes>::SetIndexArray SetIndexArray;
FCPointHandler(FixedLMConstraint<DataTypes>* _fc, sofa::component::topology::PointSubsetData<SetIndexArray >* _data)
: sofa::component::topology::TopologyDataHandler<core::topology::BaseMeshTopology::Point, SetIndexArray >(_data), fc(_fc) {}



void applyDestroyFunction(Index /*index*/, value_type& /*T*/);

protected:
FixedLMConstraint<DataTypes> *fc;
};

protected :

Deriv X,Y,Z;
SetIndexArray idxX, idxY, idxZ;
std::map< Index, Coord> restPosition;


FCPointHandler* m_pointHandler;

};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,12 @@
namespace sofa::component::constraintset
{


// Define RemovalFunction
template< class DataTypes>
void FixedLMConstraint<DataTypes>::FCPointHandler::applyDestroyFunction(Index pointIndex, value_type &)
{
if (fc)
{
fc->removeConstraint((Index) pointIndex);
}
return;
}

template <class DataTypes>
FixedLMConstraint<DataTypes>::FixedLMConstraint(MechanicalState *dof)
: core::behavior::LMConstraint<DataTypes,DataTypes>(dof,dof)
, f_indices(core::objectmodel::Base::initData(&f_indices, "indices", "List of the index of particles to be fixed"))
, _drawSize(core::objectmodel::Base::initData(&_drawSize,0.0,"drawSize","0 -> point based rendering, >0 -> radius of spheres") )
, l_topology(initLink("topology", "link to the topology container"))
, m_pointHandler(nullptr)
{

}
Expand Down Expand Up @@ -104,9 +91,8 @@ void FixedLMConstraint<DataTypes>::init()
{
msg_info() << "Topology path used: '" << l_topology.getLinkedPath() << "'";

// Initialize functions and parameters
m_pointHandler = new FCPointHandler(this, &f_indices);
f_indices.createTopologyHandler(_topology, m_pointHandler);
// Initialize topological change handling
f_indices.createTopologyHandler(_topology);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,31 +140,13 @@ public :
/// Draw the constrained points (= border mesh points)
void draw(const core::visual::VisualParams* vparams) override;

class FCPointHandler : public component::topology::TopologyDataHandler<core::topology::BaseMeshTopology::Point, SetIndexArray >
{
public:
typedef typename AffineMovementConstraint<DataTypes>::SetIndexArray SetIndexArray;

FCPointHandler(AffineMovementConstraint<DataTypes>* _fc, component::topology::PointSubsetData<SetIndexArray>* _data)
: sofa::component::topology::TopologyDataHandler<core::topology::BaseMeshTopology::Point, SetIndexArray >(_data), fc(_fc) {}

using component::topology::TopologyDataHandler<core::topology::BaseMeshTopology::Point, SetIndexArray >::applyDestroyFunction;
void applyDestroyFunction(Index /*index*/, core::objectmodel::Data<value_type>& /*T*/);

protected:
AffineMovementConstraint<DataTypes> *fc;
};

protected:

template <class DataDeriv>
void projectResponseT(const core::MechanicalParams* mparams, DataDeriv& dx);

private:

/// Handler for subset Data
FCPointHandler* m_pointHandler;

/// Initialize initial positions
void initializeInitialPositions (const SetIndexArray & indices, DataVecCoord& xData, VecCoord& x0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,6 @@
namespace sofa::component::projectiveconstraintset
{

// Define RemovalFunction
template< class DataTypes>
void AffineMovementConstraint<DataTypes>::FCPointHandler::applyDestroyFunction(Index pointIndex, core::objectmodel::Data<value_type>&)
{
if (fc)
{
fc->removeConstraint(pointIndex);
}
}


template <class DataTypes>
AffineMovementConstraint<DataTypes>::AffineMovementConstraint()
: core::behavior::ProjectiveConstraintSet<DataTypes>(nullptr)
Expand All @@ -58,7 +47,6 @@ AffineMovementConstraint<DataTypes>::AffineMovementConstraint()
, m_translation( initData(&m_translation,"translation","translation applied to border points") )
, m_drawConstrainedPoints( initData(&m_drawConstrainedPoints,"drawConstrainedPoints","draw constrained points") )
, l_topology(initLink("topology", "link to the topology container"))
, m_pointHandler(nullptr)
{
if(!m_beginConstraintTime.isSet())
m_beginConstraintTime = 0;
Expand All @@ -71,8 +59,7 @@ AffineMovementConstraint<DataTypes>::AffineMovementConstraint()
template <class DataTypes>
AffineMovementConstraint<DataTypes>::~AffineMovementConstraint()
{
if (m_pointHandler)
delete m_pointHandler;

}

template <class DataTypes>
Expand Down Expand Up @@ -116,9 +103,8 @@ void AffineMovementConstraint<DataTypes>::init()
{
msg_info() << "Topology path used: '" << l_topology.getLinkedPath() << "'";

// Initialize functions and parameters
m_pointHandler = new FCPointHandler(this, &m_indices);
m_indices.createTopologyHandler(_topology, m_pointHandler);
// Initialize topological changes support
m_indices.createTopologyHandler(_topology);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,27 +118,9 @@ class FixedConstraint : public core::behavior::ProjectiveConstraintSet<DataTypes

bool fixAllDOFs() const { return d_fixAll.getValue(); }

class FCPointHandler : public sofa::component::topology::TopologyDataHandler<core::topology::BaseMeshTopology::Point, SetIndexArray >
{
public:
typedef typename FixedConstraint<DataTypes>::SetIndexArray SetIndexArray;

FCPointHandler(FixedConstraint<DataTypes>* _fc, sofa::component::topology::PointSubsetData<SetIndexArray>* _data)
: sofa::component::topology::TopologyDataHandler<core::topology::BaseMeshTopology::Point, SetIndexArray >(_data), fc(_fc) {}


void applyDestroyFunction(Index /*index*/, value_type& /*T*/);

protected:
FixedConstraint<DataTypes> *fc;
};

protected :
/// Function check values of given indices
void checkIndices();

/// Handler for subset Data
FCPointHandler* m_pointHandler;

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,6 @@ using sofa::core::objectmodel::ComponentState;
namespace sofa::component::projectiveconstraintset
{

// Define RemovalFunction
template< class DataTypes>
void FixedConstraint<DataTypes>::FCPointHandler::applyDestroyFunction(Index pointIndex, value_type &)
{
if (fc)
{
fc->removeConstraint((Index) pointIndex);
}
}

template <class DataTypes>
FixedConstraint<DataTypes>::FixedConstraint()
: core::behavior::ProjectiveConstraintSet<DataTypes>(nullptr)
Expand All @@ -58,7 +48,6 @@ FixedConstraint<DataTypes>::FixedConstraint()
, d_projectVelocity( initData(&d_projectVelocity,false,"activate_projectVelocity","activate project velocity to set velocity") )
, l_topology(initLink("topology", "link to the topology container"))
, data(new FixedConstraintInternalData<DataTypes>())
, m_pointHandler(nullptr)
{
// default to indice 0
d_indices.beginEdit()->push_back(0);
Expand All @@ -76,9 +65,6 @@ FixedConstraint<DataTypes>::FixedConstraint()
template <class DataTypes>
FixedConstraint<DataTypes>::~FixedConstraint()
{
if (m_pointHandler)
delete m_pointHandler;

delete data;
}

Expand Down Expand Up @@ -130,9 +116,8 @@ void FixedConstraint<DataTypes>::init()
{
msg_info() << "Topology path used: '" << l_topology.getLinkedPath() << "'";

// Initialize topological functions
m_pointHandler = new FCPointHandler(this, &d_indices);
d_indices.createTopologyHandler(_topology, m_pointHandler);
// Initialize topological changes support
d_indices.createTopologyHandler(_topology);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,6 @@ class FixedPlaneConstraint : public ProjectiveConstraintSet<DataTypes>
FixedPlaneConstraintInternalData<DataTypes> data;
friend class FixedPlaneConstraintInternalData<DataTypes>;

/// Forward class declaration, definition is in the .inl
class FCPointHandler;

/// Handler for subset Data
FCPointHandler* m_pointHandler {nullptr};

/// whether vertices should be selected from 2 parallel planes
bool m_selectVerticesFromPlanes {false};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,6 @@ namespace sofa::component::projectiveconstraintset
using sofa::helper::WriteAccessor;
using sofa::defaulttype::Vec;
using sofa::component::topology::PointSubsetData;
using sofa::component::topology::TopologyDataHandler;


/////////////////////////// DEFINITION OF FCPointHandler (INNER CLASS) /////////////////////////////
template <class DataTypes>
class FixedPlaneConstraint<DataTypes>::FCPointHandler :
public TopologyDataHandler<BaseMeshTopology::Point, SetIndexArray >
{
public:
typedef typename FixedPlaneConstraint<DataTypes>::SetIndexArray SetIndexArray;

FCPointHandler(FixedPlaneConstraint<DataTypes>* _fc, PointSubsetData<SetIndexArray>* _data)
: TopologyDataHandler<BaseMeshTopology::Point, SetIndexArray >(_data), fc(_fc) {}

void applyDestroyFunction(Index /*index*/, value_type& /*T*/);

protected:
FixedPlaneConstraint<DataTypes> *fc;
};

/// Define RemovalFunction
template< class DataTypes>
void FixedPlaneConstraint<DataTypes>::FCPointHandler::applyDestroyFunction(Index pointIndex, value_type &)
{
if (fc)
{
fc->removeConstraint((Index) pointIndex);
}
}


/////////////////////////// DEFINITION OF FixedPlaneConstraint /////////////////////////////////////
template <class DataTypes>
Expand All @@ -76,16 +46,14 @@ FixedPlaneConstraint<DataTypes>::FixedPlaneConstraint()
, d_dmax( initData(&d_dmax,(Real)0,"dmax","Maximum plane distance from the origin") )
, d_indices( initData(&d_indices,"indices","Indices of the fixed points"))
, l_topology(initLink("topology", "link to the topology container"))
, m_pointHandler(nullptr)
{
m_selectVerticesFromPlanes=false;
}

template <class DataTypes>
FixedPlaneConstraint<DataTypes>::~FixedPlaneConstraint()
{
if (m_pointHandler)
delete m_pointHandler;

}

/// Matrix Integration interface
Expand Down Expand Up @@ -238,9 +206,8 @@ void FixedPlaneConstraint<DataTypes>::init()
{
msg_info() << "Topology path used: '" << l_topology.getLinkedPath() << "'";

/// Initialize functions and parameters
m_pointHandler = new FCPointHandler(this, &d_indices);
d_indices.createTopologyHandler(_topology, m_pointHandler);
// Initialize topological changes support
d_indices.createTopologyHandler(_topology);
}
else
{
Expand Down
Loading

0 comments on commit afa90a3

Please sign in to comment.