Skip to content

Writing your first Plugin

JulianThijssen edited this page Sep 5, 2023 · 10 revisions

In order to extend the functionality of the ManiVault system, it is possible to write your own plug-ins and add them to the system. The first step to doing so would be to decide what kind of plug-in you want to write. There are five possible types of plug-ins:

View Plugin

A View Plugin is specifically targeted at visualization of some data. Examples of such plugins would be:

  • A scatter plot
  • An image viewer
  • A 3D volume viewer
  • A chart or histogram

An example of how to write a View Plugin is given here: https://github.com/ManiVaultStudio/ExamplePlugins/tree/master/ExampleView

Analysis Plugin

An Analysis Plugin is used for controlled computations. These plugins have no direct visual output (although their output can be visualized with a View Plugin), but are purely concerned with transformation of input data or generation of new data. Examples of such plugins would be:

  • Generating a t-SNE embedding from input data
  • Computing clusters of data
  • Generating random points
  • Subsampling input data

An example of how to write an Analysis Plugin is given here: https://github.com/ManiVaultStudio/ExamplePlugins/tree/master/ExampleAnalysis

Data Plug-in

A Data Plugin provides a raw data store and a view on this data. It defines a type derived from RawData which contains the actual data. In addition it defines a type derived from Set which provides an indexed subset of the data and is what gets passed to all interested plugins.

Examples of data plugins would be:

  • Point data
  • Image data
  • Volume data

An example of how to write a Data Plugin is given here: https://github.com/ManiVaultStudio/ExamplePlugins/tree/master/ExampleData

Be aware that in most cases it will not be necessary to write a Data Plugin. Many types of data can be stored as Point Data which is available by default in the library.

Loader Plug-in

A Loader Plugin is used for loading data into the system. It automatically gets added to the menu options and once triggered will launch the logic defined in the plugin for loading the appropriate data. Typical implementations launch a file explorer window to select the file the user wants to load, then processes it to be in the desired format and passes the data to the core system where it is stored in the central data manager.

Examples of loader plugins would be:

  • A CSV loader
  • An image loader
  • A binary file loader

An example of how to write a Loader Plugin is given here: https://github.com/ManiVaultStudio/ExamplePlugins/tree/master/ExampleLoader

Writer Plug-in

A Writer Plugin is used for writing data from the system to disk. It automatically gets added to the menu options and once triggered will launch the logic defined in the plugin for writing the data. Typical implementations launch a file explorer window to decide under which file name and where the data will be saved, then prepares the data into the desired output format and saves it to disk.

Examples of writer plugins would be:

  • A CSV writer
  • An image writer
  • A binary file writer

An example of how to write a Writer Plugin is given here: https://github.com/ManiVaultStudio/ExamplePlugins/tree/master/ExampleWriter

Setting up the plugin

The easiest way to set up your new plugin is to build on one of the example projects listed above. Each of these projects contains a main plugin class, which extends from one of the base plugin classes (ViewPlugin, AnalysisPlugin, etc.). In addition, a plugin factory is defined which is reponsible for initializing the plugin itself.

Dealing with persistent plugin settings

The preferred way of saving/restoring persistent plugin settings is to call hdps::Plugin::setSetting(const QString& path, const QVariant& value) and hdps::Plugin::getSetting(const QString& path, const QVariant& defaultValue = QVariant()) from the plugin base class (see examples below). The path variable represents the location of the setting (setting groups are established using forward slashes).

Examples

plugin->setSetting("General/Computation/NumberOfIterations", 32)

const auto numberOfIterations= plugin->getSetting("General/Computation/NumberOfIterations").toInt()

Clone this wiki locally