From 9dbd4ec1b4d0b0950c29a4bf8a012b8b2f829069 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauld.mccarthy@gmail.com>
Date: Wed, 16 Dec 2015 22:52:10 +0000
Subject: [PATCH] Tensor scaling factor working.

---
 fsl/data/strings.py                         |  1 +
 fsl/fsleyes/controls/overlaydisplaypanel.py |  2 ++
 fsl/fsleyes/displaycontext/tensoropts.py    |  3 ++-
 fsl/fsleyes/gl/gl21/gltensor_funcs.py       |  6 ++++--
 fsl/fsleyes/gl/gltensor.py                  |  2 ++
 fsl/fsleyes/gl/shaders.py                   | 10 +++++++++-
 fsl/fsleyes/tooltips.py                     | 16 +++++++++++++++-
 7 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/fsl/data/strings.py b/fsl/data/strings.py
index acc7f1874..f52a33c3d 100644
--- a/fsl/data/strings.py
+++ b/fsl/data/strings.py
@@ -576,6 +576,7 @@ properties = TypeDict({
 
     'TensorOpts.lighting'          : 'Lighting effects',
     'TensorOpts.tensorResolution'  : 'Ellipsoid quality',
+    'TensorOpts.tensorScale'       : 'Tensor size',
 })
 
 
diff --git a/fsl/fsleyes/controls/overlaydisplaypanel.py b/fsl/fsleyes/controls/overlaydisplaypanel.py
index 00efee699..bcc874128 100644
--- a/fsl/fsleyes/controls/overlaydisplaypanel.py
+++ b/fsl/fsleyes/controls/overlaydisplaypanel.py
@@ -377,6 +377,7 @@ _DISPLAY_PROPS = td.TypeDict({
             spin=False,
             labels=[strings.choices['TensorOpts.tensorResolution.min'],
                     strings.choices['TensorOpts.tensorResolution.max']]),
+        props.Widget('tensorScale', showLimits=False, spin=False),
         props.Widget('xColour'),
         props.Widget('yColour'),
         props.Widget('zColour'),
@@ -385,6 +386,7 @@ _DISPLAY_PROPS = td.TypeDict({
         props.Widget('suppressZ'),
         props.Widget('modulateImage', labels=_imageName),
         props.Widget('clipImage',     labels=_imageName),
+        
         props.Widget('clipThreshold',
                      showLimits=False,
                      spin=False,
diff --git a/fsl/fsleyes/displaycontext/tensoropts.py b/fsl/fsleyes/displaycontext/tensoropts.py
index c3b15b34a..4061abffb 100644
--- a/fsl/fsleyes/displaycontext/tensoropts.py
+++ b/fsl/fsleyes/displaycontext/tensoropts.py
@@ -29,7 +29,8 @@ class TensorOpts(vectoropts.VectorOpts):
     :func:`.routines.unitSphere` function.
     """
 
-    tensorScale = props.Real(minval=0.0, maxval=5.0, default=1.0)
+    
+    tensorScale = props.Percentage(minval=50, maxval=600, default=100)
     """Scaling factor - by default, the tensor ellipsoids are scaled such that
     the biggest tensor (as defined by the first principal eigenvalue) fits
     inside a voxel. This parameter can be used to adjust this scale.
diff --git a/fsl/fsleyes/gl/gl21/gltensor_funcs.py b/fsl/fsleyes/gl/gl21/gltensor_funcs.py
index b38fbee52..ba5c87cbe 100644
--- a/fsl/fsleyes/gl/gl21/gltensor_funcs.py
+++ b/fsl/fsleyes/gl/gl21/gltensor_funcs.py
@@ -181,11 +181,13 @@ def updateShaderState(self):
     imageShape    = np.array(self.image.shape[:3], dtype=np.float32)
     resolution    = opts.tensorResolution
     clipThreshold = opts.clipThreshold
+    tensorScale   = opts.tensorScale
     lighting      = 1 if opts.lighting else 0
     useSpline     = 0
 
-    l1         = self.image.L1()
-    eigValNorm = 0.5 / abs(l1.data).max()
+    l1          = self.image.L1()
+    eigValNorm  = 0.5 / abs(l1.data).max()
+    eigValNorm *= tensorScale / 100.0
 
     invClipValXform = self.clipTexture .invVoxValXform
     clipThreshold   = clipThreshold * invClipValXform[0, 0] + \
diff --git a/fsl/fsleyes/gl/gltensor.py b/fsl/fsleyes/gl/gltensor.py
index 5df0291ac..8ef0097a3 100644
--- a/fsl/fsleyes/gl/gltensor.py
+++ b/fsl/fsleyes/gl/gltensor.py
@@ -58,6 +58,7 @@ class GLTensor(glvector.GLVector):
 
         opts.addListener('lighting',         name, shaderUpdate, weak=False)
         opts.addListener('tensorResolution', name, shaderUpdate, weak=False)
+        opts.addListener('tensorScale',      name, shaderUpdate, weak=False)
         
 
     def removeListeners(self):
@@ -71,6 +72,7 @@ class GLTensor(glvector.GLVector):
         
         opts.removeListener('lighting',         name)
         opts.removeListener('tensorResolution', name)
+        opts.removeListener('tensorScale',      name)
 
         
     def getDataResolution(self, xax, yax):
diff --git a/fsl/fsleyes/gl/shaders.py b/fsl/fsleyes/gl/shaders.py
index 6f503e053..ad9c40d77 100644
--- a/fsl/fsleyes/gl/shaders.py
+++ b/fsl/fsleyes/gl/shaders.py
@@ -121,7 +121,15 @@ def setFragmentProgramMatrix(index, matrix):
 
 
 def getShaderVars(shaders, vertAtts, vertUniforms, fragUniforms):
-    """
+    """Gets the position indices for all vertex shader attributes, uniforms,
+    and fragment shader uniforms for the given shader programs.
+
+    :arg shaders:
+    :arg vertAtts:
+    :arg vertUniforms:
+    :arg fragUniforms:
+
+    :returns:
     """
 
     import OpenGL.GL as gl
diff --git a/fsl/fsleyes/tooltips.py b/fsl/fsleyes/tooltips.py
index 37834889d..7afa7babf 100644
--- a/fsl/fsleyes/tooltips.py
+++ b/fsl/fsleyes/tooltips.py
@@ -186,7 +186,21 @@ properties = TypeDict({
                                'setting defines the space, relative to the '
                                'reference image, in which the model '
                                'coordinates are defined.',
-    
+
+    'TensorOpts.lighting'         : 'If enabled, a simple lighting model is '
+                                    'used to highlight the tensor '
+                                    'orientations.', 
+    'TensorOpts.tensorResolution' : 'This setting controls the number of '
+                                    'vertices used to render each tensor. '
+                                    'A higher value will result in better '
+                                    'looking tensors, but may reduce ' 
+                                    'performance.' ,
+    'TensorOpts.tensorScale'      : 'By default, the tensor radii are scaled '
+                                    'the largest eigenvalue of the tensor '
+                                    'matrix, so that the largest tensor is '
+                                    'drawn to fit within a voxel. This '
+                                    'setting allows the tensor scale to be '
+                                    'adjusted.',
     # SceneOpts
 
     'SceneOpts.showCursor'         : 'Show/hide the cursor which highlights '
-- 
GitLab