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

[IO] Apply new factory registration mechanism #4976

Merged
merged 5 commits into from
Sep 18, 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 @@ -22,13 +22,16 @@
#include <sofa/component/io/mesh/BlenderExporter.inl>
#include <sofa/core/ObjectFactory.h>

namespace sofa::component::_blenderexporter_
namespace sofa::component::io::mesh
{

using namespace defaulttype;

int BlenderExportClass = core::RegisterObject("Export the simulation result as blender point cache files")
void registerBlenderExporter(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Export the simulation result as blender point cache files.")
.add< BlenderExporter<Vec3dTypes> >()
.add< BlenderExporter<Rigid3Types> >()
;
.add< BlenderExporter<Rigid3Types> >());
}

} // sofa::component::_blenderexporter_
} // namespace sofa::component::io::mesh
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,11 @@ class SOFA_COMPONENT_IO_MESH_API BlenderExporter: public core::objectmodel::Base

} // namespace _blenderexporter_

namespace exporter {
namespace io::mesh
{
template<class T>
using BlenderExporter = _blenderexporter_::BlenderExporter<T>;
} // namespace exporter

} // namespace io::mesh

} // namespace sofa::component
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ using namespace sofa::helper;
namespace sofa::component::io::mesh
{

int GIDMeshLoaderClass = core::RegisterObject("Loads volumetric meshes generated by GID. Some element types are not implemented.")
.add< GIDMeshLoader >();
void registerGIDMeshLoader(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Load volumetric meshes generated by GID. Some element types are not implemented.")
.add< GIDMeshLoader >());
}

GIDMeshLoader::GIDMeshLoader() :
MeshLoader()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ using namespace sofa::helper;
using namespace sofa::core::loader;
using type::vector;

int GridMeshCreatorClass = core::RegisterObject("Procedural creation of a two-dimensional mesh.")
.add< GridMeshCreator >()
;


void registerGridMeshCreator(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Procedural creation of a two-dimensional mesh.")
.add< GridMeshCreator >());
}

GridMeshCreator::GridMeshCreator(): MeshLoader()
, d_resolution(initData(&d_resolution, Vec2i(2, 2), "resolution", "Number of vertices in each direction"))
Expand Down
28 changes: 17 additions & 11 deletions Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@ using sofa::core::objectmodel::ComponentState ;
namespace sofa::component::_meshexporter_
{

int MeshExporterClass = core::RegisterObject("Export topology and positions into file. " msgendl
"Supported format are: " msgendl
"- vtkxml" msgendl
"- vtk" msgendl
"- netgen" msgendl
"- teten" msgendl
"- gmsh" msgendl
"- obj" msgendl)

.add< MeshExporter >();

MeshExporter::MeshExporter()
: d_fileFormat( initData(&d_fileFormat, {"ALL","vtkxml","vtk","netgen","tetgen","gmsh","obj"}, "format", "File format to use"))
, d_position( initData(&d_position, "position", "points position (will use points from topology or mechanical state if this is empty)"))
Expand Down Expand Up @@ -889,3 +878,20 @@ void MeshExporter::handleEvent(sofa::core::objectmodel::Event *event)
}

} // namespace sofa::component::_meshexporter_

namespace sofa::component::io::mesh
{
void registerMeshExporter(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Export topology and positions into file. " msgendl
"Supported format are: " msgendl
"- vtkxml" msgendl
"- vtk" msgendl
"- netgen" msgendl
"- teten" msgendl
"- gmsh" msgendl
"- obj" msgendl)
.add< MeshExporter >());
}

} // namespace sofa::component::io::mesh
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ using namespace sofa::helper;
using std::string;
using std::stringstream;

int MeshGmshLoaderClass = core::RegisterObject("Specific mesh loader for Gmsh file format.")
.add< MeshGmshLoader >()
;
void registerMeshGmshLoader(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Specific mesh loader for Gmsh file format.")
.add< MeshGmshLoader >());
}

bool MeshGmshLoader::doLoad()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ using namespace sofa::defaulttype;
using namespace sofa::core::loader;
using sofa::helper::getWriteOnlyAccessor;

int MeshOBJLoaderClass = core::RegisterObject("Specific mesh loader for OBJ file format.")
.add< MeshOBJLoader >()
.addAlias("MeshObjLoader");
void registerMeshOBJLoader(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Specific mesh loader for OBJ file format.")
.add< MeshOBJLoader >());
}

MeshOBJLoader::MeshOBJLoader()
: MeshLoader()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ using namespace sofa::type;
using namespace sofa::defaulttype;
using namespace sofa::helper;

int MeshOffLoaderClass = core::RegisterObject("Specific mesh loader for Off file format.")
.add< MeshOffLoader >()
;
void registerMeshOffLoader(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Specific mesh loader for Off file format.")
.add< MeshOffLoader >());
}

bool MeshOffLoader::doLoad()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ using sofa::helper::getWriteOnlyAccessor;
using namespace sofa::type;
using namespace sofa::defaulttype;

static int MeshSTLLoaderClass = core::RegisterObject("Loader for the STL file format. STL can be used to represent the surface of object using with a triangulation.")
.add< MeshSTLLoader >();
void registerMeshSTLLoader(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Loader for the STL file format. STL can be used to represent the surface of object using with a triangulation.")
.add< MeshSTLLoader >());
}

//Base VTK Loader
MeshSTLLoader::MeshSTLLoader() : MeshLoader()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ namespace sofa::component::io::mesh
using namespace sofa::type;
using namespace sofa::defaulttype;

int MeshTrianLoaderClass = core::RegisterObject("Specific mesh loader for trian (only triangulations) file format.")
.add< MeshTrianLoader >()
;
void registerMeshTrianLoader(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Specific mesh loader for trian (only triangulations) file format.")
.add< MeshTrianLoader >());
}

MeshTrianLoader::MeshTrianLoader() : MeshLoader()
, d_trian2(initData(&d_trian2, (bool)false, "trian2", "Set to true if the mesh is a trian2 format."))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1257,13 +1257,10 @@ bool XMLVTKReader::loadImageData(tinyxml2::XMLHandle datasetFormatHandle)
return false;
}


//////////////////////////////////////////// REGISTERING TO FACTORY /////////////////////////////////////////
/// Registering the component
/// see: https://www.sofa-framework.org/community/doc/programming-with-sofa/components-api/the-objectfactory/
/// 2-RegisterObject("description") + .add<> : Register the component
int MeshVTKLoaderClass = core::RegisterObject("Mesh loader for the VTK/VTU file format.")
.add< MeshVTKLoader >();
void registerMeshVTKLoader(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Mesh loader for the VTK/VTU file format.")
.add< MeshVTKLoader >());
}

} /// namespace sofa::component::io::mesh

Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ void MeshXspLoader::doClearBuffers()
/// Nothing to do if no output is added to the "filename" dataTrackerEngine.
}

int MeshXspLoaderClass = core::RegisterObject("Specific mesh loader for Xsp file format.")
.add< MeshXspLoader >();
void registerMeshXspLoader(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Specific mesh loader for Xsp file format.")
.add< MeshXspLoader >());
}

} //namespace sofa::component::io::mesh
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
namespace sofa::component::io::mesh
{

using namespace sofa::defaulttype;

int OffSequenceLoaderClass = core::RegisterObject("Read and load an .off file at each timestep")
.add< OffSequenceLoader >();

void registerOffSequenceLoader(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Read and load an .off file at each timestep.")
.add< OffSequenceLoader >());
}

OffSequenceLoader::OffSequenceLoader()
: MeshOffLoader()
Expand Down
14 changes: 11 additions & 3 deletions Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/STLExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ using sofa::core::objectmodel::ComponentState ;
namespace sofa::component::_stlexporter_
{

int STLExporterClass = core::RegisterObject("Save a topology in file")
.add< STLExporter >();

STLExporter::STLExporter()
: d_binaryFormat( initData(&d_binaryFormat, (bool)true, "binaryformat", "if true, save in binary format, otherwise in ascii"))
, d_position( initData(&d_position, "position", "points coordinates"))
Expand Down Expand Up @@ -323,3 +320,14 @@ void STLExporter::handleEvent(Event *event)
}

} // namespace sofa::component::_stlexporter_

namespace sofa::component::io::mesh
{

void registerSTLExporter(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Save a topology in file.")
.add< STLExporter >());
}

} // namespace sofa::component::io::mesh
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ using namespace sofa::type;
namespace sofa::component::io::mesh
{

int SphereLoaderClass = core::RegisterObject("Loader for sphere model description files")
.add<SphereLoader>();
void registerSphereLoader(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Loader for sphere model description files.")
.add< SphereLoader >());
}

SphereLoader::SphereLoader()
:BaseLoader(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ using namespace sofa::defaulttype;
using namespace sofa::core::loader;
using type::vector;

int StringMeshCreatorClass = core::RegisterObject("Procedural creation of a one-dimensional mesh.")
.add< StringMeshCreator >()
;


void registerStringMeshCreator(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Procedural creation of a one-dimensional mesh.")
.add< StringMeshCreator >());
}

StringMeshCreator::StringMeshCreator(): MeshLoader()
, d_resolution(initData(&d_resolution, (unsigned)2, "resolution", "Number of vertices"))
Expand Down
14 changes: 11 additions & 3 deletions Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VTKExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
namespace sofa::component::_vtkexporter_
{

int VTKExporterClass = core::RegisterObject("Save State vectors from file at each timestep")
.add< VTKExporter >();

VTKExporter::VTKExporter()
: m_stepCounter(0), outfile(nullptr)
, d_vtkFilename(initData(&d_vtkFilename, "filename", "output VTK file name"))
Expand Down Expand Up @@ -1015,3 +1012,14 @@ void VTKExporter::cleanup()
}

} // namespace sofa::component::_vtkexporter_

namespace sofa::component::io::mesh
{

void registerVTKExporter(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Export a given mesh in a VTK file.")
.add< VTKExporter >());
}

} // namespace sofa::component::io::mesh
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ using sofa::core::objectmodel::KeypressedEvent ;
namespace sofa::component::_visualmodelobjexporter_
{

int VisualModelOBJExporterClass = core::RegisterObject("Export the scene under the Wavefront OBJ format."
"When several frames are exported the file name have the following pattern: outfile000.obj outfile001.obj.")
.add< VisualModelOBJExporter >()
.addAlias("ObjExporter")
.addAlias("OBJExporter");


VisualModelOBJExporter::~VisualModelOBJExporter()
{
}
Expand Down Expand Up @@ -96,3 +89,15 @@ void VisualModelOBJExporter::handleEvent(Event *event)
}

} // namespace sofa::component::_visualmodelobjexporter_

namespace sofa::component::io::mesh
{

void registerVisualModelOBJExporter(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Export the scene under the Wavefront OBJ format."
"When several frames are exported the file name have the following pattern: outfile000.obj outfile001.obj.")
.add< VisualModelOBJExporter >());
}

} // namespace sofa::component::io::mesh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ using namespace sofa::defaulttype;
using namespace sofa::core::loader;
using namespace sofa::core;

int VoxelGridLoaderClass = RegisterObject("Voxel loader based on RAW files").add<VoxelGridLoader>();
void registerVoxelGridLoader(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Voxel loader based on RAW files.")
.add< VoxelGridLoader >());
}

VoxelGridLoader::VoxelGridLoader()
: VoxelLoader(),
Expand Down
Loading
Loading