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

GL14 clipping range support

parent 7f6f9365
No related branches found
No related tags found
No related merge requests found
...@@ -117,8 +117,11 @@ class VolumeOpts(fsldisplay.DisplayOpts): ...@@ -117,8 +117,11 @@ class VolumeOpts(fsldisplay.DisplayOpts):
self.clippingRange.setLimits(0, self.clippingRange.setLimits(0,
self.dataMin - dMinDistance, self.dataMin - dMinDistance,
self.dataMax + dMinDistance) self.dataMax + dMinDistance)
# By default, the lowest values
# in the image are clipped
self.clippingRange.setRange( 0, self.clippingRange.setRange( 0,
self.dataMin, self.dataMin + dMinDistance,
self.dataMax + dMinDistance) self.dataMax + dMinDistance)
self.displayRange.setRange(0, self.dataMin, self.dataMax) self.displayRange.setRange(0, self.dataMin, self.dataMax)
......
...@@ -37,7 +37,12 @@ ...@@ -37,7 +37,12 @@
# (y), and alpha (z) values to pass to the # (y), and alpha (z) values to pass to the
# briconalpha.prog routine. # briconalpha.prog routine.
# #
# program.local[7] - If greater than or equal to 0, fragment.texcoord[1] # program.local[7] - Vector containing clipping values - voxels with a
# value below the low threshold (x), or above the
# high threshold (y) will not be shown. Assumed to
# be normalised to the image texture value range.
#
# program.local[8] - If greater than or equal to 0, fragment.texcoord[1]
# is used as the coordinates for the texture lookup. # is used as the coordinates for the texture lookup.
# Otherwise, fragment.texcoord[2] is used for the # Otherwise, fragment.texcoord[2] is used for the
# texture lookup. # texture lookup.
...@@ -50,6 +55,7 @@ ...@@ -50,6 +55,7 @@
# #
TEMP voxCoord; TEMP voxCoord;
TEMP voxClip;
TEMP normVoxCoord; TEMP normVoxCoord;
TEMP voxValue; TEMP voxValue;
TEMP fragColour; TEMP fragColour;
...@@ -57,7 +63,8 @@ TEMP fragColour; ...@@ -57,7 +63,8 @@ TEMP fragColour;
PARAM imageShape = program.local[4]; PARAM imageShape = program.local[4];
PARAM imageShapeInv = program.local[5]; PARAM imageShapeInv = program.local[5];
PARAM bca = program.local[6]; PARAM bca = program.local[6];
PARAM useTexCoords = program.local[7]; PARAM clipping = program.local[7];
PARAM useTexCoords = program.local[8];
# This matrix scales the voxel value to # This matrix scales the voxel value to
# lie in a range which is appropriate to # lie in a range which is appropriate to
...@@ -90,6 +97,17 @@ MUL normVoxCoord, voxCoord, imageShapeInv; ...@@ -90,6 +97,17 @@ MUL normVoxCoord, voxCoord, imageShapeInv;
# from 3D image texture # from 3D image texture
TEX voxValue, normVoxCoord, texture[0], 3D; TEX voxValue, normVoxCoord, texture[0], 3D;
# If the voxel value is outside the
# clipping range, don't draw it
# Test the low clipping range
SUB voxClip, voxValue.x, clipping.x;
KIL voxClip;
# And the high clipping range
SUB voxClip, clipping.y, voxValue.x;
KIL voxClip;
# Scale voxel value according # Scale voxel value according
# to the current display range # to the current display range
MAD voxValue, voxValue, voxValXform[0].x, voxValXform[0].w; MAD voxValue, voxValue, voxValXform[0].x, voxValXform[0].w;
...@@ -98,7 +116,4 @@ MAD voxValue, voxValue, voxValXform[0].x, voxValXform[0].w; ...@@ -98,7 +116,4 @@ MAD voxValue, voxValue, voxValXform[0].x, voxValXform[0].w;
# in the 1D colour map texture # in the 1D colour map texture
TEX result.color, voxValue.x, texture[1], 1D; TEX result.color, voxValue.x, texture[1], 1D;
# Colour the pixel!
# #pragma include briconalpha.prog
END END
...@@ -83,6 +83,9 @@ def preDraw(self): ...@@ -83,6 +83,9 @@ def preDraw(self):
:class:`~fsl.fslview.gl.glvolume.GLVolume` instance. :class:`~fsl.fslview.gl.glvolume.GLVolume` instance.
""" """
display = self.display
opts = self.displayOpts
# enable drawing from a vertex array # enable drawing from a vertex array
gl.glEnableClientState(gl.GL_VERTEX_ARRAY) gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY) gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)
...@@ -100,7 +103,7 @@ def preDraw(self): ...@@ -100,7 +103,7 @@ def preDraw(self):
# able to transform from display # able to transform from display
# coordinates to voxel coordinates # coordinates to voxel coordinates
shaders.setVertexProgramMatrix( shaders.setVertexProgramMatrix(
0, self.display.getTransform('display', 'voxel').T) 0, display.getTransform('display', 'voxel').T)
# The voxValXform transformation turns # The voxValXform transformation turns
# an image texture value into a raw # an image texture value into a raw
...@@ -125,12 +128,24 @@ def preDraw(self): ...@@ -125,12 +128,24 @@ def preDraw(self):
# the fragment program # the fragment program
shape = list(self.image.shape) shape = list(self.image.shape)
invshape = [1.0 / s for s in shape] invshape = [1.0 / s for s in shape]
bca = [self.display.brightness / 100.0, bca = [display.brightness / 100.0,
self.display.contrast / 100.0, display.contrast / 100.0,
self.display.alpha / 100.0] display.alpha / 100.0]
# And the clipping range, normalised
# to the image texture value range
clipLo = opts.clippingRange.xlo * \
self.imageTexture.invVoxValXform[0, 0] + \
self.imageTexture.invVoxValXform[3, 0]
clipHi = opts.clippingRange.xhi * \
self.imageTexture.invVoxValXform[0, 0] + \
self.imageTexture.invVoxValXform[3, 0]
shaders.setFragmentProgramVector(4, shape + [0]) shaders.setFragmentProgramVector(4, shape + [0])
shaders.setFragmentProgramVector(5, invshape + [0]) shaders.setFragmentProgramVector(5, invshape + [0])
shaders.setFragmentProgramVector(6, bca + [0]) shaders.setFragmentProgramVector(6, bca + [0])
shaders.setFragmentProgramVector(7, [clipLo, clipHi, 0, 0])
def draw(self, zpos, xform=None): def draw(self, zpos, xform=None):
...@@ -169,7 +184,7 @@ def drawAll(self, zposes, xforms): ...@@ -169,7 +184,7 @@ def drawAll(self, zposes, xforms):
# Instead, tell the vertex # Instead, tell the vertex
# program to use texture coordinates # program to use texture coordinates
shaders.setFragmentProgramVector(7, -np.ones(4)) shaders.setFragmentProgramVector(8, -np.ones(4))
worldCoords = np.array(self.worldCoords) worldCoords = np.array(self.worldCoords)
indices = np.array(self.indices) indices = np.array(self.indices)
......
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