From 1b0318c24b596552a793fe6dbdc436b7653936e2 Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Tue, 11 Aug 2026 18:47:15 +0200 Subject: [PATCH 1/2] [all] Fix compilation warnings --- .../algorithm/BaseSubCollisionPipeline.cpp | 1 - .../intersection/CCDTightInclusionIntersection.cpp | 4 +++- .../geometry/TriangleOctreeCollisionModel.cpp | 5 ++++- .../lagrangian/solver/BuiltConstraintSolver.cpp | 2 +- .../solver/ImprovedJacobiConstraintSolver.cpp | 8 +++++--- .../lagrangian/solver/NNCGConstraintSolver.cpp | 2 ++ .../solver/PreconditionedConjugateResidual.cpp | 8 +++++--- .../src/sofa/component/engine/select/BoxROI.inl | 8 +++++++- .../sofa/component/engine/select/MeshSampler.inl | 2 +- .../src/sofa/component/io/mesh/MeshVTKLoader.cpp | 2 ++ .../Mesh/src/sofa/component/io/mesh/STLExporter.cpp | 4 +++- .../component/mapping/linear/SkinningMapping.inl | 2 +- .../Mass/src/sofa/component/mass/FEMMass.inl | 3 ++- .../Mass/src/sofa/component/mass/NodalMassDensity.h | 2 ++ .../fem/elastic/BaseElementLinearFEMForceField.inl | 6 ++++-- .../fem/elastic/CorotationalFEMForceField.inl | 13 ++++++++++++- .../solidmechanics/fem/elastic/FEMForceField.h | 12 ++++++++++-- .../fem/elastic/LinearSmallStrainFEMForceField.inl | 6 ++++++ .../fem/elastic/TetrahedronFEMForceField.inl | 6 +++--- .../fem/elastic/impl/rotations/IdentityRotation.h | 2 ++ .../impl/rotations/RotationMethodsContainer.h | 4 ++-- .../fem/hyperelastic/material/Ogden.h | 4 ---- .../Visual/src/sofa/component/visual/VisualMesh.cpp | 2 ++ .../src/sofa/component/visual/VisualModelImpl.cpp | 3 ++- .../src/sofa/component/visual/VisualPointCloud.inl | 2 ++ .../src/sofa/component/visual/VisualVectorField.inl | 3 +++ 26 files changed, 86 insertions(+), 30 deletions(-) diff --git a/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/BaseSubCollisionPipeline.cpp b/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/BaseSubCollisionPipeline.cpp index 6fb78d79921..139b42f413c 100644 --- a/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/BaseSubCollisionPipeline.cpp +++ b/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/BaseSubCollisionPipeline.cpp @@ -19,7 +19,6 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#pragma once #include #include diff --git a/Sofa/Component/Collision/Detection/Intersection/src/sofa/component/collision/detection/intersection/CCDTightInclusionIntersection.cpp b/Sofa/Component/Collision/Detection/Intersection/src/sofa/component/collision/detection/intersection/CCDTightInclusionIntersection.cpp index 5b68cfe3040..5572a072bac 100644 --- a/Sofa/Component/Collision/Detection/Intersection/src/sofa/component/collision/detection/intersection/CCDTightInclusionIntersection.cpp +++ b/Sofa/Component/Collision/Detection/Intersection/src/sofa/component/collision/detection/intersection/CCDTightInclusionIntersection.cpp @@ -184,7 +184,9 @@ int CCDTightInclusionIntersection::computeIntersection(Line& e1, Line& e2, Outpu SReal outputTolerance = 0.0; - const auto result = ticcd::edgeEdgeCCD( + // the returned boolean is not tested here: computeIntersection is only called on pairs for which + // testIntersection already reported a collision. The call is kept for its outputs: toi and outputTolerance. + [[maybe_unused]] const auto result = ticcd::edgeEdgeCCD( Line1ABegin, Line2ABegin, Line1BBegin, Line2BBegin, Line1AEnd, Line2AEnd, Line1BEnd, Line2BEnd, err,maxSeparation, toi,d_tolerance.getValue(), tmax, d_maxIterations.getValue(), outputTolerance); diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleOctreeCollisionModel.cpp b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleOctreeCollisionModel.cpp index a6f9019aff2..c51f76479f5 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleOctreeCollisionModel.cpp +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleOctreeCollisionModel.cpp @@ -128,8 +128,11 @@ void TriangleOctreeCollisionModel::computeBoundingTree(int maxDepth) } } -void TriangleOctreeCollisionModel::computeContinuousBoundingTree(SReal/* dt*/, ContinuousIntersectionTypeFlag continuousIntersectionFlag, int maxDepth) +void TriangleOctreeCollisionModel::computeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag, int maxDepth) { + SOFA_UNUSED(dt); + SOFA_UNUSED(continuousIntersectionFlag); + computeBoundingTree(maxDepth); } diff --git a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/BuiltConstraintSolver.cpp b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/BuiltConstraintSolver.cpp index 98e60c87e3b..56447bdb02f 100644 --- a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/BuiltConstraintSolver.cpp +++ b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/BuiltConstraintSolver.cpp @@ -81,7 +81,7 @@ void BuiltConstraintSolver::addRegularization(linearalgebra::BaseMatrix& W, cons //Now for all vector of the null space basis, we look at the indices where the coefficient //is greater than 1% of the norm of the vector, this is the constraints that //belong to the null space and thus have other one that are antagonists - for(int i=nullSpaceBegin; (i != -1) && (i(problemSize)); ++i) { for(size_t j=0; j d_svdSingularVectorNullSpaceCriteriaFactor.getValue(); diff --git a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/ImprovedJacobiConstraintSolver.cpp b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/ImprovedJacobiConstraintSolver.cpp index 837615c71ae..1d7473b1b32 100644 --- a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/ImprovedJacobiConstraintSolver.cpp +++ b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/ImprovedJacobiConstraintSolver.cpp @@ -43,6 +43,8 @@ ImprovedJacobiConstraintSolver::ImprovedJacobiConstraintSolver() void ImprovedJacobiConstraintSolver::doSolve(GenericConstraintProblem * problem , SReal timeout) { + SOFA_UNUSED(timeout); + SCOPED_TIMER_VARNAME(gaussSeidelTimer, "ImprovedJacobiConstraintSolver"); @@ -63,7 +65,7 @@ void ImprovedJacobiConstraintSolver::doSolve(GenericConstraintProblem * problem std::copy_n(dfree, dimension, d); - for(unsigned i=0; i< dimension; ++i) + for(int i=0; i< dimension; ++i) { force[i] = 0; } @@ -128,7 +130,7 @@ void ImprovedJacobiConstraintSolver::doSolve(GenericConstraintProblem * problem for(unsigned l=j; lgetDimension(); diff --git a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/PreconditionedConjugateResidual.cpp b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/PreconditionedConjugateResidual.cpp index 59c4b6ef822..6efb95d3f33 100644 --- a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/PreconditionedConjugateResidual.cpp +++ b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/PreconditionedConjugateResidual.cpp @@ -40,6 +40,8 @@ PreconditionedConjugateResidual::PreconditionedConjugateResidual() void PreconditionedConjugateResidual::doSolve(GenericConstraintProblem * problem , SReal timeout) { + SOFA_UNUSED(timeout); + SCOPED_TIMER_VARNAME(gaussSeidelTimer, "PreconditionedConjugateResidual"); if (!problem) @@ -73,10 +75,10 @@ void PreconditionedConjugateResidual::doSolve(GenericConstraintProblem * problem // ===== BEGIN Initialization ===== // Initialize the state (matrices/vectors) and apply the Jacobi preconditioner on left and right to keep symmetry // This implies that the solution will be P^{-1}*x and thus should be corrected after solving. - for(unsigned j=0; j< dimension; ++j) + for(int j=0; j< dimension; ++j) { const SReal invWjj = 1.0/sqrt(W[j][j]); - for(unsigned k=0; k< dimension; ++k) + for(int k=0; k< dimension; ++k) { const SReal invWkk = 1.0/sqrt(W[k][k]); @@ -84,7 +86,7 @@ void PreconditionedConjugateResidual::doSolve(GenericConstraintProblem * problem } } - for(unsigned j=0; j< dimension; ++j) + for(int j=0; j< dimension; ++j) { const SReal invWjj = 1.0/sqrt(W[j][j]); r[j] = -dfree[j] * invWjj; diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/BoxROI.inl b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/BoxROI.inl index ea51643d363..85a6f188077 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/BoxROI.inl +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/BoxROI.inl @@ -190,7 +190,13 @@ bool BoxROI::isPointInAlignedBox(const typename DataTypes::CPos& p, c { static_assert(std::is_same_v); - for (typename type::Vec6::size_type i = 0; i < DataTypes::spatial_dimensions; ++i) + /// An axis-aligned box is stored as a Vec6 gathering the min corner (indices [0,2]) and the max + /// corner (indices [3,5]): it cannot describe more than 3 dimensions. Higher dimensions of the + /// tested point are therefore ignored. + static constexpr typename type::Vec6::size_type nbTestedDimensions = + DataTypes::spatial_dimensions < 3 ? DataTypes::spatial_dimensions : 3; + + for (typename type::Vec6::size_type i = 0; i < nbTestedDimensions; ++i) { if (p[i] < box[i] || p[i] > box[i + 3]) { diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshSampler.inl b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshSampler.inl index d8d78dd3a34..88f1fa1294c 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshSampler.inl +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshSampler.inl @@ -115,7 +115,7 @@ void MeshSampler::farthestPointSampling(VD& distances,VI& voronoi,con while(ind.size()dmax) {dmax=distances[i]; imax=(ID)i;} if(dmax==0) break; else ind.push_back(imax); diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshVTKLoader.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshVTKLoader.cpp index ddd4799fe83..8c27757a4da 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshVTKLoader.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshVTKLoader.cpp @@ -1243,6 +1243,8 @@ bool XMLVTKReader::loadUnstructuredGrid(tinyxml2::XMLHandle datasetFormatHandle) BaseVTKReader::BaseVTKDataIO* XMLVTKReader::parsePolysIndices(tinyxml2::XMLElement* element, BaseVTKReader::VTKDataIO* vtkIO_elemtypes, BaseVTKDataIO* offsetElement) { + SOFA_UNUSED(offsetElement); + const char* typeStrTemp; typeStrTemp = element->Attribute("type"); diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/STLExporter.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/STLExporter.cpp index 0ebbf79bab1..dd766d9be47 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/STLExporter.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/STLExporter.cpp @@ -22,6 +22,7 @@ #include +#include #include #include @@ -260,7 +261,8 @@ bool STLExporter::writeSTLBinary(bool autonumbering) { buffer[i]='\0'; } - strncpy(buffer, "Exported from Sofa", 18); + // the 80-byte header is not required to be null-terminated: copy the text without its trailing nul + std::memcpy(buffer, "Exported from Sofa", 18); /* Number of d_facets */ const unsigned int nbt = vecTri.size(); diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SkinningMapping.inl b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SkinningMapping.inl index e0790d829b0..3563cff2e84 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SkinningMapping.inl +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SkinningMapping.inl @@ -40,9 +40,9 @@ SkinningMapping::SkinningMapping () , d_initPos (initData (&d_initPos, "initPos", "initial child coordinates in the world reference frame." ) ) , d_nbRef (initData (&d_nbRef, "nbRef", "Number of primitives influencing each point." ) ) , d_index (initData (&d_index, "indices", "parent indices for each child." ) ) + , d_computeWeightsFromPosition (initData (&d_computeWeightsFromPosition, false, "computeWeightsFromPosition", "By default, the weights are computed w.r.t the rest positions of the input model. Set to true to compute them from the position instead." ) ) , d_weight (initData (&d_weight, "weight", "influence weights of the Dofs." ) ) , d_showFromIndex (initData (&d_showFromIndex, ( unsigned int ) 0, "showFromIndex", "Displayed From Index." ) ) - , d_computeWeightsFromPosition (initData (&d_computeWeightsFromPosition, false, "computeWeightsFromPosition", "By default, the weights are computed w.r.t the rest positions of the input model. Set to true to compute them from the position instead." ) ) , d_showWeights (initData (&d_showWeights, false, "showWeights", "Show influence." ) ) { type::vector defaultNbRef; diff --git a/Sofa/Component/Mass/src/sofa/component/mass/FEMMass.inl b/Sofa/Component/Mass/src/sofa/component/mass/FEMMass.inl index 36ce2d21249..a4167d4e7fb 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/FEMMass.inl +++ b/Sofa/Component/Mass/src/sofa/component/mass/FEMMass.inl @@ -225,7 +225,8 @@ void FEMMass::buildMassMatrix( const auto columnId = m_globalMassMatrix.colsIndex[xj]; const auto& value = m_globalMassMatrix.colsValue[xj]; - for (typename GlobalMassMatrixType::Index d = 0; d < spatial_dimensions; ++d) + const auto nbDoFs = static_cast(spatial_dimensions); + for (typename GlobalMassMatrixType::Index d = 0; d < nbDoFs; ++d) { matrices->add(rowId * spatial_dimensions + d, columnId * spatial_dimensions + d, value); } diff --git a/Sofa/Component/Mass/src/sofa/component/mass/NodalMassDensity.h b/Sofa/Component/Mass/src/sofa/component/mass/NodalMassDensity.h index 925f9c4b4b9..0544d4d1156 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/NodalMassDensity.h +++ b/Sofa/Component/Mass/src/sofa/component/mass/NodalMassDensity.h @@ -37,6 +37,8 @@ class NodalMassDensity : public sofa::core::BaseNodalProperty template static bool canCreate(T* obj, sofa::core::objectmodel::BaseContext* context, sofa::core::objectmodel::BaseObjectDescription* arg) { + SOFA_UNUSED(obj); + if (const auto* state = context->getMechanicalState()) { static const auto scalarType = defaulttype::DataTypeInfo::name(); diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/BaseElementLinearFEMForceField.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/BaseElementLinearFEMForceField.inl index e2191f8485d..d3efcb0f043 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/BaseElementLinearFEMForceField.inl +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/BaseElementLinearFEMForceField.inl @@ -69,8 +69,10 @@ void BaseElementLinearFEMForceField::precomputeElementSt if (!this->mstate) return; - const auto youngModulusAccessor = sofa::helper::ReadAccessor(this->d_youngModulus); - const auto poissonRatioAccessor = sofa::helper::ReadAccessor(this->d_poissonRatio); + // accessors are only there to make sure both Data are up-to-date before they are read + // concurrently through getYoungModulusInElement/getPoissonRatioInElement + [[maybe_unused]] const auto youngModulusAccessor = sofa::helper::ReadAccessor(this->d_youngModulus); + [[maybe_unused]] const auto poissonRatioAccessor = sofa::helper::ReadAccessor(this->d_poissonRatio); auto restPositionAccessor = this->mstate->readRestPositions(); diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/CorotationalFEMForceField.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/CorotationalFEMForceField.inl index 2e9dbe20c50..adc620ae915 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/CorotationalFEMForceField.inl +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/CorotationalFEMForceField.inl @@ -60,7 +60,8 @@ void CorotationalFEMForceField::init() if (!this->isComponentStateInvalid()) { - const auto& elements = trait::FiniteElement::getElementSequence(*this->l_topology); + // makes sure the element sequence is available in the topology container + [[maybe_unused]] const auto& elements = trait::FiniteElement::getElementSequence(*this->l_topology); } if (!this->isComponentStateInvalid()) @@ -74,6 +75,10 @@ void CorotationalFEMForceField::beforeElementForce( const sofa::core::MechanicalParams* mparams, sofa::type::vector& f, const sofa::VecCoord_t& x) { + SOFA_UNUSED(mparams); + SOFA_UNUSED(f); + SOFA_UNUSED(x); + const auto& elements = trait::FiniteElement::getElementSequence(*this->l_topology); m_rotations.resize(elements.size(), RotationMatrix::Identity()); } @@ -83,6 +88,8 @@ void CorotationalFEMForceField::computeElementsForces( const sofa::simulation::Range& range, const sofa::core::MechanicalParams* mparams, sofa::type::vector& elementForces, const sofa::VecCoord_t& nodePositions) { + SOFA_UNUSED(mparams); + static constexpr auto DIM = trait::spatial_dimensions; const auto& elements = trait::FiniteElement::getElementSequence(*this->l_topology); auto restPositionAccessor = this->mstate->readRestPositions(); @@ -134,6 +141,8 @@ void CorotationalFEMForceField::computeElementsForcesDer sofa::type::vector& elementForcesDeriv, const sofa::VecDeriv_t& nodeDx) { + SOFA_UNUSED(mparams); + const auto& elements = trait::FiniteElement::getElementSequence(*this->l_topology); auto elementStiffness = sofa::helper::getReadAccessor(this->d_elementStiffness); @@ -206,6 +215,8 @@ SReal CorotationalFEMForceField::getPotentialEnergy( const sofa::core::MechanicalParams*, const sofa::DataVecCoord_t& x) const { + SOFA_UNUSED(x); + return 0; } diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/FEMForceField.h b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/FEMForceField.h index a0a718527e3..6c7299cc4f7 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/FEMForceField.h +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/FEMForceField.h @@ -86,7 +86,12 @@ class FEMForceField : virtual void beforeElementForce(const sofa::core::MechanicalParams* mparams, sofa::type::vector& f, - const sofa::VecCoord_t& x) {} + const sofa::VecCoord_t& x) + { + SOFA_UNUSED(mparams); + SOFA_UNUSED(f); + SOFA_UNUSED(x); + } virtual void computeElementsForces( const sofa::simulation::Range& range, @@ -106,7 +111,10 @@ class FEMForceField : sofa::type::vector& df, const sofa::VecDeriv_t& dx); - virtual void beforeElementForceDeriv(const sofa::core::MechanicalParams* mparams) {} + virtual void beforeElementForceDeriv(const sofa::core::MechanicalParams* mparams) + { + SOFA_UNUSED(mparams); + } virtual void computeElementsForcesDeriv( const sofa::simulation::Range& range, diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/LinearSmallStrainFEMForceField.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/LinearSmallStrainFEMForceField.inl index 6fea5667a99..d058077ee7b 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/LinearSmallStrainFEMForceField.inl +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/LinearSmallStrainFEMForceField.inl @@ -47,6 +47,8 @@ void LinearSmallStrainFEMForceField::computeElementsForc sofa::type::vector& elementForces, const sofa::VecCoord_t& nodePositions) { + SOFA_UNUSED(mparams); + const auto& elements = trait::FiniteElement::getElementSequence(*this->l_topology); auto restPositionAccessor = this->mstate->readRestPositions(); auto elementStiffness = sofa::helper::getReadAccessor(this->d_elementStiffness); @@ -78,6 +80,8 @@ void LinearSmallStrainFEMForceField::computeElementsForc sofa::type::vector& elementForcesDeriv, const sofa::VecDeriv_t& nodeDx) { + SOFA_UNUSED(mparams); + const auto& elements = trait::FiniteElement::getElementSequence(*this->l_topology); auto elementStiffness = sofa::helper::getReadAccessor(this->d_elementStiffness); @@ -145,6 +149,8 @@ SReal LinearSmallStrainFEMForceField::getPotentialEnergy const sofa::core::MechanicalParams*, const sofa::DataVecCoord_t& x) const { + SOFA_UNUSED(x); + return 0; } diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedronFEMForceField.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedronFEMForceField.inl index 266ca6f8612..8f0f060cb45 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedronFEMForceField.inl +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedronFEMForceField.inl @@ -1339,7 +1339,7 @@ void TetrahedronFEMForceField::init() if (!((i%nx)&1)) { // swap all points on the X edges - for (const auto [v0, v1] : sofa::geometry::Hexahedron::xEdges) + for (const auto& [v0, v1] : sofa::geometry::Hexahedron::xEdges) { std::swap(c[v0], c[v1]); } @@ -1347,7 +1347,7 @@ void TetrahedronFEMForceField::init() if (((i/nx)%ny)&1) { // swap all points on the Y edges - for (const auto [v0, v1] : sofa::geometry::Hexahedron::yEdges) + for (const auto& [v0, v1] : sofa::geometry::Hexahedron::yEdges) { std::swap(c[v0], c[v1]); } @@ -1355,7 +1355,7 @@ void TetrahedronFEMForceField::init() if ((i/(nx*ny))&1) { // swap all points on the Z edges - for (const auto [v0, v1] : sofa::geometry::Hexahedron::zEdges) + for (const auto& [v0, v1] : sofa::geometry::Hexahedron::zEdges) { std::swap(c[v0], c[v1]); } diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/impl/rotations/IdentityRotation.h b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/impl/rotations/IdentityRotation.h index 1d462e91326..1935a7ffb12 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/impl/rotations/IdentityRotation.h +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/impl/rotations/IdentityRotation.h @@ -29,6 +29,8 @@ struct IdentityRotation template void computeRotation(RotationMatrix& rotationMatrix, const RotationMatrix& initialRotationMatrix, const NotUsed1&, const NotUsed2&) { + SOFA_UNUSED(initialRotationMatrix); + rotationMatrix.identity(); } diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/impl/rotations/RotationMethodsContainer.h b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/impl/rotations/RotationMethodsContainer.h index ea708f32316..f4f84998014 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/impl/rotations/RotationMethodsContainer.h +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/impl/rotations/RotationMethodsContainer.h @@ -21,7 +21,7 @@ ******************************************************************************/ #pragma once -#include +#include #include namespace sofa::component::solidmechanics::fem::elastic @@ -65,7 +65,7 @@ struct RotationMethodsContainer static constexpr auto NumberOfMethods = std::variant_size_v; - explicit RotationMethodsContainer(sofa::core::objectmodel::BaseObject* parent) + explicit RotationMethodsContainer(sofa::core::objectmodel::BaseComponent* parent) : d_rotationMethod(parent->initData(&d_rotationMethod, "rotationMethod", ("The method used to compute the element rotations.\n" + RotationMethodsItems::dataDescription()).c_str())) {} diff --git a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/Ogden.h b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/Ogden.h index 90724e3ec59..1873b5bc3d6 100644 --- a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/Ogden.h +++ b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/Ogden.h @@ -133,9 +133,6 @@ class Ogden: public HyperelasticMaterial const Real alpha1 = param.parameterArray[1]; const Real k0 = param.parameterArray[2]; - // trace of C^(alpha1/2) - const Real aBy2 = alpha1/static_cast(2); - // Siso = dWiso/dlambda*dlambda/dC + dWiso/dF*dF/dC const MatrixSym S_isochoric = m_CaBy2Minus1 * m_FJ * mu1 / alpha1 -m_invC * m_FJ * mu1 / (static_cast(3)*alpha1) * m_trCaBy2; @@ -149,7 +146,6 @@ class Ogden: public HyperelasticMaterial { this->precomputeVariables(sinfo, param); - const MatrixSym& C = sinfo->deformationTensor; const Real mu1 = param.parameterArray[0]; const Real alpha1 = param.parameterArray[1]; const Real k0 = param.parameterArray[2]; diff --git a/Sofa/Component/Visual/src/sofa/component/visual/VisualMesh.cpp b/Sofa/Component/Visual/src/sofa/component/visual/VisualMesh.cpp index d39edbc9595..a9875705b9d 100644 --- a/Sofa/Component/Visual/src/sofa/component/visual/VisualMesh.cpp +++ b/Sofa/Component/Visual/src/sofa/component/visual/VisualMesh.cpp @@ -61,6 +61,8 @@ void VisualMesh::init() void VisualMesh::computeBBox(const core::ExecParams* exec_params, bool onlyVisible) { + SOFA_UNUSED(exec_params); + if (!d_enable.getValue()) return; diff --git a/Sofa/Component/Visual/src/sofa/component/visual/VisualModelImpl.cpp b/Sofa/Component/Visual/src/sofa/component/visual/VisualModelImpl.cpp index b0b41d6ec0d..172a9f90118 100644 --- a/Sofa/Component/Visual/src/sofa/component/visual/VisualModelImpl.cpp +++ b/Sofa/Component/Visual/src/sofa/component/visual/VisualModelImpl.cpp @@ -38,6 +38,7 @@ #include +#include #include #include #include @@ -963,7 +964,7 @@ void VisualModelImpl::computeNormals() auto normals = sofa::helper::getWriteOnlyAccessor(m_vnormals); normals.resize(nbn); - std::memset(&normals[0], 0, sizeof(normals[0]) * nbn); // bulk reset with zeros + std::fill(normals.begin(), normals.end(), Coord{}); // bulk reset with zeros for (const auto& triangle : triangles) { diff --git a/Sofa/Component/Visual/src/sofa/component/visual/VisualPointCloud.inl b/Sofa/Component/Visual/src/sofa/component/visual/VisualPointCloud.inl index cc26964a292..29a78005af8 100644 --- a/Sofa/Component/Visual/src/sofa/component/visual/VisualPointCloud.inl +++ b/Sofa/Component/Visual/src/sofa/component/visual/VisualPointCloud.inl @@ -165,6 +165,8 @@ template void VisualPointCloud::drawFrames(const core::visual::VisualParams* vparams, type::RGBAColor color) requires hasWriteOpenGlMatrix { + SOFA_UNUSED(color); + if constexpr (hasWriteOpenGlMatrix) { auto* drawTool = vparams->drawTool(); diff --git a/Sofa/Component/Visual/src/sofa/component/visual/VisualVectorField.inl b/Sofa/Component/Visual/src/sofa/component/visual/VisualVectorField.inl index 2f3e8dd1fca..6895e24b00a 100644 --- a/Sofa/Component/Visual/src/sofa/component/visual/VisualVectorField.inl +++ b/Sofa/Component/Visual/src/sofa/component/visual/VisualVectorField.inl @@ -74,6 +74,9 @@ void VisualVectorField::doDrawVisual(const core::visual::VisualParams template void VisualVectorField::computeBBox(const core::ExecParams* exec_params, bool cond) { + SOFA_UNUSED(exec_params); + SOFA_UNUSED(cond); + const auto position = sofa::helper::getReadAccessor(d_position); const auto vector = sofa::helper::getReadAccessor(d_vector); From 9f9e4dc2be0279c3c312145b7ee3485b2bd6732b Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Tue, 11 Aug 2026 18:47:43 +0200 Subject: [PATCH 2/2] Fix warnings in topology --- .../dynamic/TriangleSetGeometryAlgorithms.h | 15 ++++++ .../dynamic/TriangleSetGeometryAlgorithms.inl | 52 +++++++++++++------ .../mapping/Hexa2TetraTopologicalMapping.cpp | 6 +-- .../utility/TopologicalChangeProcessor.cpp | 6 +-- 4 files changed, 57 insertions(+), 22 deletions(-) diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.h b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.h index e0cbc8cfaef..0c5b4a385e7 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.h +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.h @@ -128,6 +128,21 @@ class TriangleSetGeometryAlgorithms : public EdgeSetGeometryAlgorithms computeTriangleBarycentricCoordinates(const TriangleID ind_t, const sofa::type::Vec<3, Real>& p, bool useRestPosition = false) const; + /** \brief Compute the barycentric coordinates of input point @param p inside the triangle formed by the three + * points given by their indices, using either current position or restPosition depending on @param useRestPosition value. + * @param p position of the point to compute the coefficients + * @param ind_p1 Index of the first vertex of the triangle + * @param ind_p2 Index of the second vertex of the triangle + * @param ind_p3 Index of the third vertex of the triangle + * @param useRestPosition bool false to use position, true to use rest_position + * @return the 3 barycentric coordinates inside a sofa::type::Vec<3, Real> + */ + sofa::type::Vec<3, Real> compute3PointsBarycentricCoordinates(const sofa::type::Vec<3, Real>& p, + PointID ind_p1, + PointID ind_p2, + PointID ind_p3, + bool useRestPosition = false) const; + /** \brief Finds the two closest points from two triangles (each of the point belonging to one triangle) * diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.inl b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.inl index 33b610dee9d..112e35ddc59 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.inl +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.inl @@ -482,7 +482,8 @@ auto TriangleSetGeometryAlgorithms< DataTypes >::computeTriangleBarycoefs( const sofa::type::Vec<3,Real> &p) const -> sofa::type::vector { const Triangle &t=this->m_topology->getTriangle(ind_t); - return compute3PointsBarycoefs(p, t[0], t[1], t[2],false); + const auto baryCoords = compute3PointsBarycentricCoordinates(p, t[0], t[1], t[2], false); + return { baryCoords[0], baryCoords[1], baryCoords[2] }; } template @@ -507,7 +508,8 @@ auto TriangleSetGeometryAlgorithms< DataTypes >::computeRestTriangleBarycoefs( const sofa::type::Vec<3, Real>& p) const -> sofa::type::vector { const Triangle& t = this->m_topology->getTriangle(ind_t); - return compute3PointsBarycoefs(p, t[0], t[1], t[2], true); + const auto baryCoords = compute3PointsBarycentricCoordinates(p, t[0], t[1], t[2], true); + return { baryCoords[0], baryCoords[1], baryCoords[2] }; } // barycentric coefficients of point p in triangle whose vertices are indexed by (ind_p1,ind_p2,ind_p3) @@ -518,11 +520,23 @@ auto TriangleSetGeometryAlgorithms< DataTypes >::compute3PointsBarycoefs( PointID ind_p2, PointID ind_p3, bool bRest) const -> sofa::type::vector +{ + const auto baryCoords = compute3PointsBarycentricCoordinates(p, ind_p1, ind_p2, ind_p3, bRest); + return { baryCoords[0], baryCoords[1], baryCoords[2] }; +} + +// barycentric coordinates of point p in triangle whose vertices are indexed by (ind_p1,ind_p2,ind_p3) +template +auto TriangleSetGeometryAlgorithms< DataTypes >::compute3PointsBarycentricCoordinates( + const sofa::type::Vec<3, Real> &p, + PointID ind_p1, + PointID ind_p2, + PointID ind_p3, + bool useRestPosition) const -> sofa::type::Vec<3, Real> { const Real ZERO = 1e-12; - sofa::type::vector< SReal > baryCoefs; - const typename DataTypes::VecCoord& vect_c = (bRest ? (this->object->read(core::vec_id::read_access::restPosition)->getValue()) : (this->object->read(core::vec_id::read_access::position)->getValue())); + const typename DataTypes::VecCoord& vect_c = (useRestPosition ? (this->object->read(core::vec_id::read_access::restPosition)->getValue()) : (this->object->read(core::vec_id::read_access::position)->getValue())); const typename DataTypes::Coord& c0 = vect_c[ind_p1]; const typename DataTypes::Coord& c1 = vect_c[ind_p2]; @@ -563,11 +577,7 @@ auto TriangleSetGeometryAlgorithms< DataTypes >::compute3PointsBarycoefs( coef_c = (Real) (1.0 - (coef_a + coef_b)); //N*((a-p).cross(b-p)); } - baryCoefs.push_back(coef_a); - baryCoefs.push_back(coef_b); - baryCoefs.push_back(coef_c); - - return baryCoefs; + return { coef_a, coef_b, coef_c }; } // Find the two closest points from two triangles (each of the point belonging to one triangle) @@ -2730,7 +2740,7 @@ bool TriangleSetGeometryAlgorithms::computeIntersectedObjectsList (co } else { - auto coefs_a = computeTriangleBarycoefs (ind_triA, pointA); + auto coefs_a = computeTriangleBarycentricCoordinates (ind_triA, pointA); intersected_topoElements.push_back (sofa::geometry::ElementType::TRIANGLE); intersected_indices.push_back (ind_triA); for (unsigned int i = 0; i<3; i++) @@ -2753,7 +2763,7 @@ bool TriangleSetGeometryAlgorithms::computeIntersectedObjectsList (co } // 3 - Last point b (for the moment: always a point in a triangle) - auto coefs_b = computeTriangleBarycoefs (ind_triB, pointB); + auto coefs_b = computeTriangleBarycentricCoordinates (ind_triB, pointB); bool isOnPoint = false; for (unsigned int i = 0; i<3; i++) if (coefs_b[i] > 0.9999 ) @@ -3201,14 +3211,14 @@ void TriangleSetGeometryAlgorithms< DataTypes >::InciseAlongLinesList( Real epsilon = 0.2; // INFO : epsilon is a threshold in [0,1] to control the snapping of the extremities to the closest vertex auto a_baryCoefs = - computeTriangleBarycoefs(ind_ta, (const sofa::type::Vec<3, Real> &) a); + computeTriangleBarycentricCoordinates(ind_ta, (const sofa::type::Vec<3, Real> &) a); snapping_test_triangle(epsilon, a_baryCoefs[0], a_baryCoefs[1], a_baryCoefs[2], is_snap_a0, is_snap_a1, is_snap_a2); Real is_snapping_a = is_snap_a0 || is_snap_a1 || is_snap_a2; auto b_baryCoefs = - computeTriangleBarycoefs(ind_tb, (const sofa::type::Vec<3, Real> &) b); + computeTriangleBarycentricCoordinates(ind_tb, (const sofa::type::Vec<3, Real> &) b); snapping_test_triangle(epsilon, b_baryCoefs[0], b_baryCoefs[1], b_baryCoefs[2], is_snap_b0, is_snap_b1, is_snap_b2); @@ -3246,7 +3256,10 @@ void TriangleSetGeometryAlgorithms< DataTypes >::InciseAlongLinesList( a_first_ancestors.push_back(ta[1]); a_first_ancestors.push_back(ta[2]); p_ancestors.push_back(a_first_ancestors); - p_baryCoefs.push_back(a_baryCoefs); + p_baryCoefs.push_back(sofa::type::vector{ + static_cast(a_baryCoefs[0]), + static_cast(a_baryCoefs[1]), + static_cast(a_baryCoefs[2]) }); acc_nb_points = acc_nb_points + 1; @@ -3531,7 +3544,10 @@ void TriangleSetGeometryAlgorithms< DataTypes >::InciseAlongLinesList( b_first_ancestors.push_back(tb[1]); b_first_ancestors.push_back(tb[2]); p_ancestors.push_back(b_first_ancestors); - p_baryCoefs.push_back(b_baryCoefs); + p_baryCoefs.push_back(sofa::type::vector{ + static_cast(b_baryCoefs[0]), + static_cast(b_baryCoefs[1]), + static_cast(b_baryCoefs[2]) }); acc_nb_points = acc_nb_points + 1; @@ -4513,7 +4529,11 @@ int TriangleSetGeometryAlgorithms::SplitAlongPath(PointID ind_A, Coor if (points2Snap[i].size() == 7) { - coefs2Snap[i] = compute3PointsBarycoefs(SnapedCoord, firstAncestor, secondAncestor, (PointID)points2Snap[i][6]); + const auto baryCoords = compute3PointsBarycentricCoordinates(SnapedCoord, firstAncestor, secondAncestor, (PointID)points2Snap[i][6]); + coefs2Snap[i] = sofa::type::vector{ + static_cast(baryCoords[0]), + static_cast(baryCoords[1]), + static_cast(baryCoords[2]) }; ancestors2Snap[i].push_back((PointID)points2Snap[i][6]); } else diff --git a/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Hexa2TetraTopologicalMapping.cpp b/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Hexa2TetraTopologicalMapping.cpp index 80b730c85e4..ab99c5301ab 100644 --- a/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Hexa2TetraTopologicalMapping.cpp +++ b/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Hexa2TetraTopologicalMapping.cpp @@ -132,7 +132,7 @@ void Hexa2TetraTopologicalMapping::init() // / / // / / // Z Z - for (const auto [v0, v1] : sofa::geometry::Hexahedron::xEdges) + for (const auto& [v0, v1] : sofa::geometry::Hexahedron::xEdges) { std::swap(c[v0], c[v1]); } @@ -154,7 +154,7 @@ void Hexa2TetraTopologicalMapping::init() // / / // / / // Z Z - for (const auto [v0, v1] : sofa::geometry::Hexahedron::yEdges) + for (const auto& [v0, v1] : sofa::geometry::Hexahedron::yEdges) { std::swap(c[v0], c[v1]); } @@ -176,7 +176,7 @@ void Hexa2TetraTopologicalMapping::init() // / / // / / // Z Z - for (const auto [v0, v1] : sofa::geometry::Hexahedron::zEdges) + for (const auto& [v0, v1] : sofa::geometry::Hexahedron::zEdges) { std::swap(c[v0], c[v1]); } diff --git a/Sofa/Component/Topology/Utility/src/sofa/component/topology/utility/TopologicalChangeProcessor.cpp b/Sofa/Component/Topology/Utility/src/sofa/component/topology/utility/TopologicalChangeProcessor.cpp index c8c86d9f5ed..30cc9ce3fcc 100644 --- a/Sofa/Component/Topology/Utility/src/sofa/component/topology/utility/TopologicalChangeProcessor.cpp +++ b/Sofa/Component/Topology/Utility/src/sofa/component/topology/utility/TopologicalChangeProcessor.cpp @@ -892,7 +892,7 @@ void TopologicalChangeProcessor::saveIndices() sofa::component::topology::container::dynamic::TriangleSetGeometryAlgorithms* triangleGeo; m_topology->getContext()->get(triangleGeo); - const auto baryCoef = triangleGeo->computeTriangleBarycoefs( triInd, constCoord); + const auto baryCoef = triangleGeo->computeTriangleBarycentricCoordinates( triInd, constCoord); Vec3 barycentricCoordinates(baryCoef[0], baryCoef[1], baryCoef[2]); Vec3Types::Coord aCoord[3]; @@ -953,7 +953,7 @@ void TopologicalChangeProcessor::saveIndices() triangleIncisionInformation[i].triangleIndices[0] = triIndex; - const auto newBaryCoef = triangleGeo->computeTriangleBarycoefs( triangleIncisionInformation[i].triangleIndices[0], newPosition); + const auto newBaryCoef = triangleGeo->computeTriangleBarycentricCoordinates( triangleIncisionInformation[i].triangleIndices[0], newPosition); for (unsigned int j = 0 ; j < 3 ; j++) triangleIncisionInformation[i].barycentricCoordinates.front()[j] = newBaryCoef[j]; @@ -1366,7 +1366,7 @@ void TopologicalChangeProcessor::updateTriangleIncisionInformation() //update the triangle barycentric coordinates corresponding to the current coordinates const Vec3 constCoord = triangleIncisionInformation[i].coordinates[j]; - const auto baryCoef = triangleGeo->computeTriangleBarycoefs( newTriangleIndexb, constCoord); + const auto baryCoef = triangleGeo->computeTriangleBarycentricCoordinates( newTriangleIndexb, constCoord); triangleIncisionInformation[i].barycentricCoordinates[j] = Vec3(baryCoef[0], baryCoef[1], baryCoef[2]); } }