Skip to content
Snippets Groups Projects
Commit 87bb9871 authored by Paul McCarthy's avatar Paul McCarthy
Browse files

Location panel displays the displayed space for the currently selected image

parent 4e6f1818
No related branches found
No related tags found
No related merge requests found
...@@ -44,6 +44,10 @@ NIFTI_XFORM_ALIGNED_ANAT = 2 ...@@ -44,6 +44,10 @@ NIFTI_XFORM_ALIGNED_ANAT = 2
NIFTI_XFORM_TALAIRACH = 3 NIFTI_XFORM_TALAIRACH = 3
NIFTI_XFORM_MNI_152 = 4 NIFTI_XFORM_MNI_152 = 4
# My own code, used to indicate that the
# image is being displayed in voxel space
NIFTI_XFORM_VOXEL = 5
def _loadImageFile(filename): def _loadImageFile(filename):
"""Given the name of an image file, loads it using nibabel. """Given the name of an image file, loads it using nibabel.
...@@ -395,14 +399,16 @@ class Image(props.HasProperties): ...@@ -395,14 +399,16 @@ class Image(props.HasProperties):
# if the qform and sform codes don't # if the qform and sform codes don't
# match, I don't know what to do # match, I don't know what to do
if sform_code != qform_code: return NIFTI_XFORM_UNKNOWN if sform_code != qform_code: code = NIFTI_XFORM_UNKNOWN
# Invalid values # Invalid values
elif sform_code > 4: return NIFTI_XFORM_UNKNOWN elif sform_code > 4: code = NIFTI_XFORM_UNKNOWN
elif sform_code < 0: return NIFTI_XFORM_UNKNOWN elif sform_code < 0: code = NIFTI_XFORM_UNKNOWN
# All is well # All is well
else: return sform_code else: code = sform_code
return int(code)
def getWorldOrientation(self, axis): def getWorldOrientation(self, axis):
......
...@@ -13,6 +13,7 @@ import numpy as np ...@@ -13,6 +13,7 @@ import numpy as np
import props import props
import fsl.data.image as fslimage
import fsl.fslview.controlpanel as controlpanel import fsl.fslview.controlpanel as controlpanel
import imageselectpanel as imageselect import imageselectpanel as imageselect
...@@ -48,12 +49,16 @@ class LocationPanel(controlpanel.ControlPanel, props.HasProperties): ...@@ -48,12 +49,16 @@ class LocationPanel(controlpanel.ControlPanel, props.HasProperties):
controlpanel.ControlPanel.__init__(self, parent, imageList, displayCtx) controlpanel.ControlPanel.__init__(self, parent, imageList, displayCtx)
self._voxelPanel = wx.Panel(self) self._voxelPanel = wx.Panel(self)
self._locationPanel = wx.Panel(self)
self._imageSelect = imageselect.ImageSelectPanel( self._imageSelect = imageselect.ImageSelectPanel(
self, imageList, displayCtx) self, imageList, displayCtx)
self._locationLabel = wx.StaticText( self, style=wx.ALIGN_LEFT) self._locationLabel = wx.StaticText( self._locationPanel,
style=wx.ALIGN_LEFT)
self._spaceLabel = wx.StaticText( self._locationPanel,
style=wx.ALIGN_LEFT)
self._locationWidget = props.makeWidget(self, displayCtx, 'location') self._locationWidget = props.makeWidget(self, displayCtx, 'location')
self._dividerLine1 = wx.StaticLine( self, style=wx.LI_HORIZONTAL) self._dividerLine1 = wx.StaticLine( self, style=wx.LI_HORIZONTAL)
...@@ -69,13 +74,21 @@ class LocationPanel(controlpanel.ControlPanel, props.HasProperties): ...@@ -69,13 +74,21 @@ class LocationPanel(controlpanel.ControlPanel, props.HasProperties):
style=wx.ALIGN_RIGHT) style=wx.ALIGN_RIGHT)
self._adjustFont(self._locationLabel, -2, wx.FONTWEIGHT_LIGHT) self._adjustFont(self._locationLabel, -2, wx.FONTWEIGHT_LIGHT)
self._adjustFont(self._spaceLabel, -2, wx.FONTWEIGHT_LIGHT)
self._adjustFont(self._volumeLabel, -2, wx.FONTWEIGHT_LIGHT) self._adjustFont(self._volumeLabel, -2, wx.FONTWEIGHT_LIGHT)
self._adjustFont(self._voxelLabel, -2, wx.FONTWEIGHT_LIGHT) self._adjustFont(self._voxelLabel, -2, wx.FONTWEIGHT_LIGHT)
self._adjustFont(self._valueLabel, -2, wx.FONTWEIGHT_LIGHT) self._adjustFont(self._valueLabel, -2, wx.FONTWEIGHT_LIGHT)
self._locationLabel.SetLabel('World location (mm)') self._locationLabel.SetLabel(strings.locationPanelLocationLabel)
self._voxelLabel .SetLabel('Voxel coordinates') self._voxelLabel .SetLabel(strings.locationPanelVoxelLabel)
self._volumeLabel .SetLabel('Volume (index)') self._volumeLabel .SetLabel(strings.locationPanelVolumeLabel)
self._locationSizer = wx.BoxSizer(wx.HORIZONTAL)
self._locationPanel.SetSizer(self._locationSizer)
self._locationSizer.Add(self._locationLabel, flag=wx.EXPAND)
self._locationSizer.Add((1, 1), flag=wx.EXPAND, proportion=1)
self._locationSizer.Add(self._spaceLabel, flag=wx.EXPAND)
self._voxelSizer = wx.BoxSizer(wx.HORIZONTAL) self._voxelSizer = wx.BoxSizer(wx.HORIZONTAL)
self._voxelPanel.SetSizer(self._voxelSizer) self._voxelPanel.SetSizer(self._voxelSizer)
...@@ -88,7 +101,7 @@ class LocationPanel(controlpanel.ControlPanel, props.HasProperties): ...@@ -88,7 +101,7 @@ class LocationPanel(controlpanel.ControlPanel, props.HasProperties):
self.SetSizer(self._sizer) self.SetSizer(self._sizer)
self._sizer.Add(self._imageSelect, flag=wx.EXPAND) self._sizer.Add(self._imageSelect, flag=wx.EXPAND)
self._sizer.Add(self._locationLabel, flag=wx.EXPAND) self._sizer.Add(self._locationPanel, flag=wx.EXPAND)
self._sizer.Add(self._locationWidget, flag=wx.EXPAND) self._sizer.Add(self._locationWidget, flag=wx.EXPAND)
self._sizer.Add(self._dividerLine1, flag=wx.EXPAND) self._sizer.Add(self._dividerLine1, flag=wx.EXPAND)
self._sizer.Add(self._voxelPanel, flag=wx.EXPAND) self._sizer.Add(self._voxelPanel, flag=wx.EXPAND)
...@@ -266,14 +279,22 @@ class LocationPanel(controlpanel.ControlPanel, props.HasProperties): ...@@ -266,14 +279,22 @@ class LocationPanel(controlpanel.ControlPanel, props.HasProperties):
(which contains the image name), and sets the voxel location limits. (which contains the image name), and sets the voxel location limits.
""" """
# Make sure that a listener is registered on the
# selected image, so that the space label can be
# updated when its transformation matrix is changed
for i, img in enumerate(self._imageList):
img.removeListener('transform', self._name)
if i == self._displayCtx.selectedImage:
img.addListener('transform', self._name, self._spaceChanged)
self._spaceChanged()
if len(self._imageList) == 0: if len(self._imageList) == 0:
self._updateVoxelValue('') self._updateVoxelValue('')
self._voxelPanel.Layout() self._voxelPanel.Layout()
return return
image = self._imageList[self._displayCtx.selectedImage] image = self._imageList[self._displayCtx.selectedImage]
self._voxelPanel.Layout()
oldLoc = self._displayCtx.location.xyz oldLoc = self._displayCtx.location.xyz
voxLoc = np.round(image.worldToVox([oldLoc]))[0] voxLoc = np.round(image.worldToVox([oldLoc]))[0]
...@@ -289,6 +310,31 @@ class LocationPanel(controlpanel.ControlPanel, props.HasProperties): ...@@ -289,6 +310,31 @@ class LocationPanel(controlpanel.ControlPanel, props.HasProperties):
# coordinates. # coordinates.
self._displayCtx.location.xyz = oldLoc self._displayCtx.location.xyz = oldLoc
def _spaceChanged(self, *a):
"""Called when the transformation matrix of the currently selected
image changes. Updates the 'space' label to reflect the change.
"""
if len(self._imageList) == 0:
self._spaceLabel.SetLabel('')
self._locationPanel.Layout()
return
image = self._imageList[self._displayCtx.selectedImage]
if image.transform == 'affine':
spaceLabel = strings.imageSpaceLabels[image.getXFormCode()]
else:
spaceLabel = strings.imageSpaceLabels[fslimage.NIFTI_XFORM_VOXEL]
spaceLabel = strings.locationPanelSpaceLabel.format(spaceLabel)
self._spaceLabel.SetLabel(spaceLabel)
self._locationPanel.Layout()
# strings imports locationpanel, so this is # strings imports locationpanel, so this is
# at the bottom to avoid a circular import # at the bottom to avoid a circular import
import fsl.fslview.strings as strings import fsl.fslview.strings as strings
#!/usr/bin/env python #!/usr/bin/env python
# #
# strings.py - Labels used throughout FSLView. # strings.py - Labels used throughout various parts of FSLView.
# #
# Author: Paul McCarthy <pauldmccarthy@gmail.com> # Author: Paul McCarthy <pauldmccarthy@gmail.com>
# #
...@@ -50,8 +50,11 @@ viewPanelConfigMenuText = { ...@@ -50,8 +50,11 @@ viewPanelConfigMenuText = {
orthoConfigMenu = '{} display' orthoConfigMenu = '{} display'
lightBoxConfigMenu = '{} display' lightBoxConfigMenu = '{} display'
locationPanelOutOfBounds = 'Out of bounds' locationPanelOutOfBounds = 'Out of bounds'
locationPanelSpaceLabel = '{} space'
locationPanelLocationLabel = 'World location (mm)'
locationPanelVoxelLabel = 'Voxel coordinates'
locationPanelVolumeLabel = 'Volume (index)'
imageAxisLowLongLabels = { imageAxisLowLongLabels = {
...@@ -91,6 +94,7 @@ imageAxisHighShortLabels = { ...@@ -91,6 +94,7 @@ imageAxisHighShortLabels = {
fslimage.ORIENT_UNKNOWN : '?'} fslimage.ORIENT_UNKNOWN : '?'}
imageSpaceLabels = { imageSpaceLabels = {
fslimage.NIFTI_XFORM_VOXEL : 'Voxel',
fslimage.NIFTI_XFORM_UNKNOWN : 'Unknown', fslimage.NIFTI_XFORM_UNKNOWN : 'Unknown',
fslimage.NIFTI_XFORM_SCANNER_ANAT : 'Scanner anatomical', fslimage.NIFTI_XFORM_SCANNER_ANAT : 'Scanner anatomical',
fslimage.NIFTI_XFORM_ALIGNED_ANAT : 'Aligned anatomical', fslimage.NIFTI_XFORM_ALIGNED_ANAT : 'Aligned anatomical',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment