## Pinned Update #1

The Darc Library (C++) is now updated as of March, 2012. Click ▷here too browse the entire solution.

## Monday, March 28, 2011

### ParaView Plugins

Today, I'm going to show you how to compile your own plugins for ParaView 3.8.0 on Windows using CMake 2.8.4, QT 4.6.3 and Visual Studio 2008. Other combinations may work as well but I cannot guarantee that, therefore I suggest you stick to the ones I used.

CMake

Before you can generate your Visual Studio project you will have to prepare a bunch of files in order to tell the plugin how it's supposed to interact with ParaView. Put the files in the same folder. The most important one is CMakeLists.txt which can look like this.

:: CMAKE BLOCK ::
cmake_minimum_required(VERSION 2.6)

PROJECT(MyTestFilter)

FIND_PACKAGE(ParaView REQUIRED)
INCLUDE(\${PARAVIEW_USE_FILE})

MyTestFilterSMPlugin
"1.0"
SERVER_MANAGER_XML MyTestFilter.xml
SERVER_MANAGER_SOURCES vtkMyTestFilter.cxx
GUI_RESOURCE_FILES MyTestFilterGUI.xml
)

CMakeLists.txt

This tells CMake that we're about to create a plugin with the name MyTestFilterSMPlugin, Version 1.0, and using the respective Server Manager (Configuration), source (VTK code) and GUI files. The filenames are case sensitive here. Now lets take a look at the other 3 files.

Server Manager Configuration

:: XML BLOCK ::
<ServerManagerConfiguration>

<ProxyGroup name="filters">
<SourceProxy name="MyTestFilter"
class="vtkMyTestFilter">

<InputProperty
name="Input"
command="SetInputConnection">

<ProxyGroupDomain name="groups">
<Group name="sources"/>
<Group name="filters"/>
</ProxyGroupDomain>

<DataTypeDomain name="input_type">
<DataType value="vtkPolyData"/>
</DataTypeDomain>
</InputProperty>

</SourceProxy>
</ProxyGroup>

</ServerManagerConfiguration>

MyTestFilter.xml

This example shows the server manager configuration for a filter plugin, that takes ▷vtkPolyData as input. Depending on the implementation of your plugin these attributes can change. For example you can specify multiple outputs or different input types like String, Vector or ComboBox even without using QT.

GUI Resource File

Finally you need to tell the plugin where it's supposed to be located once loaded into ParaView. Using the resource file you can specify the name and the category of the plugin. The following example will put the filter in the Extensions group, however it will be grayed out unless you select a valid ▷vtkPolyData object as input.

:: XML BLOCK ::
<ParaViewFilters>
<Filter name="MyTestFilter" />
</Category>
</ParaViewFilters>

MyTestFilerGUI.xml

So much for the setup files. Of course CMake is going to ask for a code file to generate the project from so let's take a quick look at that.

VTK Code

So this is where the real fun starts. Every ParaView plugin must be implemented as an extended ▷vtkAlgorithm since it must be usable within the VTK pipeline. The VTK class (and only this class!) should have the prefix vtk. I dont know whether this is mandatory but for some reason this convention avoids many nasty bugs.

This is the header file for a simple filter plugin that processes ▷vtkPolyData. Note that the input type must match the extended class. You might want to take a look at the VTK ▷documentation at this point.

:: XML BLOCK ::
#ifndef _vtkMyTestFilter_h
#define _vtkMyTestFilter_h

#include "vtkPolyDataAlgorithm.h"

class VTK_EXPORT vtkMyTestFilter :
public vtkPolyDataAlgorithm
{
public:
static vtkMyTestFilter *New();
vtkTypeRevisionMacro(vtkMyTestFilter,vtkPolyDataAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);

int RequestInformation([...]);
int RequestData([...]);
int FillInputPortInformation([...]);
int FillOutputPortInformation([...]);

protected:
vtkMyTestFilter();
~vtkMyTestFilter();

private:
vtkMyTestFilter(const vtkMyTestFilter&);
void operator = (const vtkMyTestFilter&);
};

#endif

vtkMyTestFilter.h

Despite the confusing details the general setup is rather simple. The plugin sets the number of input and output ports and the respective data types. This is important because other plugins will only work (connect to the pipeline) if the data types match.

The next function is the core of the algorithm. This is where all the data processing is to be implemented. In case of our simple test plugin the most basic implementation would look something like this. The filter takes the input and passes it on to the output without doing anything.

:: CODE BLOCK ::
int vtkMyTestFilter::RequestData([...])
{
vtkPolyData *input = vtkPolyData::GetData([...]);
vtkPolyData *output = vtkPolyData::GetData([...]);

output->CopyStructure(input);

return 1;
}

int RequestData([...]);

That's it. Put all the files in the same folder, fire up CMake, select the Paraview Development directory and QT and you're done. When you start the Visual Studio project, set it to "Release" mode and compile the DLL. In case of linker errors check the settings for the correct library paths (especially QT) and remove the Python stuff. That did the trick in my case.