fastplotlib / fastplotlib

Next-gen fast plotting library running on WGPU using the pygfx rendering engine
https://fastplotlib.readthedocs.io/
Apache License 2.0
348 stars 33 forks source link

Plot area nearest graphics method #514

Open kushalkolar opened 1 week ago

kushalkolar commented 1 week ago

A method on plot area that returns the nearest n graphics could be useful. Just get world bounding sphere of all graphics and return closest in order.. Will need to see if this is fast enough. We could cache the world bounding spheres and update them whenever graphic data, offset or rotation changes.

kushalkolar commented 1 week ago

If it's slow, we could store the bounding sphere of a graphic when it's added to a PlotArea and update it whenever data, offset, or rotation changes. We could have a config option on each graphic to enable/disable this because updating all these could be slow if for example the data of a line collection is being constantly changed in a live data stream.

clewis7 commented 1 day ago

the nearest graphics relative to what?

clewis7 commented 1 day ago

I think we should provide option for "edge" vs "center" and choose one as the default (prob "center" imo)

kushalkolar commented 1 day ago

the nearest graphics relative to what?

to a passed point in world space

idea of current signature:

    def get_nearest_graphics(
        self,
        pos: tuple[float, float, float],
        n_graphics: int = None,
        method: str = "center",
        subset: tuple[Graphic] = None,
    ) -> tuple[Graphic]:
        """
        Returns the nearest ``n_graphics`` to the passed position ``pos`` in world space

        Parameters
        ----------
        pos: (x, y, z)
            position in world space, not data space

        n_graphics: int | None
            nearest number of graphics to return, if ``None`` returns all graphics

        method: "center" | "edge"
            determine the nearest objects using the "center" of graphics or the "edge"

        Returns
        -------
        tuple[Graphic]
            nearest graphics to ``pos`` in order

        """

        pass