`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. Pingback: Theo_Score

    • Pingback: Utkarsh Ayachit

  2. Pingback: Theo_Score

    • Pingback: Scott Wittenburg

      • Pingback: Theo_Score

Questions or comments are always welcome!