diff --git a/fsl/fslview/gl/gl14/glcircle_funcs.py b/fsl/fslview/gl/gl14/glcircle_funcs.py index 0ffc8d483e5cfb0a4a40761604d0097f90a11777..25e2de8afa40b381ed7cb459f344ac7009c3c470 100644 --- a/fsl/fslview/gl/gl14/glcircle_funcs.py +++ b/fsl/fslview/gl/gl14/glcircle_funcs.py @@ -8,15 +8,16 @@ import logging log = logging.getLogger(__name__) -import scipy.ndimage as ndi -import OpenGL.GL as gl +import scipy.ndimage as ndi +import OpenGL.GL as gl + +import fsl.utils.transform as transform def draw(glimg, zpos, xform=None): """Draws a slice of the image at the given Z location using immediate mode rendering. """ - image = glimg.image display = glimg.display # Don't draw the slice if this @@ -31,7 +32,7 @@ def draw(glimg, zpos, xform=None): # Transform world texture coordinates # to (floating point) voxel coordinates - voxCoords = image.worldToVox(texCoords) + voxCoords = transform.transform(texCoords, display.displayToVoxMat) imageData = glimg.imageData texCoordXform = glimg.texCoordXform colourTexture = glimg.colourTexture diff --git a/fsl/fslview/gl/gl14/glimage_funcs.py b/fsl/fslview/gl/gl14/glimage_funcs.py index 8fec7cfec923e3a45e0b3de483d940b3b7a8aa4e..837aa687a13c87a54729ffbbb9f20df2629f0a37 100644 --- a/fsl/fslview/gl/gl14/glimage_funcs.py +++ b/fsl/fslview/gl/gl14/glimage_funcs.py @@ -34,9 +34,11 @@ This module provides the following functions: import logging log = logging.getLogger(__name__) -import numpy as np -import scipy.ndimage as ndi -import OpenGL.GL as gl +import numpy as np +import scipy.ndimage as ndi +import OpenGL.GL as gl + +import fsl.utils.transform as transform def init(glimg, xax, yax): @@ -86,7 +88,6 @@ def draw(glimg, zpos, xform=None): mode rendering. """ - image = glimg.image display = glimg.display # Don't draw the slice if this @@ -101,7 +102,7 @@ def draw(glimg, zpos, xform=None): # Transform world texture coordinates # to (floating point) voxel coordinates - voxCoords = image.worldToVox(texCoords) + voxCoords = transform.transform(texCoords, display.displayToVoxMat) imageData = glimg.imageData texCoordXform = glimg.texCoordXform colourTexture = glimg.colourTexture diff --git a/fsl/fslview/gl/gl21/glcircle_funcs.py b/fsl/fslview/gl/gl21/glcircle_funcs.py index 36e68f70709f425532ea01b0137a0732a75cb483..f2d3f258b6872a95b7985d7d5ead2f54bb761319 100644 --- a/fsl/fslview/gl/gl21/glcircle_funcs.py +++ b/fsl/fslview/gl/gl21/glcircle_funcs.py @@ -39,9 +39,9 @@ def draw(glimg, zpos, xform=None): # to the shader variable if xform is None: xform = np.identity(4) - w2w = np.array(xform, dtype=np.float32).ravel('C') - w2v = np.array(image.worldToVoxMat, dtype=np.float32).ravel('C') - tcx = np.array(glimg.texCoordXform, dtype=np.float32).ravel('C') + w2w = np.array(xform, dtype=np.float32).ravel('C') + w2v = np.array(display.displayToVoxMat, dtype=np.float32).ravel('C') + tcx = np.array(glimg.texCoordXform, dtype=np.float32).ravel('C') gl.glUniformMatrix4fv(glimg.worldToVoxMatPos, 1, False, w2v) gl.glUniformMatrix4fv(glimg.worldToWorldMatPos, 1, False, w2w) diff --git a/fsl/fslview/gl/gl21/glimage_funcs.py b/fsl/fslview/gl/gl21/glimage_funcs.py index 58c9f84b94f1fac5f0e86d0083f96652b36a0c9d..9d6e3af221bc64f6d685e7fc855a99d5ff38092d 100644 --- a/fsl/fslview/gl/gl21/glimage_funcs.py +++ b/fsl/fslview/gl/gl21/glimage_funcs.py @@ -47,8 +47,6 @@ This module provides the following functions: import logging log = logging.getLogger(__name__) -import os.path as op - import numpy as np import OpenGL.GL as gl import OpenGL.arrays.vbo as vbo @@ -397,9 +395,9 @@ def draw(glimg, zpos, xform=None): # to the shader variable if xform is None: xform = np.identity(4) - w2w = np.array(xform, dtype=np.float32).ravel('C') - w2v = np.array(image.worldToVoxMat, dtype=np.float32).ravel('C') - tcx = np.array(glimg.texCoordXform, dtype=np.float32).ravel('C') + w2w = np.array(xform, dtype=np.float32).ravel('C') + w2v = np.array(display.displayToVoxMat, dtype=np.float32).ravel('C') + tcx = np.array(glimg.texCoordXform, dtype=np.float32).ravel('C') gl.glUniformMatrix4fv(glimg.worldToVoxMatPos, 1, False, w2v) gl.glUniformMatrix4fv(glimg.worldToWorldMatPos, 1, False, w2w) diff --git a/fsl/fslview/gl/glcircle.py b/fsl/fslview/gl/glcircle.py index 4be7ff3c3393c2fd9bd7c8dab43141646770991f..16f8d030d47fe757cf98927e1edeb8825e6a74c9 100644 --- a/fsl/fslview/gl/glcircle.py +++ b/fsl/fslview/gl/glcircle.py @@ -10,6 +10,8 @@ import logging log = logging.getLogger(__name__) import numpy as np + +import fsl.utils.transform as transform import fsl.fslview.gl as fslgl import fsl.fslview.gl.glimage as glimage @@ -27,21 +29,22 @@ class GLCircle(glimage.GLImage): def genVertexData(image, display, xax, yax): - zax = 3 - xax - yax - worldRes = display.worldResolution - voxelRes = display.voxelResolution - transform = display.transform + zax = 3 - xax - yax + worldRes = display.worldResolution + voxelRes = display.voxelResolution + transformCode = display.transform + transformMat = display.voxToDisplayMat # These values give the min/max x/y values # of a bounding box which encapsulates # the entire image - xmin, xmax = image.imageBounds(xax) - ymin, ymax = image.imageBounds(yax) + xmin, xmax = transform.axisBounds(image.shape, transformMat, xax) + ymin, ymax = transform.axisBounds(image.shape, transformMat, yax) # The width/height of a displayed voxel. # If we are displaying in real world space, # we use the world display resolution - if transform in ('affine'): + if transformCode in ('affine'): xpixdim = worldRes ypixdim = worldRes @@ -64,7 +67,7 @@ def genVertexData(image, display, xax, yax): log.debug('Generating coordinate buffers for {} ' '({} resolution {}/{}, num samples {})'.format( - image.name, transform, worldRes, voxelRes, + image.name, transformCode, worldRes, voxelRes, xNumSamples * yNumSamples)) # The location of every displayed diff --git a/fsl/fslview/gl/globject.py b/fsl/fslview/gl/globject.py index 43022578080a49174e97d08c56f62928d66a7c7b..ada9fcb28ee032eabc5a799e612b348240554d40 100644 --- a/fsl/fslview/gl/globject.py +++ b/fsl/fslview/gl/globject.py @@ -18,7 +18,8 @@ GL Objects must have the following methods: import logging log = logging.getLogger(__name__) -import numpy as np +import numpy as np +import fsl.utils.transform as transform def createGLObject(image, display): @@ -68,20 +69,21 @@ def calculateSamplePoints(image, display, xax, yax): """ - worldRes = display.worldResolution - voxelRes = display.voxelResolution - transform = display.transform + worldRes = display.worldResolution + voxelRes = display.voxelResolution + transformCode = display.transform + transformMat = display.voxToDisplayMat # These values give the min/max x/y values # of a bounding box which encapsulates # the entire image - xmin, xmax = image.imageBounds(xax) - ymin, ymax = image.imageBounds(yax) + xmin, xmax = transform.axisBounds(image.shape, transformMat, xax) + ymin, ymax = transform.axisBounds(image.shape, transformMat, yax) # The width/height of a displayed voxel. # If we are displaying in real world space, # we use the world display resolution - if transform in ('affine'): + if transformCode in ('affine'): xpixdim = worldRes ypixdim = worldRes @@ -104,7 +106,7 @@ def calculateSamplePoints(image, display, xax, yax): log.debug('Generating coordinate buffers for {} ' '({} resolution {}/{}, num samples {})'.format( - image.name, transform, worldRes, voxelRes, + image.name, transformCode, worldRes, voxelRes, xNumSamples * yNumSamples)) # The location of every displayed diff --git a/fsl/fslview/gl/gltensorline.py b/fsl/fslview/gl/gltensorline.py index 0f9653b82b8277e6182f7cf7022ca55c4f3869bd..007ec2d23b22735c0d6d3ebf5874f94c8bc5ec50 100644 --- a/fsl/fslview/gl/gltensorline.py +++ b/fsl/fslview/gl/gltensorline.py @@ -18,6 +18,8 @@ import scipy.ndimage as ndi import globject +import fsl.utils.transform as transform + class GLTensorLine(object): """The :class:`GLTensorLine` class encapsulates the data and logic required to render 2D slices of a X*Y*Z*3 image as tensor lines. @@ -104,7 +106,9 @@ class GLTensorLine(object): # Transform the world coordinates to # floating point voxel coordinates - voxCoords = image.worldToVox(worldCoords).transpose() + dToVMat = display.displayToVoxMat + + voxCoords = transform.transform(worldCoords, dToVMat).transpose() imageData = image.data nVoxels = worldCoords.shape[0] diff --git a/fsl/utils/transform.py b/fsl/utils/transform.py index b564ce0e290cc2d221deab3c55c2a905cd6b208b..9cf3b688e201b3e6de8b0f844e48af0a84d9aee4 100644 --- a/fsl/utils/transform.py +++ b/fsl/utils/transform.py @@ -60,7 +60,7 @@ def axisLength(shape, x, axis): return sum((tx[0, :] - tx[1, :]) ** 2) ** 0.5 -def transform(p, x, axes): +def transform(p, x, axes=None): """Transforms the given set of points ``p`` according to the given affine transformation ``x``. The transformed points are returned as a :class:``numpy.float64`` array.