ParaView 5.10+ can be downloaded from here.
ParaView comes with its own Python, which may be missing some dependencies for the desired usage. We can add more Python packages into ParaView by creating a virtual environment and then activating it inside the application using the import line
import paraview.web.venv or by using our local version and importing it.
First, we need to setup the ParaView add-on python environment, in which we will only install trame, but we could add any other Python libraries that are not included in the ParaView bundle.
python3.9 -m venv .pvenv
- We can not use our virtual environment with a
vtklibrary will conflict with the one inside Paraview.
- Since ParaView includes
vtk, any VTK example can be run with ParaView assuming the proper code is used to handle the virtual-env loading to get trame inside our Python script.
- The python you use for creating your virtual-environment must match the Python version that comes with ParaView. (So far 5.10 and 5.11 use Python 3.9)
Conda provide many open-source packages and ParaView is part of their offering. When using the conda approach you won’t need to download ParaView as it will get installed by conda for you. That way you can create a virtual-environment that can contain both ParaView and trame by doing the following.
conda create -n pv-env -c conda-forge paraview
Then later you can simply use python rather than pvpython
conda activate pv-env
Making trame available in ParaView
At the very top of our scripts, we need to import our helper script so the
--venv path/to/venv can be processed.
import paraview.web.venv # When using downloaded ParaView from Kitware
After that we can import trame and start using it (assuming we run our application with the
--venv /path/to/venv/with/trame argument).
Running an example
The command line below illustrate how a SimpleCone example can be run on a Mac computer where ParaView 5.10 has been installed.
Understanding this ParaView example
ParaView use proxies which abstracts the VTK object handling so they can be easily distributed to support the processing of very large datasets.
For simplified usage, ParaView provides a
simple package that lets us simply create and interact with these proxies. The
SimpleCone.py example provides the core concepts needed to understand how to work with ParaView.
from paraview import simple
With these three lines, we create a full pipeline and a view. Now, we can use trame to show that view in the client.
from trame.html import vuetify, paraview
The rest of the code looks very similar to the VTK Hello trame example, but instead of importing the
vtk module of trame
from trame.html import vuetify, vtk
we import the
from trame.html import vuetify, paraview
Now we can start adding some UI to control some of the parameters that we want to interact with dynamically. Let’s first add a slider to control the resolution of the cone. We need to create a method to react when the
resolution is changed by the slider. In ParaView proxies, object parameters are simple properties that can be get or set in a transparent manner. At this point, we simply need to update the
cone.Resolution and update the view to see the change.
Now, we can extend the UI with a slider on the
DEFAULT_RESOLUTION = 6
With these few lines, we have created a 3D cone, which we can adjust the resolution all leveraging ParaView.
To learn more about ParaView scripting, look into ParaView trace which let you convert your UI interaction into actual Python code that can then be reused in your application.
With the basics in place, we can now dive further in by using some built-in features of ParaView, such as saving and loading a state file. State files are a convenient way of capturing all the settings that were used to generate a visualization with Paraview.
Let’s analyse the example in
./05_paraview/StateLoader.py. The trame core of the example is as follows
The rest of the script we’ve seen before, but we are missing the details of the
load_data() function requires us to code the follow
- Process a
--dataargument that contains the path to the file to load
- Load the provided file path as a state file.
- Create a view element and connect it to the view defined in the state
- Add that view element into the content of our UI
Process CLI argument
The (1) is achieved with the following set of lines. More information on CLI are available here.
parser = trame.get_cli_parser()
Load the state file
To achieve (2) with ParaView the following set of lines are needed. ParaView trace should be able to explain the magic using the UI and looking at the corresponding Python code.
Create and Connect a view element
Then (3) is similarly as before for VTK.
html_view = paraview.VtkRemoteView(view)
Add view element to UI
Finally (4) is achieved with the following set of lines, the same way it was achieved with VTK in trame when switching from remote to local rendering.
That’s it. You now have a ParaView
trame application that let you reproduce complex visualization in a web context.
Running the StateLoader
Your browser should open automatically to