`import vtk` or `import paraview.vtk`

Any ParaView user (and developer) that is writing Python scripts in ParaView for data processing i.e. for use in Programmable Source or Programmable Filter, will soon notice that there are two ways of importing the vtk package:

In both cases, the vtk package has similar submodules eg. vtk.vtkCommonCorevtk.vtkCommonDataModel etc. What’s different is which modules are loaded and hence what classes are available within the vtk package itself. To clarify things, let’s look at a simple example:

however the following doesn’t:

To get to ‘vtkSphereSource’ from ‘paraview.vtk’, you can use the following syntax:

Thus, you have to explicitly import the class from the module in which it’s defined.

Now you may be wondering: why this complication?

Simple: since most ParaView programmable filter developers won’t use most of VTK’s Python modules, importing all of them is not only wasteful but also can slow things down considerably, especially when running on large number of MPI ranks in parallel on shared file system.

5 Responses to `import vtk` or `import paraview.vtk`

  1. Theo_Score says:

    PointSprite plugin seem not working or available on Version 5.0.0, any idea?

  2. Theo_Score says:

    Thank you for the link, that was helpful. I am wondering how do I represent particles with different sizes. With Point Sprite, we had Scale by (radius) >> Edit Radius Transfer Function >> Free Form >> Proportional >> Multiplier = 1 and we will have the particles given in a size range. With the Point Gaussian, I only see Gaussian Radius which specifies a constant radius.

    • Scott Wittenburg says:

      Once you have chosen the PointGaussian representation, you will find the options “Use Scale Array”, “Gaussian Scale Array”, and “Scale Transfer Function” under the “Point Gaussian” section of the Properties panel. However, to see all these options, you must turn on the advanced properties by clicking the cog icon near the top of the properties panel.

      If you check the “Use Scale Array” checkbox, you can then use the “Gaussian Scale Array” dropdown to choose an array to scale by. You can then also click the “Edit” button next to the “Scale Transfer Function” property, to edit the transfer function, including adjusting the range of the input values. Currently the range is not automatically set according to the array you have chosen, so it’s a good idea to make sure it is set to something reasonable.

      Hope this answers your question.

Questions or comments are always welcome!