Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

indexable graphic attributes #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added PresentFeature to toggle graphic's presence in the scene
  • Loading branch information
kushalkolar committed Dec 21, 2022
commit 71037f0c00218a412e16e95ef34f9eecf19248c3
6 changes: 5 additions & 1 deletion 6 fastplotlib/graphics/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pygfx

from fastplotlib.utils import get_colors, map_labels_to_colors
from ._graphic_attribute import GraphicFeature, ColorFeature
from ._graphic_attribute import GraphicFeature, ColorFeature, PresentFeature


class Graphic:
Expand Down Expand Up @@ -43,6 +43,10 @@ def __init__(
if colors is not False:
self.colors = ColorFeature(parent=self, colors=colors, n_colors=n_colors, alpha=alpha)

# different from visible, toggles the Graphic presence in the Scene
# useful for bbox calculations to ignore these Graphics
self.present = PresentFeature(parent=self)

valid_features = ["visible"]
for attr_name in self.__dict__.keys():
attr = getattr(self, attr_name)
Expand Down
34 changes: 34 additions & 0 deletions 34 fastplotlib/graphics/_graphic_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,37 @@ def __getitem__(self, item):

def __repr__(self):
return repr(self._parent.world_object.geometry.colors.data)


class PresentFeature(GraphicFeature):
"""
Toggles if the object is present in the scene, different from visible \n
Useful for computing bounding boxes from the Scene to only include graphics
that are present
"""
def __init__(self, parent, present: bool = True):
self._scene = None
super(PresentFeature, self).__init__(parent, present)

def _set(self, present: bool):
i = 0
while not isinstance(self._scene, Scene):
self._scene = self._parent.world_object.parent
i += 1

if i > 100:
raise RecursionError(
"Exceded scene graph depth threshold, cannot find Scene associated with"
"this graphic."
)

if present:
if self._parent.world_object not in self._scene.children:
self._scene.add(self._parent.world_object)

else:
if self._parent.world_object in self._scene.children:
self._scene.remove(self._parent.world_object)

def __repr__(self):
return repr(self.data)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.