From 600ae8a174598a9b0d145c9b7cc6067fa343a3dc Mon Sep 17 00:00:00 2001 From: PennyQ Date: Mon, 1 Aug 2016 14:26:47 -0400 Subject: [PATCH 1/3] add toggle checkbox and comment --- glue_vispy_viewers/common/viewer_options.py | 17 +++++++++++++++-- glue_vispy_viewers/common/viewer_options.ui | 11 +++++++++-- glue_vispy_viewers/common/vispy_widget.py | 3 +++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/glue_vispy_viewers/common/viewer_options.py b/glue_vispy_viewers/common/viewer_options.py index e4e5c8ba..e006608e 100644 --- a/glue_vispy_viewers/common/viewer_options.py +++ b/glue_vispy_viewers/common/viewer_options.py @@ -31,6 +31,8 @@ class VispyOptionsWidget(QtGui.QWidget): visible_box = ButtonProperty('ui.checkbox_axes') perspective_view = ButtonProperty('ui.checkbox_perspective') + use_world = ButtonProperty('ui.checkbox_world') + def __init__(self, parent=None, vispy_widget=None, data_viewer=None): super(VispyOptionsWidget, self).__init__(parent=parent) @@ -84,6 +86,7 @@ def __init__(self, parent=None, vispy_widget=None, data_viewer=None): self.ui.button_flip_z.clicked.connect(self._flip_z) self.ui.reset_button.clicked.connect(self._vispy_widget._reset_view) + self.ui.checkbox_world.toggled.connect(self._update_limits) self._components = {} @@ -106,6 +109,9 @@ def set_limits(self, x_min, x_max, y_min, y_max, z_min, z_max): self._set_limits_enabled(True) self.ui.value_x_min.editingFinished.emit() + print('call set_limits?') + print('what is xyz min max', x_max, x_min, y_max, y_min) + def _flip_x(self): self._set_limits_enabled(False) @@ -154,7 +160,7 @@ def _set_limits_enabled(self, value): self.ui.value_z_max.blockSignals(not value) def _update_attributes_from_data(self, data): - + # init attributes components = data.visible_components for component_id in components: @@ -180,6 +186,7 @@ def _update_attributes_from_data(self, data): self._update_attribute_limits() def _update_attribute_limits(self): + # called by update_attributes_from_data if not hasattr(self, '_limits'): self._limits = {} @@ -206,6 +213,11 @@ def _update_attribute_limits(self): self.ui.value_x_min.editingFinished.emit() def _update_limits(self): + if self.use_world: + print('transform xyz to world coor here') + # if I have world here + # xyz -> world coor xyz + if not hasattr(self, '_limits'): self._limits = {} @@ -250,4 +262,5 @@ def __gluestate__(self, context): z_min=self.z_min, z_max=self.z_max, z_stretch=self.z_stretch, visible_box=self.visible_box, - perspective_view=self.perspective_view) + perspective_view=self.perspective_view, + use_world=self.use_world) diff --git a/glue_vispy_viewers/common/viewer_options.ui b/glue_vispy_viewers/common/viewer_options.ui index a4a33f64..86db82a2 100644 --- a/glue_vispy_viewers/common/viewer_options.ui +++ b/glue_vispy_viewers/common/viewer_options.ui @@ -6,8 +6,8 @@ 0 0 - 254 - 279 + 267 + 295 @@ -294,6 +294,13 @@ + + + + Show real coordinates + + + diff --git a/glue_vispy_viewers/common/vispy_widget.py b/glue_vispy_viewers/common/vispy_widget.py index 59a16ec4..8bb7c106 100644 --- a/glue_vispy_viewers/common/vispy_widget.py +++ b/glue_vispy_viewers/common/vispy_widget.py @@ -100,6 +100,9 @@ def _update_stretch(self, *stretch): self._update_limits() def _update_limits(self): + # TODO: + # if real_value toggle is checked + # transform real values back to channels and do update_limits if len(self.limit_transforms) == 0: return From d0678934441b04c23f4f265004df7e99aff209c6 Mon Sep 17 00:00:00 2001 From: PennyQ Date: Mon, 1 Aug 2016 17:04:48 -0400 Subject: [PATCH 2/3] add comments --- .../common/tests/test_vispy_widget.py | 1 + glue_vispy_viewers/common/viewer_options.py | 30 +++++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/glue_vispy_viewers/common/tests/test_vispy_widget.py b/glue_vispy_viewers/common/tests/test_vispy_widget.py index 986a2a5a..9ef6d240 100644 --- a/glue_vispy_viewers/common/tests/test_vispy_widget.py +++ b/glue_vispy_viewers/common/tests/test_vispy_widget.py @@ -21,6 +21,7 @@ def test_vispy_widget(): w.add_data_visual(scat_visual) d.set_limits(-1., 1., -1., 1., -1., 1.) + d.use_world = True np.testing.assert_equal(scat_visual.transform.scale, [1., 1., 1., 1.]) np.testing.assert_equal(scat_visual.transform.translate, [0., 0., 0., 0.]) diff --git a/glue_vispy_viewers/common/viewer_options.py b/glue_vispy_viewers/common/viewer_options.py index e006608e..f3cbf7a2 100644 --- a/glue_vispy_viewers/common/viewer_options.py +++ b/glue_vispy_viewers/common/viewer_options.py @@ -5,6 +5,7 @@ import numpy as np from glue.external.qt import QtGui +from glue.core import Coordinates from glue.utils.qt.widget_properties import CurrentComboProperty, FloatLineProperty, connect_bool_button, ButtonProperty from glue.utils.qt import load_ui @@ -44,6 +45,8 @@ def __init__(self, parent=None, vispy_widget=None, data_viewer=None): vispy_widget.options = self self._data_viewer = data_viewer + self.data = None + self.stretch_sliders = [self.ui.slider_x_stretch, self.ui.slider_y_stretch, self.ui.slider_z_stretch] @@ -213,18 +216,27 @@ def _update_attribute_limits(self): self.ui.value_x_min.editingFinished.emit() def _update_limits(self): - if self.use_world: - print('transform xyz to world coor here') - # if I have world here - # xyz -> world coor xyz - - if not hasattr(self, '_limits'): self._limits = {} - self._limits[self.x_att] = self.x_min, self.x_max - self._limits[self.y_att] = self.y_min, self.y_max - self._limits[self.z_att] = self.z_min, self.z_max + if self.use_world: + # if I got data here + for i, s in enumerate(self.data.shape): + if type(self.data.coords) != Coordinates: + world = self.data.coords.world_axis(self.data, i) # i is the axis index + world_warning = len(self.data.coords.dependent_axes(i)) > 1 + else: + world = None + world_warning = False + # text = self._components[??].data + # value = np.argmin(np.abs(self._world - float(text))) + # self._limits[??] = value_min, value_max + + else: + # self.xyz _ min/max still stands for channel value + self._limits[self.x_att] = self.x_min, self.x_max + self._limits[self.y_att] = self.y_min, self.y_max + self._limits[self.z_att] = self.z_min, self.z_max self._vispy_widget._update_limits() From 978c9958e9778ce5be947aaaeb148f85ffaa07c3 Mon Sep 17 00:00:00 2001 From: PennyQ Date: Mon, 1 Aug 2016 17:33:26 -0400 Subject: [PATCH 3/3] add frame code --- glue_vispy_viewers/common/viewer_options.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/glue_vispy_viewers/common/viewer_options.py b/glue_vispy_viewers/common/viewer_options.py index f3cbf7a2..3696840b 100644 --- a/glue_vispy_viewers/common/viewer_options.py +++ b/glue_vispy_viewers/common/viewer_options.py @@ -220,20 +220,31 @@ def _update_limits(self): self._limits = {} if self.use_world: - # if I got data here + # TODO: if I got data here for i, s in enumerate(self.data.shape): - if type(self.data.coords) != Coordinates: + if type(self.data.coords) != Coordinates: # what's this for? world = self.data.coords.world_axis(self.data, i) # i is the axis index world_warning = len(self.data.coords.dependent_axes(i)) > 1 else: world = None world_warning = False - # text = self._components[??].data + + # i of 0, 1, 2 -> z, y, x + if i == 0: + self._limits[self.z_att] = min(world), max(world) + if i == 1: + self._limits[self.y_att] = min(world), max(world) + if i == 2: + self._limits[self.x_att] = min(world), max(world) + + # TODO: value is for settting limits on vispy_widget, self.xyz _ min/max still + # represent channel value so we later don't need to transform wcs back to pixel + # coor for user setting limits + # value = np.argmin(np.abs(self._world - float(text))) # self._limits[??] = value_min, value_max else: - # self.xyz _ min/max still stands for channel value self._limits[self.x_att] = self.x_min, self.x_max self._limits[self.y_att] = self.y_min, self.y_max self._limits[self.z_att] = self.z_min, self.z_max