Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mass] Apply new factory registration mechanism #5055

Merged
merged 6 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ void DisplacementTransformEngine<Rigid3Types,Mat4x4>::mult( Mat4x4& out, const M
out = out * inv;
}

/////////////////////////////////////////

int DisplacementMatrixEngineClass = core::RegisterObject("Converts a vector of Rigid to a vector of displacement matrices.")
.add< DisplacementMatrixEngine<Rigid3Types> >()
;
void registerDisplacementMatrixEngine(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Converts a vector of Rigid to a vector of displacement matrices.")
.add< DisplacementMatrixEngine<Rigid3Types> >());
}

template class SOFA_COMPONENT_ENGINE_TRANSFORM_API DisplacementMatrixEngine<Rigid3Types>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace sofa::component::engine::transform

extern void registerDifferenceEngine(sofa::core::ObjectFactory* factory);
extern void registerDilateEngine(sofa::core::ObjectFactory* factory);
extern void registerDisplacementMatrixEngine(sofa::core::ObjectFactory* factory);
extern void registerDisplacementTransformEngine(sofa::core::ObjectFactory* factory);
extern void registerIndexValueMapper(sofa::core::ObjectFactory* factory);
extern void registerIndices2ValuesMapper(sofa::core::ObjectFactory* factory);
Expand Down Expand Up @@ -73,6 +74,7 @@ void registerObjects(sofa::core::ObjectFactory* factory)
{
registerDifferenceEngine(factory);
registerDilateEngine(factory);
registerDisplacementMatrixEngine(factory);
registerDisplacementTransformEngine(factory);
registerIndexValueMapper(factory);
registerIndices2ValuesMapper(factory);
Expand Down
10 changes: 5 additions & 5 deletions Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,18 +332,18 @@ type::Vec6 DiagonalMass<Rigid3Types>::getMomentum ( const MechanicalParams* mpar
return getMomentumRigid3Impl<Rigid3Types>(mparams, vx, vv) ;
}

// Register in the Factory
int DiagonalMassClass = core::RegisterObject("Define a specific mass for each particle")
void registerDiagonalMass(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Compute a lumped (diagonalized) mass matrix resulting from the space integration of a density over a domain.")
.add< DiagonalMass<Vec3Types> >()
.add< DiagonalMass<Vec2Types, Vec3Types> >()
.add< DiagonalMass<Vec1Types> >()
.add< DiagonalMass<Vec1Types, Vec2Types> >()
.add< DiagonalMass<Vec1Types, Vec3Types> >()
.add< DiagonalMass<Rigid3Types> >()
.add< DiagonalMass<Rigid2Types> >()
.add< DiagonalMass<Rigid2Types, Rigid3Types> >()

;
.add< DiagonalMass<Rigid2Types, Rigid3Types> >());
}

template class SOFA_COMPONENT_MASS_API DiagonalMass<Vec3Types>;
template class SOFA_COMPONENT_MASS_API DiagonalMass<Vec2Types>;
Expand Down
10 changes: 5 additions & 5 deletions Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ Vec6 MeshMatrixMass<Vec3Types>::getMomentum ( const core::MechanicalParams*, con
return momentum;
}


// Register in the Factory
int MeshMatrixMassClass = core::RegisterObject("Define a specific mass for each particle")
void registerMeshMatrixMass(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Compute a mass matrix resulting from the space integration of a density over a domain.")
.add< MeshMatrixMass<Vec3Types> >()
.add< MeshMatrixMass<Vec2Types> >()
.add< MeshMatrixMass<Vec2Types, Vec3Types> >()
.add< MeshMatrixMass<Vec1Types> >()
.add< MeshMatrixMass<Vec1Types, Vec2Types> >()
.add< MeshMatrixMass<Vec1Types, Vec3Types> >()
;
.add< MeshMatrixMass<Vec1Types, Vec3Types> >());
}

template class SOFA_COMPONENT_MASS_API MeshMatrixMass<defaulttype::Vec3Types>;
template class SOFA_COMPONENT_MASS_API MeshMatrixMass<defaulttype::Vec2Types>;
Expand Down
24 changes: 5 additions & 19 deletions Sofa/Component/Mass/src/sofa/component/mass/UniformMass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,30 +503,16 @@ Vec6 UniformMass<Rigid3Types>::getMomentum ( const MechanicalParams* params,
return getMomentumRigid3DImpl<Rigid3Types>(params, d_x, d_v);
}




//////////////////////////////////////////// REGISTERING TO FACTORY /////////////////////////////////////////
/// Registering the component
/// see: https://www.sofa-framework.org/community/doc/programming-with-sofa/components-api/the-objectfactory/
/// 1-SOFA_DECL_CLASS(componentName) : Set the class name of the component
/// 2-RegisterObject("description") + .add<> : Register the component
/// 3-.add<>(true) : Set default template
// Register in the Factory
int UniformMassClass = core::RegisterObject("Define the same mass for all the particles")

void registerUniformMass(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Compute a mass equally spread over the number of nodes.")
.add< UniformMass<Vec3Types> >()
.add< UniformMass<Vec2Types> >()
.add< UniformMass<Vec1Types> >()
.add< UniformMass<Vec6Types> >()
.add< UniformMass<Rigid3Types> >()
.add< UniformMass<Rigid2Types> >()

;
////////////////////////////////////////////////////////////////////////////////////////////////////////



.add< UniformMass<Rigid2Types> >());
}

////////////////////////////// TEMPLATE INITIALIZATION /////////////////////////////////////////////////
/// Force template specialization for the most common sofa type.
Expand Down
19 changes: 18 additions & 1 deletion Sofa/Component/Mass/src/sofa/component/mass/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@
******************************************************************************/
#include <sofa/component/mass/init.h>
#include <sofa/core/ObjectFactory.h>
#include <sofa/helper/system/PluginManager.h>

namespace sofa::component::mass
{


extern void registerDiagonalMass(sofa::core::ObjectFactory* factory);
extern void registerMeshMatrixMass(sofa::core::ObjectFactory* factory);
extern void registerUniformMass(sofa::core::ObjectFactory* factory);

extern "C" {
SOFA_EXPORT_DYNAMIC_LIBRARY void initExternalModule();
SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleName();
SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleVersion();
SOFA_EXPORT_DYNAMIC_LIBRARY void registerObjects(sofa::core::ObjectFactory* factory);
}

void initExternalModule()
Expand All @@ -45,11 +52,21 @@ const char* getModuleVersion()
return MODULE_VERSION;
}

void registerObjects(sofa::core::ObjectFactory* factory)
{
registerDiagonalMass(factory);
registerMeshMatrixMass(factory);
registerUniformMass(factory);
}

void init()
{
static bool first = true;
if (first)
{
// make sure that this plugin is registered into the PluginManager
sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME);

first = false;
}
}
Expand Down
1 change: 1 addition & 0 deletions Sofa/Component/Mass/tests/DiagonalMass_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class DiagonalMass_test : public BaseTest
sofa::simpleapi::importPlugin("Sofa.Component.Topology.Container.Dynamic");
sofa::simpleapi::importPlugin("Sofa.Component.Topology.Container.Grid");
sofa::simpleapi::importPlugin("Sofa.Component.StateContainer");
sofa::simpleapi::importPlugin("Sofa.Component.Mass");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to the PR: I find it confusing that simpleapi::importPlugin does something more than pluginManager.loadPlugin, and it is not obvious which one should be preferred.


simulation = simulation::getSimulation();
root = simulation::getSimulation()->createNewGraph("root");
Expand Down
1 change: 1 addition & 0 deletions Sofa/Component/Mass/tests/MeshMatrixMass_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class MeshMatrixMass_test : public BaseTest
sofa::simpleapi::importPlugin("Sofa.Component.Topology.Container.Dynamic");
sofa::simpleapi::importPlugin("Sofa.Component.Topology.Container.Grid");
sofa::simpleapi::importPlugin("Sofa.Component.StateContainer");
sofa::simpleapi::importPlugin("Sofa.Component.Mass");

simulation = simulation::getSimulation();
root = simulation::getSimulation()->createNewGraph("root");
Expand Down
3 changes: 3 additions & 0 deletions Sofa/Component/Mass/tests/UniformMass_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ struct UniformMassTest : public BaseTest

void SetUp() override
{
sofa::simpleapi::importPlugin("Sofa.Component.StateContainer");
sofa::simpleapi::importPlugin("Sofa.Component.Mass");

todo = true ;
m_simu = sofa::simulation::getSimulation();
m_root = m_simu->createNewGraph("root");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ struct ConstantForceField_test : public BaseSimulationTest, NumericTest<typename
sofa::simpleapi::importPlugin("Sofa.Component.StateContainer");
sofa::simpleapi::importPlugin("Sofa.Component.MechanicalLoad");
sofa::simpleapi::importPlugin("Sofa.Component.LinearSolver.Iterative");
sofa::simpleapi::importPlugin("Sofa.Component.Mass");
}

void TearDown() override {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
******************************************************************************/
#include <sofa/component/sceneutility/config.h>
#include <sofa/core/ObjectFactory.h>
using sofa::core::RegisterObject ;

#include <sofa/component/sceneutility/InfoComponent.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
******************************************************************************/
#include <sofa/component/sceneutility/config.h>
#include <sofa/core/ObjectFactory.h>
using sofa::core::RegisterObject ;
using sofa::core::ObjectFactory ;

using sofa::core::objectmodel::ComponentState ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
******************************************************************************/
#include <sofa/component/sceneutility/config.h>
#include <sofa/core/ObjectFactory.h>
using sofa::core::RegisterObject ;
using sofa::core::ObjectFactory ;

using sofa::core::objectmodel::ComponentState ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
******************************************************************************/
#include <sofa/component/sceneutility/config.h>
#include <sofa/core/ObjectFactory.h>
using sofa::core::RegisterObject ;

#include <sofa/helper/logging/ConsoleMessageHandler.h>
using sofa::helper::logging::ConsoleMessageHandler ;
Expand Down Expand Up @@ -155,8 +154,10 @@ void FileMessageHandlerComponent::parse ( core::objectmodel::BaseObjectDescripti
m_isValid = true ;
}

int FileMessageHandlerComponentClass = RegisterObject("This component dump all the messages into"
"a file.")
.add< FileMessageHandlerComponent >()
;
void registerFileMessageHandlerComponent(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("This component dumps all the messages into a file.")
.add< FileMessageHandlerComponent >());
}

} // namespace sofa::component::sceneutility
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ namespace sofa::component::sceneutility
extern void registerAddDataRepository(sofa::core::ObjectFactory* factory);
extern void registerAddPluginRepository(sofa::core::ObjectFactory* factory);
extern void registerAPIVersion(sofa::core::ObjectFactory* factory);
extern void registerInfoComponent(sofa::core::ObjectFactory* factory);;
extern void registerFileMessageHandlerComponent(sofa::core::ObjectFactory* factory);
extern void registerInfoComponent(sofa::core::ObjectFactory* factory);
extern void registerMakeAliasComponent(sofa::core::ObjectFactory* factory);
extern void registerMakeDataAliasComponent(sofa::core::ObjectFactory* factory);
extern void registerMessageHandlerComponent(sofa::core::ObjectFactory* factory);
Expand Down Expand Up @@ -62,6 +63,7 @@ void registerObjects(sofa::core::ObjectFactory* factory)
registerAddDataRepository(factory);
registerAddPluginRepository(factory);
registerAPIVersion(factory);
registerFileMessageHandlerComponent(factory);
registerInfoComponent(factory);;
registerMakeAliasComponent(factory);
registerMakeDataAliasComponent(factory);
Expand Down
1 change: 1 addition & 0 deletions Sofa/Component/src/sofa/component/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ void registerObjects(sofa::core::ObjectFactory* factory)
factory->registerObjectsFromPlugin("Sofa.Component.LinearSolver");
factory->registerObjectsFromPlugin("Sofa.Component.LinearSystem");
factory->registerObjectsFromPlugin("Sofa.Component.Mapping");
factory->registerObjectsFromPlugin("Sofa.Component.Mass");
factory->registerObjectsFromPlugin("Sofa.Component.MechanicalLoad");
factory->registerObjectsFromPlugin("Sofa.Component.ODESolver");
factory->registerObjectsFromPlugin("Sofa.Component.Playback");
Expand Down
Loading