diff --git a/src/SofaMJEDFEM/MJEDTetrahedralForceField.cpp b/src/SofaMJEDFEM/MJEDTetrahedralForceField.cpp index 849486d..86de210 100644 --- a/src/SofaMJEDFEM/MJEDTetrahedralForceField.cpp +++ b/src/SofaMJEDFEM/MJEDTetrahedralForceField.cpp @@ -34,9 +34,11 @@ namespace sofa::component::forcefield using namespace sofa::defaulttype; // Register in the Factory -int MJEDTetrahedralForceFieldClass = core::RegisterObject("Tetrahedral FEM model of visco-hyperelastic material using MJED") - .add< MJEDTetrahedralForceField >() - ; +void registerMJEDTetrahedralForceField(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Tetrahedral FEM model of visco-hyperelastic material using MJED") + .add< MJEDTetrahedralForceField >()); +} template class SOFA_MJED_FEM_API MJEDTetrahedralForceField; diff --git a/src/SofaMJEDFEM/MJEDTetrahedralForceField.inl b/src/SofaMJEDFEM/MJEDTetrahedralForceField.inl index c874f5e..b4087c7 100644 --- a/src/SofaMJEDFEM/MJEDTetrahedralForceField.inl +++ b/src/SofaMJEDFEM/MJEDTetrahedralForceField.inl @@ -66,7 +66,7 @@ void MJEDTetrahedralForceField::createTetrahedronRestInformation(unsi - const typename DataTypes::VecCoord& restPosition=this->mstate->read(sofa::core::ConstVecCoordId::restPosition())->getValue(); + const typename DataTypes::VecCoord& restPosition=this->mstate->read(sofa::core::vec_id::read_access::restPosition)->getValue(); ///describe the indices of the 4 tetrahedron vertices const Tetrahedron &t= tetrahedronArray[tetrahedronIndex]; @@ -114,7 +114,6 @@ void MJEDTetrahedralForceField::createTetrahedronRestInformation(unsi materialTermArray = myMaterial->getMaterialTermArray(); typename vector::iterator it; it=materialTermArray.begin(); - int id=0; std::vector number; Real coefficient=0; tinfo.coeff.resize(0); @@ -181,7 +180,6 @@ void MJEDTetrahedralForceField::createTetrahedronRestInformation(unsi tinfo.Lij_second_k.push_back( Lijsecond ); } - id++; tinfo.functionf.push_back(1); tinfo.functiong.push_back(1); tinfo.functionDf.push_back(0); @@ -353,7 +351,7 @@ template void MJEDTetrahedralForceField::init() // get restPosition if (_initialPoints.size() == 0) { - const VecCoord& p = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& p = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); _initialPoints=p; } @@ -734,7 +732,7 @@ void MJEDTetrahedralForceField::updateMatrixData() helper::WriteOnlyAccessor< Data > > tetrahedronInf = tetrahedronInfo; // VecDeriv& x = myposition; // to uncomment for test derivatives and comment next line - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); EdgeInformation *einfo; unsigned int m,n; @@ -1136,7 +1134,7 @@ void MJEDTetrahedralForceField::testDerivatives() { DataVecCoord d_pos; VecCoord &pos = *d_pos.beginEdit(); - pos = this->mstate->read(sofa::core::ConstVecCoordId::position())->getValue(); + pos = this->mstate->read(sofa::core::vec_id::read_access::position)->getValue(); // perturbate original state: srand( 0 ); @@ -1259,7 +1257,7 @@ void MJEDTetrahedralForceField::testDerivatives() template void MJEDTetrahedralForceField::saveMesh( const char *filename ) { - VecCoord pos(this->mstate->read(sofa::core::ConstVecCoordId::position())->getValue()); + VecCoord pos(this->mstate->read(sofa::core::vec_id::read_access::position)->getValue()); core::topology::BaseMeshTopology::SeqTriangles triangles = _topology->getTriangles(); FILE *file = fopen( filename, "wb" ); if (!file) return; diff --git a/src/SofaMJEDFEM/config.h.in b/src/SofaMJEDFEM/config.h.in index 85853b2..4b567cb 100644 --- a/src/SofaMJEDFEM/config.h.in +++ b/src/SofaMJEDFEM/config.h.in @@ -32,3 +32,9 @@ #else # define SOFA_MJED_FEM_API SOFA_IMPORT_DYNAMIC_LIBRARY #endif + +namespace sofamjedfem +{ +constexpr const char* MODULE_NAME = "@PROJECT_NAME@"; +constexpr const char* MODULE_VERSION = "@PROJECT_VERSION@"; +} // namespace sofamjedfem \ No newline at end of file diff --git a/src/SofaMJEDFEM/initSofaMJEDFEM.cpp b/src/SofaMJEDFEM/initSofaMJEDFEM.cpp index f9cef1d..5971323 100644 --- a/src/SofaMJEDFEM/initSofaMJEDFEM.cpp +++ b/src/SofaMJEDFEM/initSofaMJEDFEM.cpp @@ -21,54 +21,72 @@ ******************************************************************************/ #include #include +#include + using sofa::core::ObjectFactory; -namespace sofa::component +namespace sofamjedfem { + extern void registerMJEDTetrahedralForceField(sofa::core::ObjectFactory *factory); +} // namespace sofamjedfem -extern "C" { - SOFA_MJED_FEM_API void initExternalModule(); - SOFA_MJED_FEM_API const char* getModuleName(); - SOFA_MJED_FEM_API const char* getModuleVersion(); - SOFA_MJED_FEM_API const char* getModuleLicense(); - SOFA_MJED_FEM_API const char* getModuleDescription(); - SOFA_MJED_FEM_API const char* getModuleComponentList(); -} -void initExternalModule() +namespace sofa::component { - static bool first = true; - if (first) + using namespace sofamjedfem; + + extern "C" { + SOFA_MJED_FEM_API void initExternalModule(); + SOFA_MJED_FEM_API const char* getModuleName(); + SOFA_MJED_FEM_API const char* getModuleVersion(); + SOFA_MJED_FEM_API const char* getModuleLicense(); + SOFA_MJED_FEM_API const char* getModuleDescription(); + SOFA_MJED_FEM_API const char* getModuleComponentList(); + SOFA_MJED_FEM_API void registerObjects(sofa::core::ObjectFactory* factory); + } + + void initExternalModule() { - first = false; + 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; + } } -} -const char* getModuleName() -{ - return sofa_tostring(SOFA_TARGET); -} + const char* getModuleName() + { + return sofa_tostring(SOFA_TARGET); + } -const char* getModuleVersion() -{ - return sofa_tostring(SOFAMJEDFEM_VERSION); -} + const char* getModuleVersion() + { + return sofa_tostring(SOFAMJEDFEM_VERSION); + } -const char* getModuleLicense() -{ - return "LGPL"; -} + const char* getModuleLicense() + { + return "LGPL"; + } -const char* getModuleDescription() -{ - return "This plugin implements the Multiplicative Jacobian Energy Decomposition or MJED method."; -} + const char* getModuleDescription() + { + return "This plugin implements the Multiplicative Jacobian Energy Decomposition or MJED method."; + } -const char* getModuleComponentList() -{ - /// string containing the names of the classes provided by the plugin - static std::string classes = ObjectFactory::getInstance()->listClassesFromTarget(sofa_tostring(SOFA_TARGET)); - return classes.c_str(); -} + const char* getModuleComponentList() + { + /// string containing the names of the classes provided by the plugin + static std::string classes = ObjectFactory::getInstance()->listClassesFromTarget(sofa_tostring(SOFA_TARGET)); + return classes.c_str(); + } + + void registerObjects(sofa::core::ObjectFactory* factory) + { + registerMJEDTetrahedralForceField(factory); + } } // namespace sofa::component