Commit ca92420a authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

RF: Fix line vector rendering - vector data is used for both colouring and

vector length, so the shader is passed colour-scaled data, and lenghtScale
option is used to correct the vector length
parent 457f686d
......@@ -82,11 +82,9 @@ varying vec4 fragColourFactor;
void main(void) {
vec3 texCoord;
vec3 vector;
vec3 voxCoord;
float vectorLen;
vec3 texCoord;
vec3 vector;
vec3 voxCoord;
/*
* Normalise the voxel coordinates to [0.0, 1.0],
......@@ -108,13 +106,13 @@ void main(void) {
* texture range of [0,1] to the original
* data range
*/
vector *= voxValXform[0].x;
vector += voxValXform[3].x;
vectorLen = length(vector);
vector *= voxValXform[0].x;
vector += voxValXform[3].x;
/* Invert about the x axis if necessary */
if (xFlip)
if (xFlip) {
vector.x = -vector.x;
}
/*
* Kill the vector if its length is 0.
......@@ -123,7 +121,7 @@ void main(void) {
* from the texture data range. This
* may end up being too tolerant.
*/
if (vectorLen < 0.0001) {
if (length(vector) < 0.0001) {
fragColourFactor = vec4(0, 0, 0, 0);
return;
}
......
......@@ -118,6 +118,20 @@ def updateShaderState(self):
v2dMat = opts.getTransform('voxel', 'display')
xFlip = opts.orientFlip
# If the unitLength option is on, the vector
# data will have already been scaled to have
# length 1 (see GLLineVector.__init__). But
# we draw vectors in two parts, from the voxel
# centre. So we have to half the vector lengths.
if opts.unitLength:
lengthScale /= 2
# We also scale the vector data by the
# minimum voxel length, so that each
# vector has unit length relative to
# the voxel dimensions.
fac = (image.pixdim[:3] / min(image.pixdim[:3]))
lengthScale /= fac
changed |= shader.set('vectorTexture', 4)
changed |= shader.set('displayToVoxMat', d2vMat)
changed |= shader.set('voxToDisplayMat', v2dMat)
......
......@@ -76,28 +76,25 @@ class GLLineVector(glvector.GLVector):
data = np.copy(data)
with np.errstate(invalid='ignore'):
# calculate lengths
x = data[0, ...]
y = data[1, ...]
z = data[2, ...]
lens = np.sqrt(x ** 2 + y ** 2 + z ** 2)
# scale lengths to 0.5
data[0, ...] = 0.5 * x / lens
data[1, ...] = 0.5 * y / lens
data[2, ...] = 0.5 * z / lens
# Scale the vector data by the minimum
# voxel length, so it is a unit vector
# within real world space
fac = (image.pixdim[:3] / min(image.pixdim[:3]))
data /= fac.reshape((3, 1, 1, 1))
# scale lengths to 1
data[0, ...] = x / lens
data[1, ...] = y / lens
data[2, ...] = z / lens
return data
def prefilterRange(dmin, dmax):
if self.opts.unitLength: return 0, 0.5 # todo pixdim
else: return dmin, dmax
if self.opts.unitLength:
return 0, 1.0
else:
return dmin, dmax
glvector.GLVector.__init__(self,
image,
......@@ -198,9 +195,10 @@ class GLLineVector(glvector.GLVector):
changes. Refreshes the vector image texture data.
"""
self.imageTexture.refresh()
self.updateShaderState()
class GLLineVertices(object):
class GLLineVertices:
"""The ``GLLineVertices`` class is used when rendering a
:class:`GLLineVector` with OpenGL 1.4. It contains logic to generate
vertices for every vector in the vector :class:`.Image` that is being
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment