Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VTK - vtkmodules - VTK pane does not support objects of type 'vtkWin32OpenGLRenderWindow' #1401

Closed
GilShoshan94 opened this issue Jun 11, 2020 · 1 comment · Fixed by #1406

Comments

@GilShoshan94
Copy link

Hi,
Thank you for Panel and Holoviz in general. Amazing work !

1

I am developing in vscode, I am building a custom objects defined using the vtk Python library.
The issue is that I don't get any autocomplete suggestions nor types nor documentation when I am importing vtk (import vtk), neither with Jedi nor Microsoft language server.

I understood from VTK forums that it's because of the way they wrap and import it. I also found that VTK developed a package in vtk called vtkmodules (at least since Jan 19, https://blog.kitware.com/vtk-8-2-0/)
and by doing import vtkmodules.all as vtk I get the same results than import vtk but now all the rich features (autocomplete, docs ...) work !
From what I tested, all pure VTK examples (no Panel) works as well.

It is clearly easier to work with vtkmodules.all than vtk but the problem is that Panel throw me error (and not a logical one since the type is the same with either vtk and vtkmodules.all).

While this is not a critical bug as the workaround is pretty easy (develop with import vtkmodules.all as vtk, than replace with import vtk when using panel), it would be nice to fix it if possible.


2

Also another strange bug occurs to me with this same very example.
When I use the working import vtk, if I generate vtk_pane = pn.pane.VTK(ren_win) but don't deployed it with show() and than try to initiate a VTK windows with the same ren_win, renderWindowInteractor.Start(), the script froze, like it's trapped in an infinite loop/wait.... I would expect an error message, but that's on VTK team I think. But maybe Panel should use a copy of the renderWindow object ? Or mention it in the guide. Can you explain why it behaves like that ?

ALL software version info

IDE - Visual Studio Code
OS - Windows 10 Pro (64-bit) version 1909
browser - Chrome Version 83.0.4103.97 (Official Build) (64-bit)
I use a conda environment, python 3.8, here bellow the relevant libraries (if needed I can give all of them with conda list)

Name Version Build Channel
bokeh 2.0.1 py38h32f6830_0 conda-forge
colorcet 2.0.1 py_0 conda-forge
dask 2.18.1 py_0 conda-forge
dask-core 2.18.1 py_0 conda-forge
datashader 0.10.0 py_0 conda-forge
datashape 0.5.4 py_1 conda-forge
holoviews 1.13.2 pyh9f0ad1d_0 conda-forge
hvplot 0.6.0 pyh9f0ad1d_0 conda-forge
json5 0.9.4 pyh9f0ad1d_0 conda-forge
jsoncpp 1.8.4 h1ad3211_1002 conda-forge
jsonschema 3.2.0 py38h32f6830_1 conda-forge
numba 0.49.1 py38he6e81aa_0 conda-forge
numpy 1.17.5 py38hc71023c_0 conda-forge
pandas 1.0.4 py38he6e81aa_0 conda-forge
panel 0.9.5 py_1 conda-forge
param 1.9.3 py_0 conda-forge
python 3.8.3 cpython_h5fd99cc_0 conda-forge
pyviz_comms 0.7.5 pyh9f0ad1d_0 conda-forge
streamz 0.5.3 pyh9f0ad1d_0 conda-forge
tornado 6.0.4 py38hfa6e2cd_0 conda-forge
vtk 9.0.0 no_osmesa_py38hc3221c0_101 conda-forge

Description of expected behavior and the observed behavior

- Expected behavior:

import vtkmodules.all as vtk should work as well as with import vtk

- Observed behavior:

With import vtk it works, no error.
With import vtkmodules.all as vtk it fails : ValueError: VTK pane does not support objects of type 'vtkWin32OpenGLRenderWindow'.

I checked and the type of the RenderWindow I passed to panel in the import vtk version is also 'vtkWin32OpenGLRenderWindow' .... So I don't understand why it fails.

Complete, minimal, self-contained example code that reproduces the issue

# fmt: off
## The 3 followings line are a temporary solution until I upgrate to bokeh 2.0.2 (now it's 2.0.1) and won't be necessary later
from bokeh.settings import settings  # noqa isort:skip
settings.resources = 'cdn'  # noqa isort:skip
settings.resources = 'inline'  # noqa isort:skip
# fmt: on

import panel as pn
import vtkmodules.all as vtk

# import vtk

arrow_source = vtk.vtkArrowSource()  # The shaft base is always at (0,0,0). The arrow tip is always at (1,0,0)

arrow_mapper = vtk.vtkPolyDataMapper()
arrow_mapper.SetInputConnection(arrow_source.GetOutputPort())

arrow_actor = vtk.vtkActor()
arrow_actor.SetMapper(arrow_mapper)

ren = vtk.vtkRenderer()
ren_win = vtk.vtkRenderWindow()
ren_win.AddRenderer(ren)

ren.AddActor(arrow_actor)
ren.SetBackground(0.15, 0.2, 0.22)

print(type(ren_win))  # Always return 'vtkmodules.vtkRenderingOpenGL2.vtkWin32OpenGLRenderWindow'

# Test Panel - Works with vtk but fails with vtkmodules.all
vtk_pane = pn.pane.VTK(
    ren_win,
    width=900,
    height=900,
    enable_keybindings=True,
    orientation_widget=True,
)
vtk_pane.show()

# Test VTK - Works with both vtk and vtkmodules.all
# renderWindowInteractor = vtk.vtkRenderWindowInteractor()
# renderWindowInteractor.SetRenderWindow(ren_win)
# ren_win.Render()
# renderWindowInteractor.Start()

For problem 2 comment vtk_pane.show() and uncomment the rest like that:

# Test Panel - Works with vtk but fails with vtkmodules.all
vtk_pane = pn.pane.VTK(
    ren_win,
    width=900,
    height=900,
    enable_keybindings=True,
    orientation_widget=True,
    # serialize_on_instantiation=True,
)
# vtk_pane.show()

# Test VTK - Works with both vtk and vtkmodules.all
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(ren_win)
ren_win.Render()
renderWindowInteractor.Start()

Stack traceback and/or browser JavaScript console output

Here the Traceback:
Traceback (most recent call last):
File "c:/.../dashboard/vtest.py", line 127, in
     a.get_pane().show()
File "c:/.../dashboard/vtest.py", line 104, in get_pane
     self.vtk_pane = pn.pane.VTK(
File "C:\ProgramData\Anaconda3\envs\forge\lib\site-packages\panel\pane\vtk\vtk.py", line 341, in init
     super(VTK, self).init(object, **params)
File "C:...\panel\pane\base.py", line 109, in init
     self._type_error(object)
File "C:...\panel\pane\base.py", line 118, in _type_error
     raise ValueError("%s pane does not support objects of type '%s'." %
ValueError: VTK pane does not support objects of type 'vtkWin32OpenGLRenderWindow'.`

Screenshots or screencasts of the bug in action

I don't have a screenshot of the bug but I can show the difference between vtk and vtkmodules.all :

With vtkmodules.all
image

With vtk
image

@GilShoshan94
Copy link
Author

Thank you !!!! You guys rock !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant