Commit 8447b401 authored by Thomas Vincent's avatar Thomas Vincent

Add a StackView in a tab for visualizing QSpace

parent f7a114cb
......@@ -38,6 +38,7 @@ from matplotlib import cm
from silx.gui import qt as Qt
from silx.gui.plot import actions, PlotToolButtons, PlotWidget
from silx.gui.icons import getQIcon
from silx.gui.plot.StackView import StackView
from silx.gui.plot3d.ScalarFieldView import ScalarFieldView
from silx.gui.plot3d.SFViewParamTree import TreeView as SFViewParamTree
from silx.math.combo import min_max
......@@ -268,13 +269,31 @@ class QSpaceView(Qt.QMainWindow):
firstX = sampleX[0]
firstY = sampleY[0]
# Create StackView
self.__stackView = StackView()
self.__stackView.setLabels(('qz', 'qy', 'qx'))
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.__updateStackViewROI)
self.__stackView.sigStackChanged.connect(self.__updateStackViewROI)
# setting up the plot3D and its param tree
self.__view3d = ScalarFieldView()
self.__view3d.addIsosurface(self.__defaultIsoLevel1, '#FF000060')
self.__view3d.addIsosurface(self.__defaultIsoLevel2, '#00FF00FF')
self.__view3d.setMinimumSize(400, 400)
self.__view3d.setAxesLabels('qx', 'qy', 'qz')
self.setCentralWidget(self.__view3d)
tabWidget = Qt.QTabWidget()
tabWidget.setTabPosition(Qt.QTabWidget.South)
tabWidget.addTab(self.__view3d, "3D view")
tabWidget.addTab(self.__stackView, "Image stack view")
self.setCentralWidget(tabWidget)
sfTree = SFViewParamTree()
if hasattr(sfTree, 'setIsoLevelSliderNormalization'):
# only available in silx 0.9
......@@ -304,7 +323,7 @@ class QSpaceView(Qt.QMainWindow):
fitDock.setWidget(fitWidget)
features = fitDock.features() ^ Qt.QDockWidget.DockWidgetClosable
fitDock.setFeatures(features)
self.__view3d.addDockWidget(Qt.Qt.RightDockWidgetArea, fitDock)
self.addDockWidget(Qt.Qt.RightDockWidgetArea, fitDock)
# widget that are to be disabled when the fit is running
self.__lockWidgets = lockWidgets = []
......@@ -434,7 +453,6 @@ class QSpaceView(Qt.QMainWindow):
self.__minVal = qspace[mask*(qspace>0)].min()
qspace /= self.__minVal
# Set scale and translation
# Do it before setting data as corresponding
# nodes in the SFViewParamTree are updated on sigDataChanged
......@@ -442,13 +460,25 @@ class QSpaceView(Qt.QMainWindow):
qxMin, qxMax = min(self.__qx), max(self.__qx)
qyMin, qyMax = min(self.__qy), max(self.__qy)
qzMin, qzMax = min(self.__qz), max(self.__qz)
self.__view3d.setScale((qxMax - qxMin) / (qxLen - 1),
(qyMax - qyMin) / (qyLen - 1),
(qzMax - qzMin) / (qzLen - 1))
qxScale = (qxMax - qxMin) / (qxLen - 1)
qyScale = (qyMax - qyMin) / (qyLen - 1)
qzScale = (qzMax - qzMin) / (qzLen - 1)
self.__view3d.setScale(qxScale, qyScale, qzScale)
self.__view3d.setTranslation(qxMin, qyMin, qzMin)
self.__defaultIsoLevels = None # Reset default isosurface levels
self.__view3d.setData(qspace.swapaxes(0, 2))
swapedQSpace = qspace.swapaxes(0, 2)
self.__view3d.setData(swapedQSpace)
wasStack = self.__stackView.getStack(copy=False) is not None
self.__stackView.setStack(swapedQSpace,
reset=False,
calibrations=((qzMin, qzScale),
(qyMin, qyScale),
(qxMin, qxScale)))
if not wasStack:
self.__stackView.resetZoom()
z_sum = qspace.sum(axis=0).sum(axis=0)
cube_sum_z = qspace.sum(axis=2)
......@@ -504,6 +534,34 @@ class QSpaceView(Qt.QMainWindow):
for widget in self.__lockWidgets:
widget.setEnabled(True)
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()
}
xRange = ranges[plot.getXAxis().getLabel()]
yRange = ranges[plot.getYAxis().getLabel()]
plot.addItem(
xRange, yRange,
legend="__QSpaceView_ROI__",
shape='rectangle',
color='pink',
fill=False,
overlay=True)
else:
plot.remove(legend, kind='item')
def __slotRoiToggled(self, on):
"""
Slot called when the Roi selection is enabled.
......@@ -540,6 +598,8 @@ class QSpaceView(Qt.QMainWindow):
roiWidget.ySlider().setSliderValues(yLeft, yRight)
roiWidget.zSlider().setSliderValues(zLeft, zRight)
self.__updateStackViewROI()
def __slotRoiChanged(self, event):
"""
Slot called each time the ROI is modified
......@@ -560,6 +620,8 @@ class QSpaceView(Qt.QMainWindow):
self.__view3d.setSelectedRegion(zrange=zRoi, yrange=yRoi, xrange_=xRoi)
self.__updateStackViewROI()
def __planePlotDockVisibilityChanged(self, visible):
cutPlane = self.__view3d.getCutPlanes()[0]
if visible:
......@@ -610,7 +672,3 @@ class QSpaceView(Qt.QMainWindow):
origin=planeImage.getTranslation(),
scale=planeImage.getScale(),
resetzoom=True)
if __name__ == '__main__':
pass
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