-
-
Notifications
You must be signed in to change notification settings - Fork 410
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix lagging 3d view for big data in auto color mode (#6411)
# References and relevant issues closes #6397 # Description This array fixes fps performance issues in OpenGL introduced by #3308. In that PR, the texture type was changed to float32 in order to directly pass the labels values to the texture. It turns out that OpenGL performance for float32 textures is much worse than for uint8 textures. Here we change the code to use uint8 whenever the final number of colors is less than 255 in automatic coloring mode, or uint16 if the number is less than 65535. This is achieved by transforming original data using a modulo-like operation that avoids the background label landing on 0. This PR introduces numba dependency, which might not be a long-term solution. We may try to move this utility to some package that already contains compiled code. We can revisit the decision if it causes issues (such as a delay in supporting newer Python versions), and perhaps push such a function to a compiled dependency such as scikit-image. This PR also disables caching used for speedup painting until someone starts painting. It is a significant speedup and reduces memory usage. --------- Co-authored-by: Juan Nunez-Iglesias <jni@fastmail.com> Co-authored-by: Matthias Bussonnier <bussonniermatthias@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
6affa18
commit a6e1569
Showing
17 changed files
with
449 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from typing import TYPE_CHECKING, Optional, Tuple | ||
|
||
from vispy.scene.visuals import create_visual_node | ||
from vispy.visuals.image import ImageVisual | ||
from vispy.visuals.shaders import Function, FunctionChain | ||
|
||
from napari._vispy.visuals.util import TextureMixin | ||
|
||
if TYPE_CHECKING: | ||
from vispy.visuals.visual import VisualView | ||
|
||
|
||
class LabelVisual(TextureMixin, ImageVisual): | ||
"""Visual subclass displaying a 2D array of labels.""" | ||
|
||
def _build_color_transform(self) -> FunctionChain: | ||
"""Build the color transform function chain.""" | ||
funcs = [ | ||
Function(self._func_templates['red_to_luminance']), | ||
Function(self.cmap.glsl_map), | ||
] | ||
|
||
return FunctionChain( | ||
funcs=funcs, | ||
) | ||
|
||
|
||
BaseLabel = create_visual_node(LabelVisual) | ||
|
||
|
||
class LabelNode(BaseLabel): # type: ignore [valid-type,misc] | ||
def _compute_bounds( | ||
self, axis: int, view: 'VisualView' | ||
) -> Optional[Tuple[float, float]]: | ||
if self._data is None: | ||
return None | ||
elif axis > 1: # noqa: RET505 | ||
return 0, 0 | ||
else: | ||
return 0, self.size[axis] |
Oops, something went wrong.