Adding Parametric Surfaces to ParaView

April 7, 2016

Introduction

VTK has a collection of parametric surfaces that are both orientable (e.g. Torus) and non-orientable (e.g. Möbius Strip). If you launch ParaView and look in Sources you will see that these surfaces are not there.

This article will show you how to bring these surfaces into ParaView and how to access these surfaces from the Sources menu.

By the end of the article you should be able to load a library of classic parametric surfaces that you can then explore in ParaView.

One of the really nice features of ParaView is its extensibility through the use of plugins. We will take advantage of this by creating Server Manager XML that allows the Parametric Surfaces found in VTK to be loaded into ParaView.

For more background information on writing ParaView plugins, see the ParaView/Plugin HowTo.

To see how ParaView’s Server Manager Plugins work, we will start with a quick example using the Klein Bottle, then demonstrate how to add parameters using Boy’s Surface. Finally we will provide a complete XML file for the VTK Parametric Surfaces.

A quick example

Here is a skeleton file to get you started. This will add an entry called Parametric Surfaces to the Sources drop-down list in ParaView.

<?xml version="1.0" encoding="UTF-8"?>
<ServerManagerConfiguration>
 <ProxyGroup name="parametric_functions">
 <Proxy name="Klein bottle" class="vtkParametricKlein">
 <!-- Any parameters that need to be set go here. -->
 </Proxy>
 </ProxyGroup>

 <ProxyGroup name="sources">
 <SourceProxy name="ParametricSurfaces" class="vtkParametricFunctionSource"
 label="Parametric Surfaces">
 <!-- Any parameters that need to be set go here. -->
 <ProxyProperty
 command="SetParametricFunction"
 name="ParametricFunction"
 label="Parametric Surfaces">
 <ProxyListDomain name="proxy_list">
 <!-- Here we add the surfaces defined in the proxy group called parametric_functions. -->
 <!-- These will appear as a drop-down list in ParaView named "Parametric Surfaces". -->
 <Proxy group="parametric_functions" name="Klein bottle" />
 </ProxyListDomain>
 </ProxyProperty>
 </SourceProxy>
 </ProxyGroup>
</ServerManagerConfiguration>

To use this, download Skeleton and unzip it into a folder.
Now:

  • Open ParaView.
  • Select Tools|Manage Plugins, click on Load New and navigate to where you downloaded this file.
  • You will need to change the file type to Server Manager XML (\*.xml).
  • Select Skeleton.xml and click OK. You should see a plugin called Skeleton, press Close.
  •  Now click on Sources and select Parametric Surfaces.
  • In the Properties tab you will see a drop-down list called Parametric Surfaces with one entry called Klein Bottle.
  • Click Apply and a Klein Bottle will appear.
Klein.png
Klein Bottle

At this point, feel free to experiment with the surface in ParaView. For example, try a Point Gaussian Representation or a Wireframe, this will give you a good idea of the complexity of the surface.

Dealing with Parameters

The Klein bottle really does not have any parameters that need to be set in order to get a good picture. So we will use a different surface, Boy’s Surface, as an example that shows how to incorporate parameters.

Firstly we need to know that the parameters are distributed over two classes:

  1. The vtkParametric<SurfaceName> classes, found in Common/ComputationalGeometry in the VTK source, actually generate the points and derivatives from the parametric equations. These parameters control the mapping of the surface from the u-v space to the x-y-z space.
  2. The second class we need is vtkParametricFunctionSource found in Filters/Sources in the VTK source. This takes the points and derivatives from the parametric surface and triangulates the surface adding in normals. It also adds in some predefined scalars. This is done because, for non-orientable surfaces, it is necessary to generate normals and scalars at this stage since the usual normal generation only works for orientable surfaces.

To illustrate how the classes work together here is a python example called BoysSurface. Unzip this file into a folder. In this file, these lines show how the two classes work together:

    boy = vtk.vtkParametricBoy()
    boy.SetZScale(zScale)
    source = vtk.vtkParametricFunctionSource()
    source.SetParametricFunction(boy)
    source.SetScalarModeToModulus()
    source.Update()

Here we are setting the ZScale in the surface generation and telling vtkParametricFunctionSource to insert a modulus value as a scalar when the points are generated.
When you run this example the initial display should look like this:

Boy's Surface
Boy’s Surface

Now, if you look at Skeleton.xml (above) you will see that there are comments indicating where we set the parameters. Also note the two proxy groups:

  1. In ProxyGroup name=”parametric_functions” we insert proxies for each of the vtk parametric classes along with their parameters.
  2.  In ProxyGroup name=”sources” we define the source proxy corresponding to the class vtkParametricFunctionSource. Within the source proxy we will define any parameters specific to vtkParametricFunctionSource. Additionally there is a ProxyProperty section that lists each of the parametric functions that we need to include, this is done in the ProxyListDomain.

Keeping these points in mind, we modify Skeleton.xml calling it BoysSurface.xml adding in parameters for vtkParametricBoy and vtkParametricFunctionSource. Download and unzip this file BoysSurface.zip.
In this file you will see that we have set a Z-scale for Boy’s Surface and enumerated the scalar modes in ParametricSource.
Once you have downloaded this file, do:

  • Open ParaView.
  • Select Tools|Manage Plugins, and, if it exists, click on Skeleton then click on Remove, then click on Close.
  • Select Tools|Manage Plugins, click on Load New and navigate to where you downloaded this file.
  • You will need to change the file type to Server Manager XML (\*.xml).
  • Select BoysSurface.xml and press OK, you should see a plugin called BoysSurface, press Close.
  • Now click on Sources and select Parametric Surfaces.
  • In the Properties tab you will see a drop-down list called Parametric Surfaces with one entry called Boy’s Surface.
  • Click Apply and Boy’s surface will appear.
ParaView_Boy
Boy’s Surface

Note the following:

  • You can change the resolution for U and V.
  • You can select a scalar mode from a drop down list, currently “None”.
  • You can change the Z Scale, currently 0.125.
  • You can also change the ordering of the triangles … try it and see what happens.
  • Don’t forget to press Apply if you change parameters.

As an exercise, see if you can replicate a similar image to that in the Python example. Additionally, apply the Glyph filter to see where the normals point on the surface.

Hint: Modulus would be a good start for scalar mode, do Apply and then select Scalars in Coloring, then find a suitable color map.

The Complete Implementation

Now that all the hard work has been done … download and unzip ParametricSurfaces into a folder. This file incorporates and extends all that we have learned, allowing you to select any one of the 21 Parametric Surfaces in VTK.

After downloading and unzipping you will have a file called ParametricSurfaces.zip. To use it, follow these instructions:

  • Open ParaView.
  • Select Tools|Manage Plugins, and, if Skeleton and or BoysSurface exist, click on Remove to remove them, then click on Close.
  • Select Tools|Manage Plugins, click on Load New and navigate to where you downloaded this file.
  • You will need to change the file type to Server Manager XML (\*.xml).
  • Select ParametricSurfaces.xml and press OK, you should see a plugin called ParametricSurfaces, press Close.
  • Now click on Sources and select Parametric Surfaces.
  • In the Properties tab you will see a drop-down list called Parametric Surfaces with 21 surfaces listed.
  • Select one, click Apply and the surface will appear.

If you want, you can put this file in bin/plugins in the ParaView directory. If this is done, it will be loaded automatically.

I hope you enjoy exploring these beautiful surfaces using the many features of the ParaView interface. ParaView renderers these surfaces much better than the examples on the web. It is good fun to see if you can emulate what is displayed on the web.

The beauty of Mathematics through ParaView.

 

 

 

Tags:

1 comment to Adding Parametric Surfaces to ParaView

Leave a Reply