From 2275829437777fd820f9b6b26cf7ed327d9b9baf Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauld.mccarthy@gmail.com>
Date: Mon, 7 Dec 2015 16:25:25 +0000
Subject: [PATCH] Negative colour map control parameters are being passed into
 GL14 fragment program (but not used yet).

---
 fsl/fsleyes/gl/gl14/glvolume_frag.prog | 18 +++++++++++++++++-
 fsl/fsleyes/gl/gl14/glvolume_funcs.py  | 16 +++++++++-------
 2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/fsl/fsleyes/gl/gl14/glvolume_frag.prog b/fsl/fsleyes/gl/gl14/glvolume_frag.prog
index 7fe020ebf..387efb55e 100644
--- a/fsl/fsleyes/gl/gl14/glvolume_frag.prog
+++ b/fsl/fsleyes/gl/gl14/glvolume_frag.prog
@@ -38,6 +38,14 @@
 #                          the range). Clipping values are assumed to be
 #                          normalised to the image texture value range.
 #
+#   program.local[6]     - Negative colour map control. The (x) component
+#                          is a boolean flag controlling whether the negative
+#                          colour map is used. The (y) component is the display
+#                          range centre (the value above which the regular 
+#                          colour map is used, and below which the negative
+#                          colour map is used), as a voxel value, normalised to
+#                          the image texture value range.
+#  
 # Outputs:
 #
 #   result.color         - The fragment colour
@@ -49,9 +57,12 @@ TEMP  voxCoord;
 TEMP  voxClipLo;
 TEMP  voxClipHi;
 TEMP  voxValue;
+TEMP  posColour;
+TEMP  negColour;
 
 PARAM imageShape = program.local[4];
 PARAM clipping   = program.local[5];
+PARAM negCmap    = program.local[6];
   
 # This matrix scales the voxel value to
 # lie in a range which is appropriate to
@@ -71,6 +82,8 @@ MOV voxCoord, fragment.texcoord[1];
 # from 3D image texture
 TEX voxValue, fragment.texcoord[0], texture[0], 3D;
 
+
+
 # Test the low clipping range
 SUB voxClipLo, voxValue.x, clipping.x;
 
@@ -101,6 +114,9 @@ MAD voxValue, voxValue, voxValXform[0].x, voxValXform[3].x;
 
 # look up the appropriate colour
 # in the 1D colour map texture
-TEX result.color, voxValue.x, texture[1], 1D;
+TEX posColour, voxValue.x, texture[1], 1D;
+TEX negColour, voxValue.x, texture[2], 1D;
+
+MOV result.color, posColour;
 
 END
diff --git a/fsl/fsleyes/gl/gl14/glvolume_funcs.py b/fsl/fsleyes/gl/gl14/glvolume_funcs.py
index ea444b709..d3462b447 100644
--- a/fsl/fsleyes/gl/gl14/glvolume_funcs.py
+++ b/fsl/fsleyes/gl/gl14/glvolume_funcs.py
@@ -93,19 +93,21 @@ def updateShaderState(self):
 
     # And the clipping range, normalised
     # to the image texture value range
-    invClip = 1 if opts.invertClipping else -1
-    clipLo  = opts.clippingRange[0]            * \
-        self.imageTexture.invVoxValXform[0, 0] + \
-        self.imageTexture.invVoxValXform[3, 0]
-    clipHi  = opts.clippingRange[1]            * \
-        self.imageTexture.invVoxValXform[0, 0] + \
-        self.imageTexture.invVoxValXform[3, 0]
+    xform = self.imageTexture.invVoxValXform
+    
+    invClip    = 1 if opts.invertClipping     else -1
+    useNegCmap = 1 if opts.enableNegativeCmap else  0
+    
+    clipLo  = opts.clippingRange[0] * xform[0, 0] + xform[3, 0]
+    clipHi  = opts.clippingRange[1] * xform[0, 0] + xform[3, 0]
+    texZero = 0.0                   * xform[0, 0] + xform[3, 0]
     
     shaders.setVertexProgramVector(  0, shape + [0])
     
     shaders.setFragmentProgramMatrix(0, voxValXform)
     shaders.setFragmentProgramVector(4, shape + [0])
     shaders.setFragmentProgramVector(5, [clipLo, clipHi, invClip, 0])
+    shaders.setFragmentProgramVector(6, [useNegCmap, texZero, 0, 0])
 
     gl.glDisable(arbvp.GL_VERTEX_PROGRAM_ARB) 
     gl.glDisable(arbfp.GL_FRAGMENT_PROGRAM_ARB) 
-- 
GitLab