From 6b3f7e220d10f248d6d1d7019d6e9fde9bea37e1 Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Mon, 23 Sep 2024 09:33:24 +0200 Subject: [PATCH 01/43] [Mapping.Linear] Use links instead of raw pointers (#4996) * [Mapping.Linear] Use links instead of raw pointers * fix non-Windows compilation --- .../linear/Mesh2PointMechanicalMapping.cpp | 4 - .../linear/Mesh2PointMechanicalMapping.h | 7 +- .../linear/Mesh2PointMechanicalMapping.inl | 268 ++++++++++-------- 3 files changed, 153 insertions(+), 126 deletions(-) diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/Mesh2PointMechanicalMapping.cpp b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/Mesh2PointMechanicalMapping.cpp index e8a3e2da6c4..1655148689e 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/Mesh2PointMechanicalMapping.cpp +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/Mesh2PointMechanicalMapping.cpp @@ -33,10 +33,6 @@ using namespace sofa::defaulttype; int Mesh2PointMechanicalMappingClass = core::RegisterObject("Mechanical mapping between a set of mesh primitives (point, edge, triangle...) and a set of points generated by Mesh2PointTopologicalMapping") .add< Mesh2PointMechanicalMapping< Vec3Types, Vec3Types > >() - - - -//.addAlias("SimpleTesselatedTetraMechanicalMapping") ; diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/Mesh2PointMechanicalMapping.h b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/Mesh2PointMechanicalMapping.h index 0e8a1b0e3f1..10aea9ea318 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/Mesh2PointMechanicalMapping.h +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/Mesh2PointMechanicalMapping.h @@ -76,10 +76,9 @@ class Mesh2PointMechanicalMapping : public LinearMapping void applyJT(const core::ConstraintParams *cparams, Data& out, const Data& in) override; -protected: - Mesh2PointTopologicalMapping* topoMap; - core::topology::BaseMeshTopology* inputTopo; - core::topology::BaseMeshTopology* outputTopo; + SingleLink l_topologicalMapping; + SingleLink l_inputTopology; + SingleLink l_outputTopology; }; diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/Mesh2PointMechanicalMapping.inl b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/Mesh2PointMechanicalMapping.inl index 1bca9ae1855..c7b854648da 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/Mesh2PointMechanicalMapping.inl +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/Mesh2PointMechanicalMapping.inl @@ -32,9 +32,9 @@ namespace sofa::component::mapping::linear template Mesh2PointMechanicalMapping::Mesh2PointMechanicalMapping(core::State* from, core::State* to) : Inherit(from, to) - , topoMap(nullptr) - , inputTopo(nullptr) - , outputTopo(nullptr) + , l_topologicalMapping(initLink("topologicalMapping", "Link to a Mesh2PointTopologicalMapping")) + , l_inputTopology(initLink("inputTopology", "Link to the input topology")) + , l_outputTopology(initLink("outputTopology", "Link to the output topology")) { } @@ -47,44 +47,76 @@ template void Mesh2PointMechanicalMapping::init() { this->Inherit::init(); - this->getContext()->get(topoMap); - inputTopo = this->fromModel->getContext()->getMeshTopology(); - outputTopo = this->toModel->getContext()->getMeshTopology(); + + if (!l_topologicalMapping) + { + l_topologicalMapping.set(this->getContext()->template get()); + if (!l_topologicalMapping) + { + msg_error() << "Cannot find a component " << l_topologicalMapping->getClassName() << " in the current context"; + this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid); + return; + } + } + + if (!l_inputTopology) + { + l_inputTopology.set(this->fromModel->getContext()->getMeshTopology()); + if (!l_inputTopology) + { + msg_error() << "Cannot find a component " << l_inputTopology->getClassName() << " in the context of " << this->fromModel->getPathName(); + this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid); + return; + } + } + + if (!l_outputTopology) + { + l_outputTopology.set(this->toModel->getContext()->getMeshTopology()); + if (!l_outputTopology) + { + msg_error() << "Cannot find a component " << l_outputTopology->getClassName() << " in the context of " << this->toModel->getPathName(); + this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid); + return; + } + } + + this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Valid); } template void Mesh2PointMechanicalMapping::apply(const core::MechanicalParams * /*mparams*/, Data& dOut, const Data& dIn) { - if (!topoMap) return; + if (!l_topologicalMapping) return; using sofa::InvalidID; helper::WriteAccessor< Data > out = dOut; helper::ReadAccessor< Data > in = dIn; - const auto& pointMap = topoMap->getPointsMappedFromPoint(); - const auto& edgeMap = topoMap->getPointsMappedFromEdge(); - const auto& triangleMap = topoMap->getPointsMappedFromTriangle(); - const auto& quadMap = topoMap->getPointsMappedFromQuad(); - const auto& tetraMap = topoMap->getPointsMappedFromTetra(); - const auto& hexaMap = topoMap->getPointsMappedFromHexa(); + const auto& pointMap = l_topologicalMapping->getPointsMappedFromPoint(); + const auto& edgeMap = l_topologicalMapping->getPointsMappedFromEdge(); + const auto& triangleMap = l_topologicalMapping->getPointsMappedFromTriangle(); + const auto& quadMap = l_topologicalMapping->getPointsMappedFromQuad(); + const auto& tetraMap = l_topologicalMapping->getPointsMappedFromTetra(); + const auto& hexaMap = l_topologicalMapping->getPointsMappedFromHexa(); if (pointMap.empty() && edgeMap.empty() && triangleMap.empty() && quadMap.empty() && tetraMap.empty() && hexaMap.empty()) return; - const core::topology::BaseMeshTopology::SeqEdges& edges = inputTopo->getEdges(); - const core::topology::BaseMeshTopology::SeqTriangles& triangles = inputTopo->getTriangles(); - const core::topology::BaseMeshTopology::SeqQuads& quads = inputTopo->getQuads(); - const core::topology::BaseMeshTopology::SeqTetrahedra& tetrahedra = inputTopo->getTetrahedra(); - const core::topology::BaseMeshTopology::SeqHexahedra& hexahedra = inputTopo->getHexahedra(); + const core::topology::BaseMeshTopology::SeqEdges& edges = l_inputTopology->getEdges(); + const core::topology::BaseMeshTopology::SeqTriangles& triangles = l_inputTopology->getTriangles(); + const core::topology::BaseMeshTopology::SeqQuads& quads = l_inputTopology->getQuads(); + const core::topology::BaseMeshTopology::SeqTetrahedra& tetrahedra = l_inputTopology->getTetrahedra(); + const core::topology::BaseMeshTopology::SeqHexahedra& hexahedra = l_inputTopology->getHexahedra(); - out.resize(outputTopo->getNbPoints()); + out.resize(l_outputTopology->getNbPoints()); for(unsigned int i = 0; i < pointMap.size(); ++i) { for(unsigned int j = 0; j < pointMap[i].size(); ++j) { if (pointMap[i][j] == InvalidID) continue; - out[pointMap[i][j]] = in[i]+topoMap->getPointBaryCoords()[j]; + out[pointMap[i][j]] = in[i]+l_topologicalMapping->getPointBaryCoords()[j]; } } @@ -93,7 +125,7 @@ void Mesh2PointMechanicalMapping::apply(const core::MechanicalParams for(unsigned int j = 0; j < edgeMap[i].size(); ++j) { if (edgeMap[i][j] == InvalidID) continue; - double fx = topoMap->getEdgeBaryCoords()[j][0]; + double fx = l_topologicalMapping->getEdgeBaryCoords()[j][0]; out[edgeMap[i][j]] = in[ edges[i][0] ] * (1-fx) +in[ edges[i][1] ] * fx; } @@ -104,8 +136,8 @@ void Mesh2PointMechanicalMapping::apply(const core::MechanicalParams for(unsigned int j = 0; j < triangleMap[i].size(); ++j) { if (triangleMap[i][j] == InvalidID) continue; - double fx = topoMap->getTriangleBaryCoords()[j][0]; - double fy = topoMap->getTriangleBaryCoords()[j][1]; + double fx = l_topologicalMapping->getTriangleBaryCoords()[j][0]; + double fy = l_topologicalMapping->getTriangleBaryCoords()[j][1]; out[triangleMap[i][j]] = in[ triangles[i][0] ] * (1-fx-fy) + in[ triangles[i][1] ] * fx + in[ triangles[i][2] ] * fy; @@ -117,8 +149,8 @@ void Mesh2PointMechanicalMapping::apply(const core::MechanicalParams for(unsigned int j = 0; j < quadMap[i].size(); ++j) { if (quadMap[i][j] == InvalidID) continue; - const double fx = topoMap->getQuadBaryCoords()[j][0]; - const double fy = topoMap->getQuadBaryCoords()[j][1]; + const double fx = l_topologicalMapping->getQuadBaryCoords()[j][0]; + const double fy = l_topologicalMapping->getQuadBaryCoords()[j][1]; out[quadMap[i][j]] = in[ quads[i][0] ] * ((1-fx) * (1-fy)) + in[ quads[i][1] ] * (( fx) * (1-fy)) + in[ quads[i][2] ] * ((1-fx) * ( fy)) @@ -131,9 +163,9 @@ void Mesh2PointMechanicalMapping::apply(const core::MechanicalParams for(unsigned int j = 0; j < tetraMap[i].size(); ++j) { if (tetraMap[i][j] == InvalidID) continue; - double fx = topoMap->getTetraBaryCoords()[j][0]; - double fy = topoMap->getTetraBaryCoords()[j][1]; - double fz = topoMap->getTetraBaryCoords()[j][2]; + double fx = l_topologicalMapping->getTetraBaryCoords()[j][0]; + double fy = l_topologicalMapping->getTetraBaryCoords()[j][1]; + double fz = l_topologicalMapping->getTetraBaryCoords()[j][2]; out[tetraMap[i][j]] = in[ tetrahedra[i][0] ] * (1-fx-fy-fz) + in[ tetrahedra[i][1] ] * fx + in[ tetrahedra[i][2] ] * fy @@ -146,9 +178,9 @@ void Mesh2PointMechanicalMapping::apply(const core::MechanicalParams for(unsigned int j = 0; j < hexaMap[i].size(); ++j) { if (hexaMap[i][j] == InvalidID) continue; - const double fx = topoMap->getHexaBaryCoords()[j][0]; - const double fy = topoMap->getHexaBaryCoords()[j][1]; - const double fz = topoMap->getHexaBaryCoords()[j][2]; + const double fx = l_topologicalMapping->getHexaBaryCoords()[j][0]; + const double fy = l_topologicalMapping->getHexaBaryCoords()[j][1]; + const double fz = l_topologicalMapping->getHexaBaryCoords()[j][2]; out[hexaMap[i][j]] = in[ hexahedra[i][0] ] * ((1-fx) * (1-fy) * (1-fz)) + in[ hexahedra[i][1] ] * (( fx) * (1-fy) * (1-fz)) + in[ hexahedra[i][3] ] * ((1-fx) * ( fy) * (1-fz)) @@ -164,29 +196,29 @@ void Mesh2PointMechanicalMapping::apply(const core::MechanicalParams template void Mesh2PointMechanicalMapping::applyJ(const core::MechanicalParams * /*mparams*/, Data& dOut, const Data& dIn) { - if (!topoMap) return; + if (!l_topologicalMapping) return; using sofa::InvalidID; helper::WriteAccessor< Data > out = dOut; helper::ReadAccessor< Data > in = dIn; - const auto& pointMap = topoMap->getPointsMappedFromPoint(); - const auto& edgeMap = topoMap->getPointsMappedFromEdge(); - const auto& triangleMap = topoMap->getPointsMappedFromTriangle(); - const auto& quadMap = topoMap->getPointsMappedFromQuad(); - const auto& tetraMap = topoMap->getPointsMappedFromTetra(); - const auto& hexaMap = topoMap->getPointsMappedFromHexa(); + const auto& pointMap = l_topologicalMapping->getPointsMappedFromPoint(); + const auto& edgeMap = l_topologicalMapping->getPointsMappedFromEdge(); + const auto& triangleMap = l_topologicalMapping->getPointsMappedFromTriangle(); + const auto& quadMap = l_topologicalMapping->getPointsMappedFromQuad(); + const auto& tetraMap = l_topologicalMapping->getPointsMappedFromTetra(); + const auto& hexaMap = l_topologicalMapping->getPointsMappedFromHexa(); if (pointMap.empty() && edgeMap.empty() && triangleMap.empty() && quadMap.empty() && tetraMap.empty() && hexaMap.empty()) return; - const core::topology::BaseMeshTopology::SeqEdges& edges = inputTopo->getEdges(); - const core::topology::BaseMeshTopology::SeqTriangles& triangles = inputTopo->getTriangles(); - const core::topology::BaseMeshTopology::SeqQuads& quads = inputTopo->getQuads(); - const core::topology::BaseMeshTopology::SeqTetrahedra& tetrahedra = inputTopo->getTetrahedra(); - const core::topology::BaseMeshTopology::SeqHexahedra& hexahedra = inputTopo->getHexahedra(); + const core::topology::BaseMeshTopology::SeqEdges& edges = l_inputTopology->getEdges(); + const core::topology::BaseMeshTopology::SeqTriangles& triangles = l_inputTopology->getTriangles(); + const core::topology::BaseMeshTopology::SeqQuads& quads = l_inputTopology->getQuads(); + const core::topology::BaseMeshTopology::SeqTetrahedra& tetrahedra = l_inputTopology->getTetrahedra(); + const core::topology::BaseMeshTopology::SeqHexahedra& hexahedra = l_inputTopology->getHexahedra(); - out.resize(outputTopo->getNbPoints()); + out.resize(l_outputTopology->getNbPoints()); for(unsigned int i = 0; i < pointMap.size(); ++i) { for(unsigned int j = 0; j < pointMap[i].size(); ++j) @@ -201,7 +233,7 @@ void Mesh2PointMechanicalMapping::applyJ(const core::MechanicalParams for(unsigned int j = 0; j < edgeMap[i].size(); ++j) { if (edgeMap[i][j] == InvalidID) continue; - double fx = topoMap->getEdgeBaryCoords()[j][0]; + double fx = l_topologicalMapping->getEdgeBaryCoords()[j][0]; out[edgeMap[i][j]] = in[ edges[i][0] ] * (1-fx) +in[ edges[i][1] ] * fx; } @@ -212,8 +244,8 @@ void Mesh2PointMechanicalMapping::applyJ(const core::MechanicalParams for(unsigned int j = 0; j < triangleMap[i].size(); ++j) { if (triangleMap[i][j] == InvalidID) continue; - double fx = topoMap->getTriangleBaryCoords()[j][0]; - double fy = topoMap->getTriangleBaryCoords()[j][1]; + double fx = l_topologicalMapping->getTriangleBaryCoords()[j][0]; + double fy = l_topologicalMapping->getTriangleBaryCoords()[j][1]; out[triangleMap[i][j]] = in[ triangles[i][0] ] * (1-fx-fy) + in[ triangles[i][1] ] * fx + in[ triangles[i][2] ] * fy; @@ -225,8 +257,8 @@ void Mesh2PointMechanicalMapping::applyJ(const core::MechanicalParams for(unsigned int j = 0; j < quadMap[i].size(); ++j) { if (quadMap[i][j] == InvalidID) continue; - const double fx = topoMap->getQuadBaryCoords()[j][0]; - const double fy = topoMap->getQuadBaryCoords()[j][1]; + const double fx = l_topologicalMapping->getQuadBaryCoords()[j][0]; + const double fy = l_topologicalMapping->getQuadBaryCoords()[j][1]; out[quadMap[i][j]] = in[ quads[i][0] ] * ((1-fx) * (1-fy)) + in[ quads[i][1] ] * (( fx) * (1-fy)) + in[ quads[i][2] ] * ((1-fx) * ( fy)) @@ -239,9 +271,9 @@ void Mesh2PointMechanicalMapping::applyJ(const core::MechanicalParams for(unsigned int j = 0; j < tetraMap[i].size(); ++j) { if (tetraMap[i][j] == InvalidID) continue; - double fx = topoMap->getTetraBaryCoords()[j][0]; - double fy = topoMap->getTetraBaryCoords()[j][1]; - double fz = topoMap->getTetraBaryCoords()[j][2]; + double fx = l_topologicalMapping->getTetraBaryCoords()[j][0]; + double fy = l_topologicalMapping->getTetraBaryCoords()[j][1]; + double fz = l_topologicalMapping->getTetraBaryCoords()[j][2]; out[tetraMap[i][j]] = in[ tetrahedra[i][0] ] * (1-fx-fy-fz) + in[ tetrahedra[i][1] ] * fx + in[ tetrahedra[i][2] ] * fy @@ -254,9 +286,9 @@ void Mesh2PointMechanicalMapping::applyJ(const core::MechanicalParams for(unsigned int j = 0; j < hexaMap[i].size(); ++j) { if (hexaMap[i][j] == InvalidID) continue; - const double fx = topoMap->getHexaBaryCoords()[j][0]; - const double fy = topoMap->getHexaBaryCoords()[j][1]; - const double fz = topoMap->getHexaBaryCoords()[j][2]; + const double fx = l_topologicalMapping->getHexaBaryCoords()[j][0]; + const double fy = l_topologicalMapping->getHexaBaryCoords()[j][1]; + const double fz = l_topologicalMapping->getHexaBaryCoords()[j][2]; out[hexaMap[i][j]] = in[ hexahedra[i][0] ] * ((1-fx) * (1-fy) * (1-fz)) + in[ hexahedra[i][1] ] * (( fx) * (1-fy) * (1-fz)) + in[ hexahedra[i][3] ] * ((1-fx) * ( fy) * (1-fz)) @@ -272,29 +304,29 @@ void Mesh2PointMechanicalMapping::applyJ(const core::MechanicalParams template void Mesh2PointMechanicalMapping::applyJT(const core::MechanicalParams * /*mparams*/, Data& dOut, const Data& dIn) { - if (!topoMap) return; + if (!l_topologicalMapping) return; using sofa::InvalidID; helper::WriteAccessor< Data > out = dOut; helper::ReadAccessor< Data > in = dIn; - const auto& pointMap = topoMap->getPointsMappedFromPoint(); - const auto& edgeMap = topoMap->getPointsMappedFromEdge(); - const auto& triangleMap = topoMap->getPointsMappedFromTriangle(); - const auto& quadMap = topoMap->getPointsMappedFromQuad(); - const auto& tetraMap = topoMap->getPointsMappedFromTetra(); - const auto& hexaMap = topoMap->getPointsMappedFromHexa(); + const auto& pointMap = l_topologicalMapping->getPointsMappedFromPoint(); + const auto& edgeMap = l_topologicalMapping->getPointsMappedFromEdge(); + const auto& triangleMap = l_topologicalMapping->getPointsMappedFromTriangle(); + const auto& quadMap = l_topologicalMapping->getPointsMappedFromQuad(); + const auto& tetraMap = l_topologicalMapping->getPointsMappedFromTetra(); + const auto& hexaMap = l_topologicalMapping->getPointsMappedFromHexa(); if (pointMap.empty() && edgeMap.empty() && triangleMap.empty() && quadMap.empty() && tetraMap.empty() && hexaMap.empty()) return; - const core::topology::BaseMeshTopology::SeqEdges& edges = inputTopo->getEdges(); - const core::topology::BaseMeshTopology::SeqTriangles& triangles = inputTopo->getTriangles(); - const core::topology::BaseMeshTopology::SeqQuads& quads = inputTopo->getQuads(); - const core::topology::BaseMeshTopology::SeqTetrahedra& tetrahedra = inputTopo->getTetrahedra(); - const core::topology::BaseMeshTopology::SeqHexahedra& hexahedra = inputTopo->getHexahedra(); + const core::topology::BaseMeshTopology::SeqEdges& edges = l_inputTopology->getEdges(); + const core::topology::BaseMeshTopology::SeqTriangles& triangles = l_inputTopology->getTriangles(); + const core::topology::BaseMeshTopology::SeqQuads& quads = l_inputTopology->getQuads(); + const core::topology::BaseMeshTopology::SeqTetrahedra& tetrahedra = l_inputTopology->getTetrahedra(); + const core::topology::BaseMeshTopology::SeqHexahedra& hexahedra = l_inputTopology->getHexahedra(); - out.resize(inputTopo->getNbPoints()); + out.resize(l_inputTopology->getNbPoints()); for(unsigned int i = 0; i < pointMap.size(); ++i) { for(unsigned int j = 0; j < pointMap[i].size(); ++j) @@ -309,7 +341,7 @@ void Mesh2PointMechanicalMapping::applyJT(const core::MechanicalParam for(unsigned int j = 0; j < edgeMap[i].size(); ++j) { if (edgeMap[i][j] == InvalidID) continue; - double fx = topoMap->getEdgeBaryCoords()[j][0]; + double fx = l_topologicalMapping->getEdgeBaryCoords()[j][0]; out[edges[i][0]] += in[ edgeMap[i][j] ] * (1-fx); out[edges[i][1]] += in[ edgeMap[i][j] ] * fx; } @@ -320,8 +352,8 @@ void Mesh2PointMechanicalMapping::applyJT(const core::MechanicalParam for(unsigned int j = 0; j < triangleMap[i].size(); ++j) { if (triangleMap[i][j] == InvalidID) continue; - double fx = topoMap->getTriangleBaryCoords()[j][0]; - double fy = topoMap->getTriangleBaryCoords()[j][1]; + double fx = l_topologicalMapping->getTriangleBaryCoords()[j][0]; + double fy = l_topologicalMapping->getTriangleBaryCoords()[j][1]; out[ triangles[i][0] ] += in[triangleMap[i][j]] * (1-fx-fy); out[ triangles[i][1] ] += in[triangleMap[i][j]] * fx; out[ triangles[i][2] ] += in[triangleMap[i][j]] * fy; @@ -333,8 +365,8 @@ void Mesh2PointMechanicalMapping::applyJT(const core::MechanicalParam for(unsigned int j = 0; j < quadMap[i].size(); ++j) { if (quadMap[i][j] == InvalidID) continue; - const double fx = topoMap->getQuadBaryCoords()[j][0]; - const double fy = topoMap->getQuadBaryCoords()[j][1]; + const double fx = l_topologicalMapping->getQuadBaryCoords()[j][0]; + const double fy = l_topologicalMapping->getQuadBaryCoords()[j][1]; out[ quads[i][0] ] += in[quadMap[i][j]] * ((1-fx) * (1-fy)); out[ quads[i][1] ] += in[quadMap[i][j]] * (( fx) * (1-fy)); out[ quads[i][2] ] += in[quadMap[i][j]] * ((1-fx) * ( fy)); @@ -347,9 +379,9 @@ void Mesh2PointMechanicalMapping::applyJT(const core::MechanicalParam for(unsigned int j = 0; j < tetraMap[i].size(); ++j) { if (tetraMap[i][j] == InvalidID) continue; - double fx = topoMap->getTetraBaryCoords()[j][0]; - double fy = topoMap->getTetraBaryCoords()[j][1]; - double fz = topoMap->getTetraBaryCoords()[j][2]; + double fx = l_topologicalMapping->getTetraBaryCoords()[j][0]; + double fy = l_topologicalMapping->getTetraBaryCoords()[j][1]; + double fz = l_topologicalMapping->getTetraBaryCoords()[j][2]; out[ tetrahedra[i][0] ] += in[tetraMap[i][j]] * (1-fx-fy-fz); out[ tetrahedra[i][1] ] += in[tetraMap[i][j]] * fx; out[ tetrahedra[i][2] ] += in[tetraMap[i][j]] * fy; @@ -362,9 +394,9 @@ void Mesh2PointMechanicalMapping::applyJT(const core::MechanicalParam for(unsigned int j = 0; j < hexaMap[i].size(); ++j) { if (hexaMap[i][j] == InvalidID) continue; - const double fx = topoMap->getHexaBaryCoords()[j][0]; - const double fy = topoMap->getHexaBaryCoords()[j][1]; - const double fz = topoMap->getHexaBaryCoords()[j][2]; + const double fx = l_topologicalMapping->getHexaBaryCoords()[j][0]; + const double fy = l_topologicalMapping->getHexaBaryCoords()[j][1]; + const double fz = l_topologicalMapping->getHexaBaryCoords()[j][2]; out[ hexahedra[i][0] ] += in[hexaMap[i][j]] * ((1-fx) * (1-fy) * (1-fz)); out[ hexahedra[i][1] ] += in[hexaMap[i][j]] * (( fx) * (1-fy) * (1-fz)); out[ hexahedra[i][3] ] += in[hexaMap[i][j]] * ((1-fx) * ( fy) * (1-fz)); @@ -381,10 +413,10 @@ void Mesh2PointMechanicalMapping::applyJT(const core::MechanicalParam template void Mesh2PointMechanicalMapping::applyJT(const core::ConstraintParams * /*cparams*/, Data& dOut, const Data& dIn) { - if (!topoMap) + if (!l_topologicalMapping) return; - const sofa::type::vector< std::pair< Mesh2PointTopologicalMapping::Element, sofa::Index> >& pointSource = topoMap->getPointSource(); + const sofa::type::vector< std::pair< Mesh2PointTopologicalMapping::Element, sofa::Index> >& pointSource = l_topologicalMapping->getPointSource(); if (pointSource.empty()) return; @@ -392,11 +424,11 @@ void Mesh2PointMechanicalMapping::applyJT(const core::ConstraintParam InMatrixDeriv& out = *dOut.beginEdit(); const OutMatrixDeriv& in = dIn.getValue(); - const core::topology::BaseMeshTopology::SeqEdges& edges = inputTopo->getEdges(); - const core::topology::BaseMeshTopology::SeqTriangles& triangles = inputTopo->getTriangles(); - const core::topology::BaseMeshTopology::SeqQuads& quads = inputTopo->getQuads(); - const core::topology::BaseMeshTopology::SeqTetrahedra& tetrahedra = inputTopo->getTetrahedra(); - const core::topology::BaseMeshTopology::SeqHexahedra& hexahedra = inputTopo->getHexahedra(); + const core::topology::BaseMeshTopology::SeqEdges& edges = l_inputTopology->getEdges(); + const core::topology::BaseMeshTopology::SeqTriangles& triangles = l_inputTopology->getTriangles(); + const core::topology::BaseMeshTopology::SeqQuads& quads = l_inputTopology->getQuads(); + const core::topology::BaseMeshTopology::SeqTetrahedra& tetrahedra = l_inputTopology->getTetrahedra(); + const core::topology::BaseMeshTopology::SeqHexahedra& hexahedra = l_inputTopology->getHexahedra(); typename Out::MatrixDeriv::RowConstIterator rowItEnd = in.end(); @@ -432,19 +464,19 @@ void Mesh2PointMechanicalMapping::applyJT(const core::ConstraintParam double fx = 0; - if (topoMap->getEdgeBaryCoords().size() == 1) + if (l_topologicalMapping->getEdgeBaryCoords().size() == 1) { - fx = topoMap->getEdgeBaryCoords()[0][0]; + fx = l_topologicalMapping->getEdgeBaryCoords()[0][0]; } else { - const auto& edgeMap = topoMap->getPointsMappedFromEdge(); + const auto& edgeMap = l_topologicalMapping->getPointsMappedFromEdge(); bool err = true; for(Size i = 0; i < edgeMap[source.second].size(); ++i) { if (edgeMap[source.second][i] == indexIn) { - fx = topoMap->getEdgeBaryCoords()[i][0]; + fx = l_topologicalMapping->getEdgeBaryCoords()[i][0]; err = false; break; } @@ -468,21 +500,21 @@ void Mesh2PointMechanicalMapping::applyJT(const core::ConstraintParam double fx = 0; double fy = 0; - if (topoMap->getTriangleBaryCoords().size() == 1) + if (l_topologicalMapping->getTriangleBaryCoords().size() == 1) { - fx = topoMap->getTriangleBaryCoords()[0][0]; - fy = topoMap->getTriangleBaryCoords()[0][1]; + fx = l_topologicalMapping->getTriangleBaryCoords()[0][0]; + fy = l_topologicalMapping->getTriangleBaryCoords()[0][1]; } else { - const auto& triangleMap = topoMap->getPointsMappedFromTriangle(); + const auto& triangleMap = l_topologicalMapping->getPointsMappedFromTriangle(); bool err = true; for(Size i = 0; i < triangleMap[source.second].size(); ++i) { if (triangleMap[source.second][i] == indexIn) { - fx = topoMap->getTriangleBaryCoords()[i][0]; - fy = topoMap->getTriangleBaryCoords()[i][1]; + fx = l_topologicalMapping->getTriangleBaryCoords()[i][0]; + fy = l_topologicalMapping->getTriangleBaryCoords()[i][1]; err = false; break; } @@ -507,21 +539,21 @@ void Mesh2PointMechanicalMapping::applyJT(const core::ConstraintParam double fx = 0; double fy = 0; - if (topoMap->getQuadBaryCoords().size() == 1) + if (l_topologicalMapping->getQuadBaryCoords().size() == 1) { - fx = topoMap->getQuadBaryCoords()[0][0]; - fy = topoMap->getQuadBaryCoords()[0][1]; + fx = l_topologicalMapping->getQuadBaryCoords()[0][0]; + fy = l_topologicalMapping->getQuadBaryCoords()[0][1]; } else { - const auto& quadMap = topoMap->getPointsMappedFromQuad(); + const auto& quadMap = l_topologicalMapping->getPointsMappedFromQuad(); bool err = true; for(Size i = 0; i < quadMap[source.second].size(); ++i) { if (quadMap[source.second][i] == indexIn) { - fx = topoMap->getQuadBaryCoords()[i][0]; - fy = topoMap->getQuadBaryCoords()[i][1]; + fx = l_topologicalMapping->getQuadBaryCoords()[i][0]; + fy = l_topologicalMapping->getQuadBaryCoords()[i][1]; err = false; break; } @@ -548,23 +580,23 @@ void Mesh2PointMechanicalMapping::applyJT(const core::ConstraintParam double fy = 0; double fz = 0; - if (topoMap->getTetraBaryCoords().size() == 1) + if (l_topologicalMapping->getTetraBaryCoords().size() == 1) { - fx = topoMap->getTetraBaryCoords()[0][0]; - fy = topoMap->getTetraBaryCoords()[0][1]; - fz = topoMap->getTetraBaryCoords()[0][2]; + fx = l_topologicalMapping->getTetraBaryCoords()[0][0]; + fy = l_topologicalMapping->getTetraBaryCoords()[0][1]; + fz = l_topologicalMapping->getTetraBaryCoords()[0][2]; } else { - const auto& tetraMap = topoMap->getPointsMappedFromTetra(); + const auto& tetraMap = l_topologicalMapping->getPointsMappedFromTetra(); bool err = true; for(Size i = 0; i < tetraMap[source.second].size(); ++i) { if (tetraMap[source.second][i] == indexIn) { - fx = topoMap->getTetraBaryCoords()[i][0]; - fy = topoMap->getTetraBaryCoords()[i][1]; - fz = topoMap->getTetraBaryCoords()[i][2]; + fx = l_topologicalMapping->getTetraBaryCoords()[i][0]; + fy = l_topologicalMapping->getTetraBaryCoords()[i][1]; + fz = l_topologicalMapping->getTetraBaryCoords()[i][2]; err = false; break; } @@ -590,23 +622,23 @@ void Mesh2PointMechanicalMapping::applyJT(const core::ConstraintParam double fx = 0; double fy = 0; double fz = 0; - if (topoMap->getHexaBaryCoords().size() == 1) + if (l_topologicalMapping->getHexaBaryCoords().size() == 1) { - fx = topoMap->getHexaBaryCoords()[0][0]; - fy = topoMap->getHexaBaryCoords()[0][1]; - fz = topoMap->getHexaBaryCoords()[0][2]; + fx = l_topologicalMapping->getHexaBaryCoords()[0][0]; + fy = l_topologicalMapping->getHexaBaryCoords()[0][1]; + fz = l_topologicalMapping->getHexaBaryCoords()[0][2]; } else { - const auto& hexaMap = topoMap->getPointsMappedFromHexa(); + const auto& hexaMap = l_topologicalMapping->getPointsMappedFromHexa(); bool err = true; for(Size i = 0; i < hexaMap[source.second].size(); ++i) { if (hexaMap[source.second][i] == indexIn) { - fx = topoMap->getHexaBaryCoords()[i][0]; - fy = topoMap->getHexaBaryCoords()[i][1]; - fz = topoMap->getHexaBaryCoords()[i][2]; + fx = l_topologicalMapping->getHexaBaryCoords()[i][0]; + fy = l_topologicalMapping->getHexaBaryCoords()[i][1]; + fz = l_topologicalMapping->getHexaBaryCoords()[i][2]; err = false; break; } From e0fc1a94e029645c32c8fad098aef6457cba3fa8 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Wed, 25 Sep 2024 17:05:35 +0900 Subject: [PATCH 02/43] [Config] Use cmake-generator-expression to set cxx and c flags (#4990) use generator to set cxx and c flags specifically Co-authored-by: Hugo Co-authored-by: erik pernod --- Sofa/framework/Config/CMakeLists.txt | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Sofa/framework/Config/CMakeLists.txt b/Sofa/framework/Config/CMakeLists.txt index fffe07ef454..91202e1a826 100644 --- a/Sofa/framework/Config/CMakeLists.txt +++ b/Sofa/framework/Config/CMakeLists.txt @@ -296,13 +296,22 @@ set_target_properties(${PROJECT_NAME} PROPERTIES MAP_IMPORTED_CONFIG_MINSIZEREL Release MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release ) -target_compile_options(${PROJECT_NAME} PUBLIC "$<$:${SOFACONFIG_COMPILE_OPTIONS_RELEASE}>") -target_compile_options(${PROJECT_NAME} PUBLIC "$<$:${SOFACONFIG_COMPILE_OPTIONS_DEBUG}>") -target_compile_options(${PROJECT_NAME} PUBLIC "${SOFACONFIG_COMPILE_OPTIONS}") -target_link_options(${PROJECT_NAME} PUBLIC "$<$:${SOFACONFIG_LINK_OPTIONS_RELEASE}>") -target_link_options(${PROJECT_NAME} PUBLIC "$<$:${SOFACONFIG_LINK_OPTIONS_DEBUG}>") -target_link_options(${PROJECT_NAME} PUBLIC "${SOFACONFIG_LINK_OPTIONS}") +set(is_cxx "$") +set(is_c "$") +set(is_c_cxx "$") +set(is_release "$") +set(is_debug "$") +set(is_c_cxx_release "$") +set(is_c_cxx_debug "$") + +target_compile_options(${PROJECT_NAME} PUBLIC "$<${is_c_cxx_release}:${SOFACONFIG_COMPILE_OPTIONS_RELEASE}>") +target_compile_options(${PROJECT_NAME} PUBLIC "$<${is_c_cxx_debug}:${SOFACONFIG_COMPILE_OPTIONS_DEBUG}>") +target_compile_options(${PROJECT_NAME} PUBLIC "$<${is_c_cxx}:${SOFACONFIG_COMPILE_OPTIONS}>") + +target_link_options(${PROJECT_NAME} PUBLIC "$<${is_c_cxx_release}:${SOFACONFIG_LINK_OPTIONS_RELEASE}>") +target_link_options(${PROJECT_NAME} PUBLIC "$<${is_c_cxx_debug}:${SOFACONFIG_LINK_OPTIONS_DEBUG}>") +target_link_options(${PROJECT_NAME} PUBLIC "$<${is_c_cxx}:${SOFACONFIG_LINK_OPTIONS}>") set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER Sofa.Framework) # IDE folder From 61badbe133d9249c68f2c1b81cfe8b13efa077c6 Mon Sep 17 00:00:00 2001 From: Damien Marchal Date: Wed, 25 Sep 2024 11:05:54 +0200 Subject: [PATCH 03/43] [FrameSpringForceField] Fix invalid data field's name (#5002) Fix invalid data field's name. --- .../component/solidmechanics/spring/FrameSpringForceField.inl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FrameSpringForceField.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FrameSpringForceField.inl index facc16cf0d9..0907c65f3fc 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FrameSpringForceField.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FrameSpringForceField.inl @@ -43,8 +43,8 @@ template FrameSpringForceField::FrameSpringForceField ( MechanicalState* object1, MechanicalState* object2 ) : Inherit ( object1, object2 ) , d_springs (initData (&d_springs, "spring", "pairs of indices, stiffness, damping, rest length" ) ) - , d_showLawfulTorsion (initData (&d_showLawfulTorsion, false, "show lawful Torsion", "dislpay the lawful part of the joint rotation" ) ) - , d_showExtraTorsion (initData (&d_showExtraTorsion, false, "show illicit Torsion", "dislpay the illicit part of the joint rotation" ) ) + , d_showLawfulTorsion (initData (&d_showLawfulTorsion, false, "showLawfulTorsion", "display the lawful part of the joint rotation" ) ) + , d_showExtraTorsion (initData (&d_showExtraTorsion, false, "showExtraTorsion", "display the illicit part of the joint rotation" ) ) { springs.setOriginalData(&d_springs); showLawfulTorsion.setOriginalData(&d_showLawfulTorsion); From ebc215c504849fc41f8bf0314bbd0dfeaf3d5857 Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Wed, 25 Sep 2024 18:21:26 +0200 Subject: [PATCH 04/43] [DefaultType] Fix RigidDeriv name (#5015) * [DefaultType] Fix RigidDeriv name * Reorder files --- .../src/sofa/defaulttype/RigidDeriv.h | 12 +++++- .../framework/DefaultType/test/CMakeLists.txt | 5 ++- .../DefaultType/test/RigidDeriv_test.cpp | 41 +++++++++++++++++++ 3 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 Sofa/framework/DefaultType/test/RigidDeriv_test.cpp diff --git a/Sofa/framework/DefaultType/src/sofa/defaulttype/RigidDeriv.h b/Sofa/framework/DefaultType/src/sofa/defaulttype/RigidDeriv.h index 98d6d78c98c..8e40f865a84 100644 --- a/Sofa/framework/DefaultType/src/sofa/defaulttype/RigidDeriv.h +++ b/Sofa/framework/DefaultType/src/sofa/defaulttype/RigidDeriv.h @@ -613,7 +613,15 @@ namespace sofa::linearalgebra subBlock = b[col]; } - static sofa::linearalgebra::BaseMatrix::ElementType getElementType() { return matrix_bloc_traits::getElementType(); } - static const char* Name() { return defaulttype::DataTypeName>::name(); } + static sofa::linearalgebra::BaseMatrix::ElementType getElementType() + { + return matrix_bloc_traits::getElementType(); + } + + static const char* Name() + { + static std::string name = defaulttype::DataTypeName >::name(); + return name.c_str(); + } }; } diff --git a/Sofa/framework/DefaultType/test/CMakeLists.txt b/Sofa/framework/DefaultType/test/CMakeLists.txt index 395920f8665..3cd10b20cfc 100644 --- a/Sofa/framework/DefaultType/test/CMakeLists.txt +++ b/Sofa/framework/DefaultType/test/CMakeLists.txt @@ -9,11 +9,12 @@ set(HEADER_FILES set(SOURCE_FILES MapMapSparseMatrixEigenUtils_test.cpp - TypeInfo_test.cpp + QuaternionIntegration_test.cpp + RigidDeriv_test.cpp TypeInfoRepository_test.cpp TypeInfoRepository_tu1_test.cpp + TypeInfo_test.cpp TypeInfoRepository_tu2_test.cpp - QuaternionIntegration_test.cpp ) add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${HEADER_FILES}) diff --git a/Sofa/framework/DefaultType/test/RigidDeriv_test.cpp b/Sofa/framework/DefaultType/test/RigidDeriv_test.cpp new file mode 100644 index 00000000000..bdc6fad05fc --- /dev/null +++ b/Sofa/framework/DefaultType/test/RigidDeriv_test.cpp @@ -0,0 +1,41 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture * +* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#include +#include +#include + +template +void testName(const std::string& expectedName) +{ + using Deriv = sofa::defaulttype::RigidDeriv; + using Bloc = sofa::linearalgebra::matrix_bloc_traits; + EXPECT_EQ(std::string(Bloc::Name()), expectedName); +} + +TEST(RigidDerivTest, Name) +{ + testName<3, float>("RigidDeriv3f"); + testName<3, double>("RigidDeriv3d"); + + testName<2, float>("RigidDeriv2f"); + testName<2, double>("RigidDeriv2d"); +} From 55f303fe4ec1a68c4f3861fac257063072e85eeb Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Thu, 26 Sep 2024 03:00:22 +0200 Subject: [PATCH 05/43] [LinearAlgebra] Rename class MatrixSubstraction to MatrixSubtraction (#5016) * [LinearAlgebra] Rename class MatrixSubstraction to MatrixSubtraction * fix compilation --- .../src/sofa/linearalgebra/MatrixExpr.h | 19 +++++++++++-------- .../src/sofa/linearalgebra/config.h.in | 10 ++++++++++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/MatrixExpr.h b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/MatrixExpr.h index bc828e0c30c..ddd75dc4aa4 100644 --- a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/MatrixExpr.h +++ b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/MatrixExpr.h @@ -34,7 +34,7 @@ template class MatrixAddition; template -class MatrixSubstraction; +class MatrixSubtraction; template class MatrixTranspose; @@ -66,9 +66,9 @@ class MatrixExpr : public T return MatrixExpr { MatrixAddition< Expr, typename M2::Expr >(*this, m) }; } template - MatrixExpr< MatrixSubstraction< Expr, typename M2::Expr > > operator-(const M2& m) const + MatrixExpr< MatrixSubtraction< Expr, typename M2::Expr > > operator-(const M2& m) const { - return MatrixExpr { MatrixSubstraction< Expr, typename M2::Expr >(*this, m) }; + return MatrixExpr { MatrixSubtraction< Expr, typename M2::Expr >(*this, m) }; } MatrixExpr< MatrixNegative< Expr > > operator-() const { @@ -98,9 +98,9 @@ class MatrixExpr : public T return MatrixExpr { MatrixAddition< typename M1::Expr, Expr >(m1,m2) }; } template - friend MatrixExpr< MatrixSubstraction< typename M1::Expr, Expr > > operator-(const M1& m1, const MatrixExpr& m2) + friend MatrixExpr< MatrixSubtraction< typename M1::Expr, Expr > > operator-(const M1& m1, const MatrixExpr& m2) { - return MatrixExpr { MatrixSubstraction< typename M1::Expr, Expr >(m1,m2) }; + return MatrixExpr { MatrixSubtraction< typename M1::Expr, Expr >(m1,m2) }; } }; @@ -442,10 +442,10 @@ class MatrixAddition }; template -class MatrixSubstraction +class MatrixSubtraction { public: - typedef MatrixSubstraction Expr; + typedef MatrixSubtraction Expr; enum { operand = 0 }; enum { category = ((int)M1::category>(int)M2::category) ? (int)M1::category : (int)M2::category }; enum { m_index = (((int)M1::category>(int)M2::category)?0:1) }; @@ -453,7 +453,7 @@ class MatrixSubstraction const M1& m1; const M2& m2; - MatrixSubstraction(const M1& m1, const M2& m2) : m1(m1), m2(m2) + MatrixSubtraction(const M1& m1, const M2& m2) : m1(m1), m2(m2) {} bool valid() const @@ -502,6 +502,9 @@ class MatrixSubstraction } }; +template +using MatrixSubstraction SOFA_ATTRIBUTE_DEPRECATED__MATRIXSUBTRACTION() = MatrixSubtraction; + template class MatrixProduct { diff --git a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/config.h.in b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/config.h.in index 5fdb2f7abbb..485f2ec960a 100644 --- a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/config.h.in +++ b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/config.h.in @@ -59,3 +59,13 @@ "v23.06", "v23.12", \ "bloc has been renamed to block. ") #endif // SOFA_BUILD_SOFA_LINEARALGEBRA + + +#ifdef SOFA_BUILD_SOFA_LINEARALGEBRA +#define SOFA_ATTRIBUTE_DEPRECATED__MATRIXSUBTRACTION() +#else +#define SOFA_ATTRIBUTE_DEPRECATED__MATRIXSUBTRACTION() \ + SOFA_ATTRIBUTE_DEPRECATED( \ + "v24.12", "v25.06", \ + "Use MatrixSubtraction instead (typo in the deprecated name).") +#endif // SOFA_BUILD_SOFA_LINEARALGEBRA From ede696a054f7d753de9874b675d3ad47c1df29e5 Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Mon, 30 Sep 2024 08:13:40 +0200 Subject: [PATCH 06/43] [Core] Move DevBaseMonitor in SofaValidation (#4985) Move DevBaseMonitor into SofaValidation --- .../Core/src/sofa/core/DevBaseMonitor.h | 34 +++---------------- Sofa/framework/Core/src/sofa/core/fwd.h | 1 - .../Core/src/sofa/core/objectmodel/Base.h | 1 - 3 files changed, 4 insertions(+), 32 deletions(-) diff --git a/Sofa/framework/Core/src/sofa/core/DevBaseMonitor.h b/Sofa/framework/Core/src/sofa/core/DevBaseMonitor.h index e5981d58c7a..19c11bd7657 100644 --- a/Sofa/framework/Core/src/sofa/core/DevBaseMonitor.h +++ b/Sofa/framework/Core/src/sofa/core/DevBaseMonitor.h @@ -19,35 +19,9 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ +#pragma once -#ifndef SOFA_CORE_DEVBASEMONITOR_H -#define SOFA_CORE_DEVBASEMONITOR_H +#include -#include - - -namespace sofa::core -{ - -/** - * \brief A basic interface to define a Monitor capable to compute metrics. - * - * - * - */ -class DevBaseMonitor : public virtual objectmodel::BaseObject -{ -public: - SOFA_CLASS(DevBaseMonitor, objectmodel::BaseObject); - SOFA_BASE_CAST_IMPLEMENTATION(DevBaseMonitor) - - /// Destructor - ~DevBaseMonitor() override {} - /// Compute metrics - virtual void eval() = 0; -}; - -} // namespace sofa::core - - -#endif //SOFA_CORE_DEVBASEMONITOR_H +//header moved in the plugin SofaValidation +SOFA_HEADER_DEPRECATED("v24.12", "v25.12", "SofaValidation/DevBaseMonitor.h") diff --git a/Sofa/framework/Core/src/sofa/core/fwd.h b/Sofa/framework/Core/src/sofa/core/fwd.h index 7eabd941f1f..69e738489a1 100644 --- a/Sofa/framework/Core/src/sofa/core/fwd.h +++ b/Sofa/framework/Core/src/sofa/core/fwd.h @@ -37,7 +37,6 @@ class BehaviorModel; class CollisionModel; class CollisionElementIterator; class DataEngine; -class DevBaseMonitor; class ExecParams; class ConstraintParams; diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/Base.h b/Sofa/framework/Core/src/sofa/core/objectmodel/Base.h index 5aa1709efbf..4e0fcafb84b 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/Base.h +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/Base.h @@ -421,7 +421,6 @@ class SOFA_CORE_API Base SOFA_BASE_CAST_DEFINITION( core, BehaviorModel ) SOFA_BASE_CAST_DEFINITION( core, CollisionModel ) SOFA_BASE_CAST_DEFINITION( core, DataEngine ) - SOFA_BASE_CAST_DEFINITION( core, DevBaseMonitor ) SOFA_BASE_CAST_DEFINITION( objectmodel, BaseContext ) SOFA_BASE_CAST_DEFINITION( objectmodel, BaseObject ) SOFA_BASE_CAST_DEFINITION( objectmodel, BaseNode ) From 465246fbe7ccc788bb1ae2f27463659cd688045d Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Wed, 2 Oct 2024 01:03:16 +0200 Subject: [PATCH 07/43] [Mapping.NonLinear] A base class for (almost) all non linear mappings (#5006) * Introduce base class for non-linear mappings * refactor DistanceFromTargetMapping * refactor DistanceMapping * refactor SquareDistanceMapping * refactor SquareMapping * delegate on updateK * K can be private * factorize baseMatrix * baseMatrices can be private * rename base class * rename files * fix * second fix * unused variables * rename private members * change protected member --- .../Mapping/NonLinear/CMakeLists.txt | 2 + .../component/mapping/nonlinear/AreaMapping.h | 48 ++--- .../mapping/nonlinear/AreaMapping.inl | 158 +++++---------- .../mapping/nonlinear/BaseNonLinearMapping.h | 97 ++++++++++ .../nonlinear/BaseNonLinearMapping.inl | 144 ++++++++++++++ .../nonlinear/DistanceFromTargetMapping.h | 65 +++---- .../nonlinear/DistanceFromTargetMapping.inl | 148 +++++--------- .../mapping/nonlinear/DistanceMapping.h | 73 +++---- .../mapping/nonlinear/DistanceMapping.inl | 182 ++++++------------ .../mapping/nonlinear/SquareDistanceMapping.h | 75 +++----- .../nonlinear/SquareDistanceMapping.inl | 174 ++++++----------- .../mapping/nonlinear/SquareMapping.h | 78 +++----- .../mapping/nonlinear/SquareMapping.inl | 149 +++----------- .../mapping/nonlinear/VolumeMapping.h | 48 ++--- .../mapping/nonlinear/VolumeMapping.inl | 156 +++++---------- .../NonLinear/tests/AreaMapping_test.cpp | 1 - .../NonLinear/tests/SquareMapping_test.cpp | 10 - .../NonLinear/tests/VolumeMapping_test.cpp | 1 - ...essedRowSparseMatrixConstraintEigenUtils.h | 1 + 19 files changed, 651 insertions(+), 959 deletions(-) create mode 100644 Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/BaseNonLinearMapping.h create mode 100644 Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/BaseNonLinearMapping.inl diff --git a/Sofa/Component/Mapping/NonLinear/CMakeLists.txt b/Sofa/Component/Mapping/NonLinear/CMakeLists.txt index c5f5548c6ed..d97638d9c41 100644 --- a/Sofa/Component/Mapping/NonLinear/CMakeLists.txt +++ b/Sofa/Component/Mapping/NonLinear/CMakeLists.txt @@ -8,6 +8,8 @@ set(HEADER_FILES ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/init.h ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/AreaMapping.h ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/AreaMapping.inl + ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/BaseNonLinearMapping.h + ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/BaseNonLinearMapping.inl ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/DistanceFromTargetMapping.h ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/DistanceFromTargetMapping.inl ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/DistanceMapping.h diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/AreaMapping.h b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/AreaMapping.h index 91f9cee3fc3..3554709407c 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/AreaMapping.h +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/AreaMapping.h @@ -22,7 +22,7 @@ #pragma once #include -#include +#include #include #include #include @@ -32,17 +32,16 @@ namespace sofa::component::mapping::nonlinear { template -class AreaMapping : public core::Mapping, public StabilizedNonLinearMappingData +class AreaMapping : public BaseNonLinearMapping { public: - SOFA_CLASS(SOFA_TEMPLATE2(AreaMapping,TIn,TOut), SOFA_TEMPLATE2(core::Mapping,TIn,TOut)); + SOFA_CLASS(SOFA_TEMPLATE2(AreaMapping,TIn,TOut), SOFA_TEMPLATE3(BaseNonLinearMapping,TIn,TOut, true)); using In = TIn; using Out = TOut; using Real = Real_t; - typedef linearalgebra::EigenSparseMatrix SparseMatrixEigen; static constexpr auto Nin = In::deriv_total_size; SingleLink, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology; @@ -52,44 +51,25 @@ class AreaMapping : public core::Mapping, public StabilizedNonLinearM void init() override; void apply(const core::MechanicalParams* mparams, DataVecCoord_t& out, const DataVecCoord_t& in) override; - void applyJ(const core::MechanicalParams* mparams, DataVecDeriv_t& out, const DataVecDeriv_t& in) override; - void applyJT(const core::MechanicalParams* mparams, DataVecDeriv_t& out, const DataVecDeriv_t& in) override; - void applyJT(const core::ConstraintParams *cparams, DataMatrixDeriv_t& out, const DataMatrixDeriv_t& in) override; - void applyDJT(const core::MechanicalParams* mparams, core::MultiVecDerivId parentForceId, core::ConstMultiVecDerivId childForceId) override; - - void updateK( const core::MechanicalParams* mparams, core::ConstMultiVecDerivId childForceId) override; - const linearalgebra::BaseMatrix* getK() override; void buildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) override; - const type::vector* getJs() override; - protected: AreaMapping(); - using SparseKMatrixEigen = linearalgebra::EigenSparseMatrix; - - SparseMatrixEigen jacobian; ///< Jacobian of the mapping - type::vector baseMatrices; ///< Jacobian of the mapping, in a vector - typename AreaMapping::SparseKMatrixEigen K; ///< Assembled geometric stiffness matrix - - /** - * @brief Represents an entry in the Jacobian matrix. - * - * The JacobianEntry struct is used to store information about an entry in the - * Jacobian matrix, specifically the vertex identifier and the corresponding - * Jacobian value. It also provides a comparison operator for sorting entries - * by vertex ID. - */ - struct JacobianEntry - { - sofa::Index vertexId; - typename In::Coord jacobianValue; - bool operator<(const JacobianEntry& other) const { return vertexId < other.vertexId;} - }; + void matrixFreeApplyDJT(const core::MechanicalParams* mparams, Real kFactor, + Data >& parentForce, + const Data >& parentDisplacement, + const Data >& childForce) override; - const VecCoord_t* m_vertices{nullptr}; + using typename Inherit1::SparseKMatrixEigen; + void doUpdateK( + const core::MechanicalParams* mparams, const Data >& childForce, + SparseKMatrixEigen& matrix) override; + + const VecCoord_t* m_vertices{nullptr}; + using JacobianEntry = typename Inherit1::JacobianEntry; }; #if !defined(SOFA_COMPONENT_MAPPING_NONLINEAR_AREAMAPPING_CPP) diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/AreaMapping.inl b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/AreaMapping.inl index 88d62ca8b5d..5b856d8b7ee 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/AreaMapping.inl +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/AreaMapping.inl @@ -21,8 +21,8 @@ ******************************************************************************/ #pragma once #include +#include #include -#include namespace sofa::component::mapping::nonlinear { @@ -123,10 +123,7 @@ void AreaMapping::init() typename core::behavior::MechanicalState::ReadVecCoord pos = this->getFromModel()->readPositions(); this->getToModel()->resize( nbTriangles ); - jacobian.resizeBlocks(nbTriangles, pos.size()); - - baseMatrices.resize( 1 ); - baseMatrices[0] = &jacobian; + this->m_jacobian.resizeBlocks(nbTriangles, pos.size()); Inherit1::init(); @@ -140,6 +137,8 @@ template void AreaMapping::apply(const core::MechanicalParams* mparams, DataVecCoord_t& out, const DataVecCoord_t& in) { + SOFA_UNUSED( mparams ); + helper::WriteOnlyAccessor< Data> > _out = out; helper::ReadAccessor< Data > > _in = in; @@ -147,7 +146,7 @@ void AreaMapping::apply(const core::MechanicalParams* mparams, const auto& triangles = l_topology->getTriangles(); - jacobian.clear(); + this->m_jacobian.clear(); for (unsigned int triangleId = 0; triangleId < triangles.size(); ++triangleId) { @@ -177,107 +176,60 @@ void AreaMapping::apply(const core::MechanicalParams* mparams, //insertion in increasing column order std::sort(jacobianEntries.begin(), jacobianEntries.end()); - jacobian.beginRow(triangleId); + this->m_jacobian.beginRow(triangleId); for (const auto& [vertexId, jacobianValue] : jacobianEntries) { for (unsigned d = 0; d < In::spatial_dimensions; ++d) { - jacobian.insertBack(triangleId, vertexId * Nin + d, jacobianValue[d]); + this->m_jacobian.insertBack(triangleId, vertexId * Nin + d, jacobianValue[d]); } } } - jacobian.compress(); -} - -template -void AreaMapping::applyJ(const core::MechanicalParams* mparams, - DataVecDeriv_t& out, const DataVecDeriv_t& in) -{ - if( jacobian.rowSize() ) - { - auto dOutWa = sofa::helper::getWriteOnlyAccessor(out); - auto dInRa = sofa::helper::getReadAccessor(in); - jacobian.mult(dOutWa.wref(),dInRa.ref()); - } -} - -template -void AreaMapping::applyJT(const core::MechanicalParams* mparams, - DataVecDeriv_t& out, const DataVecDeriv_t& in) -{ - if( jacobian.rowSize() ) - { - auto dOutRa = sofa::helper::getReadAccessor(in); - auto dInWa = sofa::helper::getWriteOnlyAccessor(out); - jacobian.addMultTranspose(dInWa.wref(),dOutRa.ref()); - } + this->m_jacobian.compress(); } template -void AreaMapping::applyJT(const core::ConstraintParams* cparams, - DataMatrixDeriv_t& out, const DataMatrixDeriv_t& in) +void AreaMapping::matrixFreeApplyDJT( + const core::MechanicalParams* mparams, Real kFactor, + Data>& parentForce, + const Data>& parentDisplacement, + const Data>& childForce) { - SOFA_UNUSED(cparams); - auto childMatRa = sofa::helper::getReadAccessor(in); - auto parentMatWa = sofa::helper::getWriteAccessor(out); - addMultTransposeEigen(parentMatWa.wref(), jacobian.compressedMatrix, childMatRa.ref()); -} + SOFA_UNUSED(mparams); + const unsigned geometricStiffness = this->d_geometricStiffness.getValue().getSelectedId(); -template -void AreaMapping::applyDJT(const core::MechanicalParams* mparams, - core::MultiVecDerivId parentForceId, core::ConstMultiVecDerivId childForceId) -{ - if (!m_vertices) - { - return; - } + helper::WriteAccessor parentForceAccessor(parentForce); + helper::ReadAccessor parentDisplacementAccessor(parentDisplacement); + helper::ReadAccessor childForceAccessor(childForce); - const unsigned geometricStiffness = d_geometricStiffness.getValue().getSelectedId(); - if( !geometricStiffness ) + const auto& triangles = l_topology->getTriangles(); + for (unsigned int triangleId = 0; triangleId < triangles.size(); ++triangleId) { - return; - } - - helper::WriteAccessor > > parentForceAccessor(*parentForceId[this->fromModel.get()].write()); - helper::ReadAccessor > > parentDisplacementAccessor(*mparams->readDx(this->fromModel.get())); - const SReal kFactor = mparams->kFactor(); - helper::ReadAccessor > > childForceAccessor(mparams->readF(this->toModel.get())); + const Deriv_t& childForceTri = childForceAccessor[triangleId]; - if( K.compressedMatrix.nonZeros() ) - { - K.addMult( parentForceAccessor.wref(), parentDisplacementAccessor.ref(), (typename In::Real)kFactor ); - } - else - { - const auto& triangles = l_topology->getTriangles(); - for (unsigned int triangleId = 0; triangleId < triangles.size(); ++triangleId) + if( childForceTri[0] < 0 || geometricStiffness==1 ) { - const Deriv_t& childForceTri = childForceAccessor[triangleId]; - - if( childForceTri[0] < 0 || geometricStiffness==1 ) - { - const auto& triangle = triangles[triangleId]; + const auto& triangle = triangles[triangleId]; - const sofa::type::fixed_array, 3> v{ - (*m_vertices)[triangle[0]], - (*m_vertices)[triangle[1]], - (*m_vertices)[triangle[2]] - }; + const sofa::type::fixed_array, 3> v{ + (*m_vertices)[triangle[0]], + (*m_vertices)[triangle[1]], + (*m_vertices)[triangle[2]] + }; - //it's a 3x3 matrix, where each entry is a 3x3 matrix - const auto d2Area_d2x = computeSecondDerivativeArea(v); + //it's a 3x3 matrix, where each entry is a 3x3 matrix + const auto d2Area_d2x = computeSecondDerivativeArea(v); - for (unsigned int i = 0; i < 3; ++i) + for (unsigned int i = 0; i < 3; ++i) + { + for (unsigned int j = 0; j < 3; ++j) { - for (unsigned int j = 0; j < 3; ++j) - { - parentForceAccessor[triangle[i]] += - kFactor - * d2Area_d2x[i][j] - * parentDisplacementAccessor[triangle[j]] - * childForceTri[0]; - } + parentForceAccessor[triangle[i]] += + kFactor + * d2Area_d2x[i][j] + * parentDisplacementAccessor[triangle[j]] + * childForceTri[0]; } } } @@ -285,24 +237,18 @@ void AreaMapping::applyDJT(const core::MechanicalParams* mparams, } template -void AreaMapping::updateK(const core::MechanicalParams* mparams, - core::ConstMultiVecDerivId childForceId) +void AreaMapping::doUpdateK(const core::MechanicalParams* mparams, + const Data>& childForce, SparseKMatrixEigen& matrix) { SOFA_UNUSED(mparams); - const unsigned geometricStiffness = d_geometricStiffness.getValue().getSelectedId(); - if( !geometricStiffness ) { K.resize(0,0); return; } + const unsigned geometricStiffness = this->d_geometricStiffness.getValue().getSelectedId(); - helper::ReadAccessor > > childForce( *childForceId[this->toModel.get()].read() ); - - { - unsigned int kSize = this->fromModel->getSize(); - K.resizeBlocks(kSize, kSize); - } + const helper::ReadAccessor childForceAccessor(childForce); const auto& triangles = l_topology->getTriangles(); for (unsigned int triangleId = 0; triangleId < triangles.size(); ++triangleId) { - const Deriv_t& childForceTri = childForce[triangleId]; + const Deriv_t& childForceTri = childForceAccessor[triangleId]; if( childForceTri[0] < 0 || geometricStiffness==1 ) { @@ -321,26 +267,18 @@ void AreaMapping::updateK(const core::MechanicalParams* mparams, { for (unsigned int j = 0; j < 3; ++j) { - K.addBlock(triangle[i], triangle[j], d2Area_d2x[i][j] * childForceTri[0]); + matrix.addBlock(triangle[i], triangle[j], d2Area_d2x[i][j] * childForceTri[0]); } } } } - - K.compress(); -} - -template -const linearalgebra::BaseMatrix* AreaMapping::getK() -{ - return &K; } template void AreaMapping::buildGeometricStiffnessMatrix( sofa::core::GeometricStiffnessMatrix* matrices) { - const unsigned& geometricStiffness = d_geometricStiffness.getValue().getSelectedId(); + const unsigned& geometricStiffness = this->d_geometricStiffness.getValue().getSelectedId(); if( !geometricStiffness ) { return; @@ -379,11 +317,5 @@ void AreaMapping::buildGeometricStiffnessMatrix( } -template -const type::vector* AreaMapping:: -getJs() -{ - return &baseMatrices; -} } diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/BaseNonLinearMapping.h b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/BaseNonLinearMapping.h new file mode 100644 index 00000000000..847c8628cdf --- /dev/null +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/BaseNonLinearMapping.h @@ -0,0 +1,97 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture * +* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once +#include +#include +#include +#include + + +namespace sofa::component::mapping::nonlinear +{ + +template +class BaseNonLinearMapping : public core::Mapping, public NonLinearMappingData +{ +public: + SOFA_CLASS( + SOFA_TEMPLATE3(BaseNonLinearMapping,TIn,TOut, HasStabilizedGeometricStiffness), + SOFA_TEMPLATE2(core::Mapping,TIn,TOut)); + + using In = TIn; + using Out = TOut; + + using Real = Real_t; + + typedef linearalgebra::EigenSparseMatrix SparseMatrixEigen; + static constexpr auto Nin = In::deriv_total_size; + + void init() override; + + void applyJ(const core::MechanicalParams* mparams, DataVecDeriv_t& out, const DataVecDeriv_t& in) final; + void applyJT(const core::MechanicalParams* mparams, DataVecDeriv_t& out, const DataVecDeriv_t& in) final; + void applyJT(const core::ConstraintParams *cparams, DataMatrixDeriv_t& out, const DataMatrixDeriv_t& in) final; + void applyDJT(const core::MechanicalParams* mparams, core::MultiVecDerivId parentForceId, core::ConstMultiVecDerivId childForceId) final; + + const linearalgebra::BaseMatrix* getK() final; + const type::vector* getJs() override; + + void updateK( const core::MechanicalParams* mparams, core::ConstMultiVecDerivId childForceId) final; + +protected: + + using SparseKMatrixEigen = linearalgebra::EigenSparseMatrix; + + virtual void matrixFreeApplyDJT(const core::MechanicalParams* mparams, + Real kFactor, + Data >& parentForce, + const Data >& parentDisplacement, + const Data >& childForce) = 0; + + SparseMatrixEigen m_jacobian; ///< Jacobian of the mapping + + virtual void doUpdateK( + const core::MechanicalParams* mparams, const Data >& childForce, + SparseKMatrixEigen& matrix) = 0; + + /** + * @brief Represents an entry in the Jacobian matrix. + * + * The JacobianEntry struct is used to store information about an entry in the + * Jacobian matrix, specifically the vertex identifier and the corresponding + * Jacobian value. It also provides a comparison operator for sorting entries + * by vertex ID. + */ + struct JacobianEntry + { + sofa::Index vertexId; + typename In::CPos jacobianValue; + bool operator<(const JacobianEntry& other) const { return vertexId < other.vertexId;} + }; + +private: + + SparseKMatrixEigen m_geometricStiffnessMatrix; ///< Assembled geometric stiffness matrix + type::vector m_baseMatrices; +}; + +} diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/BaseNonLinearMapping.inl b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/BaseNonLinearMapping.inl new file mode 100644 index 00000000000..742d3303e87 --- /dev/null +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/BaseNonLinearMapping.inl @@ -0,0 +1,144 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture * +* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include +#include + +namespace sofa::component::mapping::nonlinear +{ + +template +void BaseNonLinearMapping:: +init() +{ + core::Mapping::init(); + + m_baseMatrices.resize( 1 ); + m_baseMatrices[0] = &this->m_jacobian; +} + +template +void BaseNonLinearMapping::applyJ( + const core::MechanicalParams* mparams, DataVecDeriv_t& out, + const DataVecDeriv_t& in) +{ + SOFA_UNUSED( mparams ); + if( m_jacobian.rowSize() ) + { + auto dOutWa = sofa::helper::getWriteOnlyAccessor(out); + auto dInRa = sofa::helper::getReadAccessor(in); + m_jacobian.mult(dOutWa.wref(),dInRa.ref()); + } +} + +template +void BaseNonLinearMapping::applyJT( + const core::MechanicalParams* mparams, DataVecDeriv_t& out, + const DataVecDeriv_t& in) +{ + SOFA_UNUSED( mparams ); + if( m_jacobian.rowSize() ) + { + auto dOutRa = sofa::helper::getReadAccessor(in); + auto dInWa = sofa::helper::getWriteOnlyAccessor(out); + m_jacobian.addMultTranspose(dInWa.wref(),dOutRa.ref()); + } +} + +template +void BaseNonLinearMapping::applyJT( + const core::ConstraintParams* cparams, DataMatrixDeriv_t& out, + const DataMatrixDeriv_t& in) +{ + SOFA_UNUSED(cparams); + auto childMatRa = sofa::helper::getReadAccessor(in); + auto parentMatWa = sofa::helper::getWriteAccessor(out); + addMultTransposeEigen(parentMatWa.wref(), m_jacobian.compressedMatrix, childMatRa.ref()); +} + +template +void BaseNonLinearMapping::applyDJT( + const core::MechanicalParams* mparams, core::MultiVecDerivId parentForceId, + core::ConstMultiVecDerivId childForceId) +{ + SOFA_UNUSED(childForceId); + + const unsigned geometricStiffness = this->d_geometricStiffness.getValue().getSelectedId(); + if( !geometricStiffness ) + { + return; + } + + Data >& parentForce = *parentForceId[this->fromModel.get()].write(); + const Data >& parentDisplacement = *mparams->readDx(this->fromModel.get()); + + const SReal kFactor = mparams->kFactor(); + + if( m_geometricStiffnessMatrix.compressedMatrix.nonZeros() ) + { + helper::WriteAccessor parentForceAccessor(parentForce); + helper::ReadAccessor parentDisplacementAccessor(parentDisplacement); + m_geometricStiffnessMatrix.addMult( parentForceAccessor.wref(), parentDisplacementAccessor.ref(), static_cast(kFactor) ); + } + else + { + const Data >& childForce = *mparams->readF(this->toModel.get()); + + matrixFreeApplyDJT(mparams, static_cast(kFactor), + parentForce, parentDisplacement, childForce); + } +} + +template +const linearalgebra::BaseMatrix* BaseNonLinearMapping::getK() +{ + return &m_geometricStiffnessMatrix; +} + +template +const type::vector* BaseNonLinearMapping::getJs() +{ + return &m_baseMatrices; +} + +template +void BaseNonLinearMapping:: +updateK(const core::MechanicalParams* mparams, core::ConstMultiVecDerivId childForceId) +{ + const unsigned geometricStiffness = this->d_geometricStiffness.getValue().getSelectedId(); + if( !geometricStiffness ) { this->m_geometricStiffnessMatrix.resize(0,0); return; } + + const Data >& childForce = *childForceId[this->toModel.get()].read(); + + { + unsigned int kSize = this->fromModel->getSize(); + m_geometricStiffnessMatrix.resizeBlocks(kSize, kSize); + } + + doUpdateK(mparams, childForce, m_geometricStiffnessMatrix); + + m_geometricStiffnessMatrix.compress(); +} + + +} diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceFromTargetMapping.h b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceFromTargetMapping.h index 17942e099c5..9c226f13918 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceFromTargetMapping.h +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceFromTargetMapping.h @@ -22,8 +22,7 @@ #pragma once #include - -#include +#include #include #include #include @@ -61,28 +60,20 @@ struct BaseDistanceFromTargetMapping * @author Francois Faure */ template -class DistanceFromTargetMapping : public core::Mapping, public BaseDistanceFromTargetMapping, public NonLinearMappingData +class DistanceFromTargetMapping : public BaseNonLinearMapping, public BaseDistanceFromTargetMapping { public: - SOFA_CLASS(SOFA_TEMPLATE2(DistanceFromTargetMapping,TIn,TOut), SOFA_TEMPLATE2(core::Mapping,TIn,TOut)); - - typedef core::Mapping Inherit; - typedef TIn In; - typedef TOut Out; - typedef typename Out::VecCoord OutVecCoord; - typedef typename Out::VecDeriv OutVecDeriv; - typedef typename Out::Coord OutCoord; - typedef typename Out::Deriv OutDeriv; - typedef typename Out::MatrixDeriv OutMatrixDeriv; - typedef typename Out::Real Real; - typedef typename In::Deriv InDeriv; - typedef typename In::MatrixDeriv InMatrixDeriv; - typedef typename In::Coord InCoord; - typedef typename In::VecCoord InVecCoord; - typedef typename In::VecDeriv InVecDeriv; - typedef linearalgebra::EigenSparseMatrix SparseMatrixEigen; - typedef linearalgebra::EigenSparseMatrix SparseKMatrixEigen; - enum {Nin = In::deriv_total_size, Nout = Out::deriv_total_size }; + SOFA_CLASS(SOFA_TEMPLATE2(DistanceFromTargetMapping,TIn,TOut), SOFA_TEMPLATE3(BaseNonLinearMapping,TIn,TOut, true)); + + using In = TIn; + using Out = TOut; + using Real = Real_t; + static constexpr auto Nin = In::deriv_total_size; + static constexpr auto Nout = Out::deriv_total_size; + + using InCoord = Coord_t; + using InVecCoord = VecCoord_t; + typedef type::Vec Direction; SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA_IN_MAPPING_NONLINEAR() @@ -112,21 +103,7 @@ class DistanceFromTargetMapping : public core::Mapping, public BaseDi void init() override; - void apply(const core::MechanicalParams *mparams, Data& out, const Data& in) override; - - void applyJ(const core::MechanicalParams *mparams, Data& out, const Data& in) override; - - void applyJT(const core::MechanicalParams *mparams, Data& out, const Data& in) override; - - void applyJT(const core::ConstraintParams *cparams, Data& out, const Data& in) override; - - void applyDJT(const core::MechanicalParams* mparams, core::MultiVecDerivId parentForce, core::ConstMultiVecDerivId childForce ) override; - - const sofa::linearalgebra::BaseMatrix* getJ() override; - virtual const type::vector* getJs() override; - - void updateK( const core::MechanicalParams* mparams, core::ConstMultiVecDerivId childForce ) override; - const linearalgebra::BaseMatrix* getK() override; + void apply(const core::MechanicalParams *mparams, DataVecCoord_t& out, const DataVecCoord_t& in) override; void buildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) override; void draw(const core::visual::VisualParams* vparams) override; @@ -137,9 +114,17 @@ class DistanceFromTargetMapping : public core::Mapping, public BaseDi DistanceFromTargetMapping(); ~DistanceFromTargetMapping() override; - SparseMatrixEigen jacobian; ///< Jacobian of the mapping - type::vector baseMatrices; ///< Jacobian of the mapping, in a vector - SparseKMatrixEigen K; ///< Assembled geometric stiffness matrix + void matrixFreeApplyDJT(const core::MechanicalParams* mparams, Real kFactor, + Data >& parentForce, + const Data >& parentDisplacement, + const Data >& childForce) override; + + using typename Inherit1::SparseKMatrixEigen; + + void doUpdateK( + const core::MechanicalParams* mparams, const Data >& childForce, + SparseKMatrixEigen& matrix) override; + type::vector directions; ///< Unit vectors in the directions of the lines type::vector< Real > invlengths; ///< inverse of current distances. Null represents the infinity (null distance) diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceFromTargetMapping.inl b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceFromTargetMapping.inl index 79225a2b2c9..c350fdf6a0d 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceFromTargetMapping.inl +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceFromTargetMapping.inl @@ -22,6 +22,7 @@ #pragma once #include +#include #include #include #include @@ -35,12 +36,11 @@ namespace sofa::component::mapping::nonlinear template DistanceFromTargetMapping::DistanceFromTargetMapping() - : Inherit() - , d_indices(initData(&d_indices, "indices", "Indices of the parent points")) + : d_indices(initData(&d_indices, "indices", "Indices of the parent points")) , d_targetPositions(initData(&d_targetPositions, "targetPositions", "Positions to compute the distances from")) , d_restDistances(initData(&d_restDistances, "restLengths", "Rest lengths of the connections")) , d_showObjectScale(initData(&d_showObjectScale, 0.f, "showObjectScale", "Scale for object display")) - , d_color(initData(&d_color, sofa::type::RGBAColor(1,1,0,1), "showColor", "Color for object display. (default=[1.0,1.0,0.0,1.0])")) + , d_color(initData(&d_color, sofa::type::RGBAColor::yellow(), "showColor", "Color for object display.")) { f_indices.setOriginalData(&d_indices); f_targetPositions.setOriginalData(&d_targetPositions); @@ -118,11 +118,7 @@ void DistanceFromTargetMapping::init() this->getToModel()->resize(d_indices.getValue().size() ); - - baseMatrices.resize( 1 ); - baseMatrices[0] = &jacobian; - - this->Inherit::init(); // applies the mapping, so after the Data init + Inherit1::init(); // applies the mapping, so after the Data init } template @@ -132,15 +128,16 @@ void DistanceFromTargetMapping::computeCoordPositionDifference( Direc } template -void DistanceFromTargetMapping::apply(const core::MechanicalParams * /*mparams*/ , Data& dOut, const Data& dIn) +void DistanceFromTargetMapping::apply(const core::MechanicalParams * /*mparams*/ , DataVecCoord_t& dOut, const DataVecCoord_t& dIn) { - helper::WriteAccessor< Data > out = dOut; - helper::ReadAccessor< Data > in = dIn; - helper::WriteAccessor > > restDistances(d_restDistances); - const helper::ReadAccessor< Data > > indices(d_indices); - helper::ReadAccessor< Data > targetPositions(d_targetPositions); + helper::WriteAccessor out(dOut); + helper::WriteAccessor restDistances(d_restDistances); + + const helper::ReadAccessor in(dIn); + const helper::ReadAccessor indices(d_indices); + const helper::ReadAccessor targetPositions(d_targetPositions); - jacobian.resizeBlocks(out.size(),in.size()); + this->m_jacobian.resizeBlocks(out.size(),in.size()); directions.resize(out.size()); invlengths.resize(out.size()); @@ -169,70 +166,38 @@ void DistanceFromTargetMapping::apply(const core::MechanicalParams * for(unsigned j=0; jm_jacobian.beginRow(i*Nout+j); for(unsigned k=0; km_jacobian.insertBack( i*Nout+j, indices[i]*Nin+k, gap[k] ); } } } - jacobian.compress(); + this->m_jacobian.compress(); } - - template -void DistanceFromTargetMapping::applyJ(const core::MechanicalParams * /*mparams*/ , Data& dOut, const Data& dIn) +void DistanceFromTargetMapping::matrixFreeApplyDJT( + const core::MechanicalParams* mparams, Real kFactor, + Data>& parentForce, + const Data>& parentDisplacement, + const Data>& childForce) { - if( jacobian.rowSize() > 0 ) - { - auto dOutWa = sofa::helper::getWriteOnlyAccessor(dOut); - auto dInRa = sofa::helper::getReadAccessor(dIn); - jacobian.mult(dOutWa.wref(),dInRa.ref()); - } + SOFA_UNUSED( mparams ); + const unsigned geometricStiffness = this->d_geometricStiffness.getValue().getSelectedId(); -} + helper::WriteAccessor parentForceAccessor(parentForce); + const helper::ReadAccessor parentDisplacementAccessor(parentDisplacement); + const helper::ReadAccessor childForceAccessor (childForce); + const helper::ReadAccessor indices(d_indices); -template -void DistanceFromTargetMapping::applyJT(const core::MechanicalParams * /*mparams*/ , Data& dIn, const Data& dOut) -{ - if( jacobian.rowSize() > 0 ) - { - auto dOutRa = sofa::helper::getReadAccessor(dOut); - auto dInWa = sofa::helper::getWriteOnlyAccessor(dIn); - jacobian.addMultTranspose(dInWa.wref(),dOutRa.ref()); - } -} - -template -void DistanceFromTargetMapping::applyJT(const core::ConstraintParams* cparams, Data& out, const Data& in) -{ - SOFA_UNUSED(cparams); - auto childMatRa = sofa::helper::getReadAccessor(in); - auto parentMatWa = sofa::helper::getWriteAccessor(out); - addMultTransposeEigen(parentMatWa.wref(), jacobian.compressedMatrix, childMatRa.ref()); -} - - -template -void DistanceFromTargetMapping::applyDJT(const core::MechanicalParams* mparams, core::MultiVecDerivId parentDfId, core::ConstMultiVecDerivId ) -{ - const unsigned geometricStiffness = d_geometricStiffness.getValue().getSelectedId(); - if( !geometricStiffness ) return; - - helper::WriteAccessor > parentForce (*parentDfId[this->fromModel.get()].write()); - helper::ReadAccessor > parentDisplacement (*mparams->readDx(this->fromModel.get())); // parent displacement - const SReal kfactor = mparams->kFactor(); - helper::ReadAccessor > childForce (*mparams->readF(this->toModel.get())); - const helper::ReadAccessor< Data > > indices(d_indices); - - for(unsigned i=0; i0) can lead to negative eigen values in geometric stiffness // this results in an undefinite implicit matrix that causes instabilities // if stabilized GS (geometricStiffness==2) -> keep only force in extension - if( childForce[i][0] < 0 || geometricStiffness==1 ) + if( childForceAccessor[i][0] < 0 || geometricStiffness==1 ) { sofa::type::Mat b; // = (I - uu^T) for(unsigned j=0; j::applyDJT(const core::MechanicalParams } } // (I - uu^T)*f/l*kfactor -- do not forget kfactor ! - b *= (Real)(childForce[i][0] * invlengths[i] * kfactor); + b *= (Real)(childForceAccessor[i][0] * invlengths[i] * kFactor); // note that computing a block is not efficient here, but it would // makes sense for storing a stiffness matrix - InDeriv dx = parentDisplacement[indices[i]]; - InDeriv df; + const auto& dx = parentDisplacementAccessor[indices[i]]; + Deriv_t df; for(unsigned j=0; j::applyDJT(const core::MechanicalParams df[j]+=b[j][k]*dx[k]; } } - // InDeriv df = b*dx; - parentForce[indices[i]] += df; + // Deriv_t df = b*dx; + parentForceAccessor[indices[i]] += df; } } } - - - -template -const sofa::linearalgebra::BaseMatrix* DistanceFromTargetMapping::getJ() -{ - return &jacobian; -} - -template -const type::vector* DistanceFromTargetMapping::getJs() -{ - return &baseMatrices; -} - -template -const linearalgebra::BaseMatrix* DistanceFromTargetMapping::getK() -{ - return &K; -} - template void DistanceFromTargetMapping::buildGeometricStiffnessMatrix( sofa::core::GeometricStiffnessMatrix* matrices) { - const unsigned geometricStiffness = d_geometricStiffness.getValue().getSelectedId(); + const unsigned geometricStiffness = this->d_geometricStiffness.getValue().getSelectedId(); if( !geometricStiffness ) { return; @@ -299,7 +243,7 @@ void DistanceFromTargetMapping::buildGeometricStiffnessMatrix( for(sofa::Size i=0; i0) can lead to negative eigen values in geometric stiffness // this results in an undefinite implicit matrix that causes instabilities @@ -324,23 +268,22 @@ void DistanceFromTargetMapping::buildGeometricStiffnessMatrix( } template -void DistanceFromTargetMapping::updateK( const core::MechanicalParams* mparams, core::ConstMultiVecDerivId childForceId ) +void DistanceFromTargetMapping::doUpdateK( + const core::MechanicalParams* mparams, + const Data>& childForce, SparseKMatrixEigen& matrix) { SOFA_UNUSED(mparams); - const unsigned geometricStiffness = d_geometricStiffness.getValue().getSelectedId(); - if( !geometricStiffness ) { K.resize(0,0); return; } + const unsigned geometricStiffness = this->d_geometricStiffness.getValue().getSelectedId(); - helper::ReadAccessor > childForce( *childForceId[this->toModel.get()].read() ); - const helper::ReadAccessor< Data > > indices(d_indices); - helper::ReadAccessor > in (*this->fromModel->read(core::ConstVecCoordId::position())); + const helper::ReadAccessor childForceAccessor(childForce); + const helper::ReadAccessor indices(d_indices); - K.resizeBlocks(in.size(),in.size()); - for(size_t i=0; i0) can lead to negative eigen values in geometric stiffness // this results in an undefinite implicit matrix that causes instabilities // if stabilized GS (geometricStiffness==2) -> keep only force in extension - if( childForce[i][0] < 0 || geometricStiffness==1 ) + if( childForceAccessor[i][0] < 0 || geometricStiffness==1 ) { size_t idx = indices[i]; @@ -352,12 +295,11 @@ void DistanceFromTargetMapping::updateK( const core::MechanicalParams b[j][k] = static_cast(1) * ( j==k ) - directions[i][j]*directions[i][k]; } } - b *= childForce[i][0] * invlengths[i]; // (I - uu^T)*f/l + b *= childForceAccessor[i][0] * invlengths[i]; // (I - uu^T)*f/l - K.addBlock(idx,idx,b); + matrix.addBlock(idx,idx,b); } } - K.compress(); } diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceMapping.h b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceMapping.h index 07ea6194f49..949fb8fa5d3 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceMapping.h +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceMapping.h @@ -23,7 +23,7 @@ #include -#include +#include #include #include #include @@ -46,26 +46,18 @@ namespace sofa::component::mapping::nonlinear * @author Francois Faure */ template -class DistanceMapping : public core::Mapping, public StabilizedNonLinearMappingData +class DistanceMapping : public BaseNonLinearMapping { public: - SOFA_CLASS(SOFA_TEMPLATE2(DistanceMapping,TIn,TOut), SOFA_TEMPLATE2(core::Mapping,TIn,TOut)); + SOFA_CLASS(SOFA_TEMPLATE2(DistanceMapping,TIn,TOut), SOFA_TEMPLATE3(BaseNonLinearMapping,TIn,TOut,true)); typedef TIn In; typedef TOut Out; - typedef typename Out::VecCoord OutVecCoord; - typedef typename Out::VecDeriv OutVecDeriv; - typedef typename Out::Deriv OutDeriv; - typedef typename Out::MatrixDeriv OutMatrixDeriv; - typedef typename Out::Real Real; - typedef typename In::Deriv InDeriv; - typedef typename In::MatrixDeriv InMatrixDeriv; - typedef typename In::Coord InCoord; - typedef typename In::VecCoord InVecCoord; - typedef typename In::VecDeriv InVecDeriv; - typedef linearalgebra::EigenSparseMatrix SparseMatrixEigen; - typedef linearalgebra::EigenSparseMatrix SparseKMatrixEigen; + + using Real = Real_t; + static constexpr auto Nin = In::deriv_total_size; + typedef sofa::core::topology::BaseMeshTopology::SeqEdges SeqEdges; typedef type::Vec Direction; @@ -84,25 +76,9 @@ class DistanceMapping : public core::Mapping, public StabilizedNonLin /// Link to be set to the topology container in the component graph. SingleLink, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology; - - void init() override; - void apply(const core::MechanicalParams *mparams, Data& out, const Data& in) override; - - void applyJ(const core::MechanicalParams *mparams, Data& out, const Data& in) override; - - void applyJT(const core::MechanicalParams *mparams, Data& out, const Data& in) override; - - void applyJT(const core::ConstraintParams *cparams, Data& out, const Data& in) override; - - void applyDJT(const core::MechanicalParams* mparams, core::MultiVecDerivId parentForce, core::ConstMultiVecDerivId childForce ) override; - - const sofa::linearalgebra::BaseMatrix* getJ() override; - virtual const type::vector* getJs() override; - - void updateK( const core::MechanicalParams* mparams, core::ConstMultiVecDerivId childForce ) override; - const linearalgebra::BaseMatrix* getK() override; + void apply(const core::MechanicalParams *mparams, DataVecCoord_t& out, const DataVecCoord_t& in) override; void buildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) override; void computeBBox(const core::ExecParams* params, bool onlyVisible) override; @@ -111,29 +87,24 @@ class DistanceMapping : public core::Mapping, public StabilizedNonLin protected: DistanceMapping(); - SparseMatrixEigen jacobian; ///< Jacobian of the mapping - type::vector baseMatrices; ///< Jacobian of the mapping, in a vector - SparseKMatrixEigen K; ///< Assembled geometric stiffness matrix + void matrixFreeApplyDJT(const core::MechanicalParams* mparams, Real kFactor, + Data >& parentForce, + const Data >& parentDisplacement, + const Data >& childForce) override; + + using typename Inherit1::SparseKMatrixEigen; + + void doUpdateK( + const core::MechanicalParams* mparams, const Data >& childForce, + SparseKMatrixEigen& matrix) override; + type::vector directions; ///< Unit vectors in the directions of the lines type::vector< Real > invlengths; ///< inverse of current distances. Null represents the infinity (null distance) /// r=b-a only for position (eventual rotation, affine transform... remains null) - void computeCoordPositionDifference( Direction& r, const InCoord& a, const InCoord& b ); - - /** - * @brief Represents an entry in the Jacobian matrix. - * - * The JacobianEntry struct is used to store information about an entry in the - * Jacobian matrix, specifically the vertex identifier and the corresponding - * Jacobian value. It also provides a comparison operator for sorting entries - * by vertex ID. - */ - struct JacobianEntry - { - sofa::Index vertexId; - Direction jacobianValue; - bool operator<(const JacobianEntry& other) const { return vertexId < other.vertexId;} - }; + void computeCoordPositionDifference( Direction& r, const Coord_t& a, const Coord_t& b ); + + using JacobianEntry = typename Inherit1::JacobianEntry; }; diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceMapping.inl b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceMapping.inl index c4b91bb0a4a..6c90d4616fe 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceMapping.inl +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceMapping.inl @@ -22,6 +22,7 @@ #pragma once #include +#include #include #include #include @@ -69,7 +70,7 @@ void DistanceMapping::init() typename core::behavior::MechanicalState::ReadVecCoord pos = this->getFromModel()->readPositions(); this->getToModel()->resize( links.size() ); - jacobian.resizeBlocks(links.size(),pos.size()); + this->m_jacobian.resizeBlocks(links.size(),pos.size()); directions.resize(links.size()); invlengths.resize(links.size()); @@ -90,27 +91,24 @@ void DistanceMapping::init() } } - baseMatrices.resize( 1 ); - baseMatrices[0] = &jacobian; - this->Inherit1::init(); // applies the mapping, so after the Data init } template -void DistanceMapping::computeCoordPositionDifference( Direction& r, const InCoord& a, const InCoord& b ) +void DistanceMapping::computeCoordPositionDifference( Direction& r, const Coord_t& a, const Coord_t& b ) { r = TIn::getCPos(b) - TIn::getCPos(a); } template -void DistanceMapping::apply(const core::MechanicalParams * /*mparams*/ , Data& dOut, const Data& dIn) +void DistanceMapping::apply(const core::MechanicalParams * /*mparams*/ , DataVecCoord_t& dOut, const DataVecCoord_t& dIn) { - helper::WriteOnlyAccessor< Data > out = dOut; - helper::ReadAccessor< Data > in = dIn; + helper::WriteOnlyAccessor> out(dOut); + helper::ReadAccessor in(dIn); helper::ReadAccessor > > restLengths(d_restLengths); const SeqEdges& links = l_topology->getEdges(); - jacobian.clear(); + this->m_jacobian.clear(); for (unsigned int i = 0; i < links.size(); ++i) { @@ -138,145 +136,96 @@ void DistanceMapping::apply(const core::MechanicalParams * /*mparams* direction.fill(p); } - sofa::type::fixed_array jacobianEntries {JacobianEntry{link[0], -direction}, JacobianEntry{link[1], direction}}; + sofa::type::fixed_array jacobianEntries { + JacobianEntry{link[0], -direction}, + JacobianEntry{link[1], direction} + }; //invert to insert in increasing column order std::sort(jacobianEntries.begin(), jacobianEntries.end()); - jacobian.beginRow(i); + this->m_jacobian.beginRow(i); for (const auto& [vertexId, jacobianValue] : jacobianEntries) { for (unsigned k = 0; k < In::spatial_dimensions; ++k) { - jacobian.insertBack(i, vertexId * Nin + k, jacobianValue[k]); + this->m_jacobian.insertBack(i, vertexId * Nin + k, jacobianValue[k]); } } } - jacobian.compress(); -} - - -template -void DistanceMapping::applyJ(const core::MechanicalParams * /*mparams*/ , Data& out, const Data& in) -{ - if( jacobian.rowSize() ) - { - auto dOutWa = sofa::helper::getWriteOnlyAccessor(out); - auto dInRa = sofa::helper::getReadAccessor(in); - jacobian.mult(dOutWa.wref(),dInRa.ref()); - } + this->m_jacobian.compress(); } template -void DistanceMapping::applyJT(const core::MechanicalParams * /*mparams*/ , Data& out, const Data& in) +void DistanceMapping::matrixFreeApplyDJT( + const core::MechanicalParams* mparams, Real kFactor, + Data>& parentForce, + const Data>& parentDisplacement, + const Data>& childForce) { - if( jacobian.rowSize() ) - { - auto dOutRa = sofa::helper::getReadAccessor(in); - auto dInWa = sofa::helper::getWriteOnlyAccessor(out); - jacobian.addMultTranspose(dInWa.wref(),dOutRa.ref()); - } -} + SOFA_UNUSED(mparams); + const unsigned geometricStiffness = this->d_geometricStiffness.getValue().getSelectedId(); -template -void DistanceMapping::applyDJT(const core::MechanicalParams* mparams, core::MultiVecDerivId parentDfId, core::ConstMultiVecDerivId) -{ - const unsigned geometricStiffness = d_geometricStiffness.getValue().getSelectedId(); - if( !geometricStiffness ) return; + helper::WriteAccessor parentForceAccessor(parentForce); + helper::ReadAccessor parentDisplacementAccessor(parentDisplacement); + helper::ReadAccessor childForceAccessor(childForce); - helper::WriteAccessor > parentForce (*parentDfId[this->fromModel.get()].write()); - helper::ReadAccessor > parentDisplacement (*mparams->readDx(this->fromModel.get())); // parent displacement - const SReal& kfactor = mparams->kFactor(); - helper::ReadAccessor > childForce (*mparams->readF(this->toModel.get())); + const SeqEdges& links = l_topology->getEdges(); - if( K.compressedMatrix.nonZeros() ) - { - K.addMult( parentForce.wref(), parentDisplacement.ref(), (typename In::Real)kfactor ); - } - else + for (unsigned i = 0; i < links.size(); ++i) { - const SeqEdges& links = l_topology->getEdges(); - - for(unsigned i=0; i0) can lead to negative eigen values in geometric stiffness + // this results in an undefinite implicit matrix that causes instabilities + // if stabilized GS (geometricStiffness==2) -> keep only force in extension + if( childForceAccessor[i][0] < 0 || geometricStiffness==1 ) { - // force in compression (>0) can lead to negative eigen values in geometric stiffness - // this results in an undefinite implicit matrix that causes instabilities - // if stabilized GS (geometricStiffness==2) -> keep only force in extension - if( childForce[i][0] < 0 || geometricStiffness==1 ) + sofa::type::Mat b; // = (I - uu^T) + for(unsigned j=0; j b; // = (I - uu^T) - for(unsigned j=0; j(1) * ( j==k ) - directions[i][j]*directions[i][k]; - } + b[j][k] = static_cast(1) * ( j==k ) - directions[i][j]*directions[i][k]; } - // (I - uu^T)*f/l*kfactor -- do not forget kfactor ! - b *= (Real)(childForce[i][0] * invlengths[i] * kfactor); - // note that computing a block is not efficient here, but it - // would make sense for storing a stiffness matrix - - InDeriv dx = parentDisplacement[links[i][1]] - parentDisplacement[links[i][0]]; - InDeriv df; - for(unsigned j=0; j dx = parentDisplacementAccessor[links[i][1]] - parentDisplacementAccessor[links[i][0]]; + Deriv_t df; + for(unsigned j=0; j -void DistanceMapping::applyJT(const core::ConstraintParams* cparams, Data& out, const Data& in) -{ - SOFA_UNUSED(cparams); - auto childMatRa = sofa::helper::getReadAccessor(in); - auto parentMatWa = sofa::helper::getWriteAccessor(out); - addMultTransposeEigen(parentMatWa.wref(), jacobian.compressedMatrix, childMatRa.ref()); -} - - -template -const sofa::linearalgebra::BaseMatrix* DistanceMapping::getJ() -{ - return &jacobian; -} - -template -const type::vector* DistanceMapping::getJs() -{ - return &baseMatrices; -} - - - -template -void DistanceMapping::updateK(const core::MechanicalParams *mparams, core::ConstMultiVecDerivId childForceId ) +void DistanceMapping::doUpdateK( + const core::MechanicalParams* mparams, + const Data>& childForce, SparseKMatrixEigen& matrix) { SOFA_UNUSED(mparams); - const unsigned geometricStiffness = d_geometricStiffness.getValue().getSelectedId(); - if( !geometricStiffness ) { K.resize(0,0); return; } + const unsigned geometricStiffness = this->d_geometricStiffness.getValue().getSelectedId(); - helper::ReadAccessor > childForce( *childForceId[this->toModel.get()].read() ); + const helper::ReadAccessor childForceAccessor(childForce); const SeqEdges& links = l_topology->getEdges(); - unsigned int size = this->fromModel->getSize(); - K.resizeBlocks(size,size); - for(size_t i=0; i0) can lead to negative eigen values in geometric stiffness // this results in an undefinite implicit matrix that causes instabilities // if stabilized GS (geometricStiffness==2) -> keep only force in extension - if( childForce[i][0] < 0 || geometricStiffness==1 ) + if( childForceAccessor[i][0] < 0 || geometricStiffness==1 ) { sofa::type::Mat b; // = (I - uu^T) @@ -287,29 +236,22 @@ void DistanceMapping::updateK(const core::MechanicalParams *mparams, b[j][k] = static_cast(1) * ( j==k ) - directions[i][j]*directions[i][k]; } } - b *= childForce[i][0] * invlengths[i]; // (I - uu^T)*f/l + b *= childForceAccessor[i][0] * invlengths[i]; // (I - uu^T)*f/l // Note that 'links' is not sorted so the matrix can not be filled-up in order - K.addBlock(links[i][0],links[i][0],b); - K.addBlock(links[i][0],links[i][1],-b); - K.addBlock(links[i][1],links[i][0],-b); - K.addBlock(links[i][1],links[i][1],b); + matrix.addBlock(links[i][0],links[i][0],b); + matrix.addBlock(links[i][0],links[i][1],-b); + matrix.addBlock(links[i][1],links[i][0],-b); + matrix.addBlock(links[i][1],links[i][1],b); } } - K.compress(); -} - -template -const linearalgebra::BaseMatrix* DistanceMapping::getK() -{ - return &K; } template void DistanceMapping::buildGeometricStiffnessMatrix( sofa::core::GeometricStiffnessMatrix* matrices) { - const unsigned& geometricStiffness = d_geometricStiffness.getValue().getSelectedId(); + const unsigned& geometricStiffness = this->d_geometricStiffness.getValue().getSelectedId(); if( !geometricStiffness ) { return; @@ -321,7 +263,7 @@ void DistanceMapping::buildGeometricStiffnessMatrix( for(sofa::Size i=0; i force_i = childForce[i]; // force in compression (>0) can lead to negative eigen values in geometric stiffness // this results in an undefinite implicit matrix that causes instabilities diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareDistanceMapping.h b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareDistanceMapping.h index afca0b322b5..138c075f2ea 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareDistanceMapping.h +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareDistanceMapping.h @@ -23,8 +23,7 @@ #include -#include -#include +#include #include #include #include @@ -53,38 +52,21 @@ namespace sofa::component::mapping::nonlinear // If the rest lengths are not defined, they are set using the initial values. // If computeDistance is set to true, the rest lengths are set to 0. template -class SquareDistanceMapping : public core::Mapping, public NonLinearMappingData +class SquareDistanceMapping : public BaseNonLinearMapping { public: - SOFA_CLASS(SOFA_TEMPLATE2(SquareDistanceMapping,TIn,TOut), SOFA_TEMPLATE2(core::Mapping,TIn,TOut)); - - typedef core::Mapping Inherit; - typedef TIn In; - typedef TOut Out; - typedef typename Out::VecCoord OutVecCoord; - typedef typename Out::VecDeriv OutVecDeriv; - typedef typename Out::Coord OutCoord; - typedef typename Out::Deriv OutDeriv; - typedef typename Out::MatrixDeriv OutMatrixDeriv; - typedef typename Out::Real Real; - typedef typename In::Deriv InDeriv; - typedef typename In::MatrixDeriv InMatrixDeriv; - typedef typename In::Coord InCoord; - typedef typename In::VecCoord InVecCoord; - typedef typename In::VecDeriv InVecDeriv; - typedef linearalgebra::EigenSparseMatrix SparseMatrixEigen; - typedef linearalgebra::EigenSparseMatrix SparseKMatrixEigen; - typedef Data InDataVecCoord; - typedef Data InDataVecDeriv; - typedef Data InDataMatrixDeriv; - typedef Data OutDataVecCoord; - typedef Data OutDataVecDeriv; - typedef Data OutDataMatrixDeriv; - enum {Nin = In::deriv_total_size, Nout = Out::deriv_total_size }; + SOFA_CLASS(SOFA_TEMPLATE2(SquareDistanceMapping,TIn,TOut), SOFA_TEMPLATE3(BaseNonLinearMapping,TIn,TOut,true)); + + using In = TIn; + using Out = TOut; + + using Real = Real_t; + + static constexpr auto Nin = In::deriv_total_size; + typedef sofa::core::topology::BaseMeshTopology::SeqEdges SeqEdges; typedef type::Vec Direction; - Data d_showObjectScale; ///< Scale for object display Data d_color; ///< Color for object display. (default=[1.0,1.0,0.0,1.0]) @@ -93,37 +75,28 @@ class SquareDistanceMapping : public core::Mapping, public NonLinearM void init() override; - using Inherit::apply; - - void apply(const core::MechanicalParams *mparams, Data& out, const Data& in) override; - - void applyJ(const core::MechanicalParams *mparams, Data& out, const Data& in) override; - - void applyJT(const core::MechanicalParams *mparams, Data& out, const Data& in) override; - - void applyJT(const core::ConstraintParams *cparams, Data& out, const Data& in) override; - - void applyDJT(const core::MechanicalParams* mparams, core::MultiVecDerivId parentForce, core::ConstMultiVecDerivId childForce ) override; - - const sofa::linearalgebra::BaseMatrix* getJ() override; - virtual const type::vector* getJs() override; - - void updateK( const core::MechanicalParams* mparams, core::ConstMultiVecDerivId childForce ) override; - const linearalgebra::BaseMatrix* getK() override; + void apply(const core::MechanicalParams *mparams, DataVecCoord_t& out, const DataVecCoord_t& in) override; void buildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) override; void draw(const core::visual::VisualParams* vparams) override; protected: SquareDistanceMapping(); - virtual ~SquareDistanceMapping(); + ~SquareDistanceMapping() override; + + void matrixFreeApplyDJT(const core::MechanicalParams* mparams, Real kFactor, + Data >& parentForce, + const Data >& parentDisplacement, + const Data >& childForce) override; + + using typename Inherit1::SparseKMatrixEigen; - SparseMatrixEigen jacobian; ///< Jacobian of the mapping - type::vector baseMatrices; ///< Jacobian of the mapping, in a vector - SparseKMatrixEigen K; ///< Assembled geometric stiffness matrix + void doUpdateK( + const core::MechanicalParams* mparams, const Data >& childForce, + SparseKMatrixEigen& matrix) override; /// r=b-a only for position (eventual rotation, affine transform... remains null) - void computeCoordPositionDifference( Direction& r, const InCoord& a, const InCoord& b ); + void computeCoordPositionDifference( Direction& r, const Coord_t& a, const Coord_t& b ); }; diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareDistanceMapping.inl b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareDistanceMapping.inl index ae9a7e81e51..54d11d5cb55 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareDistanceMapping.inl +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareDistanceMapping.inl @@ -22,6 +22,7 @@ #pragma once #include +#include #include #include #include @@ -36,8 +37,7 @@ namespace sofa::component::mapping::nonlinear template SquareDistanceMapping::SquareDistanceMapping() - : Inherit() - , d_showObjectScale(initData(&d_showObjectScale, Real(0), "showObjectScale", "Scale for object display")) + : d_showObjectScale(initData(&d_showObjectScale, Real(0), "showObjectScale", "Scale for object display")) , d_color(initData(&d_color, sofa::type::RGBAColor(1,1,0,1), "showColor", "Color for object display. (default=[1.0,1.0,0.0,1.0])")) , l_topology(initLink("topology", "link to the topology container")) { @@ -45,9 +45,7 @@ SquareDistanceMapping::SquareDistanceMapping() template SquareDistanceMapping::~SquareDistanceMapping() -{ -} - += default; template void SquareDistanceMapping::init() @@ -71,34 +69,34 @@ void SquareDistanceMapping::init() this->getToModel()->resize( links.size() ); - baseMatrices.resize( 1 ); - baseMatrices[0] = &jacobian; - - this->Inherit::init(); // applies the mapping, so after the Data init + this->Inherit1::init(); } template -void SquareDistanceMapping::computeCoordPositionDifference( Direction& r, const InCoord& a, const InCoord& b ) +void SquareDistanceMapping::computeCoordPositionDifference( Direction& r, const Coord_t& a, const Coord_t& b ) { r = TIn::getCPos(b)-TIn::getCPos(a); } template -void SquareDistanceMapping::apply(const core::MechanicalParams * /*mparams*/ , Data& dOut, const Data& dIn) +void SquareDistanceMapping::apply( + const core::MechanicalParams * /*mparams*/, + DataVecCoord_t& dOut, + const DataVecCoord_t& dIn) { - helper::WriteOnlyAccessor< Data > out = dOut; - helper::ReadAccessor< Data > in = dIn; + helper::WriteOnlyAccessor< DataVecCoord_t > out = dOut; + const helper::ReadAccessor in (dIn); const SeqEdges& links = l_topology->getEdges(); - jacobian.resizeBlocks(out.size(),in.size()); + this->m_jacobian.resizeBlocks(out.size(),in.size()); Direction gap; for(unsigned i=0; i& p0 = in[links[i][0]]; + const Coord_t& p1 = in[links[i][1]]; // gap = in[links[i][1]] - in[links[i][0]] (only for position) computeCoordPositionDifference( gap, p0, p1 ); @@ -120,158 +118,98 @@ void SquareDistanceMapping::apply(const core::MechanicalParams * /*mp // } - jacobian.beginRow(i); + this->m_jacobian.beginRow(i); if( links[i][1]m_jacobian.insertBack( i, links[i][1]*Nin+k, gap[k] ); for(unsigned k=0; km_jacobian.insertBack( i, links[i][0]*Nin+k, -gap[k] ); } else { for(unsigned k=0; km_jacobian.insertBack( i, links[i][0]*Nin+k, -gap[k] ); for(unsigned k=0; km_jacobian.insertBack( i, links[i][1]*Nin+k, gap[k] ); } } - jacobian.compress(); -} - - -template -void SquareDistanceMapping::applyJ(const core::MechanicalParams * /*mparams*/ , Data& dOut, const Data& dIn) -{ - if( jacobian.rowSize() ) - { - auto dOutWa = sofa::helper::getWriteOnlyAccessor(dOut); - auto dInRa = sofa::helper::getReadAccessor(dIn); - jacobian.mult(dOutWa.wref(),dInRa.ref()); - } + this->m_jacobian.compress(); } template -void SquareDistanceMapping::applyJT(const core::MechanicalParams * /*mparams*/ , Data& dIn, const Data& dOut) +void SquareDistanceMapping::matrixFreeApplyDJT( + const core::MechanicalParams* mparams, Real kFactor, + Data>& parentForce, + const Data>& parentDisplacement, + const Data>& childForce) { - if( jacobian.rowSize() ) - { - auto dOutRa = sofa::helper::getReadAccessor(dOut); - auto dInWa = sofa::helper::getWriteOnlyAccessor(dIn); - jacobian.addMultTranspose(dInWa.wref(),dOutRa.ref()); - } -} + SOFA_UNUSED(mparams); + const unsigned& geometricStiffness = this->d_geometricStiffness.getValue().getSelectedId(); -template -void SquareDistanceMapping::applyDJT(const core::MechanicalParams* mparams, core::MultiVecDerivId parentDfId, core::ConstMultiVecDerivId ) -{ - const unsigned& geometricStiffness = d_geometricStiffness.getValue().getSelectedId(); - if( !geometricStiffness ) return; + helper::WriteAccessor parentForceAccessor(parentForce); + helper::ReadAccessor parentDisplacementAccessor(parentDisplacement); + helper::ReadAccessor childForceAccessor(childForce); - helper::WriteAccessor > parentForce (*parentDfId[this->fromModel.get()].write()); - helper::ReadAccessor > parentDisplacement (*mparams->readDx(this->fromModel.get())); // parent displacement - const SReal& kfactor = mparams->kFactor(); - helper::ReadAccessor > childForce (*mparams->readF(this->toModel.get())); + const SeqEdges& links = l_topology->getEdges(); - if( K.compressedMatrix.nonZeros() ) + for (unsigned i = 0; i < links.size(); i++) { - K.addMult( parentForce.wref(), parentDisplacement.ref(), (typename In::Real)kfactor ); - } - else - { - const SeqEdges& links = l_topology->getEdges(); - - for(unsigned i=0; i0) can lead to negative eigen values in geometric stiffness + // this results in an undefinite implicit matrix that causes instabilities + // if stabilized GS (geometricStiffness==2) -> keep only force in extension + if( childForceAccessor[i][0] < 0 || geometricStiffness==1 ) { - // force in compression (>0) can lead to negative eigen values in geometric stiffness - // this results in an undefinite implicit matrix that causes instabilities - // if stabilized GS (geometricStiffness==2) -> keep only force in extension - if( childForce[i][0] < 0 || geometricStiffness==1 ) - { - - SReal tmp = 2*childForce[i][0]*kfactor; + SReal tmp = 2 * childForceAccessor[i][0] * kFactor; - typename In::DPos df = tmp * ( - In::getDPos(parentDisplacement[links[i][0]]) - - In::getDPos(parentDisplacement[links[i][1]])); - // it is symmetric so -df = (parentDisplacement[links[i][1]]-parentDisplacement[links[i][0]])*tmp; + typename In::DPos df = tmp * ( + In::getDPos(parentDisplacementAccessor[links[i][0]]) - + In::getDPos(parentDisplacementAccessor[links[i][1]])); + // it is symmetric so -df = (parentDisplacement[links[i][1]]-parentDisplacement[links[i][0]])*tmp; - In::setDPos(parentForce[links[i][0]], In::getDPos(parentForce[links[i][0]]) + df); - In::setDPos(parentForce[links[i][1]], In::getDPos(parentForce[links[i][1]]) - df); - } + In::setDPos(parentForceAccessor[links[i][0]], In::getDPos(parentForceAccessor[links[i][0]]) + df); + In::setDPos(parentForceAccessor[links[i][1]], In::getDPos(parentForceAccessor[links[i][1]]) - df); } } } template -void SquareDistanceMapping::applyJT(const core::ConstraintParams* cparams, Data& out, const Data& in) -{ - SOFA_UNUSED(cparams); - auto childMatRa = sofa::helper::getReadAccessor(in); - auto parentMatWa = sofa::helper::getWriteAccessor(out); - addMultTransposeEigen(parentMatWa.wref(), jacobian.compressedMatrix, childMatRa.ref()); -} - - -template -const sofa::linearalgebra::BaseMatrix* SquareDistanceMapping::getJ() -{ - return &jacobian; -} - -template -const type::vector* SquareDistanceMapping::getJs() -{ - return &baseMatrices; -} - - - -template -void SquareDistanceMapping::updateK(const core::MechanicalParams *mparams, core::ConstMultiVecDerivId childForceId ) +void SquareDistanceMapping::doUpdateK( + const core::MechanicalParams* mparams, + const Data>& childForce, SparseKMatrixEigen& matrix) { SOFA_UNUSED(mparams); - const unsigned geometricStiffness = d_geometricStiffness.getValue().getSelectedId(); - if( !geometricStiffness ) { K.resize(0,0); return; } + const unsigned geometricStiffness = this->d_geometricStiffness.getValue().getSelectedId(); - helper::ReadAccessor > childForce( *childForceId[this->toModel.get()].read() ); + const helper::ReadAccessor childForceAccessor(childForce); const SeqEdges& links = l_topology->getEdges(); - unsigned int size = this->fromModel->getSize(); - K.resizeBlocks(size,size); for(size_t i=0; i0) can lead to negative eigen values in geometric stiffness // this results in an undefinite implicit matrix that causes instabilities // if stabilized GS (geometricStiffness==2) -> keep only force in extension - if( childForce[i][0] < 0 || geometricStiffness==1 ) + if( childForceAccessor[i][0] < 0 || geometricStiffness==1 ) { - SReal tmp = 2*childForce[i][0]; + SReal tmp = 2*childForceAccessor[i][0]; for(unsigned k=0; k -const linearalgebra::BaseMatrix* SquareDistanceMapping::getK() -{ - return &K; } template void SquareDistanceMapping::buildGeometricStiffnessMatrix( sofa::core::GeometricStiffnessMatrix* matrices) { - const unsigned geometricStiffness = d_geometricStiffness.getValue().getSelectedId(); + const unsigned geometricStiffness = this->d_geometricStiffness.getValue().getSelectedId(); if( !geometricStiffness ) { return; @@ -283,7 +221,7 @@ void SquareDistanceMapping::buildGeometricStiffnessMatrix( for(sofa::Size i=0; i& force_i = childForce[i]; const sofa::topology::Edge link = links[i]; // force in compression (>0) can lead to negative eigen values in geometric stiffness diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareMapping.h b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareMapping.h index 161037cbb24..a8131b726bc 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareMapping.h +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareMapping.h @@ -23,7 +23,7 @@ #include -#include +#include #include #include @@ -38,65 +38,33 @@ namespace sofa::component::mapping::nonlinear */ template -class SquareMapping : public core::Mapping, public NonLinearMappingData +class SquareMapping : public BaseNonLinearMapping { public: - SOFA_CLASS(SOFA_TEMPLATE2(SquareMapping,TIn,TOut), SOFA_TEMPLATE2(core::Mapping,TIn,TOut)); - - typedef core::Mapping Inherit; - typedef TIn In; - typedef TOut Out; - typedef typename Out::VecCoord OutVecCoord; - typedef typename Out::VecDeriv OutVecDeriv; - typedef typename Out::Coord OutCoord; - typedef typename Out::Deriv OutDeriv; - typedef typename Out::MatrixDeriv OutMatrixDeriv; - typedef typename Out::Real Real; - typedef typename In::Deriv InDeriv; - typedef typename In::MatrixDeriv InMatrixDeriv; - typedef typename In::Coord InCoord; - typedef typename In::VecCoord InVecCoord; - typedef typename In::VecDeriv InVecDeriv; - typedef linearalgebra::EigenSparseMatrix SparseMatrixEigen; - typedef linearalgebra::EigenSparseMatrix SparseKMatrixEigen; - typedef Data InDataVecCoord; - typedef Data InDataVecDeriv; - typedef Data InDataMatrixDeriv; - typedef Data OutDataVecCoord; - typedef Data OutDataVecDeriv; - typedef Data OutDataMatrixDeriv; - typedef type::Vec Direction; - - void init() override; - - using Inherit::apply; - - void apply(const core::MechanicalParams *mparams, Data& out, const Data& in) override; - - void applyJ(const core::MechanicalParams *mparams, Data& out, const Data& in) override; - - void applyJT(const core::MechanicalParams *mparams, Data& out, const Data& in) override; - - void applyJT(const core::ConstraintParams *cparams, Data& out, const Data& in) override; - - void applyDJT(const core::MechanicalParams* mparams, core::MultiVecDerivId parentForce, core::ConstMultiVecDerivId childForce ) override; - - const sofa::linearalgebra::BaseMatrix* getJ() override; - virtual const type::vector* getJs() override; - - void updateK( const core::MechanicalParams* mparams, core::ConstMultiVecDerivId childForce ) override; - const linearalgebra::BaseMatrix* getK() override; - void buildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) override; + SOFA_CLASS(SOFA_TEMPLATE2(SquareMapping,TIn,TOut), SOFA_TEMPLATE3(BaseNonLinearMapping,TIn,TOut,false)); + + using In = TIn; + using Out = TOut; + + using Real = Real_t; - Data < bool > d_useGeometricStiffnessMatrix; ///< If available (cached), the geometric stiffness matrix is used in order to compute the product with the parent displacement. Otherwise, the product is computed directly using the available vectors (matrix-free method). + static constexpr auto Nin = In::deriv_total_size; + + void apply(const core::MechanicalParams *mparams, DataVecCoord_t& out, const DataVecCoord_t& in) override; + void buildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) override; protected: - SquareMapping(); - ~SquareMapping() override; - SparseMatrixEigen jacobian; ///< Jacobian of the mapping - type::vector baseMatrices; ///< Jacobian of the mapping, in a vector - SparseKMatrixEigen K; ///< Assembled geometric stiffness matrix + void matrixFreeApplyDJT(const core::MechanicalParams* mparams, Real kFactor, + Data >& parentForce, + const Data >& parentDisplacement, + const Data >& childForce) override; + + using typename Inherit1::SparseKMatrixEigen; + + void doUpdateK( + const core::MechanicalParams* mparams, const Data >& childForce, + SparseKMatrixEigen& matrix) override; }; @@ -104,8 +72,6 @@ class SquareMapping : public core::Mapping, public NonLinearMappingDa #if !defined(SOFA_COMPONENT_MAPPING_SquareMapping_CPP) extern template class SOFA_COMPONENT_MAPPING_NONLINEAR_API SquareMapping< defaulttype::Vec1Types, defaulttype::Vec1Types >; - - #endif } // namespace sofa::component::mapping::nonlinear diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareMapping.inl b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareMapping.inl index 3f7eb33a74d..a74203abe0c 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareMapping.inl +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareMapping.inl @@ -22,6 +22,7 @@ #pragma once #include +#include #include #include #include @@ -33,159 +34,71 @@ namespace sofa::component::mapping::nonlinear { template -SquareMapping::SquareMapping() - : Inherit() - , d_useGeometricStiffnessMatrix(initData(&d_useGeometricStiffnessMatrix, true, "useGeometricStiffnessMatrix", - "If available (cached), the geometric stiffness matrix is used in order to compute the " - "product with the parent displacement. Otherwise, the product is computed directly using " - "the available vectors (matrix-free method).")) +void SquareMapping::apply(const core::MechanicalParams* mparams, + DataVecCoord_t& dOut, const DataVecCoord_t& dIn) { -} - -template -SquareMapping::~SquareMapping() -{ -} - - -template -void SquareMapping::init() -{ - baseMatrices.resize( 1 ); - baseMatrices[0] = &jacobian; - - this->Inherit::init(); -} - - -template -void SquareMapping::apply(const core::MechanicalParams * /*mparams*/ , Data& dOut, const Data& dIn) -{ - helper::WriteOnlyAccessor< Data > out = dOut; - helper::ReadAccessor< Data > in = dIn; + helper::WriteOnlyAccessor< DataVecCoord_t > out = dOut; + const helper::ReadAccessor> in = dIn; size_t size = in.size(); this->getToModel()->resize( size ); - jacobian.resizeBlocks( size, size ); - jacobian.reserve( size ); + this->m_jacobian.resizeBlocks( size, size ); + this->m_jacobian.reserve( size ); for( unsigned i=0 ; im_jacobian.beginRow(i); + this->m_jacobian.insertBack( i, i, 2.0*x ); } - jacobian.compress(); -} - - -template -void SquareMapping::applyJ(const core::MechanicalParams * /*mparams*/ , Data& dOut, const Data& dIn) -{ - if( jacobian.rowSize() ) - { - auto dOutWa = sofa::helper::getWriteOnlyAccessor(dOut); - auto dInRa = sofa::helper::getReadAccessor(dIn); - jacobian.mult(dOutWa.wref(),dInRa.ref()); - } -} - -template -void SquareMapping::applyJT(const core::MechanicalParams * /*mparams*/ , Data& dIn, const Data& dOut) -{ - if( jacobian.rowSize() ) - { - auto dOutRa = sofa::helper::getReadAccessor(dOut); - auto dInWa = sofa::helper::getWriteOnlyAccessor(dIn); - jacobian.addMultTranspose(dInWa.wref(),dOutRa.ref()); - } + this->m_jacobian.compress(); } template -void SquareMapping::applyDJT(const core::MechanicalParams* mparams, core::MultiVecDerivId parentDfId, core::ConstMultiVecDerivId ) +void SquareMapping::matrixFreeApplyDJT( + const core::MechanicalParams* mparams, Real kFactor, + Data>& parentForce, + const Data>& parentDisplacement, + const Data>& childForce) { - const unsigned geometricStiffness = d_geometricStiffness.getValue().getSelectedId(); - if( !geometricStiffness ) return; + helper::WriteAccessor parentForceAccessor(parentForce); + helper::ReadAccessor parentDisplacementAccessor(parentDisplacement); + helper::ReadAccessor childForceAccessor(childForce); - helper::WriteAccessor > parentForce (*parentDfId[this->fromModel.get()].write()); - helper::ReadAccessor > parentDisplacement (*mparams->readDx(this->fromModel.get())); // parent displacement - SReal kfactor = mparams->kFactor(); - helper::ReadAccessor > childForce (*mparams->readF(this->toModel.get())); + const size_t size = parentDisplacementAccessor.size(); + kFactor *= 2.0; - if(d_useGeometricStiffnessMatrix.getValue() && K.compressedMatrix.nonZeros() ) + for(unsigned i=0; i -void SquareMapping::applyJT(const core::ConstraintParams* cparams, Data& out, const Data& in) -{ - SOFA_UNUSED(cparams); - auto childMatRa = sofa::helper::getReadAccessor(in); - auto parentMatWa = sofa::helper::getWriteAccessor(out); - addMultTransposeEigen(parentMatWa.wref(), jacobian.compressedMatrix, childMatRa.ref()); -} - - -template -const sofa::linearalgebra::BaseMatrix* SquareMapping::getJ() -{ - return &jacobian; } template -const type::vector* SquareMapping::getJs() -{ - return &baseMatrices; -} - - - -template -void SquareMapping::updateK(const core::MechanicalParams *mparams, core::ConstMultiVecDerivId childForceId ) +void SquareMapping::doUpdateK(const core::MechanicalParams* mparams, + const Data>& childForce, SparseKMatrixEigen& matrix) { SOFA_UNUSED(mparams); - const unsigned geometricStiffness = d_geometricStiffness.getValue().getSelectedId(); - if( !geometricStiffness ) { K.resize(0,0); return; } - - helper::ReadAccessor > childForce( *childForceId[this->toModel.get()].read() ); + const helper::ReadAccessor childForceAccessor(childForce); unsigned int size = this->fromModel->getSize(); - K.resizeBlocks(size,size); - K.reserve( size ); - for( size_t i=0 ; i -const linearalgebra::BaseMatrix* SquareMapping::getK() -{ - return &K; } template void SquareMapping::buildGeometricStiffnessMatrix( sofa::core::GeometricStiffnessMatrix* matrices) { - const unsigned geometricStiffness = d_geometricStiffness.getValue().getSelectedId(); + const unsigned geometricStiffness = this->d_geometricStiffness.getValue().getSelectedId(); if( !geometricStiffness ) { return; diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/VolumeMapping.h b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/VolumeMapping.h index 80aae2b96d8..c8bc2df7b2f 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/VolumeMapping.h +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/VolumeMapping.h @@ -22,7 +22,7 @@ #pragma once #include -#include +#include #include #include #include @@ -32,17 +32,16 @@ namespace sofa::component::mapping::nonlinear { template -class VolumeMapping : public core::Mapping, public StabilizedNonLinearMappingData +class VolumeMapping : public BaseNonLinearMapping { public: - SOFA_CLASS(SOFA_TEMPLATE2(VolumeMapping,TIn,TOut), SOFA_TEMPLATE2(core::Mapping,TIn,TOut)); + SOFA_CLASS(SOFA_TEMPLATE2(VolumeMapping,TIn,TOut), SOFA_TEMPLATE3(BaseNonLinearMapping,TIn,TOut, true)); using In = TIn; using Out = TOut; using Real = Real_t; - typedef linearalgebra::EigenSparseMatrix SparseMatrixEigen; static constexpr auto Nin = In::deriv_total_size; SingleLink, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology; @@ -52,44 +51,25 @@ class VolumeMapping : public core::Mapping, public StabilizedNonLinea void init() override; void apply(const core::MechanicalParams* mparams, DataVecCoord_t& out, const DataVecCoord_t& in) override; - void applyJ(const core::MechanicalParams* mparams, DataVecDeriv_t& out, const DataVecDeriv_t& in) override; - void applyJT(const core::MechanicalParams* mparams, DataVecDeriv_t& out, const DataVecDeriv_t& in) override; - void applyJT(const core::ConstraintParams *cparams, DataMatrixDeriv_t& out, const DataMatrixDeriv_t& in) override; - void applyDJT(const core::MechanicalParams* mparams, core::MultiVecDerivId parentForceId, core::ConstMultiVecDerivId childForceId) override; - - void updateK( const core::MechanicalParams* mparams, core::ConstMultiVecDerivId childForceId) override; - const linearalgebra::BaseMatrix* getK() override; void buildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) override; - const type::vector* getJs() override; - protected: VolumeMapping(); - using SparseKMatrixEigen = linearalgebra::EigenSparseMatrix; - - SparseMatrixEigen jacobian; ///< Jacobian of the mapping - type::vector baseMatrices; ///< Jacobian of the mapping, in a vector - typename VolumeMapping::SparseKMatrixEigen K; ///< Assembled geometric stiffness matrix - - /** - * @brief Represents an entry in the Jacobian matrix. - * - * The JacobianEntry struct is used to store information about an entry in the - * Jacobian matrix, specifically the vertex identifier and the corresponding - * Jacobian value. It also provides a comparison operator for sorting entries - * by vertex ID. - */ - struct JacobianEntry - { - sofa::Index vertexId; - typename In::Coord jacobianValue; - bool operator<(const JacobianEntry& other) const { return vertexId < other.vertexId;} - }; + void matrixFreeApplyDJT(const core::MechanicalParams* mparams, Real kFactor, + Data >& parentForce, + const Data >& parentDisplacement, + const Data >& childForce) override; - const VecCoord_t* m_vertices{nullptr}; + using typename Inherit1::SparseKMatrixEigen; + void doUpdateK( + const core::MechanicalParams* mparams, const Data >& childForce, + SparseKMatrixEigen& matrix) override; + + const VecCoord_t* m_vertices{nullptr}; + using JacobianEntry = typename Inherit1::JacobianEntry; }; #if !defined(SOFA_COMPONENT_MAPPING_NONLINEAR_VOLUMEMAPPING_CPP) diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/VolumeMapping.inl b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/VolumeMapping.inl index 4e7fea16004..06d97729f97 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/VolumeMapping.inl +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/VolumeMapping.inl @@ -21,8 +21,8 @@ ******************************************************************************/ #pragma once #include +#include #include -#include namespace sofa::component::mapping::nonlinear { @@ -102,10 +102,7 @@ void VolumeMapping::init() typename core::behavior::MechanicalState::ReadVecCoord pos = this->getFromModel()->readPositions(); this->getToModel()->resize( nbTetrahedra ); - jacobian.resizeBlocks(nbTetrahedra, pos.size()); - - baseMatrices.resize( 1 ); - baseMatrices[0] = &jacobian; + this->m_jacobian.resizeBlocks(nbTetrahedra, pos.size()); Inherit1::init(); @@ -119,6 +116,8 @@ template void VolumeMapping::apply(const core::MechanicalParams* mparams, DataVecCoord_t& out, const DataVecCoord_t& in) { + SOFA_UNUSED( mparams ); + helper::WriteOnlyAccessor< Data> > _out = out; helper::ReadAccessor< Data > > _in = in; @@ -126,7 +125,7 @@ void VolumeMapping::apply(const core::MechanicalParams* mparams, const auto& tetrahedra = l_topology->getTetrahedra(); - jacobian.clear(); + this->m_jacobian.clear(); for (unsigned int tetId = 0; tetId < tetrahedra.size(); ++tetId) { @@ -166,115 +165,74 @@ void VolumeMapping::apply(const core::MechanicalParams* mparams, //insertion in increasing column order std::sort(jacobianEntries.begin(), jacobianEntries.end()); - jacobian.beginRow(tetId); + this->m_jacobian.beginRow(tetId); for (const auto& [vertexId, jacobianValue] : jacobianEntries) { for (unsigned d = 0; d < In::spatial_dimensions; ++d) { - jacobian.insertBack(tetId, vertexId * Nin + d, jacobianValue[d]); + this->m_jacobian.insertBack(tetId, vertexId * Nin + d, jacobianValue[d]); } } } - jacobian.compress(); -} - -template -void VolumeMapping::applyJ(const core::MechanicalParams* mparams, - DataVecDeriv_t& out, const DataVecDeriv_t& in) -{ - if( jacobian.rowSize() ) - { - auto dOutWa = sofa::helper::getWriteOnlyAccessor(out); - auto dInRa = sofa::helper::getReadAccessor(in); - jacobian.mult(dOutWa.wref(),dInRa.ref()); - } -} - -template -void VolumeMapping::applyJT(const core::MechanicalParams* mparams, - DataVecDeriv_t& out, const DataVecDeriv_t& in) -{ - if( jacobian.rowSize() ) - { - auto dOutRa = sofa::helper::getReadAccessor(in); - auto dInWa = sofa::helper::getWriteOnlyAccessor(out); - jacobian.addMultTranspose(dInWa.wref(),dOutRa.ref()); - } + this->m_jacobian.compress(); } template -void VolumeMapping::applyJT(const core::ConstraintParams* cparams, - DataMatrixDeriv_t& out, const DataMatrixDeriv_t& in) +void VolumeMapping::matrixFreeApplyDJT( + const core::MechanicalParams* mparams, Real kFactor, + Data>& parentForce, + const Data>& parentDisplacement, + const Data>& childForce) { - SOFA_UNUSED(cparams); - auto childMatRa = sofa::helper::getReadAccessor(in); - auto parentMatWa = sofa::helper::getWriteAccessor(out); - addMultTransposeEigen(parentMatWa.wref(), jacobian.compressedMatrix, childMatRa.ref()); -} + SOFA_UNUSED(mparams); -template -void VolumeMapping::applyDJT(const core::MechanicalParams* mparams, - core::MultiVecDerivId parentForceId, core::ConstMultiVecDerivId childForceId) -{ if (!m_vertices) { return; } - const unsigned geometricStiffness = d_geometricStiffness.getValue().getSelectedId(); - if( !geometricStiffness ) - { - return; - } + const unsigned geometricStiffness = this->d_geometricStiffness.getValue().getSelectedId(); - helper::WriteAccessor > > parentForceAccessor(*parentForceId[this->fromModel.get()].write()); - helper::ReadAccessor > > parentDisplacementAccessor(*mparams->readDx(this->fromModel.get())); - const SReal kFactor = mparams->kFactor(); - helper::ReadAccessor > > childForceAccessor(mparams->readF(this->toModel.get())); + helper::WriteAccessor parentForceAccessor(parentForce); + helper::ReadAccessor parentDisplacementAccessor(parentDisplacement); + helper::ReadAccessor childForceAccessor(childForce); - if( K.compressedMatrix.nonZeros() ) - { - K.addMult( parentForceAccessor.wref(), parentDisplacementAccessor.ref(), (typename In::Real)kFactor ); - } - else + const auto& tetrahedra = l_topology->getTetrahedra(); + for (unsigned int tetId = 0; tetId < tetrahedra.size(); ++tetId) { - const auto& tetrahedra = l_topology->getTetrahedra(); - for (unsigned int tetId = 0; tetId < tetrahedra.size(); ++tetId) - { - const Deriv_t& childForceTetra = childForceAccessor[tetId]; + const Deriv_t& childForceTetra = childForceAccessor[tetId]; - if( childForceTetra[0] < 0 || geometricStiffness==1 ) - { - const auto& tetra = tetrahedra[tetId]; + if( childForceTetra[0] < 0 || geometricStiffness==1 ) + { + const auto& tetra = tetrahedra[tetId]; - const sofa::type::fixed_array, 4> v{ - (*m_vertices)[tetra[0]], - (*m_vertices)[tetra[1]], - (*m_vertices)[tetra[2]], - (*m_vertices)[tetra[3]], - }; + const sofa::type::fixed_array, 4> v{ + (*m_vertices)[tetra[0]], + (*m_vertices)[tetra[1]], + (*m_vertices)[tetra[2]], + (*m_vertices)[tetra[3]], + }; - //it's a 4x4 matrix, where each entry is a 3x3 matrix - const auto d2Vol_d2x = computeSecondDerivativeVolume(v); + //it's a 4x4 matrix, where each entry is a 3x3 matrix + const auto d2Vol_d2x = computeSecondDerivativeVolume(v); - for (unsigned int i = 0; i < 4; ++i) + for (unsigned int i = 0; i < 4; ++i) + { + for (unsigned int j = i + 1; j < 4; ++j) //diagonal terms are omitted because they are null { - for (unsigned int j = i + 1; j < 4; ++j) //diagonal terms are omitted because they are null - { - parentForceAccessor[tetra[i]] += + parentForceAccessor[tetra[i]] += kFactor * d2Vol_d2x(i, j) * parentDisplacementAccessor[tetra[j]] * childForceTetra[0]; - //transpose - parentForceAccessor[tetra[j]] += + //transpose + parentForceAccessor[tetra[j]] += kFactor * d2Vol_d2x(j, i) * parentDisplacementAccessor[tetra[i]] * childForceTetra[0]; - } } } } @@ -282,26 +240,20 @@ void VolumeMapping::applyDJT(const core::MechanicalParams* mparams, } template -void VolumeMapping::updateK(const core::MechanicalParams* mparams, - core::ConstMultiVecDerivId childForceId) +void VolumeMapping::doUpdateK(const core::MechanicalParams* mparams, + const Data>& childForce, SparseKMatrixEigen& matrix) { SOFA_UNUSED(mparams); - const unsigned geometricStiffness = d_geometricStiffness.getValue().getSelectedId(); - if( !geometricStiffness ) { K.resize(0,0); return; } + const unsigned geometricStiffness = this->d_geometricStiffness.getValue().getSelectedId(); - helper::ReadAccessor > > childForce( *childForceId[this->toModel.get()].read() ); - - { - unsigned int kSize = this->fromModel->getSize(); - K.resizeBlocks(kSize, kSize); - } + const helper::ReadAccessor childForceAccessor(childForce); const auto& tetrahedra = l_topology->getTetrahedra(); for (unsigned int tetId = 0; tetId < tetrahedra.size(); ++tetId) { - const Deriv_t& childForceTri = childForce[tetId]; + const Deriv_t& childForceTetra = childForceAccessor[tetId]; - if( childForceTri[0] < 0 || geometricStiffness==1 ) + if( childForceTetra[0] < 0 || geometricStiffness==1 ) { const auto& tetra = tetrahedra[tetId]; @@ -319,27 +271,19 @@ void VolumeMapping::updateK(const core::MechanicalParams* mparams, { for (unsigned int j = i+1; j < 4; ++j) //diagonal terms are omitted because they are null { - K.addBlock(tetra[i], tetra[j], d2Volume_d2x(i, j) * childForceTri[0]); - K.addBlock(tetra[j], tetra[i], d2Volume_d2x(j, i) * childForceTri[0]); + matrix.addBlock(tetra[i], tetra[j], d2Volume_d2x(i, j) * childForceTetra[0]); + matrix.addBlock(tetra[j], tetra[i], d2Volume_d2x(j, i) * childForceTetra[0]); } } } } - - K.compress(); -} - -template -const linearalgebra::BaseMatrix* VolumeMapping::getK() -{ - return &K; } template void VolumeMapping::buildGeometricStiffnessMatrix( sofa::core::GeometricStiffnessMatrix* matrices) { - const unsigned& geometricStiffness = d_geometricStiffness.getValue().getSelectedId(); + const unsigned& geometricStiffness = this->d_geometricStiffness.getValue().getSelectedId(); if( !geometricStiffness ) { return; @@ -380,11 +324,5 @@ void VolumeMapping::buildGeometricStiffnessMatrix( } -template -const type::vector* VolumeMapping:: -getJs() -{ - return &baseMatrices; -} } diff --git a/Sofa/Component/Mapping/NonLinear/tests/AreaMapping_test.cpp b/Sofa/Component/Mapping/NonLinear/tests/AreaMapping_test.cpp index 72e7deb9e5e..1325b49c451 100644 --- a/Sofa/Component/Mapping/NonLinear/tests/AreaMapping_test.cpp +++ b/Sofa/Component/Mapping/NonLinear/tests/AreaMapping_test.cpp @@ -69,7 +69,6 @@ TEST(AreaMapping, firstDerivative) const sofa::type::Mat<3,3,SReal> dA = computeDerivativeArea(vertices); - static constexpr SReal h = 1e-6; for (unsigned int vId = 0; vId < 3; ++vId) { for (unsigned int axis = 0; axis < 3; ++axis) diff --git a/Sofa/Component/Mapping/NonLinear/tests/SquareMapping_test.cpp b/Sofa/Component/Mapping/NonLinear/tests/SquareMapping_test.cpp index ab49b58673c..66479a8c324 100644 --- a/Sofa/Component/Mapping/NonLinear/tests/SquareMapping_test.cpp +++ b/Sofa/Component/Mapping/NonLinear/tests/SquareMapping_test.cpp @@ -84,15 +84,5 @@ TYPED_TEST( SquareMappingTest , test ) ASSERT_TRUE(this->test()); } -TYPED_TEST( SquareMappingTest , testNoGeometricStiffnessMatrix ) -{ - TypeParam* map = static_cast( this->mapping ); - map->d_useGeometricStiffnessMatrix.setValue(false); - - ASSERT_TRUE(this->test()); -} - - - } // namespace } // namespace sofa diff --git a/Sofa/Component/Mapping/NonLinear/tests/VolumeMapping_test.cpp b/Sofa/Component/Mapping/NonLinear/tests/VolumeMapping_test.cpp index 26248638920..7a9f7d8b0c7 100644 --- a/Sofa/Component/Mapping/NonLinear/tests/VolumeMapping_test.cpp +++ b/Sofa/Component/Mapping/NonLinear/tests/VolumeMapping_test.cpp @@ -74,7 +74,6 @@ TEST(VolumeMapping, firstDerivative) const sofa::type::Mat<4,3,SReal> dV = computeDerivativeVolume(vertices); - static constexpr SReal h = 1e-6; for (unsigned int vId = 0; vId < 4; ++vId) { for (unsigned int axis = 0; axis < 3; ++axis) diff --git a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixConstraintEigenUtils.h b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixConstraintEigenUtils.h index dfdb2afd0c8..88da4face8e 100644 --- a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixConstraintEigenUtils.h +++ b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixConstraintEigenUtils.h @@ -19,6 +19,7 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ +#pragma once #include #include #include From 675d752fabba490dddeea31ce4256523e19aa8f9 Mon Sep 17 00:00:00 2001 From: Hugo Date: Wed, 2 Oct 2024 05:06:12 +0200 Subject: [PATCH 08/43] [examples] Update example scene of RungeKutta to make it stable (#5036) * [examples] Update example scene of RungeKutta to make it stable * remove warnings and add as a regression --- examples/Component/ODESolver/Forward/RungeKutta4Solver.scn | 6 +++--- examples/RegressionStateScenes.regression-tests | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/Component/ODESolver/Forward/RungeKutta4Solver.scn b/examples/Component/ODESolver/Forward/RungeKutta4Solver.scn index c45ca8d11f1..05fd84a1003 100644 --- a/examples/Component/ODESolver/Forward/RungeKutta4Solver.scn +++ b/examples/Component/ODESolver/Forward/RungeKutta4Solver.scn @@ -1,5 +1,5 @@ - + @@ -14,13 +14,13 @@ - + - + diff --git a/examples/RegressionStateScenes.regression-tests b/examples/RegressionStateScenes.regression-tests index 64f9119959e..9c28cd6161b 100644 --- a/examples/RegressionStateScenes.regression-tests +++ b/examples/RegressionStateScenes.regression-tests @@ -56,6 +56,7 @@ Component/Mass/MeshMatrixMass.scn 100 1e-4 0 1 Component/MechanicalLoad/InteractionEllipsoidForceField.scn 100 1e-4 0 1 Component/ODESolver/Forward/EulerExplicitSolver.scn 3000 1e-4 0 1 Component/ODESolver/Forward/EulerExplicitSolver_diagonal.scn 3000 1e-4 0 1 +Component/ODESolver/Forward/RungeKutta4Solver.scn 3000 1e-4 0 1 Component/ODESolver/Backward/EulerImplicitSolver.scn 3000 1e-4 0 1 Component/SolidMechanics/FEM/BeamFEMForceField.scn 100 1e-4 0 1 Component/SolidMechanics/FEM/HexahedronFEMForceField.scn 300 1e-4 0 1 From fcd78a723bd497bda3affeceeb9a26980d957f74 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Wed, 2 Oct 2024 20:36:20 +0900 Subject: [PATCH 09/43] [Engine] Apply new factory registration mechanism (#5010) * apply new register mechanism to engine * Apply suggestions from code review (updates on component description) Co-authored-by: Hugo * Update PairBoxRoi.cpp (remove useless comment) --------- Co-authored-by: Hugo --- .../component/engine/analyze/AverageCoord.cpp | 10 ++-- .../engine/analyze/ClusteringEngine.cpp | 9 ++-- .../component/engine/analyze/Distances.cpp | 9 ++-- .../engine/analyze/HausdorffDistance.cpp | 9 ++-- .../engine/analyze/ShapeMatching.cpp | 9 ++-- .../component/engine/analyze/SumEngine.cpp | 10 ++-- .../sofa/component/engine/analyze/init.cpp | 25 ++++++++- .../generate/ExtrudeEdgesAndGenerateQuads.cpp | 11 ++-- .../generate/ExtrudeQuadsAndGenerateHexas.cpp | 11 ++-- .../engine/generate/ExtrudeSurface.cpp | 11 ++-- .../engine/generate/GenerateCylinder.cpp | 12 ++--- .../engine/generate/GenerateGrid.cpp | 12 ++--- .../engine/generate/GenerateRigidMass.cpp | 10 ++-- .../engine/generate/GenerateSphere.cpp | 12 ++--- .../generate/GroupFilterYoungModulus.cpp | 11 ++-- .../component/engine/generate/JoinPoints.cpp | 10 ++-- .../component/engine/generate/MergeMeshes.cpp | 11 ++-- .../component/engine/generate/MergePoints.cpp | 11 ++-- .../component/engine/generate/MergeSets.cpp | 12 ++--- .../engine/generate/MergeVectors.cpp | 32 ++++++----- .../generate/MeshBarycentricMapperEngine.cpp | 12 ++--- .../engine/generate/MeshClosingEngine.cpp | 10 ++-- .../engine/generate/MeshTetraStuffing.cpp | 8 +-- .../component/engine/generate/NormEngine.cpp | 10 ++-- .../engine/generate/NormalsFromPoints.cpp | 11 ++-- .../RandomPointDistributionInSurface.cpp | 11 ++-- .../sofa/component/engine/generate/Spiral.cpp | 11 ++-- .../sofa/component/engine/generate/init.cpp | 53 ++++++++++++++++++- .../sofa/component/engine/select/BoxROI.cpp | 19 ++++--- .../engine/select/ComplementaryROI.cpp | 10 ++-- .../engine/select/IndicesFromValues.cpp | 18 ++----- .../component/engine/select/MergeROIs.cpp | 8 +-- .../engine/select/MeshBoundaryROI.cpp | 7 ++- .../sofa/component/engine/select/MeshROI.cpp | 11 ++-- .../component/engine/select/MeshSampler.cpp | 12 ++--- .../engine/select/MeshSplittingEngine.cpp | 10 ++-- .../engine/select/MeshSubsetEngine.cpp | 10 ++-- .../engine/select/NearestPointROI.cpp | 9 ++-- .../component/engine/select/PairBoxRoi.cpp | 15 +++--- .../sofa/component/engine/select/PlaneROI.cpp | 11 ++-- .../engine/select/PointsFromIndices.cpp | 13 ++--- .../component/engine/select/ProximityROI.cpp | 12 ++--- .../select/SelectConnectedLabelsROI.cpp | 8 +-- .../engine/select/SelectLabelROI.cpp | 8 +-- .../component/engine/select/SphereROI.cpp | 10 ++-- .../engine/select/SubsetTopology.cpp | 11 ++-- .../engine/select/ValuesFromIndices.cpp | 10 ++-- .../engine/select/ValuesFromPositions.cpp | 11 ++-- .../src/sofa/component/engine/select/init.cpp | 53 ++++++++++++++++++- .../engine/transform/DifferenceEngine.cpp | 10 ++-- .../engine/transform/DilateEngine.cpp | 8 +-- .../transform/DisplacementMatrixEngine.cpp | 10 ++-- .../engine/transform/IndexValueMapper.cpp | 11 ++-- .../engine/transform/Indices2ValuesMapper.cpp | 11 ++-- .../engine/transform/Indices2ValuesMapper.inl | 1 - .../component/engine/transform/MapIndices.cpp | 8 +-- .../component/engine/transform/MathOp.cpp | 28 +++++----- .../transform/ProjectiveTransformEngine.cpp | 9 ++-- .../engine/transform/QuatToRigidEngine.cpp | 11 ++-- .../engine/transform/ROIValueMapper.cpp | 11 ++-- .../engine/transform/RigidToQuatEngine.cpp | 12 ++--- .../engine/transform/SmoothMeshEngine.cpp | 11 ++-- .../engine/transform/TransformEngine.cpp | 9 ++-- .../transform/TransformMatrixEngine.cpp | 28 +++++++--- .../engine/transform/TransformPosition.cpp | 10 ++-- .../engine/transform/Vertex2Frame.cpp | 11 ++-- .../sofa/component/engine/transform/init.cpp | 50 +++++++++++++++++ .../Engine/src/sofa/component/engine/init.cpp | 15 ++++++ Sofa/Component/src/sofa/component/init.cpp | 1 + .../src/sofa/helper/ComponentChange.cpp | 1 + 70 files changed, 549 insertions(+), 366 deletions(-) diff --git a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/AverageCoord.cpp b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/AverageCoord.cpp index 4daba0bc2c4..9644f4769cf 100644 --- a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/AverageCoord.cpp +++ b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/AverageCoord.cpp @@ -30,14 +30,14 @@ namespace sofa::component::engine::analyze using namespace sofa::defaulttype; -int AverageCoordClass = core::RegisterObject("Compute the average of coordinates") +void registerAverageCoord(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Compute the average of coordinates.") .add< AverageCoord >() .add< AverageCoord >() .add< AverageCoord >() - .add< AverageCoord >() - - ; - + .add< AverageCoord >()); +} template class SOFA_COMPONENT_ENGINE_ANALYZE_API AverageCoord; template class SOFA_COMPONENT_ENGINE_ANALYZE_API AverageCoord; diff --git a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/ClusteringEngine.cpp b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/ClusteringEngine.cpp index 067d8b32fb1..5f8f1b112b3 100644 --- a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/ClusteringEngine.cpp +++ b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/ClusteringEngine.cpp @@ -29,10 +29,11 @@ namespace sofa::component::engine::analyze using namespace sofa::defaulttype; -int ClusteringEngineClass = core::RegisterObject("Group points into overlapping clusters according to a user defined number of clusters and radius") - .add< ClusteringEngine >() - - ; +void registerClusteringEngine(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Group points into overlapping clusters according to a user defined number of clusters and radius.") + .add< ClusteringEngine >()); +} template class SOFA_COMPONENT_ENGINE_ANALYZE_API ClusteringEngine; diff --git a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/Distances.cpp b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/Distances.cpp index c1becb4944f..50519602b29 100644 --- a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/Distances.cpp +++ b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/Distances.cpp @@ -30,10 +30,11 @@ namespace sofa::component::engine::analyze using namespace sofa::defaulttype; -int DistancesClass = core::RegisterObject("Compute distances based on a grid.") - .add< Distances >() - - ; +void registerDistances(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Compute distances based on a grid.") + .add< Distances >()); +} template class SOFA_COMPONENT_ENGINE_ANALYZE_API Distances; diff --git a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/HausdorffDistance.cpp b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/HausdorffDistance.cpp index fc2b4e88b8a..31260f7ca45 100644 --- a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/HausdorffDistance.cpp +++ b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/HausdorffDistance.cpp @@ -30,14 +30,15 @@ namespace sofa::component::engine::analyze using namespace sofa::defaulttype; -int HausdorffDistanceClass = core::RegisterObject("Compute the Hausdorff distance of two point clouds") +void registerHausdorffDistance(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Compute the Hausdorff distance of two point clouds.") .add< HausdorffDistance >() .add< HausdorffDistance >() .add< HausdorffDistance >(true) .add< HausdorffDistance >() - .add< HausdorffDistance >() - - ; + .add< HausdorffDistance >()); +} template class SOFA_COMPONENT_ENGINE_ANALYZE_API HausdorffDistance; template class SOFA_COMPONENT_ENGINE_ANALYZE_API HausdorffDistance; diff --git a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/ShapeMatching.cpp b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/ShapeMatching.cpp index 7df2dff0f3e..07bec50db9f 100644 --- a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/ShapeMatching.cpp +++ b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/ShapeMatching.cpp @@ -32,11 +32,12 @@ namespace sofa::component::engine::analyze using namespace defaulttype; -int ShapeMatchingClass = core::RegisterObject("Compute target positions using shape matching deformation method by Mueller et al.") +void registerShapeMatching(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Compute target positions using shape matching deformation method by Mueller et al.") .add< ShapeMatching >() - .add< ShapeMatching >() - - ; + .add< ShapeMatching >()); +} template class SOFA_COMPONENT_ENGINE_ANALYZE_API ShapeMatching; template class SOFA_COMPONENT_ENGINE_ANALYZE_API ShapeMatching; diff --git a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/SumEngine.cpp b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/SumEngine.cpp index 44e23a40712..6f42adf8dce 100644 --- a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/SumEngine.cpp +++ b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/SumEngine.cpp @@ -27,13 +27,13 @@ namespace sofa::component::engine::analyze { using namespace sofa::type; -using namespace sofa::defaulttype; -int SumEngineClass = core::RegisterObject("Computing the Sum between two vector of dofs") +void registerSumEngine(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Computing the sum between two vector of dofs.") .add< SumEngine >() - .add< SumEngine >(true) // default template - - ; + .add< SumEngine >(true)); +} template class SOFA_COMPONENT_ENGINE_ANALYZE_API SumEngine; template class SOFA_COMPONENT_ENGINE_ANALYZE_API SumEngine; diff --git a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/init.cpp b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/init.cpp index 3cb16116d29..636efc80782 100644 --- a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/init.cpp +++ b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/init.cpp @@ -21,13 +21,23 @@ ******************************************************************************/ #include #include +#include + namespace sofa::component::engine::analyze { - + +extern void registerAverageCoord(sofa::core::ObjectFactory* factory); +extern void registerClusteringEngine(sofa::core::ObjectFactory* factory); +extern void registerDistances(sofa::core::ObjectFactory* factory); +extern void registerHausdorffDistance(sofa::core::ObjectFactory* factory); +extern void registerShapeMatching(sofa::core::ObjectFactory* factory); +extern void registerSumEngine(sofa::core::ObjectFactory* factory); + extern "C" { SOFA_EXPORT_DYNAMIC_LIBRARY void initExternalModule(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleName(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleVersion(); + SOFA_EXPORT_DYNAMIC_LIBRARY void registerObjects(sofa::core::ObjectFactory* factory); } void initExternalModule() @@ -45,11 +55,24 @@ const char* getModuleVersion() return MODULE_VERSION; } +void registerObjects(sofa::core::ObjectFactory* factory) +{ + registerAverageCoord(factory); + registerClusteringEngine(factory); + registerDistances(factory); + registerHausdorffDistance(factory); + registerShapeMatching(factory); + registerSumEngine(factory); +} + void init() { static bool first = true; if (first) { + // make sure that this plugin is registered into the PluginManager + sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME); + first = false; } } diff --git a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/ExtrudeEdgesAndGenerateQuads.cpp b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/ExtrudeEdgesAndGenerateQuads.cpp index 95baaf1f2d4..08672cf543d 100644 --- a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/ExtrudeEdgesAndGenerateQuads.cpp +++ b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/ExtrudeEdgesAndGenerateQuads.cpp @@ -29,13 +29,12 @@ namespace sofa::component::engine::generate using namespace sofa::defaulttype; -int ExtrudeEdgesAndGenerateQuadsClass = core::RegisterObject("This engine extrudes an edge-based curve into a quad surface patch") - .add< ExtrudeEdgesAndGenerateQuads >(true) // default template - - ; +void registerExtrudeEdgesAndGenerateQuads(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Engine extruding an edge-based curve into a quad surface patch.") + .add< ExtrudeEdgesAndGenerateQuads >(true)); +} template class SOFA_COMPONENT_ENGINE_GENERATE_API ExtrudeEdgesAndGenerateQuads; - - } //namespace sofa::component::engine::generate diff --git a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/ExtrudeQuadsAndGenerateHexas.cpp b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/ExtrudeQuadsAndGenerateHexas.cpp index 76f27e4a39b..51fa444c9ad 100644 --- a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/ExtrudeQuadsAndGenerateHexas.cpp +++ b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/ExtrudeQuadsAndGenerateHexas.cpp @@ -29,13 +29,12 @@ namespace sofa::component::engine::generate using namespace sofa::defaulttype; -int ExtrudeQuadsAndGenerateHexasClass = core::RegisterObject("This engine extrudes a quad-based surface into a set of hexahedral elements") - .add< ExtrudeQuadsAndGenerateHexas >() - - ; +void registerExtrudeQuadsAndGenerateHexas(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Engine extruding a quad-based surface into a set of hexahedral elements.") + .add< ExtrudeQuadsAndGenerateHexas >()); +} template class SOFA_COMPONENT_ENGINE_GENERATE_API ExtrudeQuadsAndGenerateHexas; - - } //namespace sofa::component::engine::generate diff --git a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/ExtrudeSurface.cpp b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/ExtrudeSurface.cpp index 4a2101dea77..725c0f67d8e 100644 --- a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/ExtrudeSurface.cpp +++ b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/ExtrudeSurface.cpp @@ -30,13 +30,12 @@ namespace sofa::component::engine::generate using namespace sofa::defaulttype; -int ExtrudeSurfaceClass = core::RegisterObject("This class truns on spiral any topological model") - .add< ExtrudeSurface >() - - ; +void registerExtrudeSurface(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Engine creating a mesh from the extrusion of the surface of a given mesh.") + .add< ExtrudeSurface >()); +} template class SOFA_COMPONENT_ENGINE_GENERATE_API ExtrudeSurface; - - } //namespace sofa::component::engine::generate diff --git a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/GenerateCylinder.cpp b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/GenerateCylinder.cpp index 88b9afadceb..ddbc3208fe7 100644 --- a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/GenerateCylinder.cpp +++ b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/GenerateCylinder.cpp @@ -28,14 +28,12 @@ namespace sofa::component::engine::generate { using namespace sofa::defaulttype; -int GenerateCylinderClass = core::RegisterObject("Generate a Cylindrical Tetrahedral Mesh") - .add< GenerateCylinder >() - - ; - +void registerGenerateCylinder(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Engine generating a cylindrical tetrahedral mesh.") + .add< GenerateCylinder >()); +} template class SOFA_COMPONENT_ENGINE_GENERATE_API GenerateCylinder; - - } //namespace sofa::component::engine::generate diff --git a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/GenerateGrid.cpp b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/GenerateGrid.cpp index 7c630069faf..1fc515fe15b 100644 --- a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/GenerateGrid.cpp +++ b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/GenerateGrid.cpp @@ -28,16 +28,14 @@ namespace sofa::component::engine::generate { using namespace sofa::defaulttype; -int GenerateGridClass = core::RegisterObject("Generate a Grid Tetrahedral or Hexahedral Mesh") +void registerGenerateGrid(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Engine generating a grid tetrahedral or hexahedral mesh.") .add< GenerateGrid >() - .add< GenerateGrid >() - - ; - + .add< GenerateGrid >()); +} template class SOFA_COMPONENT_ENGINE_GENERATE_API GenerateGrid; template class SOFA_COMPONENT_ENGINE_GENERATE_API GenerateGrid; - - } //namespace sofa::component::engine::generate diff --git a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/GenerateRigidMass.cpp b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/GenerateRigidMass.cpp index f8374e99e33..27faf76ec6b 100644 --- a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/GenerateRigidMass.cpp +++ b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/GenerateRigidMass.cpp @@ -29,12 +29,12 @@ namespace sofa::component::engine::generate using namespace sofa::defaulttype; -int GenerateRigidMassClass = core::RegisterObject("An engine computing the RigidMass of a mesh : mass, volume and inertia matrix.") - .add< GenerateRigidMass >() - - ; +void registerGenerateRigidMass(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Engine computing the RigidMass of a mesh: mass, volume and inertia matrix.") + .add< GenerateRigidMass >()); +} template class SOFA_COMPONENT_ENGINE_GENERATE_API GenerateRigidMass; - } //namespace sofa::component::engine::generate diff --git a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/GenerateSphere.cpp b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/GenerateSphere.cpp index bb03b81213f..5d165d2f487 100644 --- a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/GenerateSphere.cpp +++ b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/GenerateSphere.cpp @@ -28,14 +28,12 @@ namespace sofa::component::engine::generate { using namespace sofa::defaulttype; -int GenerateSphereClass = core::RegisterObject("Generate a sphereical (Bezier) Tetrahedral and Triangular Mesh") - .add< GenerateSphere >() - - ; - +void registerGenerateSphere(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Engine generating a spherical (Bezier) tetrahedral and triangular mesh.") + .add< GenerateSphere >()); +} template class SOFA_COMPONENT_ENGINE_GENERATE_API GenerateSphere; - - } //namespace sofa::component::engine::generate diff --git a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/GroupFilterYoungModulus.cpp b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/GroupFilterYoungModulus.cpp index 16635fb67f9..6ecd9ecbb31 100644 --- a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/GroupFilterYoungModulus.cpp +++ b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/GroupFilterYoungModulus.cpp @@ -30,13 +30,12 @@ namespace sofa::component::engine::generate using namespace sofa::defaulttype; -int GroupFilterYoungModulusClass = core::RegisterObject("This class gives a vector of young modulus according of a list of defined groups") - .add< GroupFilterYoungModulus >() - - ; +void registerGroupFilterYoungModulus(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Engine defining a vector of young modulus according of a list of defined groups.") + .add< GroupFilterYoungModulus >()); +} template class SOFA_COMPONENT_ENGINE_GENERATE_API GroupFilterYoungModulus; - - } //namespace sofa::component::engine::generate diff --git a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/JoinPoints.cpp b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/JoinPoints.cpp index 378457abb9e..f83efab3d85 100644 --- a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/JoinPoints.cpp +++ b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/JoinPoints.cpp @@ -29,12 +29,12 @@ namespace sofa::component::engine::generate using namespace sofa::defaulttype; -int JoinPointsClass = core::RegisterObject("?") - .add< JoinPoints >() - - ; +void registerJoinPoints(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Merge points from a set of points within a given distance.") + .add< JoinPoints >()); +} template class SOFA_COMPONENT_ENGINE_GENERATE_API JoinPoints; - } //namespace sofa::component::engine::generate diff --git a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MergeMeshes.cpp b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MergeMeshes.cpp index 29a8ecfd356..d4396922807 100644 --- a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MergeMeshes.cpp +++ b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MergeMeshes.cpp @@ -26,21 +26,20 @@ namespace sofa::component::engine::generate { -int MergeMeshesClass = core::RegisterObject("Merge several meshes") +void registerMergeMeshes(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Merge several meshes.") .add< MergeMeshes >(true) // default template .add< MergeMeshes >() .add< MergeMeshes >() .add< MergeMeshes >() - .add< MergeMeshes >() - - ; + .add< MergeMeshes >()); +} template class SOFA_COMPONENT_ENGINE_GENERATE_API MergeMeshes; template class SOFA_COMPONENT_ENGINE_GENERATE_API MergeMeshes; template class SOFA_COMPONENT_ENGINE_GENERATE_API MergeMeshes; template class SOFA_COMPONENT_ENGINE_GENERATE_API MergeMeshes; template class SOFA_COMPONENT_ENGINE_GENERATE_API MergeMeshes; - - } //namespace sofa::component::engine::generate diff --git a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MergePoints.cpp b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MergePoints.cpp index b728739c584..249bce47218 100644 --- a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MergePoints.cpp +++ b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MergePoints.cpp @@ -26,14 +26,15 @@ namespace sofa::component::engine::generate { -int MergePointsClass = core::RegisterObject("Merge 2 cordinate vectors") +void registerMergePoints(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Merge 2 cordinate vectors.") .add< MergePoints >(true) // default template .add< MergePoints >() .add< MergePoints >() .add< MergePoints >() - .add< MergePoints >() - - ; + .add< MergePoints >()); +} template class SOFA_COMPONENT_ENGINE_GENERATE_API MergePoints; template class SOFA_COMPONENT_ENGINE_GENERATE_API MergePoints; @@ -41,6 +42,4 @@ template class SOFA_COMPONENT_ENGINE_GENERATE_API MergePoints; template class SOFA_COMPONENT_ENGINE_GENERATE_API MergePoints; - - } //namespace sofa::component::engine::generate diff --git a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MergeSets.cpp b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MergeSets.cpp index 584a7783d86..9e1d7602737 100644 --- a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MergeSets.cpp +++ b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MergeSets.cpp @@ -26,16 +26,14 @@ namespace sofa::component::engine::generate { -int MergeSetsClass = core::RegisterObject("Merge two sets of indices using specified boolean operation") +void registerMergeSets(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Merge two sets of indices using specified boolean operation.") .add< MergeSets >(true) - .add< MergeSets >() -//.add< MergeSets >() -//.add< MergeSets >() - ; + .add< MergeSets >()); +} template class SOFA_COMPONENT_ENGINE_GENERATE_API MergeSets; template class SOFA_COMPONENT_ENGINE_GENERATE_API MergeSets; -//template class SOFA_COMPONENT_ENGINE_GENERATE_API MergeSets; -//template class SOFA_COMPONENT_ENGINE_GENERATE_API MergeSets; } //namespace sofa::component::engine::generate diff --git a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MergeVectors.cpp b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MergeVectors.cpp index 98e469fc86d..669b954ce31 100644 --- a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MergeVectors.cpp +++ b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MergeVectors.cpp @@ -26,25 +26,25 @@ namespace sofa::component::engine::generate { -int MergeVectorsClass = core::RegisterObject("Apply a merge operation to combine several inputs") - .add< MergeVectors< type::vector > >(true) - .add< MergeVectors< type::vector > >() - .add< MergeVectors< type::vector > >() - //.add< MergeVectors< type::vector > >() - .add< MergeVectors< type::vector > >() - .add< MergeVectors< type::vector > >() - .add< MergeVectors< type::vector > >() - .add< MergeVectors< type::vector > >() - .add< MergeVectors< defaulttype::Rigid2Types::VecCoord > >() - .add< MergeVectors< defaulttype::Rigid2Types::VecDeriv > >() - .add< MergeVectors< defaulttype::Rigid3Types::VecCoord > >() - .add< MergeVectors< defaulttype::Rigid3Types::VecDeriv > >(); - +void registerMergeVectors(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Apply a merge operation to combine several inputs.") + .add< MergeVectors< type::vector > >(true) + .add< MergeVectors< type::vector > >() + .add< MergeVectors< type::vector > >() + .add< MergeVectors< type::vector > >() + .add< MergeVectors< type::vector > >() + .add< MergeVectors< type::vector > >() + .add< MergeVectors< type::vector > >() + .add< MergeVectors< defaulttype::Rigid2Types::VecCoord > >() + .add< MergeVectors< defaulttype::Rigid2Types::VecDeriv > >() + .add< MergeVectors< defaulttype::Rigid3Types::VecCoord > >() + .add< MergeVectors< defaulttype::Rigid3Types::VecDeriv > >()); +} template class SOFA_COMPONENT_ENGINE_GENERATE_API MergeVectors< type::vector >; template class SOFA_COMPONENT_ENGINE_GENERATE_API MergeVectors< type::vector >; template class SOFA_COMPONENT_ENGINE_GENERATE_API MergeVectors< type::vector >; - template class SOFA_COMPONENT_ENGINE_GENERATE_API MergeVectors< type::vector >; template class SOFA_COMPONENT_ENGINE_GENERATE_API MergeVectors< type::vector >; template class SOFA_COMPONENT_ENGINE_GENERATE_API MergeVectors< type::vector >; @@ -54,6 +54,4 @@ template class SOFA_COMPONENT_ENGINE_GENERATE_API MergeVectors< defaulttype::Rig template class SOFA_COMPONENT_ENGINE_GENERATE_API MergeVectors< defaulttype::Rigid3Types::VecCoord >; template class SOFA_COMPONENT_ENGINE_GENERATE_API MergeVectors< defaulttype::Rigid3Types::VecDeriv >; - - } //namespace sofa::component::engine::generate diff --git a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MeshBarycentricMapperEngine.cpp b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MeshBarycentricMapperEngine.cpp index c36ff11f4ca..d85c0b5d9d5 100644 --- a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MeshBarycentricMapperEngine.cpp +++ b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MeshBarycentricMapperEngine.cpp @@ -30,14 +30,12 @@ namespace sofa::component::engine::generate { using namespace sofa::defaulttype; -int MeshBarycentricMapperEngineClass = core::RegisterObject("This class maps a set of points in a topological model and provide barycentric coordinates") - .add< MeshBarycentricMapperEngine >() - - ; +void registerMeshBarycentricMapperEngine(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Engine mapping a set of points in a topological model and provide barycentric coordinates") + .add< MeshBarycentricMapperEngine >()); +} template class SOFA_COMPONENT_ENGINE_GENERATE_API MeshBarycentricMapperEngine; - - - } //namespace sofa::component::engine::generate diff --git a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MeshClosingEngine.cpp b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MeshClosingEngine.cpp index 5970a2ad90b..60697748f86 100644 --- a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MeshClosingEngine.cpp +++ b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MeshClosingEngine.cpp @@ -26,12 +26,12 @@ namespace sofa::component::engine::generate { -int MeshClosingEngineClass = core::RegisterObject("Merge several meshes") - .add< MeshClosingEngine >(true) // default template - ; +void registerMeshClosingEngine(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Close a given mesh.") + .add< MeshClosingEngine >()); +} template class SOFA_COMPONENT_ENGINE_GENERATE_API MeshClosingEngine; - - } //namespace sofa::component::engine::generate diff --git a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MeshTetraStuffing.cpp b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MeshTetraStuffing.cpp index 7b40eb82e63..2afe7cb5456 100644 --- a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MeshTetraStuffing.cpp +++ b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/MeshTetraStuffing.cpp @@ -34,9 +34,11 @@ namespace sofa::component::engine::generate using namespace sofa::defaulttype; using type::vector; -int MeshTetraStuffingClass = core::RegisterObject("Create a tetrahedral volume mesh from a surface, using the algorithm from F. Labelle and J.R. Shewchuk, \"Isosurface Stuffing: Fast Tetrahedral Meshes with Good Dihedral Angles\", SIGGRAPH 2007.") - .add< MeshTetraStuffing >() - ; +void registerMeshTetraStuffing(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Create a tetrahedral volume mesh from a surface, using the algorithm from F. Labelle and J.R. Shewchuk, \"Isosurface Stuffing: Fast Tetrahedral Meshes with Good Dihedral Angles\", SIGGRAPH 2007.") + .add< MeshTetraStuffing >()); +} MeshTetraStuffing::MeshTetraStuffing() : d_vbbox(initData(&d_vbbox, "vbbox", "BBox to restrict the volume to")) diff --git a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/NormEngine.cpp b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/NormEngine.cpp index 09ca7eec731..de24c00ec14 100644 --- a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/NormEngine.cpp +++ b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/NormEngine.cpp @@ -26,12 +26,12 @@ namespace sofa::component::engine::generate { -int NormEngineClass = core::RegisterObject("Convert Vec in Real") - .add< NormEngine >(true) // default template - - ; +void registerNormEngine(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Convert Vec in Real") + .add< NormEngine >()); +} template class SOFA_COMPONENT_ENGINE_GENERATE_API NormEngine; - } //namespace sofa::component::engine::generate diff --git a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/NormalsFromPoints.cpp b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/NormalsFromPoints.cpp index 8c9c6573bfa..953dbe0ef3d 100644 --- a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/NormalsFromPoints.cpp +++ b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/NormalsFromPoints.cpp @@ -29,13 +29,12 @@ namespace sofa::component::engine::generate using namespace sofa::defaulttype; -int NormalsFromPointsClass = core::RegisterObject("Compute vertex normals by averaging face normals") - .add< NormalsFromPoints >() - - ; +void registerNormalsFromPoints(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Compute vertex normals by averaging face normals.") + .add< NormalsFromPoints >()); +} template class SOFA_COMPONENT_ENGINE_GENERATE_API NormalsFromPoints; - - } //namespace sofa::component::engine::generate diff --git a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/RandomPointDistributionInSurface.cpp b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/RandomPointDistributionInSurface.cpp index c2ebee7f179..ead70d5312c 100644 --- a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/RandomPointDistributionInSurface.cpp +++ b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/RandomPointDistributionInSurface.cpp @@ -29,13 +29,12 @@ namespace sofa::component::engine::generate using namespace sofa::defaulttype; -int RandomPointDistributionInSurfaceClass = core::RegisterObject("This class truns on spiral any topological model") - .add< RandomPointDistributionInSurface >() - - ; +void registerRandomPointDistributionInSurface(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Engine distributing points over a surface randomly.") + .add< RandomPointDistributionInSurface >()); +} template class SOFA_COMPONENT_ENGINE_GENERATE_API RandomPointDistributionInSurface; - - } //namespace sofa::component::engine::generate diff --git a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/Spiral.cpp b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/Spiral.cpp index be857c442fe..541eea29c12 100644 --- a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/Spiral.cpp +++ b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/Spiral.cpp @@ -30,13 +30,12 @@ namespace sofa::component::engine::generate using namespace sofa::defaulttype; -int SpiralClass = core::RegisterObject("This class truns on spiral any topological model") - .add< Spiral >() - - ; +void registerSpiral(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Engine turning on spiral any topological model.") + .add< Spiral >()); +} template class SOFA_COMPONENT_ENGINE_GENERATE_API Spiral; - - } //namespace sofa::component::engine::generate diff --git a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/init.cpp b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/init.cpp index 84dbb29dcd0..9da9eda2c5e 100644 --- a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/init.cpp +++ b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/init.cpp @@ -21,13 +21,37 @@ ******************************************************************************/ #include #include +#include + namespace sofa::component::engine::generate { - + +extern void registerExtrudeEdgesAndGenerateQuads(sofa::core::ObjectFactory* factory); +extern void registerExtrudeQuadsAndGenerateHexas(sofa::core::ObjectFactory* factory); +extern void registerExtrudeSurface(sofa::core::ObjectFactory* factory); +extern void registerGenerateCylinder(sofa::core::ObjectFactory* factory); +extern void registerGenerateGrid(sofa::core::ObjectFactory* factory); +extern void registerGenerateRigidMass(sofa::core::ObjectFactory* factory); +extern void registerGenerateSphere(sofa::core::ObjectFactory* factory); +extern void registerGroupFilterYoungModulus(sofa::core::ObjectFactory* factory); +extern void registerJoinPoints(sofa::core::ObjectFactory* factory); +extern void registerMergeMeshes(sofa::core::ObjectFactory* factory); +extern void registerMergePoints(sofa::core::ObjectFactory* factory); +extern void registerMergeSets(sofa::core::ObjectFactory* factory); +extern void registerMergeVectors(sofa::core::ObjectFactory* factory); +extern void registerMeshBarycentricMapperEngine(sofa::core::ObjectFactory* factory); +extern void registerMeshClosingEngine(sofa::core::ObjectFactory* factory); +extern void registerMeshTetraStuffing(sofa::core::ObjectFactory* factory); +extern void registerNormalsFromPoints(sofa::core::ObjectFactory* factory); +extern void registerNormEngine(sofa::core::ObjectFactory* factory); +extern void registerRandomPointDistributionInSurface(sofa::core::ObjectFactory* factory); +extern void registerSpiral(sofa::core::ObjectFactory* factory); + extern "C" { SOFA_EXPORT_DYNAMIC_LIBRARY void initExternalModule(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleName(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleVersion(); + SOFA_EXPORT_DYNAMIC_LIBRARY void registerObjects(sofa::core::ObjectFactory* factory); } void initExternalModule() @@ -45,11 +69,38 @@ const char* getModuleVersion() return MODULE_VERSION; } +void registerObjects(sofa::core::ObjectFactory* factory) +{ + registerExtrudeEdgesAndGenerateQuads(factory); + registerExtrudeQuadsAndGenerateHexas(factory); + registerExtrudeSurface(factory); + registerGenerateCylinder(factory); + registerGenerateGrid(factory); + registerGenerateRigidMass(factory); + registerGenerateSphere(factory); + registerGroupFilterYoungModulus(factory); + registerJoinPoints(factory); + registerMergeMeshes(factory); + registerMergePoints(factory); + registerMergeSets(factory); + registerMergeVectors(factory); + registerMeshBarycentricMapperEngine(factory); + registerMeshClosingEngine(factory); + registerMeshTetraStuffing(factory); + registerNormalsFromPoints(factory); + registerNormEngine(factory); + registerRandomPointDistributionInSurface(factory); + registerSpiral(factory); +} + void init() { static bool first = true; if (first) { + // make sure that this plugin is registered into the PluginManager + sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME); + first = false; } } diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/BoxROI.cpp b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/BoxROI.cpp index 079bc76679c..919ce24a1e3 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/BoxROI.cpp +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/BoxROI.cpp @@ -24,25 +24,30 @@ #include #include -namespace sofa::component::engine::select::boxroi +namespace sofa::component::engine::select { using namespace sofa::defaulttype; -int BoxROIClass = core::RegisterObject("Find the primitives (vertex/edge/triangle/quad/tetrahedron/hexahedron) inside given boxes") +void registerBoxROI(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Engine selecting the any primitives (vertex/edge/triangle/quad/tetrahedron/hexahedron) inside given boxes.") .add< BoxROI >(true) //default .add< BoxROI >() .add< BoxROI >() .add< BoxROI >() - .add< BoxROI >() - - ; + .add< BoxROI >()); +} + +namespace boxroi +{ template class SOFA_COMPONENT_ENGINE_SELECT_API BoxROI; template class SOFA_COMPONENT_ENGINE_SELECT_API BoxROI; template class SOFA_COMPONENT_ENGINE_SELECT_API BoxROI; template class SOFA_COMPONENT_ENGINE_SELECT_API BoxROI; template class SOFA_COMPONENT_ENGINE_SELECT_API BoxROI; - -} // namespace sofa::component::engine::select::boxroi +} // namespace boxroi + +} // namespace sofa::component::engine::select diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/ComplementaryROI.cpp b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/ComplementaryROI.cpp index 0ad166d2833..d66fbdc3c98 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/ComplementaryROI.cpp +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/ComplementaryROI.cpp @@ -30,12 +30,12 @@ namespace sofa::component::engine::select using namespace sofa::defaulttype; -int ComplementaryROIClass = core::RegisterObject("Find the points that are NOT in the input sets") - .add >() - - ; +void registerComplementaryROI(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Find the points that are NOT in the input sets.") + .add >()); +} template class SOFA_COMPONENT_ENGINE_SELECT_API ComplementaryROI; - } //namespace sofa::component::engine::select diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/IndicesFromValues.cpp b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/IndicesFromValues.cpp index 4079bf5af78..a745d976431 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/IndicesFromValues.cpp +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/IndicesFromValues.cpp @@ -28,7 +28,9 @@ namespace sofa::component::engine::select { -int IndicesFromValuesClass = core::RegisterObject("Find the indices of a list of values within a larger set of values") +void registerIndicesFromValues(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Engine finding the indices of a list of values within a larger set of values.") .add< IndicesFromValues >() .add< IndicesFromValues >() .add< IndicesFromValues >() @@ -38,13 +40,8 @@ int IndicesFromValuesClass = core::RegisterObject("Find the indices of a list of .add< IndicesFromValues< type::fixed_array > >() .add< IndicesFromValues >() .add< IndicesFromValues >() - .add< IndicesFromValues >() - // .add< IndicesFromValues >() - // .add< IndicesFromValues >() - // .add< IndicesFromValues >() - // .add< IndicesFromValues >() - - ; + .add< IndicesFromValues >()); +} template class SOFA_COMPONENT_ENGINE_SELECT_API IndicesFromValues; template class SOFA_COMPONENT_ENGINE_SELECT_API IndicesFromValues; @@ -56,10 +53,5 @@ template class SOFA_COMPONENT_ENGINE_SELECT_API IndicesFromValues< type::fixed_a template class SOFA_COMPONENT_ENGINE_SELECT_API IndicesFromValues; template class SOFA_COMPONENT_ENGINE_SELECT_API IndicesFromValues; template class SOFA_COMPONENT_ENGINE_SELECT_API IndicesFromValues; -// template class SOFA_COMPONENT_ENGINE_SELECT_API IndicesFromValues; -// template class SOFA_COMPONENT_ENGINE_SELECT_API IndicesFromValues; -// template class SOFA_COMPONENT_ENGINE_SELECT_API IndicesFromValues; -// template class SOFA_COMPONENT_ENGINE_SELECT_API IndicesFromValues; - } //namespace sofa::component::engine::select diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MergeROIs.cpp b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MergeROIs.cpp index 6bb3910d902..fb94352fb96 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MergeROIs.cpp +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MergeROIs.cpp @@ -72,9 +72,11 @@ void MergeROIs::doUpdate() for(size_t i=0 ; i) into a single Data (vector>)") - .add< MergeROIs >(true) - ; +void registerMergeROIs(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Merge a list of ROIs (vector) into a single Data (vector>).") + .add< MergeROIs >()); +} } //namespace sofa::component::engine::select diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshBoundaryROI.cpp b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshBoundaryROI.cpp index f44b1ecea31..e866d610604 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshBoundaryROI.cpp +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshBoundaryROI.cpp @@ -26,8 +26,11 @@ namespace sofa::component::engine::select { -int MeshBoundaryROIClass = core::RegisterObject("Outputs indices of boundary vertices of a triangle/quad mesh") - .add< MeshBoundaryROI >(true); +void registerMeshBoundaryROI(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Outputs indices of boundary vertices of a triangle/quad mesh") + .add< MeshBoundaryROI >()); +} MeshBoundaryROI::MeshBoundaryROI(): Inherit1() , d_triangles(initData(&d_triangles,"triangles","input triangles")) diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshROI.cpp b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshROI.cpp index 478603b985f..ea025fa74d9 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshROI.cpp +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshROI.cpp @@ -29,17 +29,16 @@ namespace sofa::component::engine::select using namespace sofa::defaulttype; -int MeshROIClass = core::RegisterObject("Find the primitives (vertex/edge/triangle/tetrahedron) inside a given mesh") +void registerMeshROI(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Find the primitives (vertex/edge/triangle/tetrahedron) inside a given mesh.") .add< MeshROI >(true) //default template .add< MeshROI >() - .add< MeshROI >() - - ; + .add< MeshROI >()); +} template class SOFA_COMPONENT_ENGINE_SELECT_API MeshROI; template class SOFA_COMPONENT_ENGINE_SELECT_API MeshROI; template class SOFA_COMPONENT_ENGINE_SELECT_API MeshROI; - - } //namespace sofa::component::engine::select diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshSampler.cpp b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshSampler.cpp index e71bf8436a7..029bba009b6 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshSampler.cpp +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshSampler.cpp @@ -27,14 +27,12 @@ namespace sofa::component::engine::select { -int MeshSamplerClass = core::RegisterObject("Select uniformly distributed points on a mesh based on Euclidean or Geodesic distance measure") - .add< MeshSampler >(true) - - ; +void registerMeshSampler(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Select uniformly distributed points on a mesh based on Euclidean or Geodesic distance measure.") + .add< MeshSampler >()); +} template class SOFA_COMPONENT_ENGINE_SELECT_API MeshSampler; - - - } //namespace sofa::component::engine::select diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshSplittingEngine.cpp b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshSplittingEngine.cpp index d837ccbf545..a1b828281b0 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshSplittingEngine.cpp +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshSplittingEngine.cpp @@ -26,12 +26,12 @@ namespace sofa::component::engine::select { -int MeshSplittingEngineClass = core::RegisterObject("This class breaks a mesh in multiple parts, based on selected vertices or cells.") - .add< MeshSplittingEngine >(true) // default template - ; +void registerMeshSplittingEngine(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Engine breaking a mesh in multiple parts, based on selected vertices or cells.") + .add< MeshSplittingEngine >()); +} template class SOFA_COMPONENT_ENGINE_SELECT_API MeshSplittingEngine; - - } //namespace sofa::component::engine::select diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshSubsetEngine.cpp b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshSubsetEngine.cpp index 6641bcba60b..82d6b58be4c 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshSubsetEngine.cpp +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshSubsetEngine.cpp @@ -26,12 +26,12 @@ namespace sofa::component::engine::select { -int MeshSubsetEngineClass = core::RegisterObject("Extract a mesh subset based on selected vertices") - .add< MeshSubsetEngine >(true) // default template - ; +void registerMeshSubsetEngine(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Extract a mesh subset based on selected vertices.") + .add< MeshSubsetEngine >()); +} template class SOFA_COMPONENT_ENGINE_SELECT_API MeshSubsetEngine; - - } //namespace sofa::component::engine::select diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/NearestPointROI.cpp b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/NearestPointROI.cpp index 23d13270e01..469a8c082db 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/NearestPointROI.cpp +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/NearestPointROI.cpp @@ -28,14 +28,16 @@ namespace sofa::component::engine::select using namespace sofa::defaulttype; -int NearestPointROIClass = core::RegisterObject("Attach given pair of particles, projecting the positions of the second particles to the first ones") +void registerNearestPointROI(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Attach given pair of particles, projecting the positions of the second particles to the first ones.") .add< NearestPointROI >() .add< NearestPointROI >() .add< NearestPointROI >() .add< NearestPointROI >() .add< NearestPointROI >() - .add< NearestPointROI >() - ; + .add< NearestPointROI >()); +} template class SOFA_COMPONENT_ENGINE_SELECT_API NearestPointROI; template class SOFA_COMPONENT_ENGINE_SELECT_API NearestPointROI; @@ -43,4 +45,5 @@ template class SOFA_COMPONENT_ENGINE_SELECT_API NearestPointROI; template class SOFA_COMPONENT_ENGINE_SELECT_API NearestPointROI; template class SOFA_COMPONENT_ENGINE_SELECT_API NearestPointROI; + } //namespace sofa::component::engine::select diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/PairBoxRoi.cpp b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/PairBoxRoi.cpp index 0ca8ab3c352..e71474a4c5a 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/PairBoxRoi.cpp +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/PairBoxRoi.cpp @@ -29,17 +29,16 @@ namespace sofa::component::engine::select using namespace sofa::defaulttype; -int PairBoxROIClass = core::RegisterObject("Find the primitives (vertex/edge/triangle/tetrahedron) inside a given box") - .add< PairBoxROI >() +void registerPairBoxROI(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Find all the points located between two boxes.") + .add< PairBoxROI >(true) .add< PairBoxROI >() - .add< PairBoxROI >() //Phuoc - - ; + .add< PairBoxROI >()); +} template class SOFA_COMPONENT_ENGINE_SELECT_API PairBoxROI; template class SOFA_COMPONENT_ENGINE_SELECT_API PairBoxROI; -template class SOFA_COMPONENT_ENGINE_SELECT_API PairBoxROI; //Phuoc - - +template class SOFA_COMPONENT_ENGINE_SELECT_API PairBoxROI; } //namespace sofa::component::engine::select diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/PlaneROI.cpp b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/PlaneROI.cpp index 5576a015a4d..60f454d0f8f 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/PlaneROI.cpp +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/PlaneROI.cpp @@ -29,15 +29,14 @@ namespace sofa::component::engine::select using namespace sofa::defaulttype; -int PlaneROIClass = core::RegisterObject("Find the primitives inside a given plane") +void registerPlaneROI(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Find the primitives inside a given plane.") .add< PlaneROI >() - .add< PlaneROI >() - - ; + .add< PlaneROI >()); +} template class SOFA_COMPONENT_ENGINE_SELECT_API PlaneROI; template class SOFA_COMPONENT_ENGINE_SELECT_API PlaneROI; - - } //namespace sofa::component::engine::select diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/PointsFromIndices.cpp b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/PointsFromIndices.cpp index fe68535eaab..09733432acb 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/PointsFromIndices.cpp +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/PointsFromIndices.cpp @@ -30,15 +30,12 @@ namespace sofa::component::engine::select using namespace sofa::defaulttype; -int PointsFromIndicesClass = core::RegisterObject("Find the points given a list of indices") - .add< PointsFromIndices >() -// .add< PointsFromIndices >() - - ; +void registerPointsFromIndices(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Find the points given a list of indices.") + .add< PointsFromIndices >()); +} template class SOFA_COMPONENT_ENGINE_SELECT_API PointsFromIndices; -// template class SOFA_COMPONENT_ENGINE_SELECT_API PointsFromIndices; - - } //namespace sofa::component::engine::select diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/ProximityROI.cpp b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/ProximityROI.cpp index a29b50a2cf4..654d88d698e 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/ProximityROI.cpp +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/ProximityROI.cpp @@ -30,14 +30,12 @@ namespace sofa::component::engine::select using namespace sofa::defaulttype; -int ProximityROIClass = core::RegisterObject("Find the N closest primitives from a given position") - .add< ProximityROI >() - - ; +void registerProximityROI(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Find the N closest primitives from a given position.") + .add< ProximityROI >()); +} template class SOFA_COMPONENT_ENGINE_SELECT_API ProximityROI; -//template class SOFA_COMPONENT_ENGINE_SELECT_API SphereROI; - - } //namespace sofa::component::engine::select diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/SelectConnectedLabelsROI.cpp b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/SelectConnectedLabelsROI.cpp index c11b1ea7b6b..c48c676c447 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/SelectConnectedLabelsROI.cpp +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/SelectConnectedLabelsROI.cpp @@ -28,12 +28,14 @@ namespace sofa::component::engine::select { -int SelectConnectedLabelsROIClass = core::RegisterObject("Select a subset of points or cells labeled from different sources, that are connected given a list of connection pairs") +void registerSelectConnectedLabelsROI(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Select a subset of points or cells labeled from different sources, that are connected given a list of connection pairs.") .add< SelectConnectedLabelsROI >(true) .add< SelectConnectedLabelsROI >() .add< SelectConnectedLabelsROI >() - .add< SelectConnectedLabelsROI >() - ; + .add< SelectConnectedLabelsROI >()); +} template class SOFA_COMPONENT_ENGINE_SELECT_API SelectConnectedLabelsROI; template class SOFA_COMPONENT_ENGINE_SELECT_API SelectConnectedLabelsROI; diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/SelectLabelROI.cpp b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/SelectLabelROI.cpp index 226951c6aaf..038d905e4b9 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/SelectLabelROI.cpp +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/SelectLabelROI.cpp @@ -28,12 +28,14 @@ namespace sofa::component::engine::select { -int SelectLabelROIClass = core::RegisterObject("Select a subset of labeled points or cells stored in (vector>) given certain labels") +void registerSelectLabelROI(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Select a subset of labeled points or cells stored in (vector>) given certain labels.") .add< SelectLabelROI >(true) .add< SelectLabelROI >() .add< SelectLabelROI >() - .add< SelectLabelROI >() - ; + .add< SelectLabelROI >()); +} template class SOFA_COMPONENT_ENGINE_SELECT_API SelectLabelROI; template class SOFA_COMPONENT_ENGINE_SELECT_API SelectLabelROI; diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/SphereROI.cpp b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/SphereROI.cpp index 55a64ef6d57..1ea4fe8801a 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/SphereROI.cpp +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/SphereROI.cpp @@ -30,14 +30,14 @@ namespace sofa::component::engine::select using namespace sofa::defaulttype; -int SphereROIClass = core::RegisterObject("Find the primitives (vertex/edge/triangle/tetrahedron) inside a given sphere") +void registerSphereROI(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Engine selecting the primitives (vertex/edge/triangle/tetrahedron) inside a given sphere.") .add< SphereROI >(true) - .add< SphereROI >() - ; + .add< SphereROI >()); +} template class SOFA_COMPONENT_ENGINE_SELECT_API SphereROI; template class SOFA_COMPONENT_ENGINE_SELECT_API SphereROI; - - } //namespace sofa::component::engine::select diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/SubsetTopology.cpp b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/SubsetTopology.cpp index 17d5c563351..b64940945e6 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/SubsetTopology.cpp +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/SubsetTopology.cpp @@ -30,15 +30,14 @@ namespace sofa::component::engine::select using namespace sofa::defaulttype; -int SubsetTopologyClass = core::RegisterObject("Engine used to create subset topology given box, sphere, plan, ...") +void registerSubsetTopology(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Engine used to create subset topology given box, sphere, plan, ...") .add< SubsetTopology >() - .add< SubsetTopology >() - - ; + .add< SubsetTopology >()); +} template class SOFA_COMPONENT_ENGINE_SELECT_API SubsetTopology; template class SOFA_COMPONENT_ENGINE_SELECT_API SubsetTopology; - - } //namespace sofa::component::engine::select diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/ValuesFromIndices.cpp b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/ValuesFromIndices.cpp index 0255ceb695c..3c1275d1fda 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/ValuesFromIndices.cpp +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/ValuesFromIndices.cpp @@ -28,7 +28,9 @@ namespace sofa::component::engine::select { -int ValuesFromIndicesClass = core::RegisterObject("Find the values given a list of indices") +void registerValuesFromIndices(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Find the values given a list of indices.") .add< ValuesFromIndices >() .add< ValuesFromIndices >() .add< ValuesFromIndices >() @@ -44,9 +46,8 @@ int ValuesFromIndicesClass = core::RegisterObject("Find the values given a list .add< ValuesFromIndices >() .add< ValuesFromIndices >() .add< ValuesFromIndices >() - .add< ValuesFromIndices >() - - ; + .add< ValuesFromIndices >()); +} template class SOFA_COMPONENT_ENGINE_SELECT_API ValuesFromIndices; template class SOFA_COMPONENT_ENGINE_SELECT_API ValuesFromIndices; @@ -64,6 +65,5 @@ template class SOFA_COMPONENT_ENGINE_SELECT_API ValuesFromIndices; template class SOFA_COMPONENT_ENGINE_SELECT_API ValuesFromIndices; template class SOFA_COMPONENT_ENGINE_SELECT_API ValuesFromIndices; - } //namespace sofa::component::engine::select diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/ValuesFromPositions.cpp b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/ValuesFromPositions.cpp index c53cfb90d66..ceb83789ba5 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/ValuesFromPositions.cpp +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/ValuesFromPositions.cpp @@ -29,15 +29,14 @@ namespace sofa::component::engine::select using namespace sofa::defaulttype; -int ValuesFromPositionsClass = core::RegisterObject("Assign values to primitives (vertex/edge/triangle/tetrahedron) based on a linear interpolation of values along a direction") +void registerValuesFromPositions(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Assign values to primitives (vertex/edge/triangle/tetrahedron) based on a linear interpolation of values along a direction.") .add< ValuesFromPositions >() - .add< ValuesFromPositions >() - - ; + .add< ValuesFromPositions >()); +} template class SOFA_COMPONENT_ENGINE_SELECT_API ValuesFromPositions; template class SOFA_COMPONENT_ENGINE_SELECT_API ValuesFromPositions; - - } //namespace sofa::component::engine::select diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/init.cpp b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/init.cpp index 57add32cd26..4d8239a46b4 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/init.cpp +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/init.cpp @@ -21,13 +21,37 @@ ******************************************************************************/ #include #include +#include + namespace sofa::component::engine::select { - + +extern void registerBoxROI(sofa::core::ObjectFactory* factory); +extern void registerComplementaryROI(sofa::core::ObjectFactory* factory); +extern void registerIndicesFromValues(sofa::core::ObjectFactory* factory); +extern void registerMergeROIs(sofa::core::ObjectFactory* factory); +extern void registerMeshBoundaryROI(sofa::core::ObjectFactory* factory); +extern void registerMeshROI(sofa::core::ObjectFactory* factory); +extern void registerMeshSampler(sofa::core::ObjectFactory* factory); +extern void registerMeshSplittingEngine(sofa::core::ObjectFactory* factory); +extern void registerMeshSubsetEngine(sofa::core::ObjectFactory* factory); +extern void registerNearestPointROI(sofa::core::ObjectFactory* factory); +extern void registerPairBoxROI(sofa::core::ObjectFactory* factory); +extern void registerPlaneROI(sofa::core::ObjectFactory* factory); +extern void registerPointsFromIndices(sofa::core::ObjectFactory* factory); +extern void registerProximityROI(sofa::core::ObjectFactory* factory); +extern void registerSelectConnectedLabelsROI(sofa::core::ObjectFactory* factory); +extern void registerSelectLabelROI(sofa::core::ObjectFactory* factory); +extern void registerSphereROI(sofa::core::ObjectFactory* factory); +extern void registerSubsetTopology(sofa::core::ObjectFactory* factory); +extern void registerValuesFromIndices(sofa::core::ObjectFactory* factory); +extern void registerValuesFromPositions(sofa::core::ObjectFactory* factory); + extern "C" { SOFA_EXPORT_DYNAMIC_LIBRARY void initExternalModule(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleName(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleVersion(); + SOFA_EXPORT_DYNAMIC_LIBRARY void registerObjects(sofa::core::ObjectFactory* factory); } void initExternalModule() @@ -45,11 +69,38 @@ const char* getModuleVersion() return MODULE_VERSION; } +void registerObjects(sofa::core::ObjectFactory* factory) +{ + registerBoxROI(factory); + registerComplementaryROI(factory); + registerIndicesFromValues(factory); + registerMergeROIs(factory); + registerMeshBoundaryROI(factory); + registerMeshROI(factory); + registerMeshSampler(factory); + registerMeshSplittingEngine(factory); + registerMeshSubsetEngine(factory); + registerNearestPointROI(factory); + registerPairBoxROI(factory); + registerPlaneROI(factory); + registerPointsFromIndices(factory); + registerProximityROI(factory); + registerSelectConnectedLabelsROI(factory); + registerSelectLabelROI(factory); + registerSphereROI(factory); + registerSubsetTopology(factory); + registerValuesFromIndices(factory); + registerValuesFromPositions(factory); +} + void init() { static bool first = true; if (first) { + // make sure that this plugin is registered into the PluginManager + sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME); + first = false; } } diff --git a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/DifferenceEngine.cpp b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/DifferenceEngine.cpp index 1b4614c5f9f..f5da34d688b 100644 --- a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/DifferenceEngine.cpp +++ b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/DifferenceEngine.cpp @@ -29,14 +29,14 @@ namespace sofa::component::engine::transform using namespace sofa::type; using namespace sofa::defaulttype; -int DifferenceEngineClass = core::RegisterObject("Computing the difference between two vector of dofs") +void registerDifferenceEngine(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Computing the difference between two vector of dofs.") .add< DifferenceEngine >() - .add< DifferenceEngine >(true) // default template - - ; + .add< DifferenceEngine >(true)); +} template class SOFA_COMPONENT_ENGINE_TRANSFORM_API DifferenceEngine; template class SOFA_COMPONENT_ENGINE_TRANSFORM_API DifferenceEngine; - } //namespace sofa::component::engine::transform diff --git a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/DilateEngine.cpp b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/DilateEngine.cpp index 436b8d0bf09..13699d6ed80 100644 --- a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/DilateEngine.cpp +++ b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/DilateEngine.cpp @@ -28,9 +28,11 @@ namespace sofa::component::engine::transform using namespace defaulttype; -int DilateEngineClass = core::RegisterObject("Dilates a given mesh by moving vertices along their normal.") - .add< DilateEngine>(true) // default template - ; +void registerDilateEngine(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Dilates a given mesh by moving vertices along their normal.") + .add< DilateEngine>()); +} template class SOFA_COMPONENT_ENGINE_TRANSFORM_API DilateEngine; diff --git a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/DisplacementMatrixEngine.cpp b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/DisplacementMatrixEngine.cpp index 51af18326f0..8f7eab1f906 100644 --- a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/DisplacementMatrixEngine.cpp +++ b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/DisplacementMatrixEngine.cpp @@ -31,10 +31,12 @@ namespace sofa::component::engine::transform using namespace type; using namespace defaulttype; -int DisplacementTransformEngineClass = core::RegisterObject("Converts a vector of Rigid to a vector of displacement transforms.") - .add< DisplacementTransformEngine >() - .add< DisplacementTransformEngine >() -; +void registerDisplacementTransformEngine(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Converts a vector of Rigid to a vector of displacement transforms.") + .add< DisplacementTransformEngine >() + .add< DisplacementTransformEngine >()); +} template class SOFA_COMPONENT_ENGINE_TRANSFORM_API DisplacementTransformEngine; template class SOFA_COMPONENT_ENGINE_TRANSFORM_API DisplacementTransformEngine; diff --git a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/IndexValueMapper.cpp b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/IndexValueMapper.cpp index 963bf763259..0b5108baa54 100644 --- a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/IndexValueMapper.cpp +++ b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/IndexValueMapper.cpp @@ -31,13 +31,12 @@ namespace sofa::component::engine::transform using namespace sofa; using namespace sofa::defaulttype; -int IndexValueMapperClass = core::RegisterObject("Input values to output values mapper. Includes indices rules, such as replacement, resize") - .add< IndexValueMapper >(true) - - ; +void registerIndexValueMapper(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Input values to output values mapper. Includes indices rules, such as replacement, resize.") + .add< IndexValueMapper >()); +} template class SOFA_COMPONENT_ENGINE_TRANSFORM_API IndexValueMapper; - - } //namespace sofa::component::engine::transform diff --git a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/Indices2ValuesMapper.cpp b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/Indices2ValuesMapper.cpp index d44c040edaa..cd006e4371a 100644 --- a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/Indices2ValuesMapper.cpp +++ b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/Indices2ValuesMapper.cpp @@ -31,13 +31,12 @@ namespace sofa::component::engine::transform using namespace sofa; using namespace sofa::defaulttype; -int Indices2ValuesMapperClass = core::RegisterObject("?") - .add< Indices2ValuesMapper >(true) - - ; +void registerIndices2ValuesMapper(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Input multiple values to output values mapper. Includes indices rules, such as replacement, resize.") + .add< Indices2ValuesMapper >()); +} template class SOFA_COMPONENT_ENGINE_TRANSFORM_API Indices2ValuesMapper; - - } //namespace sofa::component::engine::transform diff --git a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/Indices2ValuesMapper.inl b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/Indices2ValuesMapper.inl index 57ad89da5f2..60b527c11a7 100644 --- a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/Indices2ValuesMapper.inl +++ b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/Indices2ValuesMapper.inl @@ -23,7 +23,6 @@ #include #include -#include namespace sofa::component::engine::transform { diff --git a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/MapIndices.cpp b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/MapIndices.cpp index f3229908db2..018c98036fb 100644 --- a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/MapIndices.cpp +++ b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/MapIndices.cpp @@ -28,14 +28,16 @@ namespace sofa::component::engine::transform { -int MapIndicesClass = core::RegisterObject("Apply a permutation to a set of indices") +void registerMapIndices(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Apply a permutation to a set of indices.") .add< MapIndices >() .add< MapIndices >() .add< MapIndices< type::fixed_array > >() .add< MapIndices< type::fixed_array > >() .add< MapIndices< type::fixed_array > >() - .add< MapIndices< type::fixed_array > >() - ; + .add< MapIndices< type::fixed_array > >()); +} template class SOFA_COMPONENT_ENGINE_TRANSFORM_API MapIndices; template class SOFA_COMPONENT_ENGINE_TRANSFORM_API MapIndices; diff --git a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/MathOp.cpp b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/MathOp.cpp index afbc8c493ce..1dd7a4b0895 100644 --- a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/MathOp.cpp +++ b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/MathOp.cpp @@ -26,22 +26,22 @@ namespace sofa::component::engine::transform { -int MathOpClass = core::RegisterObject("Apply a math operation to combine several inputs") - .add< MathOp< type::vector > >(true) - .add< MathOp< type::vector > >() - .add< MathOp< type::vector > >() - .add< MathOp< type::vector > >() - .add< MathOp< type::vector > >() - .add< MathOp< defaulttype::Rigid2Types::VecCoord > >() - .add< MathOp< defaulttype::Rigid2Types::VecDeriv > >() - .add< MathOp< defaulttype::Rigid3Types::VecCoord > >() - .add< MathOp< defaulttype::Rigid3Types::VecDeriv > >() - - ; +void registerMathOp(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Apply a math operation to combine several inputs.") + .add< MathOp< type::vector > >(true) + .add< MathOp< type::vector > >() + .add< MathOp< type::vector > >() + .add< MathOp< type::vector > >() + .add< MathOp< type::vector > >() + .add< MathOp< defaulttype::Rigid2Types::VecCoord > >() + .add< MathOp< defaulttype::Rigid2Types::VecDeriv > >() + .add< MathOp< defaulttype::Rigid3Types::VecCoord > >() + .add< MathOp< defaulttype::Rigid3Types::VecDeriv > >()); +} template class SOFA_COMPONENT_ENGINE_TRANSFORM_API MathOp< type::vector >; template class SOFA_COMPONENT_ENGINE_TRANSFORM_API MathOp< type::vector >; - template class SOFA_COMPONENT_ENGINE_TRANSFORM_API MathOp< type::vector >; template class SOFA_COMPONENT_ENGINE_TRANSFORM_API MathOp< type::vector >; template class SOFA_COMPONENT_ENGINE_TRANSFORM_API MathOp< type::vector >; @@ -49,7 +49,5 @@ template class SOFA_COMPONENT_ENGINE_TRANSFORM_API MathOp< defaulttype::Rigid2Ty template class SOFA_COMPONENT_ENGINE_TRANSFORM_API MathOp< defaulttype::Rigid2Types::VecDeriv >; template class SOFA_COMPONENT_ENGINE_TRANSFORM_API MathOp< defaulttype::Rigid3Types::VecCoord >; template class SOFA_COMPONENT_ENGINE_TRANSFORM_API MathOp< defaulttype::Rigid3Types::VecDeriv >; - - } //namespace sofa::component::engine::transform diff --git a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/ProjectiveTransformEngine.cpp b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/ProjectiveTransformEngine.cpp index 93e1ac3a0ba..fc1ad8e536b 100644 --- a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/ProjectiveTransformEngine.cpp +++ b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/ProjectiveTransformEngine.cpp @@ -26,12 +26,13 @@ namespace sofa::component::engine::transform { -int ProjectiveTransformEngineClass = core::RegisterObject("Project the position of 3d points onto a plane according to a projection matrix") - .add< ProjectiveTransformEngine >(true) // default template - ; +void registerProjectiveTransformEngine(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Project the position of 3d points onto a plane according to a projection matrix.") + .add< ProjectiveTransformEngine >()); +} template class SOFA_COMPONENT_ENGINE_TRANSFORM_API ProjectiveTransformEngine; - } // namespace sofa::component::engine::transform diff --git a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/QuatToRigidEngine.cpp b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/QuatToRigidEngine.cpp index 956211abae9..ab9fae4a9e7 100644 --- a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/QuatToRigidEngine.cpp +++ b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/QuatToRigidEngine.cpp @@ -29,13 +29,12 @@ namespace sofa::component::engine::transform { -int QuatToRigidEngineClass = core::RegisterObject("Transform a vector of Rigids into two independant vectors for positions (Vec3) and orientations (Quat).") - .add< QuatToRigidEngine >() - - ; +void registerQuatToRigidEngine(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Transform a vector of Rigids into two independant vectors for positions (Vec3) and orientations (Quat).") + .add< QuatToRigidEngine >()); +} template class SOFA_COMPONENT_ENGINE_TRANSFORM_API QuatToRigidEngine; - - } //namespace sofa::component::engine::transform diff --git a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/ROIValueMapper.cpp b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/ROIValueMapper.cpp index 65b67b2689e..d0f1e1d6117 100644 --- a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/ROIValueMapper.cpp +++ b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/ROIValueMapper.cpp @@ -25,11 +25,10 @@ namespace sofa::component::engine::transform { -using namespace sofa; - -int ROIValueMapperClass = core::RegisterObject("Generate a list of values from value-indices pairs") - .add< ROIValueMapper >(true) - ; - +void registerROIValueMapper(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Generate a list of values from value-indices pairs.") + .add< ROIValueMapper >()); +} } //namespace sofa::component::engine::transform diff --git a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/RigidToQuatEngine.cpp b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/RigidToQuatEngine.cpp index fe7526254ba..a051c2700fa 100644 --- a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/RigidToQuatEngine.cpp +++ b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/RigidToQuatEngine.cpp @@ -29,14 +29,12 @@ namespace sofa::component::engine::transform { -int RigidToQuatEngineClass = core::RegisterObject("Transform a couple of Vec3 and Quaternion in Rigid") - .add< RigidToQuatEngine >() - - .addAlias("RigidEngine") - ; +void registerRigidToQuatEngine(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Transform a couple of Vec3 and Quaternion in Rigid.") + .add< RigidToQuatEngine >()); +} template class SOFA_COMPONENT_ENGINE_TRANSFORM_API RigidToQuatEngine; - - } //namespace sofa::component::engine::transform diff --git a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/SmoothMeshEngine.cpp b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/SmoothMeshEngine.cpp index c85baf5ba1e..e8fefddbf54 100644 --- a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/SmoothMeshEngine.cpp +++ b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/SmoothMeshEngine.cpp @@ -29,13 +29,12 @@ namespace sofa::component::engine::transform using namespace sofa::defaulttype; -int SmoothMeshEngineClass = core::RegisterObject("Compute the laplacian smoothing of a mesh") - .add< SmoothMeshEngine >() - - ; +void registerSmoothMeshEngine(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Compute the laplacian smoothing of a mesh.") + .add< SmoothMeshEngine >()); +} template class SOFA_COMPONENT_ENGINE_TRANSFORM_API SmoothMeshEngine; - - } //namespace sofa::component::engine::transform diff --git a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/TransformEngine.cpp b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/TransformEngine.cpp index 5fa0cfec169..b3c4262e2b2 100644 --- a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/TransformEngine.cpp +++ b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/TransformEngine.cpp @@ -26,14 +26,15 @@ namespace sofa::component::engine::transform { -int TransformEngineClass = core::RegisterObject("Transform position of 3d points") +void registerTransformEngine(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Engine applying a transformation on 3d points (translation / rotation).") .add< TransformEngine >(true) // default template .add< TransformEngine >() .add< TransformEngine >() .add< TransformEngine >() - .add< TransformEngine >() - - ; + .add< TransformEngine >()); +} template class SOFA_COMPONENT_ENGINE_TRANSFORM_API TransformEngine; template class SOFA_COMPONENT_ENGINE_TRANSFORM_API TransformEngine; diff --git a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/TransformMatrixEngine.cpp b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/TransformMatrixEngine.cpp index 28589f5d4b4..86f047b6cad 100644 --- a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/TransformMatrixEngine.cpp +++ b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/TransformMatrixEngine.cpp @@ -33,17 +33,29 @@ namespace sofa::component::engine::transform using namespace sofa::type; using namespace sofa::defaulttype; -int TranslateTransformMatrixEngineClass = core::RegisterObject("Compose the input transform (if any) with the given translation") - .add< TranslateTransformMatrixEngine >(); +void registerTranslateTransformMatrixEngine(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Compose the input transform (if any) with the given translation.") + .add< TranslateTransformMatrixEngine >()); +} -int InvertTransformMatrixEngineClass = core::RegisterObject("Inverts the input transform") - .add< InvertTransformMatrixEngine >(); +void registerInvertTransformMatrixEngine(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Inverts the input transform.") + .add< InvertTransformMatrixEngine >()); +} -int ScaleTransformMatrixEngineClass = core::RegisterObject("Compose the input transform (if any) with the given scale transformation") - .add< ScaleTransformMatrixEngine >(); +void registerScaleTransformMatrixEngine(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Compose the input transform (if any) with the given scale transformation.") + .add< ScaleTransformMatrixEngine >()); +} -int RotateTransformMatrixEngineClass = core::RegisterObject("Compose the input transform (if any) with the given rotation") - .add< RotateTransformMatrixEngine >(); +void registerRotateTransformMatrixEngine(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Compose the input transform (if any) with the given rotation.") + .add< RotateTransformMatrixEngine >()); +} /* * AbstractTransformMatrixEngine diff --git a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/TransformPosition.cpp b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/TransformPosition.cpp index c038bdc03d1..1a5fda53f3b 100644 --- a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/TransformPosition.cpp +++ b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/TransformPosition.cpp @@ -30,12 +30,12 @@ namespace sofa::component::engine::transform using namespace sofa::defaulttype; -int TransformPositionClass = core::RegisterObject("Transform position of 3d points") - .add< TransformPosition >(true) - ; +void registerTransformPosition(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Transform position of 3d points.") + .add< TransformPosition >()); +} template class SOFA_COMPONENT_ENGINE_TRANSFORM_API TransformPosition; - - } //namespace sofa::component::engine::transform diff --git a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/Vertex2Frame.cpp b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/Vertex2Frame.cpp index fecc91b00c5..25990a77941 100644 --- a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/Vertex2Frame.cpp +++ b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/Vertex2Frame.cpp @@ -30,13 +30,12 @@ namespace sofa::component::engine::transform using namespace sofa::defaulttype; -int Vertex2FrameClass = core::RegisterObject("") - .add< Vertex2Frame >() - - ; +void registerVertex2Frame(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Return a rigid position from the vertices, texCoords, normals and facets of any mesh.") + .add< Vertex2Frame >()); +} template class SOFA_COMPONENT_ENGINE_TRANSFORM_API Vertex2Frame; - - } //namespace sofa::component::engine::transform diff --git a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/init.cpp b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/init.cpp index c4c25209d5d..d85e6a7fae0 100644 --- a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/init.cpp +++ b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/init.cpp @@ -21,13 +21,37 @@ ******************************************************************************/ #include #include +#include + namespace sofa::component::engine::transform { +extern void registerDifferenceEngine(sofa::core::ObjectFactory* factory); +extern void registerDilateEngine(sofa::core::ObjectFactory* factory); +extern void registerDisplacementTransformEngine(sofa::core::ObjectFactory* factory); +extern void registerIndexValueMapper(sofa::core::ObjectFactory* factory); +extern void registerIndices2ValuesMapper(sofa::core::ObjectFactory* factory); +extern void registerMapIndices(sofa::core::ObjectFactory* factory); +extern void registerMathOp(sofa::core::ObjectFactory* factory); +extern void registerProjectiveTransformEngine(sofa::core::ObjectFactory* factory); +extern void registerQuatToRigidEngine(sofa::core::ObjectFactory* factory); +extern void registerRigidToQuatEngine(sofa::core::ObjectFactory* factory); +extern void registerROIValueMapper(sofa::core::ObjectFactory* factory); +extern void registerSmoothMeshEngine(sofa::core::ObjectFactory* factory); +extern void registerTransformEngine(sofa::core::ObjectFactory* factory); +extern void registerTranslateTransformMatrixEngine(sofa::core::ObjectFactory* factory); +extern void registerInvertTransformMatrixEngine(sofa::core::ObjectFactory* factory); +extern void registerScaleTransformMatrixEngine(sofa::core::ObjectFactory* factory); +extern void registerRotateTransformMatrixEngine(sofa::core::ObjectFactory* factory); +extern void registerTransformPosition(sofa::core::ObjectFactory* factory); +extern void registerVertex2Frame(sofa::core::ObjectFactory* factory); + + extern "C" { SOFA_EXPORT_DYNAMIC_LIBRARY void initExternalModule(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleName(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleVersion(); + SOFA_EXPORT_DYNAMIC_LIBRARY void registerObjects(sofa::core::ObjectFactory* factory); } void initExternalModule() @@ -45,11 +69,37 @@ const char* getModuleVersion() return MODULE_VERSION; } +void registerObjects(sofa::core::ObjectFactory* factory) +{ + registerDifferenceEngine(factory); + registerDilateEngine(factory); + registerDisplacementTransformEngine(factory); + registerIndexValueMapper(factory); + registerIndices2ValuesMapper(factory); + registerMapIndices(factory); + registerMathOp(factory); + registerProjectiveTransformEngine(factory); + registerQuatToRigidEngine(factory); + registerRigidToQuatEngine(factory); + registerROIValueMapper(factory); + registerSmoothMeshEngine(factory); + registerTransformEngine(factory); + registerTranslateTransformMatrixEngine(factory); + registerInvertTransformMatrixEngine(factory); + registerScaleTransformMatrixEngine(factory); + registerRotateTransformMatrixEngine(factory); + registerTransformPosition(factory); + registerVertex2Frame(factory); +} + void init() { static bool first = true; if (first) { + // make sure that this plugin is registered into the PluginManager + sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME); + first = false; } } diff --git a/Sofa/Component/Engine/src/sofa/component/engine/init.cpp b/Sofa/Component/Engine/src/sofa/component/engine/init.cpp index 1b376416087..05eeff6cc2b 100644 --- a/Sofa/Component/Engine/src/sofa/component/engine/init.cpp +++ b/Sofa/Component/Engine/src/sofa/component/engine/init.cpp @@ -26,6 +26,9 @@ #include #include +#include +#include + namespace sofa::component::engine { @@ -33,6 +36,7 @@ extern "C" { SOFA_EXPORT_DYNAMIC_LIBRARY void initExternalModule(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleName(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleVersion(); + SOFA_EXPORT_DYNAMIC_LIBRARY void registerObjects(sofa::core::ObjectFactory* factory); } void initExternalModule() @@ -50,6 +54,14 @@ const char* getModuleVersion() return MODULE_VERSION; } +void registerObjects(sofa::core::ObjectFactory* factory) +{ + factory->registerObjectsFromPlugin("Sofa.Component.Engine.Analyze"); + factory->registerObjectsFromPlugin("Sofa.Component.Engine.Generate"); + factory->registerObjectsFromPlugin("Sofa.Component.Engine.Select"); + factory->registerObjectsFromPlugin("Sofa.Component.Engine.Transform"); +} + void init() { static bool first = true; @@ -61,6 +73,9 @@ void init() sofa::component::engine::select::init(); sofa::component::engine::transform::init(); + // make sure that this plugin is registered into the PluginManager + sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME); + first = false; } } diff --git a/Sofa/Component/src/sofa/component/init.cpp b/Sofa/Component/src/sofa/component/init.cpp index 783ca1c1aeb..58834cfc9a1 100644 --- a/Sofa/Component/src/sofa/component/init.cpp +++ b/Sofa/Component/src/sofa/component/init.cpp @@ -86,6 +86,7 @@ void registerObjects(sofa::core::ObjectFactory* factory) factory->registerObjectsFromPlugin("Sofa.Component.Haptics"); factory->registerObjectsFromPlugin("Sofa.Component.Diffusion"); factory->registerObjectsFromPlugin("Sofa.Component.ODESolver"); + factory->registerObjectsFromPlugin("Sofa.Component.Engine"); } void init() diff --git a/Sofa/framework/Helper/src/sofa/helper/ComponentChange.cpp b/Sofa/framework/Helper/src/sofa/helper/ComponentChange.cpp index a0ef1c3c0a9..d659ec8bb71 100644 --- a/Sofa/framework/Helper/src/sofa/helper/ComponentChange.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/ComponentChange.cpp @@ -784,6 +784,7 @@ const std::map< std::string, Dealiased, std::less<> > dealiasedComponents = { {"ImplicitEulerSolver", Dealiased("v24.12","EulerImplicitSolver")}, {"ImplicitEuler", Dealiased("v24.12","EulerImplicitSolver")}, {"VariationalSolver", Dealiased("v24.12","VariationalSymplecticSolver")}, + {"RigidEngine", Dealiased("v24.12","RigidToQuatEngine")}, }; From f963b0640baef346b9563a8ed2ceca62161892c0 Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Wed, 2 Oct 2024 13:50:51 +0200 Subject: [PATCH 10/43] [ODESolver] Rename files to match class name (#5034) --- .../ODESolver/Forward/CMakeLists.txt | 3 +- ...ulerSolver.cpp => EulerExplicitSolver.cpp} | 2 +- .../odesolver/forward/EulerExplicitSolver.h | 128 ++++++++++++++++++ .../component/odesolver/forward/EulerSolver.h | 108 +-------------- 4 files changed, 134 insertions(+), 107 deletions(-) rename Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/{EulerSolver.cpp => EulerExplicitSolver.cpp} (99%) create mode 100644 Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/EulerExplicitSolver.h diff --git a/Sofa/Component/ODESolver/Forward/CMakeLists.txt b/Sofa/Component/ODESolver/Forward/CMakeLists.txt index dbb3f1dc19b..d5f6ed16360 100644 --- a/Sofa/Component/ODESolver/Forward/CMakeLists.txt +++ b/Sofa/Component/ODESolver/Forward/CMakeLists.txt @@ -7,6 +7,7 @@ set(HEADER_FILES ${SOFACOMPONENTODESOLVERFORWARD_SOURCE_DIR}/config.h.in ${SOFACOMPONENTODESOLVERFORWARD_SOURCE_DIR}/init.h ${SOFACOMPONENTODESOLVERFORWARD_SOURCE_DIR}/EulerSolver.h + ${SOFACOMPONENTODESOLVERFORWARD_SOURCE_DIR}/EulerExplicitSolver.h ${SOFACOMPONENTODESOLVERFORWARD_SOURCE_DIR}/CentralDifferenceSolver.h ${SOFACOMPONENTODESOLVERFORWARD_SOURCE_DIR}/RungeKutta2Solver.h ${SOFACOMPONENTODESOLVERFORWARD_SOURCE_DIR}/RungeKutta4Solver.h @@ -15,7 +16,7 @@ set(HEADER_FILES set(SOURCE_FILES ${SOFACOMPONENTODESOLVERFORWARD_SOURCE_DIR}/init.cpp - ${SOFACOMPONENTODESOLVERFORWARD_SOURCE_DIR}/EulerSolver.cpp + ${SOFACOMPONENTODESOLVERFORWARD_SOURCE_DIR}/EulerExplicitSolver.cpp ${SOFACOMPONENTODESOLVERFORWARD_SOURCE_DIR}/CentralDifferenceSolver.cpp ${SOFACOMPONENTODESOLVERFORWARD_SOURCE_DIR}/RungeKutta2Solver.cpp ${SOFACOMPONENTODESOLVERFORWARD_SOURCE_DIR}/RungeKutta4Solver.cpp diff --git a/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/EulerSolver.cpp b/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/EulerExplicitSolver.cpp similarity index 99% rename from Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/EulerSolver.cpp rename to Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/EulerExplicitSolver.cpp index f13798253fa..a1a0ecc83b2 100644 --- a/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/EulerSolver.cpp +++ b/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/EulerExplicitSolver.cpp @@ -19,7 +19,7 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#include +#include #include #include #include diff --git a/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/EulerExplicitSolver.h b/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/EulerExplicitSolver.h new file mode 100644 index 00000000000..d5c9d1b83f2 --- /dev/null +++ b/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/EulerExplicitSolver.h @@ -0,0 +1,128 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture * +* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once +#include + +#include +#include +#include + +namespace sofa::simulation::common +{ +class MechanicalOperations; +class VectorOperations; +} + +namespace sofa::component::odesolver::forward +{ + +/** + * The simplest time integration. + * Two variants of the Euler solver are available in this component: + * - forward Euler method, also called explicit Euler method + * - semi-implicit Euler method, also called semi-explicit Euler method or symplectic Euler + * + * In both variants, acceleration is first computed. The system to compute the acceleration + * is M * a = f, where M is the mass matrix and f can be a force. + * In case of a diagonal mass matrix, M is trivially invertible and the acceleration + * can be computed without a linear solver. + * + * f is accumulated by force fields through the addForce function. Mappings can + * also contribute by projecting forces of mapped objects. + * f is computed based on the current state (current velocity and position). + * + * Explicit Euler method: + * The option "symplectic" must be set to false to use this variant. + * The explicit Euler method produces an approximate discrete solution by iterating + * x_{n+1} = x_n + v_n * dt + * v_{n+1} = v_n + a * dt + * + * Semi-implicit Euler method: + * The option "symplectic" must be set to true to use this variant. + * The semi-implicit Euler method produces an approximate discrete solution by iterating + * v_{n+1} = v_n + a * dt + * x_{n+1} = x_n + v_{n+1} * dt + * + * The semi-implicit Euler method is more robust than the standard Euler method. + */ +class SOFA_COMPONENT_ODESOLVER_FORWARD_API EulerExplicitSolver : public sofa::core::behavior::OdeSolver +{ +public: + SOFA_CLASS(EulerExplicitSolver, sofa::core::behavior::OdeSolver); + +protected: + EulerExplicitSolver(); + +public: + void solve(const core::ExecParams* params, SReal dt, sofa::core::MultiVecCoordId xResult, sofa::core::MultiVecDerivId vResult) override; + + Data d_symplectic; ///< If true (default), the velocities are updated before the positions and the method is symplectic, more robust. If false, the positions are updated before the velocities (standard Euler, less robust). + Data d_threadSafeVisitor; ///< If true, do not use realloc and free visitors in fwdInteractionForceField. + + SingleLink l_linearSolver; + + /// Given an input derivative order (0 for position, 1 for velocity, 2 for acceleration), + /// how much will it affect the output derivative of the given order. + SReal getIntegrationFactor(int inputDerivative, int outputDerivative) const override ; + + /// Given a solution of the linear system, + /// how much will it affect the output derivative of the given order. + /// + SReal getSolutionIntegrationFactor(int outputDerivative) const override ; + + void init() override ; + +protected: + + /// Update state variable (new position and velocity) based on the computed acceleration + /// The update takes constraints into account + void updateState(sofa::simulation::common::VectorOperations* vop, + sofa::simulation::common::MechanicalOperations* mop, + sofa::core::MultiVecCoordId xResult, + sofa::core::MultiVecDerivId vResult, + const sofa::core::behavior::MultiVecDeriv& acc, + SReal dt) const; + + /// Gravity times time step size is added to the velocity for some masses + /// v += g * dt + static void addSeparateGravity(sofa::simulation::common::MechanicalOperations* mop, SReal dt, core::MultiVecDerivId v); + + /// Assemble the force vector (right-hand side of the equation) + static void computeForce(sofa::simulation::common::MechanicalOperations* mop, core::MultiVecDerivId f); + + /// Compute the acceleration from the force and the inverse of the mass + /// acc = M^-1 * f + static void computeAcceleration(sofa::simulation::common::MechanicalOperations* mop, + core::MultiVecDerivId acc, + core::ConstMultiVecDerivId f); + + /// Apply projective constraints, such as FixedProjectiveConstraint + static void projectResponse(sofa::simulation::common::MechanicalOperations* mop, core::MultiVecDerivId vecId); + + static void solveConstraints(sofa::simulation::common::MechanicalOperations* mop, core::MultiVecDerivId acc); + + void assembleSystemMatrix(sofa::simulation::common::MechanicalOperations* mop) const; + + void solveSystem(core::MultiVecDerivId solution, core::MultiVecDerivId rhs) const; +}; + +} // namespace sofa::component::odesolver::forward diff --git a/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/EulerSolver.h b/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/EulerSolver.h index d5c9d1b83f2..2b904f356bb 100644 --- a/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/EulerSolver.h +++ b/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/EulerSolver.h @@ -20,109 +20,7 @@ * Contact information: contact@sofa-framework.org * ******************************************************************************/ #pragma once -#include +#include -#include -#include -#include - -namespace sofa::simulation::common -{ -class MechanicalOperations; -class VectorOperations; -} - -namespace sofa::component::odesolver::forward -{ - -/** - * The simplest time integration. - * Two variants of the Euler solver are available in this component: - * - forward Euler method, also called explicit Euler method - * - semi-implicit Euler method, also called semi-explicit Euler method or symplectic Euler - * - * In both variants, acceleration is first computed. The system to compute the acceleration - * is M * a = f, where M is the mass matrix and f can be a force. - * In case of a diagonal mass matrix, M is trivially invertible and the acceleration - * can be computed without a linear solver. - * - * f is accumulated by force fields through the addForce function. Mappings can - * also contribute by projecting forces of mapped objects. - * f is computed based on the current state (current velocity and position). - * - * Explicit Euler method: - * The option "symplectic" must be set to false to use this variant. - * The explicit Euler method produces an approximate discrete solution by iterating - * x_{n+1} = x_n + v_n * dt - * v_{n+1} = v_n + a * dt - * - * Semi-implicit Euler method: - * The option "symplectic" must be set to true to use this variant. - * The semi-implicit Euler method produces an approximate discrete solution by iterating - * v_{n+1} = v_n + a * dt - * x_{n+1} = x_n + v_{n+1} * dt - * - * The semi-implicit Euler method is more robust than the standard Euler method. - */ -class SOFA_COMPONENT_ODESOLVER_FORWARD_API EulerExplicitSolver : public sofa::core::behavior::OdeSolver -{ -public: - SOFA_CLASS(EulerExplicitSolver, sofa::core::behavior::OdeSolver); - -protected: - EulerExplicitSolver(); - -public: - void solve(const core::ExecParams* params, SReal dt, sofa::core::MultiVecCoordId xResult, sofa::core::MultiVecDerivId vResult) override; - - Data d_symplectic; ///< If true (default), the velocities are updated before the positions and the method is symplectic, more robust. If false, the positions are updated before the velocities (standard Euler, less robust). - Data d_threadSafeVisitor; ///< If true, do not use realloc and free visitors in fwdInteractionForceField. - - SingleLink l_linearSolver; - - /// Given an input derivative order (0 for position, 1 for velocity, 2 for acceleration), - /// how much will it affect the output derivative of the given order. - SReal getIntegrationFactor(int inputDerivative, int outputDerivative) const override ; - - /// Given a solution of the linear system, - /// how much will it affect the output derivative of the given order. - /// - SReal getSolutionIntegrationFactor(int outputDerivative) const override ; - - void init() override ; - -protected: - - /// Update state variable (new position and velocity) based on the computed acceleration - /// The update takes constraints into account - void updateState(sofa::simulation::common::VectorOperations* vop, - sofa::simulation::common::MechanicalOperations* mop, - sofa::core::MultiVecCoordId xResult, - sofa::core::MultiVecDerivId vResult, - const sofa::core::behavior::MultiVecDeriv& acc, - SReal dt) const; - - /// Gravity times time step size is added to the velocity for some masses - /// v += g * dt - static void addSeparateGravity(sofa::simulation::common::MechanicalOperations* mop, SReal dt, core::MultiVecDerivId v); - - /// Assemble the force vector (right-hand side of the equation) - static void computeForce(sofa::simulation::common::MechanicalOperations* mop, core::MultiVecDerivId f); - - /// Compute the acceleration from the force and the inverse of the mass - /// acc = M^-1 * f - static void computeAcceleration(sofa::simulation::common::MechanicalOperations* mop, - core::MultiVecDerivId acc, - core::ConstMultiVecDerivId f); - - /// Apply projective constraints, such as FixedProjectiveConstraint - static void projectResponse(sofa::simulation::common::MechanicalOperations* mop, core::MultiVecDerivId vecId); - - static void solveConstraints(sofa::simulation::common::MechanicalOperations* mop, core::MultiVecDerivId acc); - - void assembleSystemMatrix(sofa::simulation::common::MechanicalOperations* mop) const; - - void solveSystem(core::MultiVecDerivId solution, core::MultiVecDerivId rhs) const; -}; - -} // namespace sofa::component::odesolver::forward +#include +SOFA_HEADER_DEPRECATED("v24.12", "v25.06", "sofa/component/odesolver/forward/EulerExplicitSolver.h") From b8bdb031dce6577c3312bb6ba9f39c3e1c92cb32 Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Fri, 4 Oct 2024 02:26:42 +0200 Subject: [PATCH 11/43] [VolumetricRendering] Initialize SOFACuda (#5039) --- .../extensions/CUDA/src/VolumetricRendering/CUDA/init.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/applications/plugins/VolumetricRendering/extensions/CUDA/src/VolumetricRendering/CUDA/init.cpp b/applications/plugins/VolumetricRendering/extensions/CUDA/src/VolumetricRendering/CUDA/init.cpp index 53de20dbe46..a45c8caefc7 100644 --- a/applications/plugins/VolumetricRendering/extensions/CUDA/src/VolumetricRendering/CUDA/init.cpp +++ b/applications/plugins/VolumetricRendering/extensions/CUDA/src/VolumetricRendering/CUDA/init.cpp @@ -21,7 +21,10 @@ ******************************************************************************/ #include #include +#include #include + + namespace volumetricrendering::cuda { @@ -53,6 +56,7 @@ void init() if (first) { volumetricrendering::init(); + sofa::gpu::cuda::init(); first = false; } } From 9152342f360d1a25d2132b7351d58457ab2f59ec Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Fri, 4 Oct 2024 21:58:46 +0900 Subject: [PATCH 12/43] [LinearSolver] Apply new factory registration mechanism (#5011) * apply new register mechanism to linearsolver * fix unit tests * Apply suggestions from code review (updates on component description) Co-authored-by: Hugo --------- Co-authored-by: Hugo --- .../direct/AsyncSparseLDLSolver.cpp | 10 +++-- .../linearsolver/direct/BTDLinearSolver.cpp | 9 ++-- .../linearsolver/direct/CholeskySolver.cpp | 7 +++- .../direct/EigenSimplicialLDLT.cpp | 10 +++-- .../direct/EigenSimplicialLLT.cpp | 15 ++++--- .../linearsolver/direct/EigenSparseLU.cpp | 15 ++++--- .../linearsolver/direct/EigenSparseQR.cpp | 15 ++++--- .../direct/MatrixLinearSystem[BTDMatrix].cpp | 9 ++-- .../direct/PrecomputedLinearSolver.cpp | 8 ++-- .../linearsolver/direct/SVDLinearSolver.cpp | 10 ++--- .../linearsolver/direct/SparseLDLSolver.cpp | 11 ++--- .../TypedMatrixLinearSystem[BTDMatrix].cpp | 9 ++++ .../component/linearsolver/direct/init.cpp | 41 ++++++++++++++++++- .../linearsolver/iterative/CGLinearSolver.cpp | 19 ++++----- .../MatrixFreeSystem[GraphScattered].cpp | 14 ++++--- .../iterative/MinResLinearSolver.cpp | 20 ++++----- .../iterative/ShewchukPCGLinearSolver.cpp | 8 ++-- .../component/linearsolver/iterative/init.cpp | 25 ++++++++++- .../ordering/AMDOrderingMethod.cpp | 7 +++- .../ordering/COLAMDOrderingMethod.cpp | 7 +++- .../ordering/NaturalOrderingMethod.cpp | 7 +++- .../component/linearsolver/ordering/init.cpp | 17 ++++++++ .../BlockJacobiPreconditioner.cpp | 7 +++- .../preconditioner/JacobiPreconditioner.cpp | 10 ++--- .../PrecomputedMatrixSystem.cpp | 39 +++++++++++++++--- .../PrecomputedWarpPreconditioner.cpp | 8 ++-- .../preconditioner/RotationMatrixSystem.cpp | 38 ++++++++++++++--- .../preconditioner/SSORPreconditioner.cpp | 10 ++--- .../preconditioner/WarpPreconditioner.cpp | 10 +++-- .../linearsolver/preconditioner/init.cpp | 27 +++++++++++- .../src/sofa/component/linearsolver/init.cpp | 15 +++++++ .../tests/ConstantForceField_test.cpp | 1 + Sofa/Component/src/sofa/component/init.cpp | 1 + .../src/sofa/helper/ComponentChange.cpp | 11 +++++ .../ParallelImplementationsRegistry_test.cpp | 4 ++ 35 files changed, 358 insertions(+), 116 deletions(-) diff --git a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/AsyncSparseLDLSolver.cpp b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/AsyncSparseLDLSolver.cpp index 151e45250eb..5049fba0152 100644 --- a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/AsyncSparseLDLSolver.cpp +++ b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/AsyncSparseLDLSolver.cpp @@ -30,10 +30,12 @@ namespace sofa::component::linearsolver::direct using linearalgebra::CompressedRowSparseMatrix; using linearalgebra::FullVector; -int AsyncSparseLDLSolverClass = core::RegisterObject("Asynchronous direct Linear Solver using a Sparse LDL^T factorization.") - .add< AsyncSparseLDLSolver< CompressedRowSparseMatrix , FullVector > >(true) - .add< AsyncSparseLDLSolver< CompressedRowSparseMatrix >, FullVector > >() -; +void registerAsyncSparseLDLSolver(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Asynchronous direct Linear Solver using a Sparse LDL^T factorization.") + .add< AsyncSparseLDLSolver< CompressedRowSparseMatrix, FullVector > >(true) + .add< AsyncSparseLDLSolver< CompressedRowSparseMatrix >, FullVector > >()); +} template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API AsyncSparseLDLSolver< CompressedRowSparseMatrix ,FullVector >; template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API AsyncSparseLDLSolver< CompressedRowSparseMatrix< type::Mat<3,3,SReal> >,FullVector >; diff --git a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/BTDLinearSolver.cpp b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/BTDLinearSolver.cpp index 1aa29fd88ad..0eadbac996e 100644 --- a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/BTDLinearSolver.cpp +++ b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/BTDLinearSolver.cpp @@ -31,9 +31,12 @@ namespace sofa::component::linearsolver::direct { -int BTDLinearSolverClass = core::RegisterObject("Linear system solver using Thomas Algorithm for Block Tridiagonal matrices") - .add< BTDLinearSolver, linearalgebra::BlockVector<6, SReal> > >(true) -; + +void registerBTDLinearSolver(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Linear system solver using Thomas Algorithm for Block Tridiagonal matrices.") + .add< BTDLinearSolver, linearalgebra::BlockVector<6, SReal> > >(true)); +} template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API BTDLinearSolver< linearalgebra::BTDMatrix<6, SReal>, linearalgebra::BlockVector<6, SReal> >; diff --git a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/CholeskySolver.cpp b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/CholeskySolver.cpp index f4a9417e8a6..c887c85f5a5 100644 --- a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/CholeskySolver.cpp +++ b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/CholeskySolver.cpp @@ -30,9 +30,12 @@ namespace sofa::component::linearsolver::direct using namespace sofa::defaulttype; using namespace sofa::linearalgebra; -int CholeskySolverClass = core::RegisterObject("Direct linear solver based on Cholesky factorization, for dense matrices") +void registerCholeskySolver(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Direct linear solver based on Cholesky factorization, for dense matrices.") .add< CholeskySolver< SparseMatrix, FullVector > >(true) - .add< CholeskySolver< FullMatrix, FullVector > >(); + .add< CholeskySolver< FullMatrix, FullVector > >()); +} template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API CholeskySolver< SparseMatrix, FullVector >; template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API CholeskySolver< FullMatrix, FullVector >; diff --git a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/EigenSimplicialLDLT.cpp b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/EigenSimplicialLDLT.cpp index 92452e1cba8..10900568c00 100644 --- a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/EigenSimplicialLDLT.cpp +++ b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/EigenSimplicialLDLT.cpp @@ -30,9 +30,11 @@ namespace sofa::component::linearsolver::direct template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSimplicialLDLT< SReal >; template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSimplicialLDLT< sofa::type::Mat<3,3,SReal> >; -int EigenSimplicialLDLTCRSClass = sofa::core::RegisterObject("Direct Linear Solver using a Sparse LDL^T factorization.") -.add< EigenSimplicialLDLT< SReal > >() -.add< EigenSimplicialLDLT< sofa::type::Mat<3,3,SReal> > >() -; +void registerEigenSimplicialLDLT(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Direct linear solver using a Sparse LDL^T factorization.") + .add< EigenSimplicialLDLT< SReal > >() + .add< EigenSimplicialLDLT< sofa::type::Mat<3, 3, SReal> > >()); +} } diff --git a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/EigenSimplicialLLT.cpp b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/EigenSimplicialLLT.cpp index 260bf66c3c4..50ce6184726 100644 --- a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/EigenSimplicialLLT.cpp +++ b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/EigenSimplicialLLT.cpp @@ -27,12 +27,15 @@ namespace sofa::component::linearsolver::direct { - template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSimplicialLLT< SReal >; - template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSimplicialLLT< sofa::type::Mat<3,3,SReal> >; - int EigenSimplicialLLTCRSClass = sofa::core::RegisterObject("Direct Linear Solver using a Sparse LL^T factorization.") - .add< EigenSimplicialLLT< SReal > >() - .add< EigenSimplicialLLT< sofa::type::Mat<3,3,SReal> > >() - ; +template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSimplicialLLT< SReal >; +template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSimplicialLLT< sofa::type::Mat<3,3,SReal> >; + +void registerEigenSimplicialLLT(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Direct linear solver using a Sparse LL^T factorization.") + .add< EigenSimplicialLLT< SReal > >() + .add< EigenSimplicialLLT< sofa::type::Mat<3, 3, SReal> > >()); +} } diff --git a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/EigenSparseLU.cpp b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/EigenSparseLU.cpp index 3c31eb127ae..8f705911e98 100644 --- a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/EigenSparseLU.cpp +++ b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/EigenSparseLU.cpp @@ -27,12 +27,15 @@ namespace sofa::component::linearsolver::direct { - template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSparseLU< SReal >; - template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSparseLU< sofa::type::Mat<3,3,SReal> >; - int EigenSparseLUCRSClass = sofa::core::RegisterObject("Direct Linear Solver using a Sparse LU factorization.") - .add< EigenSparseLU< SReal > >() - .add< EigenSparseLU< sofa::type::Mat<3,3,SReal> > >() - ; +template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSparseLU< SReal >; +template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSparseLU< sofa::type::Mat<3,3,SReal> >; + +void registerEigenSparseLU(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Direct linear solver using a Sparse LU factorization.") + .add< EigenSparseLU< SReal > >() + .add< EigenSparseLU< sofa::type::Mat<3, 3, SReal> > >()); +} } diff --git a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/EigenSparseQR.cpp b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/EigenSparseQR.cpp index 790246c146c..ab353d4f08e 100644 --- a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/EigenSparseQR.cpp +++ b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/EigenSparseQR.cpp @@ -27,12 +27,15 @@ namespace sofa::component::linearsolver::direct { - template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSparseQR< SReal >; - template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSparseQR< sofa::type::Mat<3,3,SReal>>; - int EigenSparseQRCRSClass = sofa::core::RegisterObject("Direct Linear Solver using a Sparse QR factorization.") - .add< EigenSparseQR< SReal > >() - .add< EigenSparseQR< sofa::type::Mat<3,3,SReal> > >() - ; +template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSparseQR< SReal >; +template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSparseQR< sofa::type::Mat<3,3,SReal>>; + +void registerEigenSparseQR(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Direct linear solver using a Sparse QR factorization.") + .add< EigenSparseQR< SReal > >() + .add< EigenSparseQR< sofa::type::Mat<3, 3, SReal> > >()); +} } diff --git a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/MatrixLinearSystem[BTDMatrix].cpp b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/MatrixLinearSystem[BTDMatrix].cpp index 2bfd60b26d1..a20b2cbd53b 100644 --- a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/MatrixLinearSystem[BTDMatrix].cpp +++ b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/MatrixLinearSystem[BTDMatrix].cpp @@ -27,10 +27,13 @@ namespace sofa::component::linearsystem { + template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API MatrixLinearSystem< linearalgebra::BTDMatrix<6, SReal>, linearalgebra::BlockVector<6, SReal> >; -int AssemblingMatrixLinearSystemBTDClass = core::RegisterObject("Linear system") -.add, linearalgebra::BlockVector<6, SReal> > >(); -; +void registerMatrixLinearSystemBTDMatrix(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Linear system dedicated to a Band Tri Diagonal matrix.") + .add, linearalgebra::BlockVector<6, SReal> > >()); +} } diff --git a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/PrecomputedLinearSolver.cpp b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/PrecomputedLinearSolver.cpp index ce9235152f0..4c49fa0d738 100644 --- a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/PrecomputedLinearSolver.cpp +++ b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/PrecomputedLinearSolver.cpp @@ -28,9 +28,11 @@ namespace sofa::component::linearsolver::direct using namespace sofa::linearalgebra; -int PrecomputedLinearSolverClass = core::RegisterObject("Linear system solver based on a precomputed inverse matrix") - .add< PrecomputedLinearSolver< CompressedRowSparseMatrix , FullVector > >() - ; +void registerPrecomputedLinearSolver(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Linear system solver based on a precomputed inverse matrix") + .add< PrecomputedLinearSolver< CompressedRowSparseMatrix, FullVector > >()); +} template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API PrecomputedLinearSolver< CompressedRowSparseMatrix , FullVector >; diff --git a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/SVDLinearSolver.cpp b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/SVDLinearSolver.cpp index c1b513a292d..6b42d529ef6 100644 --- a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/SVDLinearSolver.cpp +++ b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/SVDLinearSolver.cpp @@ -32,13 +32,13 @@ namespace sofa::component::linearsolver::direct using namespace sofa::linearalgebra; -int SVDLinearSolverClass = core::RegisterObject("Linear system solver using a SVD decomposition of a dense matrix") +void registerSVDLinearSolver(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Linear system solver using a SVD decomposition of a dense matrix.") .add< SVDLinearSolver< FullMatrix, FullVector > >() .add< SVDLinearSolver< CompressedRowSparseMatrix, FullVector > >() - .add< SVDLinearSolver< CompressedRowSparseMatrix>, FullVector > >() - .addAlias("SVDLinear") - .addAlias("SVD") - ; + .add< SVDLinearSolver< CompressedRowSparseMatrix>, FullVector > >()); +} template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API SVDLinearSolver< FullMatrix, FullVector >; template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API SVDLinearSolver< CompressedRowSparseMatrix, FullVector >; diff --git a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/SparseLDLSolver.cpp b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/SparseLDLSolver.cpp index 432fce75598..5b336137077 100644 --- a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/SparseLDLSolver.cpp +++ b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/SparseLDLSolver.cpp @@ -29,11 +29,12 @@ namespace sofa::component::linearsolver::direct using namespace sofa::linearalgebra; -int SparseLDLSolverClass = core::RegisterObject("Direct Linear Solver using a Sparse LDL^T factorization.") - .add< SparseLDLSolver< CompressedRowSparseMatrix,FullVector > >(true) - .add< SparseLDLSolver< CompressedRowSparseMatrix >,FullVector > >() - -; +void registerSparseLDLSolver(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Direct linear solver using a Sparse LDL^T factorization.") + .add< SparseLDLSolver< CompressedRowSparseMatrix, FullVector > >(true) + .add< SparseLDLSolver< CompressedRowSparseMatrix >, FullVector > >()); +} template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API SparseLDLSolver< CompressedRowSparseMatrix,FullVector >; template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API SparseLDLSolver< CompressedRowSparseMatrix< type::Mat<3,3,SReal> >,FullVector >; diff --git a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/TypedMatrixLinearSystem[BTDMatrix].cpp b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/TypedMatrixLinearSystem[BTDMatrix].cpp index 83593d78d59..a379a362aec 100644 --- a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/TypedMatrixLinearSystem[BTDMatrix].cpp +++ b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/TypedMatrixLinearSystem[BTDMatrix].cpp @@ -23,7 +23,16 @@ #include #include +#include + namespace sofa::component::linearsystem { template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API TypedMatrixLinearSystem< linearalgebra::BTDMatrix<6, SReal>, linearalgebra::BlockVector<6, SReal> >; + +void registerTypedMatrixLinearSystemBTDMatrix(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Linear system dedicated to a Band Tri Diagonal typed matrix.") + .add, linearalgebra::BlockVector<6, SReal> > >()); +} + } diff --git a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/init.cpp b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/init.cpp index c2cb8734ee2..2515edac27b 100644 --- a/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/init.cpp +++ b/Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/init.cpp @@ -22,13 +22,33 @@ #include #include #include +#include + +namespace sofa::component::linearsystem +{ + extern void registerMatrixLinearSystemBTDMatrix(sofa::core::ObjectFactory* factory); + extern void registerTypedMatrixLinearSystemBTDMatrix(sofa::core::ObjectFactory* factory); +} + namespace sofa::component::linearsolver::direct { - + +extern void registerAsyncSparseLDLSolver(sofa::core::ObjectFactory* factory); +extern void registerBTDLinearSolver(sofa::core::ObjectFactory* factory); +extern void registerCholeskySolver(sofa::core::ObjectFactory* factory); +extern void registerEigenSimplicialLDLT(sofa::core::ObjectFactory* factory); +extern void registerEigenSimplicialLLT(sofa::core::ObjectFactory* factory); +extern void registerEigenSparseLU(sofa::core::ObjectFactory* factory); +extern void registerEigenSparseQR(sofa::core::ObjectFactory* factory); +extern void registerPrecomputedLinearSolver(sofa::core::ObjectFactory* factory); +extern void registerSparseLDLSolver(sofa::core::ObjectFactory* factory); +extern void registerSVDLinearSolver(sofa::core::ObjectFactory* factory); + extern "C" { SOFA_EXPORT_DYNAMIC_LIBRARY void initExternalModule(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleName(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleVersion(); + SOFA_EXPORT_DYNAMIC_LIBRARY void registerObjects(sofa::core::ObjectFactory* factory); } void initExternalModule() @@ -63,11 +83,30 @@ void registerOrderingMethods() registerOrderingMethods(); } +void registerObjects(sofa::core::ObjectFactory* factory) +{ + registerAsyncSparseLDLSolver(factory); + registerBTDLinearSolver(factory); + registerCholeskySolver(factory); + registerEigenSimplicialLDLT(factory); + registerEigenSimplicialLLT(factory); + registerEigenSparseLU(factory); + registerEigenSparseQR(factory); + linearsystem::registerMatrixLinearSystemBTDMatrix(factory); + registerPrecomputedLinearSolver(factory); + registerSparseLDLSolver(factory); + registerSVDLinearSolver(factory); + linearsystem::registerTypedMatrixLinearSystemBTDMatrix(factory); +} + void init() { static bool first = true; if (first) { + // make sure that this plugin is registered into the PluginManager + sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME); + registerOrderingMethods(); registerOrderingMethods(); diff --git a/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/CGLinearSolver.cpp b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/CGLinearSolver.cpp index d37ba06bb40..c7fc473754e 100644 --- a/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/CGLinearSolver.cpp +++ b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/CGLinearSolver.cpp @@ -64,20 +64,19 @@ inline void CGLinearSolverregisterObjects(core::ObjectRegistrationData("Linear system solver using the conjugate gradient iterative algorithm") .add< CGLinearSolver< GraphScatteredMatrix, GraphScatteredVector > >(true) .add< CGLinearSolver< FullMatrix, FullVector > >() .add< CGLinearSolver< SparseMatrix, FullVector > >() .add< CGLinearSolver< CompressedRowSparseMatrix, FullVector > >() - .add< CGLinearSolver< CompressedRowSparseMatrix >, FullVector > >() - .add< CGLinearSolver< CompressedRowSparseMatrix >, FullVector > >() - .add< CGLinearSolver< CompressedRowSparseMatrix >, FullVector > >() - .add< CGLinearSolver< CompressedRowSparseMatrix >, FullVector > >() - .add< CGLinearSolver< CompressedRowSparseMatrix >, FullVector > >() - - .addAlias("CGSolver") - .addAlias("ConjugateGradient") - ; + .add< CGLinearSolver< CompressedRowSparseMatrix >, FullVector > >() + .add< CGLinearSolver< CompressedRowSparseMatrix >, FullVector > >() + .add< CGLinearSolver< CompressedRowSparseMatrix >, FullVector > >() + .add< CGLinearSolver< CompressedRowSparseMatrix >, FullVector > >() + .add< CGLinearSolver< CompressedRowSparseMatrix >, FullVector > >()); +} template class SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API CGLinearSolver< GraphScatteredMatrix, GraphScatteredVector >; template class SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API CGLinearSolver< FullMatrix, FullVector >; diff --git a/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/MatrixFreeSystem[GraphScattered].cpp b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/MatrixFreeSystem[GraphScattered].cpp index 0c515378227..1da21eb1bbd 100644 --- a/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/MatrixFreeSystem[GraphScattered].cpp +++ b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/MatrixFreeSystem[GraphScattered].cpp @@ -25,12 +25,16 @@ namespace sofa::component::linearsystem { - using sofa::component::linearsolver::GraphScatteredMatrix; - using sofa::component::linearsolver::GraphScatteredVector; - template class SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API MatrixFreeSystem; +using sofa::component::linearsolver::GraphScatteredMatrix; +using sofa::component::linearsolver::GraphScatteredVector; - int MatrixFreeSystemClass = core::RegisterObject("Matrix-free linear system") - .add< MatrixFreeSystem >(); +template class SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API MatrixFreeSystem; + +void registerMatrixFreeSystemGraphScattered(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Matrix-free (unbuilt) linear system.") + .add< MatrixFreeSystem >()); +} } //namespace sofa::component::linearsystem diff --git a/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/MinResLinearSolver.cpp b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/MinResLinearSolver.cpp index 3461baeca09..8c967538b4a 100644 --- a/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/MinResLinearSolver.cpp +++ b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/MinResLinearSolver.cpp @@ -31,21 +31,19 @@ using namespace sofa::type; using namespace sofa::defaulttype; using namespace sofa::linearalgebra; - -int MinResLinearSolverClass = core::RegisterObject("Linear system solver using the MINRES iterative algorithm") +void registerMinResLinearSolver(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Linear system solver using the MINRES iterative algorithm.") .add< MinResLinearSolver< GraphScatteredMatrix, GraphScatteredVector > >(true) .add< MinResLinearSolver< FullMatrix, FullVector > >() .add< MinResLinearSolver< SparseMatrix, FullVector > >() .add< MinResLinearSolver< CompressedRowSparseMatrix, FullVector > >() - .add< MinResLinearSolver< CompressedRowSparseMatrix >, FullVector > >() - .add< MinResLinearSolver< CompressedRowSparseMatrix >, FullVector > >() - .add< MinResLinearSolver< CompressedRowSparseMatrix >, FullVector > >() - .add< MinResLinearSolver< CompressedRowSparseMatrix >, FullVector > >() - .add< MinResLinearSolver< CompressedRowSparseMatrix >, FullVector > >() - - .addAlias("MINRESSolver") - .addAlias("MinResSolver") - ; + .add< MinResLinearSolver< CompressedRowSparseMatrix >, FullVector > >() + .add< MinResLinearSolver< CompressedRowSparseMatrix >, FullVector > >() + .add< MinResLinearSolver< CompressedRowSparseMatrix >, FullVector > >() + .add< MinResLinearSolver< CompressedRowSparseMatrix >, FullVector > >() + .add< MinResLinearSolver< CompressedRowSparseMatrix >, FullVector > >()); +} template class SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API MinResLinearSolver< GraphScatteredMatrix, GraphScatteredVector >; template class SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API MinResLinearSolver< FullMatrix, FullVector >; diff --git a/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/ShewchukPCGLinearSolver.cpp b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/ShewchukPCGLinearSolver.cpp index 31a37f1962c..5cd240c90db 100644 --- a/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/ShewchukPCGLinearSolver.cpp +++ b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/ShewchukPCGLinearSolver.cpp @@ -28,9 +28,11 @@ namespace sofa::component::linearsolver::iterative { -int ShewchukPCGLinearSolverClass = core::RegisterObject("Linear system solver using the conjugate gradient iterative algorithm") - .add< ShewchukPCGLinearSolver >(true) - .addAlias("PCGLinearSolver"); +void registerShewchukPCGLinearSolver(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Linear system solver using the Shewchuk conjugate gradient iterative algorithm.") + .add< ShewchukPCGLinearSolver >()); +} template class SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API ShewchukPCGLinearSolver; diff --git a/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/init.cpp b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/init.cpp index c64c072b575..c29da966335 100644 --- a/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/init.cpp +++ b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/init.cpp @@ -21,13 +21,25 @@ ******************************************************************************/ #include #include +#include + +namespace sofa::component::linearsystem +{ + extern void registerMatrixFreeSystemGraphScattered(sofa::core::ObjectFactory* factory); +} + namespace sofa::component::linearsolver::iterative { - + +extern void registerCGLinearSolver(sofa::core::ObjectFactory* factory); +extern void registerMinResLinearSolver(sofa::core::ObjectFactory* factory); +extern void registerShewchukPCGLinearSolver(sofa::core::ObjectFactory* factory); + extern "C" { SOFA_EXPORT_DYNAMIC_LIBRARY void initExternalModule(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleName(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleVersion(); + SOFA_EXPORT_DYNAMIC_LIBRARY void registerObjects(sofa::core::ObjectFactory* factory); } void initExternalModule() @@ -45,11 +57,22 @@ const char* getModuleVersion() return MODULE_VERSION; } +void registerObjects(sofa::core::ObjectFactory* factory) +{ + registerCGLinearSolver(factory); + linearsystem::registerMatrixFreeSystemGraphScattered(factory); + registerMinResLinearSolver(factory); + registerShewchukPCGLinearSolver(factory); +} + void init() { static bool first = true; if (first) { + // make sure that this plugin is registered into the PluginManager + sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME); + first = false; } } diff --git a/Sofa/Component/LinearSolver/Ordering/src/sofa/component/linearsolver/ordering/AMDOrderingMethod.cpp b/Sofa/Component/LinearSolver/Ordering/src/sofa/component/linearsolver/ordering/AMDOrderingMethod.cpp index f64521895c8..9cc53bc6c49 100644 --- a/Sofa/Component/LinearSolver/Ordering/src/sofa/component/linearsolver/ordering/AMDOrderingMethod.cpp +++ b/Sofa/Component/LinearSolver/Ordering/src/sofa/component/linearsolver/ordering/AMDOrderingMethod.cpp @@ -25,8 +25,11 @@ namespace sofa::component::linearsolver::ordering { -int AMDOrderingMethodClass = sofa::core::RegisterObject("Approximate minimum degree ordering implemented in the Eigen library") - .add(); +void registerAMDOrderingMethod(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Approximate minimum degree ordering implemented in the Eigen library.") + .add()); +} std::string AMDOrderingMethod::methodName() const { diff --git a/Sofa/Component/LinearSolver/Ordering/src/sofa/component/linearsolver/ordering/COLAMDOrderingMethod.cpp b/Sofa/Component/LinearSolver/Ordering/src/sofa/component/linearsolver/ordering/COLAMDOrderingMethod.cpp index 3ee7670ffbf..7c8080f97ef 100644 --- a/Sofa/Component/LinearSolver/Ordering/src/sofa/component/linearsolver/ordering/COLAMDOrderingMethod.cpp +++ b/Sofa/Component/LinearSolver/Ordering/src/sofa/component/linearsolver/ordering/COLAMDOrderingMethod.cpp @@ -25,8 +25,11 @@ namespace sofa::component::linearsolver::ordering { -int COLAMDOrderingMethodClass = sofa::core::RegisterObject("Column approximate minimum degree ordering implemented in the Eigen library") - .add(); +void registerCOLAMDOrderingMethod(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Column approximate minimum degree ordering implemented in the Eigen library.") + .add()); +} std::string COLAMDOrderingMethod::methodName() const { diff --git a/Sofa/Component/LinearSolver/Ordering/src/sofa/component/linearsolver/ordering/NaturalOrderingMethod.cpp b/Sofa/Component/LinearSolver/Ordering/src/sofa/component/linearsolver/ordering/NaturalOrderingMethod.cpp index 95fbaaac862..e618bbc7a10 100644 --- a/Sofa/Component/LinearSolver/Ordering/src/sofa/component/linearsolver/ordering/NaturalOrderingMethod.cpp +++ b/Sofa/Component/LinearSolver/Ordering/src/sofa/component/linearsolver/ordering/NaturalOrderingMethod.cpp @@ -42,7 +42,10 @@ void NaturalOrderingMethod::computePermutation( } } -int NaturalOrderingMethodClass = core::RegisterObject("Natural order (no permutation). Corresponding to an identity matrix.") - .add(); +void registerNaturalOrderingMethod(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Natural order (no permutation). Corresponding to an identity matrix.") + .add()); +} } diff --git a/Sofa/Component/LinearSolver/Ordering/src/sofa/component/linearsolver/ordering/init.cpp b/Sofa/Component/LinearSolver/Ordering/src/sofa/component/linearsolver/ordering/init.cpp index 63dd35a4118..9df8a85c25c 100644 --- a/Sofa/Component/LinearSolver/Ordering/src/sofa/component/linearsolver/ordering/init.cpp +++ b/Sofa/Component/LinearSolver/Ordering/src/sofa/component/linearsolver/ordering/init.cpp @@ -21,13 +21,20 @@ ******************************************************************************/ #include #include +#include + namespace sofa::component::linearsolver::ordering { +extern void registerAMDOrderingMethod(sofa::core::ObjectFactory* factory); +extern void registerCOLAMDOrderingMethod(sofa::core::ObjectFactory* factory); +extern void registerNaturalOrderingMethod(sofa::core::ObjectFactory* factory); + extern "C" { SOFA_EXPORT_DYNAMIC_LIBRARY void initExternalModule(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleName(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleVersion(); + SOFA_EXPORT_DYNAMIC_LIBRARY void registerObjects(sofa::core::ObjectFactory* factory); } void initExternalModule() @@ -45,11 +52,21 @@ const char* getModuleVersion() return MODULE_VERSION; } +void registerObjects(sofa::core::ObjectFactory* factory) +{ + registerAMDOrderingMethod(factory); + registerCOLAMDOrderingMethod(factory); + registerNaturalOrderingMethod(factory); +} + void init() { static bool first = true; if (first) { + // make sure that this plugin is registered into the PluginManager + sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME); + first = false; } } diff --git a/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/BlockJacobiPreconditioner.cpp b/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/BlockJacobiPreconditioner.cpp index 0b1d8c1de4b..84c98e82376 100644 --- a/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/BlockJacobiPreconditioner.cpp +++ b/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/BlockJacobiPreconditioner.cpp @@ -27,8 +27,11 @@ namespace sofa::component::linearsolver::preconditioner using namespace sofa::linearalgebra; -int BlockJacobiPreconditionerClass = core::RegisterObject("Linear solver based on a NxN block diagonal matrix (i.e. block Jacobi preconditioner)") - .add< BlockJacobiPreconditioner ,FullVector > >(); +void registerBlockJacobiPreconditioner(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Linear solver based on a NxN block diagonal matrix (i.e. block Jacobi preconditioner).") + .add< BlockJacobiPreconditioner, FullVector > >()); +} template class SOFA_COMPONENT_LINEARSOLVER_PRECONDITIONER_API BlockJacobiPreconditioner, FullVector >; diff --git a/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/JacobiPreconditioner.cpp b/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/JacobiPreconditioner.cpp index ddc5ae29adc..162a3dfd877 100644 --- a/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/JacobiPreconditioner.cpp +++ b/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/JacobiPreconditioner.cpp @@ -28,11 +28,11 @@ namespace sofa::component::linearsolver::preconditioner using namespace sofa::linearalgebra; -int JacobiPreconditionerClass = core::RegisterObject("Linear solver based on a diagonal matrix (i.e. Jacobi preconditioner)") - .add< JacobiPreconditioner, FullVector > >(true) - .addAlias("JacobiLinearSolver") - .addAlias("JacobiSolver") - ; +void registerJacobiPreconditioner(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Linear solver based on a diagonal matrix (i.e. Jacobi preconditioner).") + .add< JacobiPreconditioner, FullVector > >()); +} template class SOFA_COMPONENT_LINEARSOLVER_PRECONDITIONER_API JacobiPreconditioner, FullVector >; diff --git a/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/PrecomputedMatrixSystem.cpp b/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/PrecomputedMatrixSystem.cpp index 3d43ff07361..d49e246c306 100644 --- a/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/PrecomputedMatrixSystem.cpp +++ b/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/PrecomputedMatrixSystem.cpp @@ -1,14 +1,41 @@ -#include +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture * +* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#include #include #include #include namespace sofa::component::linearsolver::preconditioner { - using sofa::linearalgebra::CompressedRowSparseMatrix; - using sofa::linearalgebra::FullVector; - template class SOFA_COMPONENT_LINEARSOLVER_PRECONDITIONER_API PrecomputedMatrixSystem< linearalgebra::CompressedRowSparseMatrix, FullVector >; - int PrecomputedMatrixSystemClass = core::RegisterObject("Matrix system") - .add, FullVector > >(true); +using sofa::linearalgebra::CompressedRowSparseMatrix; +using sofa::linearalgebra::FullVector; + +template class SOFA_COMPONENT_LINEARSOLVER_PRECONDITIONER_API PrecomputedMatrixSystem< linearalgebra::CompressedRowSparseMatrix, FullVector >; + +void registerPrecomputedMatrixSystem(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Precomputed matrix system.") + .add, FullVector > >()); +} + } diff --git a/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/PrecomputedWarpPreconditioner.cpp b/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/PrecomputedWarpPreconditioner.cpp index 483b4b65747..897f854328d 100644 --- a/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/PrecomputedWarpPreconditioner.cpp +++ b/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/PrecomputedWarpPreconditioner.cpp @@ -25,9 +25,11 @@ namespace sofa::component::linearsolver::preconditioner { -int PrecomputedWarpPreconditionerClass = core::RegisterObject("Linear system solver based on a precomputed inverse matrix, wrapped by a per-node rotation matrix") - .add< PrecomputedWarpPreconditioner< defaulttype::Vec3Types > >() - ; +void registerPrecomputedWarpPreconditioner(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Linear system solver based on a precomputed inverse matrix, wrapped by a per-node rotation matrix.") + .add< PrecomputedWarpPreconditioner< defaulttype::Vec3Types > >()); +} template class SOFA_COMPONENT_LINEARSOLVER_PRECONDITIONER_API PrecomputedWarpPreconditioner< defaulttype::Vec3Types >; diff --git a/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/RotationMatrixSystem.cpp b/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/RotationMatrixSystem.cpp index 6b5f16142cd..ffa1961911f 100644 --- a/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/RotationMatrixSystem.cpp +++ b/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/RotationMatrixSystem.cpp @@ -1,14 +1,40 @@ -#include +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture * +* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#include #include #include #include namespace sofa::component::linearsolver::preconditioner { - using sofa::linearalgebra::RotationMatrix; - using sofa::linearalgebra::FullVector; - template class SOFA_COMPONENT_LINEARSOLVER_PRECONDITIONER_API RotationMatrixSystem< RotationMatrix, FullVector >; +using sofa::linearalgebra::RotationMatrix; +using sofa::linearalgebra::FullVector; + +template class SOFA_COMPONENT_LINEARSOLVER_PRECONDITIONER_API RotationMatrixSystem< RotationMatrix, FullVector >; + +void registerRotationMatrixSystem(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Rotation matrix warpping the main linear system.") + .add, FullVector > >()); +} - int RotationMatrixSystemClass = core::RegisterObject("Rotation matrix warpping the main linear system") - .add, FullVector > >(true); } diff --git a/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/SSORPreconditioner.cpp b/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/SSORPreconditioner.cpp index 426ce65735e..a4e249d56f0 100644 --- a/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/SSORPreconditioner.cpp +++ b/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/SSORPreconditioner.cpp @@ -170,12 +170,12 @@ void SSORPreconditioner< linearalgebra::CompressedRowSparseMatrix< type::Mat<3,3 } } -int SSORPreconditionerClass = core::RegisterObject("Linear system solver / preconditioner based on Symmetric Successive Over-Relaxation (SSOR). If the matrix is decomposed as $A = D + L + L^T$, this solver computes $(1/(2-w))(D/w+L)(D/w)^{-1}(D/w+L)^T x = b, or $(D+L)D^{-1}(D+L)^T x = b$ if $w=1$.") +void registerSSORPreconditioner(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Linear system solver / preconditioner based on Symmetric Successive Over-Relaxation (SSOR). If the matrix is decomposed as $A = D + L + L^T$, this solver computes $(1/(2-w))(D/w+L)(D/w)^{-1}(D/w+L)^T x = b, or $(D+L)D^{-1}(D+L)^T x = b$ if $w=1$.") .add< SSORPreconditioner< CompressedRowSparseMatrix, FullVector > >(true) - .add< SSORPreconditioner< CompressedRowSparseMatrix< type::Mat<3,3,SReal> >, FullVector > >() - .addAlias("SSORLinearSolver") - .addAlias("SSORSolver") - ; + .add< SSORPreconditioner< CompressedRowSparseMatrix< type::Mat<3, 3, SReal> >, FullVector > >()); +} template class SOFA_COMPONENT_LINEARSOLVER_PRECONDITIONER_API SSORPreconditioner< linearalgebra::CompressedRowSparseMatrix, linearalgebra::FullVector >; template class SOFA_COMPONENT_LINEARSOLVER_PRECONDITIONER_API SSORPreconditioner< linearalgebra::CompressedRowSparseMatrix< type::Mat<3, 3, SReal> >, linearalgebra::FullVector >; diff --git a/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/WarpPreconditioner.cpp b/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/WarpPreconditioner.cpp index 84419ada4d6..ae1ccc31644 100644 --- a/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/WarpPreconditioner.cpp +++ b/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/WarpPreconditioner.cpp @@ -31,10 +31,12 @@ namespace sofa::component::linearsolver::preconditioner using namespace sofa::linearalgebra; -int WarpPreconditionerClass = core::RegisterObject("Linear system solver wrapping another (precomputed) linear solver by a per-node rotation matrix") - .add< WarpPreconditioner< RotationMatrix, FullVector, NoThreadManager > >() -; -template class SOFA_COMPONENT_LINEARSOLVER_PRECONDITIONER_API WarpPreconditioner< RotationMatrix, FullVector, NoThreadManager >; +void registerWarpPreconditioner(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Linear system solver wrapping another (precomputed) linear solver by a per-node rotation matrix.") + .add< WarpPreconditioner< RotationMatrix, FullVector, NoThreadManager > >()); +} +template class SOFA_COMPONENT_LINEARSOLVER_PRECONDITIONER_API WarpPreconditioner< RotationMatrix, FullVector, NoThreadManager >; } // namespace sofa::component::linearsolver::preconditioner diff --git a/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/init.cpp b/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/init.cpp index b135b8700dc..38a7944ee1d 100644 --- a/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/init.cpp +++ b/Sofa/Component/LinearSolver/Preconditioner/src/sofa/component/linearsolver/preconditioner/init.cpp @@ -21,13 +21,24 @@ ******************************************************************************/ #include #include +#include + namespace sofa::component::linearsolver::preconditioner { - + +extern void registerBlockJacobiPreconditioner(sofa::core::ObjectFactory* factory); +extern void registerJacobiPreconditioner(sofa::core::ObjectFactory* factory); +extern void registerPrecomputedMatrixSystem(sofa::core::ObjectFactory* factory); +extern void registerPrecomputedWarpPreconditioner(sofa::core::ObjectFactory* factory); +extern void registerRotationMatrixSystem(sofa::core::ObjectFactory* factory); +extern void registerSSORPreconditioner(sofa::core::ObjectFactory* factory); +extern void registerWarpPreconditioner(sofa::core::ObjectFactory* factory); + extern "C" { SOFA_EXPORT_DYNAMIC_LIBRARY void initExternalModule(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleName(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleVersion(); + SOFA_EXPORT_DYNAMIC_LIBRARY void registerObjects(sofa::core::ObjectFactory* factory); } void initExternalModule() @@ -45,11 +56,25 @@ const char* getModuleVersion() return MODULE_VERSION; } +void registerObjects(sofa::core::ObjectFactory* factory) +{ + registerBlockJacobiPreconditioner(factory); + registerJacobiPreconditioner(factory); + registerPrecomputedMatrixSystem(factory); + registerPrecomputedWarpPreconditioner(factory); + registerRotationMatrixSystem(factory); + registerSSORPreconditioner(factory); + registerWarpPreconditioner(factory); +} + void init() { static bool first = true; if (first) { + // make sure that this plugin is registered into the PluginManager + sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME); + first = false; } } diff --git a/Sofa/Component/LinearSolver/src/sofa/component/linearsolver/init.cpp b/Sofa/Component/LinearSolver/src/sofa/component/linearsolver/init.cpp index e6d0a6bdbbd..3e4a9c37cee 100644 --- a/Sofa/Component/LinearSolver/src/sofa/component/linearsolver/init.cpp +++ b/Sofa/Component/LinearSolver/src/sofa/component/linearsolver/init.cpp @@ -26,6 +26,9 @@ #include #include +#include +#include + namespace sofa::component::linearsolver { @@ -33,6 +36,7 @@ extern "C" { SOFA_EXPORT_DYNAMIC_LIBRARY void initExternalModule(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleName(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleVersion(); + SOFA_EXPORT_DYNAMIC_LIBRARY void registerObjects(sofa::core::ObjectFactory* factory); } void initExternalModule() @@ -50,6 +54,14 @@ const char* getModuleVersion() return MODULE_VERSION; } +void registerObjects(sofa::core::ObjectFactory* factory) +{ + factory->registerObjectsFromPlugin("Sofa.Component.LinearSolver.Direct"); + factory->registerObjectsFromPlugin("Sofa.Component.LinearSolver.Iterative"); + factory->registerObjectsFromPlugin("Sofa.Component.LinearSolver.Ordering"); + factory->registerObjectsFromPlugin("Sofa.Component.LinearSolver.Preconditioner"); +} + void init() { static bool first = true; @@ -61,6 +73,9 @@ void init() sofa::component::linearsolver::iterative::init(); sofa::component::linearsolver::preconditioner::init(); + // make sure that this plugin is registered into the PluginManager + sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME); + first = false; } } diff --git a/Sofa/Component/MechanicalLoad/tests/ConstantForceField_test.cpp b/Sofa/Component/MechanicalLoad/tests/ConstantForceField_test.cpp index c182c7d8e38..701de7d6e0b 100644 --- a/Sofa/Component/MechanicalLoad/tests/ConstantForceField_test.cpp +++ b/Sofa/Component/MechanicalLoad/tests/ConstantForceField_test.cpp @@ -77,6 +77,7 @@ struct ConstantForceField_test : public BaseSimulationTest, NumericTestregisterObjectsFromPlugin("Sofa.Component.Haptics"); factory->registerObjectsFromPlugin("Sofa.Component.Diffusion"); factory->registerObjectsFromPlugin("Sofa.Component.ODESolver"); + factory->registerObjectsFromPlugin("Sofa.Component.LinearSolver"); factory->registerObjectsFromPlugin("Sofa.Component.Engine"); } diff --git a/Sofa/framework/Helper/src/sofa/helper/ComponentChange.cpp b/Sofa/framework/Helper/src/sofa/helper/ComponentChange.cpp index d659ec8bb71..67f2e841145 100644 --- a/Sofa/framework/Helper/src/sofa/helper/ComponentChange.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/ComponentChange.cpp @@ -784,6 +784,17 @@ const std::map< std::string, Dealiased, std::less<> > dealiasedComponents = { {"ImplicitEulerSolver", Dealiased("v24.12","EulerImplicitSolver")}, {"ImplicitEuler", Dealiased("v24.12","EulerImplicitSolver")}, {"VariationalSolver", Dealiased("v24.12","VariationalSymplecticSolver")}, + {"SVDLinear", Dealiased("v24.12","SVDLinearSolver")}, + {"SVD", Dealiased("v24.12","SVDLinearSolver")}, + {"CGSolver", Dealiased("v24.12","CGLinearSolver")}, + {"ConjugateGradient", Dealiased("v24.12","CGLinearSolver")}, + {"MINRESSolver", Dealiased("v24.12","MinResLinearSolver")}, + {"MinResSolver", Dealiased("v24.12","MinResLinearSolver")}, + {"PCGLinearSolver", Dealiased("v24.12","ShewchukPCGLinearSolver")}, + {"JacobiLinearSolver", Dealiased("v24.12","JacobiPreconditioner")}, + {"JacobiSolver", Dealiased("v24.12","JacobiPreconditioner")}, + {"SSORLinearSolver", Dealiased("v24.12","SSORPreconditioner")}, + {"SSORSolver", Dealiased("v24.12","SSORPreconditioner")}, {"RigidEngine", Dealiased("v24.12","RigidToQuatEngine")}, }; diff --git a/applications/plugins/MultiThreading/test/ParallelImplementationsRegistry_test.cpp b/applications/plugins/MultiThreading/test/ParallelImplementationsRegistry_test.cpp index 83d38f23066..6b8d46adccc 100644 --- a/applications/plugins/MultiThreading/test/ParallelImplementationsRegistry_test.cpp +++ b/applications/plugins/MultiThreading/test/ParallelImplementationsRegistry_test.cpp @@ -24,11 +24,15 @@ #include #include +#include + namespace multithreading { TEST(ParallelImplementationsRegistry, existInObjectFactory) { + sofa::simpleapi::importPlugin("Sofa.Component.LinearSolver.Iterative"); // sequential version will be added to the ObjectFactory + const auto implementations = ParallelImplementationsRegistry::getImplementations(); for (const auto& [seq, par] : implementations) From 38ecbea18534611df204acbbd055b1a3b13a6208 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Fri, 4 Oct 2024 22:54:57 +0900 Subject: [PATCH 13/43] [Topology] Apply new factory registration mechanism (#5012) * apply new register mechanism to topology * remove aliases in scene * change test with VisualModel * remove aliases from unittest * Apply suggestions from code review (updates on component description) Co-authored-by: Hugo --------- Co-authored-by: Hugo --- .../Engine/Select/tests/MeshROI_test.cpp | 6 +- .../Mass/tests/DiagonalMass_test.cpp | 8 +-- .../container/constant/CubeTopology.cpp | 8 ++- .../container/constant/MeshTopology.cpp | 10 ++-- .../container/constant/SphereQuadTopology.cpp | 9 +-- .../topology/container/constant/init.cpp | 19 ++++++- .../DynamicSparseGridGeometryAlgorithms.cpp | 11 ++-- .../DynamicSparseGridTopologyContainer.cpp | 11 ++-- .../DynamicSparseGridTopologyModifier.cpp | 8 ++- .../dynamic/EdgeSetGeometryAlgorithms.cpp | 12 ++-- .../dynamic/EdgeSetTopologyContainer.cpp | 10 ++-- .../dynamic/EdgeSetTopologyModifier.cpp | 11 ++-- .../HexahedronSetGeometryAlgorithms.cpp | 12 ++-- .../HexahedronSetTopologyContainer.cpp | 10 ++-- .../dynamic/HexahedronSetTopologyModifier.cpp | 10 ++-- ...ltilevelHexahedronSetTopologyContainer.cpp | 10 ++-- .../dynamic/PointSetGeometryAlgorithms.cpp | 11 ++-- .../dynamic/PointSetTopologyContainer.cpp | 10 ++-- .../dynamic/PointSetTopologyModifier.cpp | 11 ++-- .../dynamic/QuadSetGeometryAlgorithms.cpp | 12 ++-- .../dynamic/QuadSetTopologyContainer.cpp | 11 ++-- .../dynamic/QuadSetTopologyModifier.cpp | 10 ++-- .../TetrahedronSetGeometryAlgorithms.cpp | 12 ++-- .../TetrahedronSetTopologyContainer.cpp | 10 ++-- .../TetrahedronSetTopologyModifier.cpp | 10 ++-- .../dynamic/TriangleSetGeometryAlgorithms.cpp | 14 ++--- .../dynamic/TriangleSetTopologyContainer.cpp | 11 ++-- .../dynamic/TriangleSetTopologyModifier.cpp | 11 ++-- .../topology/container/dynamic/init.cpp | 57 ++++++++++++++++++- .../container/grid/CylinderGridTopology.cpp | 11 ++-- .../topology/container/grid/GridTopology.cpp | 10 ++-- .../container/grid/RegularGridTopology.cpp | 11 ++-- .../grid/SparseGridMultipleTopology.cpp | 25 ++++---- .../grid/SparseGridRamificationTopology.cpp | 9 +-- .../container/grid/SparseGridTopology.cpp | 10 ++-- .../container/grid/SphereGridTopology.cpp | 11 ++-- .../topology/container/grid/init.cpp | 27 ++++++++- .../component/topology/container/init.cpp | 14 +++++ .../mapping/CenterPointTopologicalMapping.cpp | 11 ++-- .../mapping/Edge2QuadTopologicalMapping.cpp | 10 ++-- .../mapping/Hexa2QuadTopologicalMapping.cpp | 14 ++--- .../mapping/Hexa2TetraTopologicalMapping.cpp | 14 ++--- .../mapping/IdentityTopologicalMapping.cpp | 12 ++-- .../Quad2TriangleTopologicalMapping.cpp | 12 ++-- .../mapping/SubsetTopologicalMapping.cpp | 12 ++-- .../Tetra2TriangleTopologicalMapping.cpp | 14 ++--- .../Triangle2EdgeTopologicalMapping.cpp | 10 ++-- .../sofa/component/topology/mapping/init.cpp | 31 +++++++++- .../utility/TopologicalChangeProcessor.cpp | 10 ++-- .../utility/TopologyBoundingTrasher.cpp | 8 ++- .../topology/utility/TopologyChecker.cpp | 10 ++-- .../sofa/component/topology/utility/init.cpp | 19 ++++++- .../src/sofa/component/topology/init.cpp | 14 +++++ Sofa/Component/src/sofa/component/init.cpp | 1 + .../src/sofa/helper/ComponentChange.cpp | 11 +++- .../SceneChecking/tests/SceneChecker_test.cpp | 6 +- .../FixedLagrangianConstaint_Vec3.scn | 2 +- 57 files changed, 445 insertions(+), 259 deletions(-) diff --git a/Sofa/Component/Engine/Select/tests/MeshROI_test.cpp b/Sofa/Component/Engine/Select/tests/MeshROI_test.cpp index 2f5dd0ad8ef..aa3e96d8ab6 100644 --- a/Sofa/Component/Engine/Select/tests/MeshROI_test.cpp +++ b/Sofa/Component/Engine/Select/tests/MeshROI_test.cpp @@ -73,7 +73,7 @@ struct MeshROI_test : public BaseSimulationTest, " " " " " " - " " + " " " " " " " " ; @@ -136,7 +136,7 @@ struct MeshROI_test : public BaseSimulationTest, " " " " " " - " " + " " " " " " " " ; @@ -157,7 +157,7 @@ struct MeshROI_test : public BaseSimulationTest, - + diff --git a/Sofa/Component/Mass/tests/DiagonalMass_test.cpp b/Sofa/Component/Mass/tests/DiagonalMass_test.cpp index 882614ea793..1c4d0c378db 100644 --- a/Sofa/Component/Mass/tests/DiagonalMass_test.cpp +++ b/Sofa/Component/Mass/tests/DiagonalMass_test.cpp @@ -155,7 +155,7 @@ class DiagonalMass_test : public BaseTest "" " " " " - " " + " " " " " " " " ; @@ -188,7 +188,7 @@ class DiagonalMass_test : public BaseTest " " " " " " - " " + " " " " " " " " ; @@ -219,7 +219,7 @@ class DiagonalMass_test : public BaseTest " " " " " " - " " + " " " " " " " " ; @@ -249,7 +249,7 @@ class DiagonalMass_test : public BaseTest " " " " " " - " " + " " " " " " " " ; diff --git a/Sofa/Component/Topology/Container/Constant/src/sofa/component/topology/container/constant/CubeTopology.cpp b/Sofa/Component/Topology/Container/Constant/src/sofa/component/topology/container/constant/CubeTopology.cpp index e666b76e0b1..d2eaa4d0ec2 100644 --- a/Sofa/Component/Topology/Container/Constant/src/sofa/component/topology/container/constant/CubeTopology.cpp +++ b/Sofa/Component/Topology/Container/Constant/src/sofa/component/topology/container/constant/CubeTopology.cpp @@ -57,9 +57,11 @@ void CubeTopology::parse(core::objectmodel::BaseObjectDescription* arg) this->setPos(d_min.getValue()[0], d_max.getValue()[0], d_min.getValue()[1], d_max.getValue()[1], d_min.getValue()[2], d_max.getValue()[2]); } -int CubeTopologyClass = core::RegisterObject("Surface of a cube in 3D") - .add< CubeTopology >() - ; +void registerCubeTopology(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Surface topology of a cube in 3D (points, edges and quads).") + .add< CubeTopology >()); +} CubeTopology::CubeTopology(int _nx, int _ny, int _nz) : d_nx(initData(&d_nx, _nx, "nx", "x grid resolution")) diff --git a/Sofa/Component/Topology/Container/Constant/src/sofa/component/topology/container/constant/MeshTopology.cpp b/Sofa/Component/Topology/Container/Constant/src/sofa/component/topology/container/constant/MeshTopology.cpp index 47f8a909fbf..f8384eca4a1 100644 --- a/Sofa/Component/Topology/Container/Constant/src/sofa/component/topology/container/constant/MeshTopology.cpp +++ b/Sofa/Component/Topology/Container/Constant/src/sofa/component/topology/container/constant/MeshTopology.cpp @@ -478,11 +478,11 @@ void MeshTopology::QuadUpdate::doUpdate() using namespace sofa::defaulttype; using core::topology::BaseMeshTopology; - -int MeshTopologyClass = core::RegisterObject("Generic mesh topology") - .addAlias("Mesh") - .add< MeshTopology >() - ; +void registerMeshTopology(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Generic constant topology loaded from a mesh file.") + .add< MeshTopology >()); +} MeshTopology::MeshTopology() : d_seqPoints(initData(&d_seqPoints, "position", "List of point positions")) diff --git a/Sofa/Component/Topology/Container/Constant/src/sofa/component/topology/container/constant/SphereQuadTopology.cpp b/Sofa/Component/Topology/Container/Constant/src/sofa/component/topology/container/constant/SphereQuadTopology.cpp index d99065cf2b9..73e7bfaf9de 100644 --- a/Sofa/Component/Topology/Container/Constant/src/sofa/component/topology/container/constant/SphereQuadTopology.cpp +++ b/Sofa/Component/Topology/Container/Constant/src/sofa/component/topology/container/constant/SphereQuadTopology.cpp @@ -29,10 +29,11 @@ namespace sofa::component::topology::container::constant using namespace sofa::type; using namespace sofa::defaulttype; -int SphereQuadTopologyClass = core::RegisterObject("Sphere topology constructed with deformed quads") - .addAlias("SphereQuad") - .add< SphereQuadTopology >() - ; +void registerSphereQuadTopology(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Sphere topology constructed with deformed quads.") + .add< SphereQuadTopology >()); +} SphereQuadTopology::SphereQuadTopology(int nx, int ny, int nz) : CubeTopology(nx, ny, nz), diff --git a/Sofa/Component/Topology/Container/Constant/src/sofa/component/topology/container/constant/init.cpp b/Sofa/Component/Topology/Container/Constant/src/sofa/component/topology/container/constant/init.cpp index 8e3c0970fbc..52c2b119c28 100644 --- a/Sofa/Component/Topology/Container/Constant/src/sofa/component/topology/container/constant/init.cpp +++ b/Sofa/Component/Topology/Container/Constant/src/sofa/component/topology/container/constant/init.cpp @@ -21,13 +21,20 @@ ******************************************************************************/ #include #include +#include + namespace sofa::component::topology::container::constant { - + +extern void registerCubeTopology(sofa::core::ObjectFactory* factory); +extern void registerMeshTopology(sofa::core::ObjectFactory* factory); +extern void registerSphereQuadTopology(sofa::core::ObjectFactory* factory); + extern "C" { SOFA_EXPORT_DYNAMIC_LIBRARY void initExternalModule(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleName(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleVersion(); + SOFA_EXPORT_DYNAMIC_LIBRARY void registerObjects(sofa::core::ObjectFactory* factory); } void initExternalModule() @@ -45,11 +52,21 @@ const char* getModuleVersion() return MODULE_VERSION; } +void registerObjects(sofa::core::ObjectFactory* factory) +{ + registerCubeTopology(factory); + registerMeshTopology(factory); + registerSphereQuadTopology(factory); +} + void init() { static bool first = true; if (first) { + // make sure that this plugin is registered into the PluginManager + sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME); + first = false; } } diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/DynamicSparseGridGeometryAlgorithms.cpp b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/DynamicSparseGridGeometryAlgorithms.cpp index 372842adb2f..a134550bdeb 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/DynamicSparseGridGeometryAlgorithms.cpp +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/DynamicSparseGridGeometryAlgorithms.cpp @@ -28,11 +28,13 @@ namespace sofa::component::topology::container::dynamic { using namespace sofa::defaulttype; -int DynamicSparseGridGeometryAlgorithmsClass = core::RegisterObject ( "Hexahedron set geometry algorithms" ) - .add< DynamicSparseGridGeometryAlgorithms > ( true ) // default template - .add< DynamicSparseGridGeometryAlgorithms >() - ; +void registerDynamicSparseGridGeometryAlgorithms(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Dynamic sparse grid geometry algorithms.") + .add< DynamicSparseGridGeometryAlgorithms >(true) // default template + .add< DynamicSparseGridGeometryAlgorithms >()); +} template <> int DynamicSparseGridGeometryAlgorithms::findNearestElementInRestPos(const Coord& pos, sofa::type::Vec3& baryC, Real& distance) const @@ -43,5 +45,4 @@ int DynamicSparseGridGeometryAlgorithms::findNearestElementInRestPos( template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API DynamicSparseGridGeometryAlgorithms; template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API DynamicSparseGridGeometryAlgorithms; - } // namespace sofa::component::topology::container::dynamic diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/DynamicSparseGridTopologyContainer.cpp b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/DynamicSparseGridTopologyContainer.cpp index 6858eaab746..8f7c5684a5f 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/DynamicSparseGridTopologyContainer.cpp +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/DynamicSparseGridTopologyContainer.cpp @@ -30,13 +30,14 @@ namespace sofa::component::topology::container::dynamic { -using namespace std; using namespace sofa::type; using namespace sofa::defaulttype; -int DynamicSparseGridTopologyContainerClass = core::RegisterObject ( "Hexahedron set topology container" ) - .add< DynamicSparseGridTopologyContainer >() - ; +void registerDynamicSparseGridTopologyContainer(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Dynamic sparse grid geometry container.") + .add< DynamicSparseGridTopologyContainer >()); +} DynamicSparseGridTopologyContainer::DynamicSparseGridTopologyContainer() : d_resolution (initData (&d_resolution, type::Vec3i (0, 0, 0 ), "resolution", "voxel grid resolution" ) ) @@ -78,7 +79,7 @@ void DynamicSparseGridTopologyContainer::init() for( unsigned int i = 0; i < iirg.size(); i++) { - idrg2tpo.insert( make_pair( iirg[i], i )); + idrg2tpo.insert( std::make_pair( iirg[i], i )); } // Init values diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/DynamicSparseGridTopologyModifier.cpp b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/DynamicSparseGridTopologyModifier.cpp index 2a7687a7d95..3f88626577c 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/DynamicSparseGridTopologyModifier.cpp +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/DynamicSparseGridTopologyModifier.cpp @@ -30,9 +30,11 @@ namespace sofa::component::topology::container::dynamic { -int DynamicSparseGridTopologyModifierClass = core::RegisterObject ( "Hexahedron set topology modifier" ) - .add< DynamicSparseGridTopologyModifier >(); - +void registerDynamicSparseGridTopologyModifier(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Dynamic sparse grid geometry modifier.") + .add< DynamicSparseGridTopologyModifier >()); +} void DynamicSparseGridTopologyModifier::init() { diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/EdgeSetGeometryAlgorithms.cpp b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/EdgeSetGeometryAlgorithms.cpp index f315be2f8d8..98ddf0cc07d 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/EdgeSetGeometryAlgorithms.cpp +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/EdgeSetGeometryAlgorithms.cpp @@ -28,15 +28,18 @@ namespace sofa::component::topology::container::dynamic { + using namespace sofa::defaulttype; -int EdgeSetGeometryAlgorithmsClass = core::RegisterObject("Edge set geometry algorithms") + +void registerEdgeSetGeometryAlgorithms(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Geometry algorithms dedicated to an edge topology.") .add< EdgeSetGeometryAlgorithms >(true) // default template .add< EdgeSetGeometryAlgorithms >() .add< EdgeSetGeometryAlgorithms >() .add< EdgeSetGeometryAlgorithms >() - .add< EdgeSetGeometryAlgorithms >() - - ; + .add< EdgeSetGeometryAlgorithms >()); +} template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API EdgeSetGeometryAlgorithms; template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API EdgeSetGeometryAlgorithms; @@ -44,5 +47,4 @@ template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API EdgeSetGeometryAlgo template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API EdgeSetGeometryAlgorithms; template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API EdgeSetGeometryAlgorithms; - } //namespace sofa::component::topology::container::dynamic diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/EdgeSetTopologyContainer.cpp b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/EdgeSetTopologyContainer.cpp index b2c62930c8f..6d3de29e77f 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/EdgeSetTopologyContainer.cpp +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/EdgeSetTopologyContainer.cpp @@ -36,11 +36,13 @@ namespace sofa::component::topology::container::dynamic { -using namespace std; using namespace sofa::defaulttype; -int EdgeSetTopologyContainerClass = core::RegisterObject("Edge set topology container") - .add< EdgeSetTopologyContainer >() - ; + +void registerEdgeSetTopologyContainer(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Topology container for an edge topology.") + .add< EdgeSetTopologyContainer >()); +} EdgeSetTopologyContainer::EdgeSetTopologyContainer() : PointSetTopologyContainer( ) diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/EdgeSetTopologyModifier.cpp b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/EdgeSetTopologyModifier.cpp index cf7b145525b..0edd32a39a0 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/EdgeSetTopologyModifier.cpp +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/EdgeSetTopologyModifier.cpp @@ -40,12 +40,13 @@ namespace sofa::component::topology::container::dynamic { -using namespace sofa::defaulttype; -int EdgeSetTopologyModifierClass = core::RegisterObject("Edge set topology modifier") - .add< EdgeSetTopologyModifier >(); -using namespace std; -using namespace sofa::defaulttype; +void registerEdgeSetTopologyModifier(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Topology modifier dedicated to an edge topology.") + .add< EdgeSetTopologyModifier >()); +} + using namespace sofa::core::topology; void EdgeSetTopologyModifier::init() diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/HexahedronSetGeometryAlgorithms.cpp b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/HexahedronSetGeometryAlgorithms.cpp index 2a5341d54c2..db5d1b4e6eb 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/HexahedronSetGeometryAlgorithms.cpp +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/HexahedronSetGeometryAlgorithms.cpp @@ -27,15 +27,17 @@ namespace sofa::component::topology::container::dynamic { + using namespace sofa::defaulttype; -int HexahedronSetGeometryAlgorithmsClass = core::RegisterObject("Hexahedron set geometry algorithms") - .add< HexahedronSetGeometryAlgorithms >(true) // default template - .add< HexahedronSetGeometryAlgorithms >() - ; +void registerHexahedronSetGeometryAlgorithms(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Geometry algorithms dedicated to an hexahedral topology.") + .add< HexahedronSetGeometryAlgorithms >(true) // default template + .add< HexahedronSetGeometryAlgorithms >()); +} template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API HexahedronSetGeometryAlgorithms; template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API HexahedronSetGeometryAlgorithms; - } //namespace sofa::component::topology::container::dynamic diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/HexahedronSetTopologyContainer.cpp b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/HexahedronSetTopologyContainer.cpp index cf6cfe185ca..f9fa154edba 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/HexahedronSetTopologyContainer.cpp +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/HexahedronSetTopologyContainer.cpp @@ -28,15 +28,15 @@ namespace sofa::component::topology::container::dynamic { -using namespace std; -using namespace sofa::defaulttype; using sofa::core::topology::edgesInHexahedronArray; using sofa::core::topology::quadsOrientationInHexahedronArray; using sofa::core::topology::verticesInHexahedronArray; -int HexahedronSetTopologyContainerClass = core::RegisterObject("Hexahedron set topology container") - .add< HexahedronSetTopologyContainer >() - ; +void registerHexahedronSetTopologyContainer(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Topology container dedicated to an hexahedral topology.") + .add< HexahedronSetTopologyContainer >()); +} HexahedronSetTopologyContainer::HexahedronSetTopologyContainer() : QuadSetTopologyContainer() diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/HexahedronSetTopologyModifier.cpp b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/HexahedronSetTopologyModifier.cpp index 82a295788d7..93f8c310868 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/HexahedronSetTopologyModifier.cpp +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/HexahedronSetTopologyModifier.cpp @@ -30,11 +30,13 @@ namespace sofa::component::topology::container::dynamic { -int HexahedronSetTopologyModifierClass = core::RegisterObject("Hexahedron set topology modifier") - .add< HexahedronSetTopologyModifier >(); -using namespace std; -using namespace sofa::defaulttype; +void registerHexahedronSetTopologyModifier(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Topology modifier dedicated to an hexahedral topology.") + .add< HexahedronSetTopologyModifier >()); +} + using namespace sofa::core::topology; void HexahedronSetTopologyModifier::init() diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/MultilevelHexahedronSetTopologyContainer.cpp b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/MultilevelHexahedronSetTopologyContainer.cpp index 8d57a6b00e9..050ef68e952 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/MultilevelHexahedronSetTopologyContainer.cpp +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/MultilevelHexahedronSetTopologyContainer.cpp @@ -33,13 +33,13 @@ namespace sofa::component::topology::container::dynamic { -using namespace std; using namespace sofa::type; -using namespace sofa::defaulttype; -int MultilevelHexahedronSetTopologyContainerClass = core::RegisterObject("Hexahedron set topology container") - .add< MultilevelHexahedronSetTopologyContainer >() - ; +void registerMultilevelHexahedronSetTopologyContainer(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Multilevel Hexahedron set topology container.") + .add< MultilevelHexahedronSetTopologyContainer >()); +} MultilevelHexahedronSetTopologyContainer::MultilevelHexahedronSetTopologyContainer() : HexahedronSetTopologyContainer(), diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/PointSetGeometryAlgorithms.cpp b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/PointSetGeometryAlgorithms.cpp index 8022a9d2364..2f7f39b68a7 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/PointSetGeometryAlgorithms.cpp +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/PointSetGeometryAlgorithms.cpp @@ -29,12 +29,14 @@ namespace sofa::component::topology::container::dynamic { using namespace sofa::defaulttype; -int PointSetGeometryAlgorithmsClass = core::RegisterObject("Point set geometry algorithms") + +void registerPointSetGeometryAlgorithms(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Geometry algorithms dedicated to a point topology.") .add< PointSetGeometryAlgorithms >(true) // default template .add< PointSetGeometryAlgorithms >() - .add< PointSetGeometryAlgorithms >() - - ; + .add< PointSetGeometryAlgorithms >()); +} template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API PointSetGeometryAlgorithms; template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API PointSetGeometryAlgorithms; @@ -42,5 +44,4 @@ template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API PointSetGeometryAlg template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API PointSetGeometryAlgorithms; template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API PointSetGeometryAlgorithms; - } //namespace sofa::component::topology::container::dynamic diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/PointSetTopologyContainer.cpp b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/PointSetTopologyContainer.cpp index b644cdf4511..ef8b6d401e1 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/PointSetTopologyContainer.cpp +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/PointSetTopologyContainer.cpp @@ -49,11 +49,11 @@ struct GeneratePointID } -using namespace sofa::defaulttype; - -int PointSetTopologyContainerClass = core::RegisterObject("Point set topology container") - .add< PointSetTopologyContainer >() - ; +void registerPointSetTopologyContainer(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Topology container dedicated to a point topology.") + .add< PointSetTopologyContainer >()); +} PointSetTopologyContainer::PointSetTopologyContainer(Size npoints) : d_initPoints (initData(&d_initPoints, "position", "Initial position of points",true,true)) diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/PointSetTopologyModifier.cpp b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/PointSetTopologyModifier.cpp index 6573eb11f4b..cc35bf05f07 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/PointSetTopologyModifier.cpp +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/PointSetTopologyModifier.cpp @@ -33,12 +33,13 @@ namespace sofa::component::topology::container::dynamic { -int PointSetTopologyModifierClass = core::RegisterObject("Point set topology modifier") - .add< PointSetTopologyModifier >(); -using namespace std; -using namespace sofa::defaulttype; -using namespace sofa::core::behavior; +void registerPointSetTopologyModifier(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Topology modifier dedicated to a point topology.") + .add< PointSetTopologyModifier >()); +} + using namespace sofa::core::topology; void PointSetTopologyModifier::init() diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/QuadSetGeometryAlgorithms.cpp b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/QuadSetGeometryAlgorithms.cpp index 9711e21b402..cf6a9461cbf 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/QuadSetGeometryAlgorithms.cpp +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/QuadSetGeometryAlgorithms.cpp @@ -28,15 +28,17 @@ namespace sofa::component::topology::container::dynamic { + using namespace sofa::defaulttype; -int QuadSetGeometryAlgorithmsClass = core::RegisterObject("Quad set geometry algorithms") - .add< QuadSetGeometryAlgorithms >(true) // default template - .add< QuadSetGeometryAlgorithms >() - ; +void registerQuadSetGeometryAlgorithms(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Geometry algorithms dedicated to a quad topology.") + .add< QuadSetGeometryAlgorithms >(true) // default template + .add< QuadSetGeometryAlgorithms >()); +} template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API QuadSetGeometryAlgorithms; template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API QuadSetGeometryAlgorithms; - } //namespace sofa::component::topology::container::dynamic diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/QuadSetTopologyContainer.cpp b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/QuadSetTopologyContainer.cpp index ba4b361d837..05d4641150b 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/QuadSetTopologyContainer.cpp +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/QuadSetTopologyContainer.cpp @@ -28,12 +28,11 @@ namespace sofa::component::topology::container::dynamic { -using namespace std; -using namespace sofa::defaulttype; - -int QuadSetTopologyContainerClass = core::RegisterObject("Quad set topology container") - .add< QuadSetTopologyContainer >() - ; +void registerQuadSetTopologyContainer(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Topology container dedicated to a quad topology.") + .add< QuadSetTopologyContainer >()); +} QuadSetTopologyContainer::QuadSetTopologyContainer() : EdgeSetTopologyContainer() diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/QuadSetTopologyModifier.cpp b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/QuadSetTopologyModifier.cpp index fc6efdd5d74..bee7780caa3 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/QuadSetTopologyModifier.cpp +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/QuadSetTopologyModifier.cpp @@ -30,15 +30,15 @@ namespace sofa::component::topology::container::dynamic { -int QuadSetTopologyModifierClass = core::RegisterObject("Quad set topology modifier") - .add< QuadSetTopologyModifier >(); +void registerQuadSetTopologyModifier(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Topology modifier dedicated to a quad topology.") + .add< QuadSetTopologyModifier >()); +} -using namespace std; -using namespace sofa::defaulttype; using namespace sofa::core::topology; - void QuadSetTopologyModifier::init() { EdgeSetTopologyModifier::init(); diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TetrahedronSetGeometryAlgorithms.cpp b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TetrahedronSetGeometryAlgorithms.cpp index 33b6549d15b..7bf78f2b1a5 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TetrahedronSetGeometryAlgorithms.cpp +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TetrahedronSetGeometryAlgorithms.cpp @@ -27,15 +27,17 @@ namespace sofa::component::topology::container::dynamic { + using namespace sofa::defaulttype; -int TetrahedronSetGeometryAlgorithmsClass = core::RegisterObject("Tetrahedron set geometry algorithms") - .add< TetrahedronSetGeometryAlgorithms >(true) // default template - .add< TetrahedronSetGeometryAlgorithms >() - ; +void registerTetrahedronSetGeometryAlgorithms(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Geometry algorithms dedicated to a tetrahedral topology.") + .add< TetrahedronSetGeometryAlgorithms >(true) // default template + .add< TetrahedronSetGeometryAlgorithms >()); +} template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API TetrahedronSetGeometryAlgorithms; template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API TetrahedronSetGeometryAlgorithms; - } //namespace sofa::component::topology::container::dynamic diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TetrahedronSetTopologyContainer.cpp b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TetrahedronSetTopologyContainer.cpp index c4eede995d3..5f9fedd0175 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TetrahedronSetTopologyContainer.cpp +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TetrahedronSetTopologyContainer.cpp @@ -27,13 +27,13 @@ namespace sofa::component::topology::container::dynamic { -using namespace std; -using namespace sofa::defaulttype; using sofa::core::topology::edgesInTetrahedronArray; -int TetrahedronSetTopologyContainerClass = core::RegisterObject("Tetrahedron set topology container") - .add< TetrahedronSetTopologyContainer >() - ; +void registerTetrahedronSetTopologyContainer(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Topology container dedicated to a tetrahedral topology.") + .add< TetrahedronSetTopologyContainer >()); +} ///convention triangles in tetra (orientation interior) diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TetrahedronSetTopologyModifier.cpp b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TetrahedronSetTopologyModifier.cpp index 43d7a420445..faee40cbb0f 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TetrahedronSetTopologyModifier.cpp +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TetrahedronSetTopologyModifier.cpp @@ -33,11 +33,13 @@ namespace sofa::component::topology::container::dynamic { -int TetrahedronSetTopologyModifierClass = core::RegisterObject("Tetrahedron set topology modifier") - .add< TetrahedronSetTopologyModifier >(); -using namespace std; -using namespace sofa::defaulttype; +void registerTetrahedronSetTopologyModifier(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Topology modifier dedicated to a tetrahedral topology.") + .add< TetrahedronSetTopologyModifier >()); +} + using namespace sofa::core::topology; //const unsigned int edgesInTetrahedronArray[6][2] = {{0,1}, {0,2}, {0,3}, {1,2}, {1,3}, {2,3}}; diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.cpp b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.cpp index 180a0443b4f..9953a160abc 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.cpp +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.cpp @@ -27,14 +27,15 @@ namespace sofa::component::topology::container::dynamic { + using namespace sofa::defaulttype; -int TriangleSetGeometryAlgorithmsClass = core::RegisterObject("Triangle set geometry algorithms") +void registerTriangleSetGeometryAlgorithms(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Geometry algorithms dedicated to a triangular topology.") .add< TriangleSetGeometryAlgorithms >(true) // default template - .add< TriangleSetGeometryAlgorithms >() - ; - - + .add< TriangleSetGeometryAlgorithms >()); +} // methods specilizations declaration template<> SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API @@ -50,12 +51,9 @@ int TriangleSetGeometryAlgorithms::SplitAlongPath(PointI sofa::type::vector< sofa::type::Vec3 >& coords_list, sofa::type::vector& new_edges, SReal epsilonSnapPath, SReal epsilonSnapBorder); - - template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API TriangleSetGeometryAlgorithms; template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API TriangleSetGeometryAlgorithms; - template<> int TriangleSetGeometryAlgorithms::SplitAlongPath(PointID, Coord&, PointID, Coord&, sofa::type::vector< sofa::geometry::ElementType>&, diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetTopologyContainer.cpp b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetTopologyContainer.cpp index 48ab563d783..871f7896046 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetTopologyContainer.cpp +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetTopologyContainer.cpp @@ -26,13 +26,12 @@ namespace sofa::component::topology::container::dynamic { -using namespace std; -using namespace sofa::defaulttype; - -int TriangleSetTopologyContainerClass = core::RegisterObject("Triangle set topology container") - .add< TriangleSetTopologyContainer >() - ; +void registerTriangleSetTopologyContainer(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Topology container dedicated to a triangular topology.") + .add< TriangleSetTopologyContainer >()); +} TriangleSetTopologyContainer::TriangleSetTopologyContainer() : EdgeSetTopologyContainer() diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetTopologyModifier.cpp b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetTopologyModifier.cpp index f076b2cafcd..f03f972b45c 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetTopologyModifier.cpp +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetTopologyModifier.cpp @@ -33,12 +33,13 @@ namespace sofa::component::topology::container::dynamic { -int TriangleSetTopologyModifierClass = core::RegisterObject("Triangle set topology modifier") - .add< TriangleSetTopologyModifier >() - ; -using namespace std; -using namespace sofa::defaulttype; +void registerTriangleSetTopologyModifier(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Topology modifier dedicated to a triangular topology.") + .add< TriangleSetTopologyModifier >()); +} + using namespace sofa::core::topology; void TriangleSetTopologyModifier::init() diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/init.cpp b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/init.cpp index 88ac7674543..1caad7ab75e 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/init.cpp +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/init.cpp @@ -21,13 +21,39 @@ ******************************************************************************/ #include #include +#include + namespace sofa::component::topology::container::dynamic { - + +extern void registerDynamicSparseGridGeometryAlgorithms(sofa::core::ObjectFactory* factory); +extern void registerDynamicSparseGridTopologyContainer(sofa::core::ObjectFactory* factory); +extern void registerDynamicSparseGridTopologyModifier(sofa::core::ObjectFactory* factory); +extern void registerEdgeSetGeometryAlgorithms(sofa::core::ObjectFactory* factory); +extern void registerEdgeSetTopologyContainer(sofa::core::ObjectFactory* factory); +extern void registerEdgeSetTopologyModifier(sofa::core::ObjectFactory* factory); +extern void registerHexahedronSetGeometryAlgorithms(sofa::core::ObjectFactory* factory); +extern void registerHexahedronSetTopologyContainer(sofa::core::ObjectFactory* factory); +extern void registerHexahedronSetTopologyModifier(sofa::core::ObjectFactory* factory); +extern void registerMultilevelHexahedronSetTopologyContainer(sofa::core::ObjectFactory* factory); +extern void registerPointSetGeometryAlgorithms(sofa::core::ObjectFactory* factory); +extern void registerPointSetTopologyContainer(sofa::core::ObjectFactory* factory); +extern void registerPointSetTopologyModifier(sofa::core::ObjectFactory* factory); +extern void registerQuadSetGeometryAlgorithms(sofa::core::ObjectFactory* factory); +extern void registerQuadSetTopologyContainer(sofa::core::ObjectFactory* factory); +extern void registerQuadSetTopologyModifier(sofa::core::ObjectFactory* factory); +extern void registerTetrahedronSetGeometryAlgorithms(sofa::core::ObjectFactory* factory); +extern void registerTetrahedronSetTopologyContainer(sofa::core::ObjectFactory* factory); +extern void registerTetrahedronSetTopologyModifier(sofa::core::ObjectFactory* factory); +extern void registerTriangleSetGeometryAlgorithms(sofa::core::ObjectFactory* factory); +extern void registerTriangleSetTopologyContainer(sofa::core::ObjectFactory* factory); +extern void registerTriangleSetTopologyModifier(sofa::core::ObjectFactory* factory); + extern "C" { SOFA_EXPORT_DYNAMIC_LIBRARY void initExternalModule(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleName(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleVersion(); + SOFA_EXPORT_DYNAMIC_LIBRARY void registerObjects(sofa::core::ObjectFactory* factory); } void initExternalModule() @@ -45,11 +71,40 @@ const char* getModuleVersion() return MODULE_VERSION; } +void registerObjects(sofa::core::ObjectFactory* factory) +{ + registerDynamicSparseGridGeometryAlgorithms(factory); + registerDynamicSparseGridTopologyContainer(factory); + registerDynamicSparseGridTopologyModifier(factory); + registerEdgeSetGeometryAlgorithms(factory); + registerEdgeSetTopologyContainer(factory); + registerEdgeSetTopologyModifier(factory); + registerHexahedronSetGeometryAlgorithms(factory); + registerHexahedronSetTopologyContainer(factory); + registerHexahedronSetTopologyModifier(factory); + registerMultilevelHexahedronSetTopologyContainer(factory); + registerPointSetGeometryAlgorithms(factory); + registerPointSetTopologyContainer(factory); + registerPointSetTopologyModifier(factory); + registerQuadSetGeometryAlgorithms(factory); + registerQuadSetTopologyContainer(factory); + registerQuadSetTopologyModifier(factory); + registerTetrahedronSetGeometryAlgorithms(factory); + registerTetrahedronSetTopologyContainer(factory); + registerTetrahedronSetTopologyModifier(factory); + registerTriangleSetGeometryAlgorithms(factory); + registerTriangleSetTopologyContainer(factory); + registerTriangleSetTopologyModifier(factory); +} + void init() { static bool first = true; if (first) { + // make sure that this plugin is registered into the PluginManager + sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME); + first = false; } } diff --git a/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/CylinderGridTopology.cpp b/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/CylinderGridTopology.cpp index 66d02134b14..d2fadfe0bf8 100644 --- a/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/CylinderGridTopology.cpp +++ b/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/CylinderGridTopology.cpp @@ -29,12 +29,11 @@ namespace sofa::component::topology::container::grid using namespace sofa::type; using namespace sofa::defaulttype; - - -int CylinderGridTopologyClass = core::RegisterObject("Cylinder grid in 3D") - .addAlias("CylinderGrid") - .add< CylinderGridTopology >() - ; +void registerCylinderGridTopology(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Cylinder grid in 3D.") + .add< CylinderGridTopology >()); +} CylinderGridTopology::CylinderGridTopology(int nx, int ny, int nz) : GridTopology(nx, ny, nz) diff --git a/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/GridTopology.cpp b/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/GridTopology.cpp index 166d08df145..ae70dd43d2a 100644 --- a/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/GridTopology.cpp +++ b/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/GridTopology.cpp @@ -27,11 +27,11 @@ namespace sofa::component::topology::container::grid { -int GridTopologyClass = core::RegisterObject("Base class fo a regular grid in 3D") - .addAlias("Grid") - .add< GridTopology >() - ; - +void registerGridTopology(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Base class fo a regular grid in 3D.") + .add< GridTopology >()); +} GridTopology::GridUpdate::GridUpdate(GridTopology *t): m_topology(t) diff --git a/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/RegularGridTopology.cpp b/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/RegularGridTopology.cpp index da3187e7395..1f28f85aa55 100644 --- a/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/RegularGridTopology.cpp +++ b/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/RegularGridTopology.cpp @@ -411,11 +411,10 @@ void RegularGridTopology::createTexCoords() } } - -int RegularGridTopologyClass = core::RegisterObject("Regular grid in 3D") - .addAlias("RegularGrid") - .add< RegularGridTopology >() - ; - +void registerRegularGridTopology(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Regular grid in 3D.") + .add< RegularGridTopology >()); +} } //namespace sofa::component::topology::container::grid diff --git a/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/SparseGridMultipleTopology.cpp b/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/SparseGridMultipleTopology.cpp index f13bd44174c..b485ae44b92 100644 --- a/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/SparseGridMultipleTopology.cpp +++ b/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/SparseGridMultipleTopology.cpp @@ -27,18 +27,19 @@ namespace sofa::component::topology::container::grid { -int SparseGridMultipleTopologyClass = core::RegisterObject("Sparse grid in 3D") - .addAlias("SparseGridMultiple") - .add< SparseGridMultipleTopology >() - ; - - -SparseGridMultipleTopology::SparseGridMultipleTopology( bool _isVirtual ) : SparseGridRamificationTopology(_isVirtual), - d_fileTopologies(initData(&d_fileTopologies, type::vector< std::string >() , "fileTopologies", "All topology filenames")), - d_dataStiffnessCoefs(initData(&d_dataStiffnessCoefs, type::vector< float >() , "stiffnessCoefs", "A stiffness coefficient for each topology filename")), - d_dataMassCoefs(initData(&d_dataMassCoefs, type::vector< float >() , "massCoefs", "A mass coefficient for each topology filename")), - d_computeRamifications(initData(&d_computeRamifications, true , "computeRamifications", "Are ramifications wanted?")), - d_erasePreviousCoef(initData(&d_erasePreviousCoef, false , "erasePreviousCoef", "Does a new stiffness/mass coefficient replace the previous or blend half/half with it?")) +void registerSparseGridMultipleTopology(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Sparse grid in 3D.") + .add< SparseGridMultipleTopology >()); +} + +SparseGridMultipleTopology::SparseGridMultipleTopology( bool _isVirtual ) + : SparseGridRamificationTopology(_isVirtual) + , d_fileTopologies(initData(&d_fileTopologies, type::vector< std::string >() , "fileTopologies", "All topology filenames")) + , d_dataStiffnessCoefs(initData(&d_dataStiffnessCoefs, type::vector< float >() , "stiffnessCoefs", "A stiffness coefficient for each topology filename")) + , d_dataMassCoefs(initData(&d_dataMassCoefs, type::vector< float >() , "massCoefs", "A mass coefficient for each topology filename")) + , d_computeRamifications(initData(&d_computeRamifications, true , "computeRamifications", "Are ramifications wanted?")) + , d_erasePreviousCoef(initData(&d_erasePreviousCoef, false , "erasePreviousCoef", "Does a new stiffness/mass coefficient replace the previous or blend half/half with it?")) { _fileTopologies.setOriginalData(&d_fileTopologies); _dataStiffnessCoefs.setOriginalData(&d_dataStiffnessCoefs); diff --git a/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/SparseGridRamificationTopology.cpp b/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/SparseGridRamificationTopology.cpp index 62f036d2445..ea4c192920c 100644 --- a/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/SparseGridRamificationTopology.cpp +++ b/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/SparseGridRamificationTopology.cpp @@ -27,10 +27,11 @@ namespace sofa::component::topology::container::grid { -int SparseGridRamificationTopologyClass = core::RegisterObject("Sparse grid in 3D (modified)") - .addAlias("SparseGridRamification") - .add< SparseGridRamificationTopology >() - ; +void registerSparseGridRamificationTopology(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Sparse grid in 3D (modified).") + .add< SparseGridRamificationTopology >()); +} SparseGridRamificationTopology::SparseGridRamificationTopology(bool isVirtual) : SparseGridTopology(isVirtual) diff --git a/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/SparseGridTopology.cpp b/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/SparseGridTopology.cpp index 10a1f45173d..43b5e136953 100644 --- a/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/SparseGridTopology.cpp +++ b/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/SparseGridTopology.cpp @@ -42,11 +42,11 @@ using namespace sofa::helper; namespace sofa::component::topology::container::grid { -int SparseGridTopologyClass = core::RegisterObject("Sparse grid in 3D") - .addAlias("SparseGrid") - .add< SparseGridTopology >() - ; - +void registerSparseGridTopology(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Sparse grid in 3D.") + .add< SparseGridTopology >()); +} const float SparseGridTopology::WEIGHT27[8][27] = { diff --git a/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/SphereGridTopology.cpp b/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/SphereGridTopology.cpp index 2e2e93c1653..39ea54ec88e 100644 --- a/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/SphereGridTopology.cpp +++ b/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/SphereGridTopology.cpp @@ -29,12 +29,11 @@ namespace sofa::component::topology::container::grid using namespace sofa::type; using namespace sofa::defaulttype; - - -int SphereGridTopologyClass = core::RegisterObject("Sphere grid in 3D") - .addAlias("SphereGrid") - .add< SphereGridTopology >() - ; +void registerSphereGridTopology(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Sphere grid in 3D.") + .add< SphereGridTopology >()); +} SphereGridTopology::SphereGridTopology(int nx, int ny, int nz) : GridTopology(nx, ny, nz) diff --git a/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/init.cpp b/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/init.cpp index a134bb36d20..59702ee2338 100644 --- a/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/init.cpp +++ b/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/init.cpp @@ -21,13 +21,24 @@ ******************************************************************************/ #include #include +#include + namespace sofa::component::topology::container::grid { - + +extern void registerCylinderGridTopology(sofa::core::ObjectFactory* factory); +extern void registerGridTopology(sofa::core::ObjectFactory* factory); +extern void registerRegularGridTopology(sofa::core::ObjectFactory* factory); +extern void registerSparseGridMultipleTopology(sofa::core::ObjectFactory* factory); +extern void registerSparseGridRamificationTopology(sofa::core::ObjectFactory* factory); +extern void registerSparseGridTopology(sofa::core::ObjectFactory* factory); +extern void registerSphereGridTopology(sofa::core::ObjectFactory* factory); + extern "C" { SOFA_EXPORT_DYNAMIC_LIBRARY void initExternalModule(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleName(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleVersion(); + SOFA_EXPORT_DYNAMIC_LIBRARY void registerObjects(sofa::core::ObjectFactory* factory); } void initExternalModule() @@ -45,11 +56,25 @@ const char* getModuleVersion() return MODULE_VERSION; } +void registerObjects(sofa::core::ObjectFactory* factory) +{ + registerCylinderGridTopology(factory); + registerGridTopology(factory); + registerRegularGridTopology(factory); + registerSparseGridMultipleTopology(factory); + registerSparseGridRamificationTopology(factory); + registerSparseGridTopology(factory); + registerSphereGridTopology(factory); +} + void init() { static bool first = true; if (first) { + // make sure that this plugin is registered into the PluginManager + sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME); + first = false; } } diff --git a/Sofa/Component/Topology/Container/src/sofa/component/topology/container/init.cpp b/Sofa/Component/Topology/Container/src/sofa/component/topology/container/init.cpp index ff104b239f8..99b3ffeac8d 100644 --- a/Sofa/Component/Topology/Container/src/sofa/component/topology/container/init.cpp +++ b/Sofa/Component/Topology/Container/src/sofa/component/topology/container/init.cpp @@ -25,6 +25,9 @@ #include #include +#include +#include + namespace sofa::component::topology::container { @@ -32,6 +35,7 @@ extern "C" { SOFA_EXPORT_DYNAMIC_LIBRARY void initExternalModule(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleName(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleVersion(); + SOFA_EXPORT_DYNAMIC_LIBRARY void registerObjects(sofa::core::ObjectFactory* factory); } void initExternalModule() @@ -49,6 +53,13 @@ const char* getModuleVersion() return MODULE_VERSION; } +void registerObjects(sofa::core::ObjectFactory* factory) +{ + factory->registerObjectsFromPlugin("Sofa.Component.Topology.Container.Constant"); + factory->registerObjectsFromPlugin("Sofa.Component.Topology.Container.Dynamic"); + factory->registerObjectsFromPlugin("Sofa.Component.Topology.Container.Grid"); +} + void init() { static bool first = true; @@ -59,6 +70,9 @@ void init() sofa::component::topology::container::dynamic::init(); sofa::component::topology::container::grid::init(); + // make sure that this plugin is registered into the PluginManager + sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME); + first = false; } } diff --git a/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/CenterPointTopologicalMapping.cpp b/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/CenterPointTopologicalMapping.cpp index 4e9ad9e2c77..c53d1e9b848 100644 --- a/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/CenterPointTopologicalMapping.cpp +++ b/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/CenterPointTopologicalMapping.cpp @@ -31,14 +31,15 @@ namespace sofa::component::topology::mapping { -using namespace sofa::defaulttype; + using namespace sofa::component::topology::mapping; using namespace sofa::core::topology; -// Register in the Factory -int CenterPointTopologicalMappingClass = core::RegisterObject ( "" ) - .add< CenterPointTopologicalMapping >() - ; +void registerCenterPointTopologicalMapping(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Topological mapping where each primitive in the input topology will be mapped to a point in the output topology.") + .add< CenterPointTopologicalMapping >()); +} // Implementation CenterPointTopologicalMapping::CenterPointTopologicalMapping () diff --git a/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Edge2QuadTopologicalMapping.cpp b/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Edge2QuadTopologicalMapping.cpp index 2f5bcfe4a2a..4b46f4c3194 100644 --- a/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Edge2QuadTopologicalMapping.cpp +++ b/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Edge2QuadTopologicalMapping.cpp @@ -39,11 +39,11 @@ using namespace sofa::defaulttype; using namespace sofa::component::topology::mapping; using namespace sofa::core::topology; -// Register in the Factory -int Edge2QuadTopologicalMappingClass = core::RegisterObject("Special case of mapping where EdgeSetTopology is converted to QuadSetTopology.") - .add< Edge2QuadTopologicalMapping >() - - ; +void registerEdge2QuadTopologicalMapping(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Topological mapping where EdgeSetTopology is converted to QuadSetTopology.") + .add< Edge2QuadTopologicalMapping >()); +} // Implementation Edge2QuadTopologicalMapping::Edge2QuadTopologicalMapping() diff --git a/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Hexa2QuadTopologicalMapping.cpp b/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Hexa2QuadTopologicalMapping.cpp index c7a9f35ef73..c749876cfe9 100644 --- a/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Hexa2QuadTopologicalMapping.cpp +++ b/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Hexa2QuadTopologicalMapping.cpp @@ -42,18 +42,14 @@ namespace sofa::component::topology::mapping { -using namespace sofa::defaulttype; - using namespace sofa::component::topology; using namespace sofa::core::topology; -// Register in the Factory -int Hexa2QuadTopologicalMappingClass = core::RegisterObject("Special case of mapping where HexahedronSetTopology is converted to QuadSetTopology") - .add< Hexa2QuadTopologicalMapping >() - - ; - -// Implementation +void registerHexa2QuadTopologicalMapping(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Topological mapping where HexahedronSetTopology is converted to QuadSetTopology") + .add< Hexa2QuadTopologicalMapping >()); +} Hexa2QuadTopologicalMapping::Hexa2QuadTopologicalMapping() : sofa::core::topology::TopologicalMapping() 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 818c9de3f78..3a0ff141ab2 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 @@ -41,18 +41,14 @@ namespace sofa::component::topology::mapping { -using namespace sofa::defaulttype; - using namespace sofa::component::topology::mapping; using namespace sofa::core::topology; -// Register in the Factory -int Hexa2TetraTopologicalMappingClass = core::RegisterObject("Special case of mapping where HexahedronSetTopology is converted to TetrahedronSetTopology") - .add< Hexa2TetraTopologicalMapping >() - - ; - -// Implementation +void registerHexa2TetraTopologicalMapping(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Topological mapping where HexahedronSetTopology is converted to TetrahedronSetTopology") + .add< Hexa2TetraTopologicalMapping >()); +} Hexa2TetraTopologicalMapping::Hexa2TetraTopologicalMapping() : sofa::core::topology::TopologicalMapping() diff --git a/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/IdentityTopologicalMapping.cpp b/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/IdentityTopologicalMapping.cpp index 04f1d379292..12334c60a8a 100644 --- a/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/IdentityTopologicalMapping.cpp +++ b/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/IdentityTopologicalMapping.cpp @@ -48,16 +48,14 @@ namespace sofa::component::topology::mapping { -using namespace sofa::defaulttype; - using namespace sofa::component::topology::mapping; using namespace sofa::core::topology; -// Register in the Factory -int IdentityTopologicalMappingClass = core::RegisterObject("This class is a specific implementation of TopologicalMapping where the destination topology should be kept identical to the source topology. The implementation currently assumes that both topology have been initialized identically.") - .add< IdentityTopologicalMapping >() - - ; +void registerIdentityTopologicalMapping(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("TopologicalMapping where the destination topology should be kept identical to the source topology. The implementation currently assumes that both topology have been initialized identically.") + .add< IdentityTopologicalMapping >()); +} IdentityTopologicalMapping::IdentityTopologicalMapping() { diff --git a/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Quad2TriangleTopologicalMapping.cpp b/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Quad2TriangleTopologicalMapping.cpp index 1d949df3185..9158923af67 100644 --- a/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Quad2TriangleTopologicalMapping.cpp +++ b/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Quad2TriangleTopologicalMapping.cpp @@ -53,13 +53,11 @@ typedef BaseMeshTopology In; /// Output Topology typedef BaseMeshTopology Out; -// Register in the Factory -int Quad2TriangleTopologicalMappingClass = core::RegisterObject("Special case of mapping where QuadSetTopology is converted to TriangleSetTopology") - .add< Quad2TriangleTopologicalMapping >() - - ; - -// Implementation +void registerQuad2TriangleTopologicalMapping(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Topological mapping where QuadSetTopology is converted to TriangleSetTopology") + .add< Quad2TriangleTopologicalMapping >()); +} Quad2TriangleTopologicalMapping::Quad2TriangleTopologicalMapping() : sofa::core::topology::TopologicalMapping() diff --git a/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/SubsetTopologicalMapping.cpp b/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/SubsetTopologicalMapping.cpp index efbda7a7405..3330149e011 100644 --- a/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/SubsetTopologicalMapping.cpp +++ b/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/SubsetTopologicalMapping.cpp @@ -47,16 +47,14 @@ namespace sofa::component::topology::mapping { -using namespace sofa::defaulttype; - using namespace sofa::component::topology::mapping; using namespace sofa::core::topology; -// Register in the Factory -int SubsetTopologicalMappingClass = core::RegisterObject("This class is a specific implementation of TopologicalMapping where the destination topology is a subset of the source topology. The implementation currently assumes that both topologies have been initialized correctly.") - .add< SubsetTopologicalMapping >() - - ; +void registerSubsetTopologicalMapping(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("TopologicalMapping where the destination topology is a subset of the source topology. The implementation currently assumes that both topologies have been initialized correctly.") + .add< SubsetTopologicalMapping >()); +} SubsetTopologicalMapping::SubsetTopologicalMapping() : d_samePoints(initData(&d_samePoints, false, "samePoints", "True if the same set of points is used in both topologies")) diff --git a/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Tetra2TriangleTopologicalMapping.cpp b/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Tetra2TriangleTopologicalMapping.cpp index 5158b94a940..315dab425f9 100644 --- a/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Tetra2TriangleTopologicalMapping.cpp +++ b/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Tetra2TriangleTopologicalMapping.cpp @@ -42,18 +42,14 @@ namespace sofa::component::topology::mapping { -using namespace sofa::defaulttype; - using namespace sofa::component::topology::mapping; using namespace sofa::core::topology; -// Register in the Factory -int Tetra2TriangleTopologicalMappingClass = core::RegisterObject("Special case of mapping where TetrahedronSetTopology is converted to TriangleSetTopology") - .add< Tetra2TriangleTopologicalMapping >() - - ; - -// Implementation +void registerTetra2TriangleTopologicalMapping(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Topological mapping where TetrahedronSetTopology is converted to TriangleSetTopology") + .add< Tetra2TriangleTopologicalMapping >()); +} Tetra2TriangleTopologicalMapping::Tetra2TriangleTopologicalMapping() : sofa::core::topology::TopologicalMapping() diff --git a/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Triangle2EdgeTopologicalMapping.cpp b/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Triangle2EdgeTopologicalMapping.cpp index a43dbf4e255..a8c83f5b0a1 100644 --- a/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Triangle2EdgeTopologicalMapping.cpp +++ b/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Triangle2EdgeTopologicalMapping.cpp @@ -41,14 +41,14 @@ namespace sofa::component::topology::mapping { -using namespace sofa::defaulttype; - using namespace sofa::component::topology::mapping; using namespace sofa::core::topology; -// Register in the Factory -int Triangle2EdgeTopologicalMappingClass = core::RegisterObject("Special case of mapping where TriangleSetTopology is converted to EdgeSetTopology") - .add< Triangle2EdgeTopologicalMapping >(); +void registerTriangle2EdgeTopologicalMapping(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Topological mapping where TriangleSetTopology is converted to EdgeSetTopology") + .add< Triangle2EdgeTopologicalMapping >()); +} Triangle2EdgeTopologicalMapping::Triangle2EdgeTopologicalMapping() : sofa::core::topology::TopologicalMapping() diff --git a/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/init.cpp b/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/init.cpp index c84007bf931..7a520cdffd2 100644 --- a/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/init.cpp +++ b/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/init.cpp @@ -21,13 +21,26 @@ ******************************************************************************/ #include #include +#include + namespace sofa::component::topology::mapping { - + +extern void registerCenterPointTopologicalMapping(sofa::core::ObjectFactory* factory); +extern void registerEdge2QuadTopologicalMapping(sofa::core::ObjectFactory* factory); +extern void registerHexa2QuadTopologicalMapping(sofa::core::ObjectFactory* factory); +extern void registerHexa2TetraTopologicalMapping(sofa::core::ObjectFactory* factory); +extern void registerIdentityTopologicalMapping(sofa::core::ObjectFactory* factory); +extern void registerQuad2TriangleTopologicalMapping(sofa::core::ObjectFactory* factory); +extern void registerSubsetTopologicalMapping(sofa::core::ObjectFactory* factory); +extern void registerTetra2TriangleTopologicalMapping(sofa::core::ObjectFactory* factory); +extern void registerTriangle2EdgeTopologicalMapping(sofa::core::ObjectFactory* factory); + extern "C" { SOFA_EXPORT_DYNAMIC_LIBRARY void initExternalModule(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleName(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleVersion(); + SOFA_EXPORT_DYNAMIC_LIBRARY void registerObjects(sofa::core::ObjectFactory* factory); } void initExternalModule() @@ -45,11 +58,27 @@ const char* getModuleVersion() return MODULE_VERSION; } +void registerObjects(sofa::core::ObjectFactory* factory) +{ + registerCenterPointTopologicalMapping(factory); + registerEdge2QuadTopologicalMapping(factory); + registerHexa2QuadTopologicalMapping(factory); + registerHexa2TetraTopologicalMapping(factory); + registerIdentityTopologicalMapping(factory); + registerQuad2TriangleTopologicalMapping(factory); + registerSubsetTopologicalMapping(factory); + registerTetra2TriangleTopologicalMapping(factory); + registerTriangle2EdgeTopologicalMapping(factory); +} + void init() { static bool first = true; if (first) { + // make sure that this plugin is registered into the PluginManager + sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME); + first = false; } } 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 9532d64031d..f9cacb1af93 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 @@ -50,11 +50,11 @@ namespace sofa::component::topology::utility using namespace sofa::type; using namespace defaulttype; - - -int TopologicalChangeProcessorClass = core::RegisterObject("Read topological Changes and process them.") - .add< TopologicalChangeProcessor >(); - +void registerTopologicalChangeProcessor(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Read topological changes and process them.") + .add< TopologicalChangeProcessor >()); +} TopologicalChangeProcessor::TopologicalChangeProcessor() : d_filename(initData(&d_filename, "filename", "input file name for topological changes.")) diff --git a/Sofa/Component/Topology/Utility/src/sofa/component/topology/utility/TopologyBoundingTrasher.cpp b/Sofa/Component/Topology/Utility/src/sofa/component/topology/utility/TopologyBoundingTrasher.cpp index 4f2eda6e674..853dd829362 100644 --- a/Sofa/Component/Topology/Utility/src/sofa/component/topology/utility/TopologyBoundingTrasher.cpp +++ b/Sofa/Component/Topology/Utility/src/sofa/component/topology/utility/TopologyBoundingTrasher.cpp @@ -28,11 +28,13 @@ namespace sofa::component::topology::utility { -using namespace sofa::type; using namespace sofa::defaulttype; -int TopologyBoundingTrasherClass = core::RegisterObject("A class to remove all elements going outside from the given Bounding Box.") - .add< TopologyBoundingTrasher >(true); +void registerTopologyBoundingTrasher(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Component removing all elements going outside from the given bounding box.") + .add< TopologyBoundingTrasher >()); +} template class SOFA_COMPONENT_TOPOLOGY_UTILITY_API TopologyBoundingTrasher; diff --git a/Sofa/Component/Topology/Utility/src/sofa/component/topology/utility/TopologyChecker.cpp b/Sofa/Component/Topology/Utility/src/sofa/component/topology/utility/TopologyChecker.cpp index a2b86bf7270..cc5994e227a 100644 --- a/Sofa/Component/Topology/Utility/src/sofa/component/topology/utility/TopologyChecker.cpp +++ b/Sofa/Component/Topology/Utility/src/sofa/component/topology/utility/TopologyChecker.cpp @@ -33,13 +33,13 @@ namespace sofa::component::topology::utility { -using namespace defaulttype; using namespace sofa::core::topology; - -int TopologyCheckerClass = core::RegisterObject("Read topological Changes and process them.") - .add< TopologyChecker >(); - +void registerTopologyChecker(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Read topological Changes and process them.") + .add< TopologyChecker >()); +} TopologyChecker::TopologyChecker() : d_eachStep(initData(&d_eachStep, false, "eachStep", "Check topology at each step")) diff --git a/Sofa/Component/Topology/Utility/src/sofa/component/topology/utility/init.cpp b/Sofa/Component/Topology/Utility/src/sofa/component/topology/utility/init.cpp index c4cbe818890..fc671fdd1e1 100644 --- a/Sofa/Component/Topology/Utility/src/sofa/component/topology/utility/init.cpp +++ b/Sofa/Component/Topology/Utility/src/sofa/component/topology/utility/init.cpp @@ -21,13 +21,20 @@ ******************************************************************************/ #include #include +#include + namespace sofa::component::topology::utility { - + +extern void registerTopologicalChangeProcessor(sofa::core::ObjectFactory* factory); +extern void registerTopologyBoundingTrasher(sofa::core::ObjectFactory* factory); +extern void registerTopologyChecker(sofa::core::ObjectFactory* factory); + extern "C" { SOFA_EXPORT_DYNAMIC_LIBRARY void initExternalModule(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleName(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleVersion(); + SOFA_EXPORT_DYNAMIC_LIBRARY void registerObjects(sofa::core::ObjectFactory* factory); } void initExternalModule() @@ -45,11 +52,21 @@ const char* getModuleVersion() return MODULE_VERSION; } +void registerObjects(sofa::core::ObjectFactory* factory) +{ + registerTopologicalChangeProcessor(factory); + registerTopologyBoundingTrasher(factory); + registerTopologyChecker(factory); +} + void init() { static bool first = true; if (first) { + // make sure that this plugin is registered into the PluginManager + sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME); + first = false; } } diff --git a/Sofa/Component/Topology/src/sofa/component/topology/init.cpp b/Sofa/Component/Topology/src/sofa/component/topology/init.cpp index 90c1fb75ffc..145ed36c9ec 100644 --- a/Sofa/Component/Topology/src/sofa/component/topology/init.cpp +++ b/Sofa/Component/Topology/src/sofa/component/topology/init.cpp @@ -25,6 +25,9 @@ #include #include +#include +#include + namespace sofa::component::topology { @@ -32,6 +35,7 @@ extern "C" { SOFA_EXPORT_DYNAMIC_LIBRARY void initExternalModule(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleName(); SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleVersion(); + SOFA_EXPORT_DYNAMIC_LIBRARY void registerObjects(sofa::core::ObjectFactory* factory); } void initExternalModule() @@ -49,6 +53,13 @@ const char* getModuleVersion() return MODULE_VERSION; } +void registerObjects(sofa::core::ObjectFactory* factory) +{ + factory->registerObjectsFromPlugin("Sofa.Component.Topology.Container"); + factory->registerObjectsFromPlugin("Sofa.Component.Topology.Mapping"); + factory->registerObjectsFromPlugin("Sofa.Component.Topology.Utility"); +} + void init() { static bool first = true; @@ -59,6 +70,9 @@ void init() sofa::component::topology::mapping::init(); sofa::component::topology::utility::init(); + // make sure that this plugin is registered into the PluginManager + sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME); + first = false; } } diff --git a/Sofa/Component/src/sofa/component/init.cpp b/Sofa/Component/src/sofa/component/init.cpp index 540a98d851b..c9626de10c1 100644 --- a/Sofa/Component/src/sofa/component/init.cpp +++ b/Sofa/Component/src/sofa/component/init.cpp @@ -86,6 +86,7 @@ void registerObjects(sofa::core::ObjectFactory* factory) factory->registerObjectsFromPlugin("Sofa.Component.Haptics"); factory->registerObjectsFromPlugin("Sofa.Component.Diffusion"); factory->registerObjectsFromPlugin("Sofa.Component.ODESolver"); + factory->registerObjectsFromPlugin("Sofa.Component.Topology"); factory->registerObjectsFromPlugin("Sofa.Component.LinearSolver"); factory->registerObjectsFromPlugin("Sofa.Component.Engine"); } diff --git a/Sofa/framework/Helper/src/sofa/helper/ComponentChange.cpp b/Sofa/framework/Helper/src/sofa/helper/ComponentChange.cpp index 67f2e841145..b2d0cd8f36d 100644 --- a/Sofa/framework/Helper/src/sofa/helper/ComponentChange.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/ComponentChange.cpp @@ -784,6 +784,15 @@ const std::map< std::string, Dealiased, std::less<> > dealiasedComponents = { {"ImplicitEulerSolver", Dealiased("v24.12","EulerImplicitSolver")}, {"ImplicitEuler", Dealiased("v24.12","EulerImplicitSolver")}, {"VariationalSolver", Dealiased("v24.12","VariationalSymplecticSolver")}, + {"Mesh", Dealiased("v24.12","MeshTopology")}, + {"SphereQuad", Dealiased("v24.12","SphereQuadTopology")}, + {"CylinderGrid", Dealiased("v24.12","CylinderGridTopology")}, + {"Grid", Dealiased("v24.12","GridTopology")}, + {"RegularGrid", Dealiased("v24.12","RegularGridTopology")}, + {"SparseGridMultiple", Dealiased("v24.12","SparseGridMultipleTopology")}, + {"SparseGridRamification", Dealiased("v24.12","SparseGridRamificationTopology")}, + {"SparseGrid", Dealiased("v24.12","SparseGridTopology")}, + {"SphereGrid", Dealiased("v24.12","SphereGridTopology")}, {"SVDLinear", Dealiased("v24.12","SVDLinearSolver")}, {"SVD", Dealiased("v24.12","SVDLinearSolver")}, {"CGSolver", Dealiased("v24.12","CGLinearSolver")}, @@ -796,7 +805,7 @@ const std::map< std::string, Dealiased, std::less<> > dealiasedComponents = { {"SSORLinearSolver", Dealiased("v24.12","SSORPreconditioner")}, {"SSORSolver", Dealiased("v24.12","SSORPreconditioner")}, {"RigidEngine", Dealiased("v24.12","RigidToQuatEngine")}, - + }; } // namespace sofa::helper::lifecycle diff --git a/applications/projects/SceneChecking/tests/SceneChecker_test.cpp b/applications/projects/SceneChecking/tests/SceneChecker_test.cpp index b5511140d91..9de8d0bbcf4 100644 --- a/applications/projects/SceneChecking/tests/SceneChecker_test.cpp +++ b/applications/projects/SceneChecking/tests/SceneChecker_test.cpp @@ -209,15 +209,15 @@ struct SceneChecker_test : public BaseSimulationTest void checkUsingAlias(bool sceneWithAlias) { - const std::string withAlias = "Mesh"; - const std::string withoutAlias = "MeshTopology"; + const std::string withAlias = "VisualModel"; + const std::string withoutAlias = "VisualModelImpl"; const std::string componentName = sceneWithAlias ? withAlias : withoutAlias; std::stringstream scene; scene << " \n" << " \n" << " \n" - << " \n" + << " \n" << " \n" << " <" << componentName << "/> \n" << " \n"; diff --git a/examples/Component/Constraint/Lagrangian/FixedLagrangianConstaint_Vec3.scn b/examples/Component/Constraint/Lagrangian/FixedLagrangianConstaint_Vec3.scn index ef74dbb59a4..47d32cedd42 100644 --- a/examples/Component/Constraint/Lagrangian/FixedLagrangianConstaint_Vec3.scn +++ b/examples/Component/Constraint/Lagrangian/FixedLagrangianConstaint_Vec3.scn @@ -29,7 +29,7 @@ - + From 9e08f22f3dd3373d0137344222074c59d6f3573e Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 7 Oct 2024 02:09:12 +0200 Subject: [PATCH 14/43] [examples] Remove old tutorials (#5035) Co-authored-by: Paul Baksic <30337881+bakpaul@users.noreply.github.com> --- examples/Tutorials/OldTutorials/demo1.scn | 39 ----- .../Tutorials/OldTutorials/demo1.scn.view | 2 - examples/Tutorials/OldTutorials/demo10.scn | 125 -------------- .../Tutorials/OldTutorials/demo10Triangle.scn | 144 ---------------- examples/Tutorials/OldTutorials/demo2.scn | 47 ----- .../Tutorials/OldTutorials/demo2.scn.view | 2 - examples/Tutorials/OldTutorials/demo3.scn | 89 ---------- .../Tutorials/OldTutorials/demo3.scn.view | 2 - examples/Tutorials/OldTutorials/demo4.scn | 126 -------------- .../Tutorials/OldTutorials/demo4.scn.view | 2 - examples/Tutorials/OldTutorials/demo5.scn | 133 -------------- .../Tutorials/OldTutorials/demo5.scn.view | 2 - examples/Tutorials/OldTutorials/demo6.scn | 143 --------------- .../Tutorials/OldTutorials/demo6.scn.view | 2 - .../Tutorials/OldTutorials/demo6Triangle.scn | 161 ----------------- .../OldTutorials/demo6Triangle.scn.view | 2 - examples/Tutorials/OldTutorials/demo7.scn | 145 ---------------- .../Tutorials/OldTutorials/demo7.scn.view | 2 - .../Tutorials/OldTutorials/demo7Triangle.scn | 162 ----------------- .../OldTutorials/demo7Triangle.scn.view | 2 - examples/Tutorials/OldTutorials/demo8.scn | 146 ---------------- .../Tutorials/OldTutorials/demo8.scn.view | 2 - .../Tutorials/OldTutorials/demo8Triangle.scn | 163 ------------------ .../OldTutorials/demo8Triangle.scn.view | 2 - examples/Tutorials/OldTutorials/demo9.scn | 148 ---------------- examples/Tutorials/OldTutorials/tutorial1.scn | 73 -------- .../Tutorials/OldTutorials/tutorial1.scn.view | 2 - examples/Tutorials/OldTutorials/tutorial2.scn | 84 --------- .../Tutorials/OldTutorials/tutorial2.scn.view | 2 - examples/Tutorials/OldTutorials/tutorial3.scn | 99 ----------- .../Tutorials/OldTutorials/tutorial3.scn.view | 2 - examples/Tutorials/OldTutorials/tutorial4.scn | 105 ----------- .../Tutorials/OldTutorials/tutorial4.scn.view | 2 - .../Tutorials/OldTutorials/tutorial4FEM.scn | 105 ----------- .../OldTutorials/tutorial4FEM.scn.view | 2 - 35 files changed, 2269 deletions(-) delete mode 100644 examples/Tutorials/OldTutorials/demo1.scn delete mode 100644 examples/Tutorials/OldTutorials/demo1.scn.view delete mode 100644 examples/Tutorials/OldTutorials/demo10.scn delete mode 100644 examples/Tutorials/OldTutorials/demo10Triangle.scn delete mode 100644 examples/Tutorials/OldTutorials/demo2.scn delete mode 100644 examples/Tutorials/OldTutorials/demo2.scn.view delete mode 100644 examples/Tutorials/OldTutorials/demo3.scn delete mode 100644 examples/Tutorials/OldTutorials/demo3.scn.view delete mode 100644 examples/Tutorials/OldTutorials/demo4.scn delete mode 100644 examples/Tutorials/OldTutorials/demo4.scn.view delete mode 100644 examples/Tutorials/OldTutorials/demo5.scn delete mode 100644 examples/Tutorials/OldTutorials/demo5.scn.view delete mode 100644 examples/Tutorials/OldTutorials/demo6.scn delete mode 100644 examples/Tutorials/OldTutorials/demo6.scn.view delete mode 100644 examples/Tutorials/OldTutorials/demo6Triangle.scn delete mode 100644 examples/Tutorials/OldTutorials/demo6Triangle.scn.view delete mode 100644 examples/Tutorials/OldTutorials/demo7.scn delete mode 100644 examples/Tutorials/OldTutorials/demo7.scn.view delete mode 100644 examples/Tutorials/OldTutorials/demo7Triangle.scn delete mode 100644 examples/Tutorials/OldTutorials/demo7Triangle.scn.view delete mode 100644 examples/Tutorials/OldTutorials/demo8.scn delete mode 100644 examples/Tutorials/OldTutorials/demo8.scn.view delete mode 100644 examples/Tutorials/OldTutorials/demo8Triangle.scn delete mode 100644 examples/Tutorials/OldTutorials/demo8Triangle.scn.view delete mode 100644 examples/Tutorials/OldTutorials/demo9.scn delete mode 100644 examples/Tutorials/OldTutorials/tutorial1.scn delete mode 100644 examples/Tutorials/OldTutorials/tutorial1.scn.view delete mode 100644 examples/Tutorials/OldTutorials/tutorial2.scn delete mode 100644 examples/Tutorials/OldTutorials/tutorial2.scn.view delete mode 100644 examples/Tutorials/OldTutorials/tutorial3.scn delete mode 100644 examples/Tutorials/OldTutorials/tutorial3.scn.view delete mode 100644 examples/Tutorials/OldTutorials/tutorial4.scn delete mode 100644 examples/Tutorials/OldTutorials/tutorial4.scn.view delete mode 100644 examples/Tutorials/OldTutorials/tutorial4FEM.scn delete mode 100644 examples/Tutorials/OldTutorials/tutorial4FEM.scn.view diff --git a/examples/Tutorials/OldTutorials/demo1.scn b/examples/Tutorials/OldTutorials/demo1.scn deleted file mode 100644 index 6d7280901d5..00000000000 --- a/examples/Tutorials/OldTutorials/demo1.scn +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/Tutorials/OldTutorials/demo1.scn.view b/examples/Tutorials/OldTutorials/demo1.scn.view deleted file mode 100644 index ef5f276aa54..00000000000 --- a/examples/Tutorials/OldTutorials/demo1.scn.view +++ /dev/null @@ -1,2 +0,0 @@ --21.4245 17.4428 -75.5591 --0.00692736 -0.695133 0 0.718676 diff --git a/examples/Tutorials/OldTutorials/demo10.scn b/examples/Tutorials/OldTutorials/demo10.scn deleted file mode 100644 index 6f33a7e6d6c..00000000000 --- a/examples/Tutorials/OldTutorials/demo10.scn +++ /dev/null @@ -1,125 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/Tutorials/OldTutorials/demo10Triangle.scn b/examples/Tutorials/OldTutorials/demo10Triangle.scn deleted file mode 100644 index 5fd5d9cc010..00000000000 --- a/examples/Tutorials/OldTutorials/demo10Triangle.scn +++ /dev/null @@ -1,144 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/Tutorials/OldTutorials/demo2.scn b/examples/Tutorials/OldTutorials/demo2.scn deleted file mode 100644 index 322db51c3cf..00000000000 --- a/examples/Tutorials/OldTutorials/demo2.scn +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/Tutorials/OldTutorials/demo2.scn.view b/examples/Tutorials/OldTutorials/demo2.scn.view deleted file mode 100644 index 56f3449e944..00000000000 --- a/examples/Tutorials/OldTutorials/demo2.scn.view +++ /dev/null @@ -1,2 +0,0 @@ --6.8634 15.7104 -75.5591 --0.00692736 -0.695133 0 0.718676 diff --git a/examples/Tutorials/OldTutorials/demo3.scn b/examples/Tutorials/OldTutorials/demo3.scn deleted file mode 100644 index ea266f58de0..00000000000 --- a/examples/Tutorials/OldTutorials/demo3.scn +++ /dev/null @@ -1,89 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/Tutorials/OldTutorials/demo3.scn.view b/examples/Tutorials/OldTutorials/demo3.scn.view deleted file mode 100644 index 56f3449e944..00000000000 --- a/examples/Tutorials/OldTutorials/demo3.scn.view +++ /dev/null @@ -1,2 +0,0 @@ --6.8634 15.7104 -75.5591 --0.00692736 -0.695133 0 0.718676 diff --git a/examples/Tutorials/OldTutorials/demo4.scn b/examples/Tutorials/OldTutorials/demo4.scn deleted file mode 100644 index 7e91f57e0c0..00000000000 --- a/examples/Tutorials/OldTutorials/demo4.scn +++ /dev/null @@ -1,126 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/Tutorials/OldTutorials/demo4.scn.view b/examples/Tutorials/OldTutorials/demo4.scn.view deleted file mode 100644 index 56f3449e944..00000000000 --- a/examples/Tutorials/OldTutorials/demo4.scn.view +++ /dev/null @@ -1,2 +0,0 @@ --6.8634 15.7104 -75.5591 --0.00692736 -0.695133 0 0.718676 diff --git a/examples/Tutorials/OldTutorials/demo5.scn b/examples/Tutorials/OldTutorials/demo5.scn deleted file mode 100644 index 7c225a6884d..00000000000 --- a/examples/Tutorials/OldTutorials/demo5.scn +++ /dev/null @@ -1,133 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/Tutorials/OldTutorials/demo5.scn.view b/examples/Tutorials/OldTutorials/demo5.scn.view deleted file mode 100644 index 56f3449e944..00000000000 --- a/examples/Tutorials/OldTutorials/demo5.scn.view +++ /dev/null @@ -1,2 +0,0 @@ --6.8634 15.7104 -75.5591 --0.00692736 -0.695133 0 0.718676 diff --git a/examples/Tutorials/OldTutorials/demo6.scn b/examples/Tutorials/OldTutorials/demo6.scn deleted file mode 100644 index e1b35d507e9..00000000000 --- a/examples/Tutorials/OldTutorials/demo6.scn +++ /dev/null @@ -1,143 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/Tutorials/OldTutorials/demo6.scn.view b/examples/Tutorials/OldTutorials/demo6.scn.view deleted file mode 100644 index 56f3449e944..00000000000 --- a/examples/Tutorials/OldTutorials/demo6.scn.view +++ /dev/null @@ -1,2 +0,0 @@ --6.8634 15.7104 -75.5591 --0.00692736 -0.695133 0 0.718676 diff --git a/examples/Tutorials/OldTutorials/demo6Triangle.scn b/examples/Tutorials/OldTutorials/demo6Triangle.scn deleted file mode 100644 index 8e8e4d7117c..00000000000 --- a/examples/Tutorials/OldTutorials/demo6Triangle.scn +++ /dev/null @@ -1,161 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/Tutorials/OldTutorials/demo6Triangle.scn.view b/examples/Tutorials/OldTutorials/demo6Triangle.scn.view deleted file mode 100644 index 56f3449e944..00000000000 --- a/examples/Tutorials/OldTutorials/demo6Triangle.scn.view +++ /dev/null @@ -1,2 +0,0 @@ --6.8634 15.7104 -75.5591 --0.00692736 -0.695133 0 0.718676 diff --git a/examples/Tutorials/OldTutorials/demo7.scn b/examples/Tutorials/OldTutorials/demo7.scn deleted file mode 100644 index e36feaf25c5..00000000000 --- a/examples/Tutorials/OldTutorials/demo7.scn +++ /dev/null @@ -1,145 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/Tutorials/OldTutorials/demo7.scn.view b/examples/Tutorials/OldTutorials/demo7.scn.view deleted file mode 100644 index 56f3449e944..00000000000 --- a/examples/Tutorials/OldTutorials/demo7.scn.view +++ /dev/null @@ -1,2 +0,0 @@ --6.8634 15.7104 -75.5591 --0.00692736 -0.695133 0 0.718676 diff --git a/examples/Tutorials/OldTutorials/demo7Triangle.scn b/examples/Tutorials/OldTutorials/demo7Triangle.scn deleted file mode 100644 index 65b6f54b53d..00000000000 --- a/examples/Tutorials/OldTutorials/demo7Triangle.scn +++ /dev/null @@ -1,162 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/Tutorials/OldTutorials/demo7Triangle.scn.view b/examples/Tutorials/OldTutorials/demo7Triangle.scn.view deleted file mode 100644 index 56f3449e944..00000000000 --- a/examples/Tutorials/OldTutorials/demo7Triangle.scn.view +++ /dev/null @@ -1,2 +0,0 @@ --6.8634 15.7104 -75.5591 --0.00692736 -0.695133 0 0.718676 diff --git a/examples/Tutorials/OldTutorials/demo8.scn b/examples/Tutorials/OldTutorials/demo8.scn deleted file mode 100644 index c6eef70a25c..00000000000 --- a/examples/Tutorials/OldTutorials/demo8.scn +++ /dev/null @@ -1,146 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/Tutorials/OldTutorials/demo8.scn.view b/examples/Tutorials/OldTutorials/demo8.scn.view deleted file mode 100644 index 56f3449e944..00000000000 --- a/examples/Tutorials/OldTutorials/demo8.scn.view +++ /dev/null @@ -1,2 +0,0 @@ --6.8634 15.7104 -75.5591 --0.00692736 -0.695133 0 0.718676 diff --git a/examples/Tutorials/OldTutorials/demo8Triangle.scn b/examples/Tutorials/OldTutorials/demo8Triangle.scn deleted file mode 100644 index ee2e7d1e25e..00000000000 --- a/examples/Tutorials/OldTutorials/demo8Triangle.scn +++ /dev/null @@ -1,163 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/Tutorials/OldTutorials/demo8Triangle.scn.view b/examples/Tutorials/OldTutorials/demo8Triangle.scn.view deleted file mode 100644 index 56f3449e944..00000000000 --- a/examples/Tutorials/OldTutorials/demo8Triangle.scn.view +++ /dev/null @@ -1,2 +0,0 @@ --6.8634 15.7104 -75.5591 --0.00692736 -0.695133 0 0.718676 diff --git a/examples/Tutorials/OldTutorials/demo9.scn b/examples/Tutorials/OldTutorials/demo9.scn deleted file mode 100644 index 2b7471e6f11..00000000000 --- a/examples/Tutorials/OldTutorials/demo9.scn +++ /dev/null @@ -1,148 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/Tutorials/OldTutorials/tutorial1.scn b/examples/Tutorials/OldTutorials/tutorial1.scn deleted file mode 100644 index 819a1e27bd5..00000000000 --- a/examples/Tutorials/OldTutorials/tutorial1.scn +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/Tutorials/OldTutorials/tutorial1.scn.view b/examples/Tutorials/OldTutorials/tutorial1.scn.view deleted file mode 100644 index a268647ca4c..00000000000 --- a/examples/Tutorials/OldTutorials/tutorial1.scn.view +++ /dev/null @@ -1,2 +0,0 @@ --17.4652 2.62751 -50.7728 -0.00248989 -0.986682 -0.162642 0.000857851 diff --git a/examples/Tutorials/OldTutorials/tutorial2.scn b/examples/Tutorials/OldTutorials/tutorial2.scn deleted file mode 100644 index 0de1906dc30..00000000000 --- a/examples/Tutorials/OldTutorials/tutorial2.scn +++ /dev/null @@ -1,84 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/Tutorials/OldTutorials/tutorial2.scn.view b/examples/Tutorials/OldTutorials/tutorial2.scn.view deleted file mode 100644 index 9e6925d2e1d..00000000000 --- a/examples/Tutorials/OldTutorials/tutorial2.scn.view +++ /dev/null @@ -1,2 +0,0 @@ --32.4575 24.5749 -80.9119 -0.0368403 -0.950489 -0.0483001 -0.304763 diff --git a/examples/Tutorials/OldTutorials/tutorial3.scn b/examples/Tutorials/OldTutorials/tutorial3.scn deleted file mode 100644 index 3afc2a6612d..00000000000 --- a/examples/Tutorials/OldTutorials/tutorial3.scn +++ /dev/null @@ -1,99 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/Tutorials/OldTutorials/tutorial3.scn.view b/examples/Tutorials/OldTutorials/tutorial3.scn.view deleted file mode 100644 index ab36d579123..00000000000 --- a/examples/Tutorials/OldTutorials/tutorial3.scn.view +++ /dev/null @@ -1,2 +0,0 @@ --2.85936 -10.5873 -60.4127 -0.000252845 -0.985949 -0.166852 0.00812279 diff --git a/examples/Tutorials/OldTutorials/tutorial4.scn b/examples/Tutorials/OldTutorials/tutorial4.scn deleted file mode 100644 index 04c345c03e2..00000000000 --- a/examples/Tutorials/OldTutorials/tutorial4.scn +++ /dev/null @@ -1,105 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/Tutorials/OldTutorials/tutorial4.scn.view b/examples/Tutorials/OldTutorials/tutorial4.scn.view deleted file mode 100644 index ab36d579123..00000000000 --- a/examples/Tutorials/OldTutorials/tutorial4.scn.view +++ /dev/null @@ -1,2 +0,0 @@ --2.85936 -10.5873 -60.4127 -0.000252845 -0.985949 -0.166852 0.00812279 diff --git a/examples/Tutorials/OldTutorials/tutorial4FEM.scn b/examples/Tutorials/OldTutorials/tutorial4FEM.scn deleted file mode 100644 index 42fec0ffbc8..00000000000 --- a/examples/Tutorials/OldTutorials/tutorial4FEM.scn +++ /dev/null @@ -1,105 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/Tutorials/OldTutorials/tutorial4FEM.scn.view b/examples/Tutorials/OldTutorials/tutorial4FEM.scn.view deleted file mode 100644 index ab36d579123..00000000000 --- a/examples/Tutorials/OldTutorials/tutorial4FEM.scn.view +++ /dev/null @@ -1,2 +0,0 @@ --2.85936 -10.5873 -60.4127 -0.000252845 -0.985949 -0.166852 0.00812279 From d36dcf8a620cda3e9b54a0dc5d48d3e9b4bab6cf Mon Sep 17 00:00:00 2001 From: Paul Baksic <30337881+bakpaul@users.noreply.github.com> Date: Mon, 7 Oct 2024 06:57:06 +0200 Subject: [PATCH 15/43] [DefaultAnimationLoop] Add timer for collision begin and collision end (#5043) Add timer for collision begin and collision end Co-authored-by: erik pernod --- .../Core/src/sofa/simulation/DefaultAnimationLoop.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/DefaultAnimationLoop.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/DefaultAnimationLoop.cpp index c20b0c0d80b..ad80661f338 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/DefaultAnimationLoop.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/DefaultAnimationLoop.cpp @@ -240,6 +240,7 @@ void DefaultAnimationLoop::propagateOnlyPositionAndVelocity(const SReal nextTime void DefaultAnimationLoop::propagateCollisionBeginEvent(const core::ExecParams* params) const { + SCOPED_TIMER("CollisionBeginEvent"); CollisionBeginEvent evBegin; PropagateEventVisitor eventPropagation( params, &evBegin); eventPropagation.execute(m_node); @@ -247,6 +248,7 @@ void DefaultAnimationLoop::propagateCollisionBeginEvent(const core::ExecParams* void DefaultAnimationLoop::propagateCollisionEndEvent(const core::ExecParams* params) const { + SCOPED_TIMER("CollisionEndEvent"); CollisionEndEvent evEnd; PropagateEventVisitor eventPropagation( params, &evEnd); eventPropagation.execute(m_node); From 8e4619c8e8da1e032c7699fd93d87ec220b7d469 Mon Sep 17 00:00:00 2001 From: Paul Baksic <30337881+bakpaul@users.noreply.github.com> Date: Tue, 8 Oct 2024 02:05:53 +0200 Subject: [PATCH 16/43] [tools] Deactivate all plugin containing CUDA in its name (#5044) Deactivate all plugin containing CUDA in its name --- tools/postinstall-fixup/common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/postinstall-fixup/common.sh b/tools/postinstall-fixup/common.sh index 07085a11805..6ffca518e09 100644 --- a/tools/postinstall-fixup/common.sh +++ b/tools/postinstall-fixup/common.sh @@ -25,7 +25,6 @@ function clean_default_plugins() ShapeMatchingPlugin \ SofaAssimp \ SofaCarving \ - SofaCUDA \ SofaDistanceGrid \ SofaEulerianFluid \ SofaImplicitField \ @@ -36,6 +35,7 @@ function clean_default_plugins() SofaValidation \ STLIB \ VolumetricRendering \ + CUDA \ ; do disabled_plugins=$disabled_plugins'\|'$plugin done From ffdc263e9d616f3563bc48bedfcc28ac3e5495d6 Mon Sep 17 00:00:00 2001 From: Paul Baksic <30337881+bakpaul@users.noreply.github.com> Date: Tue, 8 Oct 2024 06:08:48 +0200 Subject: [PATCH 17/43] [GenericConstraintSolver] FIX Generic constraint solver timer (#5045) FIX Generic constraint solver timer --- .../lagrangian/solver/GenericConstraintSolver.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.cpp b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.cpp index 93263884467..7a60a110c4e 100644 --- a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.cpp +++ b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.cpp @@ -531,8 +531,6 @@ void GenericConstraintSolver::applyMotionCorrection( void GenericConstraintSolver::computeAndApplyMotionCorrection(const core::ConstraintParams* cParams, MultiVecId res1, MultiVecId res2) const { - SCOPED_TIMER("Compute And Apply Motion Correction"); - static constexpr auto supportedCorrections = { sofa::core::ConstraintOrder::POS_AND_VEL, sofa::core::ConstraintOrder::POS, @@ -544,11 +542,11 @@ void GenericConstraintSolver::computeAndApplyMotionCorrection(const core::Constr for (const auto& constraintCorrection : filteredConstraintCorrections()) { { - SCOPED_TIMER("ComputeCorrection"); + SCOPED_TIMER("doComputeCorrection"); constraintCorrection->computeMotionCorrectionFromLambda(cParams, this->getDx(), ¤t_cp->f); } - SCOPED_TIMER("ApplyCorrection"); + SCOPED_TIMER("doApplyCorrection"); applyMotionCorrection(cParams, res1, res2, constraintCorrection); } } From ac296a34802c44001989f65094265cd65d7ec62e Mon Sep 17 00:00:00 2001 From: erik pernod Date: Tue, 8 Oct 2024 08:18:38 +0200 Subject: [PATCH 18/43] [Engine.Select] Fix MeshSubsetEngine compilation (#5046) [Engine] Fix MeshSubsetEngine compilation --- .../src/sofa/component/engine/select/MeshSubsetEngine.inl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshSubsetEngine.inl b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshSubsetEngine.inl index cbc1ece7f81..bed1fa6999b 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshSubsetEngine.inl +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshSubsetEngine.inl @@ -104,9 +104,9 @@ void extractElements( template void MeshSubsetEngine::doUpdate() { - helper::ReadAccessor > pos(this->inputPosition); - const helper::ReadAccessor > ind(this->indices); - helper::WriteOnlyAccessor > opos(this->position); + helper::ReadAccessor > pos(this->d_inputPosition); + const helper::ReadAccessor > ind(this->d_indices); + helper::WriteOnlyAccessor > opos(this->d_position); opos.resize(ind.size()); std::map FtoS; From 95beb4ad5875bf6d146b5de8230853eecc161896 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Tue, 8 Oct 2024 17:26:21 +0900 Subject: [PATCH 19/43] [Core.Collision] NarrowPhaseDetection: disable lighting when displaying detection outputs (#5048) remove lighting when displaying contacts --- .../Core/src/sofa/core/collision/NarrowPhaseDetection.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sofa/framework/Core/src/sofa/core/collision/NarrowPhaseDetection.cpp b/Sofa/framework/Core/src/sofa/core/collision/NarrowPhaseDetection.cpp index afcd04e761e..af9c8208d9d 100644 --- a/Sofa/framework/Core/src/sofa/core/collision/NarrowPhaseDetection.cpp +++ b/Sofa/framework/Core/src/sofa/core/collision/NarrowPhaseDetection.cpp @@ -54,6 +54,9 @@ void NarrowPhaseDetection::draw(const core::visual::VisualParams* vparams) { if(! vparams->displayFlags().getShowDetectionOutputs()) return; + [[maybe_unused]] auto state = vparams->drawTool()->makeStateLifeCycle(); + vparams->drawTool()->disableLighting(); + std::vector points; for (auto mapIt = m_outputsMap.begin(); mapIt!=m_outputsMap.end() ; ++mapIt) From 0a8be8e56625dfe6fa47a6fb7f67fbd200320911 Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Thu, 10 Oct 2024 06:01:58 +0200 Subject: [PATCH 20/43] [all] Various changes relative to the constraint matrix (#5017) * [all] Various changes relative to the constraint matrix * rename * cross-platform random generation --- .../LinearSolverConstraintCorrection.h | 17 +- .../LinearSolverConstraintCorrection.inl | 80 +++++---- .../lagrangian/correction/config.h.in | 11 +- .../iterative/MatrixLinearSolver.h | 83 +++++---- .../iterative/MatrixLinearSolver.inl | 15 +- .../src/sofa/core/behavior/LinearSolver.h | 6 + .../CompressedRowSparseMatrixConstraint.h | 163 ++++++++++++------ ...essedRowSparseMatrixConstraintEigenUtils.h | 40 ++++- .../CompressedRowSparseMatrixGeneric.h | 3 + .../CompressedRowSparseMatrixMechanical.h | 7 +- .../test/CompressedRowSparseMatrix_test.cpp | 47 +++++ Sofa/framework/Type/CMakeLists.txt | 1 + .../sofa/type/trait/is_specialization_of.h | 81 +++++++++ 13 files changed, 408 insertions(+), 146 deletions(-) create mode 100644 Sofa/framework/Type/src/sofa/type/trait/is_specialization_of.h diff --git a/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/LinearSolverConstraintCorrection.h b/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/LinearSolverConstraintCorrection.h index 9c29139a60f..3704981a5e7 100644 --- a/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/LinearSolverConstraintCorrection.h +++ b/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/LinearSolverConstraintCorrection.h @@ -62,7 +62,7 @@ class LinearSolverConstraintCorrection : public sofa::core::behavior::Constraint protected: LinearSolverConstraintCorrection(sofa::core::behavior::MechanicalState *mm = nullptr); - virtual ~LinearSolverConstraintCorrection(); + ~LinearSolverConstraintCorrection() override; public: void init() override; @@ -110,13 +110,22 @@ class LinearSolverConstraintCorrection : public sofa::core::behavior::Constraint void getBlockDiagonalCompliance(linearalgebra::BaseMatrix* W, int begin, int end) override; protected: - linearalgebra::SparseMatrix J; ///< constraint matrix + DeprecatedAndRemoved J; ///< use m_constraintMatrix instead + + linearalgebra::SparseMatrix m_constraintJacobian; + + SOFA_ATTRIBUTE_DEPRECATED__FORCES_IN_LINEARSOLVERCONSTRAINTCORRECTION() linearalgebra::FullVector F; ///< forces computed from the constraints /** - * @brief Compute the compliance matrix + * @brief Convert the constraint matrix */ - virtual void computeJ(sofa::linearalgebra::BaseMatrix* W, const MatrixDeriv& j); + void convertConstraintMatrix(sofa::SignedIndex numberOfConstraints, const MatrixDeriv& inputConstraintMatrix); + + virtual void computeJ(sofa::linearalgebra::BaseMatrix* W, const MatrixDeriv& j) + { + convertConstraintMatrix(W->rowSize(), j); + } ////////////////////////// Inherited attributes //////////////////////////// diff --git a/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/LinearSolverConstraintCorrection.inl b/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/LinearSolverConstraintCorrection.inl index 2e228d321a8..4abdd39f127 100644 --- a/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/LinearSolverConstraintCorrection.inl +++ b/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/LinearSolverConstraintCorrection.inl @@ -32,6 +32,8 @@ #include #include +#include + namespace sofa::component::constraint::lagrangian::correction { @@ -84,9 +86,9 @@ void LinearSolverConstraintCorrection::init() } else { - if (l_linearSolver.get()->getTemplateName() == "GraphScattered") + if (l_linearSolver->getTemplateName() == "GraphScattered") { - msg_error() << "Can not use the solver " << l_linearSolver.get()->getName() << " because it is templated on GraphScatteredType"; + msg_error() << "Can not use the solver " << l_linearSolver->getName() << " because it is templated on GraphScatteredType"; sofa::core::objectmodel::BaseObject::d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid); return; } @@ -130,21 +132,24 @@ void LinearSolverConstraintCorrection::init() } template -void LinearSolverConstraintCorrection::computeJ(sofa::linearalgebra::BaseMatrix* W, const MatrixDeriv& c) +void LinearSolverConstraintCorrection::convertConstraintMatrix(const sofa::SignedIndex numberOfConstraints, const MatrixDeriv& inputConstraintMatrix) { - if(d_componentState.getValue() != ComponentState::Valid) + if (d_componentState.getValue() != ComponentState::Valid) + { return ; + } + + SCOPED_TIMER("convertConstraintMatrix"); const unsigned int numDOFs = mstate->getSize(); - const unsigned int N = Deriv::size(); - const unsigned int numDOFReals = numDOFs*N; - const unsigned int totalNumConstraints = W->rowSize(); + static constexpr unsigned int N = Deriv::size(); + const unsigned int numDOFReals = numDOFs * N; - J.resize(totalNumConstraints, numDOFReals); + m_constraintJacobian.resize(numberOfConstraints, numDOFReals); - MatrixDerivRowConstIterator rowItEnd = c.end(); + MatrixDerivRowConstIterator rowItEnd = inputConstraintMatrix.end(); - for (MatrixDerivRowConstIterator rowIt = c.begin(); rowIt != rowItEnd; ++rowIt) + for (MatrixDerivRowConstIterator rowIt = inputConstraintMatrix.begin(); rowIt != rowItEnd; ++rowIt) { const int cid = rowIt.index(); @@ -153,11 +158,11 @@ void LinearSolverConstraintCorrection::computeJ(sofa::linearalgebra: for (MatrixDerivColConstIterator colIt = rowIt.begin(); colIt != colItEnd; ++colIt) { const unsigned int dof = colIt.index(); - const Deriv n = colIt.val(); + const Deriv& n = colIt.val(); for (unsigned int r = 0; r < N; ++r) { - J.add(cid, dof * N + r, n[r]); + m_constraintJacobian.add(cid, dof * N + r, n[r]); } } } @@ -188,19 +193,22 @@ void LinearSolverConstraintCorrection::addComplianceInConstraintSpace break; } - // Compute J - this->computeJ(W, cparams->readJ(this->mstate)->getValue()); + { + helper::ReadAccessor inputConstraintMatrix ( *cparams->readJ(this->mstate) ); + const sofa::SignedIndex numberOfConstraints = W->rowSize(); + convertConstraintMatrix(numberOfConstraints, inputConstraintMatrix.ref()); + } // use the Linear solver to compute J*inv(M)*Jt, where M is the mechanical linear system matrix - l_linearSolver.get()->setSystemLHVector(sofa::core::MultiVecDerivId::null()); - l_linearSolver.get()->addJMInvJt(W, &J, factor); + l_linearSolver->setSystemLHVector(sofa::core::MultiVecDerivId::null()); + l_linearSolver->addJMInvJt(W, &m_constraintJacobian, factor); } template void LinearSolverConstraintCorrection::rebuildSystem(SReal massFactor, SReal forceFactor) { - l_linearSolver.get()->rebuildSystem(massFactor, forceFactor); + l_linearSolver->rebuildSystem(massFactor, forceFactor); } template @@ -225,7 +233,7 @@ void LinearSolverConstraintCorrection::getComplianceMatrix(linearalge Minv->resize(numDOFReals,numDOFReals); // use the Linear solver to compute J*inv(M)*Jt, where M is the mechanical linear system matrix - l_linearSolver.get()->addJMInvJt(Minv, &J, factor); + l_linearSolver->addJMInvJt(Minv, &J, factor); } template< class DataTypes > @@ -233,9 +241,9 @@ void LinearSolverConstraintCorrection< DataTypes >::computeMotionCorrection(cons { if (mstate && l_linearSolver.get()) { - l_linearSolver.get()->setSystemRHVector(f); - l_linearSolver.get()->setSystemLHVector(dx); - l_linearSolver.get()->solveSystem(); + l_linearSolver->setSystemRHVector(f); + l_linearSolver->setSystemLHVector(dx); + l_linearSolver->solveSystem(); } } @@ -359,9 +367,9 @@ void LinearSolverConstraintCorrection::applyContactForce(const linear } } } - l_linearSolver.get()->setSystemRHVector(forceID); - l_linearSolver.get()->setSystemLHVector(dxID); - l_linearSolver.get()->solveSystem(); + l_linearSolver->setSystemRHVector(forceID); + l_linearSolver->setSystemLHVector(dxID); + l_linearSolver->solveSystem(); //TODO: tell the solver not to recompute the matrix @@ -529,13 +537,13 @@ void LinearSolverConstraintCorrection::resetForUnbuiltResolution(SRea core::VecDerivId forceID(core::VecDerivId::V_FIRST_DYNAMIC_INDEX); core::VecDerivId dxID = core::VecDerivId::dx(); - l_linearSolver.get()->setSystemRHVector(forceID); - l_linearSolver.get()->setSystemLHVector(dxID); + l_linearSolver->setSystemRHVector(forceID); + l_linearSolver->setSystemLHVector(dxID); - systemMatrix_buf = l_linearSolver.get()->getSystemBaseMatrix(); - systemRHVector_buf = l_linearSolver.get()->getSystemRHBaseVector(); - systemLHVector_buf = l_linearSolver.get()->getSystemLHBaseVector(); + systemMatrix_buf = l_linearSolver->getSystemBaseMatrix(); + systemRHVector_buf = l_linearSolver->getSystemRHBaseVector(); + systemLHVector_buf = l_linearSolver->getSystemLHBaseVector(); systemLHVector_buf_fullvector = dynamic_cast*>(systemLHVector_buf); // Cast checking whether the LH vector is a FullVector to improve performances constexpr const auto derivDim = Deriv::total_size; @@ -550,7 +558,7 @@ void LinearSolverConstraintCorrection::resetForUnbuiltResolution(SRea } // Init the internal data of the solver for partial solving - l_linearSolver.get()->init_partial_solve(); + l_linearSolver->init_partial_solve(); ///////// new : precalcul des liste d'indice /////// @@ -687,14 +695,14 @@ void LinearSolverConstraintCorrection::getBlockDiagonalCompliance(lin const SReal factor = l_ODESolver.get()->getPositionIntegrationFactor(); //*m_ODESolver->getPositionIntegrationFactor(); // dt*dt const unsigned int numDOFs = mstate->getSize(); - const unsigned int N = Deriv::size(); - const unsigned int numDOFReals = numDOFs*N; + static constexpr unsigned int N = Deriv::size(); + const unsigned int numDOFReals = numDOFs * N; // Compute J const MatrixDeriv& constraints = mstate->read(core::ConstMatrixDerivId::constraintJacobian())->getValue(); - const unsigned int totalNumConstraints = W->rowSize(); + const sofa::SignedIndex totalNumConstraints = W->rowSize(); - J.resize(totalNumConstraints, numDOFReals); + m_constraintJacobian.resize(totalNumConstraints, numDOFReals); for (int i = begin; i <= end; i++) { @@ -715,7 +723,7 @@ void LinearSolverConstraintCorrection::getBlockDiagonalCompliance(lin const Deriv n = colIt.val(); for (unsigned int r = 0; r < N; ++r) - J.add(i, dof * N + r, n[r]); + m_constraintJacobian.add(i, dof * N + r, n[r]); if (debug!=0) { @@ -730,7 +738,7 @@ void LinearSolverConstraintCorrection::getBlockDiagonalCompliance(lin } // use the Linear solver to compute J*inv(M)*Jt, where M is the mechanical linear system matrix - l_linearSolver.get()->addJMInvJt(W, &J, factor); + l_linearSolver->addJMInvJt(W, &m_constraintJacobian, factor); // construction of Vec_I_list_dof : vector containing, for each constraint block, the list of dof concerned diff --git a/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/config.h.in b/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/config.h.in index b1c84604f66..de54500fa95 100644 --- a/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/config.h.in +++ b/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/config.h.in @@ -44,4 +44,13 @@ namespace sofa::component::constraint::lagrangian::correction SOFA_ATTRIBUTE_DEPRECATED( \ "v24.06", "v24.12", \ "Data renamed according to the guidelines") -#endif \ No newline at end of file +#endif + +#ifdef SOFA_BUILD_SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_CORRECTION +#define SOFA_ATTRIBUTE_DEPRECATED__FORCES_IN_LINEARSOLVERCONSTRAINTCORRECTION() +#else +#define SOFA_ATTRIBUTE_DEPRECATED__FORCES_IN_LINEARSOLVERCONSTRAINTCORRECTION() \ + SOFA_ATTRIBUTE_DEPRECATED( \ + "v24.12", "v25.06", \ + "Class member 'LinearSolverConstraintCorrection::F' is not used.") +#endif diff --git a/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/MatrixLinearSolver.h b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/MatrixLinearSolver.h index 79b7f86fa38..a70367e4e74 100644 --- a/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/MatrixLinearSolver.h +++ b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/MatrixLinearSolver.h @@ -36,6 +36,7 @@ #include #include #include +#include #if SOFA_CORE_ENABLE_CRSMULTIMATRIXACCESSOR #include @@ -86,25 +87,6 @@ class MatrixLinearSolverInternalData typedef sofa::linearalgebra::SparseMatrix JMatrixType; typedef linearalgebra::BaseMatrix ResMatrixType; - template - JMatrixType * copyJmatrix(linearalgebra::SparseMatrix * J) - { - J_local.clear(); - J_local.resize(J->rowSize(),J->colSize()); - - for (auto jit1 = J->begin(); jit1 != J->end(); jit1++) - { - auto l = jit1->first; - for (auto i1 = jit1->second.begin(); i1 != jit1->second.end(); i1++) - { - auto c = i1->first; - MReal val = i1->second; - J_local.set(l,c,val); - } - } - return &J_local; - } - void projectForceInConstraintSpace(linearalgebra::BaseVector* r,const linearalgebra::BaseVector* f) { for (typename linearalgebra::SparseMatrix::LineConstIterator jit = J_local.begin(), jitend = J_local.end(); jit != jitend; ++jit) { auto row = jit->first; @@ -121,35 +103,43 @@ class MatrixLinearSolverInternalData return &J_local; } + /** + * Returns a JMatrixType as a pointer to the input matrix (if the input + * matrix type is a JMatrixType), or a copy of the input matrix as a pointer + * to the class member @J_local. + */ JMatrixType * getLocalJ(linearalgebra::BaseMatrix * J) { if (JMatrixType * j = dynamic_cast(J)) { return j; } - else if (linearalgebra::SparseMatrix * j = dynamic_cast *>(J)) - { - return copyJmatrix(j); - } - else if (linearalgebra::SparseMatrix * j = dynamic_cast *>(J)) + + using OtherReal = std::conditional_t, float, double>; + + //in case the matrix J is not the same type as JMatrixType, it is + //copied in the local variable. There are 2 cases: + + //Case 1: J can be rebound: the copy is optimized + if (auto * j_d = dynamic_cast *>(J)) { - return copyJmatrix(j); + return convertMatrix(*j_d); } - else - { - J_local.clear(); - J_local.resize(J->rowSize(),J->colSize()); - for (typename JMatrixType::Index j=0; jrowSize(); j++) + //Case 2: generic case: slow copy + J_local.clear(); + J_local.resize(J->rowSize(),J->colSize()); + + using Index = typename JMatrixType::Index; + for (Index j = 0; j < J->rowSize(); ++j) + { + for (Index i = 0; i < J->colSize(); ++i) { - for (typename JMatrixType::Index i=0; icolSize(); i++) - { - J_local.set(j,i,J->element(j,i)); - } + J_local.set(j, i, J->element(j, i)); } - - return &J_local; } + + return &J_local; } ResMatrixType * getLocalRes(linearalgebra::BaseMatrix * R) @@ -161,6 +151,27 @@ class MatrixLinearSolverInternalData void addLocalRes(linearalgebra::BaseMatrix * /*R*/) {} +protected: + + template + JMatrixType * convertMatrix(const linearalgebra::SparseMatrix& inputMatrix) + { + J_local.clear(); + J_local.resize(inputMatrix.rowSize(), inputMatrix.colSize()); + + for (auto jit1 = inputMatrix.begin(); jit1 != inputMatrix.end(); ++jit1) + { + const auto l = jit1->first; + for (auto i1 = jit1->second.begin(); i1 != jit1->second.end(); ++i1) + { + const auto c = i1->first; + const MReal val = i1->second; + J_local.set(l, c, val); + } + } + return &J_local; + } + private : JMatrixType J_local; }; diff --git a/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/MatrixLinearSolver.inl b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/MatrixLinearSolver.inl index 39297dbb067..c3429b4b1ae 100644 --- a/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/MatrixLinearSolver.inl +++ b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/MatrixLinearSolver.inl @@ -528,10 +528,10 @@ bool MatrixLinearSolver::singleThreadAddJMInvJtLocal(Matrix* M, template bool MatrixLinearSolver::addMInvJtLocal(Matrix * /*M*/,ResMatrixType * result,const JMatrixType * J, SReal fact) { - for (typename JMatrixType::Index row=0; rowrowSize(); row++) + for (typename JMatrixType::Index row = 0; row < J->rowSize(); ++row) { // STEP 1 : put each line of matrix Jt in the right hand term of the system - for (typename JMatrixType::Index i=0; icolSize(); i++) + for (typename JMatrixType::Index i = 0; i < J->colSize(); ++i) { getSystemRHVector()->set(i, J->element(row, i)); // linearSystem.systemMatrix->rowSize() } @@ -540,7 +540,7 @@ bool MatrixLinearSolver::addMInvJtLocal(Matrix * /*M*/,ResMatrixT solveSystem(); // STEP 3 : project the result using matrix J - for (typename JMatrixType::Index i=0; icolSize(); i++) + for (typename JMatrixType::Index i = 0; i < J->colSize(); ++i) { result->add(row, i, getSystemRHVector()->element(i) * fact); } @@ -552,7 +552,10 @@ bool MatrixLinearSolver::addMInvJtLocal(Matrix * /*M*/,ResMatrixT template bool MatrixLinearSolver::addJMInvJt(linearalgebra::BaseMatrix* result, linearalgebra::BaseMatrix* J, SReal fact) { - if (J->rowSize()==0) return true; + if (J->rowSize() == 0) + { + return true; + } const JMatrixType * j_local = internalData.getLocalJ(J); ResMatrixType * res_local = internalData.getLocalRes(result); @@ -585,9 +588,9 @@ bool MatrixLinearSolver::buildComplianceMatrix(const sofa::core:: return true; } - executeVisitor(MechanicalGetConstraintJacobianVisitor(cparams,j_local)); + executeVisitor(MechanicalGetConstraintJacobianVisitor(cparams, j_local)); - return addJMInvJt(result,j_local,fact); + return addJMInvJt(result, j_local, fact); } template diff --git a/Sofa/framework/Core/src/sofa/core/behavior/LinearSolver.h b/Sofa/framework/Core/src/sofa/core/behavior/LinearSolver.h index 2ccd0c27dc0..b2403bfcf55 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/LinearSolver.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/LinearSolver.h @@ -130,6 +130,12 @@ class SOFA_CORE_API LinearSolver : public BaseLinearSolver /// Multiply the inverse of the system matrix by the transpose of the given matrix, and multiply the result with the given matrix J /// + /// This method can compute the Schur complement of the constrained system: + /// W = H A^{-1} H^T, where: + /// - A is the mechanical matrix + /// - H is the constraints matrix + /// - W is the compliance matrix projected in the constraints space + /// /// @param result the variable where the result will be added /// @param J the matrix J to use /// @param fact integrator parameter diff --git a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixConstraint.h b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixConstraint.h index 9f5fd8643d4..e9083dcb108 100644 --- a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixConstraint.h +++ b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixConstraint.h @@ -25,6 +25,8 @@ #include #include +#include + namespace sofa::linearalgebra { @@ -83,6 +85,12 @@ class CompressedRowSparseMatrixConstraint : public sofa::linearalgebra::Compress typedef typename CRSMatrix::Index KeyType; typedef typename CRSMatrix::IndexedBlock IndexedBlock; + static constexpr sofa::Index NL = CRSMatrix::NL; ///< Number of rows of a block + static constexpr sofa::Index NC = CRSMatrix::NC; ///< Number of columns of a block + + template + using rebind_to = CompressedRowSparseMatrixConstraint< TBlock2, Policy >; + public: CompressedRowSparseMatrixConstraint() : CRSMatrix() @@ -167,54 +175,72 @@ class CompressedRowSparseMatrixConstraint : public sofa::linearalgebra::Compress return m_internal == CompressedRowSparseMatrixConstraint::s_invalidIndex; } - void operator++() // prefix + ColConstIterator& operator++() // prefix { - m_internal++; + ++m_internal; + return *this; } - void operator++(int) // postfix + ColConstIterator operator++(difference_type) // postfix { - m_internal++; + ColConstIterator tmp = *this; + ++(*this); + return tmp; } - void operator--() // prefix + ColConstIterator& operator--() // prefix { - m_internal--; + --m_internal; + return *this; } - void operator--(int) // postfix + ColConstIterator operator--(difference_type) // postfix { - m_internal--; + ColConstIterator tmp = *this; + --(*this); + return tmp; } - void operator+=(int i) + ColConstIterator& operator+=(difference_type i) { m_internal += i; + return *this; } - void operator-=(int i) + ColConstIterator& operator-=(difference_type i) { m_internal -= i; + return *this; } - bool operator==(const ColConstIterator& it2) const + bool operator==(const ColConstIterator& other) const { - return (m_internal == it2.m_internal); + return (m_internal == other.m_internal); } - bool operator!=(const ColConstIterator& it2) const + bool operator!=(const ColConstIterator& other) const { - return (m_internal != it2.m_internal); + return m_internal != other.m_internal; } - bool operator<(const ColConstIterator& it2) const + bool operator<(const ColConstIterator& other) const { - return m_internal < it2.m_internal; + return m_internal < other.m_internal; } - bool operator>(const ColConstIterator& it2) const + bool operator>(const ColConstIterator& other) const { - return m_internal > it2.m_internal; + return other < *this; + } + + bool operator<=(const ColConstIterator& other) const + { + return !(other < *this); + } + + bool operator>=(const ColConstIterator& other) const + { + return !(*this < other); } private : @@ -249,10 +275,9 @@ class CompressedRowSparseMatrixConstraint : public sofa::linearalgebra::Compress , m_matrix(it2.m_matrix) {} - RowConstIterator() - {} + RowConstIterator() = default; - RowConstIterator& operator=(const RowConstIterator& other) + RowConstIterator& operator=(const RowConstIterator& other) { if (this != &other) { @@ -262,28 +287,28 @@ class CompressedRowSparseMatrixConstraint : public sofa::linearalgebra::Compress return *this; } - Index index() const + [[nodiscard]] Index index() const { return m_matrix->rowIndex[m_internal]; } - Index getInternal() const + [[nodiscard]] Index getInternal() const { return m_internal; } - bool isInvalid() const + [[nodiscard]] bool isInvalid() const { return m_internal == CompressedRowSparseMatrixConstraint::s_invalidIndex; } - ColConstIterator begin() const + [[nodiscard]] ColConstIterator begin() const { if (isInvalid()) { return ColConstIterator(m_internal, s_invalidIndex, m_matrix); } - Range r = m_matrix->getRowRange(m_internal); + const Range r = m_matrix->getRowRange(m_internal); return ColConstIterator(m_internal, r.begin(), m_matrix); } @@ -293,51 +318,59 @@ class CompressedRowSparseMatrixConstraint : public sofa::linearalgebra::Compress { return ColConstIterator(m_internal, s_invalidIndex, m_matrix); } - Range r = m_matrix->getRowRange(m_internal); + const Range r = m_matrix->getRowRange(m_internal); return ColConstIterator(m_internal, r.end(), m_matrix); } - RowType row() const + [[nodiscard]] RowType row() const { - Range r = m_matrix->getRowRange(m_internal); + const Range r = m_matrix->getRowRange(m_internal); return RowType(ColConstIterator(m_internal, r.begin(), m_matrix), ColConstIterator(m_internal, r.end(), m_matrix)); } - bool empty() const + [[nodiscard]] bool empty() const { - Range r = m_matrix->getRowRange(m_internal); + const Range r = m_matrix->getRowRange(m_internal); return r.empty(); } - void operator++() // prefix + RowConstIterator& operator++() // prefix { - m_internal++; + ++m_internal; + return *this; } - void operator++(int) // postfix + RowConstIterator operator++(difference_type) // postfix { - m_internal++; + RowConstIterator tmp = *this; + ++(*this); + return tmp; } - void operator--() // prefix + RowConstIterator& operator--() // prefix { - m_internal--; + --m_internal; + return *this; } - void operator--(int) // postfix + RowConstIterator operator--(difference_type) // postfix { - m_internal--; + RowConstIterator tmp = *this; + --(*this); + return tmp; } - void operator+=(int i) + RowConstIterator& operator+=(difference_type i) { m_internal += i; + return *this; } - void operator-=(int i) + RowConstIterator& operator-=(difference_type i) { m_internal -= i; + return *this; } int operator-(const RowConstIterator& it2) const @@ -345,38 +378,48 @@ class CompressedRowSparseMatrixConstraint : public sofa::linearalgebra::Compress return m_internal - it2.m_internal; } - RowConstIterator operator+(int i) const + RowConstIterator operator+(difference_type i) const { RowConstIterator res = *this; res += i; return res; } - RowConstIterator operator-(int i) const + RowConstIterator operator-(difference_type i) const { RowConstIterator res = *this; res -= i; return res; } - bool operator==(const RowConstIterator& it2) const + bool operator==(const RowConstIterator& other) const + { + return m_internal == other.m_internal; + } + + bool operator!=(const RowConstIterator& other) const { - return m_internal == it2.m_internal; + return !(m_internal == other.m_internal); } - bool operator!=(const RowConstIterator& it2) const + bool operator<(const RowConstIterator& other) const { - return !(m_internal == it2.m_internal); + return m_internal < other.m_internal; } - bool operator<(const RowConstIterator& it2) const + bool operator>(const RowConstIterator& other) const { - return m_internal < it2.m_internal; + return other < *this; } - bool operator>(const RowConstIterator& it2) const + bool operator<=(const RowConstIterator& other) const { - return m_internal > it2.m_internal; + return !(other < *this); + } + + bool operator>=(const RowConstIterator& other) const + { + return !(*this < other); } template @@ -581,10 +624,24 @@ class CompressedRowSparseMatrixConstraint : public sofa::linearalgebra::Compress { out << "Constraint ID : "; out << rowIt.index(); - for (ColConstIterator colIt = rowIt.begin(); colIt != rowIt.end(); ++colIt) + const auto colToString = [](const ColConstIterator& colIt) + { + std::stringstream ss; + ss << "dof ID : " << colIt.index() << " value : " << colIt.val(); + return ss.str(); + }; + + ColConstIterator colIt = rowIt.begin(); + const ColConstIterator colItEnd = rowIt.end(); + if (colIt != colItEnd) { - out << " dof ID : " << colIt.index() << " value : " << colIt.val() << " "; + out << " " << colToString(colIt++); + while(colIt != colItEnd) + { + out << " " << colToString(colIt++); + } } + out << "\n"; } diff --git a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixConstraintEigenUtils.h b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixConstraintEigenUtils.h index 88da4face8e..434d8758e37 100644 --- a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixConstraintEigenUtils.h +++ b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixConstraintEigenUtils.h @@ -40,15 +40,19 @@ struct CompressedRowSparseMatrixToEigenSparse template struct CompressedRowSparseMatrixToEigenSparseVec { - typedef typename TVec::Real Real; typedef CompressedRowSparseMatrixConstraint< TVec > TCompressedRowSparseMatrix; + typedef typename TCompressedRowSparseMatrix::Real Real; typedef Eigen::SparseMatrix EigenSparseMatrix; + EigenSparseMatrix operator() (const TCompressedRowSparseMatrix& mat, std::size_t size) const + { + SOFA_UNUSED(size); + return operator()(mat); + } - EigenSparseMatrix operator() (const TCompressedRowSparseMatrix& mat, std::size_t size) + EigenSparseMatrix operator() (const TCompressedRowSparseMatrix& mat) const { - const std::size_t eigenMatSize = size * TVec::size(); - EigenSparseMatrix eigenMat(eigenMatSize, eigenMatSize); + EigenSparseMatrix eigenMat(mat.nBlockRow * NL, mat.nBlockCol * NC); sofa::type::vector > triplets; @@ -57,25 +61,45 @@ struct CompressedRowSparseMatrixToEigenSparseVec for (auto col = row.begin(), colend = row.end(); col !=colend; ++col) { const TVec& vec = col.val(); - const int colIndex = col.index() * TVec::size(); + const int colIndex = col.index() * NC; for (std::size_t i = 0; i < TVec::size(); ++i) { - triplets.emplace_back(row.index(), colIndex + i, vec[i]); + if (row.index() < eigenMat.rows()) + { + const auto colInsertion = colIndex + i; + if (colInsertion < eigenMat.cols()) + { + triplets.emplace_back(row.index(), colInsertion, vec[i]); + } + else + { + msg_error("CompressedRowSparseMatrixToEigenSparseVec") << "Trying to insert in col " << colInsertion << " whereas matrix size is " << eigenMat.rows() << "x" << eigenMat.cols(); + } + } + else + { + msg_error("CompressedRowSparseMatrixToEigenSparseVec") << "Trying to insert in row " << row.index() << " whereas matrix size is " << eigenMat.rows() << "x" << eigenMat.cols(); + } } } } - eigenMat.setFromTriplets(triplets.begin(), triplets.end());; + eigenMat.setFromTriplets(triplets.begin(), triplets.end()); return eigenMat; } +private: + + static constexpr sofa::Index NL = TCompressedRowSparseMatrix::NL; ///< Number of rows of a block + static constexpr sofa::Index NC = TCompressedRowSparseMatrix::NC; ///< Number of columns of a block + }; template< int N, typename Real > -class CompressedRowSparseMatrixToEigenSparse< sofa::type::Vec > +struct CompressedRowSparseMatrixToEigenSparse< sofa::type::Vec > : public CompressedRowSparseMatrixToEigenSparseVec< sofa::type::Vec > { diff --git a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixGeneric.h b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixGeneric.h index 31fd33baf5c..c4ab41990e4 100644 --- a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixGeneric.h +++ b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixGeneric.h @@ -105,6 +105,9 @@ class CompressedRowSparseMatrixGeneric : public TPolicy typedef typename traits::BlockTranspose BlockTranspose; typedef typename traits::Real Real; + template + using rebind_to = CompressedRowSparseMatrixGeneric< TBlock2, Policy >; + typedef Matrix Expr; enum { category = MATRIX_SPARSE }; enum { operand = 1 }; diff --git a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixMechanical.h b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixMechanical.h index 2294d9cf5d2..4083f078909 100644 --- a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixMechanical.h +++ b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixMechanical.h @@ -71,13 +71,16 @@ class CompressedRowSparseMatrixMechanical final // final is used to allow the co typedef typename CRSMatrix::IndexedBlock IndexedBlock; typedef typename CRSMatrix::VecIndexedBlock VecIndexedBlock; + template + using rebind_to = CompressedRowSparseMatrixMechanical< TBlock2, Policy >; + typedef Matrix Expr; typedef CompressedRowSparseMatrixMechanical matrix_type; enum { category = MATRIX_SPARSE }; enum { operand = 1 }; - enum { NL = CRSMatrix::NL }; ///< Number of rows of a block - enum { NC = CRSMatrix::NC }; ///< Number of columns of a block + static constexpr sofa::Index NL = traits::NL; ///< Number of rows of a block + static constexpr sofa::Index NC = traits::NC; ///< Number of columns of a block /// Size Index nRow,nCol; ///< Mathematical size of the matrix, in scalars diff --git a/Sofa/framework/LinearAlgebra/test/CompressedRowSparseMatrix_test.cpp b/Sofa/framework/LinearAlgebra/test/CompressedRowSparseMatrix_test.cpp index 14afd273729..eafbe4ce636 100644 --- a/Sofa/framework/LinearAlgebra/test/CompressedRowSparseMatrix_test.cpp +++ b/Sofa/framework/LinearAlgebra/test/CompressedRowSparseMatrix_test.cpp @@ -89,6 +89,34 @@ void generateMatrix(sofa::linearalgebra::CompressedRowSparseMatrix& matr matrix.compress(); } +template +void generateMatrix(sofa::linearalgebra::CompressedRowSparseMatrixConstraint& matrix, + sofa::SignedIndex nbRows, sofa::SignedIndex nbCols, + typename sofa::linearalgebra::CompressedRowSparseMatrixConstraint::Real sparsity, + long seed) +{ + using Matrix = sofa::linearalgebra::CompressedRowSparseMatrixConstraint; + using Real = typename Matrix::Real; + const auto nbNonZero = static_cast(sparsity * static_cast(nbRows*nbCols)); + + sofa::testing::LinearCongruentialRandomGenerator lcg(seed); + + matrix.resizeBlock(nbRows / Matrix::NL, nbCols / Matrix::NC); + + for (sofa::SignedIndex i = 0; i < nbNonZero; ++i) + { + const auto value = lcg.generateInUnitRange(); + const auto row = static_cast(lcg.generateInRange(0., nbRows)); + const auto col = static_cast(lcg.generateInRange(0., nbCols)); + + auto line = matrix.writeLine(row); + TBlock block; + block[col % Matrix::NC] = value; + line.addCol(col, block); + } + matrix.compress(); +} + /** * Two matrices A and B are generated randomly as CompressedRowSparseMatrix. * The test checks the consistency of the results of A^T * B, computed using 3 methods: @@ -381,3 +409,22 @@ TEST(CompressedRowSparseMatrixConstraint, emptyMatrixGetRowRange) checkIterator(begin); checkIterator(end); } + +TEST(CompressedRowSparseMatrixConstraint, ostream) +{ + sofa::linearalgebra::CompressedRowSparseMatrixConstraint A; + + generateMatrix(A, 5, 15, 0.1, 7); + + std::stringstream ss; + ss << A; + + static const std::string expectedOutput = +R"(Constraint ID : 0 dof ID : 1 value : 0 0.360985 0 dof ID : 12 value : 0.926981 0 0 +Constraint ID : 2 dof ID : 9 value : 0.451858 0 0 +Constraint ID : 3 dof ID : 6 value : 0.777417 0 0 +Constraint ID : 4 dof ID : 5 value : 0 0 0.474108 dof ID : 7 value : 0 0.983937 0 dof ID : 9 value : 0.238781 0 0 +)"; + + EXPECT_EQ(ss.str(), expectedOutput); +} diff --git a/Sofa/framework/Type/CMakeLists.txt b/Sofa/framework/Type/CMakeLists.txt index 30764b338cb..0ac5894d541 100644 --- a/Sofa/framework/Type/CMakeLists.txt +++ b/Sofa/framework/Type/CMakeLists.txt @@ -36,6 +36,7 @@ set(HEADER_FILES ${SOFATYPESRC_ROOT}/stable_vector.h ${SOFATYPESRC_ROOT}/trait/Rebind.h ${SOFATYPESRC_ROOT}/trait/is_container.h + ${SOFATYPESRC_ROOT}/trait/is_specialization_of.h ${SOFATYPESRC_ROOT}/trait/is_vector.h ${SOFATYPESRC_ROOT}/vector.h ${SOFATYPESRC_ROOT}/vector_Integral.h diff --git a/Sofa/framework/Type/src/sofa/type/trait/is_specialization_of.h b/Sofa/framework/Type/src/sofa/type/trait/is_specialization_of.h new file mode 100644 index 00000000000..69a8a797b98 --- /dev/null +++ b/Sofa/framework/Type/src/sofa/type/trait/is_specialization_of.h @@ -0,0 +1,81 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture * +* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once +#include + +namespace sofa::type::trait +{ +/** + * @brief Trait to check if a type `T` is a specialization of a given template class `Template`. + * + * The `is_specialization_of` trait is a compile-time check to determine if a type `T` + * is a specialization of a particular template class `Template`. This trait works with + * template classes that accept any number of template parameters. + * + * Example usage: + * @code + * template + * class Foo {}; + * + * template + * class Bar {}; + * + * class Baz {}; + * + * static_assert(is_specialization_of, Foo>::value, "Foo is a Foo!"); + * static_assert(is_specialization_of, Bar>::value, "Bar is a Bar!"); + * static_assert(!is_specialization_of::value, "int is not a Foo specialization."); + * static_assert(!is_specialization_of::value, "Baz is not a Bar specialization."); + * @endcode + * + * @tparam T The type to be checked. This is the type that you want to determine whether it is a specialization of `Template`. + * @tparam Template The template class to check against. This can be any template class that accepts one or more template parameters. + */ +template class Template> +struct is_specialization_of : std::false_type {}; + +/** + * @brief Partial specialization for the case where `T` is an instance of `Template`. + * + * This specialization checks if `T` matches the form `Template`, meaning `T` is a specialization + * of the template class `Template` with specific template parameters `Args...`. + * + * @tparam Template The template class that `T` is expected to be an instance of. + * @tparam Args The actual template parameters used in the instantiation of `Template`. + */ +template