diff --git a/fsl/fsleyes/gl/globject.py b/fsl/fsleyes/gl/globject.py index a250696d962c9d919a43e9d4fbb36739a9c610e2..ec291985c7203d20d4d522b122fc5db193936c4d 100644 --- a/fsl/fsleyes/gl/globject.py +++ b/fsl/fsleyes/gl/globject.py @@ -380,23 +380,36 @@ class GLImageObject(GLObject): ``GLImageObject``. """ - image = self.image - opts = self.displayOpts - res = opts.resolution - - if opts.transform in ('id', 'pixdim'): - - pixdim = np.array(image.pixdim[:3]) - steps = [res, res, res] / pixdim - steps = np.maximum(steps, [1, 1, 1]) - res = image.shape[:3] / steps - - return np.array(res.round(), dtype=np.uint32) - - else: - lo, hi = map(np.array, self.getDisplayBounds()) - maxres = int(round(((hi - lo) / res).max())) - return [maxres] * 3 + import nibabel as nib + + image = self.image + opts = self.displayOpts + res = opts.resolution + + # Figure out a good display resolution + # along each voxel dimension + pixdim = np.array(image.pixdim[:3]) + steps = [res, res, res] / pixdim + steps = np.maximum(steps, [1, 1, 1]) + res = image.shape[:3] / steps + + # Make sure the pixel + # resolutions are integers + res = np.array(res.round(), dtype=np.uint32) + + # Figure out an approximate + # correspondence between the + # voxel axes and the display + # coordinate system axes. + xform = opts.getTransform('id', 'display') + axes = nib.orientations.aff2axcodes( + xform, ((0, 0), (1, 1), (2, 2))) + + # Re-order the voxel resolutions + # in the display space + res = [res[axes[0]], res[axes[1]], res[axes[2]]] + + return res def generateVertices(self, zpos, xform): diff --git a/fsl/fsleyes/gl/glvolume.py b/fsl/fsleyes/gl/glvolume.py index 461bc098a4063f2310f678e9ad9e7c9f199b4d49..b678b5534b458382ae7cd5ba9f66681b03acdd28 100644 --- a/fsl/fsleyes/gl/glvolume.py +++ b/fsl/fsleyes/gl/glvolume.py @@ -183,6 +183,9 @@ class GLVolume(globject.GLImageObject): fslgl.glvolume_funcs.updateShaderState(self) self.onUpdate() + def update(*a): + self.onUpdate() + def imageUpdate(*a): volume = opts.volume resolution = opts.resolution @@ -207,6 +210,7 @@ class GLVolume(globject.GLImageObject): 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) if opts.getParent() is not None: opts.addSyncChangeListener( @@ -237,6 +241,7 @@ class GLVolume(globject.GLImageObject): opts .removeListener( 'volume', lName) opts .removeListener( 'resolution', lName) opts .removeListener( 'interpolation', lName) + opts .removeListener( 'transform', lName) if opts.getParent() is not None: opts.removeSyncChangeListener('volume', lName) opts.removeSyncChangeListener('resolution', lName)