Skip to content

Commit

Permalink
[Topology] Apply new factory registration mechanism (#5012)
Browse files Browse the repository at this point in the history
* apply new register mechanism to topology

* remove aliases in scene

* change test with VisualModel

* remove aliases from unittest

* Apply suggestions from code review (updates on component description)

Co-authored-by: Hugo <[email protected]>

---------

Co-authored-by: Hugo <[email protected]>
  • Loading branch information
fredroy and hugtalbot authored Oct 4, 2024
1 parent 9152342 commit 38ecbea
Show file tree
Hide file tree
Showing 57 changed files with 445 additions and 259 deletions.
6 changes: 3 additions & 3 deletions Sofa/Component/Engine/Select/tests/MeshROI_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct MeshROI_test : public BaseSimulationTest,
"<Node name='Root' gravity='0 0 0' time='0' animate='0' > "
" <Node name='node'> "
" <MeshOBJLoader name='loader' filename='mesh/cube.obj'/> "
" <Mesh name='topology' src='@loader'/> "
" <MeshTopology name='topology' src='@loader'/> "
" <MeshROI template='Vec3d' name='MeshROI'/> "
" </Node> "
"</Node> " ;
Expand Down Expand Up @@ -136,7 +136,7 @@ struct MeshROI_test : public BaseSimulationTest,
"<Node name='Root' gravity='0 0 0' time='0' animate='0' > "
" <Node name='node'> "
" <MeshOBJLoader name='loader' filename='mesh/dragon.obj'/> "
" <Mesh name='topology' src='@loader'/> "
" <MeshTopology name='topology' src='@loader'/> "
" <MeshROI template='Vec3d' name='MeshROI'/> "
" </Node> "
"</Node> " ;
Expand All @@ -157,7 +157,7 @@ struct MeshROI_test : public BaseSimulationTest,
<Node name='Root' gravity='0 0 0' time='0' animate='0' >
<Node name='node'>
<MeshOBJLoader name='loader' filename='mesh/cube.obj'/>
<Mesh name='topology' src='@loader'/>
<MeshTopology name='topology' src='@loader'/>
<MeshROI template='Vec3d' name='MeshROI' position='0. 0. 0. 2. 0. 0.' />
</Node>
</Node>
Expand Down
8 changes: 4 additions & 4 deletions Sofa/Component/Mass/tests/DiagonalMass_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class DiagonalMass_test : public BaseTest
"<?xml version='1.0'?>"
"<Node name='Root' gravity='0 0 0' time='0' animate='0' > "
" <MechanicalObject /> "
" <RegularGrid nx='2' ny='2' nz='2' xmin='0' xmax='2' ymin='0' ymax='2' zmin='0' zmax='2' /> "
" <RegularGridTopology nx='2' ny='2' nz='2' xmin='0' xmax='2' ymin='0' ymax='2' zmin='0' zmax='2' /> "
" <HexahedronSetGeometryAlgorithms /> "
" <DiagonalMass name='m_mass'/> "
"</Node> " ;
Expand Down Expand Up @@ -188,7 +188,7 @@ class DiagonalMass_test : public BaseTest
"<?xml version='1.0'?> "
"<Node name='Root' gravity='0 0 0' time='0' animate='0' > "
" <MechanicalObject /> "
" <RegularGrid nx='2' ny='2' nz='2' xmin='0' xmax='2' ymin='0' ymax='2' zmin='0' zmax='2' /> "
" <RegularGridTopology nx='2' ny='2' nz='2' xmin='0' xmax='2' ymin='0' ymax='2' zmin='0' zmax='2' /> "
" <HexahedronSetGeometryAlgorithms /> "
" <DiagonalMass name='m_mass' massDensity='1.0' /> "
"</Node> " ;
Expand Down Expand Up @@ -219,7 +219,7 @@ class DiagonalMass_test : public BaseTest
"<?xml version='1.0'?> "
"<Node name='Root' gravity='0 0 0' time='0' animate='0' > "
" <MechanicalObject /> "
" <RegularGrid nx='2' ny='2' nz='2' xmin='0' xmax='2' ymin='0' ymax='2' zmin='0' zmax='2' /> "
" <RegularGridTopology nx='2' ny='2' nz='2' xmin='0' xmax='2' ymin='0' ymax='2' zmin='0' zmax='2' /> "
" <HexahedronSetGeometryAlgorithms/> "
" <DiagonalMass name='m_mass' totalMass='10'/> "
"</Node> " ;
Expand Down Expand Up @@ -249,7 +249,7 @@ class DiagonalMass_test : public BaseTest
"<?xml version='1.0'?> "
"<Node name='Root' gravity='0 0 0' time='0' animate='0' > "
" <MechanicalObject /> "
" <RegularGrid nx='2' ny='2' nz='2' xmin='0' xmax='2' ymin='0' ymax='2' zmin='0' zmax='2' /> "
" <RegularGridTopology nx='2' ny='2' nz='2' xmin='0' xmax='2' ymin='0' ymax='2' zmin='0' zmax='2' /> "
" <HexahedronSetGeometryAlgorithms /> "
" <DiagonalMass name='m_mass' massDensity='1.0' totalMass='10'/> "
"</Node> " ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ void CubeTopology::parse(core::objectmodel::BaseObjectDescription* arg)
this->setPos(d_min.getValue()[0], d_max.getValue()[0], d_min.getValue()[1], d_max.getValue()[1], d_min.getValue()[2], d_max.getValue()[2]);
}

int CubeTopologyClass = core::RegisterObject("Surface of a cube in 3D")
.add< CubeTopology >()
;
void registerCubeTopology(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Surface topology of a cube in 3D (points, edges and quads).")
.add< CubeTopology >());
}

CubeTopology::CubeTopology(int _nx, int _ny, int _nz)
: d_nx(initData(&d_nx, _nx, "nx", "x grid resolution"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,11 @@ void MeshTopology::QuadUpdate::doUpdate()
using namespace sofa::defaulttype;
using core::topology::BaseMeshTopology;


int MeshTopologyClass = core::RegisterObject("Generic mesh topology")
.addAlias("Mesh")
.add< MeshTopology >()
;
void registerMeshTopology(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Generic constant topology loaded from a mesh file.")
.add< MeshTopology >());
}

MeshTopology::MeshTopology()
: d_seqPoints(initData(&d_seqPoints, "position", "List of point positions"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ namespace sofa::component::topology::container::constant
using namespace sofa::type;
using namespace sofa::defaulttype;

int SphereQuadTopologyClass = core::RegisterObject("Sphere topology constructed with deformed quads")
.addAlias("SphereQuad")
.add< SphereQuadTopology >()
;
void registerSphereQuadTopology(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Sphere topology constructed with deformed quads.")
.add< SphereQuadTopology >());
}

SphereQuadTopology::SphereQuadTopology(int nx, int ny, int nz)
: CubeTopology(nx, ny, nz),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@
******************************************************************************/
#include <sofa/component/topology/container/constant/init.h>
#include <sofa/core/ObjectFactory.h>
#include <sofa/helper/system/PluginManager.h>

namespace sofa::component::topology::container::constant
{


extern void registerCubeTopology(sofa::core::ObjectFactory* factory);
extern void registerMeshTopology(sofa::core::ObjectFactory* factory);
extern void registerSphereQuadTopology(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)
{
registerCubeTopology(factory);
registerMeshTopology(factory);
registerSphereQuadTopology(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
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ namespace sofa::component::topology::container::dynamic
{

using namespace sofa::defaulttype;
int DynamicSparseGridGeometryAlgorithmsClass = core::RegisterObject ( "Hexahedron set geometry algorithms" )
.add< DynamicSparseGridGeometryAlgorithms<Vec3Types> > ( true ) // default template
.add< DynamicSparseGridGeometryAlgorithms<Vec2Types> >()

;
void registerDynamicSparseGridGeometryAlgorithms(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Dynamic sparse grid geometry algorithms.")
.add< DynamicSparseGridGeometryAlgorithms<Vec3Types> >(true) // default template
.add< DynamicSparseGridGeometryAlgorithms<Vec2Types> >());
}

template <>
int DynamicSparseGridGeometryAlgorithms<Vec2Types>::findNearestElementInRestPos(const Coord& pos, sofa::type::Vec3& baryC, Real& distance) const
Expand All @@ -43,5 +45,4 @@ int DynamicSparseGridGeometryAlgorithms<Vec2Types>::findNearestElementInRestPos(
template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API DynamicSparseGridGeometryAlgorithms<Vec3Types>;
template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API DynamicSparseGridGeometryAlgorithms<Vec2Types>;


} // namespace sofa::component::topology::container::dynamic
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@
namespace sofa::component::topology::container::dynamic
{

using namespace std;
using namespace sofa::type;
using namespace sofa::defaulttype;

int DynamicSparseGridTopologyContainerClass = core::RegisterObject ( "Hexahedron set topology container" )
.add< DynamicSparseGridTopologyContainer >()
;
void registerDynamicSparseGridTopologyContainer(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Dynamic sparse grid geometry container.")
.add< DynamicSparseGridTopologyContainer >());
}

DynamicSparseGridTopologyContainer::DynamicSparseGridTopologyContainer()
: d_resolution (initData (&d_resolution, type::Vec3i (0, 0, 0 ), "resolution", "voxel grid resolution" ) )
Expand Down Expand Up @@ -78,7 +79,7 @@ void DynamicSparseGridTopologyContainer::init()

for( unsigned int i = 0; i < iirg.size(); i++)
{
idrg2tpo.insert( make_pair( iirg[i], i ));
idrg2tpo.insert( std::make_pair( iirg[i], i ));
}

// Init values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
namespace sofa::component::topology::container::dynamic
{

int DynamicSparseGridTopologyModifierClass = core::RegisterObject ( "Hexahedron set topology modifier" )
.add< DynamicSparseGridTopologyModifier >();

void registerDynamicSparseGridTopologyModifier(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Dynamic sparse grid geometry modifier.")
.add< DynamicSparseGridTopologyModifier >());
}

void DynamicSparseGridTopologyModifier::init()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,23 @@

namespace sofa::component::topology::container::dynamic
{

using namespace sofa::defaulttype;
int EdgeSetGeometryAlgorithmsClass = core::RegisterObject("Edge set geometry algorithms")

void registerEdgeSetGeometryAlgorithms(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Geometry algorithms dedicated to an edge topology.")
.add< EdgeSetGeometryAlgorithms<Vec3Types> >(true) // default template
.add< EdgeSetGeometryAlgorithms<Vec2Types> >()
.add< EdgeSetGeometryAlgorithms<Vec1Types> >()
.add< EdgeSetGeometryAlgorithms<Rigid3Types> >()
.add< EdgeSetGeometryAlgorithms<Rigid2Types> >()

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

template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API EdgeSetGeometryAlgorithms<Vec3Types>;
template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API EdgeSetGeometryAlgorithms<Vec2Types>;
template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API EdgeSetGeometryAlgorithms<Vec1Types>;
template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API EdgeSetGeometryAlgorithms<Rigid3Types>;
template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API EdgeSetGeometryAlgorithms<Rigid2Types>;


} //namespace sofa::component::topology::container::dynamic
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@
namespace sofa::component::topology::container::dynamic
{

using namespace std;
using namespace sofa::defaulttype;
int EdgeSetTopologyContainerClass = core::RegisterObject("Edge set topology container")
.add< EdgeSetTopologyContainer >()
;

void registerEdgeSetTopologyContainer(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Topology container for an edge topology.")
.add< EdgeSetTopologyContainer >());
}

EdgeSetTopologyContainer::EdgeSetTopologyContainer()
: PointSetTopologyContainer( )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@

namespace sofa::component::topology::container::dynamic
{
using namespace sofa::defaulttype;
int EdgeSetTopologyModifierClass = core::RegisterObject("Edge set topology modifier")
.add< EdgeSetTopologyModifier >();

using namespace std;
using namespace sofa::defaulttype;
void registerEdgeSetTopologyModifier(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Topology modifier dedicated to an edge topology.")
.add< EdgeSetTopologyModifier >());
}

using namespace sofa::core::topology;

void EdgeSetTopologyModifier::init()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@

namespace sofa::component::topology::container::dynamic
{

using namespace sofa::defaulttype;
int HexahedronSetGeometryAlgorithmsClass = core::RegisterObject("Hexahedron set geometry algorithms")
.add< HexahedronSetGeometryAlgorithms<Vec3Types> >(true) // default template
.add< HexahedronSetGeometryAlgorithms<Vec2Types> >()

;
void registerHexahedronSetGeometryAlgorithms(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Geometry algorithms dedicated to an hexahedral topology.")
.add< HexahedronSetGeometryAlgorithms<Vec3Types> >(true) // default template
.add< HexahedronSetGeometryAlgorithms<Vec2Types> >());
}

template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API HexahedronSetGeometryAlgorithms<Vec3Types>;
template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API HexahedronSetGeometryAlgorithms<Vec2Types>;


} //namespace sofa::component::topology::container::dynamic
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
namespace sofa::component::topology::container::dynamic
{

using namespace std;
using namespace sofa::defaulttype;
using sofa::core::topology::edgesInHexahedronArray;
using sofa::core::topology::quadsOrientationInHexahedronArray;
using sofa::core::topology::verticesInHexahedronArray;

int HexahedronSetTopologyContainerClass = core::RegisterObject("Hexahedron set topology container")
.add< HexahedronSetTopologyContainer >()
;
void registerHexahedronSetTopologyContainer(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Topology container dedicated to an hexahedral topology.")
.add< HexahedronSetTopologyContainer >());
}

HexahedronSetTopologyContainer::HexahedronSetTopologyContainer()
: QuadSetTopologyContainer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@

namespace sofa::component::topology::container::dynamic
{
int HexahedronSetTopologyModifierClass = core::RegisterObject("Hexahedron set topology modifier")
.add< HexahedronSetTopologyModifier >();

using namespace std;
using namespace sofa::defaulttype;
void registerHexahedronSetTopologyModifier(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Topology modifier dedicated to an hexahedral topology.")
.add< HexahedronSetTopologyModifier >());
}

using namespace sofa::core::topology;

void HexahedronSetTopologyModifier::init()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
namespace sofa::component::topology::container::dynamic
{

using namespace std;
using namespace sofa::type;
using namespace sofa::defaulttype;

int MultilevelHexahedronSetTopologyContainerClass = core::RegisterObject("Hexahedron set topology container")
.add< MultilevelHexahedronSetTopologyContainer >()
;
void registerMultilevelHexahedronSetTopologyContainer(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Multilevel Hexahedron set topology container.")
.add< MultilevelHexahedronSetTopologyContainer >());
}

MultilevelHexahedronSetTopologyContainer::MultilevelHexahedronSetTopologyContainer()
: HexahedronSetTopologyContainer(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,19 @@ namespace sofa::component::topology::container::dynamic
{

using namespace sofa::defaulttype;
int PointSetGeometryAlgorithmsClass = core::RegisterObject("Point set geometry algorithms")

void registerPointSetGeometryAlgorithms(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Geometry algorithms dedicated to a point topology.")
.add< PointSetGeometryAlgorithms<Vec3Types> >(true) // default template
.add< PointSetGeometryAlgorithms<Vec2Types> >()
.add< PointSetGeometryAlgorithms<Vec1Types> >()

;
.add< PointSetGeometryAlgorithms<Vec1Types> >());
}

template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API PointSetGeometryAlgorithms<Vec3Types>;
template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API PointSetGeometryAlgorithms<Vec2Types>;
template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API PointSetGeometryAlgorithms<Vec1Types>;
template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API PointSetGeometryAlgorithms<Rigid3Types>;
template class SOFA_COMPONENT_TOPOLOGY_CONTAINER_DYNAMIC_API PointSetGeometryAlgorithms<Rigid2Types>;


} //namespace sofa::component::topology::container::dynamic
Loading

0 comments on commit 38ecbea

Please sign in to comment.