Fix scatter3d so it handles updates to positions#484
Conversation
|
|
||
| self._add_point_cloud_to_scene() | ||
|
|
||
| def _make_point_cloud(self) -> None: |
There was a problem hiding this comment.
How long does this take approximately? Is it as fast as updating a 2d plot?
There was a problem hiding this comment.
It depends on the number of points. I did some basic timings: it's about 0.01s for 100_000 points, and ~0.04s for 500_000 points.
But this is only run if the updated values have a different shape than the existing ones, which I am guessing is not super common.
A more relevant question is probably how long does it take to update the positions every time?
We are now running
self.geometry.attributes["position"].array = np.array(
[
self._data.coords[self._x].values.astype('float32'),
self._data.coords[self._y].values.astype('float32'),
self._data.coords[self._z].values.astype('float32'),
]
).Ton every update, which is potentially quite a large allocation?
Before, we only have one array of floats for the colors, now we have 4 (colors + 3 positions).
We could only update if the coords have changed, but we would have to check something like
if any(not sc.identical(old_coords[dim], self._data.coords[dim]) for dim in "xyz"):I need to check the timings of such a check, maybe it's fast enough?
There was a problem hiding this comment.
Yes, check it before you optimise too much! 0.04s seems fine. I don't think anyone expects 60fps.
Just a guess, but maybe you can make the big allocation slightly cheaper by using np.stack or any of its variants instead of np.array([..]).T.
There was a problem hiding this comment.
The check can actually be pretty fast (10x or more) compared to setting the position, so I added it in.
| self._update_colors() | ||
|
|
||
| if need_new_point_cloud: | ||
| self._add_point_cloud_to_scene() |
There was a problem hiding this comment.
Do you have to remove the old cloud?
There was a problem hiding this comment.
This is done above on L111, but maybe it makes more sense to do it here... and remove of the if self.points is not None
Co-authored-by: Jan-Lukas Wynen <jan-lukas.wynen@ess.eu>
|
@jl-wynen this is now ready for another look. The logic is probably not super easy to follow from the diff, so we can do a run-through if you'd like that. |
|
Hold on, there are some issues with the 3d clipping... |
…ly adding and removing them
|
I need to investigate further. The performance impact of changes here is very noticeable on e.g. the DREAM instrument view... |
Like the 2d scatter plots, the 3d scatter plot will now handle updates to the data that have a different number of points.
If this is the case, we have to remove the point cloud and add a new one to the scene.