Commit f9d357cd authored by Thomas Vincent's avatar Thomas Vincent

Update stack view management

parent 8447b401
......@@ -35,6 +35,7 @@ import numpy as np
from matplotlib import cm
from silx.utils.weakref import WeakMethodProxy
from silx.gui import qt as Qt
from silx.gui.plot import actions, PlotToolButtons, PlotWidget
from silx.gui.icons import getQIcon
......@@ -272,14 +273,17 @@ class QSpaceView(Qt.QMainWindow):
# Create StackView
self.__stackView = StackView()
self.__stackView.setLabels(('qz', 'qy', 'qx'))
self.__stackView.setTitleCallback(
WeakMethodProxy(self.__stackViewTitle))
self.__stackView.setColormap('viridis')
self.__stackView.setKeepDataAspectRatio(True)
self.__stackView.getProfileToolbar().setVisible(False)
self.__stackView.getColorBarAction().setVisible(False)
self.__stackView.getPlot().getMaskAction().setVisible(False)
self.__stackView.sigInteractiveModeChanged.connect(
self.__stackView.sigPlaneSelectionChanged.connect(
self.__updateStackViewROI)
self.__stackView.sigStackChanged.connect(self.__updateStackViewROI)
self.__stackView.sigFrameChanged.connect(self.__updateStackViewROI)
# setting up the plot3D and its param tree
self.__view3d = ScalarFieldView()
......@@ -534,33 +538,69 @@ class QSpaceView(Qt.QMainWindow):
for widget in self.__lockWidgets:
widget.setEnabled(True)
def __getStackViewCurrentLabels(self):
"""Retrieves StackView axis labels ordered as currently viewed
(Frame axis label, Y axis, X axis)
:rtype: List[str]
"""
plot = self.__stackView.getPlot()
xLabel = plot.getXAxis().getLabel()
yLabel = plot.getYAxis().getLabel()
zLabel = ['qx', 'qy', 'qz']
zLabel.remove(xLabel)
zLabel.remove(yLabel)
zLabel = zLabel[0]
return zLabel, yLabel, xLabel
def __stackViewTitle(self, index):
"""Returns StackView title
:param ind index: Frame index
:rtype: str
"""
labels = self.__getStackViewCurrentLabels()
# TODO apply calibration
return '%s = %d' % (labels[0], index)
def __updateStackViewROI(self, *args, **kwargs):
"""Update display of ROI on StackView"""
roiWidget = self.__fitWidget.roiWidget()
plot = self.__stackView.getPlot()
legend = "__QSpaceView_ROI__"
if roiWidget.isActive():
# Get ROI range for currently displayed axes
ranges = {
'qx': roiWidget.xSlider().getSliderValues(),
'qy': roiWidget.ySlider().getSliderValues(),
'qz': roiWidget.zSlider().getSliderValues()
roiSliders = {
'qx': roiWidget.xSlider(),
'qy': roiWidget.ySlider(),
'qz': roiWidget.zSlider()
}
zLabel, yLabel, xLabel = self.__getStackViewCurrentLabels()
frame = self.__stackView.getFrameNumber()
begin, end = roiSliders[zLabel].getSliderIndices()
if begin <= frame <= end:
# Fill for edges of the ROI
fill = (frame == begin) or (frame == end)
xRange = ranges[plot.getXAxis().getLabel()]
yRange = ranges[plot.getYAxis().getLabel()]
xRange = roiSliders[xLabel].getSliderValues()
yRange = roiSliders[yLabel].getSliderValues()
plot.addItem(
xRange, yRange,
legend="__QSpaceView_ROI__",
shape='rectangle',
color='pink',
fill=False,
overlay=True)
self.__stackView.addItem(
xRange, yRange,
legend="__QSpaceView_ROI__",
shape='rectangle',
color='pink',
fill=fill,
overlay=True)
else:
self.__stackView.remove(legend, kind='item')
else:
plot.remove(legend, kind='item')
self.__stackView.remove(legend, kind='item')
def __slotRoiToggled(self, on):
"""
......
Markdown is supported
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