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

Re-worked GLVolume property listeners so they are less confusing. Also

fixed little bug in OrthoViewProfile - mouse down position can sometimes
be None.
parent 70e735bf
No related branches found
No related tags found
No related merge requests found
...@@ -98,15 +98,16 @@ def updateShaderState(self): ...@@ -98,15 +98,16 @@ def updateShaderState(self):
clipping = [clipLo, clipHi, invClip, imageIsClip] clipping = [clipLo, clipHi, invClip, imageIsClip]
negCmap = [useNegCmap, texZero, 0, 0] negCmap = [useNegCmap, texZero, 0, 0]
self.shader.setVertParam('imageShape', shape) changed = False
self.shader.setFragParam('imageShape', shape) changed |= self.shader.setVertParam('imageShape', shape)
self.shader.setFragParam('voxValXform', voxValXform) changed |= self.shader.setFragParam('imageShape', shape)
self.shader.setFragParam('clipping', clipping) changed |= self.shader.setFragParam('voxValXform', voxValXform)
self.shader.setFragParam('negCmap', negCmap) changed |= self.shader.setFragParam('clipping', clipping)
changed |= self.shader.setFragParam('negCmap', negCmap)
self.shader.unload() self.shader.unload()
return True return changed
def preDraw(self): def preDraw(self):
......
...@@ -261,79 +261,32 @@ class GLVolume(globject.GLImageObject): ...@@ -261,79 +261,32 @@ class GLVolume(globject.GLImageObject):
display properties are changed. display properties are changed.
""" """
image = self.image
display = self.display display = self.display
opts = self.displayOpts opts = self.displayOpts
lName = self.name name = self.name
def update(*a): crPVs = opts.getPropVal('clippingRange').getPropertyValueList()
self.notify()
def shaderUpdate(*a): display .addListener('alpha', name, self._alphaChanged)
if self.ready(): opts .addListener('displayRange', name,
fslgl.glvolume_funcs.updateShaderState(self) self._displayRangeChanged)
self.notify()
def condShaderUpdate(*a):
if self.ready():
if fslgl.glvolume_funcs.updateShaderState(self):
self.notify()
def cmapUpdate(*a):
self.refreshColourTextures()
self.notify()
def colourUpdate(*a): crPVs[0].addListener(name, self._lowClippingRangeChanged)
self.refreshColourTextures() crPVs[1].addListener(name, self._highClippingRangeChanged)
shaderUpdate()
opts .addListener('clipImage', name, self._clipImageChanged)
def imageRefresh(*a): opts .addListener('invertClipping', name,
async.wait([self.refreshImageTexture()], shaderUpdate) self._invertClippingChanged)
opts .addListener('cmap', name, self._cmapChanged)
def imageUpdate(*a): opts .addListener('negativeCmap', name, self._cmapChanged)
volume = opts.volume opts .addListener('useNegativeCmap', name,
resolution = opts.resolution self._useNegativeCmapChanged)
opts .addListener('invert', name, self._invertChanged)
if opts.interpolation == 'none': interp = gl.GL_NEAREST opts .addListener('volume', name, self._volumeChanged)
else: interp = gl.GL_LINEAR opts .addListener('interpolation', name,
self._interpolationChanged)
self.imageTexture.set(volume=volume, opts .addListener('resolution', name, self._resolutionChanged)
interp=interp, opts .addListener('transform', name, self._transformChanged)
resolution=resolution,
notify=False)
waitfor = [self.imageTexture.refreshThread()]
if self.clipTexture is not None:
self.clipTexture.set(interp=interp,
resolution=resolution,
notify=False)
waitfor.append(self.clipTexture.refreshThread())
async.wait(waitfor, shaderUpdate)
def clipUpdate(*a):
self.deregisterClipImage()
self.registerClipImage()
async.wait([self.refreshClipTexture()], shaderUpdate)
display.addListener('alpha', lName, colourUpdate, weak=False)
opts .addListener('displayRange', lName, colourUpdate, weak=False)
opts .addListener('clippingRange',
lName, condShaderUpdate, weak=False)
opts .addListener('clipImage', lName, clipUpdate, weak=False)
opts .addListener('invertClipping',
lName, condShaderUpdate, weak=False)
opts .addListener('cmap', lName, cmapUpdate, weak=False)
opts .addListener('negativeCmap', lName, cmapUpdate, weak=False)
opts .addListener('useNegativeCmap',
lName, condShaderUpdate, weak=False)
opts .addListener('invert', lName, colourUpdate, weak=False)
opts .addListener('volume', lName, imageUpdate, weak=False)
opts .addListener('resolution', lName, imageUpdate, weak=False)
opts .addListener('interpolation', lName, imageUpdate, weak=False)
opts .addListener('transform', lName, update, weak=False)
image .addListener('data', lName, update, weak=False)
# Save a flag so the removeDisplayListeners # Save a flag so the removeDisplayListeners
# method knows whether it needs to de-register # method knows whether it needs to de-register
...@@ -345,12 +298,15 @@ class GLVolume(globject.GLImageObject): ...@@ -345,12 +298,15 @@ class GLVolume(globject.GLImageObject):
self.__syncListenersRegistered = opts.getParent() is not None self.__syncListenersRegistered = opts.getParent() is not None
if self.__syncListenersRegistered: if self.__syncListenersRegistered:
opts.addSyncChangeListener( opts.addSyncChangeListener('volume',
'volume', lName, imageRefresh, weak=False) name,
opts.addSyncChangeListener( self._imageSyncChanged)
'resolution', lName, imageRefresh, weak=False) opts.addSyncChangeListener('resolution',
opts.addSyncChangeListener( name,
'interpolation', lName, imageRefresh, weak=False) self._imageSyncChanged)
opts.addSyncChangeListener('interpolation',
name,
self._imageSyncChanged)
def removeDisplayListeners(self): def removeDisplayListeners(self):
...@@ -361,29 +317,30 @@ class GLVolume(globject.GLImageObject): ...@@ -361,29 +317,30 @@ class GLVolume(globject.GLImageObject):
image = self.image image = self.image
display = self.display display = self.display
opts = self.displayOpts opts = self.displayOpts
name = self.name
lName = self.name crPVs = opts.getPropVal('clippingRange').getPropertyValueList()
display.removeListener( 'alpha', lName) display .removeListener( 'alpha', name)
opts .removeListener( 'displayRange', lName) opts .removeListener( 'displayRange', name)
opts .removeListener( 'clippingRange', lName) crPVs[0].removeListener(name)
opts .removeListener( 'clipImage', lName) crPVs[1].removeListener(name)
opts .removeListener( 'invertClipping', lName) opts .removeListener( 'clipImage', name)
opts .removeListener( 'cmap', lName) opts .removeListener( 'invertClipping', name)
opts .removeListener( 'negativeCmap', lName) opts .removeListener( 'cmap', name)
opts .removeListener( 'useNegativeCmap', lName) opts .removeListener( 'negativeCmap', name)
opts .removeListener( 'cmap', lName) opts .removeListener( 'useNegativeCmap', name)
opts .removeListener( 'invert', lName) opts .removeListener( 'cmap', name)
opts .removeListener( 'volume', lName) opts .removeListener( 'invert', name)
opts .removeListener( 'resolution', lName) opts .removeListener( 'volume', name)
opts .removeListener( 'interpolation', lName) opts .removeListener( 'resolution', name)
opts .removeListener( 'transform', lName) opts .removeListener( 'interpolation', name)
image .removeListener( 'data', lName) opts .removeListener( 'transform', name)
image .removeListener( 'data', name)
if self.__syncListenersRegistered: if self.__syncListenersRegistered:
opts.removeSyncChangeListener('volume', lName) opts.removeSyncChangeListener('volume', name)
opts.removeSyncChangeListener('resolution', lName) opts.removeSyncChangeListener('resolution', name)
opts.removeSyncChangeListener('interpolation', lName) opts.removeSyncChangeListener('interpolation', name)
def testUnsynced(self): def testUnsynced(self):
...@@ -398,7 +355,144 @@ class GLVolume(globject.GLImageObject): ...@@ -398,7 +355,144 @@ class GLVolume(globject.GLImageObject):
not self.displayOpts.isSyncedToParent('volume') or not self.displayOpts.isSyncedToParent('volume') or
not self.displayOpts.isSyncedToParent('resolution') or not self.displayOpts.isSyncedToParent('resolution') or
not self.displayOpts.isSyncedToParent('interpolation')) not self.displayOpts.isSyncedToParent('interpolation'))
def _alphaChanged(self, *a):
"""Called when the :attr:`.Display.alpha` property changes. """
self.refreshColourTextures()
self.notify()
def _displayRangeChanged(self, *a):
"""Called when the :attr:`.VolumeOpts.displayRange` property changes.
"""
self.refreshColourTextures()
if fslgl.glvolume_funcs.updateShaderState(self):
self.notify()
def _lowClippingRangeChanged(self, *a):
"""Called when the low :attr:`.VolumeOpts.clippingRange` property
changes. Separate listeners are used for the low and high clipping
values to avoid unnecessary duplicate refreshes in the event that the
:attr:`.VolumeOpts.linkLowRanges` or
:attr:`.VolumeOpts.linkHighRanges` flags are set.
"""
if self.displayOpts.linkLowRanges:
return
if fslgl.glvolume_funcs.updateShaderState(self):
self.notify()
def _highClippingRangeChanged(self, *a):
"""Called when the high :attr:`.VolumeOpts.clippingRange` property
changes (see :meth:`_lowClippingRangeChanged`).
"""
if self.displayOpts.linkHighRanges:
return
if fslgl.glvolume_funcs.updateShaderState(self):
self.notify()
def _clipImageChanged(self, *a):
"""Called when the :attr:`.VolumeOpts.clipImage` property changes.
"""
def onRefresh():
if fslgl.glvolume_funcs.updateShaderState(self):
self.notify()
self.deregisterClipImage()
self.registerClipImage()
async.wait([self.refreshClipTexture()], onRefresh)
def _invertClippingChanged(self, *a):
"""Called when the :attr:`.VolumeOpts.invertClipping` property changes.
"""
if fslgl.glvolume_funcs.updateShaderState(self):
self.notify()
def _cmapChanged(self, *a):
"""Called when the :attr:`.VolumeOpts.cmap` or
:attr:`.VolumeOpts.negativeCmap` properties change.
"""
self.refreshColourTextures()
self.notify()
def _useNegativeCmapChanged(self, *a):
"""Called when the :attr:`.VolumeOpts.useNegativeCmap` property
changes.
"""
if fslgl.glvolume_funcs.updateShaderState(self):
self.notify()
def _invertChanged(self, *a):
"""Called when the :attr:`.VolumeOpts.invert` property changes. """
self.refreshColourTextures()
fslgl.glvolume_funcs.updateShaderState(self)
self.notify()
def _volumeChanged(self, *a):
"""Called when the :attr:`.Nifti1Opts.volume` property changes. """
opts = self.displayOpts
volume = opts.volume
resolution = opts.resolution
if opts.interpolation == 'none': interp = gl.GL_NEAREST
else: interp = gl.GL_LINEAR
self.imageTexture.set(volume=volume,
interp=interp,
resolution=resolution,
notify=False)
waitfor = [self.imageTexture.refreshThread()]
if self.clipTexture is not None:
self.clipTexture.set(interp=interp,
resolution=resolution,
notify=False)
waitfor.append(self.clipTexture.refreshThread())
def onRefresh():
fslgl.glvolume_funcs.updateShaderState(self)
self.notify()
async.wait(waitfor, onRefresh)
def _interpolationChanged(self, *a):
"""Called when the :attr:`.Nifti1Opts.interpolation` property changes.
"""
self._volumeChanged()
def _resolutionChanged(self, *a):
"""Called when the :attr:`.Nifti1Opts.resolution` property changes.
"""
self._volumeChanged()
def _transformChanged(self, *a):
"""Called when the :attr:`.Nifti1Opts.transform` property changes.
"""
self.notify()
def _imageSyncChanged(self, *a):
"""Called when the synchronisation state of the
:attr:`.Nifti1Opts.volume`, :attr:`.Nifti1Opts.resolution`, or
:attr:`.VolumeOpts.interpolation` properties change.
"""
self.refreshImageTexture()
fslgl.glvolume_funcs.updateShaderState(self)
self.notify()
def refreshImageTexture(self): def refreshImageTexture(self):
"""Refreshes the :class:`.ImageTexture` used to store the """Refreshes the :class:`.ImageTexture` used to store the
......
...@@ -491,12 +491,12 @@ class OrthoViewProfile(profiles.Profile): ...@@ -491,12 +491,12 @@ class OrthoViewProfile(profiles.Profile):
If the target canvas is not zoomed in, this has no effect. If the target canvas is not zoomed in, this has no effect.
""" """
if canvasPos is None:
return
mouseDownPos, canvasDownPos = self.getMouseDownLocation() mouseDownPos, canvasDownPos = self.getMouseDownLocation()
if canvasPos is None: return
if canvasDownPos is None: return
xoff = canvasPos[canvas.xax] - canvasDownPos[canvas.xax] xoff = canvasPos[canvas.xax] - canvasDownPos[canvas.xax]
yoff = canvasPos[canvas.yax] - canvasDownPos[canvas.yax] yoff = canvasPos[canvas.yax] - canvasDownPos[canvas.yax]
......
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