Skip to content

Commit

Permalink
[constraint] applies requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
EulalieCoevoet committed Oct 17, 2024
1 parent 36d2095 commit 8f800fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ class SOFA_SOFTROBOTS_INVERSE_API BarycentricCenterEffector : public PositionEff
/// traversal of graph creation and modification,
void init() override;

/// According to BaseObject::reset
/// this method should be used to reset the object in its initial state.
void reset() override;

/// According to BaseObject::draw
/// this method should be used to render internal data of this object,
/// for debugging purposes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,21 @@ void BarycentricCenterEffector<DataTypes>::init()
}
}

template<class DataTypes>
void BarycentricCenterEffector<DataTypes>::reset()
{
}

template<class DataTypes>
void BarycentricCenterEffector<DataTypes>::computeBarycenter()
{
ReadAccessor<sofa::Data<VecCoord> > positions = m_state->readPositions();
const unsigned int nbp = m_state->getSize();
Coord barycenter = Coord();
for (unsigned int i=0; i<nbp; i++)
for(sofa::Size j=0; j<DataTypes::Coord::total_size; j++)
barycenter[j] += positions[i][j]/Real(nbp);

d_barycenter.setValue(barycenter);
const ReadAccessor<sofa::Data<VecCoord> > positions = m_state->readPositions();
if (const sofa::Size nbp = m_state->getSize())
{
const Coord barycenter = std::accumulate(positions->begin(), positions->end(), Coord{}, std::plus<Coord>()) / nbp;
d_barycenter.setValue(barycenter);
}
else
{
d_barycenter.setValue(Coord{});
msg_error() << "Trying to compute a barycenter from an empty list of positions.";
}
}

template<class DataTypes>
Expand Down Expand Up @@ -201,9 +200,8 @@ void BarycentricCenterEffector<DataTypes>::draw(const VisualParams* vparams)
return;

computeBarycenter();
Coord b = d_barycenter.getValue();
std::vector<Vec3> positions;
positions.push_back(b);
const Coord& b = d_barycenter.getValue();
std::vector<Vec3> positions(1, b);
vparams->drawTool()->drawPoints(positions, float(5.), RGBAColor(0.0f,0.0f,1.0f,1.0f));
}

Expand Down

0 comments on commit 8f800fe

Please sign in to comment.