-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(examples): Add docker remote rendering example
- Loading branch information
Showing
14 changed files
with
159 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
DEFAULT_VALUE = 5 | ||
state.trame_title = "Counter" | ||
|
||
|
||
# Updates | ||
def increment(): | ||
state.my_number += 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"schemaVersion": 2, | ||
"dockerfilePath": "./Dockerfile" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
trame | ||
--find-links wheels.vtk.org vtk-osmesa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters