From 177f0c615901fb1e80d327d0b839739337e886cc Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauld.mccarthy@gmail.com> Date: Thu, 29 Jan 2015 16:45:14 +0000 Subject: [PATCH] GL14 tensor lines now wotk with any transformation - the code was previously assuming that voxel axes equaled display space axes. Also, bugfix in transform.scaleOffsetXform --- fsl/fslview/gl/gl14/gltensor_frag.prog | 14 ++++++++------ fsl/fslview/gl/gl14/gltensor_line_funcs.py | 21 ++++++++------------- fsl/utils/transform.py | 4 ++-- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/fsl/fslview/gl/gl14/gltensor_frag.prog b/fsl/fslview/gl/gl14/gltensor_frag.prog index c97343333..72c560417 100644 --- a/fsl/fslview/gl/gl14/gltensor_frag.prog +++ b/fsl/fslview/gl/gl14/gltensor_frag.prog @@ -54,13 +54,15 @@ TEX voxValue, normVoxCoord, texture[0], 3D; ADD voxValue, voxValue, { 0.0, 0.0, 0.0, 1.0 }; # Look up the modulation value -# from the modulation texture +# from the modulation texture - +# initialise modValue transparency +# to 1.0, so it doesn't corrupt +# our voxel colour value later on +MOV modValue, { 0.0, 0.0, 0.0, 1.0 }; TEX modValue, normVoxCoord, texture[1], 3D; -ADD modValue, modValue, { 0.0, 0.0, 0.0, 1.0 }; -# Use those values to look up -# the colours for each xyz -# direction +# Use those values to look up the +# colours for each xyz direction TEX xColour, voxValue.x, texture[2], 1D; TEX yColour, voxValue.y, texture[3], 1D; TEX zColour, voxValue.z, texture[4], 1D; @@ -71,7 +73,7 @@ MOV voxColour, xColour; ADD voxColour, voxColour, yColour; ADD voxColour, voxColour, zColour; -# But take the average of the alpha channel +# Take the average of the alpha channel MUL voxColour, voxColour, { 1.0, 1.0, 1.0, 0.333333 }; # Apply the modulation factor diff --git a/fsl/fslview/gl/gl14/gltensor_line_funcs.py b/fsl/fslview/gl/gl14/gltensor_line_funcs.py index 37ea8033e..54569aa35 100644 --- a/fsl/fslview/gl/gl14/gltensor_line_funcs.py +++ b/fsl/fslview/gl/gl14/gltensor_line_funcs.py @@ -121,6 +121,7 @@ def draw(self, zpos, xform=None): # Transform the world coordinates to # floating point voxel coordinates dToVMat = display.displayToVoxMat + vToDMat = display.voxToDisplayMat voxCoords = transform.transform(worldCoords, dToVMat).transpose() imageData = image.data @@ -157,23 +158,17 @@ def draw(self, zpos, xform=None): # make a bunch of vertices which represent lines # (two vertices per line), centered at the origin # and scaled appropriately - vecs[:, xax] *= 0.5 * self.xpixdim - vecs[:, yax] *= 0.5 * self.ypixdim + vecs *= 0.5 + vecs = np.hstack((-vecs, vecs)).reshape((2 * nVoxels, 3)) - # Flatten on the depth axis - vecs[:, zax] = 0.0 - vecs = np.hstack((-vecs, vecs)).reshape((2 * nVoxels, 3)) - - # - # TODO The above code assumes a correspondence - # between the image array axes and the display - # coordinate system axes. I'm not currently - # sure how to get around this. - # + # Offset each of those vertices by + # their original voxel coordinates + vecs += voxCoords.T.repeat(2, 0) # Translate the world coordinates # by those line vertices - worldCoords = worldCoords.repeat(2, 0) + vecs + worldCoords = transform.transform(vecs, vToDMat) + worldCoords[:, zax] = zpos worldCoords = np.array(worldCoords, dtype=np.float32).ravel('C') # Draw all the lines! diff --git a/fsl/utils/transform.py b/fsl/utils/transform.py index f8d427ca3..b77526f25 100644 --- a/fsl/utils/transform.py +++ b/fsl/utils/transform.py @@ -44,8 +44,8 @@ def scaleOffsetXform(scales, offsets): xform[2, 2] = scales[2] xform[3, 0] = offsets[0] - xform[3, 1] = offsets[0] - xform[3, 2] = offsets[0] + xform[3, 1] = offsets[1] + xform[3, 2] = offsets[2] return xform -- GitLab