Skip to content

Commit

Permalink
[GL, GUI] Apply new factory registration mechanism (sofa-framework#5097)
Browse files Browse the repository at this point in the history
* apply new register mechanism to gui::components

* apply new register mechanism to gl::components

* clean

* Apply suggestions from code review

---------

Co-authored-by: Hugo <[email protected]>
  • Loading branch information
fredroy and hugtalbot authored Dec 10, 2024
1 parent e694dc8 commit 240e4e6
Show file tree
Hide file tree
Showing 44 changed files with 446 additions and 338 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ using sofa::core::MultiVecDerivId;
using sofa::core::MultiVecCoordId;
using sofa::core::ExecParams;
using sofa::linearalgebra::BaseVector;
using sofa::core::RegisterObject;
using sofa::core::ConstMultiVecDerivId;
using sofa::core::VecDerivId;
using sofa::core::VecCoordId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ namespace sofa::gl::component::engine

using namespace sofa::defaulttype;

int TextureInterpolationClass = core::RegisterObject("Create texture coordinate for a given field")
void registerTextureInterpolation(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Create texture coordinate for a given field.")
.add< TextureInterpolation <Vec1Types> >()
.add< TextureInterpolation <Vec2Types> >()
.add< TextureInterpolation <Vec3Types> >()

;
.add< TextureInterpolation <Vec3Types> >());
}

template class SOFA_GL_COMPONENT_ENGINE_API TextureInterpolation <Vec1Types>;
template class SOFA_GL_COMPONENT_ENGINE_API TextureInterpolation <Vec2Types>;
Expand Down
28 changes: 21 additions & 7 deletions Sofa/GL/Component/Engine/src/sofa/gl/component/engine/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,24 @@
******************************************************************************/
#include <sofa/gl/component/engine/init.h>

#include <sofa/core/ObjectFactory.h>
#include <sofa/helper/system/PluginManager.h>

namespace sofa::gl::component::engine
{


extern void registerTextureInterpolation(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()
{
static bool first = true;
if (first)
{
first = false;
}
init();
}

const char* getModuleName()
Expand All @@ -49,9 +51,21 @@ const char* getModuleVersion()
return MODULE_VERSION;
}

void registerObjects(sofa::core::ObjectFactory* factory)
{
registerTextureInterpolation(factory);
}

void init()
{
initExternalModule();
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;
}
}

} // namespace sofa::gl::component::engine
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
namespace sofa::gl::component::rendering2d
{

int OglColorMapClass = core::RegisterObject("Provides color palette and support for conversion of numbers to colors.")
.add< OglColorMap >()
.addAlias("ColorMap")
;
void registerOglColorMap(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Provides color palette and support for conversion of numbers to colors.")
.add< OglColorMap >());
}

OglColorMap::OglColorMap()
: d_paletteSize(initData(&d_paletteSize, (unsigned int)256, "paletteSize", "How many colors to use"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,10 @@ void OglLabel::setColor(float r, float g, float b, float a)
d_color.endEdit();
}


int OglLabelClass = core::RegisterObject("Display 2D text in the viewport.")
.add< OglLabel >()
;
void registerOglLabel(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Display 2D text in the viewport.")
.add< OglLabel >());
}

} // namespace sofa::gl::component::rendering2d
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ namespace sofa::gl::component::rendering2d
using namespace sofa::type;
using namespace sofa::defaulttype;

//Register OglViewport in the Object Factory
int OglViewportClass = core::RegisterObject("OglViewport")
.add< OglViewport >()
;

void registerOglViewport(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Set an additional viewport into the main one.")
.add< OglViewport >());
}

OglViewport::OglViewport()
:p_screenPosition(initData(&p_screenPosition, "screenPosition", "Viewport position"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,25 @@
******************************************************************************/
#include <sofa/gl/component/rendering2d/init.h>
#include <sofa/core/ObjectFactory.h>
#include <sofa/helper/system/PluginManager.h>

namespace sofa::gl::component::rendering2d
{


extern void registerOglColorMap(sofa::core::ObjectFactory* factory);
extern void registerOglLabel(sofa::core::ObjectFactory* factory);
extern void registerOglViewport(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()
{
static bool first = true;
if (first)
{
first = false;
}
init();
}

const char* getModuleName()
Expand All @@ -49,9 +52,23 @@ const char* getModuleVersion()
return MODULE_VERSION;
}

void registerObjects(sofa::core::ObjectFactory* factory)
{
registerOglColorMap(factory);
registerOglLabel(factory);
registerOglViewport(factory);
}

void init()
{
initExternalModule();
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;
}
}

} // namespace sofa::gl::component::rendering2d
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ using sofa::core::objectmodel::ComponentState ;
namespace sofa::gl::component::rendering3d
{

int ClipPlaneClass = core::RegisterObject("OpenGL Clipping Plane")
.add< ClipPlane >()
;

void registerClipPlane(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Define arbitrary clipping plane into OpenGL.")
.add< ClipPlane >());
}

ClipPlane::ClipPlane()
: position(initData(&position, sofa::type::Vec3(0,0,0), "position", "Point crossed by the clipping plane"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ using namespace sofa::type;
using namespace sofa::defaulttype;
using sofa::gl::component::rendering2d::OglColorMap;

int DataDisplayClass = core::RegisterObject("Rendering of meshes colored by data")
.add< DataDisplay >()
;
void registerDataDisplay(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Color rendering of data associated with a mesh.")
.add< DataDisplay >());
}

DataDisplay::DataDisplay()
: f_maximalRange(initData(&f_maximalRange, true, "maximalRange", "Keep the maximal range through all timesteps"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
namespace sofa::gl::component::rendering3d
{

int MergeVisualModelsClass = core::RegisterObject("Merge several visual models")
.add< MergeVisualModels >(true);


void registerMergeVisualModels(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Merge several visual models.")
.add< MergeVisualModels >());
}

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

int OglCylinderModelClass = core::RegisterObject("A simple visualization for set of cylinder.")
.add< OglCylinderModel >()
;
void registerOglCylinderModel(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("OpenGL-based visualization for a cylinders over edges.")
.add< OglCylinderModel >());
}

using namespace sofa::defaulttype;
using namespace sofa::core::topology;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ using sofa::type::RGBAColor;
using sofa::type::Material;
using namespace sofa::type;

int OglModelClass = core::RegisterObject("Generic visual model for OpenGL display")
.add< OglModel >();

void registerOglModel(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Generic visual model for OpenGL display.")
.add< OglModel >());
}

OglModel::OglModel()
: blendTransparency(initData(&blendTransparency, true, "blendTranslucency", "Blend transparent parts"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
namespace sofa::gl::component::rendering3d
{

int OglSceneFrameClass = core::RegisterObject("Display a frame at the corner of the scene view")
.add< OglSceneFrame >()
;
void registerOglSceneFrame(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Display a frame at the corner of the scene view.")
.add< OglSceneFrame >());
}

using namespace sofa::defaulttype;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@
namespace sofa::gl::component::rendering3d
{

int PointSplatModelClass = core::RegisterObject("A simple visualization for a cloud of points.")
.add< PointSplatModel >()
.addAlias("PointSplat")
;
void registerPointSplatModel(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Visualization for a cloud of points using splatting.")
.add< PointSplatModel >());
}

using namespace sofa::defaulttype;
using namespace sofa::core::topology;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@
namespace sofa::gl::component::rendering3d
{

int SlicedVolumetricModelClass = core::RegisterObject("A simple visualization for a cloud of points.")
.add< SlicedVolumetricModel >()
;
void registerSlicedVolumetricModel(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Sliced visualization for a volumetric model defined with hexahedra.")
.add< SlicedVolumetricModel >());
}

using namespace sofa::defaulttype;
using namespace sofa::core::topology;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,30 @@
******************************************************************************/
#include <sofa/gl/component/rendering3d/init.h>
#include <sofa/core/ObjectFactory.h>
#include <sofa/helper/system/PluginManager.h>

namespace sofa::gl::component::rendering3d
{


extern void registerClipPlane(sofa::core::ObjectFactory* factory);
extern void registerDataDisplay(sofa::core::ObjectFactory* factory);
extern void registerMergeVisualModels(sofa::core::ObjectFactory* factory);
extern void registerOglCylinderModel(sofa::core::ObjectFactory* factory);
extern void registerOglModel(sofa::core::ObjectFactory* factory);
extern void registerOglSceneFrame(sofa::core::ObjectFactory* factory);
extern void registerPointSplatModel(sofa::core::ObjectFactory* factory);
extern void registerSlicedVolumetricModel(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()
{
static bool first = true;
if (first)
{
first = false;
}
init();
}

const char* getModuleName()
Expand All @@ -49,9 +57,28 @@ const char* getModuleVersion()
return MODULE_VERSION;
}

void registerObjects(sofa::core::ObjectFactory* factory)
{
registerClipPlane(factory);
registerDataDisplay(factory);
registerMergeVisualModels(factory);
registerOglCylinderModel(factory);
registerOglModel(factory);
registerOglSceneFrame(factory);
registerPointSplatModel(factory);
registerSlicedVolumetricModel(factory);
}

void init()
{
initExternalModule();
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;
}
}

} // namespace sofa::gl::component::rendering3d
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
namespace sofa::gl::component::shader
{

int CompositingVisualLoopClass = core::RegisterObject("Visual loop enabling multipass rendering. Needs multiple fbo data and a compositing shader")
.add< CompositingVisualLoop >()
;
void registerCompositingVisualLoop(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Visual loop enabling multipass rendering. Needs multiple fbo data and a compositing shader.")
.add< CompositingVisualLoop >());
}

CompositingVisualLoop::CompositingVisualLoop()
: simulation::DefaultVisualManagerLoop(),
Expand Down
Loading

0 comments on commit 240e4e6

Please sign in to comment.