From 2a00eed9b7cb7326c1d8ea70c19c4498e12c886e Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Mon, 3 Nov 2025 19:47:33 +0100 Subject: [PATCH 1/2] Apply new factory registration mechanism --- .../ClosestPointRegistrationForceField.cpp | 16 +++--- .../GroupwiseRegistrationEngine.cpp | 9 ++-- src/Registration/InertiaAlign.cpp | 8 +-- src/Registration/IntensityProfileCreator.cpp | 8 +-- ...IntensityProfileRegistrationForceField.cpp | 30 ++++++------ .../RegistrationContactForceField.cpp | 8 +-- src/Registration/RegistrationExporter.cpp | 7 ++- src/Registration/config.h.in | 9 ++-- src/Registration/initRegistration.cpp | 49 ++++++++++++++----- 9 files changed, 91 insertions(+), 53 deletions(-) diff --git a/src/Registration/ClosestPointRegistrationForceField.cpp b/src/Registration/ClosestPointRegistrationForceField.cpp index d9916e1..73c8aa1 100644 --- a/src/Registration/ClosestPointRegistrationForceField.cpp +++ b/src/Registration/ClosestPointRegistrationForceField.cpp @@ -34,17 +34,15 @@ namespace forcefield { using namespace sofa::defaulttype; - - // Register in the Factory - int ClosestPointRegistrationForceFieldClass = core::RegisterObject("Compute forces based on closest points from/to a target surface/point set") - .add< ClosestPointRegistrationForceField >() - ; - - template class SOFA_REGISTRATION_API ClosestPointRegistrationForceField; + // Register in the Factory + void registerClosestPointRegistrationForceField(sofa::core::ObjectFactory* factory) + { + factory->registerObjects(sofa::core::ObjectRegistrationData("Compute forces based on closest points from/to a target surface/point set") + .add< ClosestPointRegistrationForceField >()); + } - - + template class SOFA_REGISTRATION_API ClosestPointRegistrationForceField; } } diff --git a/src/Registration/GroupwiseRegistrationEngine.cpp b/src/Registration/GroupwiseRegistrationEngine.cpp index 97446b8..0323335 100644 --- a/src/Registration/GroupwiseRegistrationEngine.cpp +++ b/src/Registration/GroupwiseRegistrationEngine.cpp @@ -34,10 +34,13 @@ namespace engine using namespace defaulttype; -int GroupwiseRegistrationEngineClass = core::RegisterObject("Register a set of meshes of similar topology") - .add >(true) - ; +void registerGroupwiseRegistrationEngine(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(sofa::core::ObjectRegistrationData("Register a set of meshes of similar topology") + .add< GroupwiseRegistrationEngine< Vec3Types > >(true)); +} + template class SOFA_REGISTRATION_API GroupwiseRegistrationEngine< Vec3Types >; diff --git a/src/Registration/InertiaAlign.cpp b/src/Registration/InertiaAlign.cpp index c97e93e..5ab7c2f 100644 --- a/src/Registration/InertiaAlign.cpp +++ b/src/Registration/InertiaAlign.cpp @@ -38,9 +38,11 @@ namespace component using namespace sofa::type; using namespace sofa::defaulttype; -int InertiaAlignClass = core::RegisterObject("An engine computing inertia matrix and the principal direction of a mesh.") - .add< InertiaAlign >() - ; +void registerInertiaAlign(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(sofa::core::ObjectRegistrationData("An engine computing inertia matrix and the principal direction of a mesh") + .add< InertiaAlign >()); +} InertiaAlign::InertiaAlign() diff --git a/src/Registration/IntensityProfileCreator.cpp b/src/Registration/IntensityProfileCreator.cpp index eaf6c44..9167f6e 100644 --- a/src/Registration/IntensityProfileCreator.cpp +++ b/src/Registration/IntensityProfileCreator.cpp @@ -35,13 +35,15 @@ namespace engine using namespace defaulttype; -int IntensityProfileCreatorClass = core::RegisterObject("Create reference intensity profiles from custom values") +void registerIntensityProfileCreator(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(sofa::core::ObjectRegistrationData("Create reference intensity profiles from custom values") .add >(true) .add >() .add >() .add >() - .add >() - ; + .add >()); +} template class SOFA_REGISTRATION_API IntensityProfileCreator; template class SOFA_REGISTRATION_API IntensityProfileCreator; diff --git a/src/Registration/IntensityProfileRegistrationForceField.cpp b/src/Registration/IntensityProfileRegistrationForceField.cpp index 6d9f3b7..2fcf8cd 100644 --- a/src/Registration/IntensityProfileRegistrationForceField.cpp +++ b/src/Registration/IntensityProfileRegistrationForceField.cpp @@ -36,23 +36,23 @@ namespace forcefield using namespace defaulttype; // Register in the Factory - int IntensityProfileRegistrationForceFieldClass = core::RegisterObject("Compute normal forces on a point set based on the closest intensity profile in the target image") + void registerIntensityProfileRegistrationForceField(sofa::core::ObjectFactory* factory) + { + factory->registerObjects(sofa::core::ObjectRegistrationData("Compute normal forces on a point set based on the closest intensity profile in the target image") .add< IntensityProfileRegistrationForceField >(true) - .add< IntensityProfileRegistrationForceField >() - .add< IntensityProfileRegistrationForceField >() - .add< IntensityProfileRegistrationForceField >() - .add< IntensityProfileRegistrationForceField >() - .add< IntensityProfileRegistrationForceField >() - .add< IntensityProfileRegistrationForceField >() - .add< IntensityProfileRegistrationForceField >() - .add< IntensityProfileRegistrationForceField >() - .add< IntensityProfileRegistrationForceField >() - .add< IntensityProfileRegistrationForceField >() + .add< IntensityProfileRegistrationForceField >() + .add< IntensityProfileRegistrationForceField >() + .add< IntensityProfileRegistrationForceField >() + .add< IntensityProfileRegistrationForceField >() + .add< IntensityProfileRegistrationForceField >() + .add< IntensityProfileRegistrationForceField >() + .add< IntensityProfileRegistrationForceField >() + .add< IntensityProfileRegistrationForceField >() + .add< IntensityProfileRegistrationForceField >() + .add< IntensityProfileRegistrationForceField >()); + } - - ; - - template class SOFA_REGISTRATION_API IntensityProfileRegistrationForceField; + template class SOFA_REGISTRATION_API IntensityProfileRegistrationForceField; template class SOFA_REGISTRATION_API IntensityProfileRegistrationForceField; template class SOFA_REGISTRATION_API IntensityProfileRegistrationForceField; template class SOFA_REGISTRATION_API IntensityProfileRegistrationForceField; diff --git a/src/Registration/RegistrationContactForceField.cpp b/src/Registration/RegistrationContactForceField.cpp index 079d9e7..a6bb239 100644 --- a/src/Registration/RegistrationContactForceField.cpp +++ b/src/Registration/RegistrationContactForceField.cpp @@ -39,10 +39,12 @@ using namespace sofa::defaulttype; // Register in the Factory -int RegistrationContactForceFieldClass = core::RegisterObject("Contact using attractive springs") -.add< RegistrationContactForceField >() +void registerRegistrationContactForceField(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(sofa::core::ObjectRegistrationData("Contact using attractive springs") + .add< RegistrationContactForceField >()); +} -; template class SOFA_REGISTRATION_API RegistrationContactForceField; diff --git a/src/Registration/RegistrationExporter.cpp b/src/Registration/RegistrationExporter.cpp index 7ecb4d8..8e70cab 100644 --- a/src/Registration/RegistrationExporter.cpp +++ b/src/Registration/RegistrationExporter.cpp @@ -43,8 +43,11 @@ namespace component namespace misc { -int RegistrationExporterClass = core::RegisterObject("Replicate loaded obj files into path, with current positions") -.add< RegistrationExporter >(); +void registerRegistrationExporter(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(sofa::core::ObjectRegistrationData("Replicate loaded obj files into path, with current positions") + .add< RegistrationExporter >()); +} RegistrationExporter::RegistrationExporter() : stepCounter(0) diff --git a/src/Registration/config.h.in b/src/Registration/config.h.in index 2ad825b..f03db9b 100644 --- a/src/Registration/config.h.in +++ b/src/Registration/config.h.in @@ -19,8 +19,7 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#ifndef REGISTRATION_CONFIG_H -#define REGISTRATION_CONFIG_H +#pragma once #include @@ -39,4 +38,8 @@ # define SOFA_REGISTRATION_API SOFA_IMPORT_DYNAMIC_LIBRARY #endif -#endif +namespace registration +{ + constexpr const char* MODULE_NAME = "@PROJECT_NAME@"; + constexpr const char* MODULE_VERSION = "@PROJECT_VERSION@"; +} // namespace registration diff --git a/src/Registration/initRegistration.cpp b/src/Registration/initRegistration.cpp index 799896a..79d3f9b 100644 --- a/src/Registration/initRegistration.cpp +++ b/src/Registration/initRegistration.cpp @@ -21,12 +21,31 @@ ******************************************************************************/ #include -namespace sofa +namespace sofa::component { - -namespace component + extern void registerInertiaAlign(sofa::core::ObjectFactory* factory); +} +namespace sofa::component::engine +{ + extern void registerGroupwiseRegistrationEngine(sofa::core::ObjectFactory* factory); + extern void registerIntensityProfileCreator(sofa::core::ObjectFactory* factory); +} +namespace sofa::component::forcefield +{ + extern void registerIntensityProfileRegistrationForceField(sofa::core::ObjectFactory* factory); + extern void registerClosestPointRegistrationForceField(sofa::core::ObjectFactory* factory); +} +namespace sofa::component::interactionforcefield +{ + extern void registerRegistrationContactForceField(sofa::core::ObjectFactory* factory); +} +namespace sofa::component::misc { + extern void registerRegistrationExporter(sofa::core::ObjectFactory* factory); +} +namespace registration +{ //Here are just several convenient functions to help user to know what contains the plugin extern "C" { @@ -35,7 +54,7 @@ namespace component SOFA_REGISTRATION_API const char* getModuleVersion(); SOFA_REGISTRATION_API const char* getModuleLicense(); SOFA_REGISTRATION_API const char* getModuleDescription(); - SOFA_REGISTRATION_API const char* getModuleComponentList(); + SOFA_REGISTRATION_API void registerObjects(sofa::core::ObjectFactory* factory); } void initExternalModule() @@ -43,18 +62,21 @@ namespace component 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 "Registration"; + return MODULE_NAME; } const char* getModuleVersion() { - return "0.1"; + return MODULE_VERSION; } const char* getModuleLicense() @@ -68,12 +90,15 @@ namespace component return "Model/image registration force fields"; } - const char* getModuleComponentList() + void registerObjects(sofa::core::ObjectFactory* factory) { - return "ImageRegistrationLoader, IntensityProfileRegistrationForceField, RegistrationContact, RegistrationContactForceField, ClosestPointRegistrationForceField, RegistrationExporter"; + sofa::component::registerInertiaAlign(factory); + sofa::component::engine::registerGroupwiseRegistrationEngine( factory); + sofa::component::engine::registerIntensityProfileCreator(factory); + sofa::component::forcefield::registerIntensityProfileRegistrationForceField(factory); + sofa::component::forcefield::registerClosestPointRegistrationForceField(factory); + sofa::component::interactionforcefield::registerRegistrationContactForceField(factory); + sofa::component::misc::registerRegistrationExporter(factory); } -} // namespace registration - -} // namespace sofa - +} // namespace registration \ No newline at end of file From 6c2e8cdbe98221bec4ac423ed78dd6008751426c Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Mon, 3 Nov 2025 20:21:09 +0100 Subject: [PATCH 2/2] fix compilation with CMake var REGISTRATION_USES_IMAGE --- src/Registration/RegistrationExporter.cpp | 3 ++- src/Registration/config.h.in | 1 + src/Registration/initRegistration.cpp | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Registration/RegistrationExporter.cpp b/src/Registration/RegistrationExporter.cpp index 8e70cab..2952ea7 100644 --- a/src/Registration/RegistrationExporter.cpp +++ b/src/Registration/RegistrationExporter.cpp @@ -18,7 +18,8 @@ * Authors: The SOFA Team and external contributors (see Authors.txt) * * * * Contact information: contact@sofa-framework.org * -******************************************************************************/#include "RegistrationExporter.h" +******************************************************************************/ +#include "RegistrationExporter.h" #include #include diff --git a/src/Registration/config.h.in b/src/Registration/config.h.in index f03db9b..a46ee15 100644 --- a/src/Registration/config.h.in +++ b/src/Registration/config.h.in @@ -30,6 +30,7 @@ #cmakedefine01 REGISTRATION_HAVE_SOFA_GL #cmakedefine01 REGISTRATION_HAVE_IMAGE +#cmakedefine REGISTRATION_USES_IMAGE #ifdef SOFA_BUILD_REGISTRATION # define SOFA_TARGET Registration diff --git a/src/Registration/initRegistration.cpp b/src/Registration/initRegistration.cpp index 79d3f9b..02bbf58 100644 --- a/src/Registration/initRegistration.cpp +++ b/src/Registration/initRegistration.cpp @@ -20,6 +20,8 @@ * Contact information: contact@sofa-framework.org * ******************************************************************************/ #include +#include +#include namespace sofa::component { @@ -28,11 +30,15 @@ namespace sofa::component namespace sofa::component::engine { extern void registerGroupwiseRegistrationEngine(sofa::core::ObjectFactory* factory); +#ifdef REGISTRATION_USES_IMAGE extern void registerIntensityProfileCreator(sofa::core::ObjectFactory* factory); +#endif } namespace sofa::component::forcefield { +#ifdef REGISTRATION_USES_IMAGE extern void registerIntensityProfileRegistrationForceField(sofa::core::ObjectFactory* factory); +#endif extern void registerClosestPointRegistrationForceField(sofa::core::ObjectFactory* factory); } namespace sofa::component::interactionforcefield @@ -94,8 +100,10 @@ namespace registration { sofa::component::registerInertiaAlign(factory); sofa::component::engine::registerGroupwiseRegistrationEngine( factory); +#ifdef REGISTRATION_USES_IMAGE sofa::component::engine::registerIntensityProfileCreator(factory); sofa::component::forcefield::registerIntensityProfileRegistrationForceField(factory); +#endif sofa::component::forcefield::registerClosestPointRegistrationForceField(factory); sofa::component::interactionforcefield::registerRegistrationContactForceField(factory); sofa::component::misc::registerRegistrationExporter(factory);