Commit 457f686d authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

RF: GL21 line vector lengths are now pre-scaled, instead of being scaled in

vertex shader. This is so that colours can be scaled too. Not quite correct yet.
parent 80fefb44
......@@ -56,12 +56,6 @@ uniform bool xFlip;
*/
uniform bool directed;
/*
* If true, each vector is scaled to have a length
* of 1*lengthScale in the image coordinate system.
*/
uniform bool unitLength;
/*
* Scale vector lengths by this amount.
*/
......@@ -134,20 +128,6 @@ void main(void) {
return;
}
if (unitLength) {
/*
* Scale the vector so it has length 0.5.
*/
vector /= 2 * vectorLen;
/*
* Scale the vector by the minimum voxel length,
* so it is a unit vector within real world space
*/
vector /= imageDims / min(imageDims.x, min(imageDims.y, imageDims.z));
}
vector *= lengthScale;
/*
......
......@@ -207,7 +207,7 @@ void main(void) {
/*
* Combine the xyz component colours.
* Opacity should be ident0ical across
* Opacity should be identical across
* the three colours.
*/
vec4 voxColour = voxValue.x * xColour +
......
......@@ -65,7 +65,6 @@ def init(self):
# changes.
self.opts.addListener('orientFlip', name, update, weak=False)
self.opts.addListener('directed', name, update, weak=False)
self.opts.addListener('unitLength', name, update, weak=False)
self.opts.addListener('lengthScale', name, update, weak=False)
self.opts.addListener('transform',
name,
......@@ -79,7 +78,6 @@ def destroy(self):
self.opts.removeListener('orientFlip', self.name)
self.opts.removeListener('directed', self.name)
self.opts.removeListener('unitLength', self.name)
self.opts.removeListener('lengthScale', self.name)
self.opts.removeListener('transform', self.name)
......@@ -114,7 +112,6 @@ def updateShaderState(self):
vvxMat = self.imageTexture.voxValXform
directed = opts.directed
unitLength = opts.unitLength
lengthScale = opts.lengthScale / 100.0
imageDims = image.pixdim[:3]
d2vMat = opts.getTransform('display', 'voxel')
......@@ -127,7 +124,6 @@ def updateShaderState(self):
changed |= shader.set('voxValXform', vvxMat)
changed |= shader.set('imageDims', imageDims)
changed |= shader.set('directed', directed)
changed |= shader.set('unitLength', unitLength)
changed |= shader.set('lengthScale', lengthScale)
changed |= shader.set('xFlip', xFlip)
......
......@@ -68,17 +68,52 @@ class GLLineVector(glvector.GLVector):
if isinstance(image, dtifit.DTIFitTensor): vecImage = image.V1()
else: vecImage = image
def prefilter(data):
# Scale to unit length if required.
if not self.opts.unitLength:
return data
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))
return data
def prefilterRange(dmin, dmax):
if self.opts.unitLength: return 0, 0.5 # todo pixdim
else: return dmin, dmax
glvector.GLVector.__init__(self,
image,
overlayList,
displayCtx,
canvas,
threedee,
prefilter=prefilter,
prefilterRange=prefilterRange,
vectorImage=vecImage,
init=lambda: fslgl.gllinevector_funcs.init(
self))
self.opts.addListener('lineWidth', self.name, self.notify)
self.opts.addListener('lineWidth', self.name, self.notify)
self.opts.addListener('unitLength', self.name,
self.__unitLengthChanged)
def destroy(self):
......@@ -87,7 +122,8 @@ class GLLineVector(glvector.GLVector):
instance, calls the OpenGL version-specific ``destroy``
function, and calls the :meth:`.GLVector.destroy` method.
"""
self.opts.removeListener('lineWidth', self.name)
self.opts.removeListener('lineWidth', self.name)
self.opts.removeListener('unitLength', self.name)
fslgl.gllinevector_funcs.destroy(self)
glvector.GLVector.destroy(self)
......@@ -157,6 +193,13 @@ class GLLineVector(glvector.GLVector):
fslgl.gllinevector_funcs.postDraw(self, xform, bbox)
def __unitLengthChanged(self, *a):
"""Called when the :attr:`.LineVectorOptsunitLength` property
changes. Refreshes the vector image texture data.
"""
self.imageTexture.refresh()
class GLLineVertices(object):
"""The ``GLLineVertices`` class is used when rendering a
:class:`GLLineVector` with OpenGL 1.4. It contains logic to generate
......
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