Skip to content

Commit 967d9a0

Browse files
authored
Merge pull request #29 from hugtalbot/202511_new_registration_mechanism
Apply new factory registration mechanism
2 parents f9802b4 + 6c2e8cd commit 967d9a0

9 files changed

Lines changed: 102 additions & 54 deletions

src/Registration/ClosestPointRegistrationForceField.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,15 @@ namespace forcefield
3434
{
3535

3636
using namespace sofa::defaulttype;
37-
38-
// Register in the Factory
39-
int ClosestPointRegistrationForceFieldClass = core::RegisterObject("Compute forces based on closest points from/to a target surface/point set")
40-
.add< ClosestPointRegistrationForceField<Vec3Types> >()
4137

42-
;
43-
44-
template class SOFA_REGISTRATION_API ClosestPointRegistrationForceField<Vec3Types>;
38+
// Register in the Factory
39+
void registerClosestPointRegistrationForceField(sofa::core::ObjectFactory* factory)
40+
{
41+
factory->registerObjects(sofa::core::ObjectRegistrationData("Compute forces based on closest points from/to a target surface/point set")
42+
.add< ClosestPointRegistrationForceField<Vec3Types> >());
43+
}
4544

46-
47-
45+
template class SOFA_REGISTRATION_API ClosestPointRegistrationForceField<Vec3Types>;
4846

4947
}
5048
}

src/Registration/GroupwiseRegistrationEngine.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@ namespace engine
3434

3535
using namespace defaulttype;
3636

37-
int GroupwiseRegistrationEngineClass = core::RegisterObject("Register a set of meshes of similar topology")
38-
.add<GroupwiseRegistrationEngine< Vec3Types > >(true)
3937

40-
;
38+
void registerGroupwiseRegistrationEngine(sofa::core::ObjectFactory* factory)
39+
{
40+
factory->registerObjects(sofa::core::ObjectRegistrationData("Register a set of meshes of similar topology")
41+
.add< GroupwiseRegistrationEngine< Vec3Types > >(true));
42+
}
43+
4144
template class SOFA_REGISTRATION_API GroupwiseRegistrationEngine< Vec3Types >;
4245

4346

src/Registration/InertiaAlign.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ namespace component
3838
using namespace sofa::type;
3939
using namespace sofa::defaulttype;
4040

41-
int InertiaAlignClass = core::RegisterObject("An engine computing inertia matrix and the principal direction of a mesh.")
42-
.add< InertiaAlign >()
43-
;
41+
void registerInertiaAlign(sofa::core::ObjectFactory* factory)
42+
{
43+
factory->registerObjects(sofa::core::ObjectRegistrationData("An engine computing inertia matrix and the principal direction of a mesh")
44+
.add< InertiaAlign >());
45+
}
4446

4547

4648
InertiaAlign::InertiaAlign()

src/Registration/IntensityProfileCreator.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ namespace engine
3535

3636
using namespace defaulttype;
3737

38-
int IntensityProfileCreatorClass = core::RegisterObject("Create reference intensity profiles from custom values")
38+
void registerIntensityProfileCreator(sofa::core::ObjectFactory* factory)
39+
{
40+
factory->registerObjects(sofa::core::ObjectRegistrationData("Create reference intensity profiles from custom values")
3941
.add<IntensityProfileCreator<ImageUC> >(true)
4042
.add<IntensityProfileCreator<ImageUS> >()
4143
.add<IntensityProfileCreator<ImageS> >()
4244
.add<IntensityProfileCreator<ImageD> >()
43-
.add<IntensityProfileCreator<ImageB> >()
44-
;
45+
.add<IntensityProfileCreator<ImageB> >());
46+
}
4547

4648
template class SOFA_REGISTRATION_API IntensityProfileCreator<ImageUC>;
4749
template class SOFA_REGISTRATION_API IntensityProfileCreator<ImageUS>;

src/Registration/IntensityProfileRegistrationForceField.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,23 @@ namespace forcefield
3636
using namespace defaulttype;
3737

3838
// Register in the Factory
39-
int IntensityProfileRegistrationForceFieldClass = core::RegisterObject("Compute normal forces on a point set based on the closest intensity profile in the target image")
39+
void registerIntensityProfileRegistrationForceField(sofa::core::ObjectFactory* factory)
40+
{
41+
factory->registerObjects(sofa::core::ObjectRegistrationData("Compute normal forces on a point set based on the closest intensity profile in the target image")
4042
.add< IntensityProfileRegistrationForceField<Vec3Types,ImageUC> >(true)
41-
.add< IntensityProfileRegistrationForceField<Vec3Types,ImageUS> >()
42-
.add< IntensityProfileRegistrationForceField<Vec3Types,ImageD> >()
43-
.add< IntensityProfileRegistrationForceField<Vec3Types,ImageC> >()
44-
.add< IntensityProfileRegistrationForceField<Vec3Types,ImageI> >()
45-
.add< IntensityProfileRegistrationForceField<Vec3Types,ImageUI> >()
46-
.add< IntensityProfileRegistrationForceField<Vec3Types,ImageS> >()
47-
.add< IntensityProfileRegistrationForceField<Vec3Types,ImageL> >()
48-
.add< IntensityProfileRegistrationForceField<Vec3Types,ImageUL> >()
49-
.add< IntensityProfileRegistrationForceField<Vec3Types,ImageF> >()
50-
.add< IntensityProfileRegistrationForceField<Vec3Types,ImageB> >()
43+
.add< IntensityProfileRegistrationForceField<Vec3Types,ImageUS> >()
44+
.add< IntensityProfileRegistrationForceField<Vec3Types,ImageD> >()
45+
.add< IntensityProfileRegistrationForceField<Vec3Types,ImageC> >()
46+
.add< IntensityProfileRegistrationForceField<Vec3Types,ImageI> >()
47+
.add< IntensityProfileRegistrationForceField<Vec3Types,ImageUI> >()
48+
.add< IntensityProfileRegistrationForceField<Vec3Types,ImageS> >()
49+
.add< IntensityProfileRegistrationForceField<Vec3Types,ImageL> >()
50+
.add< IntensityProfileRegistrationForceField<Vec3Types,ImageUL> >()
51+
.add< IntensityProfileRegistrationForceField<Vec3Types,ImageF> >()
52+
.add< IntensityProfileRegistrationForceField<Vec3Types,ImageB> >());
53+
}
5154

52-
53-
;
54-
55-
template class SOFA_REGISTRATION_API IntensityProfileRegistrationForceField<Vec3Types,ImageUC>;
55+
template class SOFA_REGISTRATION_API IntensityProfileRegistrationForceField<Vec3Types,ImageUC>;
5656
template class SOFA_REGISTRATION_API IntensityProfileRegistrationForceField<Vec3Types,ImageUS>;
5757
template class SOFA_REGISTRATION_API IntensityProfileRegistrationForceField<Vec3Types,ImageD>;
5858
template class SOFA_REGISTRATION_API IntensityProfileRegistrationForceField<Vec3Types,ImageC>;

src/Registration/RegistrationContactForceField.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ using namespace sofa::defaulttype;
3939

4040

4141
// Register in the Factory
42-
int RegistrationContactForceFieldClass = core::RegisterObject("Contact using attractive springs")
43-
.add< RegistrationContactForceField<Vec3Types> >()
42+
void registerRegistrationContactForceField(sofa::core::ObjectFactory* factory)
43+
{
44+
factory->registerObjects(sofa::core::ObjectRegistrationData("Contact using attractive springs")
45+
.add< RegistrationContactForceField<Vec3Types> >());
46+
}
4447

45-
;
4648

4749
template class SOFA_REGISTRATION_API RegistrationContactForceField<Vec3Types>;
4850

src/Registration/RegistrationExporter.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
* Authors: The SOFA Team and external contributors (see Authors.txt) *
1919
* *
2020
* Contact information: contact@sofa-framework.org *
21-
******************************************************************************/#include "RegistrationExporter.h"
21+
******************************************************************************/
22+
#include "RegistrationExporter.h"
2223

2324
#include <sstream>
2425
#include <iomanip>
@@ -43,8 +44,11 @@ namespace component
4344
namespace misc
4445
{
4546

46-
int RegistrationExporterClass = core::RegisterObject("Replicate loaded obj files into path, with current positions")
47-
.add< RegistrationExporter >();
47+
void registerRegistrationExporter(sofa::core::ObjectFactory* factory)
48+
{
49+
factory->registerObjects(sofa::core::ObjectRegistrationData("Replicate loaded obj files into path, with current positions")
50+
.add< RegistrationExporter >());
51+
}
4852

4953
RegistrationExporter::RegistrationExporter()
5054
: stepCounter(0)

src/Registration/config.h.in

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
* *
2020
* Contact information: contact@sofa-framework.org *
2121
******************************************************************************/
22-
#ifndef REGISTRATION_CONFIG_H
23-
#define REGISTRATION_CONFIG_H
22+
#pragma once
2423

2524
#include <sofa/config.h>
2625

@@ -31,6 +30,7 @@
3130
#cmakedefine01 REGISTRATION_HAVE_SOFA_GL
3231

3332
#cmakedefine01 REGISTRATION_HAVE_IMAGE
33+
#cmakedefine REGISTRATION_USES_IMAGE
3434

3535
#ifdef SOFA_BUILD_REGISTRATION
3636
# define SOFA_TARGET Registration
@@ -39,4 +39,8 @@
3939
# define SOFA_REGISTRATION_API SOFA_IMPORT_DYNAMIC_LIBRARY
4040
#endif
4141

42-
#endif
42+
namespace registration
43+
{
44+
constexpr const char* MODULE_NAME = "@PROJECT_NAME@";
45+
constexpr const char* MODULE_VERSION = "@PROJECT_VERSION@";
46+
} // namespace registration

src/Registration/initRegistration.cpp

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,38 @@
2020
* Contact information: contact@sofa-framework.org *
2121
******************************************************************************/
2222
#include <Registration/config.h>
23+
#include <sofa/core/ObjectFactory.h>
24+
#include <sofa/helper/system/PluginManager.h>
2325

24-
namespace sofa
26+
namespace sofa::component
2527
{
26-
27-
namespace component
28+
extern void registerInertiaAlign(sofa::core::ObjectFactory* factory);
29+
}
30+
namespace sofa::component::engine
31+
{
32+
extern void registerGroupwiseRegistrationEngine(sofa::core::ObjectFactory* factory);
33+
#ifdef REGISTRATION_USES_IMAGE
34+
extern void registerIntensityProfileCreator(sofa::core::ObjectFactory* factory);
35+
#endif
36+
}
37+
namespace sofa::component::forcefield
38+
{
39+
#ifdef REGISTRATION_USES_IMAGE
40+
extern void registerIntensityProfileRegistrationForceField(sofa::core::ObjectFactory* factory);
41+
#endif
42+
extern void registerClosestPointRegistrationForceField(sofa::core::ObjectFactory* factory);
43+
}
44+
namespace sofa::component::interactionforcefield
45+
{
46+
extern void registerRegistrationContactForceField(sofa::core::ObjectFactory* factory);
47+
}
48+
namespace sofa::component::misc
2849
{
50+
extern void registerRegistrationExporter(sofa::core::ObjectFactory* factory);
51+
}
2952

53+
namespace registration
54+
{
3055
//Here are just several convenient functions to help user to know what contains the plugin
3156

3257
extern "C" {
@@ -35,26 +60,29 @@ namespace component
3560
SOFA_REGISTRATION_API const char* getModuleVersion();
3661
SOFA_REGISTRATION_API const char* getModuleLicense();
3762
SOFA_REGISTRATION_API const char* getModuleDescription();
38-
SOFA_REGISTRATION_API const char* getModuleComponentList();
63+
SOFA_REGISTRATION_API void registerObjects(sofa::core::ObjectFactory* factory);
3964
}
4065

4166
void initExternalModule()
4267
{
4368
static bool first = true;
4469
if (first)
4570
{
71+
// make sure that this plugin is registered into the PluginManager
72+
sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME);
73+
4674
first = false;
4775
}
4876
}
4977

5078
const char* getModuleName()
5179
{
52-
return "Registration";
80+
return MODULE_NAME;
5381
}
5482

5583
const char* getModuleVersion()
5684
{
57-
return "0.1";
85+
return MODULE_VERSION;
5886
}
5987

6088
const char* getModuleLicense()
@@ -68,12 +96,17 @@ namespace component
6896
return "Model/image registration force fields";
6997
}
7098

71-
const char* getModuleComponentList()
99+
void registerObjects(sofa::core::ObjectFactory* factory)
72100
{
73-
return "ImageRegistrationLoader, IntensityProfileRegistrationForceField, RegistrationContact, RegistrationContactForceField, ClosestPointRegistrationForceField, RegistrationExporter";
101+
sofa::component::registerInertiaAlign(factory);
102+
sofa::component::engine::registerGroupwiseRegistrationEngine( factory);
103+
#ifdef REGISTRATION_USES_IMAGE
104+
sofa::component::engine::registerIntensityProfileCreator(factory);
105+
sofa::component::forcefield::registerIntensityProfileRegistrationForceField(factory);
106+
#endif
107+
sofa::component::forcefield::registerClosestPointRegistrationForceField(factory);
108+
sofa::component::interactionforcefield::registerRegistrationContactForceField(factory);
109+
sofa::component::misc::registerRegistrationExporter(factory);
74110
}
75111

76-
} // namespace registration
77-
78-
} // namespace sofa
79-
112+
} // namespace registration

0 commit comments

Comments
 (0)