Skip to content
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
1 change: 1 addition & 0 deletions glue_vispy_viewers/common/tests/test_vispy_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.])
Expand Down
48 changes: 42 additions & 6 deletions glue_vispy_viewers/common/viewer_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -31,6 +32,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)
Expand All @@ -42,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]
Expand Down Expand Up @@ -84,6 +89,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 = {}

Expand All @@ -106,6 +112,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)
Expand Down Expand Up @@ -154,7 +163,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:
Expand All @@ -180,6 +189,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 = {}
Expand All @@ -206,13 +216,38 @@ def _update_attribute_limits(self):
self.ui.value_x_min.editingFinished.emit()

def _update_limits(self):

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:
# TODO: if I got data here
for i, s in enumerate(self.data.shape):
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

# 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._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()

Expand Down Expand Up @@ -250,4 +285,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)
11 changes: 9 additions & 2 deletions glue_vispy_viewers/common/viewer_options.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>254</width>
<height>279</height>
<width>267</width>
<height>295</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -294,6 +294,13 @@
</property>
</widget>
</item>
<item row="11" column="3" colspan="3">
<widget class="QCheckBox" name="checkbox_world">
<property name="text">
<string>Show real coordinates</string>
</property>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
Expand Down
3 changes: 3 additions & 0 deletions glue_vispy_viewers/common/vispy_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down