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

Use constexpr VecIds #163

Merged
merged 2 commits into from
Jan 6, 2025
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
5 changes: 2 additions & 3 deletions src/BeamAdapter/component/BaseBeamInterpolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ using sofa::type::Quat ;
using sofa::type::Vec ;
using sofa::type::Vec3d ;
using sofa::type::vector;
using sofa::core::ConstVecCoordId;
using sofa::core::behavior::MechanicalState;
using sofa::component::statecontainer::MechanicalObject;

Expand Down Expand Up @@ -170,11 +169,11 @@ class BaseBeamInterpolation : public virtual sofa::core::objectmodel::BaseObject

/// spline base interpolation of points and transformation
void interpolatePointUsingSpline(unsigned int edgeInList, const Real& baryCoord, const Vec3& localPos, const VecCoord& x, Vec3& posResult) {
interpolatePointUsingSpline(edgeInList, baryCoord, localPos, x, posResult, true, ConstVecCoordId::position());
interpolatePointUsingSpline(edgeInList, baryCoord, localPos, x, posResult, true, sofa::core::vec_id::read_access::position);
}

void interpolatePointUsingSpline(unsigned int edgeInList, const Real& baryCoord, const Vec3& localPos,
const VecCoord& x, Vec3& posResult, bool recompute, const ConstVecCoordId& vecXId);
const VecCoord& x, Vec3& posResult, bool recompute, const sofa::core::ConstVecCoordId& vecXId);


void InterpolateTransformUsingSpline(unsigned int edgeInList, const Real& baryCoord, const Vec3& localPos,
Expand Down
2 changes: 1 addition & 1 deletion src/BeamAdapter/component/BaseBeamInterpolation.inl
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ void BaseBeamInterpolation<DataTypes>::interpolatePointUsingSpline(unsigned int
const VecCoord& x,
Vec3& posResult,
bool recompute,
const ConstVecCoordId& vecXId)
const sofa::core::ConstVecCoordId& vecXId)
{
if (recompute)
{
Expand Down
3 changes: 1 addition & 2 deletions src/BeamAdapter/component/BeamInterpolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ namespace _beaminterpolation_
using sofa::component::fem::BaseBeamInterpolation;
using sofa::helper::OptionsGroup;
using sofa::core::topology::BaseMeshTopology;
using sofa::core::ConstVecCoordId;
using sofa::core::behavior::MechanicalState;
using sofa::component::statecontainer::MechanicalObject;

Expand Down Expand Up @@ -148,7 +147,7 @@ class BeamInterpolation : public BaseBeamInterpolation<DataTypes>
Real &_Asy, Real &_Asz, Real &J) override;
void getMechanicalParameters(sofa::Index beamId, Real& youngModulus, Real& cPoisson, Real& massDensity) override;

void getTangentUsingSplinePoints(unsigned int edgeInList, const Real& baryCoord, const ConstVecCoordId &vecXId, Vec3& t );
void getTangentUsingSplinePoints(unsigned int edgeInList, const Real& baryCoord, const sofa::core::ConstVecCoordId &vecXId, Vec3& t );


/// computeActualLength => given the 4 control points of the spline, it provides an estimate of the length (using gauss points integration)
Expand Down
17 changes: 8 additions & 9 deletions src/BeamAdapter/component/BeamInterpolation.inl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ namespace sofa::component::fem::_beaminterpolation_
using sofa::core::topology::BaseMeshTopology ;
using sofa::core::objectmodel::ComponentState ;
using sofa::core::behavior::MechanicalState;
using sofa::core::ConstVecCoordId ;
using sofa::core::objectmodel::BaseContext ;
using sofa::helper::ReadAccessor ;

Expand Down Expand Up @@ -188,7 +187,7 @@ void BeamInterpolation<DataTypes>::bwdInit()
DOF1TransformNode1.resize(edgeList.size());
}

ReadAccessor<Data<VecCoord> > statePos = this->m_mstate->read(ConstVecCoordId::position()) ;
ReadAccessor<Data<VecCoord> > statePos = this->m_mstate->read(sofa::core::vec_id::read_access::position) ;

auto lengthList = sofa::helper::getWriteOnlyAccessor(this->d_lengthList);
lengthList.clear();
Expand Down Expand Up @@ -478,8 +477,8 @@ void BeamInterpolation<DataTypes>::getSplineRestTransform(unsigned int edgeInLis
unsigned int node0Id, node1Id;
this->getNodeIndices(edgeInList,node0Id,node1Id);

Coord global_0 = state->read(core::VecCoordId::restPosition())->getValue()[node0Id];
Coord global_1 = state->read(core::VecCoordId::restPosition())->getValue()[node1Id];
Coord global_0 = state->read(sofa::core::vec_id::read_access::restPosition)->getValue()[node0Id];
Coord global_1 = state->read(sofa::core::vec_id::read_access::restPosition)->getValue()[node1Id];

Transform global_H_DOF0 = Transform(global_0.getCenter(),global_0.getOrientation());
Transform global_H_DOF1 = Transform(global_1.getCenter(),global_1.getOrientation());
Expand Down Expand Up @@ -508,7 +507,7 @@ void BeamInterpolation<DataTypes>::getSplineRestTransform(unsigned int edgeInLis

template<class DataTypes>
void BeamInterpolation<DataTypes>::getTangentUsingSplinePoints(unsigned int edgeInList, const Real& baryCoord,
const ConstVecCoordId &vecXId, Vec3& t )
const sofa::core::ConstVecCoordId &vecXId, Vec3& t )
{

const VectorVec3& splinePos = this->m_StateNodes->read(vecXId)->getValue();
Expand Down Expand Up @@ -563,16 +562,16 @@ void BeamInterpolation<DataTypes>::updateInterpolation(){
if(d_vecID.getValue().getSelectedItem() == "current")
{
dmsg_info() <<" position " << msgendl
<< " ="<< this->m_mstate->read( core::ConstVecCoordId::position() )->getValue( ) ;
x=this->m_mstate->read( core::ConstVecCoordId::position() );
<< " ="<< this->m_mstate->read( sofa::core::vec_id::read_access::position )->getValue( ) ;
x=this->m_mstate->read( sofa::core::vec_id::read_access::position );
}
else if(d_vecID.getValue().getSelectedItem() == "free")
{
x=this->m_mstate->read( core::ConstVecCoordId::freePosition() ) ;
x=this->m_mstate->read( sofa::core::vec_id::read_access::freePosition ) ;
}
else /// rest position
{
x=this->m_mstate->read( core::ConstVecCoordId::restPosition() ) ;
x=this->m_mstate->read( sofa::core::vec_id::read_access::restPosition ) ;
computeVel = false;
}

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

using helper::ReadAccessor;
using sofa::core::ConstVecCoordId;
using std::stringstream;
using sofa::core::ConstraintParams;
using sofa::linearalgebra::BaseVector;
Expand Down Expand Up @@ -295,8 +294,8 @@ void AdaptiveBeamLengthConstraint<DataTypes>::buildConstraintMatrix(const Constr
m_nbConstraints = 0;
m_cid = constraintId;

ReadAccessor<Data<VecCoord> > x = this->mstate->read(ConstVecCoordId::position()) ;
ReadAccessor<Data<VecCoord> > xfree = this->mstate->read(ConstVecCoordId::freePosition()) ;
ReadAccessor<Data<VecCoord> > x = this->mstate->read(sofa::core::vec_id::read_access::position) ;
ReadAccessor<Data<VecCoord> > xfree = this->mstate->read(sofa::core::vec_id::read_access::freePosition) ;

auto c = sofa::helper::getWriteOnlyAccessor(c_d);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/******************************************************************************
/******************************************************************************
* BeamAdapter plugin *
* (c) 2006 Inria, University of Lille, CNRS *
* *
Expand Down Expand Up @@ -32,7 +32,6 @@ namespace sofa::component::constraintset::_adaptiveBeamSlidingConstraint_
{

using sofa::core::behavior::ConstraintResolution ;
using sofa::core::ConstVecCoordId;
using sofa::core::ConstraintParams;
using sofa::helper::ReadAccessor;

Expand Down Expand Up @@ -102,8 +101,8 @@ void AdaptiveBeamSlidingConstraint<DataTypes>::internalInit()
// We search for the closest segment, on which to project each point
// Convention : object1 is the beam model, object2 is the list of point constraints

ReadAccessor<Data<VecCoord> > x1 = mstate1->read(ConstVecCoordId::position()) ;
ReadAccessor<Data<VecCoord> > x2 = mstate2->read(ConstVecCoordId::position()) ;
ReadAccessor<Data<VecCoord> > x1 = mstate1->read(sofa::core::vec_id::read_access::position) ;
ReadAccessor<Data<VecCoord> > x2 = mstate2->read(sofa::core::vec_id::read_access::position) ;

unsigned int m2Size = x2.size();
m_previousPositions.clear();
Expand Down Expand Up @@ -154,8 +153,8 @@ void AdaptiveBeamSlidingConstraint<DataTypes>::buildConstraintMatrix(const Const
Real baryCoord;
unsigned int beam = 0;

ReadAccessor<Data<VecCoord> > x1free=mstate1->read(ConstVecCoordId::freePosition()) ;
ReadAccessor<Data<VecCoord> > x2free=mstate2->read(ConstVecCoordId::freePosition()) ;
ReadAccessor<Data<VecCoord> > x1free=mstate1->read(sofa::core::vec_id::read_access::freePosition) ;
ReadAccessor<Data<VecCoord> > x2free=mstate2->read(sofa::core::vec_id::read_access::freePosition) ;

unsigned int m2 = x2free.size();
WireBeamInterpolation<DataTypes>* interpolation = m_interpolation.get();
Expand Down Expand Up @@ -274,7 +273,7 @@ void AdaptiveBeamSlidingConstraint<DataTypes>::draw(const VisualParams* vparams)

vparams->drawTool()->saveLastState();

ReadAccessor<Data<VecCoord> > x = mstate2->read(ConstVecCoordId::position());
ReadAccessor<Data<VecCoord> > x = mstate2->read(sofa::core::vec_id::read_access::position);
sofa::type::Vec3 point;
std::vector< sofa::type::Vec3 > points;
std::vector< sofa::type::RGBAColor> colors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ namespace sofa::component::controller::_adaptivebeamcontroller_

using sofa::core::objectmodel::BaseContext ;
using std::string;
using sofa::core::VecCoordId;
using sofa::core::VecDerivId;

//TODO(dmarchal 2017-05-17) to christian & euallie.
// This component seems specific to radiology instrument... but its name suggest a very generic behavior
Expand Down Expand Up @@ -229,8 +227,8 @@ void AdaptiveBeamController<DataTypes>::onBeginAnimationStep(const double /*dt*/
template <class DataTypes>
void AdaptiveBeamController<DataTypes>::applyController()
{
Data<VecCoord>* datax = this->getMechanicalState()->write(VecCoordId::position());
Data<VecDeriv>* datav = this->getMechanicalState()->write(VecDerivId::velocity());
Data<VecCoord>* datax = this->getMechanicalState()->write(sofa::core::vec_id::write_access::position);
Data<VecDeriv>* datav = this->getMechanicalState()->write(sofa::core::vec_id::write_access::velocity);
auto x = sofa::helper::getWriteOnlyAccessor(*datax);
auto v = sofa::helper::getWriteOnlyAccessor(*datav);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void InterventionalRadiologyController<DataTypes>::bwdInit()
return;
}

WriteAccessor<Data<VecCoord> > x = *this->mState->write(core::VecCoordId::position());
WriteAccessor<Data<VecCoord> > x = *this->mState->write(sofa::core::vec_id::write_access::position);
for(unsigned int i=0; i<x.size(); i++)
x[i] = d_startingPos.getValue();
m_numControlledNodes = x.size();
Expand Down Expand Up @@ -773,7 +773,7 @@ void InterventionalRadiologyController<DataTypes>::applyInterventionalRadiologyC
totalLengthIsChanging(newCurvAbs, modifiedCurvAbs, idInstrumentTable);

// => Get write access to current nodes/dofs
Data<VecCoord>* datax = this->getMechanicalState()->write(core::VecCoordId::position());
Data<VecCoord>* datax = this->getMechanicalState()->write(sofa::core::vec_id::write_access::position);
auto x = sofa::helper::getWriteOnlyAccessor(*datax);
VecCoord xbuf = x.ref();

Expand Down Expand Up @@ -1036,8 +1036,8 @@ void InterventionalRadiologyController<DataTypes>::fillInstrumentCurvAbsTable(co
template <class DataTypes>
void InterventionalRadiologyController<DataTypes>::fixFirstNodesWithUntil(unsigned int firstSimulatedNode)
{
WriteAccessor<Data<VecCoord> > xMstate = *getMechanicalState()->write(core::VecCoordId::position());
WriteAccessor<Data<VecDeriv> > vMstate = *getMechanicalState()->write(core::VecDerivId::velocity());
WriteAccessor<Data<VecCoord> > xMstate = *getMechanicalState()->write(sofa::core::vec_id::write_access::position);
WriteAccessor<Data<VecDeriv> > vMstate = *getMechanicalState()->write(sofa::core::vec_id::write_access::velocity);

// set the position to startingPos for all the nodes that are not simulated
// and add a fixedConstraint
Expand Down
14 changes: 7 additions & 7 deletions src/BeamAdapter/component/controller/SutureController.inl
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ void SutureController<DataTypes>::initWireModel()

Real x_curv = 0.0;

Data<VecCoord>* datax = getMechanicalState()->write(sofa::core::VecCoordId::position());
Data<VecDeriv>* datav = getMechanicalState()->write(sofa::core::VecDerivId::velocity());
Data<VecCoord>* datax = getMechanicalState()->write(sofa::core::vec_id::write_access::position);
Data<VecDeriv>* datav = getMechanicalState()->write(sofa::core::vec_id::write_access::velocity);
auto x = sofa::helper::getWriteOnlyAccessor(*datax);
auto v = sofa::helper::getWriteOnlyAccessor(*datav);

Expand Down Expand Up @@ -323,8 +323,8 @@ void SutureController<DataTypes>::onBeginAnimationStep(const double dt)
applyController();

// Propagate modifications
MechanicalProjectPositionAndVelocityVisitor(core::MechanicalParams::defaultInstance(), getContext()->getTime(), sofa::core::VecCoordId::position(),sofa::core::VecDerivId::velocity()); // apply projective constraints
MechanicalPropagateOnlyPositionAndVelocityVisitor(core::MechanicalParams::defaultInstance(), getContext()->getTime(),sofa::core::VecCoordId::position(),sofa::core::VecDerivId::velocity()).execute( getContext() );
MechanicalProjectPositionAndVelocityVisitor(core::MechanicalParams::defaultInstance(), getContext()->getTime(), sofa::core::vec_id::write_access::position,sofa::core::vec_id::write_access::velocity); // apply projective constraints
MechanicalPropagateOnlyPositionAndVelocityVisitor(core::MechanicalParams::defaultInstance(), getContext()->getTime(),sofa::core::vec_id::write_access::position,sofa::core::vec_id::write_access::velocity).execute( getContext() );
simulation::UpdateMappingVisitor(core::ExecParams::defaultInstance()).execute(getContext());
}

Expand Down Expand Up @@ -503,8 +503,8 @@ void SutureController<DataTypes>::addImposedCurvAbs(type::vector<Real> &newCurvA
template <class DataTypes>
void SutureController<DataTypes>::applyController()
{
Data<VecCoord>* datax = getMechanicalState()->write(sofa::core::VecCoordId::position());
Data<VecDeriv>* datav = getMechanicalState()->write(sofa::core::VecDerivId::velocity());
Data<VecCoord>* datax = getMechanicalState()->write(sofa::core::vec_id::write_access::position);
Data<VecDeriv>* datav = getMechanicalState()->write(sofa::core::vec_id::write_access::velocity);
auto x = sofa::helper::getWriteOnlyAccessor(*datax);
auto v = sofa::helper::getWriteOnlyAccessor(*datav);
type::vector<Real> newCurvAbs;
Expand Down Expand Up @@ -1171,7 +1171,7 @@ void SutureController<DataTypes>::updateControlPointsPositions()

unsigned int numBeams = l_adaptiveInterpolation->getNumBeams();
Transform global_H0_local, global_H1_local;
const VecCoord& x = getMechanicalState()->write(sofa::core::VecCoordId::position())->getValue();
const VecCoord& x = getMechanicalState()->read(sofa::core::vec_id::read_access::position)->getValue();
for (unsigned int b = 0; b < numBeams; b++)
{
l_adaptiveInterpolation->computeTransform(b, global_H0_local, global_H1_local, x);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ using sofa::core::objectmodel::BaseContext ;
using sofa::type::Vec3 ;
using sofa::type::Quat ;
using sofa::helper::ReadAccessor ;
using sofa::core::ConstVecCoordId ;
using std::set ;
using sofa::helper::ScopedAdvancedTimer;

Expand Down Expand Up @@ -746,7 +745,7 @@ void AdaptiveBeamForceFieldAndMass<DataTypes>::draw(const VisualParams *vparams)

vparams->drawTool()->saveLastState();

ReadAccessor<Data<VecCoord> > x = mstate->read(ConstVecCoordId::position()) ;
ReadAccessor<Data<VecCoord> > x = mstate->read(sofa::core::vec_id::read_access::position) ;

unsigned int numBeams = l_interpolation->getNumBeams();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ using sofa::core::objectmodel::BaseContext ;
using sofa::type::Vec3 ;
using sofa::type::Quat ;
using sofa::helper::ReadAccessor ;
using sofa::core::ConstVecCoordId ;
using std::set ;

template <class DataTypes>
Expand Down Expand Up @@ -730,7 +729,7 @@ void AdaptiveInflatableBeamForceField<DataTypes>::draw(const VisualParams *vpara
if (!vparams->displayFlags().getShowForceFields() && !vparams->displayFlags().getShowBehaviorModels()) return;
if (!mstate) return;

ReadAccessor<Data<VecCoord> > x = mstate->read(ConstVecCoordId::position()) ;
ReadAccessor<Data<VecCoord> > x = mstate->read(sofa::core::vec_id::read_access::position) ;

unsigned int numBeams = l_interpolation->getNumBeams();

Expand Down
19 changes: 9 additions & 10 deletions src/BeamAdapter/component/mapping/AdaptiveBeamMapping.inl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ namespace _adaptivebeammapping_
using sofa::core::State;
using helper::ReadAccessor;
using helper::WriteAccessor;
using sofa::core::ConstVecCoordId;
using sofa::helper::AdvancedTimer;
using sofa::helper::ScopedAdvancedTimer;
using sofa::core::MultiVecCoordId;
Expand Down Expand Up @@ -233,20 +232,20 @@ void AdaptiveBeamMapping< TIn, TOut>::apply(const MechanicalParams* mparams, Dat
}
}

MultiVecCoordId x = VecCoordId::position();
MultiVecCoordId xfree = VecCoordId::freePosition();
MultiVecCoordId x = sofa::core::vec_id::write_access::position;
MultiVecCoordId xfree = sofa::core::vec_id::write_access::freePosition;

const ConstMultiVecCoordId &xId = mparams->x();
ConstVecCoordId xtest = xId.getId(this->fromModel);
sofa::core::ConstVecCoordId xtest = xId.getId(this->fromModel);

if(xtest == xfree.getId(this->fromModel))
{
VecCoordId xfreeIn = VecCoordId::freePosition();
VecCoordId xfreeIn = sofa::core::vec_id::write_access::freePosition;
l_adaptativebeamInterpolation->updateBezierPoints(in, xfreeIn);
}
else if(xtest == x.getId(this->fromModel))
{
VecCoordId positionIn = VecCoordId::position();
VecCoordId positionIn = sofa::core::vec_id::write_access::position;
l_adaptativebeamInterpolation->updateBezierPoints(in, positionIn);
}

Expand Down Expand Up @@ -307,7 +306,7 @@ void AdaptiveBeamMapping< TIn, TOut>::applyJ(const core::MechanicalParams* mpara
auto out = sofa::helper::getWriteOnlyAccessor(dOut);
const InVecDeriv& in= dIn.getValue();

Data<InVecCoord>& dataInX = *this->getFromModel()->write(VecCoordId::position());
Data<InVecCoord>& dataInX = *this->getFromModel()->write(sofa::core::vec_id::write_access::position);
auto x = sofa::helper::getWriteOnlyAccessor(dataInX);

if (d_useCurvAbs.getValue() && !d_contactDuplicate.getValue())
Expand Down Expand Up @@ -392,7 +391,7 @@ void AdaptiveBeamMapping< TIn, TOut>::applyJT(const core::MechanicalParams* mpar
auto out = sofa::helper::getWriteOnlyAccessor(dOut);
const VecDeriv& in= dIn.getValue();

const Data<InVecCoord>& dataInX = *this->getFromModel()->read(ConstVecCoordId::position());
const Data<InVecCoord>& dataInX = *this->getFromModel()->read(sofa::core::vec_id::read_access::position);
const InVecCoord& x = dataInX.getValue();

for (unsigned int i=0; i<m_pointBeamDistribution.size(); i++)
Expand Down Expand Up @@ -434,7 +433,7 @@ void AdaptiveBeamMapping< TIn, TOut>::applyJT(const core::ConstraintParams* cpar
SCOPED_TIMER("AdaptiveBeamMapping_ApplyJT");
auto out = sofa::helper::getWriteOnlyAccessor(dOut);
const OutMatrixDeriv& in = dIn.getValue();
const Data<InVecCoord>& dataInX = *this->getFromModel()->read(ConstVecCoordId::position());
const Data<InVecCoord>& dataInX = *this->getFromModel()->read(sofa::core::vec_id::read_access::position);
const InVecCoord& x = dataInX.getValue();

m_isXBufferUsed = false;
Expand Down Expand Up @@ -512,7 +511,7 @@ void AdaptiveBeamMapping< TIn, TOut>::bwdInit()

if (ptsSize == 0)
{
helper::ReadAccessor<Data<VecCoord> > xTo = this->toModel->read(sofa::core::ConstVecCoordId::position()) ;
helper::ReadAccessor<Data<VecCoord> > xTo = this->toModel->read(sofa::core::vec_id::read_access::position) ;

if(xTo.size()==0)
{
Expand Down
Loading
Loading