Commit 8bee41da authored by Thomas Vincent's avatar Thomas Vincent

Partial support of spherical coords for 3d view

- still need to change roi intensity widget
parent 0ffd1547
......@@ -42,6 +42,7 @@ from silx.gui.plot.StackView import StackView
from silx.math.combo import min_max
from ... import config
from ...io import QSpaceH5
from ...util import bin_centers_to_range_step
from ..widgets.XsocsPlot2D import XsocsPlot2D
from ..process.FitWidget import FitWidget
......@@ -91,9 +92,10 @@ class ROIPlotIntensityMap(PlotIntensityMap):
_DEFAULT_TOOLTIP = 'Intensity Map: sum of the whole QSpace'
_ROI_TOOLTIP = ('ROI Intensity Map: sum of the Region of Interest:\n' +
'qx = [%f, %f]\nqy = [%f, %f]\nqz = [%f, %f]')
'qx = [%f, %f]\nqy = [%f, %f]\nqz = [%f, %f]') # TODO
def __init__(self, parent, qspaceH5):
# TODO
self.__roiSlices = None # qz, qy, qx ROI slices or None
self.__roiQRange = None # qx, qy, qz ROI range in Q space or None
self.__qspaceH5 = qspaceH5
......@@ -276,17 +278,11 @@ class QSpaceView(Qt.QMainWindow):
self.__setPlotData(sampleX,
sampleY,
qspaceH5.qspace_sum)
self.__qx = qspaceH5.qx
self.__qy = qspaceH5.qy
self.__qz = qspaceH5.qz
self.__histo = qspaceH5.histo
self.__mask = self.__histo > 0
firstX = sampleX[0]
firstY = sampleY[0]
# Create StackView
self.__stackView = StackView()
self.__stackView.setLabels(('qz', 'qy', 'qx'))
self.__stackView.setTitleCallback(
WeakMethodProxy(self.__stackViewTitle))
self.__stackView.setColormap('viridis')
......@@ -310,7 +306,6 @@ class QSpaceView(Qt.QMainWindow):
self.__view3d.addIsosurface(self.__defaultIsoLevel1, '#FF000060')
self.__view3d.addIsosurface(self.__defaultIsoLevel2, '#00FF00FF')
self.__view3d.setMinimumSize(400, 400)
self.__view3d.setAxesLabels('qx', 'qy', 'qz')
sfTree = SFViewParamTree()
sfTree.setIsoLevelSliderNormalization('arcsinh')
......@@ -474,8 +469,8 @@ class QSpaceView(Qt.QMainWindow):
idx = ((sampleX - x)**2 + (sampleY - y)**2).argmin()
qspace = qspaceH5.qspace_slice(idx)
histo = self.__histo
mask = self.__mask
histo = qspaceH5.histo
mask = histo > 0
# Normalize values with histogram counts
qspace[mask] /= histo[mask]
......@@ -490,31 +485,48 @@ class QSpaceView(Qt.QMainWindow):
# Set scale and translation
# Do it before setting data as corresponding
# nodes in the SFViewParamTree are updated on sigDataChanged
qxMinBinEdge, _, qxBinStep = bin_centers_to_range_step(self.__qx)
qyMinBinEdge, _, qyBinStep = bin_centers_to_range_step(self.__qy)
qzMinBinEdge, _, qzBinStep = bin_centers_to_range_step(self.__qz)
swappedQSpace = qspace.swapaxes(0, 2)
minBinEdge = []
binSteps = []
for array in qspaceH5.qspace_dimension_values:
min_, _, step = bin_centers_to_range_step(array)
minBinEdge.append(min_)
binSteps.append(step)
axisNames = list(qspaceH5.qspace_dimension_names)
# For cartesian coordinates swap axes as it is stored as qx, qy, qz
# Would need to change how it is stored in the file to avoid this...
if axisNames == list(QSpaceH5.QSpaceCoordinates.axesNames(
QSpaceH5.QSpaceCoordinates.CARTESIAN)):
# Swap qspace dataset to be qz, qy, qx (was qx, qy, qz)
qspace = qspace.swapaxes(0, 2)
# in-place operations
minBinEdge.reverse()
binSteps.reverse()
axisNames.reverse()
if self.__view3d is not None:
self.__view3d.setScale(qxBinStep, qyBinStep, qzBinStep)
self.__view3d.setTranslation(
qxMinBinEdge, qyMinBinEdge, qzMinBinEdge)
# swap scale, transition, labels as it is follows x, y, z convention
self.__view3d.setScale(*tuple(reversed(binSteps)))
self.__view3d.setTranslation(*tuple(reversed(minBinEdge)))
self.__view3d.setAxesLabels(*tuple(reversed(axisNames)))
self.__defaultIsoLevels = None # Reset default isosurface levels
self.__view3d.setData(swappedQSpace)
self.__view3d.setData(qspace)
perspective = self.__stackView.getPerspective()
wasStack = self.__stackView.getStack(copy=False) is not None
self.__stackView.setLabels(axisNames)
self.__stackView.setStack(
swappedQSpace,
qspace,
perspective=perspective,
reset=False,
calibrations=((qzMinBinEdge, qzBinStep),
(qyMinBinEdge, qyBinStep),
(qxMinBinEdge, qxBinStep)))
calibrations=tuple(zip(minBinEdge, binSteps)))
if not wasStack:
self.__stackView.resetZoom()
......
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