Skip to content

WIP: Initial addition of components for point select #477

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
41 changes: 41 additions & 0 deletions glue_jupyter/bqplot/common/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from bqplot.interacts import BrushSelector, BrushIntervalSelector
from bqplot_image_gl.interacts import BrushEllipseSelector
from glue import __version__ as glue_version
from glue.core.edit_subset_mode import ReplaceMode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed?

from glue.core.roi import RectangularROI, RangeROI, CircularROI, EllipticalROI, PolygonalROI
from glue.core.subset import RoiSubsetState
from glue.config import viewer_tool
Expand Down Expand Up @@ -724,3 +725,43 @@ class HomeTool(Tool):

def activate(self):
self.viewer.state.reset_limits()


@viewer_tool
class PointSelectTool(InteractCheckableTool):
tool_id = 'bqplot:point'
icon = 'glue_point'
action_text = 'Point'
tool_tip = 'Select a single pixel based on the mouse location'

def __init__(self, viewer, finalize_callback=None, **kwargs):
super().__init__(viewer, **kwargs)

self.interact = BrushSelector(x_scale=self.viewer.scale_x,
y_scale=self.viewer.scale_y,
color=INTERACT_COLOR)

self.interact.observe(self.update_selection, "brushing")
self.interact.observe(self.on_selection_change, "selected")
self.finalize_callback = finalize_callback

def update_selection(self, *args):
if self.interact.brushing:
return
with self.viewer._output_widget or nullcontext():
if self.interact.selected_x is not None and self.interact.selected_y is not None:
x = self.interact.selected_x
y = self.interact.selected_y

def on_selection_change(self, *args):
if self.interact.selected_x is None and self.interact.selected_y is None:
if self.finalize_callback is not None:
self.finalize_callback()

def activate(self):
with self.viewer._output_widget or nullcontext():
self.interact.selected_x = None
self.interact.selected_y = None
super().activate()


2 changes: 1 addition & 1 deletion glue_jupyter/bqplot/image/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class BqplotImageView(BqplotBaseView):
_options_cls = ImageViewerStateWidget

tools = ['bqplot:home', 'bqplot:panzoom', 'bqplot:rectangle', 'bqplot:circle',
'bqplot:ellipse', 'bqplot:polygon', 'bqplot:lasso']
'bqplot:ellipse', 'bqplot:polygon', 'bqplot:lasso', 'bqplot:point']

def __init__(self, session, compression='png'):

Expand Down
162 changes: 162 additions & 0 deletions glue_jupyter/icons/glue_point.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 20 additions & 1 deletion glue_jupyter/ipyvolume/common/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from glue.core.roi import PolygonalROI, CircularROI, RectangularROI, Projected3dROI

from glue.config import viewer_tool
from glue.viewers.common.tool import CheckableTool
from glue.viewers.common.tool import Tool, CheckableTool
from glue.viewers.matplotlib

__all__ = []

Expand Down Expand Up @@ -64,6 +65,24 @@ class IpyvolumeLassoMode(IpyvolumePolygonMode):

selector = 'lasso'

@viewer_tool
class IpyvolumePointMode(IPyVolumeCheckableTool):
icon = 'glue_point'
tool_id = 'select:point'
action_text = 'Select Point'
tool_tip = 'Select a single pixel for e.g. spectral slicing'

# pretty sure this is wrong
selector = 'point'

def on_selection(self, data, other=None):
if data['type'] != self.selector:
return

if data['device']:
with self.viewer._output_widget or nullcontext():
x1, y1 = data['device']


@viewer_tool
class IpyvolumeCircleMode(IPyVolumeCheckableTool):
Expand Down
2 changes: 1 addition & 1 deletion glue_jupyter/ipyvolume/common/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class IpyvolumeBaseView(IPyWidgetView):

_options_cls = Viewer3DStateWidget

tools = ['ipyvolume:lasso', 'ipyvolume:circle', 'ipyvolume:rectangle']
tools = ['ipyvolume:lasso', 'ipyvolume:circle', 'ipyvolume:rectangle', 'ipyvolume:point']

def __init__(self, *args, **kwargs):

Expand Down
3 changes: 2 additions & 1 deletion glue_jupyter/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from glue.viewers.scatter.layer_artist import ScatterLayerArtist
from glue.viewers.image.state import ImageViewerState
from glue.viewers.image.viewer import MatplotlibImageMixin
from glue.viewers.image.pixel_selection_mode import PixelSelectionTool

from .base import MatplotlibJupyterViewer

Expand All @@ -31,7 +32,7 @@ class ImageJupyterViewer(MatplotlibImageMixin, MatplotlibJupyterViewer):

tools = ['select:rectangle', 'select:xrange',
'select:yrange', 'select:circle',
'select:polygon']
'select:polygon', 'image:selection_mode']

def __init__(self, session, parent=None, state=None):
super(ImageJupyterViewer, self).__init__(session, wcs=True, parent=parent, state=state)
Expand Down
Loading