Commit 6bdd35ba authored by Kendrick, Coleman's avatar Kendrick, Coleman
Browse files

Add full dim transformation in sliceviewer for mdhisto

parent a49e771b
......@@ -13,6 +13,7 @@ import numpy as np
from mantidqt.utils.qt import import_qt
from matplotlib.collections import QuadMesh
from matplotlib.image import AxesImage
from matplotlib.transforms import Bbox
from .lineplots import CursorTracker, cursor_info
from .transform import NonOrthogonalTransform
......@@ -25,7 +26,7 @@ ImageInfoWidget = import_qt('.._common', 'mantidqt.widgets', 'ImageInfoWidget')
class ImageInfoTracker(CursorTracker):
def __init__(self, image: Union[AxesImage, QuadMesh], transform: NonOrthogonalTransform,
do_transform: bool, widget: ImageInfoWidget):
do_transform: bool, widget: ImageInfoWidget, cursor_transform):
"""
Update the image that the widget refers too.
:param: An AxesImage or Mesh instance to track
......@@ -37,6 +38,10 @@ class ImageInfoTracker(CursorTracker):
self.transform = transform
self.do_transform = do_transform
self._widget = widget
self._cursor_transform = None
if cursor_transform is not None:
self._cursor_transform = Bbox([[cursor_transform[1][0], cursor_transform[0][0]],
[cursor_transform[1][1], cursor_transform[0][1]]])
if hasattr(image, 'get_extent'):
self.on_cursor_at = self._on_cursor_at_axesimage
......@@ -59,7 +64,7 @@ class ImageInfoTracker(CursorTracker):
if self._image is None:
return
cinfo = cursor_info(self._image, xdata, ydata)
cinfo = cursor_info(self._image, xdata, ydata, full_bbox=self._cursor_transform)
if cinfo is not None:
arr, _, (i, j) = cinfo
if (0 <= i < arr.shape[0]) and (0 <= j < arr.shape[1]) and not np.ma.is_masked(arr[i, j]):
......
......@@ -397,7 +397,7 @@ CursorInfo = namedtuple("CursorInfo", ("array", "extent", "point"))
@lru_cache(maxsize=32)
def cursor_info(image: AxesImage, xdata: float, ydata: float) -> Optional[CursorInfo]:
def cursor_info(image: AxesImage, xdata: float, ydata: float, full_bbox=None) -> Optional[CursorInfo]:
"""Return information on the image for the given position in
data coordinates.
:param image: An instance of an image type
......@@ -410,7 +410,10 @@ def cursor_info(image: AxesImage, xdata: float, ydata: float) -> Optional[Cursor
arr = image.get_array()
data_extent = Bbox([[ymin, xmin], [ymax, xmax]])
array_extent = Bbox([[0, 0], arr.shape[:2]])
trans = BboxTransform(boxin=data_extent, boxout=array_extent)
if full_bbox is None:
trans = BboxTransform(boxin=data_extent, boxout=array_extent)
else:
trans = BboxTransform(boxin=full_bbox, boxout=array_extent)
point = trans.transform_point([ydata, xdata])
if any(np.isnan(point)):
return None
......
......@@ -65,6 +65,7 @@ class SliceViewerDataView(QWidget):
self._line_plots = None
self._image_info_tracker = None
self._region_selection_on = False
self._orig_lims = None
# Dimension widget
self.dimensions_layout = QGridLayout()
......@@ -262,6 +263,7 @@ class SliceViewerDataView(QWidget):
extent = self.image.get_extent()
self.ax.set_xlim(extent[0], extent[1])
self.ax.set_ylim(extent[2], extent[3])
self._orig_lims = self.get_axes_limits()
self.draw_plot()
......@@ -384,7 +386,8 @@ class SliceViewerDataView(QWidget):
self._image_info_tracker = ImageInfoTracker(image=self.image,
transform=self.nonortho_transform,
do_transform=self.nonorthogonal_mode,
widget=self.image_info_widget)
widget=self.image_info_widget,
cursor_transform=self._orig_lims)
if state:
self._image_info_tracker.connect()
......@@ -463,7 +466,6 @@ class SliceViewerDataView(QWidget):
else:
return None
def set_axes_limits(self, xlim, ylim):
"""
Set the view limits on the image axes to the given extents. Assume the
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment