From 147adad217b41adbba9227569f9286cf54f823f5 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Fri, 6 Sep 2024 14:07:54 +0900 Subject: [PATCH 1/4] apply new register mechanism to io --- .../component/io/mesh/BlenderExporter.cpp | 13 +++-- .../sofa/component/io/mesh/BlenderExporter.h | 6 ++- .../sofa/component/io/mesh/GIDMeshLoader.cpp | 6 +++ .../component/io/mesh/GridMeshCreator.cpp | 10 ++-- .../sofa/component/io/mesh/MeshExporter.cpp | 28 ++++++----- .../sofa/component/io/mesh/MeshGmshLoader.cpp | 8 +-- .../sofa/component/io/mesh/MeshOBJLoader.cpp | 8 +-- .../sofa/component/io/mesh/MeshOffLoader.cpp | 8 +-- .../sofa/component/io/mesh/MeshSTLLoader.cpp | 7 ++- .../component/io/mesh/MeshTrianLoader.cpp | 8 +-- .../sofa/component/io/mesh/MeshVTKLoader.cpp | 13 ++--- .../sofa/component/io/mesh/MeshXspLoader.cpp | 8 ++- .../component/io/mesh/OffSequenceLoader.cpp | 10 ++-- .../sofa/component/io/mesh/STLExporter.cpp | 14 ++++-- .../sofa/component/io/mesh/SphereLoader.cpp | 7 ++- .../component/io/mesh/StringMeshCreator.cpp | 10 ++-- .../sofa/component/io/mesh/VTKExporter.cpp | 14 ++++-- .../io/mesh/VisualModelOBJExporter.cpp | 19 ++++--- .../component/io/mesh/VoxelGridLoader.cpp | 6 ++- .../Mesh/src/sofa/component/io/mesh/init.cpp | 49 ++++++++++++++++++- .../IO/src/sofa/component/io/init.cpp | 7 +++ Sofa/Component/src/sofa/component/init.cpp | 1 + .../src/sofa/helper/ComponentChange.cpp | 4 +- 23 files changed, 189 insertions(+), 75 deletions(-) diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/BlenderExporter.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/BlenderExporter.cpp index 1212985563c..0a511681340 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/BlenderExporter.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/BlenderExporter.cpp @@ -22,13 +22,16 @@ #include #include -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 >() - .add< BlenderExporter >() - ; + .add< BlenderExporter >()); +} -} // sofa::component::_blenderexporter_ +} // namespace sofa::component::io::mesh diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/BlenderExporter.h b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/BlenderExporter.h index 8d32f52f15f..d6d9e614a59 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/BlenderExporter.h +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/BlenderExporter.h @@ -133,9 +133,11 @@ class SOFA_COMPONENT_IO_MESH_API BlenderExporter: public core::objectmodel::Base } // namespace _blenderexporter_ -namespace exporter { +namespace io::mesh +{ template using BlenderExporter = _blenderexporter_::BlenderExporter; -} // namespace exporter + +} // namespace io::mesh } // namespace sofa::component diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/GIDMeshLoader.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/GIDMeshLoader.cpp index c267bd5dd48..f6c34e4c513 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/GIDMeshLoader.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/GIDMeshLoader.cpp @@ -31,6 +31,12 @@ using namespace sofa::helper; namespace sofa::component::io::mesh { +void registerGIDMeshLoader(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Load volumetric meshes generated by GID. Some element types are not implemented.") + .add< GIDMeshLoader >()); +} + int GIDMeshLoaderClass = core::RegisterObject("Loads volumetric meshes generated by GID. Some element types are not implemented.") .add< GIDMeshLoader >(); diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/GridMeshCreator.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/GridMeshCreator.cpp index 85ff87257c3..6fa590ba410 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/GridMeshCreator.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/GridMeshCreator.cpp @@ -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")) diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshExporter.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshExporter.cpp index 62c9607843d..a107a8fd4c0 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshExporter.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshExporter.cpp @@ -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)")) @@ -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 diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshGmshLoader.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshGmshLoader.cpp index 0d922b25e32..13e5631da92 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshGmshLoader.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshGmshLoader.cpp @@ -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() { diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshOBJLoader.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshOBJLoader.cpp index b94374ae915..9b8e83b4d5a 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshOBJLoader.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshOBJLoader.cpp @@ -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() diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshOffLoader.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshOffLoader.cpp index e2a81cec71a..646b122d7a8 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshOffLoader.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshOffLoader.cpp @@ -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() { diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshSTLLoader.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshSTLLoader.cpp index 3b10c6bac25..461ce1a8eab 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshSTLLoader.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshSTLLoader.cpp @@ -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() diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshTrianLoader.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshTrianLoader.cpp index 2015d56d42c..1a576ec3686 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshTrianLoader.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshTrianLoader.cpp @@ -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.")) diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshVTKLoader.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshVTKLoader.cpp index c5324ce59b0..aab8adc5b2e 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshVTKLoader.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshVTKLoader.cpp @@ -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 - diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshXspLoader.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshXspLoader.cpp index c0012fb6d83..d31f2cd63c7 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshXspLoader.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshXspLoader.cpp @@ -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 diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/OffSequenceLoader.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/OffSequenceLoader.cpp index adf916c64d0..8ac9d9ec47c 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/OffSequenceLoader.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/OffSequenceLoader.cpp @@ -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() diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/STLExporter.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/STLExporter.cpp index 3d5624862eb..ddd9e60c458 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/STLExporter.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/STLExporter.cpp @@ -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")) @@ -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 diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/SphereLoader.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/SphereLoader.cpp index 3e58773ac85..50541071531 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/SphereLoader.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/SphereLoader.cpp @@ -34,8 +34,11 @@ using namespace sofa::type; namespace sofa::component::io::mesh { -int SphereLoaderClass = core::RegisterObject("Loader for sphere model description files") - .add(); +void registerSphereLoader(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Loader for sphere model description files.") + .add< SphereLoader >()); +} SphereLoader::SphereLoader() :BaseLoader(), diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/StringMeshCreator.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/StringMeshCreator.cpp index 9176fd655e5..2b35dff17d0 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/StringMeshCreator.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/StringMeshCreator.cpp @@ -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")) diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VTKExporter.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VTKExporter.cpp index 0093afe0a0b..7d48e252a74 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VTKExporter.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VTKExporter.cpp @@ -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")) @@ -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 diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VisualModelOBJExporter.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VisualModelOBJExporter.cpp index 813ae840fa6..4ed69e5e1ff 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VisualModelOBJExporter.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VisualModelOBJExporter.cpp @@ -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() { } @@ -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 diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VoxelGridLoader.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VoxelGridLoader.cpp index 3089bda7fab..fb3e4601cd6 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VoxelGridLoader.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VoxelGridLoader.cpp @@ -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(); +void registerVoxelGridLoader(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Voxel loader based on RAW files.") + .add< VoxelGridLoader >()); +} VoxelGridLoader::VoxelGridLoader() : VoxelLoader(), diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/init.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/init.cpp index 3bb7f8f9487..9eb01ce96f0 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/init.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/init.cpp @@ -21,13 +21,35 @@ ******************************************************************************/ #include #include +#include + namespace sofa::component::io::mesh { - + +extern void registerBlenderExporter(sofa::core::ObjectFactory* factory); +extern void registerGIDMeshLoader(sofa::core::ObjectFactory* factory); +extern void registerGridMeshCreator(sofa::core::ObjectFactory* factory); +extern void registerMeshExporter(sofa::core::ObjectFactory* factory); +extern void registerMeshGmshLoader(sofa::core::ObjectFactory* factory); +extern void registerMeshOBJLoader(sofa::core::ObjectFactory* factory); +extern void registerMeshOffLoader(sofa::core::ObjectFactory* factory); +extern void registerMeshSTLLoader(sofa::core::ObjectFactory* factory); +extern void registerMeshTrianLoader(sofa::core::ObjectFactory* factory); +extern void registerMeshVTKLoader(sofa::core::ObjectFactory* factory); +extern void registerMeshXspLoader(sofa::core::ObjectFactory* factory); +extern void registerOffSequenceLoader(sofa::core::ObjectFactory* factory); +extern void registerSphereLoader(sofa::core::ObjectFactory* factory); +extern void registerSTLExporter(sofa::core::ObjectFactory* factory); +extern void registerStringMeshCreator(sofa::core::ObjectFactory* factory); +extern void registerVisualModelOBJExporter(sofa::core::ObjectFactory* factory); +extern void registerVoxelGridLoader(sofa::core::ObjectFactory* factory); +extern void registerVTKExporter(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() @@ -45,11 +67,36 @@ const char* getModuleVersion() return MODULE_VERSION; } +void registerObjects(sofa::core::ObjectFactory* factory) +{ + registerBlenderExporter(factory); + registerGIDMeshLoader(factory); + registerGridMeshCreator(factory); + registerMeshExporter(factory); + registerMeshGmshLoader(factory); + registerMeshOBJLoader(factory); + registerMeshOffLoader(factory); + registerMeshSTLLoader(factory); + registerMeshTrianLoader(factory); + registerMeshVTKLoader(factory); + registerMeshXspLoader(factory); + registerOffSequenceLoader(factory); + registerSphereLoader(factory); + registerSTLExporter(factory); + registerStringMeshCreator(factory); + registerVisualModelOBJExporter(factory); + registerVoxelGridLoader(factory); + registerVTKExporter(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; } } diff --git a/Sofa/Component/IO/src/sofa/component/io/init.cpp b/Sofa/Component/IO/src/sofa/component/io/init.cpp index 4f8e9d3ed2d..9420f4c267f 100644 --- a/Sofa/Component/IO/src/sofa/component/io/init.cpp +++ b/Sofa/Component/IO/src/sofa/component/io/init.cpp @@ -23,6 +23,8 @@ #include +#include + namespace sofa::component::io { @@ -47,6 +49,11 @@ const char* getModuleVersion() return MODULE_VERSION; } +void registerObjects(sofa::core::ObjectFactory* factory) +{ + factory->registerObjectsFromPlugin("Sofa.Component.IO.Mesh"); +} + void init() { static bool first = true; diff --git a/Sofa/Component/src/sofa/component/init.cpp b/Sofa/Component/src/sofa/component/init.cpp index bacd8ad22ce..0ed2aa7d84d 100644 --- a/Sofa/Component/src/sofa/component/init.cpp +++ b/Sofa/Component/src/sofa/component/init.cpp @@ -79,6 +79,7 @@ void registerObjects(sofa::core::ObjectFactory* factory) factory->registerObjectsFromPlugin("Sofa.Component.Visual"); factory->registerObjectsFromPlugin("Sofa.Component.Playback"); factory->registerObjectsFromPlugin("Sofa.Component.SceneUtility"); + factory->registerObjectsFromPlugin("Sofa.Component.IO"); } void init() diff --git a/Sofa/framework/Helper/src/sofa/helper/ComponentChange.cpp b/Sofa/framework/Helper/src/sofa/helper/ComponentChange.cpp index 4fe474599f3..3eb23dc40bf 100644 --- a/Sofa/framework/Helper/src/sofa/helper/ComponentChange.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/ComponentChange.cpp @@ -773,7 +773,9 @@ const std::map< std::string, Dealiased, std::less<> > dealiasedComponents = { {"SofaDefaultPath", Dealiased("v24.12","SofaDefaultPathSetting")}, {"Stats", Dealiased("v24.12","StatsSetting")}, {"Viewer", Dealiased("v24.12","ViewerSetting")}, - + {"MeshObjLoader", Dealiased("v24.12","MeshOBJLoader")}, + {"ObjExporter", Dealiased("v24.12","VisualModelOBJExporter")}, + {"OBJExporter", Dealiased("v24.12","VisualModelOBJExporter")}, }; } // namespace sofa::helper::lifecycle From d0ce021fd18a204805fa73500f85e1e99e8764a3 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Fri, 6 Sep 2024 15:37:17 +0900 Subject: [PATCH 2/4] force registering meta plugin --- Sofa/Component/IO/src/sofa/component/io/init.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sofa/Component/IO/src/sofa/component/io/init.cpp b/Sofa/Component/IO/src/sofa/component/io/init.cpp index 9420f4c267f..b20fbf64c77 100644 --- a/Sofa/Component/IO/src/sofa/component/io/init.cpp +++ b/Sofa/Component/IO/src/sofa/component/io/init.cpp @@ -24,6 +24,7 @@ #include #include +#include namespace sofa::component::io { @@ -62,6 +63,9 @@ void init() // force dependencies at compile-time sofa::component::io::mesh::init(); + // make sure that this plugin is registered into the PluginManager + sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME); + first = false; } } From 35bf3ef12fbb64caadc318525a5b46e48c391649 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Fri, 6 Sep 2024 16:52:51 +0900 Subject: [PATCH 3/4] fix forgotten declaration of entrypoint registerObject --- Sofa/Component/IO/src/sofa/component/io/init.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Sofa/Component/IO/src/sofa/component/io/init.cpp b/Sofa/Component/IO/src/sofa/component/io/init.cpp index b20fbf64c77..45cfe4d1971 100644 --- a/Sofa/Component/IO/src/sofa/component/io/init.cpp +++ b/Sofa/Component/IO/src/sofa/component/io/init.cpp @@ -33,6 +33,7 @@ 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() From 26cf514d898c17389b94bde82dfd6e8156b0cb0d Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Fri, 6 Sep 2024 21:16:05 +0900 Subject: [PATCH 4/4] remove forgotten implicit registration --- .../IO/Mesh/src/sofa/component/io/mesh/GIDMeshLoader.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/GIDMeshLoader.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/GIDMeshLoader.cpp index f6c34e4c513..a88f5b62cac 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/GIDMeshLoader.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/GIDMeshLoader.cpp @@ -37,9 +37,6 @@ void registerGIDMeshLoader(sofa::core::ObjectFactory* factory) .add< GIDMeshLoader >()); } -int GIDMeshLoaderClass = core::RegisterObject("Loads volumetric meshes generated by GID. Some element types are not implemented.") - .add< GIDMeshLoader >(); - GIDMeshLoader::GIDMeshLoader() : MeshLoader() {