From a6632a14e2161474eec59ebba5759bc80fb5702b Mon Sep 17 00:00:00 2001 From: Lucas Burel Date: Mon, 22 Dec 2025 16:39:09 +0100 Subject: [PATCH 01/20] cleaning add functions --- .../sofa/core/objectmodel/BaseComponent.cpp | 2 +- .../Core/src/sofa/core/objectmodel/BaseLink.h | 2 + .../Core/src/sofa/core/objectmodel/Link.h | 52 ++++++++++--------- .../Core/src/sofa/simulation/Node.cpp | 4 +- 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp index 827aa9659bb..fb2b16f2d8f 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp @@ -225,7 +225,7 @@ void BaseComponent::addSlave(BaseComponent::SPtr s) if (previous == this) return; if (previous) previous->l_slaves.remove(s); - l_slaves.add(s); + l_slaves.add(s.get()); if (previous) this->getContext()->notifyMoveSlave(previous.get(), this, s.get()); else diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseLink.h b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseLink.h index d5c71fc6d57..cad9af993e2 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseLink.h +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseLink.h @@ -171,6 +171,7 @@ class SOFA_CORE_API BaseLink /// Add a new target to the link. bool add(Base* baseptr, const std::string& path) { return _doAdd_(baseptr, path); } + bool add(Base* baseptr) { return _doAdd_(baseptr); } /// Change the link's target at the provided index. bool set(Base* baseptr, size_t index=0) { return _doSet_(baseptr, index); } @@ -181,6 +182,7 @@ class SOFA_CORE_API BaseLink virtual void _doSetOwner_(Base* owner) = 0; virtual Base* _doGet_(const size_t=0) const = 0; virtual bool _doAdd_(Base* target, const std::string&) = 0; + virtual bool _doAdd_(Base*) = 0; virtual void _doClear_() = 0; virtual std::string _doGetLinkedPath_(const size_t=0) const = 0; diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/Link.h b/Sofa/framework/Core/src/sofa/core/objectmodel/Link.h index b1519d4bc89..e5821c8e254 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/Link.h +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/Link.h @@ -377,27 +377,6 @@ class TLink : public BaseLink return true; } - bool add(DestPtr v) - { - if (!v) - return false; - const std::size_t index = TraitsContainer::add(m_value,v); - updateCounter(); - added(v, index); - return true; - } - - bool add(DestPtr v, const std::string& path) - { - if (!v && path.empty()) - return false; - std::size_t index = TraitsContainer::add(m_value,v); - TraitsValueType::setPath(m_value[index],path); - updateCounter(); - added(v, index); - return true; - } - bool addPath(const std::string& path) { if (path.empty()) @@ -503,7 +482,32 @@ class TLink : public BaseLink } /// TLink:adding accepts nullptr (for a not yet resolved link). - return TLink::add(destptr, path); + std::size_t index = TraitsContainer::add(m_value, destptr); + TraitsValueType::setPath(m_value[index], path); + updateCounter(); + added(destptr, index); + return true; + } + + bool _doAdd_(Base* baseptr) override + { + /// If the pointer is null and the path empty we do nothing + if(!baseptr) + return false; + + /// Downcast the pointer to a compatible type and + /// If the types are not compatible with the Link we returns false + auto destptr = castTo(baseptr); + if(!destptr) + { + return false; + } + + /// TLink:adding accepts nullptr (for a not yet resolved link). + const std::size_t index = TraitsContainer::add(m_value, destptr); + updateCounter(); + added(destptr, index); + return true;; } /// Returns false on type mismatch @@ -577,7 +581,7 @@ class MultiLink : public TLink& init, DestPtr val) : Inherit(init), m_validator(nullptr) { - if (val) this->add(val); + if (val) this->_doAdd_(sofa::core::castToBase(TraitsDestPtr::get(val))); } virtual ~MultiLink() @@ -654,7 +658,7 @@ class SingleLink : public TLink& init, DestPtr val) : Inherit(init), m_validator(nullptr) { - if (val) this->add(val); + if (val) this->_doAdd_(sofa::core::castToBase(TraitsDestPtr::get(val))); } virtual ~SingleLink() diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp index bcc0dd329fa..97bc1e887c6 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp @@ -628,7 +628,7 @@ bool Node::doAddObject(sofa::core::objectmodel::BaseComponent::SPtr sobj, sofa:: { this->setObjectContext(sobj); if(insertionLocation == sofa::core::objectmodel::TypeOfInsertion::AtEnd) - object.add(sobj); + object.add(sobj.get()); else object.addBegin(sobj); @@ -1175,7 +1175,7 @@ void Node::doAddChild(BaseNode::SPtr node) { const Node::SPtr dagnode = sofa::core::objectmodel::SPtr_static_cast(node); setDirtyDescendancy(); - child.add(dagnode); + child.add(dagnode.get()); dagnode->l_parents.add(this); dagnode->l_parents.updateLinks(); // to fix load-time unresolved links } From 9ded89158bf9f013c22ce67338564e87a8be69e9 Mon Sep 17 00:00:00 2001 From: Lucas-TJ Date: Thu, 18 Jun 2026 09:10:14 +0200 Subject: [PATCH 02/20] add unit test --- .../objectmodel/BaseLink_simutest.cpp | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp b/Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp index a895d4bf6c4..802a27b962d 100644 --- a/Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp +++ b/Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp @@ -30,7 +30,7 @@ using sofa::testing::BaseSimulationTest ; using sofa::simulation::Node ; #include -using sofa::core::objectmodel::BaseObject; +using sofa::core::objectmodel::BaseComponent; #include using sofa::core::PathResolver; @@ -41,6 +41,8 @@ using sofa::defaulttype::Rigid3Types; #include using sofa::defaulttype::Vec3Types; +using sofa::core::objectmodel::BaseLink; + namespace { @@ -79,6 +81,41 @@ class BaseLink_test : public BaseSimulationTest, } }; +class FakeComponent : public BaseComponent +{ +public: + SOFA_CLASS(FakeComponent, BaseComponent); + sofa::MultiLink l_target; + + FakeComponent() + : l_target(initLink("target","link for test")) + {} + +}; + +TEST_F(BaseLink_test, add) +{ + FakeComponent Component1; + Component1.setName("Component1"); + FakeComponent Component2; + Component2.setName("Component2"); + FakeComponent Component3; + Component3.setName("Component3"); + + FakeComponent* ptr; + ptr = &Component2; + + EXPECT_EQ(Component1.l_target.getValueString(), ""); + + Component1.l_target.add(ptr); + EXPECT_EQ(Component1.l_target.getValueString(), "@Component2"); + + ptr = &Component3; + + Component1.l_target.add(ptr); + EXPECT_EQ(Component1.l_target.getValueString(), "@Component2 @Component3"); +} + //////////////////////// Testing valid path ////////////////////////////////////// class MultiLink_simutest : public BaseLink_test {}; From 9ada96283e55c460e27f544378073bc3c0866452 Mon Sep 17 00:00:00 2001 From: Hugo Date: Tue, 28 Jul 2026 08:54:46 +0200 Subject: [PATCH 03/20] [Project] Start dev phase v26.12 (#6195) * [v26.06] Add changelog (#6180) Add changelog for v26.06 * Bump version to v26.12.99 * forgotten build action --------- Co-authored-by: Paul Baksic <30337881+bakpaul@users.noreply.github.com> --- .../workflows/CI_trigger_build_and_tests.yml | 2 +- CHANGELOG.md | 267 ++++++++++++++++++ CMakeLists.txt | 2 +- package.nix | 2 +- pixi.toml | 2 +- 5 files changed, 271 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CI_trigger_build_and_tests.yml b/.github/workflows/CI_trigger_build_and_tests.yml index 7a5c0c2da73..da2efb038be 100644 --- a/.github/workflows/CI_trigger_build_and_tests.yml +++ b/.github/workflows/CI_trigger_build_and_tests.yml @@ -53,7 +53,7 @@ on: push: branches: - 'master' - - 'v25.12' + - 'v26.06' # =============================================================== # =============================================================== diff --git a/CHANGELOG.md b/CHANGELOG.md index 3856763a6ba..5ff408c2bda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,273 @@ # SOFA Changelog + +## [v26.06.00]( https://github.com/sofa-framework/sofa/tree/v26.06.00 ) + +[Full log]( https://github.com/sofa-framework/sofa/compare/v25.12..v26.06 ) + +### Highlighted contributions + +- [Pixi][CI] Add pixi support [#5252](https://github.com/sofa-framework/sofa/pull/5252) +- [Visual] Introduce generic visualization of mesh [#5782](https://github.com/sofa-framework/sofa/pull/5782) +- [Collision] Introduce multi-staged collision pipeline [#5841](https://github.com/sofa-framework/sofa/pull/5841) +- [CMake] Remove CGALPlugin from supported plugins [#5869](https://github.com/sofa-framework/sofa/pull/5869) +- [FEM.Elastic] Introduce generic element-agnostic elastic FEM force field [#5882](https://github.com/sofa-framework/sofa/pull/5882) +- [SofaCUDA] SofaCUDA is now a meta-plugin of two plugins: SofaCUDA.Core and SofaCUDA.Component [#5973](https://github.com/sofa-framework/sofa/pull/5973) +- [Topology.Mapping] Introduce component `Hexa2PrismTopologicalMapping` [#5984](https://github.com/sofa-framework/sofa/pull/5984) +- [ODESolver.Forward] Support mapped masses in EulerExplicitSolver [#6000](https://github.com/sofa-framework/sofa/pull/6000) +- [Mass] Introduce element-agnostic FEM mass [#6061](https://github.com/sofa-framework/sofa/pull/6061) +- [FEM] Add support for elasticity of prisms [#6062](https://github.com/sofa-framework/sofa/pull/6062) +- [SofaCUDA] ElementFEMForceField: Generic CUDA implementation [#6071](https://github.com/sofa-framework/sofa/pull/6071) +- [CMake] Remove Qt from all configurations [#6072](https://github.com/sofa-framework/sofa/pull/6072) +- [Simulation] Mapping graph visitors [#6087](https://github.com/sofa-framework/sofa/pull/6087) +- [FEM] Add support of pyramids elements [#6132](https://github.com/sofa-framework/sofa/pull/6132) + + +### Breaking + +- [Testing] Modularize functions in ForceFieldTestCreation and add test of buildStiffnessMatrix [#5918](https://github.com/sofa-framework/sofa/pull/5918) +- [Core] Rename BaseObject to BaseComponent [#5934](https://github.com/sofa-framework/sofa/pull/5934) +- [SofaCUDA] Reorganize files and components [#5967](https://github.com/sofa-framework/sofa/pull/5967) +- [SofaCUDA] move Qt-related code [#5968](https://github.com/sofa-framework/sofa/pull/5968) +- [SofaCUDA] GUI: create extension to use Sofa.GUI with SofaCUDA [#5971](https://github.com/sofa-framework/sofa/pull/5971) +- [Helper] Add `getName` method to all `MessageHandler` implementations and update related tests [#5979](https://github.com/sofa-framework/sofa/pull/5979) +- [Helper] ScopedAdvancedTimer: add a compile-time check on string argument in macros [#6036](https://github.com/sofa-framework/sofa/pull/6036) +- [Sofa.Helper] Fix a few warnings [#6037](https://github.com/sofa-framework/sofa/pull/6037) +- [Visual] VisualModelImpl: clean apply transformations [#6136](https://github.com/sofa-framework/sofa/pull/6136) +- [Core] Move SceneCheckerVisitor out of the SceneChecking project into the core [#6150](https://github.com/sofa-framework/sofa/pull/6150) + + +### Improvements + +- [FileSystem] Add openFileWithDefaultApplication method [#5798](https://github.com/sofa-framework/sofa/pull/5798) +- [Type] Add optional support for mimalloc [#5814](https://github.com/sofa-framework/sofa/pull/5814) +- [IO] Update MeshVTKLoader so that it can read polydata description of meshes [#5821](https://github.com/sofa-framework/sofa/pull/5821) +- [SceneChecking] Collision: new checker on the presence of a pipeline and models [#5839](https://github.com/sofa-framework/sofa/pull/5839) +- [Core] Support generic drawing of edges and quads [#5852](https://github.com/sofa-framework/sofa/pull/5852) +- [Helper] Add default constructor for iota_iterator [#5853](https://github.com/sofa-framework/sofa/pull/5853) +- [helper/system] FileRepository: adds findAllFilesInRepository method [#5857](https://github.com/sofa-framework/sofa/pull/5857) +- [Lagrangian.Solver] UnbuiltConstraintSolver: Fix resetForUnbuiltResolution (constraint re-ordering) [#5871](https://github.com/sofa-framework/sofa/pull/5871) +- [Type] Introduce function to compute the determinant of any square matrix [#5877](https://github.com/sofa-framework/sofa/pull/5877) +- [Config] CMake: Shallow clone when using the git-fetch mechanism [#5889](https://github.com/sofa-framework/sofa/pull/5889) +- [Config] Introduce CMake function to treat compilation warnings as errors [#5914](https://github.com/sofa-framework/sofa/pull/5914) +- [Mass] Add unit test framework and tests for Mass components [#5920](https://github.com/sofa-framework/sofa/pull/5920) +- [Type] Mat: better cache locality for operator*(Mat) [#5921](https://github.com/sofa-framework/sofa/pull/5921) +- [Collision] CompositeCollisionPipeline: add bwdInit for subcollision pipelines [#5942](https://github.com/sofa-framework/sofa/pull/5942) +- [Topology] Add support for adding prism and pyramid elements in MeshTopology [#5946](https://github.com/sofa-framework/sofa/pull/5946) +- [Topology.Mapping] Refactor Hexa2TetraTopologicalMapping to support MeshTopology output [#5947](https://github.com/sofa-framework/sofa/pull/5947) +- [Topology.Mapping] Support MeshTopology as output in Tetra2TriangleTopologicalMapping [#5948](https://github.com/sofa-framework/sofa/pull/5948) +- [Constraint] Add PCR direct constraint solver [#5958](https://github.com/sofa-framework/sofa/pull/5958) +- [Mass] Add missing Vec2 template to DiagonalMass in the ObjectFactory [#5960](https://github.com/sofa-framework/sofa/pull/5960) +- [LinearSystem] Update the "M, B, K factors" of the linear system when necessary [#5963](https://github.com/sofa-framework/sofa/pull/5963) +- [Project] Update rules for pull-requests regarding AI [#5975](https://github.com/sofa-framework/sofa/pull/5975) +- [example] Add a demo scene showcasing mesh-induced anisotropy effects [#5982](https://github.com/sofa-framework/sofa/pull/5982) +- [examples] Mitigate mesh-induced anisotropy in cantilever beam simulations [#5983](https://github.com/sofa-framework/sofa/pull/5983) +- [Visual] Compute bounding box in VisualMesh [#5985](https://github.com/sofa-framework/sofa/pull/5985) +- [Simulation] Move MappingGraph class from Sofa.Component.LinearSystem to Sofa.Simulation.Core [#5991](https://github.com/sofa-framework/sofa/pull/5991) +- [Visual] add support of 2d and 1d for TrailRenderer [#6001](https://github.com/sofa-framework/sofa/pull/6001) +- [Visual] Consider sphere boundaries when computing bbox in VisualPointCloud [#6002](https://github.com/sofa-framework/sofa/pull/6002) +- [Type] Vec: Short-circuit toVecN for same-type conversions [#6022](https://github.com/sofa-framework/sofa/pull/6022) +- [Core] Introduce WriteAccessor move constructor [#6032](https://github.com/sofa-framework/sofa/pull/6032) +- [Mapping.Linear] Add applyJT for matrices for IdentityMultiMapping [#6033](https://github.com/sofa-framework/sofa/pull/6033) +- [Simulation] Update advice to use RequiredPlugin using the Data pluginName [#6040](https://github.com/sofa-framework/sofa/pull/6040) +- [SceneChecking] CMake option to treat warnings as errors in SceneChecking [#6042](https://github.com/sofa-framework/sofa/pull/6042) +- [LinearAlgebra] Fixed element for lower triangular part of BTDMatrix [#6050](https://github.com/sofa-framework/sofa/pull/6050) +- [visual] VisualModelImpl: add resetMaterial variable [#6057](https://github.com/sofa-framework/sofa/pull/6057) +- [Mapping] SkinningMapping: compute weights from position [#6080](https://github.com/sofa-framework/sofa/pull/6080) +- [Visual] draw more lines for LineAxis and VisualGrid [#6090](https://github.com/sofa-framework/sofa/pull/6090) +- [Sofa.GL] DrawToolGL: Auto-scale indices display based on camera distance [#6092](https://github.com/sofa-framework/sofa/pull/6092) +- [Sofa.GL] DrawToolGL: improve indices text rendering quality [#6093](https://github.com/sofa-framework/sofa/pull/6093) +- [Mass] Support prisms in mass [#6110](https://github.com/sofa-framework/sofa/pull/6110) +- [FEM.Elastic] Remove complex unproductive stiffness matrix data structure [#6133](https://github.com/sofa-framework/sofa/pull/6133) +- [Helper] FileRepository::findFile(): use the list of paths when given a dotted path [#6135](https://github.com/sofa-framework/sofa/pull/6135) +- [FEM.Elastic] introduce virtual method called before force derivatives [#6139](https://github.com/sofa-framework/sofa/pull/6139) +- [Helper] Refactor SimpleTimer [#6140](https://github.com/sofa-framework/sofa/pull/6140) +- [Topology][Mapping] Add swapping of triangle diagonals when mapping Quads-2-Triangles as an option [#6143](https://github.com/sofa-framework/sofa/pull/6143) +- [examples] Use CCD for example scene [#6159](https://github.com/sofa-framework/sofa/pull/6159) + + +### Bug Fixes + +- [CollisionOBBCapsule] MeshIntTool: remove useless assignments [#5840](https://github.com/sofa-framework/sofa/pull/5840) +- [Container.Grid] SparseGridTopology: Fix dangling reference [#5844](https://github.com/sofa-framework/sofa/pull/5844) +- [Geomagic] Fix crash when drawDevice is set to true and add option to log haptic thread speed [#5850](https://github.com/sofa-framework/sofa/pull/5850) +- [Core] DrawMesh: Fix assertion [#5860](https://github.com/sofa-framework/sofa/pull/5860) +- [Helper] Fix compilation [#5866](https://github.com/sofa-framework/sofa/pull/5866) +- [Helper] FileSystem: (really) fix compilation on macOS [#5867](https://github.com/sofa-framework/sofa/pull/5867) +- [CMake] Remove SofaViscoElastic from supported plugins [#5868](https://github.com/sofa-framework/sofa/pull/5868) +- [Tools] Fix windows postinstall [#5879](https://github.com/sofa-framework/sofa/pull/5879) +- [CMake] Fix cmake error on already defined metis target [#5880](https://github.com/sofa-framework/sofa/pull/5880) +- [Core] BaseObject: remove components from the slave list [#5891](https://github.com/sofa-framework/sofa/pull/5891) +- [All] Security: malloc checks [#5900](https://github.com/sofa-framework/sofa/pull/5900) +- [All] Security: fix overflows [#5901](https://github.com/sofa-framework/sofa/pull/5901) +- [All] Security: unsafe string operations [#5902](https://github.com/sofa-framework/sofa/pull/5902) +- [All] Security : nullptr checks [#5903](https://github.com/sofa-framework/sofa/pull/5903) +- [All] Security : memory management, destructors and al [#5904](https://github.com/sofa-framework/sofa/pull/5904) +- [Type] Mat: add unit tests and fix isDiagonal() [#5909](https://github.com/sofa-framework/sofa/pull/5909) +- [CI] CMake & Nix: add tight_inclusion [#5916](https://github.com/sofa-framework/sofa/pull/5916) +- [Helper] Match ubuntu implementation of create dir for Windows [#5924](https://github.com/sofa-framework/sofa/pull/5924) +- [Mass] Fix kinetic energy in MeshMatrixMass when lumped [#5925](https://github.com/sofa-framework/sofa/pull/5925) +- [Type] Default constructor zero-initialized [#5938](https://github.com/sofa-framework/sofa/pull/5938) +- [Mapping] Fix rigid mapping init [#5943](https://github.com/sofa-framework/sofa/pull/5943) +- [HyperElastic] Enable the SelfAdjointEigenSolver in Ogden [#5953](https://github.com/sofa-framework/sofa/pull/5953) +- [All] Clean task scheduler usage [#5957](https://github.com/sofa-framework/sofa/pull/5957) +- [Collision] CompositeCollisionPipeline: propagate reset calls on the sub collision pipelines [#5959](https://github.com/sofa-framework/sofa/pull/5959) +- [SofaCUDA] Call register functions in the plugin initialization function [#5961](https://github.com/sofa-framework/sofa/pull/5961) +- [SofaCUDA] Cleanup cmake file and remove obsolete options [#5965](https://github.com/sofa-framework/sofa/pull/5965) +- [SofaDistanceGrid] Use the correct flag for miniflowvr activation [#5966](https://github.com/sofa-framework/sofa/pull/5966) +- [SofaCUDA] FixedProjectiveConstraint: Fix for double templates [#5974](https://github.com/sofa-framework/sofa/pull/5974) +- [Visual] Scene center and radius are not longer cached [#5976](https://github.com/sofa-framework/sofa/pull/5976) +- [Helper] Replace console message handler instantiation with singleton usage [#5978](https://github.com/sofa-framework/sofa/pull/5978) +- [Type] Quat : Add more unit tests and two bugfixes [#5980](https://github.com/sofa-framework/sofa/pull/5980) +- [Geometry] Bugfixes and add unit tests [#5987](https://github.com/sofa-framework/sofa/pull/5987) +- [Defaulttype] RigidTypes: Fix various bugs in RigidCoord/RigidMass and add unit tests [#5988](https://github.com/sofa-framework/sofa/pull/5988) +- [LinearAlgebra] Various bugfixes and add unit tests [#5989](https://github.com/sofa-framework/sofa/pull/5989) +- [Constraint.Projective] Fix warning in DirectionProjectiveConstraint [#5992](https://github.com/sofa-framework/sofa/pull/5992) +- [CMake] Add missing install compat headers for Sofa.Core [#5994](https://github.com/sofa-framework/sofa/pull/5994) +- [LinearSystem] Remove stale cached components [#5998](https://github.com/sofa-framework/sofa/pull/5998) +- [Core] Fix warning unreachable code in BaseClassNameHelper.h [#6006](https://github.com/sofa-framework/sofa/pull/6006) +- [CMake] Fix TinyXML2 cmake module for windeppack [#6015](https://github.com/sofa-framework/sofa/pull/6015) +- [CMake] Add missing install compat headers for Sofa.Component.LinearSystem [#6023](https://github.com/sofa-framework/sofa/pull/6023) +- [CMake] Add path to the windeppack to help cmake find it [#6024](https://github.com/sofa-framework/sofa/pull/6024) +- [Core] Fix MeshLoader parse method when calling super method [#6029](https://github.com/sofa-framework/sofa/pull/6029) +- [Tracy] Fix compilation when enabling Tracy [#6031](https://github.com/sofa-framework/sofa/pull/6031) +- [Type] vector: Fix warning(error) about implicit cast of long into int [#6035](https://github.com/sofa-framework/sofa/pull/6035) +- [Type] FullySymmetric4Tensor: fix compilation error on macos/xcode 26 [#6058](https://github.com/sofa-framework/sofa/pull/6058) +- [FEM.Elastic] FEMForcefield: getExecutionPolicy did not use the provided data [#6066](https://github.com/sofa-framework/sofa/pull/6066) +- [LinearSystem] ConstantSparsityPatternSystem: change key type to support bigger meshes [#6067](https://github.com/sofa-framework/sofa/pull/6067) +- [FEM.Elastic] Fix includes [#6070](https://github.com/sofa-framework/sofa/pull/6070) +- [Visual] Fix crash when texturename is not leading to a valid texture file [#6075](https://github.com/sofa-framework/sofa/pull/6075) +- [FEM.Elastic] FEMForcefield: implement computeBBox [#6078](https://github.com/sofa-framework/sofa/pull/6078) +- [LinearSystem] Check if state is mapped to contribute to the global vector [#6081](https://github.com/sofa-framework/sofa/pull/6081) +- [Core] Fix: avoid extra ';' in macro causing massive warnings [#6102](https://github.com/sofa-framework/sofa/pull/6102) +- [All] Fix float compilation [#6115](https://github.com/sofa-framework/sofa/pull/6115) +- [Simulation.Core] WorkerThread: fix use-after-free crash with ultra-short Task [#6116](https://github.com/sofa-framework/sofa/pull/6116) +- [SofaCarving] Clean the handleEvent method to have less conditions and also remove some Data [#6118](https://github.com/sofa-framework/sofa/pull/6118) +- [defaulttype] Fix VecN type when compiling with float [#6120](https://github.com/sofa-framework/sofa/pull/6120) +- [Simulation.Core] WorkerThread: fix memory leak/resource retention [#6125](https://github.com/sofa-framework/sofa/pull/6125) +- [FEM.Elastic] Expose potential energy getter in FEM force fields [#6131](https://github.com/sofa-framework/sofa/pull/6131) +- [type] Add missing TypeTrait.h in CMakeList [#6134](https://github.com/sofa-framework/sofa/pull/6134) +- [GUI] Factorize camera related code to use in child class [#6141](https://github.com/sofa-framework/sofa/pull/6141) +- [Simulation.Core] Fix BoundingBox initialization and updates [#6146](https://github.com/sofa-framework/sofa/pull/6146) +- [XML] Error handling when parsing [#6149](https://github.com/sofa-framework/sofa/pull/6149) +- [Core] DrawMesh: add quick test for quads when drawing hexa [#6152](https://github.com/sofa-framework/sofa/pull/6152) +- [Spring] Enable dynamic update of spring stiffness [#6153](https://github.com/sofa-framework/sofa/pull/6153) +- [FileSystem] Use generic_string to enfore forward slash in path [#6173](https://github.com/sofa-framework/sofa/pull/6173) +- [SceneChecking] Mapping checks are no longer errors [#6177](https://github.com/sofa-framework/sofa/pull/6177) + + +### Cleaning + +- [Core] Introduction of TopologyAccessor [#5824](https://github.com/sofa-framework/sofa/pull/5824) +- [All] add namespace to all BaseObject relying on using declarations [#5825](https://github.com/sofa-framework/sofa/pull/5825) +- [Helper] Minor improvements in AdvancedTimer [#5836](https://github.com/sofa-framework/sofa/pull/5836) +- [AnimationLoop] Deprecated ConstraintAnimationLoop [#5842](https://github.com/sofa-framework/sofa/pull/5842) +- [SolidMechanics.Spring] Cleaning in SpringForceField [#5847](https://github.com/sofa-framework/sofa/pull/5847) +- [FEM] Less calls to getValue [#5861](https://github.com/sofa-framework/sofa/pull/5861) +- [script] replace bash script by Python [#5883](https://github.com/sofa-framework/sofa/pull/5883) +- [Core] Show closest matches only if any [#5884](https://github.com/sofa-framework/sofa/pull/5884) +- [Mass] Remove wrong URL from doxygen [#5886](https://github.com/sofa-framework/sofa/pull/5886) +- [Lifecycle] v26.06 : SOFA_ATTRIBUTE_DISABLED [#5888](https://github.com/sofa-framework/sofa/pull/5888) +- [Lifecycle] v26.06 : SOFA_HEADER_DISABLED [#5892](https://github.com/sofa-framework/sofa/pull/5892) +- [Core] Fix warning in CollisionModel [#5894](https://github.com/sofa-framework/sofa/pull/5894) +- [ODESolver] Minor fix warning in NewtonRaphsonSolver_test [#5896](https://github.com/sofa-framework/sofa/pull/5896) +- [StateContainer] Fix warning in MechanicalObjectVOp_test [#5897](https://github.com/sofa-framework/sofa/pull/5897) +- [All] Clean uncovered lifecycle codes [#5898](https://github.com/sofa-framework/sofa/pull/5898) +- [Lifecycle] v26.06 : SOFA_ATTRIBUTE_DEPRECATED [#5899](https://github.com/sofa-framework/sofa/pull/5899) +- [Lifecycle] v26.06 : SOFA_HEADER_DEPRECATED [#5905](https://github.com/sofa-framework/sofa/pull/5905) +- [All] Fix some compilation warnings [#5906](https://github.com/sofa-framework/sofa/pull/5906) +- [Type] Array/Vec: small refresh for modern C++ [#5907](https://github.com/sofa-framework/sofa/pull/5907) +- [Ordering] Remove deprecated 'ordering' datafield [#5911](https://github.com/sofa-framework/sofa/pull/5911) +- [Config] Enable W4 option for MSVC [#5913](https://github.com/sofa-framework/sofa/pull/5913) +- [Type] Fix type conversion in RGBAColor [#5917](https://github.com/sofa-framework/sofa/pull/5917) +- [Elastic] Load required plugin in test [#5919](https://github.com/sofa-framework/sofa/pull/5919) +- [Type] Deprecated determinant for non-square matrices [#5926](https://github.com/sofa-framework/sofa/pull/5926) +- [Helper] FileSystem::createDirectory: fix missing return warning [#5929](https://github.com/sofa-framework/sofa/pull/5929) +- [Framework] BaseMatrix:: Remove warnings about overloaded-virtual about add() [#5931](https://github.com/sofa-framework/sofa/pull/5931) +- [Framework] remove virtual keyword for final classes [#5932](https://github.com/sofa-framework/sofa/pull/5932) +- [Constraint] Improve initialization and state validation in StopperLagrangianConstraint [#5935](https://github.com/sofa-framework/sofa/pull/5935) +- [Simulation.Core] use `getNodeObjects` for cleaner iteration over objects [#5945](https://github.com/sofa-framework/sofa/pull/5945) +- [SofaCUDA] examples: replace PHP scenes with python3 [#5962](https://github.com/sofa-framework/sofa/pull/5962) +- [SofaCUDA] Clean dead code due to required CUDA version [#5964](https://github.com/sofa-framework/sofa/pull/5964) +- [Topology.Mapping] Refactor Hexa2TetraTopologicalMapping to improve readability and add unit tests [#5981](https://github.com/sofa-framework/sofa/pull/5981) +- [Example] BUFIX: Adjust relative paths in fallingSOFA.scn file [#5996](https://github.com/sofa-framework/sofa/pull/5996) +- [All] Replace BaseObject.h by BaseComponent.h [#6003](https://github.com/sofa-framework/sofa/pull/6003) +- [Core] Use `toBaseComponent()` instead of `toBaseObject()` [#6004](https://github.com/sofa-framework/sofa/pull/6004) +- [All] Replace `BaseObject::canCreate` by `BaseComponent::canCreate` [#6005](https://github.com/sofa-framework/sofa/pull/6005) +- [Core] BaseContext: Remove usage of BaseObject alias [#6007](https://github.com/sofa-framework/sofa/pull/6007) +- [Core] BaseNode: Remove usage of BaseObject alias [#6009](https://github.com/sofa-framework/sofa/pull/6009) +- [Collision.Detection] SubCollisionPipeline: fix timings [#6019](https://github.com/sofa-framework/sofa/pull/6019) +- [All] Another round of renaming of BaseObject to BaseComponent [#6020](https://github.com/sofa-framework/sofa/pull/6020) +- [Geometry] Prism: remove warning about multiline comment [#6021](https://github.com/sofa-framework/sofa/pull/6021) +- [SceneChecking] Introduce SceneCheckSpecialCharacters [#6025](https://github.com/sofa-framework/sofa/pull/6025) +- [Sofa.Type] Treat warnings as errors [#6027](https://github.com/sofa-framework/sofa/pull/6027) +- [Sofa.Geometry] Treat warnings as errors [#6028](https://github.com/sofa-framework/sofa/pull/6028) +- [Type] Quat: factorize matrix code [#6030](https://github.com/sofa-framework/sofa/pull/6030) +- [Sofa.Topology] Treat warnings as errors [#6034](https://github.com/sofa-framework/sofa/pull/6034) +- [Simulation.Core] Add warning if RequiredPlugin uses its name to load a plugin [#6038](https://github.com/sofa-framework/sofa/pull/6038) +- [All] In RequiredPlugin, use pluginName instead of name [#6039](https://github.com/sofa-framework/sofa/pull/6039) +- [Sofa.Config] Remove already define macro warning [#6045](https://github.com/sofa-framework/sofa/pull/6045) +- [Framework] Remove warnings by adding compilation time checks [#6046](https://github.com/sofa-framework/sofa/pull/6046) +- [SofaCUDA] init: print info about driver and runtime version [#6048](https://github.com/sofa-framework/sofa/pull/6048) +- [SceneChecking] Update message for missing RequiredPlugin [#6059](https://github.com/sofa-framework/sofa/pull/6059) +- [Framework] Fix warnings from modern gcc/clang [#6060](https://github.com/sofa-framework/sofa/pull/6060) +- [SofaCUDA] CMake: Remove old options [#6079](https://github.com/sofa-framework/sofa/pull/6079) +- [Framework] Fix more warnings (clang, macos) [#6083](https://github.com/sofa-framework/sofa/pull/6083) +- [Core, Simulation.Core] MSVC: fix inconsistent linkages [#6084](https://github.com/sofa-framework/sofa/pull/6084) +- [Core] Clarify how the visitor knows if a state is mapped or not [#6086](https://github.com/sofa-framework/sofa/pull/6086) +- [Engine.Select] Explicit template instantiation for BaseROI and export to API [#6094](https://github.com/sofa-framework/sofa/pull/6094) +- [Helper] FileSystem: refactor using std::filesystem [#6096](https://github.com/sofa-framework/sofa/pull/6096) +- [LinearSystem] Replace deprecated header [#6101](https://github.com/sofa-framework/sofa/pull/6101) +- [Type] Add streaming deserialization for vector [#6106](https://github.com/sofa-framework/sofa/pull/6106) +- [SofaCarving] CarvingManager: use checkEventType instead of dynamic_cast-ing [#6109](https://github.com/sofa-framework/sofa/pull/6109) +- [GitHub] Revise CONTRIBUTING.md for clarity and updates [#6112](https://github.com/sofa-framework/sofa/pull/6112) +- [Framework] Fix more warnings (msvc) [#6113](https://github.com/sofa-framework/sofa/pull/6113) +- [LinearSolver,LinearSystem] Include appropriate inl to no longer on extern symbols [#6119](https://github.com/sofa-framework/sofa/pull/6119) +- [All] Factorize primitive numeric types reflection [#6121](https://github.com/sofa-framework/sofa/pull/6121) +- [LinearAlgebra] Factorize matrix bloc trait using concept [#6122](https://github.com/sofa-framework/sofa/pull/6122) +- [FEM] Refactor templates in latest FEM classes [#6124](https://github.com/sofa-framework/sofa/pull/6124) +- [Visual] VisualModelImpl: add data to optionally generate uv coords [#6137](https://github.com/sofa-framework/sofa/pull/6137) +- [Type] Remove `VecView` class and update codebase to use `Vec` utilities instead [#6138](https://github.com/sofa-framework/sofa/pull/6138) +- [Framework] Fix last warnings [#6144](https://github.com/sofa-framework/sofa/pull/6144) + + +### Refactoring + +- [SofaCUDA] Apply new factory registration mechanism [#5827](https://github.com/sofa-framework/sofa/pull/5827) + + +### Project / CI / Infrastructure + +- [GitHub] Update install-nix-action to version 31 [#5885](https://github.com/sofa-framework/sofa/pull/5885) +- [CI] Add action to trigger conda packages "nightly" builds [#5910](https://github.com/sofa-framework/sofa/pull/5910) +- [Project] Start dev phase v26.06 [#5928](https://github.com/sofa-framework/sofa/pull/5928) +- [CI] Fix workflow that trigger conda-ci for devel conda packages [#5956](https://github.com/sofa-framework/sofa/pull/5956) +- [CI] Add action to update pixi lockfile [#6010](https://github.com/sofa-framework/sofa/pull/6010) +- [CI] Update pixi lockfile [#6011](https://github.com/sofa-framework/sofa/pull/6011) +- [CI] Change name of pr and tags for update pixi lockfile PR [#6012](https://github.com/sofa-framework/sofa/pull/6012) +- [CI] Fix title and label in update pixi lockfile action [#6013](https://github.com/sofa-framework/sofa/pull/6013) +- [CI] Fix scene tests by ignoring Cuda scenes from benchmarks [#6014](https://github.com/sofa-framework/sofa/pull/6014) +- [Conda-ci] Add hash info for glfw in the payload [#6052](https://github.com/sofa-framework/sofa/pull/6052) +- [Conda-CI] Fix launch action [#6053](https://github.com/sofa-framework/sofa/pull/6053) +- [CI] Fix conda ci curl call [#6056](https://github.com/sofa-framework/sofa/pull/6056) +- [CI] Update pixi lockfile [#6063](https://github.com/sofa-framework/sofa/pull/6063) +- [CI] Update pixi lockfile [#6099](https://github.com/sofa-framework/sofa/pull/6099) +- [plugins] Change Cosserat plugin GIT_REF from master to main [#6103](https://github.com/sofa-framework/sofa/pull/6103) +- [Pixi] Fix pixi compilation for CUDA related plugins [#6108](https://github.com/sofa-framework/sofa/pull/6108) +- [CI] Clean old results folder if it exists [#6114](https://github.com/sofa-framework/sofa/pull/6114) +- [GitHub] Prefix actions for better readibility [#6123](https://github.com/sofa-framework/sofa/pull/6123) +- [CI] Fix build_and_test script [#6126](https://github.com/sofa-framework/sofa/pull/6126) +- [CI] Only launch pixi action in sofa-framework [#6147](https://github.com/sofa-framework/sofa/pull/6147) +- [CI] Update pixi lockfile [#6167](https://github.com/sofa-framework/sofa/pull/6167) +- [CI] Fix relocation in NSIS [#6174](https://github.com/sofa-framework/sofa/pull/6174) +- [applications] Change remote version for fetched plugins [#6178](https://github.com/sofa-framework/sofa/pull/6178) +- [CMake] Bump SOFA version v26.06.00 [#6179](https://github.com/sofa-framework/sofa/pull/6179) + + + + + ## [v25.12.00]( https://github.com/sofa-framework/sofa/tree/v25.12.00 ) [Full log]( https://github.com/sofa-framework/sofa/compare/v25.06..v25.12 ) diff --git a/CMakeLists.txt b/CMakeLists.txt index 49aeca02503..fdfa5130972 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ endif() # Manually define VERSION set(Sofa_VERSION_MAJOR 26) -set(Sofa_VERSION_MINOR 06) +set(Sofa_VERSION_MINOR 12) set(Sofa_VERSION_PATCH 99) set(Sofa_VERSION ${Sofa_VERSION_MAJOR}.${Sofa_VERSION_MINOR}.${Sofa_VERSION_PATCH}) diff --git a/package.nix b/package.nix index 1b7fa45bc67..6595a172afa 100644 --- a/package.nix +++ b/package.nix @@ -19,7 +19,7 @@ stdenv.mkDerivation (finalAttrs: { pname = "sofa"; - version = "26.06.99"; + version = "26.12.99"; src = lib.fileset.toSource { root = ./.; diff --git a/pixi.toml b/pixi.toml index 828b9cb30d4..b76905f8142 100644 --- a/pixi.toml +++ b/pixi.toml @@ -8,7 +8,7 @@ platforms = ["osx-64", "osx-arm64", "linux-64", "win-64"] -version = "25.06.99" +version = "26.12.99" license = "LGPL-2.1-or-later" license-file = "LICENSE-LGPL.md" From 71f6e044f13529ae71e4f013850c014f72ae3d62 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Wed, 29 Jul 2026 02:21:02 -0700 Subject: [PATCH 04/20] [Scene] TetrahedronHyperelasticityFEMForceField.scn: add correct plugin for topology (#6212) fix required plugin for TetrahedronHyperelasticityFEMForceField --- .../FEM/TetrahedronHyperelasticityFEMForceField.scn | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/Component/SolidMechanics/FEM/TetrahedronHyperelasticityFEMForceField.scn b/examples/Component/SolidMechanics/FEM/TetrahedronHyperelasticityFEMForceField.scn index b888ca94ff4..ca726bf5121 100644 --- a/examples/Component/SolidMechanics/FEM/TetrahedronHyperelasticityFEMForceField.scn +++ b/examples/Component/SolidMechanics/FEM/TetrahedronHyperelasticityFEMForceField.scn @@ -1,6 +1,6 @@ - + @@ -11,10 +11,10 @@ - + - + From 0c1e65c18dac8b1a90aa3b8ddabb5fd98c44c392 Mon Sep 17 00:00:00 2001 From: Lucas-TJ Date: Wed, 29 Jul 2026 18:04:53 +0200 Subject: [PATCH 05/20] [CORE] Add remove function in BaseLink (#6130) * add doremove * clean * add unit test * remove useless include --- .../objectmodel/BaseLink_simutest.cpp | 47 +++++++++---------- .../sofa/core/objectmodel/BaseComponent.cpp | 4 +- .../Core/src/sofa/core/objectmodel/BaseLink.h | 3 ++ .../Core/src/sofa/core/objectmodel/Link.h | 6 +-- .../Core/src/sofa/simulation/Node.cpp | 4 +- 5 files changed, 33 insertions(+), 31 deletions(-) diff --git a/Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp b/Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp index 802a27b962d..94bfe56f5ae 100644 --- a/Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp +++ b/Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp @@ -30,6 +30,7 @@ using sofa::testing::BaseSimulationTest ; using sofa::simulation::Node ; #include +using sofa::core::objectmodel::BaseObject; using sofa::core::objectmodel::BaseComponent; #include @@ -41,8 +42,6 @@ using sofa::defaulttype::Rigid3Types; #include using sofa::defaulttype::Vec3Types; -using sofa::core::objectmodel::BaseLink; - namespace { @@ -58,6 +57,7 @@ class BaseLink_test : public BaseSimulationTest, scene << "" " \n" " \n" + " \n" " \n" " \n" " \n" @@ -81,42 +81,39 @@ class BaseLink_test : public BaseSimulationTest, } }; -class FakeComponent : public BaseComponent -{ +class FakeComponent : public BaseComponent { public: SOFA_CLASS(FakeComponent, BaseComponent); - sofa::MultiLink l_target; - FakeComponent() - : l_target(initLink("target","link for test")) - {} + sofa::MultiLink l_target; + FakeComponent() + : l_target(initLink("target", "link for test")) { + } }; -TEST_F(BaseLink_test, add) +TEST_F(BaseLink_test, remove) { - FakeComponent Component1; - Component1.setName("Component1"); - FakeComponent Component2; - Component2.setName("Component2"); - FakeComponent Component3; - Component3.setName("Component3"); - - FakeComponent* ptr; - ptr = &Component2; + FakeComponent owner; + FakeComponent target1; + FakeComponent target2; - EXPECT_EQ(Component1.l_target.getValueString(), ""); + ASSERT_FALSE(owner.l_target.remove(&target1)); - Component1.l_target.add(ptr); - EXPECT_EQ(Component1.l_target.getValueString(), "@Component2"); + ASSERT_TRUE(owner.l_target.add(&target1, "")); + ASSERT_TRUE(owner.l_target.add(&target2, "")); + ASSERT_EQ(owner.l_target.size(), size_t(2)); + ASSERT_EQ(owner.l_target.get(0), &target1); + ASSERT_EQ(owner.l_target.get(1), &target2); - ptr = &Component3; + ASSERT_TRUE(owner.l_target.remove(&target1)); + ASSERT_EQ(owner.l_target.size(), size_t(1)); + ASSERT_EQ(owner.l_target.get(0), &target2); - Component1.l_target.add(ptr); - EXPECT_EQ(Component1.l_target.getValueString(), "@Component2 @Component3"); + ASSERT_FALSE(owner.l_target.remove(&target1)); + ASSERT_FALSE(owner.l_target.remove(nullptr)); } - //////////////////////// Testing valid path ////////////////////////////////////// class MultiLink_simutest : public BaseLink_test {}; diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp index e1fa55bb72d..0c3bf63bfe5 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp @@ -226,6 +226,8 @@ void BaseComponent::addSlave(BaseComponent::SPtr s) if (previous) previous->l_slaves.remove(s); l_slaves.add(s.get()); + previous->l_slaves.remove(s.get()); + l_slaves.add(s); if (previous) this->getContext()->notifyMoveSlave(previous.get(), this, s.get()); else @@ -234,7 +236,7 @@ void BaseComponent::addSlave(BaseComponent::SPtr s) void BaseComponent::removeSlave(BaseComponent::SPtr s) { - if (l_slaves.remove(s)) + if (l_slaves.remove(s.get())) { this->getContext()->notifyRemoveSlave(this, s.get()); } diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseLink.h b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseLink.h index cad9af993e2..4c7c879f97b 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseLink.h +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseLink.h @@ -176,6 +176,8 @@ class SOFA_CORE_API BaseLink /// Change the link's target at the provided index. bool set(Base* baseptr, size_t index=0) { return _doSet_(baseptr, index); } + bool remove(Base* baseptr) {return _doRemove_(baseptr); } + protected: virtual bool _doSet_(Base* target, const size_t index=0) = 0; virtual Base* _doGetOwner_() const = 0 ; @@ -185,6 +187,7 @@ class SOFA_CORE_API BaseLink virtual bool _doAdd_(Base*) = 0; virtual void _doClear_() = 0; virtual std::string _doGetLinkedPath_(const size_t=0) const = 0; + virtual bool _doRemove_(Base* target) = 0; unsigned int m_flags; std::string m_name; diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/Link.h b/Sofa/framework/Core/src/sofa/core/objectmodel/Link.h index e5821c8e254..bc8061ac8d6 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/Link.h +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/Link.h @@ -387,11 +387,11 @@ class TLink : public BaseLink return add(ptr, path); } - bool remove(DestPtr v) + bool _doRemove_(Base* target) override { - if (!v) + if (!target) return false; - return removeAt(TraitsContainer::find(m_value,v)); + return removeAt(TraitsContainer::find(m_value,castTo(target))); } bool removeAt(std::size_t index) diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp index cda006290b0..23303e6ea6b 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp @@ -654,7 +654,7 @@ bool Node::doRemoveObject(sofa::core::objectmodel::BaseComponent::SPtr sobj) dmsg_warning_when(sobj == nullptr) << "Trying to remove a nullptr object"; this->clearObjectContext(sobj); - object.remove(sobj); + object.remove(sobj.get()); sofa::core::objectmodel::BaseComponent* obj = sobj.get(); if(obj != nullptr && !obj->removeInNode( this ) ) @@ -1192,7 +1192,7 @@ void Node::doRemoveChild(BaseNode::SPtr node) { const Node::SPtr dagnode = sofa::core::objectmodel::SPtr_static_cast(node); setDirtyDescendancy(); - child.remove(dagnode); + child.remove(dagnode.get()); dagnode->l_parents.remove(this); } From bc5341387a5f6e9c331ae6a8aa57ad777bb60108 Mon Sep 17 00:00:00 2001 From: Paul Baksic <30337881+bakpaul@users.noreply.github.com> Date: Thu, 30 Jul 2026 00:27:38 +0200 Subject: [PATCH 06/20] [Tests] Fix LCPForceFeedbackTests (#6213) * Fix unit test for forcefeedback * Fix forces values --- .../Haptics/tests/LCPForceFeedback_test.cpp | 53 ++++++++++--------- .../scenes/ToolvsFloorCollision_test.scn | 31 +++++------ 2 files changed, 41 insertions(+), 43 deletions(-) diff --git a/Sofa/Component/Haptics/tests/LCPForceFeedback_test.cpp b/Sofa/Component/Haptics/tests/LCPForceFeedback_test.cpp index cbd67350821..39e5d95a9ef 100644 --- a/Sofa/Component/Haptics/tests/LCPForceFeedback_test.cpp +++ b/Sofa/Component/Haptics/tests/LCPForceFeedback_test.cpp @@ -195,21 +195,21 @@ bool LCPForceFeedback_test::test_SimpleCollision() EXPECT_EQ(meca->getSize(), 1); VecCoord truthCoords; - truthCoords.push_back(Coord(sofa::type::Vec3d(0, -0.002498750625, 0), sofa::type::Quat(0, 0, 0, 1))); - truthCoords.push_back(Coord(sofa::type::Vec3d(0, -0.1646431247, 0), sofa::type::Quat(0, 0, 0, 1))); - truthCoords.push_back(Coord(sofa::type::Vec3d(0, -0.5752928747, 0), sofa::type::Quat(0, 0, 0, 1))); - truthCoords.push_back(Coord(sofa::type::Vec3d(0, -1.233208884, 0), sofa::type::Quat(0, 0, 0, 1))); - truthCoords.push_back(Coord(sofa::type::Vec3d(0, -2.137158214, 0), sofa::type::Quat(0, 0, 0, 1))); - truthCoords.push_back(Coord(sofa::type::Vec3d(0, -3.285914075, 0), sofa::type::Quat(0, 0, 0, 1))); - truthCoords.push_back(Coord(sofa::type::Vec3d(0, -4.678255793, 0), sofa::type::Quat(0, 0, 0, 1))); - truthCoords.push_back(Coord(sofa::type::Vec3d(0, -6.312968782, 0), sofa::type::Quat(0, 0, 0, 1))); - truthCoords.push_back(Coord(sofa::type::Vec3d(0, -8.188844511, 0), sofa::type::Quat(0, 0, 0, 1))); - - truthCoords.push_back(Coord(sofa::type::Vec3d(0.06312707665, -9.252446766, 0.01034522507), sofa::type::Quat(0.01791466055, -0.001121278545, -0.1466133921, 0.989031001))); - truthCoords.push_back(Coord(sofa::type::Vec3d(0.1068031131, -9.480637263, 0.01138742455), sofa::type::Quat(0.01596551667, -0.006985361948, -0.4382452548, 0.8986864879))); - truthCoords.push_back(Coord(sofa::type::Vec3d(-0.003396912202, -9.692178925, 0.01301318567), sofa::type::Quat(0.01059102598, -0.01374254084, -0.7148386272, 0.6990741805))); - truthCoords.push_back(Coord(sofa::type::Vec3d(-0.1668556563, -9.577363026, 0.03455744119), sofa::type::Quat(-0.02439727795, -0.04585925265, -0.9016493065, 0.4293369653))); - truthCoords.push_back(Coord(sofa::type::Vec3d(-0.230611987, -9.409244076, 0.05034655108), sofa::type::Quat(-0.06676044546, -0.08462859852, -0.9839281746, 0.1423600732))); + truthCoords.push_back(Coord(sofa::type::Vec3d(0, -0.0024875621, 0), sofa::type::Quat(0, 0, 0, 1))); + truthCoords.push_back(Coord(sofa::type::Vec3d(0, -0.16148664, 0), sofa::type::Quat(0, 0, 0, 1))); + truthCoords.push_back(Coord(sofa::type::Vec3d(0, -0.55601037, 0), sofa::type::Quat(0, 0, 0, 1))); + truthCoords.push_back(Coord(sofa::type::Vec3d(0, -1.1746, 0), sofa::type::Quat(0, 0, 0, 1))); + truthCoords.push_back(Coord(sofa::type::Vec3d(0, -2.0063543, 0), sofa::type::Quat(0, 0, 0, 1))); + truthCoords.push_back(Coord(sofa::type::Vec3d(0, -3.0409024, 0), sofa::type::Quat(0, 0, 0, 1))); + truthCoords.push_back(Coord(sofa::type::Vec3d(0, -4.2683778, 0), sofa::type::Quat(0, 0, 0, 1))); + truthCoords.push_back(Coord(sofa::type::Vec3d(0, -5.6793942, 0), sofa::type::Quat(0, 0, 0, 1))); + truthCoords.push_back(Coord(sofa::type::Vec3d(0, -7.2650223, 0), sofa::type::Quat(0, 0, 0, 1))); + truthCoords.push_back(Coord(sofa::type::Vec3d(0, -9.0167665, 0), sofa::type::Quat(0,0,0,1))); + + truthCoords.push_back(Coord(sofa::type::Vec3d(0.081810147, -9.3104954, 0.0084159356), sofa::type::Quat(0.0175437, -0.0027353484, -0.22570916, 0.97403294))); + truthCoords.push_back(Coord(sofa::type::Vec3d(0.080605865, -9.5144129, 0.0084154662), sofa::type::Quat(0.015405586, -0.0075208684, -0.47918597, 0.87754595))); + truthCoords.push_back(Coord(sofa::type::Vec3d(-0.038712446, -9.6903, 0.0090729725), sofa::type::Quat(0.011461957, -0.012498143, -0.71390605, 0.70003611))); + truthCoords.push_back(Coord(sofa::type::Vec3d(-0.17837876, -9.6024733, 0.020258242), sofa::type::Quat(-0.0072201439, -0.031115066, -0.87544507, 0.48226097))); int pctTru = 0; for (int step = 0; step < 140; step++) @@ -270,7 +270,7 @@ bool LCPForceFeedback_test::test_Collision() // check position and constraint problem EXPECT_LT(coords[0][1], -9.0); - EXPECT_EQ(cons.size(), 84); + EXPECT_EQ(cons.size(), 105); // check LCP computeForce method sofa::type::Vec3 position = sofa::type::Vec3(0, 0, 0); @@ -287,7 +287,7 @@ bool LCPForceFeedback_test::test_Collision() m_LCPFFBack->computeForce(coords[0][0], coords[0][1], coords[0][2], 0, 0, 0, 0, force[0], force[1], force[2]); // test with groundtruth, do it index by index for better log - Coord coordT = Coord(sofa::type::Vec3d(0.1083095508, -9.45640795, 0.01134330546), sofa::type::Quat(0.01623300333, -0.006386979003, -0.408876291, 0.9124230788)); + Coord coordT = Coord(sofa::type::Vec3d(0.07618425, -9.2916698, 0.0084328074), sofa::type::Quat(0.017680431, -0.0022677642, -0.20060691, 0.97950965)); //// position EXPECT_FLOAT_EQ(coords[0][0], coordT[0]); EXPECT_FLOAT_EQ(coords[0][1], coordT[1]); @@ -300,7 +300,7 @@ bool LCPForceFeedback_test::test_Collision() EXPECT_FLOAT_EQ(coords[0][6], coordT[6]); //// force - trueForce = sofa::type::Vec3(-0.001655988795, 0.002759984308, -2.431849862e-06); + trueForce = sofa::type::Vec3(-0.00084725959, 0.0024373089, -4.2111449e-05); EXPECT_FLOAT_EQ(force[0], trueForce[0]); EXPECT_FLOAT_EQ(force[1], trueForce[1]); EXPECT_FLOAT_EQ(force[2], trueForce[2]); @@ -310,7 +310,7 @@ bool LCPForceFeedback_test::test_Collision() m_LCPFFBack->computeForce(inside[0], inside[1], inside[2], 0, 0, 0, 0, force[0], force[1], force[2]); // test with groundtruth, do it index by index for better log - coordT = Coord(sofa::type::Vec3d(0.1083095508, -10.45640795, 0.01134330546), sofa::type::Quat(0.01623300333, -0.006386979003, -0.408876291, 0.9124230788)); + coordT = Coord(sofa::type::Vec3d(0.07618425, -10.29167, 0.0084328074), sofa::type::Quat(0.01623300333, -0.006386979003, -0.408876291, 0.9124230788)); //// position EXPECT_FLOAT_EQ(inside[0], coordT[0]); EXPECT_FLOAT_EQ(inside[1], coordT[1]); @@ -323,7 +323,7 @@ bool LCPForceFeedback_test::test_Collision() EXPECT_FLOAT_EQ(inside[6], coordT[6]); //// force - trueForce = sofa::type::Vec3(-0.1450155705, 8.930516304, 0.1567013005); + trueForce = sofa::type::Vec3(0.27008709, 9.1463537, 0.060468301); EXPECT_FLOAT_EQ(force[0], trueForce[0]); EXPECT_FLOAT_EQ(force[1], trueForce[1]); EXPECT_FLOAT_EQ(force[2], trueForce[2]); @@ -333,12 +333,12 @@ bool LCPForceFeedback_test::test_Collision() m_LCPFFBack->computeForce(coords, forces); EXPECT_EQ(forces.size(), 1); - EXPECT_FLOAT_EQ(forces[0][0], -0.00164953925); - EXPECT_FLOAT_EQ(forces[0][1], 0.002749336856); - EXPECT_FLOAT_EQ(forces[0][2], -1.032894327e-05); - EXPECT_FLOAT_EQ(forces[0][3], 0.0001298280752); - EXPECT_FLOAT_EQ(forces[0][4], 7.443984612e-05); - EXPECT_FLOAT_EQ(forces[0][5], -0.0009855082698); + EXPECT_FLOAT_EQ(forces[0][0], -0.00013606942); + EXPECT_FLOAT_EQ(forces[0][1], 0.0027710579); + EXPECT_FLOAT_EQ(forces[0][2], -0.00090467848); + EXPECT_FLOAT_EQ(forces[0][3], 0.00030387595); + EXPECT_FLOAT_EQ(forces[0][4], -0.00031411531); + EXPECT_FLOAT_EQ(forces[0][5], -0.0010078497); return true; } @@ -421,3 +421,4 @@ TEST_F(LCPForceFeedback_test, test_multiThread) } // namespace sofa + diff --git a/Sofa/Component/Haptics/tests/scenes/ToolvsFloorCollision_test.scn b/Sofa/Component/Haptics/tests/scenes/ToolvsFloorCollision_test.scn index 797bdc5b433..c412bcf1d3b 100644 --- a/Sofa/Component/Haptics/tests/scenes/ToolvsFloorCollision_test.scn +++ b/Sofa/Component/Haptics/tests/scenes/ToolvsFloorCollision_test.scn @@ -13,27 +13,25 @@ - + - + - + - - + + - - @@ -41,29 +39,28 @@ - + - + - - + + - + - + - - - - + + + From 416737e78ea0fac1e66aa7c73914c843a9113fc8 Mon Sep 17 00:00:00 2001 From: Paul Baksic <30337881+bakpaul@users.noreply.github.com> Date: Thu, 30 Jul 2026 04:19:12 +0200 Subject: [PATCH 07/20] [Plugins] Set SofaImplicitField as supported plugin (#6189) Remove plugin from sources and add it to the preset --- CMakePresets.json | 12 +- applications/plugins/CMakeLists.txt | 2 +- .../plugins/SofaImplicitField/CMakeLists.txt | 65 --- .../SofaImplicitField/MarchingCube.cpp | 165 -------- .../plugins/SofaImplicitField/MarchingCube.h | 83 ---- .../plugins/SofaImplicitField/README.md | 4 - .../SofaImplicitFieldConfig.cmake.in | 21 - .../SofaImplicitField_test/CMakeLists.txt | 14 - .../ImplicitShape_test.cpp | 53 --- .../components/engine/FieldToSurfaceMesh.cpp | 174 -------- .../components/engine/FieldToSurfaceMesh.h | 102 ----- .../components/geometry/BottleField.cpp | 171 -------- .../components/geometry/BottleField.h | 84 ---- .../components/geometry/DiscreteGridField.cpp | 376 ------------------ .../components/geometry/DiscreteGridField.h | 99 ----- .../components/geometry/ScalarField.cpp | 291 -------------- .../components/geometry/ScalarField.h | 143 ------- .../components/geometry/SphericalField.cpp | 112 ------ .../components/geometry/SphericalField.h | 83 ---- .../components/geometry/StarShapedField.cpp | 137 ------- .../components/geometry/StarShapedField.h | 79 ---- .../mapping/ImplicitSurfaceMapping.cpp | 41 -- .../mapping/ImplicitSurfaceMapping.h | 164 -------- .../mapping/ImplicitSurfaceMapping.inl | 164 -------- .../plugins/SofaImplicitField/config.h.in | 37 -- .../deprecated/ImplicitSurfaceContainer.h | 50 --- .../deprecated/ImplicitSurfaceMapping.h | 1 - .../deprecated/ImplicitSurfaceMapping.inl | 1 - .../InterpolatedImplicitSurface.cpp | 18 - .../deprecated/InterpolatedImplicitSurface.h | 52 --- .../deprecated/SphereSurface.cpp | 30 -- .../deprecated/SphereSurface.h | 29 -- .../examples/ImplicitSurfaceMapping.scn | 25 -- .../example-mesh-extraction-from-implicit.py | 53 --- .../examples/python/python-scalarfield.py | 50 --- .../examples/python/xshape/__init__.py | 0 .../examples/python/xshape/operators.py | 35 -- .../examples/python/xshape/primitives.py | 34 -- .../examples/python/xshape/transforms.py | 15 - .../initSofaImplicitField.cpp | 115 ------ .../SofaImplicitField/initSofaImplicitField.h | 37 -- .../SofaImplicitField/python/CMakeLists.txt | 26 -- .../python/src/Binding_ScalarField.cpp | 140 ------- .../python/src/Binding_ScalarField.h | 29 -- .../python/src/Module_SofaImplicitField.cpp | 38 -- 45 files changed, 9 insertions(+), 3445 deletions(-) delete mode 100644 applications/plugins/SofaImplicitField/CMakeLists.txt delete mode 100644 applications/plugins/SofaImplicitField/MarchingCube.cpp delete mode 100644 applications/plugins/SofaImplicitField/MarchingCube.h delete mode 100644 applications/plugins/SofaImplicitField/README.md delete mode 100644 applications/plugins/SofaImplicitField/SofaImplicitFieldConfig.cmake.in delete mode 100644 applications/plugins/SofaImplicitField/SofaImplicitField_test/CMakeLists.txt delete mode 100644 applications/plugins/SofaImplicitField/SofaImplicitField_test/ImplicitShape_test.cpp delete mode 100644 applications/plugins/SofaImplicitField/components/engine/FieldToSurfaceMesh.cpp delete mode 100644 applications/plugins/SofaImplicitField/components/engine/FieldToSurfaceMesh.h delete mode 100644 applications/plugins/SofaImplicitField/components/geometry/BottleField.cpp delete mode 100644 applications/plugins/SofaImplicitField/components/geometry/BottleField.h delete mode 100644 applications/plugins/SofaImplicitField/components/geometry/DiscreteGridField.cpp delete mode 100644 applications/plugins/SofaImplicitField/components/geometry/DiscreteGridField.h delete mode 100644 applications/plugins/SofaImplicitField/components/geometry/ScalarField.cpp delete mode 100644 applications/plugins/SofaImplicitField/components/geometry/ScalarField.h delete mode 100644 applications/plugins/SofaImplicitField/components/geometry/SphericalField.cpp delete mode 100644 applications/plugins/SofaImplicitField/components/geometry/SphericalField.h delete mode 100644 applications/plugins/SofaImplicitField/components/geometry/StarShapedField.cpp delete mode 100644 applications/plugins/SofaImplicitField/components/geometry/StarShapedField.h delete mode 100644 applications/plugins/SofaImplicitField/components/mapping/ImplicitSurfaceMapping.cpp delete mode 100644 applications/plugins/SofaImplicitField/components/mapping/ImplicitSurfaceMapping.h delete mode 100644 applications/plugins/SofaImplicitField/components/mapping/ImplicitSurfaceMapping.inl delete mode 100644 applications/plugins/SofaImplicitField/config.h.in delete mode 100644 applications/plugins/SofaImplicitField/deprecated/ImplicitSurfaceContainer.h delete mode 100644 applications/plugins/SofaImplicitField/deprecated/ImplicitSurfaceMapping.h delete mode 100644 applications/plugins/SofaImplicitField/deprecated/ImplicitSurfaceMapping.inl delete mode 100644 applications/plugins/SofaImplicitField/deprecated/InterpolatedImplicitSurface.cpp delete mode 100644 applications/plugins/SofaImplicitField/deprecated/InterpolatedImplicitSurface.h delete mode 100644 applications/plugins/SofaImplicitField/deprecated/SphereSurface.cpp delete mode 100644 applications/plugins/SofaImplicitField/deprecated/SphereSurface.h delete mode 100644 applications/plugins/SofaImplicitField/examples/ImplicitSurfaceMapping.scn delete mode 100644 applications/plugins/SofaImplicitField/examples/python/example-mesh-extraction-from-implicit.py delete mode 100644 applications/plugins/SofaImplicitField/examples/python/python-scalarfield.py delete mode 100644 applications/plugins/SofaImplicitField/examples/python/xshape/__init__.py delete mode 100644 applications/plugins/SofaImplicitField/examples/python/xshape/operators.py delete mode 100644 applications/plugins/SofaImplicitField/examples/python/xshape/primitives.py delete mode 100644 applications/plugins/SofaImplicitField/examples/python/xshape/transforms.py delete mode 100644 applications/plugins/SofaImplicitField/initSofaImplicitField.cpp delete mode 100644 applications/plugins/SofaImplicitField/initSofaImplicitField.h delete mode 100644 applications/plugins/SofaImplicitField/python/CMakeLists.txt delete mode 100644 applications/plugins/SofaImplicitField/python/src/Binding_ScalarField.cpp delete mode 100644 applications/plugins/SofaImplicitField/python/src/Binding_ScalarField.h delete mode 100644 applications/plugins/SofaImplicitField/python/src/Module_SofaImplicitField.cpp diff --git a/CMakePresets.json b/CMakePresets.json index 29dd152ed01..5d8af5429fc 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -214,6 +214,14 @@ "PLUGIN_MODELORDERREDUCTION": { "type": "BOOL", "value": "ON" + }, + "SOFA_FETCH_SOFAIMPLICITFIELD": { + "type": "BOOL", + "value": "ON" + }, + "PLUGIN_SOFAIMPLICITFIELD": { + "type": "BOOL", + "value": "ON" } } }, @@ -256,10 +264,6 @@ "type": "BOOL", "value": "ON" }, - "PLUGIN_SOFAIMPLICITFIELD": { - "type": "BOOL", - "value": "ON" - }, "SOFA_FETCH_SOFASPHFLUID": { "type": "BOOL", "value": "ON" diff --git a/applications/plugins/CMakeLists.txt b/applications/plugins/CMakeLists.txt index ba69551ca83..d748d0610ec 100644 --- a/applications/plugins/CMakeLists.txt +++ b/applications/plugins/CMakeLists.txt @@ -74,4 +74,4 @@ else() endif() sofa_add_subdirectory(plugin SofaDistanceGrid SofaDistanceGrid) # Also defines SofaDistanceGrid.CUDA -sofa_add_subdirectory(plugin SofaImplicitField SofaImplicitField) +sofa_add_external(plugin SofaImplicitField GIT_REF master GIT_REPOSITORY https://www.github.com/sofa-framework/SofaImplicitField.git) diff --git a/applications/plugins/SofaImplicitField/CMakeLists.txt b/applications/plugins/SofaImplicitField/CMakeLists.txt deleted file mode 100644 index aca4a06b47b..00000000000 --- a/applications/plugins/SofaImplicitField/CMakeLists.txt +++ /dev/null @@ -1,65 +0,0 @@ -cmake_minimum_required(VERSION 3.22) -project(SofaImplicitField VERSION 1.0) - -sofa_find_package(Sofa.Component.Topology.Container.Constant REQUIRED) - -set(HEADER_FILES - config.h.in - initSofaImplicitField.h - MarchingCube.h - - # This is backward compatibility - deprecated/SphereSurface.h - deprecated/ImplicitSurfaceContainer.h # This is a backward compatibility file toward ScalarField - deprecated/InterpolatedImplicitSurface.h # This is a backward compatibility file toward DiscreteGridField - - components/engine/FieldToSurfaceMesh.h - components/geometry/BottleField.h - components/geometry/DiscreteGridField.h - components/geometry/SphericalField.h - components/geometry/ScalarField.h - components/geometry/StarShapedField.h - components/mapping/ImplicitSurfaceMapping.h - components/mapping/ImplicitSurfaceMapping.inl -) - -set(SOURCE_FILES - initSofaImplicitField.cpp - MarchingCube.cpp - - ## This is a backward compatibility.. - deprecated/SphereSurface.cpp - deprecated/InterpolatedImplicitSurface.cpp - - components/engine/FieldToSurfaceMesh.cpp - components/geometry/BottleField.cpp - components/geometry/ScalarField.cpp - components/geometry/DiscreteGridField.cpp - components/geometry/SphericalField.cpp - components/geometry/StarShapedField.cpp - components/mapping/ImplicitSurfaceMapping.cpp -) - -set(EXTRA_FILES - README.md - ) - -if(SOFA_BUILD_TESTS) - add_subdirectory(SofaImplicitField_test) -endif() - -add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} ${EXTRA_FILES}) -target_link_libraries(${PROJECT_NAME} PRIVATE Sofa.Component.Topology.Container.Constant) - -find_package(SofaPython3 REQUIRED) -if (SofaPython3_FOUND) - add_subdirectory(python) -endif() - -## Install rules for the library and headers; CMake package configurations files -sofa_create_package_with_targets( - PACKAGE_NAME ${PROJECT_NAME} - PACKAGE_VERSION ${PROJECT_VERSION} - TARGETS ${PROJECT_NAME} AUTO_SET_TARGET_PROPERTIES - RELOCATABLE "plugins" - ) diff --git a/applications/plugins/SofaImplicitField/MarchingCube.cpp b/applications/plugins/SofaImplicitField/MarchingCube.cpp deleted file mode 100644 index 4a7d0098b20..00000000000 --- a/applications/plugins/SofaImplicitField/MarchingCube.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2025 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 -#include -#include - -namespace sofaimplicitfield -{ - -void MarchingCube::generateSurfaceMesh(const double isoval, const double mstep, const double invStep, - const Vec3d& gridmin, const Vec3d& gridmax, - std::function&, std::vector&)> getFieldValueAt, - SeqCoord& tmpPoints, SeqTriangles& tmpTriangles) -{ - int nx = floor((gridmax.x() - gridmin.x()) * invStep) + 1 ; - int ny = floor((gridmax.y() - gridmin.y()) * invStep) + 1 ; - int nz = floor((gridmax.z() - gridmin.z()) * invStep) + 1 ; - - // Marching cubes only works for a grid size larger than two - if( nz < 2 || ny < 2 || nx < 2 ) - return; - - double cx,cy,cz; - int z,mk; - const int *tri; - - // Creates two planes - CubeData c{{-1,-1,-1},0}; - planes.resize(2*nx*ny); - for(size_t i=0;i &positions, std::vector& output, - double mstep, double gridmin_y, double gridmin_x, int ny, int nx, float cz, - std::vector::iterator itDestPlane) - { - for (int i=0, y = 0 ; y < ny ; ++y) - { - double cy = gridmin_y + mstep * y ; - for (int x = 0 ; x < nx ; ++x) - { - double cx = gridmin_x + mstep * x ; - positions[i++].set(cx, cy, cz ); - } - } - getFieldValueAt(positions, output) ; - - for(auto res : output){ - itDestPlane->data = res; - itDestPlane++; - } - }; - - std::vector positions; - std::vector output; - positions.resize(nx*ny); - output.resize(nx*ny); - - fillPlane(positions, output, mstep, gridmin.y(), gridmin.x(), ny, nx, gridmin.z(), P0); - for (z=1; z<=nz; ++z) - { - fillPlane(positions, output, mstep, gridmin.y(), gridmin.x(), ny, nx, gridmin.z() + mstep * z, P1); - - int edgecube[12]; - const int edgepts[12] = {0,1,0,1,0,1,0,1,2,2,2,2}; - typename std::vector::iterator base = planes.begin(); - int ip0 = P0-base; - int ip1 = P1-base; - edgecube[0] = (ip0 -dy); - edgecube[1] = (ip0 ); - edgecube[2] = (ip0 ); - edgecube[3] = (ip0-dx ); - edgecube[4] = (ip1 -dy); - edgecube[5] = (ip1 ); - edgecube[6] = (ip1 ); - edgecube[7] = (ip1-dx ); - edgecube[8] = (ip1-dx-dy); - edgecube[9] = (ip1-dy ); - edgecube[10] = (ip1 ); - edgecube[11] = (ip1-dx ); - - unsigned int di = nx; - for(int y=1; ydata>isoval)^((P1+di-dx)->data>isoval)) - { - (P1+di)->p[0] = addPoint(tmpPoints, 0, pos,gridmin, (P1+di)->data,(P1+di-dx)->data, mstep, isoval); - } - if (((P1+di)->data>isoval)^((P1+di-dy)->data>isoval)) - { - (P1+di)->p[1] = addPoint(tmpPoints, 1, pos,gridmin,(P1+di)->data,(P1+di-dy)->data, mstep, isoval); - } - if (((P1+di)->data>isoval)^((P0+di)->data>isoval)) - { - (P1+di)->p[2] = addPoint(tmpPoints, 2, pos,gridmin,(P1+di)->data,(P0+di)->data, mstep, isoval); - } - - // All points should now be created - if ((P0+di-dx-dy)->data > isoval) mk = 1; - else mk=0; - if ((P0+di -dy)->data > isoval) mk|= 2; - if ((P0+di )->data > isoval) mk|= 4; - if ((P0+di-dx )->data > isoval) mk|= 8; - if ((P1+di-dx-dy)->data > isoval) mk|= 16; - if ((P1+di -dy)->data > isoval) mk|= 32; - if ((P1+di )->data > isoval) mk|= 64; - if ((P1+di-dx )->data > isoval) mk|= 128; - - tri=sofa::helper::MarchingCubeTriTable[mk]; - while (*tri>=0) - { - typename std::vector::iterator b = base+di; - addFace(tmpTriangles, - (b+edgecube[tri[0]])->p[edgepts[tri[0]]], - (b+edgecube[tri[1]])->p[edgepts[tri[1]]], - (b+edgecube[tri[2]])->p[edgepts[tri[2]]], tmpPoints.size()); - tri+=3; - } - ++di; - } - } - std::swap(P0, P1); - } -} - -} diff --git a/applications/plugins/SofaImplicitField/MarchingCube.h b/applications/plugins/SofaImplicitField/MarchingCube.h deleted file mode 100644 index 394a6163b1c..00000000000 --- a/applications/plugins/SofaImplicitField/MarchingCube.h +++ /dev/null @@ -1,83 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2025 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 sofaimplicitfield -{ - -typedef sofa::core::topology::BaseMeshTopology::SeqTriangles SeqTriangles; -typedef sofa::core::topology::BaseMeshTopology::Triangle Triangle; -typedef sofa::type::vector SeqCoord; -using sofa::type::Vec3d; - -class MarchingCube -{ -public: - void generateSurfaceMesh(const double isoval, const double mstep, const double invStep, - const Vec3d& gridmin, const Vec3d& gridmax, - std::function &, std::vector &)> field, - SeqCoord& tmpPoints, SeqTriangles& tmpTriangles); - -private: - /// For each cube, store the vertex indices on each 3 first edges, and the data value - struct CubeData - { - int p[3]; - double data; - }; - - sofa::type::vector planes; - typename sofa::type::vector::iterator P0; /// Pointer to first plane - typename sofa::type::vector::iterator P1; /// Pointer to second plane - - int addPoint(SeqCoord& v, int i, Vec3d pos, const Vec3d& gridmin, double v0, double v1, double step, double iso) - { - pos[i] -= (iso-v0)/(v1-v0); - v.push_back( (pos * step)+gridmin ) ; - return v.size()-1; - } - - int addFace(SeqTriangles& triangles, int p1, int p2, int p3, int nbp) - { - if ((unsigned)p1<(unsigned)nbp && - (unsigned)p2<(unsigned)nbp && - (unsigned)p3<(unsigned)nbp) - { - triangles.push_back(Triangle(p1, p3, p2)); - return triangles.size()-1; - } - else - { - return -1; - } - } -}; - - -} - diff --git a/applications/plugins/SofaImplicitField/README.md b/applications/plugins/SofaImplicitField/README.md deleted file mode 100644 index 73b1bda083b..00000000000 --- a/applications/plugins/SofaImplicitField/README.md +++ /dev/null @@ -1,4 +0,0 @@ -= ImplicitField plugin. - - - diff --git a/applications/plugins/SofaImplicitField/SofaImplicitFieldConfig.cmake.in b/applications/plugins/SofaImplicitField/SofaImplicitFieldConfig.cmake.in deleted file mode 100644 index f7535c7e032..00000000000 --- a/applications/plugins/SofaImplicitField/SofaImplicitFieldConfig.cmake.in +++ /dev/null @@ -1,21 +0,0 @@ -# CMake package configuration file for the SofaImplicitField plugin - -@PACKAGE_GUARD@ -@PACKAGE_INIT@ - -set(SOFAIMPLICITFIELD_HAVE_SOFADISTANCEGRID @SOFAIMPLICITFIELD_HAVE_SOFADISTANCEGRID@) - -find_package(Sofa.Framework QUIET REQUIRED) - -if(SOFAIMPLICITFIELD_HAVE_SOFADISTANCEGRID) - find_package(SofaDistanceGrid QUIET REQUIRED) -endif() - -if(NOT TARGET SofaImplicitField) - include("${CMAKE_CURRENT_LIST_DIR}/SofaImplicitFieldTargets.cmake") -endif() - -check_required_components(SofaImplicitField) -set(SofaImplicitField_LIBRARIES SofaImplicitField) -set(SofaImplicitField_INCLUDE_DIRS @PACKAGE_SOFAIMPLICITFIELD_INCLUDE_DIR@ ${SOFAIMPLICITFIELD_INCLUDE_DIR}) - diff --git a/applications/plugins/SofaImplicitField/SofaImplicitField_test/CMakeLists.txt b/applications/plugins/SofaImplicitField/SofaImplicitField_test/CMakeLists.txt deleted file mode 100644 index b4042f0c308..00000000000 --- a/applications/plugins/SofaImplicitField/SofaImplicitField_test/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.22) - -project(SofaImplicitField_test) - -set(SOURCE_FILES - ImplicitShape_test.cpp -) - - - -add_executable(${PROJECT_NAME} ${SOURCE_FILES}) -target_link_libraries(${PROJECT_NAME} Sofa.Testing SofaImplicitField) - -add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME}) diff --git a/applications/plugins/SofaImplicitField/SofaImplicitField_test/ImplicitShape_test.cpp b/applications/plugins/SofaImplicitField/SofaImplicitField_test/ImplicitShape_test.cpp deleted file mode 100644 index f48bc8cccfb..00000000000 --- a/applications/plugins/SofaImplicitField/SofaImplicitField_test/ImplicitShape_test.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/****************************************************************************** -* 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 General Public License as published by the Free * -* Software Foundation; either version 2 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 General Public License for * -* more details. * -* * -* You should have received a copy of the GNU 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 -using sofa::type::Vec3d ; - -#include -using sofa::component::geometry::SphericalField ; - -namespace -{ - -class SphericalFieldTest : public sofa::testing::BaseTest -{ -public: - bool checkSphericalField(); - bool checkDiscreteGridField(); -}; - - -bool SphericalFieldTest::checkSphericalField() -{ - SphericalField sphere_test; - Vec3d p(1,1,2); - sphere_test.getValue(p) ; - return true; -} - - -TEST_F(SphericalFieldTest, checkSphericalField) { ASSERT_TRUE( checkSphericalField() ); } - -} diff --git a/applications/plugins/SofaImplicitField/components/engine/FieldToSurfaceMesh.cpp b/applications/plugins/SofaImplicitField/components/engine/FieldToSurfaceMesh.cpp deleted file mode 100644 index e42e18467a9..00000000000 --- a/applications/plugins/SofaImplicitField/components/engine/FieldToSurfaceMesh.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2025 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 -using sofa::core::visual::VisualParams ; - -#include -using sofa::core::RegisterObject ; - -#include - -#include "FieldToSurfaceMesh.h" - -namespace sofaimplicitfield::component::engine -{ - -FieldToSurfaceMesh::FieldToSurfaceMesh() - : l_field(initLink("field", "The scalar field to generate a mesh from.")) - , d_step(initData(&d_step,0.1,"step","Step")) - , d_IsoValue(initData(&d_IsoValue,0.0,"isoValue","Iso Value")) - , d_gridMin(initData(&d_gridMin, Vec3d(-1,-1,-1),"min","Grid Min")) - , d_gridMax(initData(&d_gridMax, Vec3d(1,1,1),"max","Grid Max")) - , d_outPoints(initData(&d_outPoints, "points", "position of the tiangles vertex")) - , d_outTriangles(initData(&d_outTriangles, "triangles", "list of triangles")) - , d_debugDraw(initData(&d_debugDraw,false, "debugDraw","Display the extracted surface")) -{ - addUpdateCallback("updateMesh", {&d_step, &d_IsoValue, &d_gridMin, &d_gridMax}, [this](const sofa::core::DataTracker&) - { - checkInputs(); - updateMeshIfNeeded(); - return core::objectmodel::ComponentState::Valid; - }, {&d_outPoints, &d_outTriangles}); - d_outPoints.setGroup("Output"); - d_outTriangles.setGroup("Output"); -} - -FieldToSurfaceMesh::~FieldToSurfaceMesh() -{ -} - -void FieldToSurfaceMesh::init() -{ - if(!l_field.get()) - { - msg_error() << "Missing field to extract surface from"; - d_componentState = core::objectmodel::ComponentState::Invalid; - } - - d_componentState = core::objectmodel::ComponentState::Valid; -} - -void FieldToSurfaceMesh::computeBBox(const core::ExecParams* /* params */, bool /*onlyVisible*/) -{ - f_bbox.setValue({d_gridMin.getValue(), d_gridMax.getValue()}); -} - -void FieldToSurfaceMesh::checkInputs(){ - - auto length = d_gridMax.getValue()-d_gridMin.getValue() ; - auto step = d_step.getValue(); - - // clamp the mStep value to avoid too large grids - if( step < 0.0001 || (length.x() / step > 256) || length.y() / step > 256 || length.z() / step > 256) - { - d_step.setValue( *std::max_element(length.begin(), length.end()) / 256.0 ); - msg_warning() << "step exceeding grid size, clamped to " << d_step.getValue(); - } -} - -void FieldToSurfaceMesh::updateMeshIfNeeded() -{ - sofa::helper::getWriteOnlyAccessor(d_outPoints).clear(); - sofa::helper::getWriteOnlyAccessor(d_outTriangles).clear(); - - double isoval = d_IsoValue.getValue(); - double mstep = d_step.getValue(); - double invStep = 1.0/d_step.getValue(); - - Vec3d gridmin = d_gridMin.getValue() ; - Vec3d gridmax = d_gridMax.getValue() ; - - auto field = l_field.get(); - - if(!field) - return; - - // Clear the previously used buffer - tmpPoints.clear(); - tmpTriangles.clear(); - - marchingCube.generateSurfaceMesh(isoval, mstep, invStep, gridmin, gridmax, - [field](std::vector& positions, std::vector& res){ - int i=0; - for(auto& position : positions) - { - res[i++]=field->getValue(position); - } - }, - tmpPoints, tmpTriangles); - - /// Copy the surface to Sofa topology - d_outPoints.setValue(tmpPoints); - d_outTriangles.setValue(tmpTriangles); - - tmpPoints.clear(); - tmpTriangles.clear(); - - hasChanged = false; - return; -} - -void FieldToSurfaceMesh::draw(const VisualParams* vparams) -{ - if(isComponentStateInvalid()) - return; - - if(!d_debugDraw.getValue()) - return; - - auto drawTool = vparams->drawTool(); - - sofa::helper::ReadAccessor< Data > x = d_outPoints; - sofa::helper::ReadAccessor< Data > triangles = d_outTriangles; - drawTool->setLightingEnabled(true); - - for(const Triangle& triangle : triangles) - { - int a = triangle[0]; - int b = triangle[1]; - int c = triangle[2]; - Vec3d center = (x[a]+x[b]+x[c])*0.333333; - Vec3d pa = (0.9*x[a]+0.1*center) ; - Vec3d pb = (0.9*x[b]+0.1*center) ; - Vec3d pc = (0.9*x[c]+0.1*center) ; - - vparams->drawTool()->drawTriangles({pb,pa,pc}, - type::RGBAColor(0.0,0.0,1.0,1.0)); - } - - if(x.size()>1000){ - drawTool->drawPoints(x, 1.0, type::RGBAColor(1.0,1.0,0.0,0.2)) ; - }else{ - drawTool->drawSpheres(x, 0.01, type::RGBAColor(1.0,1.0,0.0,0.2)) ; - } -} - -// Register in the Factory -void registerFieldToSurfaceMesh(sofa::core::ObjectFactory* factory) -{ - factory->registerObjects(sofa::core::ObjectRegistrationData("Generates a surface mesh from a field function.") - .add< FieldToSurfaceMesh >()); -} - -} diff --git a/applications/plugins/SofaImplicitField/components/engine/FieldToSurfaceMesh.h b/applications/plugins/SofaImplicitField/components/engine/FieldToSurfaceMesh.h deleted file mode 100644 index e92783b020e..00000000000 --- a/applications/plugins/SofaImplicitField/components/engine/FieldToSurfaceMesh.h +++ /dev/null @@ -1,102 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2025 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 -#include - -//////////////////////////////////////////////////////////////////////////////////////////////////// -namespace sofaimplicitfield::component::engine -{ -using namespace sofa; - -typedef sofa::core::topology::BaseMeshTopology::SeqTriangles SeqTriangles; -typedef sofa::core::topology::BaseMeshTopology::Triangle Triangle; -typedef sofa::type::vector VecCoord; - -using sofa::component::geometry::ScalarField; -using sofa::core::visual::VisualParams ; -using BaseObject [[deprecated("Use sofa::core::objectmodel::BaseObject instead.")]] = sofa::core::objectmodel::BaseObject; -using sofa::type::Vec3d ; - -class FieldToSurfaceMesh : public BaseObject -{ -public: - SOFA_CLASS(FieldToSurfaceMesh, BaseObject); - - virtual void init() override ; - virtual void draw(const VisualParams*params) override ; - - double getStep() const { return d_step.getValue(); } - void setStep(double val) { d_step.setValue(val); } - - double getIsoValue() const { return d_IsoValue.getValue(); } - void setIsoValue(double val) { d_IsoValue.setValue(val); } - - const Vec3d& getGridMin() const { return d_gridMin.getValue(); } - void setGridMin(const Vec3d& val) { d_gridMin.setValue(val); } - void setGridMin(double x, double y, double z) { d_gridMin.setValue( Vec3d(x,y,z)); } - - const Vec3d& getGridMax() const { return d_gridMax.getValue(); } - void setGridMax(const Vec3d& val) { d_gridMax.setValue(val); } - void setGridMax(double x, double y, double z) { d_gridMax.setValue( Vec3d(x,y,z)); } - -protected: - SingleLink l_field ; - - Data d_step; - Data d_IsoValue; - - Data< Vec3d > d_gridMin; - Data< Vec3d > d_gridMax; - - /// Output - Data d_outPoints; - Data d_outTriangles; - Data d_debugDraw; - -protected: - FieldToSurfaceMesh() ; - virtual ~FieldToSurfaceMesh() ; - -private: - void computeBBox(const core::ExecParams* /* params */, bool /*onlyVisible*/=false) override; - - void checkInputs(); - - void generateSurfaceMesh(double isoval, double mstep, double invStep, - Vec3d gridmin, Vec3d gridmax, - sofa::component::geometry::ScalarField*); - void updateMeshIfNeeded(); - - bool hasChanged {true} ; - VecCoord tmpPoints; - SeqTriangles tmpTriangles; - - MarchingCube marchingCube; -}; - -} - diff --git a/applications/plugins/SofaImplicitField/components/geometry/BottleField.cpp b/applications/plugins/SofaImplicitField/components/geometry/BottleField.cpp deleted file mode 100644 index 2ed50eb2837..00000000000 --- a/applications/plugins/SofaImplicitField/components/geometry/BottleField.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/****************************************************************************** -* 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 -using sofa::core::RegisterObject ; - -#include "BottleField.h" - -namespace sofa::component::geometry::_BottleField_ -{ - -using sofa::type::Vec2; - -BottleField::BottleField() - : d_inside(initData(&d_inside, false, "inside", "If true the field is oriented inside (resp. outside) the bottle-shaped object. (default = false)")) - , d_radiusSphere(initData(&d_radiusSphere, 1.0, "radius", "Radius of Sphere emitting the field. (default = 1)")) - , d_centerSphere(initData(&d_centerSphere, Vec3d(0.0,0.0,0.0), "center", "Position of the Sphere Surface. (default=0 0 0)" )) - , d_shift(initData(&d_shift, 1.0, "shift", "How much the top ellipsoid is shifted from the bottom sphere. (default=1)" )) - , d_ellipsoidRadius(initData(&d_ellipsoidRadius, 1.0, "ellipsoidRadius", "Radius of the ellipsoid whose intersection with the sphere is taken off" )) - , d_excentricity(initData(&d_excentricity, 1.0, "excentricity", "excentricity of ellipsoid" )) -{ - init(); - addUpdateCallback("myUpdateCallback", {&d_inside, &d_radiusSphere, &d_centerSphere, &d_shift, &d_ellipsoidRadius, &d_excentricity}, [this](const core::DataTracker& t) - { - SOFA_UNUSED(t); - this->init(); - return sofa::core::objectmodel::ComponentState::Valid; - }, {}); -} - -void BottleField::init() -{ - m_inside = d_inside.getValue(); - m_center = d_centerSphere.getValue(); - m_radius = d_radiusSphere.getValue(); - m_shift = d_shift.getValue(); - m_ellipsoidRadius = d_ellipsoidRadius.getValue(); - m_excentricity = d_excentricity.getValue(); -} - -void BottleField::reinit() -{ - init(); -} - -double BottleField::outerLength(Vec3d& Pos) -{ - return sqrt((Pos[0] - m_center[0])*(Pos[0] - m_center[0]) + - (Pos[1] - m_center[1])*(Pos[1] - m_center[1]) + - (Pos[2] - m_center[2])*(Pos[2] - m_center[2])); -} - -double BottleField::innerLength(Vec3d& Pos) -{ - return sqrt(m_excentricity*(Pos[0] - m_center[0])*(Pos[0] - m_center[0]) + - (Pos[1] - (m_center[1]+m_shift))*(Pos[1] - (m_center[1]+m_shift)) + - m_excentricity*(Pos[2] - m_center[2])*(Pos[2] - m_center[2])); -} - -double BottleField::getValue(Vec3d& Pos, int& domain) -{ - SOFA_UNUSED(domain) ; - double resultSphereOuter = this->outerLength(Pos) - m_radius ; - double resultEllipsoidInner = this->innerLength(Pos) - m_ellipsoidRadius; - - double result = std::max(resultSphereOuter,-resultEllipsoidInner); - - if(m_inside) - result = -result; - - return result; -} - -Vec3d BottleField::getGradient(Vec3d &Pos, int &domain) -{ - SOFA_UNUSED(domain); - Vec3d g; - - double LsphereOuter = this->outerLength(Pos) ; - double LEllipsoidInner = this->innerLength(Pos) ; - - if (LsphereOuter - m_radius > - (LEllipsoidInner- m_ellipsoidRadius)){ - g[0] = (Pos[0] - m_center[0])/LsphereOuter; - g[1] = (Pos[1] - m_center[1])/LsphereOuter; - g[2] = (Pos[2] - m_center[2])/LsphereOuter; - } - else - { - g[0] = -m_excentricity*(Pos[0] - m_center[0])/LEllipsoidInner; - g[1] = -(Pos[1] - (m_center[1]+m_shift))/LEllipsoidInner; - g[2] = -m_excentricity*(Pos[2] - m_center[2])/LEllipsoidInner; - } - - - if (m_inside) - { - g[0] = -g[0]; - g[1] = -g[1]; - g[2] = -g[2]; - } - - return g; -} - -void BottleField::getHessian(Vec3d &Pos, Mat3x3& h) -{ - double LsphereOuter = this->outerLength(Pos) ; - double LEllipsoidInner = this->innerLength(Pos) ; - - if (LsphereOuter - m_radius > - (LEllipsoidInner- m_ellipsoidRadius)) - { - double LsphereOuterSquare = LsphereOuter*LsphereOuter; - double LsphereOuterCube = LsphereOuter*LsphereOuter*LsphereOuter; - h[0][0] = ( LsphereOuter - (Pos[0] - m_center[0])*(Pos[0] - m_center[0])/LsphereOuter )/LsphereOuterSquare ; - h[1][1] = ( LsphereOuter - (Pos[1] - m_center[1])*(Pos[1] - m_center[1])/LsphereOuter )/LsphereOuterSquare ; - h[2][2] = ( LsphereOuter - (Pos[2] - m_center[2])*(Pos[2] - m_center[2])/LsphereOuter )/LsphereOuterSquare ; - - h[0][1] = h[1][0] = - (Pos[0] - m_center[0])*(Pos[1] - m_center[1]) / LsphereOuterCube; - h[0][2] = h[2][0] = - (Pos[0] - m_center[0])*(Pos[2] - m_center[2]) / LsphereOuterCube; - h[1][2] = h[2][1] = - (Pos[2] - m_center[2])*(Pos[1] - m_center[1]) / LsphereOuterCube; - } - else - { - double LEllipsoidInnerSquare = LEllipsoidInner*LEllipsoidInner; - double LEllipsoidInnerCube = LEllipsoidInner*LEllipsoidInner*LEllipsoidInner; - h[0][0] = -m_excentricity*(LEllipsoidInner - m_excentricity*(Pos[0] - m_center[0])*(Pos[0] - m_center[0])/LEllipsoidInner )/LEllipsoidInnerSquare ; - h[1][1] = -(LEllipsoidInner - (Pos[1] - (m_center[1]+m_shift))*(Pos[1] - (m_center[1]+m_shift))/LEllipsoidInner )/LEllipsoidInnerSquare ; - h[2][2] = -m_excentricity*(LEllipsoidInner - m_excentricity*(Pos[2] - m_center[2])*(Pos[2] - m_center[2])/LEllipsoidInner )/LEllipsoidInnerSquare ; - - h[0][1] = h[1][0] = m_excentricity*(Pos[0] - m_center[0])*(Pos[1] - (m_center[1]+m_shift)) / LEllipsoidInnerCube; - h[0][2] = h[2][0] = m_excentricity*m_excentricity*(Pos[0] - m_center[0])*(Pos[2] - m_center[2]) / LEllipsoidInnerCube; - h[1][2] = h[2][1] = m_excentricity*(Pos[2] - m_center[2])*(Pos[1] - (m_center[1]+m_shift)) / LEllipsoidInnerCube; - } - - if (m_inside) - { - for (unsigned int i=0; i<3; i++) - for (unsigned int j=0; j<3; j++) - h[i][j] = -h[i][j]; - } - - return; -} - -// Register in the Factory -void registerBottleField(sofa::core::ObjectFactory* factory) -{ - factory->registerObjects(sofa::core::ObjectRegistrationData("A bottle implicit field.") - .add< BottleField >()); -} - -} // namespace sofa::component::geometry::_BottleField_ diff --git a/applications/plugins/SofaImplicitField/components/geometry/BottleField.h b/applications/plugins/SofaImplicitField/components/geometry/BottleField.h deleted file mode 100644 index 1f62df0c172..00000000000 --- a/applications/plugins/SofaImplicitField/components/geometry/BottleField.h +++ /dev/null @@ -1,84 +0,0 @@ -/****************************************************************************** -* 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 "ScalarField.h" -#include -namespace sofa::component::geometry -{ - -namespace _BottleField_ -{ - -using sofa::type::Vec3d; -using sofa::type::Mat3x3; - -/** - * This component emulates an implicit field shaped by a sphere with a hole made by an ellispsoid. The result may look like some kind of bottle or vase. -*/ - -class SOFA_SOFAIMPLICITFIELD_API BottleField : public ScalarField -{ -public: - SOFA_CLASS(BottleField, ScalarField); - -public: - BottleField() ; - ~BottleField() override { } - - /// Inherited from BaseObject - void init() override ; - void reinit() override ; - - /// Inherited from ScalarField. - double getValue(Vec3d& Pos, int &domain) override ; - Vec3d getGradient(Vec3d &Pos, int& domain) override ; - void getHessian(Vec3d &Pos, Mat3x3& h) override; - - double outerLength(Vec3d& Pos); - double innerLength(Vec3d& Pos); - - using ScalarField::getValue ; - using ScalarField::getGradient ; - using ScalarField::getValueAndGradient ; - - Data d_inside; ///< If true the field is oriented inside (resp. outside) the bottle-shaped object. (default = false) - Data d_radiusSphere; ///< Radius of Sphere emitting the field. (default = 1) - Data d_centerSphere; ///< Position of the Sphere Surface. (default=0 0 0) - Data d_shift; ///< How much the top ellipsoid is shifted from the bottom sphere. (default=1) - Data d_ellipsoidRadius; ///< Radius of the ellipsoid whose intersection with the sphere is taken off - Data d_excentricity; ///< excentricity of ellipsoid -protected: - Vec3d m_center; - double m_radius; - bool m_inside; - double m_shift; - double m_ellipsoidRadius; - double m_excentricity; -}; - -} //namespace _BottleField_ - -using sofa::component::geometry::_BottleField_::BottleField; - -} //namespace sofa::component::geometry - diff --git a/applications/plugins/SofaImplicitField/components/geometry/DiscreteGridField.cpp b/applications/plugins/SofaImplicitField/components/geometry/DiscreteGridField.cpp deleted file mode 100644 index fa6949c0928..00000000000 --- a/applications/plugins/SofaImplicitField/components/geometry/DiscreteGridField.cpp +++ /dev/null @@ -1,376 +0,0 @@ -/****************************************************************************** -* 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 -using sofa::core::RegisterObject ; - -#include "DiscreteGridField.h" - - -namespace sofa::component::geometry::_discretegrid_ -{ - -/** -DiscreteGridField::DiscreteGridField() - : in_filename(initData(&in_filename,"filename","filename")) - , in_nx(initData(&in_nx,0,"nx","in_nx")) - , in_ny(initData(&in_ny,0,"ny","in_ny")) - , in_nz(initData(&in_nz,0,"nz","in_nz")) - , in_scale(initData(&in_scale,0.0,"scale","in_scale")) - , in_sampling(initData(&in_sampling,0.0,"sampling","in_sampling")) -{ -} - - - -void DiscreteGridField::init() -{ - if(in_nx.getValue()==0 && in_nz.getValue()==0 && in_nz.getValue()==0) { - d_componentState.setValue(ComponentState::Invalid); - msg_error() << "uninitialized grid"; - } - else if(in_filename.isSet() == false) { - d_componentState.setValue(ComponentState::Invalid) - msg_error() << "unset filename"; - } - else { - pmin.set(0,0,-5.0); - pmax.set(27,27,5.0); - loadGrid(in_scale.getValue(),in_sampling.getValue(),in_nx.getValue(),in_ny.getValue(),in_nz.getValue(),pmin,pmax); - } - - d_componentState.setValue(ComponentState::Valid) -} -*/ - -DiscreteGridField::DiscreteGridField() - : ScalarField(), - d_distanceMapHeader( initData( &d_distanceMapHeader, "file", "MHD file for the distance map" ) ), - d_maxDomains( initData( &d_maxDomains, 1, "maxDomains", "Number of domains available for caching" ) ), - dx( initData( &dx, 0.0, "dx", "x translation" ) ), - dy( initData( &dy, 0.0, "dy", "y translation" ) ), - dz( initData( &dz, 0.0, "dz", "z translation" ) ) -{ - m_usedDomains = 0; - m_imgData = nullptr; -} - - -DiscreteGridField::~DiscreteGridField() -{ - if (m_imgData) - { - delete[] m_imgData; - m_imgData = nullptr; - } -} - - -///used to set a name in tests -void DiscreteGridField::setFilename(const std::string& name) -{ - d_distanceMapHeader.setValue(name); -} - - -void DiscreteGridField::init() -{ - m_domainCache.resize( d_maxDomains.getValue() ); - bool ok = loadGridFromMHD( d_distanceMapHeader.getFullPath().c_str() ); - if (ok) printf( "Successfully loaded distance map.\n" ); -} - - -bool DiscreteGridField::loadGridFromMHD( const char *filename ) -{ - m_imgMin[0]=m_imgMin[1]=m_imgMin[2] = 0; - m_spacing[0]=m_spacing[1]=m_spacing[2] = 1; - m_imgSize[0]=m_imgSize[1]=m_imgSize[2] = 0; - - char buffer[1024]; - char *value; - bool dataFileSpecified = false; - float f0, f1, f2; - int i0, i1, i2; - char dataFile[1024]; - - // read header file - std::ifstream header( filename ); - if (!header.is_open()) return false; - while (!header.eof()) - { - header.getline( buffer, 1024 ); - if (strncmp( buffer, "ObjectType", 10 ) == 0) - { - value = strchr( buffer, '=' )+1; while (*value==' ') value++; - if (strncmp( value, "Image", 5 ) != 0) - { - printf( "ERROR: Object is no image.\n" ); - return false; - } - } - else if (strncmp( buffer, "NDims", 5 ) == 0) - { - value = strchr( buffer, '=' )+1; while (*value==' ') value++; - if (*value != '3') - { - printf( "ERROR: Wrong number of dimensions.\n" ); - return false; - } - } - else if (strncmp( buffer, "BinaryData ", 11 ) == 0 || strncmp( buffer, "BinaryData=", 11 ) == 0) - { - value = strchr( buffer, '=' )+1; while (*value==' ') value++; - if (strncmp( value, "True", 4 ) != 0) - { - printf( "ERROR: Data is not binary.\n" ); - return false; - } - } - else if (strncmp( buffer, "CompressedData", 14 ) == 0) - { - value = strchr( buffer, '=' )+1; while (*value==' ') value++; - if (strncmp( value, "False", 5 ) != 0) - { - printf( "ERROR: Data is compressed.\n" ); - return false; - } - } - else if (strncmp( buffer, "TransformMatrix", 15 ) == 0) - { - value = strchr( buffer, '=' )+1; while (*value==' ') value++; - if (strncmp( value, "1 0 0 0 1 0 0 0 1", 17 ) != 0) - { - printf( "ERROR: Unsupported transform matrix.\n" ); - return false; - } - } - else if (strncmp( buffer, "Offset", 6 ) == 0) - { - value = strchr( buffer, '=' )+1; while (*value==' ') value++; - sscanf( value, "%f %f %f", &f0, &f1, &f2 ); - m_imgMin[0]=f0; m_imgMin[1]=f1; m_imgMin[2]=f2; - printf( "Image offset = %f %f %f\n", m_imgMin[0], m_imgMin[1], m_imgMin[2] ); - } - else if (strncmp( buffer, "ElementSpacing", 14 ) == 0) - { - value = strchr( buffer, '=' )+1; while (*value==' ') value++; - sscanf( value, "%f %f %f", &f0, &f1, &f2 ); - m_spacing[0]=f0; m_spacing[1]=f1; m_spacing[2]=f2; - printf( "Image spacing = %f %f %f\n", m_spacing[0], m_spacing[1], m_spacing[2] ); - } - else if (strncmp( buffer, "DimSize", 7 ) == 0) - { - value = strchr( buffer, '=' )+1; while (*value==' ') value++; - sscanf( value, "%d %d %d", &i0, &i1, &i2 ); - m_imgSize[0]=i0; m_imgSize[1]=i1; m_imgSize[2]=i2; - printf( "Image size = %i %i %i\n", m_imgSize[0], m_imgSize[1], m_imgSize[2] ); - } - else if (strncmp( buffer, "ElementType", 11 ) == 0) - { - value = strchr( buffer, '=' )+1; while (*value==' ') value++; - if (strncmp( value, "MET_FLOAT", 9) != 0) - { - printf( "ERROR: Datatype is not supported.\n" ); - return false; - } - } - /* Don't allow variable names for problems with correct file paths! - else if (strncmp( buffer, "ElementDataFile", 11 ) == 0) { - value = strchr( buffer, '=' )+1; while (*value==' ') value++; - strncpy( dataFile, value, sizeof(dataFile) - 1 ); - dataFile[sizeof(dataFile) - 1] = '\0'; - dataFileSpecified = true; - }*/ - } - header.close(); - - // init remaining variables - for (int d=0; d<3; d++) - { - m_scale[d] = 1.0/m_spacing[d]; - m_imgMax[d] = m_imgMin[d] + (double)(m_imgSize[d]-1)*m_spacing[d]; - } - m_deltaOfs[0] = 0; - m_deltaOfs[1] = 1; - m_deltaOfs[2] = m_imgSize[0]; - m_deltaOfs[3] = m_imgSize[0]+1; - unsigned int sliceSize = m_imgSize[0]*m_imgSize[1]; - m_deltaOfs[4] = m_deltaOfs[0] + sliceSize; - m_deltaOfs[5] = m_deltaOfs[1] + sliceSize; - m_deltaOfs[6] = m_deltaOfs[2] + sliceSize; - m_deltaOfs[7] = m_deltaOfs[3] + sliceSize; - - // read data file - if (!dataFileSpecified) - { - // change extension to .raw - strncpy( dataFile, filename, sizeof(dataFile) - 1 ); - dataFile[sizeof(dataFile) - 1] = '\0'; - size_t lenWithoutExt = strlen( filename ); - if (lenWithoutExt >= 3) - lenWithoutExt -= 3; - if (lenWithoutExt < sizeof(dataFile) - 4) - { - dataFile[lenWithoutExt] = '\0'; - strncat( dataFile, "raw", sizeof(dataFile) - lenWithoutExt - 1 ); - } - else - { - printf( "Warning: filename too long to replace extension, keeping '%s'\n", dataFile ); - } - } - std::ifstream data( dataFile, std::ios_base::binary|std::ios_base::in ); - if (!data.is_open()) return false; - unsigned int numVoxels = m_imgSize[0]*m_imgSize[1]*m_imgSize[2]; - m_imgData = new float[numVoxels]; - data.read( (char*)m_imgData, numVoxels*sizeof(float) ); - if (data.bad()) return false; - data.close(); - return true; -} - -void DiscreteGridField::updateCache( DomainCache *cache, Vec3d& pos ) -{ - cache->insideImg = true; - for (int d=0; d<3; d++) if (pos[d]=m_imgMax[d]) - { - cache->insideImg = false; - break; - } - if (cache->insideImg) - { - int voxMinPos[3]; - for (int d=0; d<3; d++) - { - voxMinPos[d] = (int)(m_scale[d] * (pos[d]-m_imgMin[d])); - cache->bbMin[d] = m_spacing[d]*(double)voxMinPos[d] + m_imgMin[d]; - cache->bbMax[d] = cache->bbMin[d] + m_spacing[d]; - } - unsigned int ofs = voxMinPos[0] + m_imgSize[0]*(voxMinPos[1] + m_imgSize[1]*voxMinPos[2]); - cache->val[0] = m_imgData[ofs]; - for (int i=1; i<8; i++) cache->val[i] = m_imgData[ofs+m_deltaOfs[i]]; - } - else - { - // init bounding box to be as large as possible to prevent unnecessary cache updates while outside image - const double MIN=-10e6, MAX=10e6; - int voxMappedPos[3]; - for (int d=0; d<3; d++) - { - if (pos[d] < m_imgMin[d]) - { - cache->bbMin[d] = MIN; - cache->bbMax[d] = m_imgMin[d]; - voxMappedPos[d] = 0; - } - else if (pos[d] >= m_imgMax[d]) - { - cache->bbMin[d] = m_imgMax[d]; - cache->bbMax[d] = MAX; - voxMappedPos[d] = m_imgSize[d]-1; - } - else - { - cache->bbMin[d] = MIN; - cache->bbMax[d] = MAX; - voxMappedPos[d] = (int)(m_scale[d] * (pos[d]-m_imgMin[d])); - } - } - unsigned int ofs = voxMappedPos[0] + m_imgSize[0]*(voxMappedPos[1] + m_imgSize[1]*voxMappedPos[2]); - // if cache lies outside image, the returned distance is not updated anymore, instead this boundary value is returned - cache->val[0] = m_imgData[ofs] + m_spacing[0]+m_spacing[1]+m_spacing[2]; - } -} - - -int DiscreteGridField::getNextDomain() -{ - // while we have free domains always return the next one, afterwards always use the last one - if (m_usedDomains < (int)m_domainCache.size()) m_usedDomains++; - return m_usedDomains-1; -} - - -double DiscreteGridField::getValue( Vec3d &transformedPos, int &domain ) -{ - // use translation - Vec3d pos; - pos[0] = transformedPos[0] - dx.getValue(); - pos[1] = transformedPos[1] - dy.getValue(); - pos[2] = transformedPos[2] - dz.getValue(); - // find cache domain and check if it needs an update - DomainCache *cache; - if (domain < 0) - { - domain = getNextDomain(); - cache = &(m_domainCache[domain]); - updateCache( cache, pos ); - } - else - { - cache = &(m_domainCache[domain]); - for (int d=0; d<3; d++) - { - if (pos[d]bbMin[d] || pos[d]>cache->bbMax[d]) - { - updateCache( cache, pos ); - break; - } - } - } - - // if cache lies outside image, the returned distance is not updated anymore, instead this boundary value is returned - if (!cache->insideImg) return cache->val[0]; - - // use trilinear interpolation on cached cube - double weight[3]; - for (int d=0; d<3; d++) - { - weight[d] = m_scale[d] * (pos[d]-cache->bbMin[d]); - } - double d = weight[0]*weight[1]; - double c = weight[1] - d; - double b = weight[0] - d; - double a = (1.0-weight[1]) - b; - double res = ( cache->val[0]*a + cache->val[1]*b + cache->val[2]*c + cache->val[3]*d ) * (1.0-weight[2]) - + ( cache->val[4]*a + cache->val[5]*b + cache->val[6]*c + cache->val[7]*d ) * weight[2]; - - return res; -} - - -double DiscreteGridField::getValue( Vec3d &transformedPos ) -{ - static int domain=-1; - return getValue( transformedPos, domain ); -} - -// Register in the Factory -void registerDiscreteGridField(sofa::core::ObjectFactory* factory) -{ - factory->registerObjects(sofa::core::ObjectRegistrationData("A discrete scalar field from a regular grid storing field value with interpolation.") - .add< DiscreteGridField >()); -} - -} ///namespace sofa::component::geometry::_discretegrid_ diff --git a/applications/plugins/SofaImplicitField/components/geometry/DiscreteGridField.h b/applications/plugins/SofaImplicitField/components/geometry/DiscreteGridField.h deleted file mode 100644 index a98e897d4c3..00000000000 --- a/applications/plugins/SofaImplicitField/components/geometry/DiscreteGridField.h +++ /dev/null @@ -1,99 +0,0 @@ -/****************************************************************************** -* 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 * -******************************************************************************/ -#ifndef SOFAIMPLICITFIELD_COMPONENT_DISCRETEGRIDFIELD_H -#define SOFAIMPLICITFIELD_COMPONENT_DISCRETEGRIDFIELD_H -#include - -#include -#include - -namespace sofa -{ - -namespace component -{ - -namespace geometry -{ - -namespace _discretegrid_ -{ - -using sofa::type::Vec3d; - -class SOFA_SOFAIMPLICITFIELD_API DomainCache -{ -public: - bool insideImg; // shows if the domain lies inside the valid image region or outside - Vec3d bbMin, bbMax; // bounding box (min and max) of the domain - double val[8]; // corner values of the domain -}; - -class SOFA_SOFAIMPLICITFIELD_API DiscreteGridField : public virtual ScalarField -{ - -public: - SOFA_CLASS(DiscreteGridField, ScalarField); - -public: - DiscreteGridField(); - ~DiscreteGridField() override; - - void init() override; - - virtual double getValue( Vec3d &transformedPos ); - double getValue( Vec3d &transformedPos, int &domain ) override; - int getDomain( Vec3d &pos, int ref_domain ) override { (void)pos; return ref_domain; } - - void setFilename(const std::string& filename) ; - bool loadGridFromMHD( const char *filename ) ; - - void updateCache( DomainCache *cache, Vec3d& pos ); - int getNextDomain(); - - sofa::core::objectmodel::DataFileName d_distanceMapHeader; - Data< int > d_maxDomains; ///< Number of domains available for caching - Data< double > dx; ///< x translation - Data< double > dy; ///< y translation - Data< double > dz; ///< z translation - - int m_usedDomains; // number of domains already given out - unsigned int m_imgSize[3]; // number of voxels - double m_spacing[3]; // physical distance between two neighboring voxels - double m_scale[3]; // (1/spacing) - double m_imgMin[3], m_imgMax[3]; // physical locations of the centers of both corner voxels - float *m_imgData; // raw data - unsigned int m_deltaOfs[8]; // offsets to define 8 corners of cube for interpolation - std::vector m_domainCache; -}; - -} /// namespace _discretegrid_ -using _discretegrid_::DiscreteGridField ; - -} /// namespace geometry - -} /// namespace component - -} /// namespace sofa - -#endif - diff --git a/applications/plugins/SofaImplicitField/components/geometry/ScalarField.cpp b/applications/plugins/SofaImplicitField/components/geometry/ScalarField.cpp deleted file mode 100644 index 9c0323bbfd8..00000000000 --- a/applications/plugins/SofaImplicitField/components/geometry/ScalarField.cpp +++ /dev/null @@ -1,291 +0,0 @@ -/****************************************************************************** -* 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 * -******************************************************************************/ -/****************************************************************************** -* Contributors: -* - damien.marchal@univ-lille.fr -* - olivier.goury@inria.fr -******************************************************************************/ - - -#include -#include "ScalarField.h" -namespace sofa -{ - -namespace component -{ - -namespace geometry -{ - -namespace _scalarfield_ -{ - -void ScalarField::init() -{ - d_componentState.setValue(core::objectmodel::ComponentState::Valid); -} - -Vec3d ScalarField::getGradientByFinitDifference(Vec3d& pos, int& i) -{ - Vec3d Result; - double epsilon = d_epsilon.getValue(); - pos[0] += epsilon; - Result[0] = getValue(pos, i); - pos[0] -= epsilon; - pos[1] += epsilon; - Result[1] = getValue(pos, i); - pos[1] -= epsilon; - pos[2] += epsilon; - Result[2] = getValue(pos, i); - pos[2] -= epsilon; - - double v = getValue(pos, i); - Result[0] = (Result[0]-v)/epsilon; - Result[1] = (Result[1]-v)/epsilon; - Result[2] = (Result[2]-v)/epsilon; - - return Result; -} - -Vec3d ScalarField::getGradient(Vec3d& pos, int& i) -{ - return getGradientByFinitDifference(pos, i); -} - -void ScalarField::getValueAndGradient(Vec3d& pos, double &value, Vec3d& grad, int& domain) -{ - value = getValue(pos,domain); - grad = getGradient(pos,domain); -} - -void ScalarField::getHessianByCentralFiniteDifference(const Vec3d& x, const double dx, - Mat3x3& hessian) -{ - /// Centrale Finite difference using only function's value - /// implemented from https://v8doc.sas.com/sashtml/ormp/chap5/sect28.htm - /// Second-order derivatives based on function calls only (Abramowitz and Stegun 1972, p. 884): - Vec3d e[3] = {Vec3d{dx,0.0,0.0}, - Vec3d{0.0,dx,0.0}, - Vec3d{0.0,0.0,dx}}; - double invTerm = 1.0 / (4.0 * dx * dx); - Vec3d tmpX; - for(unsigned int i=0;i<3;i++) - { - for(unsigned int j=0;j<3;j++) - { - tmpX = x + e[i] + e[j] ; - double p1 = this->getValue(tmpX); - - tmpX = x + e[i] - e[j]; - double p2 = -this->getValue(tmpX); - - tmpX = x - e[i] + e[j]; - double p3 = - this->getValue(tmpX); - - tmpX = x - e[i] - e[j]; - double p4 = +this->getValue(tmpX); - hessian[i][j] = (p1 + p2 + p3 + p4) * invTerm; - } - } -} - - -void ScalarField::getHessian(Vec3d &Pos, Mat3x3& h) -{ - getHessianByCentralFiniteDifference(Pos, d_epsilon.getValue(), h); -} - -bool ScalarField::computeSegIntersection(Vec3d& posInside, Vec3d& posOutside, Vec3d& intersecPos, int i) -{ - - - double tolerance = 0.00001; // tolerance sur la précision m - - float a = (float)getValue(posInside, i); - float b = (float)getValue(posOutside, i); - - if (a*b>0) - { - msg_warning()<<"les deux points sont du même côté de la surface \n"; - return false; - } - - if(b<0) - { - msg_warning()<<"posOutside is inside"; - return false; - } - - - - Vec3d Seg = posInside-posOutside; - if (Seg.norm() < tolerance) // TODO : macro on the global precision - { - intersecPos = posOutside; - return true; - } - - // we start on posInside and search for the first point outside with a step given by scale // - int count=0; - Vec3d step = Seg; - double val = b; - intersecPos = posOutside; - - double step_incr=0.1; - - while(step.norm()> tolerance && count < 1000) - { - step *= step_incr; - - while (val >= 0 && count < (1/step_incr + 1)) - { - count++; - intersecPos += step; - val = getValue(intersecPos, i); - } - - // we restart with more precision - intersecPos -=step; - - val = getValue(intersecPos, i); - if (val < 0) - msg_warning()<<": val is negative\n" ; - } - - if (count>998) - { - msg_error()<<"in computeSegIntersection: Seg : "<0) - { - posInside = point; - while(value>0 && count < 30) - { - count++; - posInside -= dir * step; - value = getValue(posInside, i); - } - posOutside = point; - } - else - { - posOutside = point; - while(value<0 && count < 30) - { - count++; - posOutside += dir * step; - value = getValue(posOutside, i); - } - posInside = point; - - } - if (count == 30) - { - dmsg_warning() << "no projection found in ImplSurf::projectPointonSurface(Vec3d& point, Vec3d& dir)"; - return false; - } - return computeSegIntersection(posInside, posOutside, point, i); - - -} - - -bool ScalarField::projectPointOutOfSurface(Vec3d& point, int i, Vec3d& dir, double &dist_out) -{ - - - if (projectPointonSurface2(point, i, dir)) - { - Vec3d grad = getGradient(point, i); - grad.normalize(); - point += grad*dist_out; - return true; - } - dmsg_warning() << " problem while computing 'projectPointOutOfSurface" ; - return false; - - -} - -} /// namespace _scalarfield_ - -} /// namespace geometry - -} /// namespace component - -} /// namespace sofa diff --git a/applications/plugins/SofaImplicitField/components/geometry/ScalarField.h b/applications/plugins/SofaImplicitField/components/geometry/ScalarField.h deleted file mode 100644 index d676dd2e8d4..00000000000 --- a/applications/plugins/SofaImplicitField/components/geometry/ScalarField.h +++ /dev/null @@ -1,143 +0,0 @@ -/****************************************************************************** -* 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 * -******************************************************************************/ -/****************************************************************************** -* Contributors: -* - damien.marchal@univ-lille.fr -* - olivier.goury@inria.fr -******************************************************************************/ - -#ifndef SOFAIMPLICITFIELD_COMPONENT_SCALARFIELD_H -#define SOFAIMPLICITFIELD_COMPONENT_SCALARFIELD_H -#include - -#include -#include - -namespace sofa::component::geometry -{ - -namespace _scalarfield_ -{ - -using BaseObject [[deprecated("Use sofa::core::objectmodel::BaseObject instead.")]] = sofa::core::objectmodel::BaseObject; -using sofa::type::Vec3d ; -using sofa::type::Mat3x3 ; - -////////////////// /////////////// -class SOFA_SOFAIMPLICITFIELD_API ScalarField : public BaseObject -{ -public: - SOFA_CLASS(ScalarField, BaseObject); - -public: - void init() override; - - /// Compute the gradient using a first order finite-difference scheme. - /// This is of lower precision compared to analytical gradient computed by derivating - /// the equations. - Vec3d getGradientByFinitDifference(Vec3d& pos, int& domain) ; - void getHessianByCentralFiniteDifference(const Vec3d& x, const double dx, - Mat3x3& hessian); - virtual int getDomain(Vec3d& pos, int domain) { - SOFA_UNUSED(pos); - SOFA_UNUSED(domain); - return -1; - } - - virtual double getValue(Vec3d& pos, int& domain) = 0; - inline double getValue(Vec3d& pos) { int domain=-1; return getValue(pos,domain); } - - /// By default compute the gradient using a first order finite difference approache - /// If you have analytical derivative don't hesitate to override this function. - virtual Vec3d getGradient(Vec3d& pos, int& domain); - inline Vec3d getGradient(Vec3d& pos) {int domain=-1; return getGradient(pos,domain); } - virtual void getHessian(Vec3d &Pos, Mat3x3& h); - - /// Returns the value and the gradiant by evaluating one after an other. - /// For some computation it is possible to implement more efficiently the computation - /// By factoring the computing of the two...if you can do this please override this function. - virtual void getValueAndGradient(Vec3d& pos, double &value, Vec3d& grad, int& domain) ; - inline void getValueAndGradient(Vec3d& pos, double &value, Vec3d& grad) - { - int domain=-1; - return getValueAndGradient(pos,value,grad,domain); - } - - virtual bool computeSegIntersection(Vec3d& posInside, Vec3d& posOutside, Vec3d& intersecPos, int domain=-1); - bool computeSegIntersection(Vec3d& posInside, double valInside, Vec3d& gradInside, - Vec3d& posOutside, double valOutside, Vec3d& gradOutside, - Vec3d& intersecPos, int domain=-1) - { - (void)valInside; - (void)gradInside; - (void)valOutside; - (void)gradOutside; - return computeSegIntersection(posInside, posOutside, intersecPos, domain); - } - - virtual void projectPointonSurface(Vec3d& point, int i=-1); - void projectPointonSurface(Vec3d& point, double value, Vec3d& grad, int domain=-1) - { - (void)value; - (void)grad; - projectPointonSurface(point, domain); - } - - // TODO mettre les paramètres step=0.1 & countMax=30 en paramètre - virtual bool projectPointonSurface2(Vec3d& point, int i, Vec3d& dir); - bool projectPointonSurface2(Vec3d& point, int domain=-1) - { - Vec3d dir = Vec3d(0,0,0); - return projectPointonSurface2(point, domain, dir); - } - - virtual bool projectPointOutOfSurface(Vec3d& point, int i, Vec3d& dir, double &dist_out); - bool projectPointOutOfSurface(Vec3d& point, int domain=-1) - { - Vec3d dir; - double dist_out = 0.0; - return projectPointOutOfSurface(point, domain, dir, dist_out); - } - - -protected: - Data< double > d_epsilon; ///< Tolerance when evaluating the gradient and/or the hessian of the implicit surface numerically - ScalarField( ) - : d_epsilon(initData(&d_epsilon,0.00001,"epsilon","Tolerance when evaluating the gradient and/or the hessian of the implicit surface numerically")) - { - } - ~ScalarField() override { } - -private: - ScalarField(const ScalarField& n) ; - ScalarField& operator=(const ScalarField& n) ; -}; - - -} /// namespace _scalarfield_ - -using _scalarfield_::ScalarField ; - -} /// namespace sofa::component::geometry - -#endif - diff --git a/applications/plugins/SofaImplicitField/components/geometry/SphericalField.cpp b/applications/plugins/SofaImplicitField/components/geometry/SphericalField.cpp deleted file mode 100644 index 14b0c52c6f0..00000000000 --- a/applications/plugins/SofaImplicitField/components/geometry/SphericalField.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/****************************************************************************** -* 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 -using sofa::core::RegisterObject ; - -#include "SphericalField.h" - -namespace sofa::component::geometry::_sphericalfield_ -{ - -SphericalField::SphericalField() - : d_inside(initData(&d_inside, false, "inside", "If true the field is oriented inside (resp. outside) the sphere. (default = false)")) - , d_radiusSphere(initData(&d_radiusSphere, 1.0, "radius", "Radius of Sphere emitting the field. (default = 1)")) - , d_centerSphere(initData(&d_centerSphere, Vec3d(0.0,0.0,0.0), "center", "Position of the Sphere Surface. (default=0 0 0)" )) -{init(); - } - -void SphericalField::init() -{ - m_inside = d_inside.getValue(); - m_center = d_centerSphere.getValue(); - m_radius = d_radiusSphere.getValue(); -} - -void SphericalField::reinit() -{ - init(); -} - -double SphericalField::getValue(Vec3d& Pos, int& domain) -{ - SOFA_UNUSED(domain) ; - double result = (Pos[0] - m_center[0])*(Pos[0] - m_center[0]) + - (Pos[1] - m_center[1])*(Pos[1] - m_center[1]) + - (Pos[2] - m_center[2])*(Pos[2] - m_center[2]) - - m_radius * m_radius ; - if(m_inside) - result = -result; - - return result; -} - -Vec3d SphericalField::getGradient(Vec3d &Pos, int &domain) -{ - SOFA_UNUSED(domain); - Vec3d g; - if (m_inside) - { - g[0] = -2* (Pos[0] - m_center[0]); - g[1] = -2* (Pos[1] - m_center[1]); - g[2] = -2* (Pos[2] - m_center[2]); - } - else - { - g[0] = 2* (Pos[0] - m_center[0]); - g[1] = 2* (Pos[1] - m_center[1]); - g[2] = 2* (Pos[2] - m_center[2]); - } - - return g; -} - -void SphericalField::getValueAndGradient(Vec3d& Pos, double &value, Vec3d& /*grad*/, int& domain) -{ - SOFA_UNUSED(domain); - Vec3d g; - g[0] = (Pos[0] - m_center[0]); - g[1] = (Pos[1] - m_center[1]); - g[2] = (Pos[2] - m_center[2]); - if (m_inside) - { - value = m_radius*m_radius - g.norm2(); - g = g * (-2); - } - else - { - value = g.norm2() - m_radius*m_radius; - g = g * 2; - } - - return; -} - - -// Register in the Factory -void registerSphericalField(sofa::core::ObjectFactory* factory) -{ - factory->registerObjects(sofa::core::ObjectRegistrationData("A spherical implicit field.") - .add< SphericalField >()); -} - -} /// sofa::component::geometry::_sphericalfield_ diff --git a/applications/plugins/SofaImplicitField/components/geometry/SphericalField.h b/applications/plugins/SofaImplicitField/components/geometry/SphericalField.h deleted file mode 100644 index 6880a14ec25..00000000000 --- a/applications/plugins/SofaImplicitField/components/geometry/SphericalField.h +++ /dev/null @@ -1,83 +0,0 @@ -/****************************************************************************** -* 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 * -******************************************************************************/ -#ifndef SOFA_IMPLICIT_SPHERICALFIELD_H -#define SOFA_IMPLICIT_SPHERICALFIELD_H - -#include "ScalarField.h" - -namespace sofa -{ - -namespace component -{ - -namespace geometry -{ - -namespace _sphericalfield_ -{ - -using sofa::type::Vec3d ; - -class SOFA_SOFAIMPLICITFIELD_API SphericalField : public ScalarField -{ -public: - SOFA_CLASS(SphericalField, ScalarField); - -public: - SphericalField() ; - ~SphericalField() override { } - - /// Inherited from BaseObject - void init() override ; - void reinit() override ; - - /// Inherited from ScalarField. - double getValue(Vec3d& Pos, int &domain) override ; - Vec3d getGradient(Vec3d &Pos, int& domain) override ; - void getValueAndGradient(Vec3d& pos, double& val, Vec3d& grad, int& domain) override ; - - using ScalarField::getValue ; - using ScalarField::getGradient ; - using ScalarField::getValueAndGradient ; - - Data d_inside; ///< If true the field is oriented inside (resp. outside) the sphere. (default = false) - Data d_radiusSphere; ///< Radius of Sphere emitting the field. (default = 1) - Data d_centerSphere; ///< Position of the Sphere Surface. (default=0 0 0) - -protected: - Vec3d m_center; - double m_radius; - bool m_inside; -}; - -} /// _sphericalfield_ - -using _sphericalfield_::SphericalField ; - -} /// geometry - -} /// component - -} /// sofa - -#endif diff --git a/applications/plugins/SofaImplicitField/components/geometry/StarShapedField.cpp b/applications/plugins/SofaImplicitField/components/geometry/StarShapedField.cpp deleted file mode 100644 index f41b2d75880..00000000000 --- a/applications/plugins/SofaImplicitField/components/geometry/StarShapedField.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/****************************************************************************** -* 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 -using sofa::core::RegisterObject ; - -#include "StarShapedField.h" - -namespace sofa::component::geometry::_StarShapedField_ -{ - - -StarShapedField::StarShapedField() - : d_inside(initData(&d_inside, false, "inside", "If true the field is oriented inside (resp. outside) the sphere. (default = false)")) - , d_radiusSphere(initData(&d_radiusSphere, 1.0, "radius", "Radius of Sphere emitting the field. (default = 1)")) - , d_centerSphere(initData(&d_centerSphere, Vec3d(0.0,0.0,0.0), "center", "Position of the Sphere Surface. (default=0 0 0)" )) - , d_branches(initData(&d_branches, 1.0, "branches", "Number of branches of the star. (default=1)" )) - , d_branchesRadius(initData(&d_branchesRadius, 1.0, "branchesRadius", "Size of the branches of the star. (default=1)" )) -{ - init(); - addUpdateCallback("myUpdateCallback", {&d_inside, &d_radiusSphere, &d_centerSphere, &d_branches, &d_branchesRadius}, [this](const core::DataTracker& t) - { - SOFA_UNUSED(t); - this->init(); - return sofa::core::objectmodel::ComponentState::Valid; - }, {}); - -} - -void StarShapedField::init() -{ - m_inside = d_inside.getValue(); - m_center = d_centerSphere.getValue(); - m_radius = d_radiusSphere.getValue(); - m_branches = d_branches.getValue(); - m_branchesRadius = d_branchesRadius.getValue(); -} - -void StarShapedField::reinit() -{ - init(); -} - -double StarShapedField::getValue(Vec3d& Pos, int& domain) -{ - SOFA_UNUSED(domain) ; - double length = sqrt((Pos[0] - m_center[0])*(Pos[0] - m_center[0]) + - (Pos[1] - m_center[1])*(Pos[1] - m_center[1]) + - (Pos[2] - m_center[2])*(Pos[2] - m_center[2])); - double result = length - m_radius ; - - double simpleCos0 = (Pos[0] - m_center[0]); - double simpleCos1 = (Pos[1] - m_center[1]); - double simpleCos2 = (Pos[2] - m_center[2]); - - result += m_branchesRadius * ( cos( m_branches*simpleCos0 ) + cos( m_branches*simpleCos1 ) + cos( m_branches*simpleCos2 ) ); - if(m_inside) - result = -result; - - return result; -} - -Vec3d StarShapedField::getGradient(Vec3d &Pos, int &domain) -{ - SOFA_UNUSED(domain); - Vec3d g; - - double length = sqrt((Pos[0] - m_center[0])*(Pos[0] - m_center[0]) + - (Pos[1] - m_center[1])*(Pos[1] - m_center[1]) + - (Pos[2] - m_center[2])*(Pos[2] - m_center[2])); - double deltaLength0 = (Pos[0] - m_center[0])/length; - double deltaLength1 = (Pos[1] - m_center[1])/length; - double deltaLength2 = (Pos[2] - m_center[2])/length; - - g[0] = deltaLength0 - m_branchesRadius*m_branches*sin(m_branches*(Pos[0] - m_center[0])); - g[1] = deltaLength1 - m_branchesRadius*m_branches*sin(m_branches*(Pos[1] - m_center[1])); - g[2] = deltaLength2 - m_branchesRadius*m_branches*sin(m_branches*(Pos[2] - m_center[2])); - - if (m_inside) - { - g[0] = -g[0]; - g[1] = -g[1]; - g[2] = -g[2]; - } - - return g; -} - -void StarShapedField::getHessian(Vec3d &Pos, Mat3x3& h) -{ - double length = sqrt((Pos[0] - m_center[0])*(Pos[0] - m_center[0]) + - (Pos[1] - m_center[1])*(Pos[1] - m_center[1]) + - (Pos[2] - m_center[2])*(Pos[2] - m_center[2])); - double deltaLength0 = (Pos[0] - m_center[0])/length; - double deltaLength1 = (Pos[1] - m_center[1])/length; - double deltaLength2 = (Pos[2] - m_center[2])/length; - - - h[0][0] = (length - (Pos[0] - m_center[0])*deltaLength0 )/(length*length) - m_branchesRadius*m_branches*m_branches*cos(m_branches*(Pos[0] - m_center[0])); - h[1][1] = (length - (Pos[1] - m_center[1])*deltaLength1 )/(length*length) - m_branchesRadius*m_branches*m_branches*cos(m_branches*(Pos[1] - m_center[1])); - h[2][2] = (length - (Pos[2] - m_center[2])*deltaLength2 )/(length*length) - m_branchesRadius*m_branches*m_branches*cos(m_branches*(Pos[2] - m_center[2])); - - h[0][1] = h[1][0] = - (Pos[0] - m_center[0])*(Pos[1] - m_center[1]) / (length*length*length); - h[0][2] = h[2][0] = - (Pos[0] - m_center[0])*(Pos[2] - m_center[2]) / (length*length*length); - h[1][2] = h[2][1] = - (Pos[2] - m_center[2])*(Pos[1] - m_center[1]) / (length*length*length); - - return; -} - -// Register in the Factory -void registerStarShapedField(sofa::core::ObjectFactory* factory) -{ - factory->registerObjects(sofa::core::ObjectRegistrationData("A star-shape implicit field.") - .add< StarShapedField >()); -} - -} // namespace sofa::component::geometry::_StarShapedField_ - diff --git a/applications/plugins/SofaImplicitField/components/geometry/StarShapedField.h b/applications/plugins/SofaImplicitField/components/geometry/StarShapedField.h deleted file mode 100644 index 1d0aebb33b7..00000000000 --- a/applications/plugins/SofaImplicitField/components/geometry/StarShapedField.h +++ /dev/null @@ -1,79 +0,0 @@ -/****************************************************************************** -* 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 "ScalarField.h" -#include - -namespace sofa::component::geometry -{ - -namespace _StarShapedField_ -{ - -using sofa::type::Vec3d; -using sofa::type::Mat3x3; - -/** - * This component emulates an implicit field that looks like some kind of star. -*/ -class SOFA_SOFAIMPLICITFIELD_API StarShapedField : public ScalarField -{ -public: - SOFA_CLASS(StarShapedField, ScalarField); - -public: - StarShapedField() ; - ~StarShapedField() override { } - - /// Inherited from BaseObject - void init() override ; - void reinit() override ; - - /// Inherited from ScalarField. - double getValue(Vec3d& Pos, int &domain) override ; - Vec3d getGradient(Vec3d &Pos, int& domain) override ; - void getHessian(Vec3d &Pos, Mat3x3& h) override; - - using ScalarField::getValue ; - using ScalarField::getGradient ; - using ScalarField::getValueAndGradient ; - - Data d_inside; ///< If true the field is oriented inside (resp. outside) the sphere. (default = false) - Data d_radiusSphere; ///< Radius of Sphere emitting the field. (default = 1) - Data d_centerSphere; ///< Position of the Sphere Surface. (default=0 0 0) - Data d_branches; ///< Number of branches of the star. (default=1) - Data d_branchesRadius; ///< Size of the branches of the star. (default=1) -protected: - Vec3d m_center; - double m_radius; - bool m_inside; - double m_branches; - double m_branchesRadius; -}; - -} // namespace _StarShapedField_ - -using sofa::component::geometry::_StarShapedField_::StarShapedField; - -} // namespace sofa::component::geometry - diff --git a/applications/plugins/SofaImplicitField/components/mapping/ImplicitSurfaceMapping.cpp b/applications/plugins/SofaImplicitField/components/mapping/ImplicitSurfaceMapping.cpp deleted file mode 100644 index 9609e654e7f..00000000000 --- a/applications/plugins/SofaImplicitField/components/mapping/ImplicitSurfaceMapping.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/****************************************************************************** -* 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 * -******************************************************************************/ -#define SOFA_COMPONENT_MAPPING_IMPLICITSURFACEMAPPING_CPP -#include -#include -#include "ImplicitSurfaceMapping.inl" - -namespace sofaimplicitfield::mapping -{ - -using namespace sofa::defaulttype; - -// Register in the Factory -void registerImplicitSurfaceMapping(sofa::core::ObjectFactory* factory) -{ - factory->registerObjects(sofa::core::ObjectRegistrationData("Compute an iso-surface from a set of particles.") - .add< ImplicitSurfaceMapping< Vec3dTypes, Vec3dTypes > >()); -} - -template class SOFA_SOFAIMPLICITFIELD_API ImplicitSurfaceMapping< Vec3dTypes, Vec3dTypes >; - -} diff --git a/applications/plugins/SofaImplicitField/components/mapping/ImplicitSurfaceMapping.h b/applications/plugins/SofaImplicitField/components/mapping/ImplicitSurfaceMapping.h deleted file mode 100644 index 6b66ece9bd8..00000000000 --- a/applications/plugins/SofaImplicitField/components/mapping/ImplicitSurfaceMapping.h +++ /dev/null @@ -1,164 +0,0 @@ -/****************************************************************************** -* 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 -#include -#include - -namespace sofaimplicitfield::mapping -{ - -using namespace sofa; -using sofa::component::topology::container::constant::MeshTopology; - -template -class ImplicitSurfaceMapping : public core::Mapping, public MeshTopology -{ -public: - SOFA_CLASS2(SOFA_TEMPLATE2(ImplicitSurfaceMapping, In, Out), SOFA_TEMPLATE2(core::Mapping, In, Out), MeshTopology); - - typedef core::Mapping Inherit; - typedef typename Out::VecCoord OutVecCoord; - typedef typename Out::VecDeriv OutVecDeriv; - typedef typename Out::Coord OutCoord; - typedef typename Out::Deriv OutDeriv; - typedef typename OutCoord::value_type OutReal; - typedef typename In::VecCoord InVecCoord; - typedef typename In::VecDeriv InVecDeriv; - typedef typename In::Coord InCoord; - typedef typename In::Deriv InDeriv; - typedef typename InCoord::value_type InReal; - - typedef typename In::MatrixDeriv InMatrixDeriv; - typedef typename Out::MatrixDeriv OutMatrixDeriv; - - typedef Data InDataVecCoord; - typedef Data InDataVecDeriv; - typedef Data InDataMatrixDeriv; - - typedef Data OutDataVecCoord; - typedef Data OutDataVecDeriv; - typedef Data OutDataMatrixDeriv; -protected: - ImplicitSurfaceMapping() - : Inherit(), - mStep(initData(&mStep,0.5,"step","Step")), - mRadius(initData(&mRadius,2.0,"radius","Radius")), - mIsoValue(initData(&mIsoValue,0.5,"isoValue","Iso Value")), - mGridMin(initData(&mGridMin,InCoord(-100,-100,-100),"min","Grid Min")), - mGridMax(initData(&mGridMax,InCoord(100,100,100),"max","Grid Max")) - { - } - - ~ImplicitSurfaceMapping() override - { - } -public: - void init() override; - - void parse(core::objectmodel::BaseObjectDescription* arg) override; - - double getStep() const { return mStep.getValue(); } - void setStep(double val) { mStep.setValue(val); } - - double getRadius() const { return mRadius.getValue(); } - void setRadius(double val) { mRadius.setValue(val); } - - double getIsoValue() const { return mIsoValue.getValue(); } - void setIsoValue(double val) { mIsoValue.setValue(val); } - - const InCoord& getGridMin() const { return mGridMin.getValue(); } - void setGridMin(const InCoord& val) { mGridMin.setValue(val); } - void setGridMin(double x, double y, double z) { mGridMin.setValue( InCoord((InReal)x,(InReal)y,(InReal)z)); } - - const InCoord& getGridMax() const { return mGridMax.getValue(); } - void setGridMax(const InCoord& val) { mGridMax.setValue(val); } - void setGridMax(double x, double y, double z) { mGridMax.setValue( InCoord((InReal)x,(InReal)y,(InReal)z)); } - - 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 sofa::core::MechanicalParams* /*mparams*/, InDataVecDeriv& /*out*/, const OutDataVecDeriv& /*in*/) override - { - msg_error() << "applyJT(dx) is not implemented"; - } - - void applyJT( const sofa::core::ConstraintParams* /*cparams*/, InDataMatrixDeriv& /*out*/, const OutDataMatrixDeriv& /*in*/) override - { - msg_error() << "applyJT(constraint) is not implemented"; - } - - void draw(const core::visual::VisualParams* params) override; - -protected: - Data mStep; ///< Step - Data mRadius; ///< Radius - Data mIsoValue; ///< Iso Value - - Data< InCoord > mGridMin; ///< Grid Min - Data< InCoord > mGridMax; ///< Grid Max - - Vec3d mLocalGridMin; ///< Grid Min - Vec3d mLocalGridMax; ///< Grid Max - - - // Marching cube data - - /// For each cube, store the vertex indices on each 3 first edges, and the data value - struct CubeData - { - int p[3]; - OutReal data; - inline friend std::istream& operator >> ( std::istream& in, CubeData& c) - { - in >> c.p[0] >> c.p[1] >> c.p[2] >> c.data; - - return in; - } - - inline friend std::ostream& operator << ( std::ostream& out, const CubeData& c) - { - out << c.p[0] << " " << c.p[1] << " " << c.p[2] << " " << c.data ; - return out; - } - }; - - Data < sofa::type::vector > planes; - typename sofa::type::vector::iterator P0; /// Pointer to first plane - typename sofa::type::vector::iterator P1; /// Pointer to second plane -public: - bool insertInNode( core::objectmodel::BaseNode* node ) override { Inherit1::insertInNode(node); Inherit2::insertInNode(node); return true; } - bool removeInNode( core::objectmodel::BaseNode* node ) override { Inherit1::removeInNode(node); Inherit2::removeInNode(node); return true; } - -private: - MarchingCube marchingCube; -}; - -#if !defined(SOFA_COMPONENT_MAPPING_IMPLICITSURFACEMAPPING_CPP) -extern template class SOFA_SOFAIMPLICITFIELD_API ImplicitSurfaceMapping< defaulttype::Vec3dTypes, defaulttype::Vec3dTypes >; -#endif - -} // namespace - diff --git a/applications/plugins/SofaImplicitField/components/mapping/ImplicitSurfaceMapping.inl b/applications/plugins/SofaImplicitField/components/mapping/ImplicitSurfaceMapping.inl deleted file mode 100644 index 267b73e3fc3..00000000000 --- a/applications/plugins/SofaImplicitField/components/mapping/ImplicitSurfaceMapping.inl +++ /dev/null @@ -1,164 +0,0 @@ -/****************************************************************************** -* 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 "ImplicitSurfaceMapping.h" -#include -#include -#include -#include - -namespace sofaimplicitfield::mapping -{ - -template -void ImplicitSurfaceMapping::init() -{ - core::Mapping::init(); - MeshTopology::init(); -} - -template -void ImplicitSurfaceMapping::parse(core::objectmodel::BaseObjectDescription* arg) -{ - this->Inherit::parse(arg); - if ( arg->getAttribute("minx") || arg->getAttribute("miny") || arg->getAttribute("minz")) - this->setGridMin(arg->getAttributeAsFloat("minx",-100.0), - arg->getAttributeAsFloat("miny",-100.0), - arg->getAttributeAsFloat("minz",-100.0)); - if (arg->getAttribute("maxx") || arg->getAttribute("maxy") || arg->getAttribute("maxz")) - this->setGridMax(arg->getAttributeAsFloat("maxx",100.0), - arg->getAttributeAsFloat("maxy",100.0), - arg->getAttributeAsFloat("maxz",100.0)); -} - -template -Real sqr(Real r) -{ - return r*r; -} - -template -void ImplicitSurfaceMapping::draw(const core::visual::VisualParams* params) -{ - auto dt = params->drawTool(); - - dt->drawBoundingBox(mGridMin.getValue(), mGridMax.getValue()); - dt->drawBoundingBox(mLocalGridMin, mLocalGridMax); -} - -template -void ImplicitSurfaceMapping::apply(const core::MechanicalParams * /*mparams*/, Data& dOut, const Data& dIn) -{ - const InVecCoord& in = dIn.getValue(); - - clear(); - - if (in.size()==0) - { - OutVecCoord &out = *dOut.beginEdit(); - dOut.endEdit(); - return; - } - - auto minGrid = mGridMin.getValue(); - auto maxGrid = mGridMax.getValue(); - - InReal invStep = (InReal)(1/mStep.getValue()); - const InReal r = getRadius(); - - std::unordered_map > sortParticles; - for (unsigned int ip=0; ip maxGrid[0] || - c0[1] < minGrid[1] || c0[1] > maxGrid[1] || - c0[2] < minGrid[2] || c0[2] > maxGrid[2]) - continue; - - InCoord c = c0 ; - int z0 = helper::rfloor((c[2]-r)*invStep); - int z1 = helper::rceil((c[2]+r)*invStep); - for (int z = z0; z <= z1; ++z) - sortParticles[z].push_back(c); - } - - OutReal r2 = (OutReal)sqr(r); - - double rr = getRadius(); - type::BoundingBox box{}; - for(auto& particle : in) - { - box.include(particle); - } - box.include(box.minBBox()+Vec3d{-rr,-rr,-rr}); - box.include(box.maxBBox()+Vec3d{+rr,+rr,+rr}); - - mLocalGridMin = box.minBBox(); - mLocalGridMax = box.maxBBox(); - - type::BoundingBox bigBox {mGridMin.getValue(), mGridMax.getValue()}; - box.intersection(bigBox); - - auto fieldFunction = [&sortParticles, &r, &r2, &invStep]( - std::vector& pos, std::vector& res) -> void { - - auto z = pos[0].z(); - int index = helper::rfloor(z*invStep); - auto particlesIt = sortParticles.find(index); - if(particlesIt==sortParticles.end()) - return; - - int i = 0; - for(auto& position : pos ) - { - double sumd = 0.0; - for(auto& particle : (particlesIt->second)){ - position.z() = z; - double d2 = (position - particle).norm2(); - if(d2 < r2){ - d2 /= r2; - sumd += (1 + (-4*d2*d2*d2 + 17*d2*d2 - 22*d2)/9); - } - } - res[i++] = sumd; - } - return; - }; - - auto triangles = helper::getWriteOnlyAccessor(d_seqTriangles); - auto points = helper::getWriteOnlyAccessor(dOut); - - points.clear(); - triangles.clear(); - marchingCube.generateSurfaceMesh(mIsoValue.getValue(), mStep.getValue(), - invStep, box.minBBox(), box.maxBBox(), - fieldFunction, points.wref(), triangles.wref()); - -} - -template -void ImplicitSurfaceMapping::applyJ(const core::MechanicalParams * /*mparams*/, Data& /*dOut*/, const Data& /*dIn*/) -{ -} - -} diff --git a/applications/plugins/SofaImplicitField/config.h.in b/applications/plugins/SofaImplicitField/config.h.in deleted file mode 100644 index 875a9b62f0d..00000000000 --- a/applications/plugins/SofaImplicitField/config.h.in +++ /dev/null @@ -1,37 +0,0 @@ -/****************************************************************************** -* 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 - -#ifdef SOFA_BUILD_SOFAIMPLICITFIELD -# define SOFA_TARGET SofaImplicitField -# define SOFA_SOFAIMPLICITFIELD_API SOFA_EXPORT_DYNAMIC_LIBRARY -#else -# define SOFA_SOFAIMPLICITFIELD_API SOFA_IMPORT_DYNAMIC_LIBRARY -#endif - -namespace sofaimplicitfield -{ - constexpr const char* MODULE_NAME = "@PROJECT_NAME@"; - constexpr const char* MODULE_VERSION = "@PROJECT_VERSION@"; -} // namespace sofaimplicitfield diff --git a/applications/plugins/SofaImplicitField/deprecated/ImplicitSurfaceContainer.h b/applications/plugins/SofaImplicitField/deprecated/ImplicitSurfaceContainer.h deleted file mode 100644 index 9858a7ea1ab..00000000000 --- a/applications/plugins/SofaImplicitField/deprecated/ImplicitSurfaceContainer.h +++ /dev/null @@ -1,50 +0,0 @@ -/// This file is only forwarding to the new location -#include - -namespace sofa -{ -namespace component -{ -namespace container -{ - -class ImplicitSurfaceContainer : public sofa::component::geometry::DiscreteGridField -{ -public: - bool loadImage( const char *filename ) - { - return loadGridFromMHD(filename) ; - } - - virtual double getDistance(type::Vec3d& pos) - { - int domain=-1; - return getDistance(pos,domain); - } - - virtual double getDistance(type::Vec3d& pos, int& domain) - { - type::Vec3d grad; - double value; - getValueAndGradient(pos,value,grad,domain); - return getDistance(pos,value,grad.norm()); - } - - virtual double getDistance(type::Vec3d& pos, double value, double grad_norm) - { - int domain=-1; - return getDistance(pos, value, grad_norm, domain); - } - - virtual double getDistance(type::Vec3d& /*pos*/, double value, double grad_norm, int &domain) - { - SOFA_UNUSED(domain); - /// use Taubin's distance by default - if (grad_norm < 1e-10) return value < 0 ? double(std::numeric_limits::min()) : double(std::numeric_limits::max()); - return value/grad_norm; - } -}; - -} -} -} diff --git a/applications/plugins/SofaImplicitField/deprecated/ImplicitSurfaceMapping.h b/applications/plugins/SofaImplicitField/deprecated/ImplicitSurfaceMapping.h deleted file mode 100644 index 9e2d3d4a250..00000000000 --- a/applications/plugins/SofaImplicitField/deprecated/ImplicitSurfaceMapping.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/applications/plugins/SofaImplicitField/deprecated/ImplicitSurfaceMapping.inl b/applications/plugins/SofaImplicitField/deprecated/ImplicitSurfaceMapping.inl deleted file mode 100644 index 3e60617ebde..00000000000 --- a/applications/plugins/SofaImplicitField/deprecated/ImplicitSurfaceMapping.inl +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/applications/plugins/SofaImplicitField/deprecated/InterpolatedImplicitSurface.cpp b/applications/plugins/SofaImplicitField/deprecated/InterpolatedImplicitSurface.cpp deleted file mode 100644 index d02ac4597f8..00000000000 --- a/applications/plugins/SofaImplicitField/deprecated/InterpolatedImplicitSurface.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include -using sofa::core::RegisterObject ; - -#include - -namespace sofa::component::container -{ - -// Register in the Factory -void registerInterpolatedImplicitSurface(sofa::core::ObjectFactory* factory) -{ - factory->registerObjects(sofa::core::ObjectRegistrationData("Deprecated. This class is forwarding DiscreteGridField.") - .add< InterpolatedImplicitSurface >() - .addAlias("DistGrid")); -} - -} /// sofa::component::container diff --git a/applications/plugins/SofaImplicitField/deprecated/InterpolatedImplicitSurface.h b/applications/plugins/SofaImplicitField/deprecated/InterpolatedImplicitSurface.h deleted file mode 100644 index 9d83c47f827..00000000000 --- a/applications/plugins/SofaImplicitField/deprecated/InterpolatedImplicitSurface.h +++ /dev/null @@ -1,52 +0,0 @@ -#include - -namespace sofa -{ -namespace component -{ -namespace container -{ - -class InterpolatedImplicitSurface : public sofa::component::geometry::DiscreteGridField -{ -public: - SOFA_CLASS(InterpolatedImplicitSurface, DiscreteGridField) ; - - bool loadImage( const char *filename ) { - return loadGridFromMHD(filename) ; - } - - virtual double getDistance(type::Vec3d& pos) - { - int domain=-1; - return getDistance(pos,domain); - } - - virtual double getDistance(type::Vec3d& pos, int& domain) - { - type::Vec3d grad; - double value; - getValueAndGradient(pos,value,grad,domain); - return getDistance(pos,value,grad.norm()); - } - - virtual double getDistance(type::Vec3d& pos, double value, double grad_norm) - { - int domain=-1; - return getDistance(pos, value, grad_norm, domain); - } - - virtual double getDistance(type::Vec3d& /*pos*/, double value, double grad_norm, int &domain) - { - SOFA_UNUSED(domain); - /// use Taubin's distance by default - if (grad_norm < 1e-10) return value < 0 ? double(std::numeric_limits::min()) : double(std::numeric_limits::max()); - return value/grad_norm; - } - - -}; - -} /// container -} /// component -} /// sofa diff --git a/applications/plugins/SofaImplicitField/deprecated/SphereSurface.cpp b/applications/plugins/SofaImplicitField/deprecated/SphereSurface.cpp deleted file mode 100644 index daa9abd2c96..00000000000 --- a/applications/plugins/SofaImplicitField/deprecated/SphereSurface.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "SphereSurface.h" - -namespace sofa -{ -namespace component -{ -namespace container -{ - -double SphereSurface::getDistance(type::Vec3d& Pos, int& domain) -{ - SOFA_UNUSED(domain) ; - double result = m_radius - sqrt((Pos[0] - m_center[0])*(Pos[0] - m_center[0]) + - (Pos[1] - m_center[1])*(Pos[1] - m_center[1]) + - (Pos[2] - m_center[2])*(Pos[2] - m_center[2])); - return m_inside ? result : -result; -} - -double SphereSurface::getDistance(type::Vec3d& /*Pos*/, double value, double grad_norm, int &domain) -{ - (void)domain; - if (grad_norm < 0) // use value - grad_norm = sqrt(m_inside ? m_radius*m_radius - value : value + m_radius*m_radius); - else grad_norm /= 2; - return m_inside ? m_radius - grad_norm : grad_norm - m_radius; -} - -} -} -} diff --git a/applications/plugins/SofaImplicitField/deprecated/SphereSurface.h b/applications/plugins/SofaImplicitField/deprecated/SphereSurface.h deleted file mode 100644 index ab24ba2cc7e..00000000000 --- a/applications/plugins/SofaImplicitField/deprecated/SphereSurface.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef SOFA_SOFAIMPLICITFIELD_H -#define SOFA_SOFAIMPLICITFIELD_H - -#include - -namespace sofa -{ -namespace component -{ -namespace container -{ - -class SphereSurface : public sofa::component::geometry::SphericalField -{ -public: - SOFA_CLASS(SphereSurface, sofa::component::geometry::SphericalField) ; - - // The following function uses only either value or grad_norm (they are redundant) - // - value is used is grad_norm < 0 - // - else grad_norm is used: for example, in that case dist = _radius - grad_norm/2 (with _inside=true) - virtual double getDistance(sofa::type::Vec3d& pos, int& domain) ; - virtual double getDistance(sofa::type::Vec3d& pos, double value, double grad_norm, int &domain) ; -}; - -} /// container -} /// components -} /// sofa - -#endif /// SOFA_SOFAIMPLICITFIELD_H diff --git a/applications/plugins/SofaImplicitField/examples/ImplicitSurfaceMapping.scn b/applications/plugins/SofaImplicitField/examples/ImplicitSurfaceMapping.scn deleted file mode 100644 index 174e8d159fc..00000000000 --- a/applications/plugins/SofaImplicitField/examples/ImplicitSurfaceMapping.scn +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/applications/plugins/SofaImplicitField/examples/python/example-mesh-extraction-from-implicit.py b/applications/plugins/SofaImplicitField/examples/python/example-mesh-extraction-from-implicit.py deleted file mode 100644 index 4b848a7d86a..00000000000 --- a/applications/plugins/SofaImplicitField/examples/python/example-mesh-extraction-from-implicit.py +++ /dev/null @@ -1,53 +0,0 @@ -import Sofa -from Sofa.Types import RGBAColor -from xshape.primitives import * -from xshape.transforms import * -from xshape.operators import * - -class DrawController(Sofa.Core.Controller): - def __init__(self, *args, **kwargs): - Sofa.Core.Controller.__init__(self, *args, **kwargs) - - def draw(self, visual_context): - dt = visual_context.getDrawTool() - dt.drawText([-1.0, 1.0, 0.5], 0.2, "Union(Sphere, Box)", RGBAColor(1.0,1.0,1.0,1.0)) - dt.drawText([ 1.0, 1.0, 0.5], 0.2, "Difference(Sphere, Box)", RGBAColor(1.0,1.0,1.0,1.0)) - -def createScene(root : Sofa.Core.Node): - """Creates two different mesh from two scalar field. - The scalar fields are 'spherical', one implemented in python, the other in c++ - One of the produced mesh is then connected to a visual model. - """ - root.addObject("RequiredPlugin", pluginName="SofaImplicitField") - - root.addObject(DrawController()) - - ########################### Fields ################## - root.addChild("Fields") - f1 = root.Fields.addObject( - Union(name="field1", - childA=Sphere(name="sphere", center=[0,0,0],radius=0.7), - childB=RoundedBox(center=[0.0,0.0,0.0],dimensions=[0.95,0.5,0.5], rounding_radius=0.1)) - ) - - f2 = root.Fields.addObject( - Difference(name="field2", - childB=Sphere(name="sphere", center=[2,0,0],radius=0.9), - childA=RoundedBox(center=[2.0,0.0,0.0],dimensions=[0.95,0.5,0.5], rounding_radius=0.1)) - ) - - ########################### Meshing ################## - root.addChild("Meshing") - m1 = root.Meshing.addObject("FieldToSurfaceMesh", name="polygonizer1", - field=f1.linkpath, min=[-1,-1,-1], max=[1,1,1], - step=0.1, debugDraw=True) - - m2 = root.Meshing.addObject("FieldToSurfaceMesh", name="polygonizer2", - field=f2.linkpath, min=[1,-1,-1], max=[3,1,1], - step=0.07) - - ########################### Fields ################## - root.addChild("Visual") - root.Visual.addObject("OglModel", name="renderer", - position=root.Meshing.polygonizer2.points.linkpath, - triangles=root.Meshing.polygonizer2.triangles.linkpath) diff --git a/applications/plugins/SofaImplicitField/examples/python/python-scalarfield.py b/applications/plugins/SofaImplicitField/examples/python/python-scalarfield.py deleted file mode 100644 index 9a43da272a9..00000000000 --- a/applications/plugins/SofaImplicitField/examples/python/python-scalarfield.py +++ /dev/null @@ -1,50 +0,0 @@ -import Sofa -from SofaImplicitField import ScalarField -from SofaTypes.SofaTypes import Vec3d, Mat3x3 -import numpy - -class Sphere(ScalarField): - def __init__(self, *args, **kwargs): - ScalarField.__init__(self, *args, **kwargs) - - self.addData("center", type="Vec3d",value=kwargs.get("center", [0.0,0.0,0.0]), default=[0.0,0.0,0.0], help="center of the sphere", group="Geometry") - self.addData("radius", type="double",value=kwargs.get("radius", 1.0), default=1, help="radius of the sphere", group="Geometry") - - def getValue(self, position): - x,y,z = position - return numpy.sqrt( numpy.sum((self.center.value - numpy.array([x,y,z]))**2) ) - self.radius.value - -class SphereWithCustomHessianAndGradient(Sphere): - def __init__(self, *args, **kwargs): - Sphere.__init__(self, *args, **kwargs)# - - def getGradient(self, position): - return Vec3d(3.0,2.0,1.0) - - def getHessian(self, position): - return Mat3x3([[1,1,1],[2,1,1],[3,1,1]]) - -class FieldController(Sofa.Core.Controller): - def __init__(self, *args, **kwargs): - Sofa.Core.Controller.__init__(self, *args, **kwargs) - self.field = kwargs.get("target") - - def onAnimateEndEvent(self, event): - print("Animation end event, ") - print("Field value at 0,0,0 is: ", self.field.getValue(Vec3d(0.0,0.0,0.0)) ) - print("Field value at 1,0,0 is: ", self.field.getValue(Vec3d(1.0,0.0,0.0)) ) - print("Field value at 2,0,0 is: ", self.field.getValue(Vec3d(2.0,0.0,0.0)) ) - - print("Gradient value at 0,0,0 is: ", type(self.field.getGradient(Vec3d(0.0,0.0,0.0)))) - print("Hessian value at 0,0,0 is: ", type(self.field.getHessian(Vec3d(0.0,0.0,0.0)))) - -def createScene(root): - """In this scene we create two scalar field of spherical shape, the two are implemented using - python. The first one is overriding only the getValue, the hessian and gradient is thus computed using - finite difference in the c++ code. The second field is overriding the hessian and gradient function - """ - root.addObject(Sphere("field1")) - root.addObject(FieldController(name="controller1", target=root.field1)) - - root.addObject(SphereWithCustomHessianAndGradient("field2")) - root.addObject(FieldController(name="controller2", target=root.field2)) diff --git a/applications/plugins/SofaImplicitField/examples/python/xshape/__init__.py b/applications/plugins/SofaImplicitField/examples/python/xshape/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/applications/plugins/SofaImplicitField/examples/python/xshape/operators.py b/applications/plugins/SofaImplicitField/examples/python/xshape/operators.py deleted file mode 100644 index 4506c1342a3..00000000000 --- a/applications/plugins/SofaImplicitField/examples/python/xshape/operators.py +++ /dev/null @@ -1,35 +0,0 @@ -from SofaImplicitField import ScalarField -import numpy - -class Union(ScalarField): - """Union of two scalar fields""" - def __init__(self, *args, **kwargs): - ScalarField.__init__(self, *args, **kwargs) - - self.childA = kwargs.get("childA", None) - self.childB = kwargs.get("childB", None) - - def getValue(self, position): - return min(self.childA.getValue(position), self.childB.getValue(position)) - -class Difference(ScalarField): - """Difference of two scalar fields""" - def __init__(self, *args, **kwargs): - ScalarField.__init__(self, *args, **kwargs) - - self.childA = kwargs.get("childA", None) - self.childB = kwargs.get("childB", None) - - def getValue(self, position): - return max(-self.childA.getValue(position), self.childB.getValue(position)) - -class Intersection(ScalarField): - """Intersection of two scalar fields""" - def __init__(self, *args, **kwargs): - ScalarField.__init__(self, *args, **kwargs) - - self.childA = kwargs.get("childA", None) - self.childB = kwargs.get("childB", None) - - def getValue(self, position): - return max(self.childA.getValue(position), self.childB.getValue(position)) \ No newline at end of file diff --git a/applications/plugins/SofaImplicitField/examples/python/xshape/primitives.py b/applications/plugins/SofaImplicitField/examples/python/xshape/primitives.py deleted file mode 100644 index 87f8a34fff2..00000000000 --- a/applications/plugins/SofaImplicitField/examples/python/xshape/primitives.py +++ /dev/null @@ -1,34 +0,0 @@ -"""Distance field function - -Sources: - https://iquilezles.org/articles/distfunctions/ -""" -from SofaImplicitField import ScalarField -import numpy - -class Sphere(ScalarField): - def __init__(self, *args, **kwargs): - ScalarField.__init__(self, *args, **kwargs) - - self.addData("center", type="Vec3d",value=kwargs.get("center", [0.0,0.0,0.0]), default=[0.0,0.0,0.0], help="center of the sphere", group="Geometry") - self.addData("radius", type="double",value=kwargs.get("radius", 1.0), default=1, help="radius of the sphere", group="Geometry") - - def getValue(self, pos): - x,y,z = pos - return numpy.linalg.norm(self.center.value - numpy.array([x,y,z])) - self.radius.value - -class RoundedBox(ScalarField): - def __init__(self, *args, **kwargs): - ScalarField.__init__(self, *args, **kwargs) - - self.addData("center", type="Vec3d",value=kwargs.get("center", [0.0,0.0,0.0]), default=[0.0,0.0,0.0], help="center of the sphere", group="Geometry") - self.addData("dimensions", type="Vec3d",value=kwargs.get("dimensions", [1.0,1.0,1.0]), default=[1.0,1.0,1.0], help="dimmension of the box", group="Geometry") - self.addData("rounding_radius", type="double",value=kwargs.get("rounding_radius", 0.1), default=0.1, help="radius of the sphere", group="Geometry") - - def getValue(self, pos): - x,y,z = pos - b = self.dimensions.value - r = self.rounding_radius.value - q = numpy.abs(self.center.value - numpy.array([x,y,z])) - b + r - res = numpy.linalg.norm(numpy.maximum(q, 0.0)) + min(max(q[0], max(q[1],q[2]) ), 0.0) - r - return res diff --git a/applications/plugins/SofaImplicitField/examples/python/xshape/transforms.py b/applications/plugins/SofaImplicitField/examples/python/xshape/transforms.py deleted file mode 100644 index 778b4f7dd7c..00000000000 --- a/applications/plugins/SofaImplicitField/examples/python/xshape/transforms.py +++ /dev/null @@ -1,15 +0,0 @@ -from SofaImplicitField import ScalarField -import numpy - -class Translate(ScalarField): - """Translate a scalar field given as attribute""" - def __init__(self, *args, **kwargs): - ScalarField.__init__(self, *args, **kwargs) - - self.addData("translate", type="Vec3d",value=kwargs.get("translate", [0.0,0.0,0.0]), default=[0.0,0.0,0.0], help="amount of translation", group="Geometry") - self.child = kwargs.get("child", None) - - def getValue(self, pos): - x,y,z = pos - position = numpy.array([x,y,z])-self.translate.value - return self.child.getValue(position) \ No newline at end of file diff --git a/applications/plugins/SofaImplicitField/initSofaImplicitField.cpp b/applications/plugins/SofaImplicitField/initSofaImplicitField.cpp deleted file mode 100644 index 9e3a2d51e6f..00000000000 --- a/applications/plugins/SofaImplicitField/initSofaImplicitField.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/****************************************************************************** -* 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 -using sofa::helper::system::PluginManager ; - -namespace sofa::component::geometry::_BottleField_ -{ - extern void registerBottleField(sofa::core::ObjectFactory* factory); -} -namespace sofa::component::geometry::_sphericalfield_ -{ - extern void registerSphericalField(sofa::core::ObjectFactory* factory); -} -namespace sofa::component::geometry::_StarShapedField_ -{ - extern void registerStarShapedField(sofa::core::ObjectFactory* factory); -} -namespace sofaimplicitfield::mapping -{ - extern void registerImplicitSurfaceMapping(sofa::core::ObjectFactory* factory); -} -namespace sofa::component::container -{ - extern void registerInterpolatedImplicitSurface(sofa::core::ObjectFactory* factory); -} -namespace sofa::component::geometry::_discretegrid_ -{ - extern void registerDiscreteGridField(sofa::core::ObjectFactory* factory); -} -namespace sofaimplicitfield::component::engine -{ -extern void registerFieldToSurfaceMesh(sofa::core::ObjectFactory* factory); -} - -namespace sofaimplicitfield -{ - -extern "C" { - SOFA_SOFAIMPLICITFIELD_API void initExternalModule(); - SOFA_SOFAIMPLICITFIELD_API const char* getModuleName(); - SOFA_SOFAIMPLICITFIELD_API const char* getModuleVersion(); - SOFA_SOFAIMPLICITFIELD_API const char* getModuleLicense(); - SOFA_SOFAIMPLICITFIELD_API const char* getModuleDescription(); - SOFA_SOFAIMPLICITFIELD_API void registerObjects(sofa::core::ObjectFactory* factory); -} - -void initExternalModule() -{ - 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; - } -} - -const char* getModuleName() -{ - return MODULE_NAME; -} - -const char* getModuleVersion() -{ - return MODULE_VERSION; -} - -const char* getModuleLicense() -{ - return "LGPL"; -} - -const char* getModuleDescription() -{ - return "ImplicitField describe shapes of objects using implicit equation. \n" - "In general of function of a n-dimentional space f(X) returns a scalar value \n" - "The surface is then defined as f(x) = aConstant."; -} - -void registerObjects(sofa::core::ObjectFactory* factory) -{ - sofa::component::geometry::_BottleField_::registerBottleField(factory); - sofa::component::geometry::_sphericalfield_::registerSphericalField(factory); - sofa::component::geometry::_StarShapedField_::registerStarShapedField(factory); - sofaimplicitfield::mapping::registerImplicitSurfaceMapping(factory); - sofa::component::container::registerInterpolatedImplicitSurface(factory); - sofa::component::geometry::_discretegrid_::registerDiscreteGridField(factory); - sofaimplicitfield::component::engine::registerFieldToSurfaceMesh(factory); -} - -} /// sofaimplicitfield diff --git a/applications/plugins/SofaImplicitField/initSofaImplicitField.h b/applications/plugins/SofaImplicitField/initSofaImplicitField.h deleted file mode 100644 index b7c7e37e2fd..00000000000 --- a/applications/plugins/SofaImplicitField/initSofaImplicitField.h +++ /dev/null @@ -1,37 +0,0 @@ -/****************************************************************************** -* 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 * -******************************************************************************/ -#ifndef SOFA_COMPONENT_VOLUMETRIC_DATA_INIT_H -#define SOFA_COMPONENT_VOLUMETRIC_DATA_INIT_H -#include - -namespace sofa -{ - -namespace component -{ - -} // namespace component - -} // namespace sofa - -#endif - diff --git a/applications/plugins/SofaImplicitField/python/CMakeLists.txt b/applications/plugins/SofaImplicitField/python/CMakeLists.txt deleted file mode 100644 index bd66bd9546b..00000000000 --- a/applications/plugins/SofaImplicitField/python/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -project(SofaImplicitField.Python) - -set(SOURCE_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/src/Binding_ScalarField.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/Module_SofaImplicitField.cpp -) - -set(HEADER_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/src/Binding_ScalarField.h -) - -if (NOT TARGET SofaPython3::Plugin) - find_package(SofaPython3 REQUIRED COMPONENTS Plugin Bindings.Sofa.Core) -endif() - -sofa_find_package(SofaImplicitField REQUIRED) - -SP3_add_python_module( - TARGET ${PROJECT_NAME} - PACKAGE SofaImplicitField.Python - MODULE SofaImplicitField - DESTINATION . - SOURCES ${SOURCE_FILES} - HEADERS ${HEADER_FILES} - DEPENDS SofaImplicitField SofaPython3::Plugin SofaPython3::Bindings.Sofa.Core -) diff --git a/applications/plugins/SofaImplicitField/python/src/Binding_ScalarField.cpp b/applications/plugins/SofaImplicitField/python/src/Binding_ScalarField.cpp deleted file mode 100644 index 927a801b7a3..00000000000 --- a/applications/plugins/SofaImplicitField/python/src/Binding_ScalarField.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/****************************************************************************** -* SofaImplicitField plugin * -* (c) 2024 CNRS, University of Lille, INRIA * -* * -* 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 . * -******************************************************************************* -* Contact information: contact@sofa-framework.org * -******************************************************************************/ -#include - -#include -#include -#include -#include - -#include "Binding_ScalarField.h" - -/// Makes an alias for the pybind11 namespace to increase readability. -namespace py { using namespace pybind11; } - -namespace sofaimplicitfield { -using namespace sofapython3; -using sofa::component::geometry::ScalarField; -using sofa::core::objectmodel::BaseObject; -using sofa::type::Vec3; -using sofa::type::Mat3x3; - -class ScalarField_Trampoline : public ScalarField { -public: - SOFA_CLASS(ScalarField_Trampoline, ScalarField); - - // Override this function so that it returns the actual python class name instead of - // "ScalarField_Trampoline" which correspond to this utility class. - std::string getClassName() const override - { - PythonEnvironment::gil acquire; - - // Get the actual class name from python. - return py::str(py::cast(this).get_type().attr("__name__")); - } - - double getValue(Vec3& pos, int& domain) override - { - SOFA_UNUSED(domain); - PythonEnvironment::gil acquire; - - PYBIND11_OVERLOAD_PURE(double, ScalarField, getValue, pos); - } - - Vec3 getGradient(Vec3& pos, int& domain) override - { - SOFA_UNUSED(domain); - PythonEnvironment::gil acquire; - - PYBIND11_OVERLOAD(Vec3, ScalarField, getGradient, pos); - } - - void getHessian(Vec3 &pos, Mat3x3& h) override - { - /// The implementation is a bit more complex compared to getGradient. This is because we change de signature between the c++ API and the python one. - PythonEnvironment::gil acquire; - - // Search if there is a python override, - pybind11::function override = pybind11::get_override(static_cast(this),"getHessian"); - if(!override){ - return ScalarField::getHessian(pos, h); - } - // as there is one override, we call it, passing the "pos" argument and storing the return of the - // value in the "o" variable. - auto o = override(pos); - - // then we check that the function correctly returned a Mat3x3 object and copy its value - // in case there is no Mat3x3 returned values, rise an error - if(py::isinstance(o)) - h = py::cast(o); - else - throw py::type_error("The function getHessian must return a Mat3x3"); - return; - } -}; - -void moduleAddScalarField(py::module &m) { - py::class_> f(m, "ScalarField", py::dynamic_attr(), ""); - - f.def(py::init([](py::args &args, py::kwargs &kwargs) { - auto ff = sofa::core::sptr (new ScalarField_Trampoline()); - - ff->f_listening.setValue(true); - - if (args.size() == 1) ff->setName(py::cast(args[0])); - - py::object cc = py::cast(ff); - for (auto kv : kwargs) { - std::string key = py::cast(kv.first); - py::object value = py::reinterpret_borrow(kv.second); - if (key == "name") { - if (args.size() != 0) { - throw py::type_error("The name is set twice as a " - "named argument='" + py::cast(value) + "' and as a" - "positional argument='" + - py::cast(args[0]) + "'."); - } - ff->setName(py::cast(value)); - } - } - return ff; - })); - - f.def("getValue", [](ScalarField* self, Vec3 pos){ - int domain=-1; - // This shouldn't be self->ScalarField::getValue because it is a pure function - // so there is not ScalarField::getValue emitted. - return self->getValue(pos, domain); - }); - - f.def("getGradient", [](ScalarField* self, Vec3 pos){ - int domain=-1; - return self->ScalarField::getGradient(pos, domain); - }); - - f.def("getHessian", [](ScalarField* self, Vec3 pos){ - Mat3x3 result; - self->getHessian(pos, result); - return result; - }); -} - -} diff --git a/applications/plugins/SofaImplicitField/python/src/Binding_ScalarField.h b/applications/plugins/SofaImplicitField/python/src/Binding_ScalarField.h deleted file mode 100644 index 8ab31e32945..00000000000 --- a/applications/plugins/SofaImplicitField/python/src/Binding_ScalarField.h +++ /dev/null @@ -1,29 +0,0 @@ -/****************************************************************************** -* SofaImplicitField plugin * -* (c) 2021 CNRS, University of Lille, INRIA * -* * -* 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 . * -******************************************************************************* -* Contact information: contact@sofa-framework.org * -******************************************************************************/ - -#pragma once - -#include - -namespace sofaimplicitfield { - -void moduleAddScalarField(pybind11::module &m); - -} diff --git a/applications/plugins/SofaImplicitField/python/src/Module_SofaImplicitField.cpp b/applications/plugins/SofaImplicitField/python/src/Module_SofaImplicitField.cpp deleted file mode 100644 index bd7e9480856..00000000000 --- a/applications/plugins/SofaImplicitField/python/src/Module_SofaImplicitField.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/****************************************************************************** -* SofaImplicitField plugin * -* (c) 2024 CNRS, University of Lille, INRIA * -* * -* 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 . * -******************************************************************************* -* Contact information: contact@sofa-framework.org * -******************************************************************************/ - -#include -namespace py = pybind11; - -#include "Binding_ScalarField.h" - -namespace sofaimplicitfield -{ - -PYBIND11_MODULE(SofaImplicitField, m) { - m.doc() = R"doc( - Implement scalar field representation in python - )doc"; - - moduleAddScalarField(m); -} - -} - From 33acf3abe5ee459ba71f55e60939f8f6cf641ab1 Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Thu, 30 Jul 2026 04:26:21 +0200 Subject: [PATCH 08/20] [Engine] Rename VolumeFromTetrahedrons to VolumeFromVolumetricElements (#6175) * rename to VolumeFromVolumetricElements * compat * last changes * rename test file * rename example * add to component change list * add alias --- Sofa/Component/Engine/Generate/CMakeLists.txt | 19 +++++++++-- .../engine/generate/VolumeFromTetrahedrons.h | 32 +++++++++++++++++++ .../generate/VolumeFromTetrahedrons.inl | 25 +++++++++++++++ ...s.cpp => VolumeFromVolumetricElements.cpp} | 12 ++++--- ...drons.h => VolumeFromVolumetricElements.h} | 16 +++++----- ...s.inl => VolumeFromVolumetricElements.inl} | 20 ++++++------ .../component/engine/generate/config.h.in | 8 +++++ .../sofa/component/engine/generate/init.cpp | 4 +-- .../Engine/Generate/tests/CMakeLists.txt | 2 +- ... => VolumeFromVolumetricElements_test.cpp} | 24 +++++++------- .../src/sofa/helper/ComponentChange.cpp | 3 +- ...s.scn => VolumeFromVolumetricElements.scn} | 4 +-- 12 files changed, 125 insertions(+), 44 deletions(-) create mode 100644 Sofa/Component/Engine/Generate/compat/sofa/component/engine/generate/VolumeFromTetrahedrons.h create mode 100644 Sofa/Component/Engine/Generate/compat/sofa/component/engine/generate/VolumeFromTetrahedrons.inl rename Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/{VolumeFromTetrahedrons.cpp => VolumeFromVolumetricElements.cpp} (82%) rename Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/{VolumeFromTetrahedrons.h => VolumeFromVolumetricElements.h} (83%) rename Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/{VolumeFromTetrahedrons.inl => VolumeFromVolumetricElements.inl} (92%) rename Sofa/Component/Engine/Generate/tests/{VolumeFromTetrahedrons_test.cpp => VolumeFromVolumetricElements_test.cpp} (86%) rename examples/Component/Engine/Generate/{VolumeFromTetrahedrons.scn => VolumeFromVolumetricElements.scn} (90%) diff --git a/Sofa/Component/Engine/Generate/CMakeLists.txt b/Sofa/Component/Engine/Generate/CMakeLists.txt index 62df2348889..4e1ff25d08c 100644 --- a/Sofa/Component/Engine/Generate/CMakeLists.txt +++ b/Sofa/Component/Engine/Generate/CMakeLists.txt @@ -43,8 +43,8 @@ set(HEADER_FILES ${SOFACOMPONENTENGINEGENERATE_SOURCE_DIR}/NormalsFromPoints.inl ${SOFACOMPONENTENGINEGENERATE_SOURCE_DIR}/RandomPointDistributionInSurface.h ${SOFACOMPONENTENGINEGENERATE_SOURCE_DIR}/RandomPointDistributionInSurface.inl - ${SOFACOMPONENTENGINEGENERATE_SOURCE_DIR}/VolumeFromTetrahedrons.h - ${SOFACOMPONENTENGINEGENERATE_SOURCE_DIR}/VolumeFromTetrahedrons.inl + ${SOFACOMPONENTENGINEGENERATE_SOURCE_DIR}/VolumeFromVolumetricElements.h + ${SOFACOMPONENTENGINEGENERATE_SOURCE_DIR}/VolumeFromVolumetricElements.inl ${SOFACOMPONENTENGINEGENERATE_SOURCE_DIR}/VolumeFromTriangles.h ${SOFACOMPONENTENGINEGENERATE_SOURCE_DIR}/VolumeFromTriangles.inl ${SOFACOMPONENTENGINEGENERATE_SOURCE_DIR}/Spiral.h @@ -72,15 +72,26 @@ set(SOURCE_FILES ${SOFACOMPONENTENGINEGENERATE_SOURCE_DIR}/NormEngine.cpp ${SOFACOMPONENTENGINEGENERATE_SOURCE_DIR}/NormalsFromPoints.cpp ${SOFACOMPONENTENGINEGENERATE_SOURCE_DIR}/RandomPointDistributionInSurface.cpp - ${SOFACOMPONENTENGINEGENERATE_SOURCE_DIR}/VolumeFromTetrahedrons.cpp + ${SOFACOMPONENTENGINEGENERATE_SOURCE_DIR}/VolumeFromVolumetricElements.cpp ${SOFACOMPONENTENGINEGENERATE_SOURCE_DIR}/VolumeFromTriangles.cpp ${SOFACOMPONENTENGINEGENERATE_SOURCE_DIR}/Spiral.cpp ) +set(DEPRECATED_DIR "compat/sofa/component/engine/generate") +set(DEPRECATED_HEADER_FILES + ${DEPRECATED_DIR}/VolumeFromTetrahedrons.h + ${DEPRECATED_DIR}/VolumeFromTetrahedrons.inl +) + + sofa_find_package(Sofa.Simulation.Core REQUIRED) add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES}) target_link_libraries(${PROJECT_NAME} PUBLIC Sofa.Simulation.Core) +target_include_directories(${PROJECT_NAME} PUBLIC + $ + $ +) sofa_create_package_with_targets( PACKAGE_NAME ${PROJECT_NAME} @@ -90,6 +101,8 @@ sofa_create_package_with_targets( INCLUDE_INSTALL_DIR "${PROJECT_NAME}" ) +install(DIRECTORY compat/ DESTINATION include/${PROJECT_NAME}_compat COMPONENT headers) + # Tests # If SOFA_BUILD_TESTS exists and is OFF, then these tests will be auto-disabled cmake_dependent_option(SOFA_COMPONENT_ENGINE_GENERATE_BUILD_TESTS "Compile the automatic tests" ON "SOFA_BUILD_TESTS OR NOT DEFINED SOFA_BUILD_TESTS" OFF) diff --git a/Sofa/Component/Engine/Generate/compat/sofa/component/engine/generate/VolumeFromTetrahedrons.h b/Sofa/Component/Engine/Generate/compat/sofa/component/engine/generate/VolumeFromTetrahedrons.h new file mode 100644 index 00000000000..1e8416d18bc --- /dev/null +++ b/Sofa/Component/Engine/Generate/compat/sofa/component/engine/generate/VolumeFromTetrahedrons.h @@ -0,0 +1,32 @@ +/****************************************************************************** +* 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 +SOFA_HEADER_DEPRECATED("v26.12", "v27.06", "sofa/component/engine/generate/VolumeFromVolumetricElements.h") + +namespace sofa::component::engine::generate +{ + +template +using VolumeFromTetrahedrons SOFA_ATTRIBUTE_DEPRECATED__VOLUMEFROMTETRAHEDRONS() = VolumeFromVolumetricElements; + +} diff --git a/Sofa/Component/Engine/Generate/compat/sofa/component/engine/generate/VolumeFromTetrahedrons.inl b/Sofa/Component/Engine/Generate/compat/sofa/component/engine/generate/VolumeFromTetrahedrons.inl new file mode 100644 index 00000000000..56fe5150811 --- /dev/null +++ b/Sofa/Component/Engine/Generate/compat/sofa/component/engine/generate/VolumeFromTetrahedrons.inl @@ -0,0 +1,25 @@ +/****************************************************************************** +* 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 +SOFA_HEADER_DEPRECATED("v26.12", "v27.06", "sofa/component/engine/generate/VolumeFromVolumetricElements.inl") diff --git a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/VolumeFromTetrahedrons.cpp b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/VolumeFromVolumetricElements.cpp similarity index 82% rename from Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/VolumeFromTetrahedrons.cpp rename to Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/VolumeFromVolumetricElements.cpp index 1bfe0d5067e..3e183a24f62 100644 --- a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/VolumeFromTetrahedrons.cpp +++ b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/VolumeFromVolumetricElements.cpp @@ -19,9 +19,9 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#define SOFA_COMPONENT_ENGINE_VOLUMEFROMTETRAHEDRONS_CPP +#define SOFA_COMPONENT_ENGINE_VOLUMEFROMVOLUMETRICELEMENTS_CPP -#include +#include #include namespace sofa::component::engine::generate @@ -30,13 +30,15 @@ namespace sofa::component::engine::generate using namespace sofa::defaulttype; using namespace sofa::helper; -void registerVolumeFromTetrahedrons(sofa::core::ObjectFactory* factory) +void registerVolumeFromVolumetricElements(sofa::core::ObjectFactory* factory) { factory->registerObjects(sofa::core::ObjectRegistrationData("This component computes the volume of a given volumetric mesh.") - .add< VolumeFromTetrahedrons >(true)); + .add< VolumeFromVolumetricElements >(true) + .addAlias("VolumeFromTetrahedrons") + ); } -template class SOFA_COMPONENT_ENGINE_GENERATE_API VolumeFromTetrahedrons; +template class SOFA_COMPONENT_ENGINE_GENERATE_API VolumeFromVolumetricElements; } // namespace diff --git a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/VolumeFromTetrahedrons.h b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/VolumeFromVolumetricElements.h similarity index 83% rename from Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/VolumeFromTetrahedrons.h rename to Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/VolumeFromVolumetricElements.h index 1fe4653e932..dbced3d256b 100644 --- a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/VolumeFromTetrahedrons.h +++ b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/VolumeFromVolumetricElements.h @@ -33,10 +33,10 @@ namespace sofa::component::engine::generate * This class returns the volumes of a given volumic mesh. */ template -class VolumeFromTetrahedrons : public sofa::core::DataEngine +class VolumeFromVolumetricElements : public sofa::core::DataEngine { public: - SOFA_CLASS(SOFA_TEMPLATE(VolumeFromTetrahedrons,DataTypes), sofa::core::DataEngine); + SOFA_CLASS(SOFA_TEMPLATE(VolumeFromVolumetricElements,DataTypes), sofa::core::DataEngine); typedef typename DataTypes::VecCoord VecCoord; @@ -54,8 +54,8 @@ class VolumeFromTetrahedrons : public sofa::core::DataEngine public: - VolumeFromTetrahedrons(); - ~VolumeFromTetrahedrons() override; + VolumeFromVolumetricElements(); + ~VolumeFromVolumetricElements() override; ////////////////////////// Inherited from BaseObject /////////////////// void init() override; @@ -71,8 +71,8 @@ class VolumeFromTetrahedrons : public sofa::core::DataEngine protected: - SingleLink, BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology; - SingleLink, MechanicalState, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_state; + SingleLink, BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology; + SingleLink, MechanicalState, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_state; sofa::Data d_positions; sofa::Data d_tetras; @@ -89,8 +89,8 @@ class VolumeFromTetrahedrons : public sofa::core::DataEngine void checkTopology(); }; -#if !defined(SOFA_COMPONENT_ENGINE_VOLUMEFROMTETRAHEDRONS_CPP) -extern template class VolumeFromTetrahedrons; +#if !defined(SOFA_COMPONENT_ENGINE_VOLUMEFROMVOLUMETRICELEMENTS_CPP) +extern template class VolumeFromVolumetricElements; #endif } // namespace diff --git a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/VolumeFromTetrahedrons.inl b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/VolumeFromVolumetricElements.inl similarity index 92% rename from Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/VolumeFromTetrahedrons.inl rename to Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/VolumeFromVolumetricElements.inl index dd1632b03c9..b9b09e2b3c3 100644 --- a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/VolumeFromTetrahedrons.inl +++ b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/VolumeFromVolumetricElements.inl @@ -22,7 +22,7 @@ #pragma once #include -#include +#include #include #include @@ -37,7 +37,7 @@ using sofa::core::objectmodel::BaseData; template -VolumeFromTetrahedrons::VolumeFromTetrahedrons() +VolumeFromVolumetricElements::VolumeFromVolumetricElements() : l_topology(initLink("topology", "link to the topology")) , l_state(initLink("mechanical", "link to the mechanical")) @@ -51,7 +51,7 @@ VolumeFromTetrahedrons::VolumeFromTetrahedrons() } template -void VolumeFromTetrahedrons::parse(core::objectmodel::BaseObjectDescription* arg) +void VolumeFromVolumetricElements::parse(core::objectmodel::BaseObjectDescription* arg) { Inherit1::parse(arg); @@ -63,13 +63,13 @@ void VolumeFromTetrahedrons::parse(core::objectmodel::BaseObjectDescr } template -VolumeFromTetrahedrons::~VolumeFromTetrahedrons() +VolumeFromVolumetricElements::~VolumeFromVolumetricElements() { } template -void VolumeFromTetrahedrons::init() +void VolumeFromVolumetricElements::init() { Inherit1::init(); @@ -107,7 +107,7 @@ void VolumeFromTetrahedrons::init() template -void VolumeFromTetrahedrons::reinit() +void VolumeFromVolumetricElements::reinit() { if(d_componentState.getValue() != ComponentState::Valid) return ; @@ -117,7 +117,7 @@ void VolumeFromTetrahedrons::reinit() template -void VolumeFromTetrahedrons::initTopology() +void VolumeFromVolumetricElements::initTopology() { if (!l_topology.get()) { @@ -145,7 +145,7 @@ void VolumeFromTetrahedrons::initTopology() template -void VolumeFromTetrahedrons::checkTopology() +void VolumeFromVolumetricElements::checkTopology() { ReadAccessor > positions = d_positions; ReadAccessor > tetras = d_tetras; @@ -194,7 +194,7 @@ void VolumeFromTetrahedrons::checkTopology() template -void VolumeFromTetrahedrons::doUpdate() +void VolumeFromVolumetricElements::doUpdate() { if(d_componentState.getValue() != ComponentState::Valid) return ; @@ -210,7 +210,7 @@ void VolumeFromTetrahedrons::doUpdate() template -void VolumeFromTetrahedrons::updateVolume() +void VolumeFromVolumetricElements::updateVolume() { Real volume = 0.; diff --git a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/config.h.in b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/config.h.in index a71a0a86bec..4c78c7bdb4b 100644 --- a/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/config.h.in +++ b/Sofa/Component/Engine/Generate/src/sofa/component/engine/generate/config.h.in @@ -36,3 +36,11 @@ namespace sofa::component::engine::generate constexpr const char* MODULE_NAME = "@PROJECT_NAME@"; constexpr const char* MODULE_VERSION = "@PROJECT_VERSION@"; } // namespace sofa::component::engine::generate + + +#ifdef SOFA_BUILD_SOFA_COMPONENT_ENGINE_GENERATE +#define SOFA_ATTRIBUTE_DEPRECATED__VOLUMEFROMTETRAHEDRONS() +#else +#define SOFA_ATTRIBUTE_DEPRECATED__VOLUMEFROMTETRAHEDRONS() \ + SOFA_ATTRIBUTE_DEPRECATED("v26.12", "v27.06", "Use the VolumeFromVolumetricElements instead") +#endif 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 ebdca5b8b3c..3df2ea05b4b 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 @@ -47,7 +47,7 @@ extern void registerNormEngine(sofa::core::ObjectFactory* factory); extern void registerRandomPointDistributionInSurface(sofa::core::ObjectFactory* factory); extern void registerSpiral(sofa::core::ObjectFactory* factory); extern void registerVolumeFromTriangles(sofa::core::ObjectFactory* factory); -extern void registerVolumeFromTetrahedrons(sofa::core::ObjectFactory* factory); +extern void registerVolumeFromVolumetricElements(sofa::core::ObjectFactory* factory); extern "C" { SOFA_EXPORT_DYNAMIC_LIBRARY void initExternalModule(); @@ -94,7 +94,7 @@ void registerObjects(sofa::core::ObjectFactory* factory) registerRandomPointDistributionInSurface(factory); registerSpiral(factory); registerVolumeFromTriangles(factory); - registerVolumeFromTetrahedrons(factory); + registerVolumeFromVolumetricElements(factory); } void init() diff --git a/Sofa/Component/Engine/Generate/tests/CMakeLists.txt b/Sofa/Component/Engine/Generate/tests/CMakeLists.txt index b6c01cdc787..3d0f97a6cd6 100644 --- a/Sofa/Component/Engine/Generate/tests/CMakeLists.txt +++ b/Sofa/Component/Engine/Generate/tests/CMakeLists.txt @@ -9,7 +9,7 @@ set(SOURCE_FILES MergePoints_test.cpp RandomPointDistributionInSurface_test.cpp VolumeFromTriangles_test.cpp - VolumeFromTetrahedrons_test.cpp + VolumeFromVolumetricElements_test.cpp ) find_package(Sofa.Component.StateContainer REQUIRED) diff --git a/Sofa/Component/Engine/Generate/tests/VolumeFromTetrahedrons_test.cpp b/Sofa/Component/Engine/Generate/tests/VolumeFromVolumetricElements_test.cpp similarity index 86% rename from Sofa/Component/Engine/Generate/tests/VolumeFromTetrahedrons_test.cpp rename to Sofa/Component/Engine/Generate/tests/VolumeFromVolumetricElements_test.cpp index 1221828b7ad..81d08829f81 100644 --- a/Sofa/Component/Engine/Generate/tests/VolumeFromTetrahedrons_test.cpp +++ b/Sofa/Component/Engine/Generate/tests/VolumeFromVolumetricElements_test.cpp @@ -48,8 +48,8 @@ using sofa::component::statecontainer::MechanicalObject ; using sofa::core::topology::BaseMeshTopology ; using sofa::core::objectmodel::Data ; -#include -using sofa::component::engine::generate::VolumeFromTetrahedrons ; +#include +using sofa::component::engine::generate::VolumeFromVolumetricElements ; #include using sofa::helper::system::DataRepository; @@ -60,9 +60,9 @@ namespace sofa { template -struct VolumeFromTetrahedronsTest : public sofa::testing::BaseTest, VolumeFromTetrahedrons<_DataTypes> +struct VolumeFromVolumetricElementsTest : public sofa::testing::BaseTest, VolumeFromVolumetricElements<_DataTypes> { - typedef VolumeFromTetrahedrons<_DataTypes> ThisClass ; + typedef VolumeFromVolumetricElements<_DataTypes> ThisClass ; typedef _DataTypes DataTypes; typedef typename DataTypes::Coord Coord; typedef typename DataTypes::VecCoord VecCoord; @@ -76,9 +76,9 @@ struct VolumeFromTetrahedronsTest : public sofa::testing::BaseTest, VolumeFromTe /////////////////////////////////////////////////////////////// // Bring parents members in the current lookup context. // more info at: https://gcc.gnu.org/onlinedocs/gcc/Name-lookup.html - using VolumeFromTetrahedrons<_DataTypes>::d_volume ; - using VolumeFromTetrahedrons<_DataTypes>::d_tetras ; - using VolumeFromTetrahedrons<_DataTypes>::d_hexas ; + using VolumeFromVolumetricElements<_DataTypes>::d_volume ; + using VolumeFromVolumetricElements<_DataTypes>::d_tetras ; + using VolumeFromVolumetricElements<_DataTypes>::d_hexas ; /////////////////////////////////////////////////////////////// @@ -111,7 +111,7 @@ struct VolumeFromTetrahedronsTest : public sofa::testing::BaseTest, VolumeFromTe "" " " " " - " " + " " " " ; EXPECT_NO_THROW(SceneLoaderXML::loadFromMemory ( "test", scene.c_str())) ; } @@ -139,18 +139,18 @@ struct VolumeFromTetrahedronsTest : public sofa::testing::BaseTest, VolumeFromTe using ::testing::Types; typedef Types DataTypes; -TYPED_TEST_SUITE(VolumeFromTetrahedronsTest, DataTypes); +TYPED_TEST_SUITE(VolumeFromVolumetricElementsTest, DataTypes); -TYPED_TEST(VolumeFromTetrahedronsTest, NormalBehavior) { +TYPED_TEST(VolumeFromVolumetricElementsTest, NormalBehavior) { ASSERT_NO_THROW(this->normalTests()) ; } -TYPED_TEST(VolumeFromTetrahedronsTest, SimpleScene) { +TYPED_TEST(VolumeFromVolumetricElementsTest, SimpleScene) { ASSERT_NO_THROW(this->simpleSceneTest()) ; } -TYPED_TEST(VolumeFromTetrahedronsTest, VolumeComputation) { +TYPED_TEST(VolumeFromVolumetricElementsTest, VolumeComputation) { ASSERT_DOUBLE_EQ(12.5,this->volumeComputationTest()); } } diff --git a/Sofa/framework/Helper/src/sofa/helper/ComponentChange.cpp b/Sofa/framework/Helper/src/sofa/helper/ComponentChange.cpp index 41835aa4239..2688625d38a 100644 --- a/Sofa/framework/Helper/src/sofa/helper/ComponentChange.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/ComponentChange.cpp @@ -767,7 +767,8 @@ std::map< std::string, Renamed, std::less<> > renamedComponents = { {"ParallelStiffSpringForceField", Renamed("v24.06","v25.06","ParallelSpringForceField")}, {"ShewchukPCGLinearSolver", Renamed("v24.12","v25.12","PCGLinearSolver")}, {"OglCylinderModel", Renamed("v24.12", "v25.06", "CylinderVisualModel")}, - {"TriangleOctreeModel", Renamed("v25.12", "v26.06", "TriangleOctreeCollisionModel") } + {"TriangleOctreeModel", Renamed("v25.12", "v26.06", "TriangleOctreeCollisionModel") }, + {"VolumeFromTetrahedrons", Renamed("v26.12", "v27.06", "VolumeFromVolumetricElements") } }; diff --git a/examples/Component/Engine/Generate/VolumeFromTetrahedrons.scn b/examples/Component/Engine/Generate/VolumeFromVolumetricElements.scn similarity index 90% rename from examples/Component/Engine/Generate/VolumeFromTetrahedrons.scn rename to examples/Component/Engine/Generate/VolumeFromVolumetricElements.scn index d275a36de14..a26ad69aaba 100644 --- a/examples/Component/Engine/Generate/VolumeFromTetrahedrons.scn +++ b/examples/Component/Engine/Generate/VolumeFromVolumetricElements.scn @@ -1,6 +1,6 @@ - + @@ -14,7 +14,7 @@ - + From 246108d5d70a38bc5801a765e37077533fec6adf Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Thu, 30 Jul 2026 04:33:06 +0200 Subject: [PATCH 09/20] [Mapper] Missing `override` keyword (#6215) --- .../response/mapper/RigidContactMapper.h | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Sofa/Component/Collision/Response/Mapper/src/sofa/component/collision/response/mapper/RigidContactMapper.h b/Sofa/Component/Collision/Response/Mapper/src/sofa/component/collision/response/mapper/RigidContactMapper.h index 9b2407fda8f..dc17f2d4c9e 100644 --- a/Sofa/Component/Collision/Response/Mapper/src/sofa/component/collision/response/mapper/RigidContactMapper.h +++ b/Sofa/Component/Collision/Response/Mapper/src/sofa/component/collision/response/mapper/RigidContactMapper.h @@ -67,11 +67,11 @@ class RigidContactMapper : public BaseContactMapper this->model = model; } - void cleanup(); + void cleanup() override; - MMechanicalState* createMapping(const char* name="contactPoints"); + MMechanicalState* createMapping(const char* name="contactPoints") override; - void resize(Size size) + void resize(Size size) override { if (mapping != nullptr) mapping->clear(size); @@ -80,7 +80,7 @@ class RigidContactMapper : public BaseContactMapper nbp = 0; } - Index addPoint(const Coord& P, Index index, Real&) + Index addPoint(const Coord& P, Index index, Real&) override { Index i = nbp++; if (outmodel->getSize() <= i) @@ -97,7 +97,7 @@ class RigidContactMapper : public BaseContactMapper return i; } - void update() + void update() override { if (mapping != nullptr) { @@ -107,7 +107,7 @@ class RigidContactMapper : public BaseContactMapper } } - void updateXfree() + void updateXfree() override { if (mapping != nullptr) { @@ -122,8 +122,8 @@ class RigidContactMapper : public BaseContactMapper template class ContactMapper : public RigidContactMapper{ public: - sofa::Index addPoint(const typename TVec3Types::Coord & P, sofa::Index index,typename TVec3Types::Real & r) - { + sofa::Index addPoint(const typename TVec3Types::Coord & P, sofa::Index index,typename TVec3Types::Real & r) override + { const collision::geometry::RigidSphere e(this->model, index); const typename collision::geometry::SphereCollisionModel::DataTypes::Coord & rCenter = e.rigidCenter(); const typename TVec3Types::Coord & cP = P - rCenter.getCenter(); @@ -138,8 +138,8 @@ class ContactMapper : public template class ContactMapper,TVec3Types > : public RigidContactMapper, TVec3Types >{ public: - sofa::Index addPoint(const typename TVec3Types::Coord & P, sofa::Index index,typename TVec3Types::Real & r) - { + sofa::Index addPoint(const typename TVec3Types::Coord & P, sofa::Index index,typename TVec3Types::Real & r) override + { const typename TVec3Types::Coord & cP = P - this->model->center(index); const type::Quat & ori = this->model->orientation(index); From 48c059a7cb0ce3d43a4d94f99806141aed881ea3 Mon Sep 17 00:00:00 2001 From: Lucas Burel Date: Mon, 22 Dec 2025 16:39:09 +0100 Subject: [PATCH 10/20] cleaning add functions --- Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp index 0c3bf63bfe5..96bb3739e7b 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp @@ -227,7 +227,7 @@ void BaseComponent::addSlave(BaseComponent::SPtr s) previous->l_slaves.remove(s); l_slaves.add(s.get()); previous->l_slaves.remove(s.get()); - l_slaves.add(s); + l_slaves.add(s.get()); if (previous) this->getContext()->notifyMoveSlave(previous.get(), this, s.get()); else From 6ab4044eda9bc0d4062bf08497f01bb64ffb69e8 Mon Sep 17 00:00:00 2001 From: Lucas-TJ Date: Thu, 18 Jun 2026 09:10:14 +0200 Subject: [PATCH 11/20] add unit test --- .../objectmodel/BaseLink_simutest.cpp | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp b/Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp index 94bfe56f5ae..8bcc99800bf 100644 --- a/Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp +++ b/Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp @@ -42,6 +42,8 @@ using sofa::defaulttype::Rigid3Types; #include using sofa::defaulttype::Vec3Types; +using sofa::core::objectmodel::BaseLink; + namespace { @@ -114,6 +116,30 @@ TEST_F(BaseLink_test, remove) ASSERT_FALSE(owner.l_target.remove(nullptr)); } +TEST_F(BaseLink_test, add) +{ + FakeComponent Component1; + Component1.setName("Component1"); + FakeComponent Component2; + Component2.setName("Component2"); + FakeComponent Component3; + Component3.setName("Component3"); + + FakeComponent* ptr; + ptr = &Component2; + + EXPECT_EQ(Component1.l_target.getValueString(), ""); + + Component1.l_target.add(ptr); + EXPECT_EQ(Component1.l_target.getValueString(), "@Component2"); + + ptr = &Component3; + + Component1.l_target.add(ptr); + EXPECT_EQ(Component1.l_target.getValueString(), "@Component2 @Component3"); +} + + //////////////////////// Testing valid path ////////////////////////////////////// class MultiLink_simutest : public BaseLink_test {}; From b84f7b5259d31b007b9c144c7013a2d52b1981bc Mon Sep 17 00:00:00 2001 From: Lucas-TJ Date: Wed, 29 Jul 2026 18:04:53 +0200 Subject: [PATCH 12/20] [CORE] Add remove function in BaseLink (#6130) * add doremove * clean * add unit test * remove useless include --- Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp | 2 -- Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp | 2 -- 2 files changed, 4 deletions(-) diff --git a/Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp b/Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp index 8bcc99800bf..03f69825c08 100644 --- a/Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp +++ b/Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp @@ -42,8 +42,6 @@ using sofa::defaulttype::Rigid3Types; #include using sofa::defaulttype::Vec3Types; -using sofa::core::objectmodel::BaseLink; - namespace { diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp index 96bb3739e7b..52b37938401 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp @@ -224,8 +224,6 @@ void BaseComponent::addSlave(BaseComponent::SPtr s) const BaseComponent::SPtr previous = s->getMaster(); if (previous == this) return; if (previous) - previous->l_slaves.remove(s); - l_slaves.add(s.get()); previous->l_slaves.remove(s.get()); l_slaves.add(s.get()); if (previous) From 3e4784c282e668d19b2ef5b1b49a19fa12e9b4eb Mon Sep 17 00:00:00 2001 From: Lucas-TJ Date: Wed, 29 Jul 2026 18:04:53 +0200 Subject: [PATCH 13/20] [CORE] Add remove function in BaseLink (#6130) * add doremove * clean * add unit test * remove useless include --- Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp index 52b37938401..7536722f52c 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp @@ -226,6 +226,8 @@ void BaseComponent::addSlave(BaseComponent::SPtr s) if (previous) previous->l_slaves.remove(s.get()); l_slaves.add(s.get()); + previous->l_slaves.remove(s.get()); + l_slaves.add(s); if (previous) this->getContext()->notifyMoveSlave(previous.get(), this, s.get()); else From 2e78dc5c0480d221622a5deddaecc16a22a4cb47 Mon Sep 17 00:00:00 2001 From: Lucas Burel Date: Mon, 22 Dec 2025 16:39:09 +0100 Subject: [PATCH 14/20] cleaning add functions --- Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp index 7536722f52c..def3d1c03b6 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp @@ -227,7 +227,7 @@ void BaseComponent::addSlave(BaseComponent::SPtr s) previous->l_slaves.remove(s.get()); l_slaves.add(s.get()); previous->l_slaves.remove(s.get()); - l_slaves.add(s); + l_slaves.add(s.get()); if (previous) this->getContext()->notifyMoveSlave(previous.get(), this, s.get()); else From 359eefe118560dd16f12153fbc8c42a9536e63a0 Mon Sep 17 00:00:00 2001 From: Lucas-TJ Date: Thu, 18 Jun 2026 09:10:14 +0200 Subject: [PATCH 15/20] add unit test --- Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp b/Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp index 03f69825c08..8bcc99800bf 100644 --- a/Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp +++ b/Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp @@ -42,6 +42,8 @@ using sofa::defaulttype::Rigid3Types; #include using sofa::defaulttype::Vec3Types; +using sofa::core::objectmodel::BaseLink; + namespace { From c48cee3f46925fc71f2386be51212265b0e72949 Mon Sep 17 00:00:00 2001 From: Lucas-TJ Date: Thu, 30 Jul 2026 16:43:18 +0200 Subject: [PATCH 16/20] cleaning --- Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp index def3d1c03b6..52b37938401 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp @@ -225,8 +225,6 @@ void BaseComponent::addSlave(BaseComponent::SPtr s) if (previous == this) return; if (previous) previous->l_slaves.remove(s.get()); - l_slaves.add(s.get()); - previous->l_slaves.remove(s.get()); l_slaves.add(s.get()); if (previous) this->getContext()->notifyMoveSlave(previous.get(), this, s.get()); From 0e7f361f10118ade9a9ffa3fe1bc8176fea5f058 Mon Sep 17 00:00:00 2001 From: Lucas-TJ Date: Thu, 30 Jul 2026 16:59:40 +0200 Subject: [PATCH 17/20] cleaning --- Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp b/Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp index 8bcc99800bf..03f69825c08 100644 --- a/Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp +++ b/Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp @@ -42,8 +42,6 @@ using sofa::defaulttype::Rigid3Types; #include using sofa::defaulttype::Vec3Types; -using sofa::core::objectmodel::BaseLink; - namespace { From cf24261e5a4dc2a725c683091f939701a8d36ff0 Mon Sep 17 00:00:00 2001 From: Lucas-TJ Date: Fri, 31 Jul 2026 14:40:32 +0200 Subject: [PATCH 18/20] restore and rename functions in Link.h --- .../sofa/core/objectmodel/BaseComponent.cpp | 2 +- .../Core/src/sofa/core/objectmodel/Link.h | 36 +++++++++++++------ .../Core/src/sofa/simulation/Node.cpp | 4 +-- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp index 52b37938401..f3da3fff4d4 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp @@ -225,7 +225,7 @@ void BaseComponent::addSlave(BaseComponent::SPtr s) if (previous == this) return; if (previous) previous->l_slaves.remove(s.get()); - l_slaves.add(s.get()); + l_slaves.addDestPtr(s); if (previous) this->getContext()->notifyMoveSlave(previous.get(), this, s.get()); else diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/Link.h b/Sofa/framework/Core/src/sofa/core/objectmodel/Link.h index bc8061ac8d6..6180eec630f 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/Link.h +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/Link.h @@ -377,6 +377,27 @@ class TLink : public BaseLink return true; } + bool addDestPtr(DestPtr v) + { + if (!v) + return false; + const std::size_t index = TraitsContainer::add(m_value,v); + updateCounter(); + added(v, index); + return true; + } + + bool addDestPtrPath(DestPtr v, const std::string& path) + { + if (!v && path.empty()) + return false; + std::size_t index = TraitsContainer::add(m_value,v); + TraitsValueType::setPath(m_value[index],path); + updateCounter(); + added(v, index); + return true; + } + bool addPath(const std::string& path) { if (path.empty()) @@ -482,11 +503,7 @@ class TLink : public BaseLink } /// TLink:adding accepts nullptr (for a not yet resolved link). - std::size_t index = TraitsContainer::add(m_value, destptr); - TraitsValueType::setPath(m_value[index], path); - updateCounter(); - added(destptr, index); - return true; + return TLink::addDestPtrPath(destptr, path); } bool _doAdd_(Base* baseptr) override @@ -504,10 +521,7 @@ class TLink : public BaseLink } /// TLink:adding accepts nullptr (for a not yet resolved link). - const std::size_t index = TraitsContainer::add(m_value, destptr); - updateCounter(); - added(destptr, index); - return true;; + return TLink::addDestPtr(destptr); } /// Returns false on type mismatch @@ -581,7 +595,7 @@ class MultiLink : public TLink& init, DestPtr val) : Inherit(init), m_validator(nullptr) { - if (val) this->_doAdd_(sofa::core::castToBase(TraitsDestPtr::get(val))); + if (val) this->addDestPtr(val); } virtual ~MultiLink() @@ -658,7 +672,7 @@ class SingleLink : public TLink& init, DestPtr val) : Inherit(init), m_validator(nullptr) { - if (val) this->_doAdd_(sofa::core::castToBase(TraitsDestPtr::get(val))); + if (val) this->addDestPtr(val); } virtual ~SingleLink() diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp index 23303e6ea6b..336246aef08 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp @@ -635,7 +635,7 @@ bool Node::doAddObject(sofa::core::objectmodel::BaseComponent::SPtr sobj, sofa:: { this->setObjectContext(sobj); if(insertionLocation == sofa::core::objectmodel::TypeOfInsertion::AtEnd) - object.add(sobj.get()); + object.addDestPtr(sobj); else object.addBegin(sobj); @@ -1182,7 +1182,7 @@ void Node::doAddChild(BaseNode::SPtr node) { const Node::SPtr dagnode = sofa::core::objectmodel::SPtr_static_cast(node); setDirtyDescendancy(); - child.add(dagnode.get()); + child.addDestPtr(dagnode); dagnode->l_parents.add(this); dagnode->l_parents.updateLinks(); // to fix load-time unresolved links } From 089ae6fac9e8db8fc82a3e5f35b88ff2e0e9c054 Mon Sep 17 00:00:00 2001 From: Lucas-TJ Date: Fri, 31 Jul 2026 14:44:42 +0200 Subject: [PATCH 19/20] cleaning --- .../Core/src/sofa/core/objectmodel/BaseComponent.cpp | 2 +- Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp index f3da3fff4d4..49e17f00a59 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp @@ -225,7 +225,7 @@ void BaseComponent::addSlave(BaseComponent::SPtr s) if (previous == this) return; if (previous) previous->l_slaves.remove(s.get()); - l_slaves.addDestPtr(s); + l_slaves.addDestPtr(s.get()); if (previous) this->getContext()->notifyMoveSlave(previous.get(), this, s.get()); else diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp index 336246aef08..23303e6ea6b 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp @@ -635,7 +635,7 @@ bool Node::doAddObject(sofa::core::objectmodel::BaseComponent::SPtr sobj, sofa:: { this->setObjectContext(sobj); if(insertionLocation == sofa::core::objectmodel::TypeOfInsertion::AtEnd) - object.addDestPtr(sobj); + object.add(sobj.get()); else object.addBegin(sobj); @@ -1182,7 +1182,7 @@ void Node::doAddChild(BaseNode::SPtr node) { const Node::SPtr dagnode = sofa::core::objectmodel::SPtr_static_cast(node); setDirtyDescendancy(); - child.addDestPtr(dagnode); + child.add(dagnode.get()); dagnode->l_parents.add(this); dagnode->l_parents.updateLinks(); // to fix load-time unresolved links } From f0621d28680428d51e260d08fe181fd32b69ecbf Mon Sep 17 00:00:00 2001 From: Lucas-TJ Date: Fri, 31 Jul 2026 14:46:45 +0200 Subject: [PATCH 20/20] cleaning --- Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp index 49e17f00a59..52b37938401 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp @@ -225,7 +225,7 @@ void BaseComponent::addSlave(BaseComponent::SPtr s) if (previous == this) return; if (previous) previous->l_slaves.remove(s.get()); - l_slaves.addDestPtr(s.get()); + l_slaves.add(s.get()); if (previous) this->getContext()->notifyMoveSlave(previous.get(), this, s.get()); else