summaryrefslogtreecommitdiff
path: root/silx/gui/plot3d/items/image.py
diff options
context:
space:
mode:
Diffstat (limited to 'silx/gui/plot3d/items/image.py')
-rw-r--r--silx/gui/plot3d/items/image.py68
1 files changed, 59 insertions, 9 deletions
diff --git a/silx/gui/plot3d/items/image.py b/silx/gui/plot3d/items/image.py
index 9e8bf1e..210f2f3 100644
--- a/silx/gui/plot3d/items/image.py
+++ b/silx/gui/plot3d/items/image.py
@@ -1,7 +1,7 @@
# coding: utf-8
# /*##########################################################################
#
-# Copyright (c) 2017 European Synchrotron Radiation Facility
+# Copyright (c) 2017-2018 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -33,22 +33,72 @@ __date__ = "15/11/2017"
import numpy
-from ..scene import primitives
+from ..scene import primitives, utils
from .core import DataItem3D, ItemChangedType
from .mixins import ColormapMixIn, InterpolationMixIn
+from ._pick import PickingResult
-class ImageData(DataItem3D, ColormapMixIn, InterpolationMixIn):
- """Description of a 2D image data.
+class _Image(DataItem3D, InterpolationMixIn):
+ """Base class for images
:param parent: The View widget this item belongs to.
"""
def __init__(self, parent=None):
DataItem3D.__init__(self, parent=parent)
- ColormapMixIn.__init__(self)
InterpolationMixIn.__init__(self)
+ def _setPrimitive(self, primitive):
+ InterpolationMixIn._setPrimitive(self, primitive)
+
+ def getData(self, copy=True):
+ raise NotImplementedError()
+
+ def _pickFull(self, context):
+ """Perform picking in this item at given widget position.
+
+ :param PickContext context: Current picking context
+ :return: Object holding the results or None
+ :rtype: Union[None,PickingResult]
+ """
+ rayObject = context.getPickingSegment(frame=self._getScenePrimitive())
+ if rayObject is None:
+ return None
+
+ points = utils.segmentPlaneIntersect(
+ rayObject[0, :3],
+ rayObject[1, :3],
+ planeNorm=numpy.array((0., 0., 1.), dtype=numpy.float64),
+ planePt=numpy.array((0., 0., 0.), dtype=numpy.float64))
+
+ if len(points) == 1: # Single intersection
+ if points[0][0] < 0. or points[0][1] < 0.:
+ return None # Outside image
+ row, column = int(points[0][1]), int(points[0][0])
+ data = self.getData(copy=False)
+ height, width = data.shape[:2]
+ if row < height and column < width:
+ return PickingResult(
+ self,
+ positions=[(points[0][0], points[0][1], 0.)],
+ indices=([row], [column]))
+ else:
+ return None # Outside image
+ else: # Either no intersection or segment and image are coplanar
+ return None
+
+
+class ImageData(_Image, ColormapMixIn):
+ """Description of a 2D image data.
+
+ :param parent: The View widget this item belongs to.
+ """
+
+ def __init__(self, parent=None):
+ _Image.__init__(self, parent=parent)
+ ColormapMixIn.__init__(self)
+
self._data = numpy.zeros((0, 0), dtype=numpy.float32)
self._image = primitives.ImageData(self._data)
@@ -56,7 +106,7 @@ class ImageData(DataItem3D, ColormapMixIn, InterpolationMixIn):
# Connect scene primitive to mix-in class
ColormapMixIn._setSceneColormap(self, self._image.colormap)
- InterpolationMixIn._setPrimitive(self, self._image)
+ _Image._setPrimitive(self, self._image)
def setData(self, data, copy=True):
"""Set the image data to display.
@@ -83,14 +133,14 @@ class ImageData(DataItem3D, ColormapMixIn, InterpolationMixIn):
return self._image.getData(copy=copy)
-class ImageRgba(DataItem3D, InterpolationMixIn):
+class ImageRgba(_Image, InterpolationMixIn):
"""Description of a 2D data RGB(A) image.
:param parent: The View widget this item belongs to.
"""
def __init__(self, parent=None):
- DataItem3D.__init__(self, parent=parent)
+ _Image.__init__(self, parent=parent)
InterpolationMixIn.__init__(self)
self._data = numpy.zeros((0, 0, 3), dtype=numpy.float32)
@@ -99,7 +149,7 @@ class ImageRgba(DataItem3D, InterpolationMixIn):
self._getScenePrimitive().children.append(self._image)
# Connect scene primitive to mix-in class
- InterpolationMixIn._setPrimitive(self, self._image)
+ _Image._setPrimitive(self, self._image)
def setData(self, data, copy=True):
"""Set the RGB(A) image data to display.