Kitware / trame

Trame lets you weave various components and technologies into a Web Application solely written in Python.
https://kitware.github.io/trame/
Other
433 stars 57 forks source link

"Text Actors" won't show up in "Local" rendering #608

Open hmralavi opened 1 month ago

hmralavi commented 1 month ago

Describe the bug

Vtk Text Actors won't show up when using "Local" rendering method.

To Reproduce

Steps to reproduce the behavior:

  1. run the python code
  2. switch between "local" and "remote" rendering using the provided switch in the toolbar.
  3. you can see the text actors when "remote" rendering is ON, but they dissapear when switching to "local" rendering.

Code

from trame.app import get_server
from trame.decorators import TrameApp
from trame.widgets import html, vuetify, vtk as trame_vtk_widgets
from trame.ui.vuetify import SinglePageLayout

from vtkmodules.vtkRenderingCore import (
    vtkRenderer,
    vtkRenderWindow,
    vtkRenderWindowInteractor,
    vtkTextActor,
)

from vtkmodules.vtkInteractionStyle import (
    vtkInteractorStyleTrackballActor,
    vtkInteractorStyleTrackballCamera,
)

from vtkmodules.vtkRenderingAnnotation import vtkAxesActor

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

@TrameApp()
class MainApp:
    def __init__(self, server_or_name=None) -> None:
        self.server = get_server(server_or_name, client_type="vue2")
        self.state.trame__title = "Text actor issue"

        self._render_window = self._setup_render_window()
        self._origin_axes_actor = self._setup_origin_axes_actor()
        self._logo_actor = self._setup_text_actor()
        self.renderer.ResetCamera()

        self.ui = self._setup_ui()

    def _setup_render_window(self) -> vtkRenderWindow:
        renderer = vtkRenderer()
        renderWindow = vtkRenderWindow()
        renderWindow.AddRenderer(renderer)
        interactor = vtkRenderWindowInteractor()
        interactor.SetInteractorStyle(vtkInteractorStyleTrackballCamera())
        interactor.SetRenderWindow(renderWindow)

        return renderWindow

    def _setup_origin_axes_actor(self) -> vtkAxesActor:
        axes = vtkAxesActor()
        self.renderer.AddActor(axes)

        return axes

    def _setup_text_actor(self) -> vtkTextActor:
        text_actor = vtkTextActor()
        text_actor.SetInput("My Text")
        text_actor.GetTextProperty().SetFontSize(24)
        text_actor.GetTextProperty().BoldOn()
        text_actor.GetTextProperty().SetColor(1.0, 0.0, 0.0)
        text_actor.SetPosition(10, 10)
        self.renderer.AddActor(text_actor)

        return text_actor

    def _setup_ui(self):
        with SinglePageLayout(self.server) as layout:
            layout.title.set_text("Text actor issue")
            with layout.toolbar as toolbar:
                toolbar.dense = True
                vuetify.VSpacer()
                html.Div("Switch between remote/local rendering: ")
                vuetify.VCheckbox(
                    v_model=("viewMode", "local"),
                    on_icon="mdi-lan-disconnect",
                    off_icon="mdi-lan-connect",
                    true_value="local",
                    false_value="remote",
                    classes="mx-1",
                    hide_details=True,
                    dense=True,
                )
                vuetify.VSpacer()
                with vuetify.VBtn(icon=True, click=self.ctrl.view_reset_camera):
                    vuetify.VIcon("mdi-crop-free")

            with layout.content:
                with vuetify.VContainer(fluid=True, classes="pa-0 fill-height"):
                    view = trame_vtk_widgets.VtkRemoteLocalView(
                        self._render_window,
                        namespace="view",
                        mode="local",
                        interactive_ratio=1,
                    )
                    self.ctrl.view_update = view.update
                    self.ctrl.view_reset_camera = view.reset_camera
        return layout

    @property
    def ctrl(self):
        return self.server.controller

    @property
    def state(self):
        return self.server.state

    @property
    def renderer(self) -> vtkRenderer:
        return self._render_window.GetRenderers().GetFirstRenderer()

if __name__ == "__main__":
    app = MainApp()
    app.server.start()

Expected behavior

It is expected that the text actors show up in the "local" rendering mode as well as "remote" rendering

Screenshots

image

Platform:

Device:

OS:

Browsers Affected:

jourdain commented 1 month ago

Thanks for the detailed report issue. What you are describing is a known limitation of vtk.js which we are aiming to fix by using WASM. You can see the work progress on that topic here.

hmralavi commented 1 month ago

Thank you Sebastien.

Is there a list of all current known limitations of trame/vtk.js?

jourdain commented 1 month ago

vtk.js mainly focus on vtkPolyData rendering. Anything on the side, may be different or have a mismatch feature set.