Skip to content

Commit

Permalink
docs(examples): Add docker remote rendering example
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Apr 13, 2023
1 parent fbaffe3 commit 7a847a0
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 4 deletions.
1 change: 1 addition & 0 deletions examples/00_howdoi/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
DEFAULT_VALUE = 5
state.trame_title = "Counter"


# Updates
def increment():
state.my_number += 1
Expand Down
1 change: 0 additions & 1 deletion examples/02_vuetify/00_dataframe-table.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def fetch_data(samples=15):

@state.change("selection")
def selection_change(selection=[], **kwargs):

global DATA_FRAME
selected_df = pd.DataFrame(selection)

Expand Down
1 change: 0 additions & 1 deletion examples/06_vtk/Applications/SurfacePicking/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ def update_tooltip(pickData, pixel_ratio, **kwargs):
xyx = data["worldPosition"]
idx = f1_mesh.FindPoint(xyx)
if idx > -1:

messages = []
cone_state = {
"resolution": 12,
Expand Down
5 changes: 5 additions & 0 deletions examples/deploy/docker/VtkRendering/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM kitware/trame

COPY --chown=trame-user:trame-user . /deploy

RUN /opt/trame/entrypoint.sh build
31 changes: 31 additions & 0 deletions examples/deploy/docker/VtkRendering/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Disclaimer

The current example rely on OSMesa for doing remote rendering but for good rendering performance
using the nvidia-runtime with __kitware/trame:glvnd__ base image and an EGL build of VTK would be preferred.

# Build the image

```bash
docker build -t trame-vtk-app .
```

# Run the image on port 8080

```bash
docker run -it --rm -p 8080:80 trame-vtk-app
```

# Deploying into CapRover

If that directory was at the root of a git repo you could run the following command line

```bash
caprover deploy
```

That app could also be deployed by running the following set of commands

```bash
tar -cvf trame-vtk-app.tar captain-definition Dockerfile app.py setup
caprover deploy -t trame-vtk-app.tar
```
102 changes: 102 additions & 0 deletions examples/deploy/docker/VtkRendering/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
from trame.app import get_server
from trame.widgets import vuetify, vtk as vtk_widgets
from trame.ui.vuetify import SinglePageLayout

from vtkmodules.vtkFiltersSources import vtkConeSource
from vtkmodules.vtkRenderingCore import (
vtkRenderer,
vtkRenderWindow,
vtkRenderWindowInteractor,
vtkPolyDataMapper,
vtkActor,
)

# VTK factory initialization
from vtkmodules.vtkInteractionStyle import vtkInteractorStyleSwitch # noqa
import vtkmodules.vtkRenderingOpenGL2 # noqa

# -----------------------------------------------------------------------------
# Trame initialization
# -----------------------------------------------------------------------------

server = get_server()
state, ctrl = server.state, server.controller

state.trame__title = "VTK Remote rendering"

# -----------------------------------------------------------------------------
# VTK code
# -----------------------------------------------------------------------------

DEFAULT_RESOLUTION = 6

renderer = vtkRenderer()
renderWindow = vtkRenderWindow()
renderWindow.AddRenderer(renderer)
renderWindow.OffScreenRenderingOn()

renderWindowInteractor = vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)
renderWindowInteractor.GetInteractorStyle().SetCurrentStyleToTrackballCamera()

cone_source = vtkConeSource()
mapper = vtkPolyDataMapper()
actor = vtkActor()
mapper.SetInputConnection(cone_source.GetOutputPort())
actor.SetMapper(mapper)
renderer.AddActor(actor)
renderer.ResetCamera()
renderWindow.Render()


@state.change("resolution")
def update_cone(resolution=DEFAULT_RESOLUTION, **kwargs):
cone_source.SetResolution(resolution)
ctrl.view_update()


def update_reset_resolution():
state.resolution = DEFAULT_RESOLUTION


# -----------------------------------------------------------------------------
# GUI
# -----------------------------------------------------------------------------

with SinglePageLayout(server) as layout:
layout.icon.click = ctrl.view_reset_camera
layout.title.set_text("Cone Application")

with layout.toolbar:
vuetify.VSpacer()
vuetify.VSlider(
v_model=("resolution", DEFAULT_RESOLUTION),
min=3,
max=60,
step=1,
hide_details=True,
dense=True,
style="max-width: 300px",
)
vuetify.VDivider(vertical=True, classes="mx-2")
with vuetify.VBtn(icon=True, click=update_reset_resolution):
vuetify.VIcon("mdi-undo-variant")

with layout.content:
with vuetify.VContainer(
fluid=True,
classes="pa-0 fill-height",
):
view = vtk_widgets.VtkRemoteView(
renderWindow,
ref="view",
)
ctrl.view_update = view.update
ctrl.view_reset_camera = view.reset_camera

# -----------------------------------------------------------------------------
# Main
# -----------------------------------------------------------------------------

if __name__ == "__main__":
server.start()
4 changes: 4 additions & 0 deletions examples/deploy/docker/VtkRendering/captain-definition
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"schemaVersion": 2,
"dockerfilePath": "./Dockerfile"
}
11 changes: 11 additions & 0 deletions examples/deploy/docker/VtkRendering/setup/apps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
trame:
cmd:
- python
- /deploy/app.py
- --host
- ${host}
- --port
- ${port}
- --authKey
- ${secret}
- --server
2 changes: 2 additions & 0 deletions examples/deploy/docker/VtkRendering/setup/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
trame
--find-links wheels.vtk.org vtk-osmesa
1 change: 1 addition & 0 deletions examples/validation/core/00_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# -----------------------------------------------------------------------------
layout = DivLayout(server)


# UI helper to extent layout
def create_variable_editor(name):
with layout:
Expand Down
1 change: 1 addition & 0 deletions examples/validation/core/01_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def update_variable(var_name="a", delta=+1):
with layout:
trame.LifeCycleMonitor()


# UI helper to extent layout
def create_variable_editor(name):
with layout:
Expand Down
1 change: 1 addition & 0 deletions examples/validation/core/17_hot_reload.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
html.initialize(server)
vuetify.initialize(server)


# -----------------------------------------------------------------------------
# Dynamically modify any `ChangeMe` to see the new code execute while
# interacting with the app.
Expand Down
1 change: 0 additions & 1 deletion examples/validation/core/21_file_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def open_directory():
layout = SinglePageLayout(server)

with layout:

# Toolbar
with layout.toolbar as toolbar:
toolbar.clear()
Expand Down
1 change: 0 additions & 1 deletion examples/validation/core/26_vtk_swap_view_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ async def refresh_function(**kwargs):


with VAppLayout(server) as layout:

with layout.root:
with vuetify.VContainer(fluid=True, classes="pa-0 fill-height"):
view = vtk.VtkRemoteView(cone_window)
Expand Down

0 comments on commit 7a847a0

Please sign in to comment.