Skip to content

Conversation

@xavArtley
Copy link
Collaborator

@xavArtley xavArtley commented Mar 16, 2019

Panel model for vtk representations

A minimal example is the following
image

Should not work for the moment (need next bokeh version)

TODO:
Add tests
clean api to work with vtk renderers

Examples:

@xavArtley xavArtley added type: enhancement Minor feature or improvement to an existing feature status: paused Paused labels Mar 16, 2019
@xavArtley
Copy link
Collaborator Author

xavArtley commented Mar 16, 2019

Exmaple inspired from :
https://vtk.org/Wiki/VTK/Examples/Python/Cylinder

image

@philippjfr
Copy link
Member

Looks like a great start! Note that I'd expect the Vtk pane to accept Vtk object directly and convert them to a VtkPlot model internally. Generally users should not be creating bokeh models directly since they are not meant to be reused, while a pane can be reused as often as desired.

@xavArtley xavArtley closed this Mar 16, 2019
@xavArtley xavArtley reopened this Mar 16, 2019
Copy link
Member

@jbednar jbednar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm very happy to have VTK support in Panel; that should be very handy. I don't have much opinion about the actual code that interfaces to VTK, other than that there seems to be a lot of it! :-) . And I haven't tested to see how well it works in practice.

@@ -0,0 +1,519 @@
# coding: utf-8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file has quite a bit of code; was it really all developed from scratch for Panel? Or was it adapted from some other starting point? If the latter, probably need to include the license of the original code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code is an adaptation from this Macro
https://raw.githubusercontent.com/Kitware/vtk-js/master/Utilities/ParaView/export-scene-macro.py
It allows to convert a paraview scene to a zip file

Most of developpement are inspired from
https://kitware.github.io/vtk-js/examples/SceneExplorer.html

I'm not very aware about licensing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think you'd need to paste in the license from: https://github.com/Kitware/vtk-js/blob/master/LICENSE

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(And should include the link to the original example, for reference.)

@xavArtley
Copy link
Collaborator Author

xavArtley commented Mar 16, 2019

There are two parts to the vtk panel work:

@xavArtley xavArtley force-pushed the vtk_plot branch 2 times, most recently from 738f980 to 4b3a728 Compare March 16, 2019 19:07
@xavArtley
Copy link
Collaborator Author

xavArtley commented Mar 16, 2019

Now panel are construct using:

import vtk
import panel as pn
pn.extension('vtk')
from vtk.util.colors import tomato

cylinder = vtk.vtkCylinderSource()
cylinder.SetResolution(8)
cylinderMapper = vtk.vtkPolyDataMapper()
cylinderMapper.SetInputConnection(cylinder.GetOutputPort())
cylinderActor = vtk.vtkActor()
cylinderActor.SetMapper(cylinderMapper)
cylinderActor.GetProperty().SetColor(tomato)
cylinderActor.RotateX(30.0)
cylinderActor.RotateY(-45.0)
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
ren.AddActor(cylinderActor)
ren.SetBackground(0.1, 0.2, 0.4)
ren.ResetCamera()
ren.GetActiveCamera().Zoom(1.5)

VTK(renWin)

or

import panel as pn
pn.extension('vtk')
import urllib

data_url = urllib.request.urlopen(r'https://raw.githubusercontent.com/Kitware/vtk-js/master/Data/StanfordDragon.vtkjs')
pn.pane.VTK(data_url)

@philippjfr
Copy link
Member

data_url = urllib.request.urlopen(r'https://raw.githubusercontent.com/Kitware/vtk-js/master/Data/StanfordDragon.vtkjs')

With a file extension as specific as vtkjs I'd be happy for the pane to accept filepaths and URLs which end in .vtkjs and then fetch it internally using requests.

@philippjfr
Copy link
Member

Another question, you say that the data is converted to a zip file stream. Are there any other formats which are potentially more efficient, e.g. could you imagine extracting any binary buffers such as arrays and sending those independently via a ColumnDataSource and then reconstituting it client-side?

@xavArtley
Copy link
Collaborator Author

xavArtley commented Mar 16, 2019

Another question, you say that the data is converted to a zip file stream. Are there any other formats which are potentially more efficient, e.g. could you imagine extracting any binary buffers such as arrays and sending those independently via a ColumnDataSource and then reconstituting it client-side?

Yes I think we could create a scene and add and update actors through this process. But it exceeds my current skills.

Actually it could be something similar of the second part of this gif
vtk_plot.gif

The second object is divided in three parts.
The files are results of a FE simulation and the raw binary vtk where about 100MB each
Each vtkjs file was ~10MB

@philippjfr
Copy link
Member

Yes I think we could create a scene and add and update actors through this process. But it exceeds my current skills.

Okay, once you're finished with this PR, let's just file an issue providing a rough outline of such an approach. Certainly doesn't have to happen in this PR.

@codecov-io
Copy link

codecov-io commented Mar 16, 2019

Codecov Report

Merging #312 into master will decrease coverage by 2.62%.
The diff coverage is 41.09%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #312      +/-   ##
==========================================
- Coverage   89.41%   86.79%   -2.63%     
==========================================
  Files          83       77       -6     
  Lines        6776     7105     +329     
==========================================
+ Hits         6059     6167     +108     
- Misses        717      938     +221
Impacted Files Coverage Δ
panel/config.py 48% <ø> (ø) ⬆️
setup.py 0% <0%> (ø) ⬆️
panel/models/vtk.py 100% <100%> (ø)
panel/pane/__init__.py 100% <100%> (ø) ⬆️
panel/pane/vtk.py 28.61% <28.61%> (ø)
panel/tests/test_vtk.py 96.22% <96.22%> (ø)
panel/tests/test_links.py 97.4% <0%> (-2.6%) ⬇️
panel/links.py 83.92% <0%> (-0.82%) ⬇️
panel/tests/test_param.py 99.66% <0%> (-0.34%) ⬇️
panel/tests/test_layout.py 100% <0%> (ø) ⬆️
... and 30 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 018f1b0...e8626ff. Read the comment docs.

@xavArtley
Copy link
Collaborator Author

image

@philippjfr
Copy link
Member

Resolved the merge conflict I introduced as part of the KaTeX/MathJax PR.

@xavArtley xavArtley force-pushed the vtk_plot branch 2 times, most recently from fbc0236 to d9c393c Compare March 17, 2019 06:58
@xavArtley
Copy link
Collaborator Author

Locally tests passed for me
image

But I don't know what's the error on CI servers

@xavArtley
Copy link
Collaborator Author

xavArtley commented Mar 17, 2019

example reference:
https://lorensen.github.io/VTKExamples/site/Python/
To test and see limits of the panel

@philippjfr
Copy link
Member

It looks like the CI is crashing when the VTK render window is loaded, does that expect a windowing system to exist by any chance?

@xavArtley
Copy link
Collaborator Author

I hope it's not the windowing system system,
I set the off screen mode before rendering
https://github.com/pyviz/panel/blob/717d084f643c3bea933a6cf31e18a9252d854168/panel/pane/vtk.py#L373

@philippjfr
Copy link
Member

I think it is down to missing windowing, I've seen a couple of issues filed by people seeing similar errors despite the fact that they used SetOffScreenRendering.

@philippjfr
Copy link
Member

Okay rebased, just run:

git fetch
git reset origin/vtk_plot --hard

@xavArtley
Copy link
Collaborator Author

xavArtley commented Mar 21, 2019

Linking carmera between views should not be hard if we expose camera settings in vtk model
adding pan on the left click of the mouse seems doable, need to look more in detail of this example
https://kitware.github.io/vtk-js/examples/InteractorStyleManipulator.html
The size of thw widget must be set in VTK panel object

@dharhas
Copy link
Member

dharhas commented Mar 21, 2019

With some experimentation I realized 'shift + left button' pans in the code I pasted.

I was able to set the size on the pane object, i.e. pn.pane.VTK(renWin, height=800, width=800)

Linked camera would be really useful. I have a set of unstructured objects at different mesh resolutions that I want to create a panel dashboard to compare.

@jourdain
Copy link

Guys is awesome and great work!
Sorry I was out in the wild the last couple of days without network or computer so I couldn't provide pointers sooner.

@xavArtley the python serializer that you found is indeed a better approach and will be improved while things progress on our end. It should be paired with the SynchronizedRenderWindow. Right now it is used with wslink (our WebSocket connection to VTK or ParaView backend) but can be adapted to exchange data with whatever communication protocol you would like.

Please find below some links of the usage of it.

Feel free to reach out on the vtk.js bug tracker as well...

@dharhas
Copy link
Member

dharhas commented Mar 22, 2019

So how close is this to being merged? i.e. what is still needed?

@philippjfr
Copy link
Member

It sounds like a lot of the existing serialization code could be swapped out for the code that @jourdain helpfully pointed to. The next release is scheduled for about a week from today, @xavArtley do you think you'll be able to do that swapping before then? If not I'd be okay with merging it using the current serialization approach and filing an issue to swap that out at a later date.

@xavArtley
Copy link
Collaborator Author

Seems unlikely I can pass some times on this PR next week.
I have several work deadline next week

@philippjfr
Copy link
Member

Okay, how would you feel about merging this in its current state (after I've made a quick pass to clean it up), and then improve the serialization in a subsequent PR?

@xavArtley
Copy link
Collaborator Author

xavArtley commented Mar 22, 2019 via email

@xavArtley
Copy link
Collaborator Author

@philippjfr do you know if it is possible in bokehjs to trigger a python function to transfer data from python to javascript?

@philippjfr
Copy link
Member

@philippjfr do you know if it is possible in bokehjs to trigger a python function to transfer data from python to javascript?

Not sure there is a straightforward mechanism particularly on the model itself. You could add a sync boolean property to the model and then subscribe to it on the Pane, because at the model level you don't know whether to sync via a JS callback (which triggers an event python side) or via a bokeh server callback.

@xavArtley
Copy link
Collaborator Author

After passing some times this week end on refactoring serializers, I need more time to reconstruct vtk rendering on the javascript side.
So I think you can merge when you want and we will open another PR to improve it

@philippjfr
Copy link
Member

So I think you can merge when you want and we will open another PR to improve it

Okay, I'll maybe make a pass over it tonight and will merge tomorrow.

@philippjfr
Copy link
Member

Okay, I'll merge this now and let you improve it in a subsequent PR.

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

status: paused Paused type: enhancement Minor feature or improvement to an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants