GitLab will be upgraded on June 23rd evening. During the upgrade the service will be unavailable, sorry for the inconvenience.

Commit 7855f5ab authored by Thomas Vincent's avatar Thomas Vincent

Generalized qspace axes (to support spherical coordinates)

parent 8bee41da
......@@ -53,9 +53,10 @@ class Roi3DSelectorWidget(Qt.QWidget):
"""
sigRoiChanged = Qt.Signal(object)
""" Signal emitted when one of the slider is moved. The new ranges are
passed to the listener : a dictionary with three SliderState instances,
one for each axis.
"""Signal emitted when one of the slider is moved.
The new ranges are passed to the listener as
a tuple of three SliderState instances, one for each axis.
"""
sigRoiToggled = Qt.Signal(bool)
......@@ -74,72 +75,35 @@ class Roi3DSelectorWidget(Qt.QWidget):
grpBox.toggled.connect(self.sigRoiToggled)
grpLayout = Qt.QVBoxLayout(grpBox)
self.__xRoiWid = RoiAxisWidget('X')
self.__yRoiWid = RoiAxisWidget('Y')
self.__zRoiWid = RoiAxisWidget('Z')
grpLayout.addWidget(self.__xRoiWid)
grpLayout.addWidget(self.__yRoiWid)
grpLayout.addWidget(self.__zRoiWid)
self.__xRoiWid.sigSliderMoved.connect(self.__slotSliderMoved)
self.__yRoiWid.sigSliderMoved.connect(self.__slotSliderMoved)
self.__zRoiWid.sigSliderMoved.connect(self.__slotSliderMoved)
self.__roiWidgets = (
RoiAxisWidget(''), RoiAxisWidget(''), RoiAxisWidget(''))
for widget in self.__roiWidgets:
grpLayout.addWidget(widget)
widget.sigSliderMoved.connect(self.__slotSliderMoved)
layout.addWidget(grpBox)
def __slotSliderMoved(self, sliderEvt):
"""
Slot called each time a slider moves.
:param sliderEvt:
:return:
"""
sender = self.sender()
if sender == self.__xRoiWid:
xState = sliderEvt
yState = self.__yRoiWid.getSliderState()
zState = self.__zRoiWid.getSliderState()
elif sender == self.__yRoiWid:
xState = self.__xRoiWid.getSliderState()
yState = sliderEvt
zState = self.__zRoiWid.getSliderState()
elif sender == self.__zRoiWid:
xState = self.__xRoiWid.getSliderState()
yState = self.__yRoiWid.getSliderState()
zState = sliderEvt
elif sender == self.__grpBox:
return
else:
raise RuntimeError('Unknown sender.')
self.sigRoiChanged.emit({'x': xState,
'y': yState,
'z': zState})
def __slotSliderMoved(self, _):
"""Slot called each time a slider moves."""
self.sigRoiChanged.emit(
[widget.getSliderState() for widget in self.roiAxisWidgets()])
def isActive(self):
return self.__grpBox.isChecked()
def xSlider(self):
"""
Returns the RangeSlider for the X axis
:return:
"""
return self.__xRoiWid.slider()
def sliders(self):
"""Returns all ROI widgets sliders
def ySlider(self):
"""
Returns the RangeSlider for the X axis
:return:
:rtype: List[RangeSlider]
"""
return self.__yRoiWid.slider()
return tuple(widget.slider() for widget in self.__roiWidgets)
def zSlider(self):
"""
Returns the RangeSlider for the X axis
:return:
def roiAxisWidgets(self):
"""Returns all RoiAxisWidget
:rtype: List[RoiAxisWidget]
"""
return self.__zRoiWid.slider()
return self.__roiWidgets
class FitWidget(Qt.QWidget):
......@@ -222,13 +186,9 @@ class FitWidget(Qt.QWidget):
# Set sliders range and step
with qspaceH5:
qx = qspaceH5.qx
qy = qspaceH5.qy
qz = qspaceH5.qz
qDimensions = qspaceH5.qspace_dimension_values
for slider, binCenters in ((self.roiWidget().xSlider(), qx),
(self.roiWidget().ySlider(), qy),
(self.roiWidget().zSlider(), qz)):
for slider, binCenters in zip(self.roiWidget().sliders(), qDimensions):
slider.setPositionCount(len(binCenters) + 1)
min_, max_ = bin_centers_to_range_step(binCenters)[:2]
slider.setRange(min_, max_)
......@@ -252,14 +212,13 @@ class FitWidget(Qt.QWidget):
:return:
"""
qspace = self.__qspaceH5.qspace_slice(index)
z_sum = qspace.sum(axis=0).sum(axis=0)
cube_sum_z = qspace.sum(axis=2)
y_sum = cube_sum_z.sum(axis=0)
x_sum = cube_sum_z.sum(axis=1)
for profile, slider in ((x_sum, self.roiWidget().xSlider()),
(y_sum, self.roiWidget().ySlider()),
(z_sum, self.roiWidget().zSlider())):
dim2_sum = qspace.sum(axis=0).sum(axis=0)
cube_sum_dim2 = qspace.sum(axis=2)
dim1_sum = cube_sum_dim2.sum(axis=0)
dim0_sum = cube_sum_dim2.sum(axis=1)
for profile, slider in zip((dim0_sum, dim1_sum, dim2_sum),
self.roiWidget().sliders()):
slider.setGroovePixmapFromProfile(profile, colormap='jet')
def setOutputFile(self, outputFile):
......@@ -288,17 +247,17 @@ class FitWidget(Qt.QWidget):
fitType = self.__fitTypeCb.itemData(self.__fitTypeCb.currentIndex())
if self.roiWidget().isActive():
x0, x1 = self.roiWidget().xSlider().getPositions()
y0, y1 = self.roiWidget().ySlider().getPositions()
z0, z1 = self.roiWidget().zSlider().getPositions()
if x0 == x1 or y0 == y1 or z0 == z1:
message = "QSpace ROI is void: cannot perform fit"
_logger.error(message)
Qt.QMessageBox.critical(self, "QSpace ROI Error", message)
self.__lock(False)
return
roiIndices = [[x0, x1], [y0, y1], [z0, z1]]
roiIndices = [slider.getPositions()
for slider in self.roiWidget().sliders()]
# Check that roi ranges are not empty
for min_, max_ in roiIndices:
if min_ >= max_:
message = "QSpace ROI is void: cannot perform fit"
_logger.error(message)
Qt.QMessageBox.critical(self, "QSpace ROI Error", message)
self.__lock(False)
return
else:
roiIndices = None
......
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