Kitware / trame

Trame lets you weave various components and technologies into a Web Application solely written in Python.

Home Page:https://kitware.github.io/trame/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Trame unexpectedly affects the render window and vtkWindowToImageFilter

banesullivan opened this issue · comments

Describe the bug

Trame is doing something to the render window that makes vtkWindowToImageFilter produce incorrect images with repeated patches.

To Reproduce

Slightly modify the examples/validation/core/24_vtk_download_image.py example to use vtkWindowToImageFilter.SetScale to magnify the saved screenshot.

I can only reproduce this when using trame... otherwise vtkWindowToImageFilter works perfectly fine for me. This makes me think that the mechanism for how trame captures a screenshot is altering the render window in an unexpected way.

I ran into this while working on pyvista/pyvista#3897. It seems that when a render window is paired with vtkRemoteView (or vtkRemoteLocalView) these repeated patches occur.

diff --git a/examples/validation/core/24_vtk_download_image.py b/examples/validation/core/24_vtk_download_image.py
index 7ec4605..d55bdbf 100644
--- a/examples/validation/core/24_vtk_download_image.py
+++ b/examples/validation/core/24_vtk_download_image.py
@@ -56,6 +56,7 @@ def update_resolution(resolution, **kwargs):
 def download_screenshot():
     w2if = vtkWindowToImageFilter()
     w2if.SetInput(renderWindow)
+    w2if.SetScale(3)
     w2if.SetInputBufferTypeToRGB()
     w2if.ReadFrontBufferOff()
     #

Expected behavior

The screenshots shouldn't have these repeated patches and don't when using vtkWindowToImageFilter in any other context

Screenshots

vtk

Platform:

Device:

  • Desktop
  • Mobile

OS:

  • Windows
  • MacOS
  • Linux
  • Android
  • iOS

Browsers Affected:

  • Chrome
  • Firefox
  • Microsoft Edge
  • Safari
  • Opera
  • Brave
  • IE 11

Turns out the issue is that EnableRender needs to be on for the interaction.

These changes make it work again:

diff --git a/examples/validation/core/24_vtk_download_image.py b/examples/validation/core/24_vtk_download_image.py
index 7ec4605..e868d36 100644
--- a/examples/validation/core/24_vtk_download_image.py
+++ b/examples/validation/core/24_vtk_download_image.py
@@ -55,7 +55,11 @@ def update_resolution(resolution, **kwargs):
 @ctrl.trigger("download_screenshot")
 def download_screenshot():
     w2if = vtkWindowToImageFilter()
+    status = renderWindow.GetInteractor().GetEnableRender()
+    if not status:
+        renderWindow.GetInteractor().EnableRenderOn()
     w2if.SetInput(renderWindow)
+    w2if.SetScale(3)
     w2if.SetInputBufferTypeToRGB()
     w2if.ReadFrontBufferOff()
     #
@@ -64,6 +68,8 @@ def download_screenshot():
     writer1.SetWriteToMemory(True)
     writer1.Write()
     #
+    if not status:
+        renderWindow.GetInteractor().EnableRenderOff()
     return server.protocol.addAttachment(memoryview(writer1.GetResult()))