Skip to content

Commit

Permalink
[all] Remove some warnings (sofa-framework#4698)
Browse files Browse the repository at this point in the history
* fix trivial warnings

* fix dangling ref to temporary

* fix obscure dangling ref to temporary warnings

* Apply suggestions from code review (indentations)

Co-authored-by: Hugo <[email protected]>

---------

Co-authored-by: Hugo <[email protected]>
  • Loading branch information
fredroy and hugtalbot authored May 3, 2024
1 parent 9544978 commit d64a5b5
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ template <class TIn, class TOut>
void DistanceFromTargetMapping<TIn, TOut>::applyJT(const core::ConstraintParams* cparams, Data<InMatrixDeriv>& out, const Data<OutMatrixDeriv>& in)
{
SOFA_UNUSED(cparams);
const OutMatrixDeriv& childMat = sofa::helper::getReadAccessor(in).ref();
InMatrixDeriv& parentMat = sofa::helper::getWriteAccessor(out).wref();
addMultTransposeEigen(parentMat, jacobian.compressedMatrix, childMat);
auto childMatRa = sofa::helper::getReadAccessor(in);
auto parentMatWa = sofa::helper::getWriteAccessor(out);
addMultTransposeEigen(parentMatWa.wref(), jacobian.compressedMatrix, childMatRa.ref());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ template <class TIn, class TOut>
void DistanceMapping<TIn, TOut>::applyJT(const core::ConstraintParams* cparams, Data<InMatrixDeriv>& out, const Data<OutMatrixDeriv>& in)
{
SOFA_UNUSED(cparams);
const OutMatrixDeriv& childMat = sofa::helper::getReadAccessor(in).ref();
InMatrixDeriv& parentMat = sofa::helper::getWriteAccessor(out).wref();
addMultTransposeEigen(parentMat, jacobian.compressedMatrix, childMat);
auto childMatRa = sofa::helper::getReadAccessor(in);
auto parentMatWa = sofa::helper::getWriteAccessor(out);
addMultTransposeEigen(parentMatWa.wref(), jacobian.compressedMatrix, childMatRa.ref());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,11 @@ void DistanceMultiMapping<TIn, TOut>::init()
const type::Vec2i& pair0 = pairs[ links[i][0] ];
const type::Vec2i& pair1 = pairs[ links[i][1] ];

const InCoord& pos0 = this->getFromModels()[pair0[0]]->readPositions()[pair0[1]];
const InCoord& pos1 = this->getFromModels()[pair1[0]]->readPositions()[pair1[1]];
auto posPair0 = this->getFromModels()[pair0[0]]->readPositions();
auto posPair1 = this->getFromModels()[pair1[0]]->readPositions();

const InCoord& pos0 = posPair0[pair0[1]];
const InCoord& pos1 = posPair1[pair1[1]];

restLengths[i] = (pos0 - pos1).norm();

Expand Down Expand Up @@ -268,7 +271,8 @@ void DistanceMultiMapping<TIn, TOut>::applyDJT(const core::MechanicalParams* mpa
if( !geometricStiffness ) return;

const SReal kfactor = mparams->kFactor();
const OutVecDeriv& childForce = this->getToModels()[0]->readForces().ref();
auto childForceRa = this->getToModels()[0]->readForces();
const OutVecDeriv& childForce = childForceRa.ref();
const SeqEdges& links = l_topology->getEdges();
const type::vector<type::Vec2i>& pairs = d_indexPairs.getValue();

Expand Down Expand Up @@ -481,8 +485,11 @@ void DistanceMultiMapping<TIn, TOut>::draw(const core::visual::VisualParams* vpa
const type::Vec2i& pair0 = pairs[ links[i][0] ];
const type::Vec2i& pair1 = pairs[ links[i][1] ];

const InCoord& pos0 = this->getFromModels()[pair0[0]]->readPositions()[pair0[1]];
const InCoord& pos1 = this->getFromModels()[pair1[0]]->readPositions()[pair1[1]];
auto posPair0 = this->getFromModels()[pair0[0]]->readPositions();
auto posPair1 = this->getFromModels()[pair1[0]]->readPositions();

const InCoord& pos0 = posPair0[pair0[1]];
const InCoord& pos1 = posPair1[pair1[1]];

points.push_back( type::Vec3( TIn::getCPos(pos0) ) );
points.push_back( type::Vec3( TIn::getCPos(pos1) ) );
Expand All @@ -496,8 +503,11 @@ void DistanceMultiMapping<TIn, TOut>::draw(const core::visual::VisualParams* vpa
const type::Vec2i& pair0 = pairs[ links[i][0] ];
const type::Vec2i& pair1 = pairs[ links[i][1] ];

const InCoord& pos0 = this->getFromModels()[pair0[0]]->readPositions()[pair0[1]];
const InCoord& pos1 = this->getFromModels()[pair1[0]]->readPositions()[pair1[1]];
auto posPair0 = this->getFromModels()[pair0[0]]->readPositions();
auto posPair1 = this->getFromModels()[pair1[0]]->readPositions();

const InCoord& pos0 = posPair0[pair0[1]];
const InCoord& pos1 = posPair1[pair1[1]];

type::Vec3 p0 = TIn::getCPos(pos0);
type::Vec3 p1 = TIn::getCPos(pos1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ template <class TIn, class TOut>
void SquareDistanceMapping<TIn, TOut>::applyJT(const core::ConstraintParams* cparams, Data<InMatrixDeriv>& out, const Data<OutMatrixDeriv>& in)
{
SOFA_UNUSED(cparams);
const OutMatrixDeriv& childMat = sofa::helper::getReadAccessor(in).ref();
InMatrixDeriv& parentMat = sofa::helper::getWriteAccessor(out).wref();
addMultTransposeEigen(parentMat, jacobian.compressedMatrix, childMat);
auto childMatRa = sofa::helper::getReadAccessor(in);
auto parentMatWa = sofa::helper::getWriteAccessor(out);
addMultTransposeEigen(parentMatWa.wref(), jacobian.compressedMatrix, childMatRa.ref());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ template <class TIn, class TOut>
void SquareMapping<TIn, TOut>::applyJT(const core::ConstraintParams* cparams, Data<InMatrixDeriv>& out, const Data<OutMatrixDeriv>& in)
{
SOFA_UNUSED(cparams);
const OutMatrixDeriv& childMat = sofa::helper::getReadAccessor(in).ref();
InMatrixDeriv& parentMat = sofa::helper::getWriteAccessor(out).wref();
addMultTransposeEigen(parentMat, jacobian.compressedMatrix, childMat);
auto childMatRa = sofa::helper::getReadAccessor(in);
auto parentMatWa = sofa::helper::getWriteAccessor(out);
addMultTransposeEigen(parentMatWa.wref(), jacobian.compressedMatrix, childMatRa.ref());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -944,11 +944,12 @@ bool TriangleSetGeometryAlgorithms< DataTypes >::isQuadDeulaunayOriented(const t
const typename DataTypes::Coord& p3,
const typename DataTypes::Coord& p4)
{
// use formula with angles
// A----B p1----p2
// \ \ \ \
// D----C p4----p3
// if the sum of opposites angles (not on the common edge) is < 180deg, the triangles meet the Delaunay condition
/* use formula with angles
* A----B p1----p2
* \ \ \ \
* D----C p4----p3
* if the sum of opposites angles (not on the common edge) is < 180deg, the triangles meet the Delaunay condition
*/
sofa::type::Vec<3, Real> AB = { p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2] };
sofa::type::Vec<3, Real> AD = { p4[0] - p1[0], p4[1] - p1[1], p4[2] - p1[2] };

Expand Down
16 changes: 8 additions & 8 deletions Sofa/GUI/Common/src/sofa/gui/common/PickHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@ BodyPicked PickHandler::findCollisionUsingPipeline()
return result;
}

const type::Vec3& origin = mouseCollision->getRay(0).origin();
const type::Vec3& direction = mouseCollision->getRay(0).direction();
const double& maxLength = mouseCollision->getRay(0).l();
const type::Vec3 origin = mouseCollision->getRay(0).origin();
const type::Vec3 direction = mouseCollision->getRay(0).direction();
const double maxLength = mouseCollision->getRay(0).l();

const auto &contacts = mouseCollision->getContacts();
for (auto it=contacts.cbegin(); it != contacts.cend(); ++it)
Expand Down Expand Up @@ -438,17 +438,17 @@ BodyPicked PickHandler::findCollisionUsingPipeline()

BodyPicked PickHandler::findCollisionUsingBruteForce()
{
const type::Vec3& origin = mouseCollision->getRay(0).origin();
const type::Vec3& direction = mouseCollision->getRay(0).direction();
const double& maxLength = mouseCollision->getRay(0).l();
const type::Vec3 origin = mouseCollision->getRay(0).origin();
const type::Vec3 direction = mouseCollision->getRay(0).direction();
const double maxLength = mouseCollision->getRay(0).l();

return findCollisionUsingBruteForce(origin, direction, maxLength, mouseNode->getRoot());
}

BodyPicked PickHandler::findCollisionUsingColourCoding()
{
const type::Vec3& origin = mouseCollision->getRay(0).origin();
const type::Vec3& direction = mouseCollision->getRay(0).direction();
const type::Vec3 origin = mouseCollision->getRay(0).origin();
const type::Vec3 direction = mouseCollision->getRay(0).direction();

return findCollisionUsingColourCoding(origin, direction);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ void SparseMatrixProduct<Lhs, Rhs, ResultType>::computeProductFromIntersection()
auto* rhs_ptr = m_rhs->valuePtr();
auto* product_ptr = m_productResult.valuePtr();

const auto lhsNonZeros = m_lhs->nonZeros();
const auto rhsNonZeros = m_rhs->nonZeros();
[[maybe_unused]] const auto lhsNonZeros = m_lhs->nonZeros();
[[maybe_unused]] const auto rhsNonZeros = m_rhs->nonZeros();

for (const auto& pairs : m_intersectionAB.intersection)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@
namespace sofa::simulation
{

void UpdateMappingVisitor::processMapping(simulation::Node* /*n*/, core::BaseMapping* obj)
void UpdateMappingVisitor::processMapping(simulation::Node* n, core::BaseMapping* obj)
{
SOFA_UNUSED(n);
obj->apply(core::mechanicalparams::defaultInstance(), core::VecCoordId::position(), core::ConstVecCoordId::position());
obj->applyJ(core::mechanicalparams::defaultInstance(), core::VecDerivId::velocity(), core::ConstVecDerivId::velocity());
}

void UpdateMappingVisitor::processMechanicalMapping(simulation::Node* /*n*/, core::BaseMapping* obj)
{}
void UpdateMappingVisitor::processMechanicalMapping(simulation::Node* n, core::BaseMapping* obj)
{
SOFA_UNUSED(n);
SOFA_UNUSED(obj);
}

Visitor::Result UpdateMappingVisitor::processNodeTopDown(simulation::Node* node)
{
Expand Down

0 comments on commit d64a5b5

Please sign in to comment.