Appearance
Running a ParaView visualization
With ParaView things are different as ParaView is not available via pip install
. Technically it is available via conda and can be used as such, but for this hands-on we will be using ParaView downloaded from Kitware Website.
Steps needed
- Download ParaView 5.13.3 or newer for your system.
- Create a new virtual environment compatible with the downloaded ParaView.
- Install the trame pieces that you need.
- Run pvpython with the
--venv
argument so the trame import could be resolved.
Exact command lines and steps
Based on which version of ParaView you've downloaded you will have to create a virtual environment with either python 3.10 or 3.12.
bash
uv venv -p 3.10 .pv-venv
bash
# Activate venv
source .pv-venv/bin/activate
# Install dependencies
uv pip install trame trame-vuetify trame-vtk
py
from paraview import simple
from trame.app import get_server
from trame.ui.vuetify3 import SinglePageLayout
from trame.widgets import vuetify3 as v3, paraview as pvw
from trame.decorators import TrameApp, change
@TrameApp()
class PVApp:
def __init__(self, server=None):
self.server = get_server(server)
# ParaView
self.cone = simple.Cone()
self.representation = simple.Show()
self.view = simple.Render()
# GUI
self._build_ui()
@property
def ctrl(self):
return self.server.controller
@change("resolution")
def on_change(self, resolution, **_):
self.cone.Resolution = resolution
self.ctrl.view_update()
def _build_ui(self):
with SinglePageLayout(self.server, full_height=True) as layout:
with layout.toolbar as tb:
tb.density = "compact"
v3.VSpacer()
v3.VSlider(
v_model=("resolution", 6),
min=3,
max=60,
step=1,
density="compact",
hide_details=True,
classes="mx-4",
)
v3.VBtn(
icon="mdi-crop-free",
click=self.ctrl.view_reset_camera,
)
with layout.content:
with v3.VContainer(fluid=True, classes="ma-0 pa-0 h-100"):
with pvw.VtkRemoteView(self.view, interactive_ratio=1) as view:
self.ctrl.view_update = view.update
self.ctrl.view_reset_camera = view.reset_camera
if __name__ == "__main__":
app = PVApp()
app.server.start()
python
# shortcut to pvpython
export PVPYTHON=/Applications/ParaView-5.13.3.app/Contents/bin/pvpython
# Run from repo
$PVPYTHON --venv .pv-venv ./code/04-visualization-3d/05-paraview-cone.py