ParaView:Extend: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
No edit summary
(Change SetInput to SetInputConnection)
Line 26: Line 26:
           <ProxyGroupDomain name="groups">
           <ProxyGroupDomain name="groups">
             <Group name="sources"/>
             <Group name="sources"/>

Revision as of 18:52, 30 January 2007


There are several ways to extend ParaView's capabilities:

  • Enable existing VTK reader, writer, source, or algorithm.
  • Include new reader, writer, source, or algorightm during compile time
  • Include new reader, writer, source, or algorightm during run time
  • Include arbitrary new code during compile time
  • Include arbitrary new code during run time
  • Include ParaView in some other project

Enable Existing VTK Class

Let say we require a class in ParaView that already exists in VTK, but is not available in the ParaView GUI. To enable this filter we need to provide two XML files. One describes the use of class in the ParaView server manager, while the other describes the properties GUI. Let take as an example vtkCellDerivatives.

The first part is the server manager XML which we will call vtkCellDerivatives.pvsm:

  <ProxyGroup name="filters">
   <SourceProxy name="CellDerivatives" class="vtkCellDerivatives">
          <ProxyGroupDomain name="groups">
            <Group name="sources"/>
            <Group name="filters"/>
          <DataTypeDomain name="input_type">
            <DataType value="vtkDataSet"/>

        default_values="0" >
       <EnumerationDomain name="enum">
         <Entry value="0" text="PassVectors"/>
         <Entry value="1" text="ComputeGradient"/>
         <Entry value="2" text="ComputeVorticity"/>
   <!-- End CellDerivatives -->

For more options to XML, please check the files in ParaView/Servers/ServerManager/Resources.

The second XML is the one that describes the GUI. Let us call it vtkCellDerivatives.xml:

  <ServerManagerFile name="vtkCellDerivatives.pvsm" />
  <Module name="CellDerivatives"
          menu_name="Cell Derivatives"
          long_help="Compute derivatives of scalars and vectors."
          short_help="Compute derivatives of scalars and vectors.">
    <Filter class="vtkCellDerivatives">
      <Input name="Input"
    <InputMenu trace_name="Input" label="Input" property="Input"
               help="Set the input to this filter."
    <SelectionList label="Vector Mode" property="VectorMode"
                   help="Control how the filter works to generate vector cell data.
                         You can choose to pass the input cell vectors, compute the gradient
                         of the input scalars, or extract the vorticity of the computed
                         vector gradient tensor. By default (VectorModeToComputeGradient),
                         the filter will take the gradient of the input scalar data.">
      <Item name="Pass Vectors" value="0"/>
      <Item name="Compute Gradients" value="1"/>
      <Item name="Compute Vorticity" value="2"/>
vtkCellDerivatives is a filter that computes derivatives of scalars
and vectors at the center of cells. You can choose to generate
different output including the scalar gradient (a vector), computed
tensor vorticity (a vector), gradient of input vectors (a tensor),
and strain matrix of the input vectors (a tensor); or you may
choose to pass data through to the output.

Note that it is assumed that on input scalars and vector point data
is available, which are then used to generate cell vectors and tensors.
(The interpolation functions of the cells are used to compute the
derivatives which is why point data is required.)

Note that this XML refers to the previous one. This is the XML we will import into ParaView. For more GUI options, please check the XML files in ParaView/GUI/Client/Resources.

The XMLs can now be loaded into ParaView GUI using two options:

Load Module Into GUI

To load the XML file into the ParaView, we will go to menu File and select Import Package. This will popup a dialog in which we can select the apropriate XML file. Once we load the XML file, we can use the class in the ParaView.

Load Module Using Environment Variable

If we load custom modules into ParaView frequently, it is cumbersome to import package every single time. To load modules automatically, we set environment variable PV_INTERFACE_PATH to point to the directory that contains XML files with modules. Once ParaView is started, it will load all XML files (with extension .xml) in this directory.

Include Custom Class During Compile Time

Let say we have our file format called MyFancy and we require the reader for it. The file format is something completely new, so we cannot reuse any other class. So we write our own reader and we want to include it into the ParaView. Let say the header file for the reader looks like this:

#ifndef __vtkMyFancyReader_h
#define __vtkMyFancyReader_h

#include "vtkUnstructuredGridAlgorithm.h"


class VTK_EXPORT vtkMyFancyReader : public vtkUnstructuredGridAlgorithm 
  static vtkMyFancyReader *New();
  void PrintSelf(ostream& os, vtkIndent indent);

  // Description:
  // Specify file name of the MyFancy file.

  // Description:
  // Which TimeStep to read.    
  vtkSetMacro(TimeStep, int);
  vtkGetMacro(TimeStep, int);

  vtkGetVector2Macro(TimeStepRange, int);




  vtkMyFancyReader(const vtkMyFancyReader&); // Not implemented
  void operator=(const vtkMyFancyReader&); // Not implemented


To make it work within the ParaView, we need to perform two tasks:

  1. Build the reader as a part of ParaView
  2. Register with the ParaView Server Manager and the GUI

Build Code As Part Of ParaView

The most obvious way to build particular code with the ParaView is to just put it in the ParaView source tree and modify the CMake lists files. The drawbacks of this approach are that we have to now maintain our own modifications to ParaView code, and we cannot use versioning software to maintain the history of our code. Well, at least not without some problems. The solution to this is to import the code to the ParaView build process using ParaView External Modules.

ParaView External Modules are collection of code that are included during the ParaView build process, but reside somewhere outside the ParaView source tree. To generate ParaView External Module, we need to create a file called <Module-Name>ParaViewImport.cmake. Let say our module will be called MYFANCY, so the file needs to be called MYFANCYParaViewImport.cmake. It will look like this:




To load this file into ParaView, we have to run CMake GUI on ParaView and find an advanced option called PARAVIEW_EXTRA_EXTERNAL_MODULE. We should set it to MYFANCY. If it is already set to something, we should add MYFANCY to the list. For example: MYFANCY;ULTRASPECIAL. Once we run the Configure, new option will appear called: PARAVIEW_USE_MYFANCY. To actually include the module, we need to set that option to ON. After running Configure, CMake will attemt to find the MYFANCY source directory. If it cannot find the file MYFANCYParaViewImport.cmake, it will produce an error that the source directory was not found. The CMake variable that specifies location to the module source directory will be called <Module-Name>_SOURCE_DIR. In our case this is MYFANCY_SOURCE_DIR. Note that this is the same variable used in the MYFANCYParaViewImport.cmake file. This variable should be set to the directory containing the MYFANCYParaViewImport.cmake file and not to the actual file.

At this point the ParaView is all set to build. If all the locations are correct and the MYFANCYParaViewImport.cmake file is without errors, the ParaView will be build with the reader included.

Additionally, you can use the following macros:

  • To include a special widget:
  • To incldue Server manager XML:
  • To include GUI Client XML:

Register Code With The ParaView Server Manager And The GUI

Once ParaView is build, we can register our code using instructions in Enable Existing VTK Class.

If we want the code to be permanently available in ParaView after compiling (without having to setup environment variable or loading XML file), we must use PARAVIEW_INCLUDE_SERVERMANAGER_RESOURCES and PARAVIEW_INCLUDE_GUI_RESOURCES macros in the ParaView module import file.

ParaView: [Welcome | Site Map]