plotly / dash-vtk

Bringing vtk.js into Dash and Python
MIT License
120 stars 22 forks source link

Slow mesh state update, lack of access #70

Open m-vik opened 1 year ago

m-vik commented 1 year ago

Description

Hello, I am trying to handle around 100 to 200 GeometryRepresentations in a vtk view. Each representation is defined by around 200 points.

At some point I update the positions/orientations of the representations and generate a new mesh state with the "to_mesh_state" method in a callback.

I found out that the slowest method in the chain is the following and all following methods like GetStrips(): https://github.com/plotly/dash-vtk/blob/d888a15889c8534ef3611cb2950632118cd9f84c/dash_vtk/utils/vtk.py#L98 It is the GetPoints() method, not the vtk_to_numpy or encode method.

A topic which was already discussed here: https://discourse.vtk.org/t/faster-method-for-getpoint/3189 and https://discourse.vtk.org/t/what-is-best-way-to-get-the-highest-point-z-axis-in-a-polydata/1833/5

For one representation it takes around 40-80ms to get the points. When I have many representations, it gets very fast, very slow. Unable to animate anything.

Solution 1: I combine all my polydata into one vtkAppendPolydata and create only one GeometryRepresentation. But then I have no possibility to select individual polydata/representation. If I would have access to the renderer/interactor/picker or at least the cellid within the click callback, then I could manage to get the selected polydata through global ids on vtk side.

Solution 2: More efficient way to transfer the data from vtk to dash? Other method the GetPoints...etc.

Solution 1 seems to me more feasible. Is there a possibility to access the renderer/interactor/picker and/or cellid in the callback?

Thank you very much!

jourdain commented 1 year ago

The data transfer is as efficient as possible with dash. But when you do the picking, you should do the resolution on the server side as the client send you the ray info. Then the lookup on block id or else can then be achieved directly on the server like we do with the F1 example.