From 6a2554e65f2becb9076e418990b4db75d907fd98 Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Wed, 4 Jun 2025 20:57:51 +0200 Subject: [PATCH 1/5] Apply new factory registration mechanism --- .../ShapeMatchingForceField.cpp | 12 ++++++---- .../ShapeMatchingForceField.h | 4 ++-- .../ShapeMatchingForceField.inl | 4 ++-- .../ShapeMatchingRotationFinder.cpp | 14 ++++++----- .../ShapeMatchingRotationFinder.h | 4 ++-- .../ShapeMatchingRotationFinder.inl | 4 ++-- .../initShapeMatchingPlugin.cpp | 24 ++++++++++++------- .../initShapeMatchingPlugin.h | 5 ++-- 8 files changed, 40 insertions(+), 31 deletions(-) diff --git a/src/ShapeMatchingPlugin/ShapeMatchingForceField.cpp b/src/ShapeMatchingPlugin/ShapeMatchingForceField.cpp index 681f3ad..0957bad 100644 --- a/src/ShapeMatchingPlugin/ShapeMatchingForceField.cpp +++ b/src/ShapeMatchingPlugin/ShapeMatchingForceField.cpp @@ -25,15 +25,17 @@ #include #include -namespace sofa::component::forcefield +namespace shapematchingplugin { using namespace sofa::defaulttype; -int ShapeMatchingForceFieldClass = core::RegisterObject("Meshless deformations based on shape matching") -.add< ShapeMatchingForceField >() -; +void registerShapeMatchingForceField(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(sofa::core::ObjectRegistrationData("Meshless deformations based on shape matching") + .add< ShapeMatchingForceField >()); +} template class SOFA_SHAPEMATCHINGPLUGIN_API ShapeMatchingForceField; -} // namespace sofa::component::forcefield +} // namespace shapematchingplugin diff --git a/src/ShapeMatchingPlugin/ShapeMatchingForceField.h b/src/ShapeMatchingPlugin/ShapeMatchingForceField.h index df03096..42ab526 100644 --- a/src/ShapeMatchingPlugin/ShapeMatchingForceField.h +++ b/src/ShapeMatchingPlugin/ShapeMatchingForceField.h @@ -30,7 +30,7 @@ #include -namespace sofa::component::forcefield +namespace shapematchingplugin { /// Meshless deformations based on shape matching @@ -74,4 +74,4 @@ class ShapeMatchingForceField : public core::behavior::ForceField extern template class SOFA_SHAPEMATCHINGPLUGIN_API ShapeMatchingForceField; #endif // !defined(SOFA_COMPONENT_FORCEFIELD_SHAPEMATCHINGFORCEFIELD_CPP) -} // namespace sofa::component::forcefield +} // namespace shapematchingplugin diff --git a/src/ShapeMatchingPlugin/ShapeMatchingForceField.inl b/src/ShapeMatchingPlugin/ShapeMatchingForceField.inl index ef75632..8618ade 100644 --- a/src/ShapeMatchingPlugin/ShapeMatchingForceField.inl +++ b/src/ShapeMatchingPlugin/ShapeMatchingForceField.inl @@ -28,7 +28,7 @@ #include #include -namespace sofa::component::forcefield +namespace shapematchingplugin { template @@ -148,4 +148,4 @@ void ShapeMatchingForceField::draw(const core::visual::VisualParams* } -} // namespace sofa::component::forcefield +} // namespace shapematchingplugin diff --git a/src/ShapeMatchingPlugin/ShapeMatchingRotationFinder.cpp b/src/ShapeMatchingPlugin/ShapeMatchingRotationFinder.cpp index 04fa8e4..ab08324 100644 --- a/src/ShapeMatchingPlugin/ShapeMatchingRotationFinder.cpp +++ b/src/ShapeMatchingPlugin/ShapeMatchingRotationFinder.cpp @@ -32,17 +32,19 @@ #include #include -namespace sofa::component::container +namespace shapematchingplugin { using namespace sofa::defaulttype; // Register in the Factory -int ShapeMatchingRotationFinderClass = core::RegisterObject("ShapeMatchingRotationFinder") -.add< ShapeMatchingRotationFinder< Vec3Types > >() -.addAlias("RotationFinder") -; +void registerShapeMatchingRotationFinder(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(sofa::core::ObjectRegistrationData("ShapeMatchingRotationFinder") + .add< ShapeMatchingRotationFinder< Vec3Types > >() + .addAlias("RotationFinder")); +} template class SOFA_SHAPEMATCHINGPLUGIN_API ShapeMatchingRotationFinder< defaulttype::Vec3Types >; -} // namespace sofa::component::container +} // namespace shapematchingplugin diff --git a/src/ShapeMatchingPlugin/ShapeMatchingRotationFinder.h b/src/ShapeMatchingPlugin/ShapeMatchingRotationFinder.h index 1f994bd..745069d 100644 --- a/src/ShapeMatchingPlugin/ShapeMatchingRotationFinder.h +++ b/src/ShapeMatchingPlugin/ShapeMatchingRotationFinder.h @@ -36,7 +36,7 @@ * "Meshless Deformations Based on Shape Matching" (Muller, Heidelberger, Teschner and Gross) * */ -namespace sofa::component::container +namespace shapematchingplugin { template @@ -120,4 +120,4 @@ class ShapeMatchingRotationFinder : public sofa::core::behavior::RotationFinder< extern template class SOFA_SHAPEMATCHINGPLUGIN_API ShapeMatchingRotationFinder< defaulttype::Vec3Types >; #endif -} // namespace sofa::component::container +} // namespace shapematchingplugin diff --git a/src/ShapeMatchingPlugin/ShapeMatchingRotationFinder.inl b/src/ShapeMatchingPlugin/ShapeMatchingRotationFinder.inl index 70c578b..abc869a 100644 --- a/src/ShapeMatchingPlugin/ShapeMatchingRotationFinder.inl +++ b/src/ShapeMatchingPlugin/ShapeMatchingRotationFinder.inl @@ -31,7 +31,7 @@ #include -namespace sofa::component::container +namespace shapematchingplugin { using namespace sofa::core::topology; @@ -619,4 +619,4 @@ void ShapeMatchingRotationFinder::draw(const core::visual::VisualPara vparams->drawTool()->restoreLastState(); } -} // namespace sofa::component::container +} // namespace shapematchingplugin diff --git a/src/ShapeMatchingPlugin/initShapeMatchingPlugin.cpp b/src/ShapeMatchingPlugin/initShapeMatchingPlugin.cpp index 623ccfd..f3f9f9a 100644 --- a/src/ShapeMatchingPlugin/initShapeMatchingPlugin.cpp +++ b/src/ShapeMatchingPlugin/initShapeMatchingPlugin.cpp @@ -24,17 +24,21 @@ ******************************************************************************/ #include #include +#include -namespace sofa::component +namespace shapematchingplugin { + extern void registerShapeMatchingForceField(sofa::core::ObjectFactory* factory); + extern void registerShapeMatchingRotationFinder(sofa::core::ObjectFactory* factory); + extern "C" { SOFA_SHAPEMATCHINGPLUGIN_API void initExternalModule(); SOFA_SHAPEMATCHINGPLUGIN_API const char* getModuleName(); SOFA_SHAPEMATCHINGPLUGIN_API const char* getModuleVersion(); SOFA_SHAPEMATCHINGPLUGIN_API const char* getModuleLicense(); SOFA_SHAPEMATCHINGPLUGIN_API const char* getModuleDescription(); - SOFA_SHAPEMATCHINGPLUGIN_API const char* getModuleComponentList(); + SOFA_SHAPEMATCHINGPLUGIN_API void registerObjects(sofa::core::ObjectFactory* factory); } void initShapeMatchingPlugin() @@ -44,6 +48,9 @@ namespace sofa::component void initExternalModule() { + // make sure that this plugin is registered into the PluginManager + sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME); + static bool first = true; if (first) { @@ -53,12 +60,12 @@ namespace sofa::component const char* getModuleName() { - return shapematching::MODULE_NAME; + return MODULE_NAME; } const char* getModuleVersion() { - return shapematching::MODULE_VERSION; + return MODULE_VERSION; } const char* getModuleLicense() @@ -71,11 +78,10 @@ namespace sofa::component return "Plugin with ShapeMatchingPlugin"; } - const char* getModuleComponentList() + void registerObjects(sofa::core::ObjectFactory* factory) { - /// string containing the names of the classes provided by the plugin - static std::string classes = sofa::core::ObjectFactory::getInstance()->listClassesFromTarget(sofa_tostring(SOFA_TARGET)); - return classes.c_str(); + void registerShapeMatchingForceField(factory); + void registerShapeMatchingRotationFinder(factory); } -} // namespace sofa::component +} // namespace shapematchingplugin diff --git a/src/ShapeMatchingPlugin/initShapeMatchingPlugin.h b/src/ShapeMatchingPlugin/initShapeMatchingPlugin.h index 812345c..7ee2de2 100644 --- a/src/ShapeMatchingPlugin/initShapeMatchingPlugin.h +++ b/src/ShapeMatchingPlugin/initShapeMatchingPlugin.h @@ -24,9 +24,8 @@ ******************************************************************************/ #include -namespace sofa::component -{ +namespace shapematchingplugin void SOFA_SHAPEMATCHINGPLUGIN_API initShapeMatchingPlugin(); -} // namespace sofa::component +} // namespace shapematchingplugin From d5ef295a0129dfa52f3f5aa4e118449a0162dc4a Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Wed, 4 Jun 2025 21:06:48 +0200 Subject: [PATCH 2/5] Use using namespace sofa --- src/ShapeMatchingPlugin/config.h.in | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ShapeMatchingPlugin/config.h.in b/src/ShapeMatchingPlugin/config.h.in index cbcde01..fbf7003 100644 --- a/src/ShapeMatchingPlugin/config.h.in +++ b/src/ShapeMatchingPlugin/config.h.in @@ -24,6 +24,8 @@ #include #include +using namespace sofa; + #define SHAPEMATCHINGPLUGIN_VERSION @PROJECT_VERSION@ #ifdef SOFA_BUILD_SHAPEMATCHINGPLUGIN @@ -33,7 +35,7 @@ # define SOFA_SHAPEMATCHINGPLUGIN_API SOFA_IMPORT_DYNAMIC_LIBRARY #endif -namespace shapematching +namespace shapematchingplugin { constexpr const char* MODULE_NAME = "@PROJECT_NAME@"; constexpr const char* MODULE_VERSION = "@PROJECT_VERSION@"; From 3047f741627c26a0677ea5afccd21b4eea3a253c Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Wed, 4 Jun 2025 21:25:26 +0200 Subject: [PATCH 3/5] Fix compil --- src/ShapeMatchingPlugin/initShapeMatchingPlugin.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ShapeMatchingPlugin/initShapeMatchingPlugin.h b/src/ShapeMatchingPlugin/initShapeMatchingPlugin.h index 7ee2de2..925ee08 100644 --- a/src/ShapeMatchingPlugin/initShapeMatchingPlugin.h +++ b/src/ShapeMatchingPlugin/initShapeMatchingPlugin.h @@ -25,6 +25,7 @@ #include namespace shapematchingplugin +{ void SOFA_SHAPEMATCHINGPLUGIN_API initShapeMatchingPlugin(); From 2d53a69c6029f1346cd4ec7c0219526d9b8425e0 Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Wed, 4 Jun 2025 21:38:55 +0200 Subject: [PATCH 4/5] Fix compil --- src/ShapeMatchingPlugin/initShapeMatchingPlugin.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ShapeMatchingPlugin/initShapeMatchingPlugin.cpp b/src/ShapeMatchingPlugin/initShapeMatchingPlugin.cpp index f3f9f9a..c528840 100644 --- a/src/ShapeMatchingPlugin/initShapeMatchingPlugin.cpp +++ b/src/ShapeMatchingPlugin/initShapeMatchingPlugin.cpp @@ -80,8 +80,8 @@ namespace shapematchingplugin void registerObjects(sofa::core::ObjectFactory* factory) { - void registerShapeMatchingForceField(factory); - void registerShapeMatchingRotationFinder(factory); + registerShapeMatchingForceField(factory); + registerShapeMatchingRotationFinder(factory); } } // namespace shapematchingplugin From 78da3195bad79e0773593116f5e5ba52c8a08770 Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Wed, 4 Jun 2025 21:48:09 +0200 Subject: [PATCH 5/5] remove container::ShapeMatching --- src/ShapeMatchingPlugin/ShapeMatchingForceField.h | 2 +- src/ShapeMatchingPlugin/ShapeMatchingForceField.inl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ShapeMatchingPlugin/ShapeMatchingForceField.h b/src/ShapeMatchingPlugin/ShapeMatchingForceField.h index 42ab526..5a11147 100644 --- a/src/ShapeMatchingPlugin/ShapeMatchingForceField.h +++ b/src/ShapeMatchingPlugin/ShapeMatchingForceField.h @@ -57,7 +57,7 @@ class ShapeMatchingForceField : public core::behavior::ForceField ShapeMatchingForceField(); public: - SingleLink, container::ShapeMatchingRotationFinder, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_rotationFinder; + SingleLink, ShapeMatchingRotationFinder, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_rotationFinder; Data d_stiffness; void init() override; diff --git a/src/ShapeMatchingPlugin/ShapeMatchingForceField.inl b/src/ShapeMatchingPlugin/ShapeMatchingForceField.inl index 8618ade..7a035f6 100644 --- a/src/ShapeMatchingPlugin/ShapeMatchingForceField.inl +++ b/src/ShapeMatchingPlugin/ShapeMatchingForceField.inl @@ -47,7 +47,7 @@ void ShapeMatchingForceField::init() if (!l_rotationFinder.get()) { - sofa::core::sptr< container::ShapeMatchingRotationFinder> rotationFinder; + sofa::core::sptr< ShapeMatchingRotationFinder> rotationFinder; this->getContext()->get(rotationFinder); if (!rotationFinder) {