dtk plugins tricks

In this post, we are going to explore two tricks around plugins: auto-loading and application private plugins.

auto-loading

dtk plugins path is usually set in a .config/inria/dtk-LAYER-NAME.ini file (in linux) in order to be loaded at runtime. Let’s take the layer dtk-discrete-geometry for demonstration. For this layer, my dtk-discrete-geometry.ini file is:

[discrete-geometry]
plugins=/home/tcabel/Devel/dtk-plugins-discrete-geometry/build/lib64

the default action when you initialize a layer is to scan all files in the plugins directory define in this .ini file and load them if they are plugins of the layer being initialized.
However, you may have some plugins that cannot work together (for example two plugins compiled with different versions of VTK). In this situation, you can choose to only load the plugins you need. Here is how you do these two options:

  • default way:
    // dtk-discrete-geometry
     dtkDiscreteGeometry::pluginManager::initialize();
    
     mesh_view = dtkDiscreteGeometry::meshView::pluginFactory().create("dtkMeshViewVTKCatalyst");
  • no auto-load
     //dtk-discrete-geometry
     dtkDiscreteGeometry::pluginManager::setAutoLoading(false);
     dtkDiscreteGeometry::pluginManager::initialize();
    
     dtkDiscreteGeometry::meshView::pluginManager().loadFromName("dtkMeshViewVTKCatalyst");
     mesh_view = dtkDiscreteGeometry::meshView::pluginFactory().create("dtkMeshViewVTKCatalyst");

 

private plugins

Another usefull functionality that you may need is to use plugins specific for your application: private plugins. In order to use this kind of plugins do the three following steps.

  1. First add a new file dtkTracesPluginsConfig.in in your application plugins source directory as this:
    #pragma once
    #define DTKTRACES_PLUGINS_PATH "@CMAKE_BINARY_DIR@/lib"
    

    As you guessed “@CMAKE_BINARY_DIR@/lib” is the directory where the plugins will be compiled.

  2. Then, edit your CMakeLists.txt to include this config file
    configure_file(plugins/dtkTracesPluginsConfig.in dtkTracesPluginsConfig.h)
  3. To finish, when you initialize your plugins, use this pre-processing variable:
    #include "dtkTracesPluginsConfig.h"
    [...]
    
     dtkDiscreteGeometry::pluginManager::initialize();
     dtkDiscreteGeometry::mesher::pluginManager().initialize(DTKTRACES_PLUGINS_PATH);
     dtkDiscreteGeometry::meshPartitionner::pluginManager().initialize(DTKTRACES_PLUGINS_PATH);
    

About Tristan CABEL

Tristan received an engineer diploma from INSA Rennes in communications network in 2009. In the same year, he began to be interested in HPC and particularly using accelerators to speed-up the computation. Since then, he continued to work in High Performance Computing either as an engineer in research team or as an expert in a national computing center. In 2015, he took a liking in deep learning and self trained himself on it.

Leave a Reply

Your email address will not be published.