diff --git a/CMakeLists.txt b/CMakeLists.txt index 85302c55c..d136f5563 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.12) -project(BeamAdapter VERSION 1.0) +project(BeamAdapter VERSION 1.0 LANGUAGES CXX) include(cmake/environment.cmake) diff --git a/extensions/CUDA/CMakeLists.txt b/extensions/CUDA/CMakeLists.txt index 51ffef0dc..edcfdfcde 100644 --- a/extensions/CUDA/CMakeLists.txt +++ b/extensions/CUDA/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.12) -project(BeamAdapter.CUDA) +project(BeamAdapter.CUDA LANGUAGES CXX CUDA) set(HEADER_FILES src/BeamAdapter/CUDA/init.h diff --git a/extensions/CUDA/src/BeamAdapter/CUDA/CudaInstantiations.cpp b/extensions/CUDA/src/BeamAdapter/CUDA/CudaInstantiations.cpp index 3c56f451b..b2ca6ea62 100644 --- a/extensions/CUDA/src/BeamAdapter/CUDA/CudaInstantiations.cpp +++ b/extensions/CUDA/src/BeamAdapter/CUDA/CudaInstantiations.cpp @@ -20,7 +20,7 @@ * Contact information: contact@sofa-framework.org * ******************************************************************************/ #include -#include +#include #include #include @@ -36,149 +36,114 @@ #include #include #include -#include // for InterventionalRadiologyController +#include // for InterventionalRadiologyController #include using namespace sofa::gpu::cuda; -namespace sofa::component::fem::_beaminterpolation_ +namespace beamadapter::cuda { // template class SOFA_BEAMADAPTER_CUDA_API BeamInterpolation; -#ifdef SOFA_GPU_CUDA_DOUBLE - template class SOFA_BEAMADAPTER_CUDA_API BeamInterpolation; -#endif -} // namespace sofa::component::fem::_beaminterpolation_ - -namespace sofa::component::fem::_wirebeaminterpolation_ -{ // template class SOFA_BEAMADAPTER_CUDA_API WireBeamInterpolation; -#ifdef SOFA_GPU_CUDA_DOUBLE - template class SOFA_BEAMADAPTER_CUDA_API WireBeamInterpolation; -#endif -} // namespace sofa::component::fem::_beaminterpolation_ - -namespace sofa::component::engine::_wirerestshape_ -{ template class SOFA_BEAMADAPTER_CUDA_API WireRestShape; -#ifdef SOFA_GPU_CUDA_DOUBLE - template class SOFA_BEAMADAPTER_CUDA_API WireRestShape; -#endif -} // namespace sofa::component::engine::_wirerestshape_ - -namespace sofa::component::controller::_interventionalradiologycontroller_ -{ template class SOFA_BEAMADAPTER_CUDA_API InterventionalRadiologyController; -#ifdef SOFA_GPU_CUDA_DOUBLE - template class SOFA_BEAMADAPTER_CUDA_API InterventionalRadiologyController; -#endif -} // namespace sofa::component::controller::_interventionalradiologycontroller_ - -namespace sofa::component::mapping::_adaptivebeammapping_ -{ template class SOFA_BEAMADAPTER_CUDA_API AdaptiveBeamMapping; -#ifdef SOFA_GPU_CUDA_DOUBLE - template class SOFA_BEAMADAPTER_CUDA_API AdaptiveBeamMapping; -#endif -} // namespace sofa::component::mapping::_adaptivebeammapping_ - -namespace sofa::component::mapping -{ template class SOFA_BEAMADAPTER_CUDA_API MultiAdaptiveBeamMapping; -#ifdef SOFA_GPU_CUDA_DOUBLE - template class SOFA_BEAMADAPTER_CUDA_API MultiAdaptiveBeamMapping; -#endif -} // namespace sofa::component::mapping - -namespace sofa::beamadapter -{ template class SOFA_BEAMADAPTER_CUDA_API RodMeshSection; template class SOFA_BEAMADAPTER_CUDA_API RodSpireSection; template class SOFA_BEAMADAPTER_CUDA_API RodStraightSection; #ifdef SOFA_GPU_CUDA_DOUBLE + template class SOFA_BEAMADAPTER_CUDA_API BeamInterpolation; + template class SOFA_BEAMADAPTER_CUDA_API WireBeamInterpolation; + template class SOFA_BEAMADAPTER_CUDA_API WireRestShape; + template class SOFA_BEAMADAPTER_CUDA_API InterventionalRadiologyController; + template class SOFA_BEAMADAPTER_CUDA_API AdaptiveBeamMapping; + template class SOFA_BEAMADAPTER_CUDA_API MultiAdaptiveBeamMapping; template class SOFA_BEAMADAPTER_CUDA_API RodMeshSection; template class SOFA_BEAMADAPTER_CUDA_API RodSpireSection; template class SOFA_BEAMADAPTER_CUDA_API RodStraightSection; #endif -} // namespace sofa::beamadapter +using namespace sofa::gpu::cuda; -namespace sofa::gpu::cuda +void registerBeamAdapterCUDAComponents(sofa::core::ObjectFactory* factory) { - #ifdef SOFA_GPU_CUDA_DOUBLE -int CudaBeamInterpolationClass = core::RegisterObject("Adaptive Beam Interpolation - Supports GPU-side computations using CUDA") - // .add< sofa::component::fem::BeamInterpolation >() - .add< sofa::component::fem::BeamInterpolation >() - ; + factory->registerObjects(sofa::core::ObjectRegistrationData("Adaptive Beam Interpolation - Supports GPU-side computations using CUDA") + // .add< BeamInterpolation >() + .add< BeamInterpolation >()); #endif #ifdef SOFA_GPU_CUDA_DOUBLE -int CudaWireBeamInterpolationClass = core::RegisterObject("Adaptive Wire Beam Interpolation - Supports GPU-side computations using CUDA") - // .add< sofa::component::fem::WireBeamInterpolation >() - .add< sofa::component::fem::WireBeamInterpolation >() - ; + factory->registerObjects(sofa::core::ObjectRegistrationData("Adaptive Wire Beam Interpolation - Supports GPU-side computations using CUDA") + // .add< WireBeamInterpolation >() + .add< WireBeamInterpolation >()); #endif -int CudaWireRestShapenClass = core::RegisterObject("Wire Shape - Supports GPU-side computations using CUDA") - .add< sofa::component::engine::WireRestShape >() + factory->registerObjects(sofa::core::ObjectRegistrationData("Wire Shape - Supports GPU-side computations using CUDA") + .add< WireRestShape >() #ifdef SOFA_GPU_CUDA_DOUBLE - .add< sofa::component::engine::WireRestShape >() + .add< WireRestShape >() #endif - ; + ); -int CudaAdaptiveBeamForceFieldAndMassClass = core::RegisterObject("Adaptive Beam finite elements - Supports GPU-side computations using CUDA") - .add< sofa::component::forcefield::AdaptiveBeamForceFieldAndMass >() + factory->registerObjects(sofa::core::ObjectRegistrationData("Adaptive Beam finite elements - Supports GPU-side computations using CUDA") + .add< AdaptiveBeamForceFieldAndMass >() #ifdef SOFA_GPU_CUDA_DOUBLE - .add< sofa::component::forcefield::AdaptiveBeamForceFieldAndMass >() + .add< AdaptiveBeamForceFieldAndMass >() #endif - ; + ); -int CudaInterventionalRadiologyControllerClass = core::RegisterObject("Provides a Mouse & Keyboard user control on an EdgeSet Topology - Supports GPU-side computations using CUDA") - .add< sofa::component::controller::InterventionalRadiologyController >() + factory->registerObjects(sofa::core::ObjectRegistrationData("Provides a Mouse & Keyboard user control on an EdgeSet Topology - Supports GPU-side computations using CUDA") + .add< InterventionalRadiologyController >() #ifdef SOFA_GPU_CUDA_DOUBLE - .add< sofa::component::controller::InterventionalRadiologyController >() + .add< InterventionalRadiologyController >() #endif - ; + ); -int CudaAdaptiveBeamMappingClass = core::RegisterObject("Set the positions and velocities of points attached to a beam using linear interpolation between DOFs - Supports GPU-side computations using CUDA") - .add< sofa::component::mapping::AdaptiveBeamMapping >() + factory->registerObjects(sofa::core::ObjectRegistrationData("Provides a Mouse & Keyboard user control on an EdgeSet Topology - Supports GPU-side computations using CUDA") + .add< InterventionalRadiologyController >() #ifdef SOFA_GPU_CUDA_DOUBLE - .add< sofa::component::mapping::AdaptiveBeamMapping >() + .add< InterventionalRadiologyController >() #endif - ; + ); -int CudaMultiAdaptiveBeamMappingClass = core::RegisterObject("Set the positions and velocities of points attached to a beam using linear interpolation between DOFs - Supports GPU-side computations using CUDA") - .add< sofa::component::mapping::MultiAdaptiveBeamMapping >() + factory->registerObjects(sofa::core::ObjectRegistrationData("Set the positions and velocities of points attached to a beam using linear interpolation between DOFs - Supports GPU-side computations using CUDA") + .add< AdaptiveBeamMapping >() #ifdef SOFA_GPU_CUDA_DOUBLE - .add< sofa::component::mapping::MultiAdaptiveBeamMapping >() + .add< AdaptiveBeamMapping >() #endif - ; + ); -const int CudaRodMeshSectionClass = core::RegisterObject("Class defining a Rod Section using a MeshLoader and material parameters using CUDA.") - .add< sofa::beamadapter::RodMeshSection >() + factory->registerObjects(sofa::core::ObjectRegistrationData("Set the positions and velocities of points attached to a beam using linear interpolation between DOFs - Supports GPU-side computations using CUDA") + .add< MultiAdaptiveBeamMapping >() #ifdef SOFA_GPU_CUDA_DOUBLE - .add< sofa::beamadapter::RodMeshSection >() + .add< MultiAdaptiveBeamMapping >() #endif - ; + ); -const int CudaRodSpireSectionClass = core::RegisterObject("Class defining a rod spire section, defining material and geometry parameters using CUDA.") - .add< sofa::beamadapter::RodSpireSection >() + factory->registerObjects(sofa::core::ObjectRegistrationData("Class defining a Rod Section using a MeshLoader and material parameters using CUDA.") + .add< RodMeshSection >() #ifdef SOFA_GPU_CUDA_DOUBLE - .add< sofa::beamadapter::RodSpireSection >() + .add< RodMeshSection >() #endif -; + ); -const int CudaRodStraightSectionClass = core::RegisterObject("Class defining a rod straight section Material, defining material and geometry parameters using CUDA.") - .add< sofa::beamadapter::RodStraightSection >() + factory->registerObjects(sofa::core::ObjectRegistrationData("Class defining a rod spire section, defining material and geometry parameters using CUDA.") + .add< RodSpireSection >() #ifdef SOFA_GPU_CUDA_DOUBLE - .add< sofa::beamadapter::RodStraightSection >() + .add< RodSpireSection >() #endif -; + ); + factory->registerObjects(sofa::core::ObjectRegistrationData("Class defining a rod straight section Material, defining material and geometry parameters using CUDA.") + .add< RodStraightSection >() +#ifdef SOFA_GPU_CUDA_DOUBLE + .add< RodStraightSection >() +#endif + ); +} - - -} // namespace sofa::gpu::cuda - +} // namespace beamadapter diff --git a/extensions/CUDA/src/BeamAdapter/CUDA/init.cpp b/extensions/CUDA/src/BeamAdapter/CUDA/init.cpp index 585cdc745..b29d0a635 100644 --- a/extensions/CUDA/src/BeamAdapter/CUDA/init.cpp +++ b/extensions/CUDA/src/BeamAdapter/CUDA/init.cpp @@ -22,15 +22,20 @@ #include #include #include + #include +#include + namespace beamadapter::cuda { +extern void registerBeamAdapterCUDAComponents(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 const char* getModuleComponentList(); + SOFA_BEAMADAPTER_API void registerObjects(sofa::core::ObjectFactory* factory); } void initExternalModule() @@ -53,17 +58,18 @@ void init() static bool first = true; if (first) { - sofa::component::initBeamAdapter(); + // make sure that this plugin is registered into the PluginManager + sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME); + + beamadapter::initBeamAdapter(); sofa::gpu::cuda::init(); first = false; } } -const char* getModuleComponentList() +void registerObjects(sofa::core::ObjectFactory* factory) { - /// string containing the names of the classes provided by the plugin - static std::string classes = sofa::core::ObjectFactory::getInstance()->listClassesFromTarget(MODULE_NAME); - return classes.c_str(); + registerBeamAdapterCUDAComponents(factory); } } // namespace beamadapter::cuda diff --git a/src/BeamAdapter/component/engine/WireRestShape.inl b/src/BeamAdapter/component/engine/WireRestShape.inl index 3fed22982..dcd08e25d 100644 --- a/src/BeamAdapter/component/engine/WireRestShape.inl +++ b/src/BeamAdapter/component/engine/WireRestShape.inl @@ -198,7 +198,7 @@ void WireRestShape::getMechanicalSampling(Real &dx, const Real x_curv Real x_used = x_curv - EPSILON; const Real totalLength = this->getLength(); - x_used = std::clamp(x_used, 0.0, totalLength); + x_used = std::clamp(x_used, static_cast(0.0), totalLength); const type::vector& keyPts = d_keyPoints.getValue();