From 1c4a71a944b411b3cd861c9a82732f15efd1301b Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauld.mccarthy@gmail.com>
Date: Mon, 9 Mar 2015 15:15:13 +0000
Subject: [PATCH] SliceCanvas._refresh no longer calls _draw directly - back to
 calling Refresh. *But* the SliceCanvas position listener does call draw
 directly, thus hopefully achieving the same effect.

---
 fsl/data/atlases.py           | 17 +++++++++++++++++
 fsl/fslview/gl/__init__.py    |  6 +++---
 fsl/fslview/gl/slicecanvas.py | 14 ++++++--------
 3 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/fsl/data/atlases.py b/fsl/data/atlases.py
index c148916da..41e7e0905 100644
--- a/fsl/data/atlases.py
+++ b/fsl/data/atlases.py
@@ -256,6 +256,14 @@ class LabelAtlas(Atlas):
     def label(self, worldLoc):
 
         voxelLoc = transform.transform([worldLoc], self.worldToVoxMat.T)[0]
+
+        if voxelLoc[0] <  0             or \
+           voxelLoc[1] <  0             or \
+           voxelLoc[2] <  0             or \
+           voxelLoc[0] >= self.shape[0] or \
+           voxelLoc[1] >= self.shape[1] or \
+           voxelLoc[2] >= self.shape[2]:
+            return np.nan        
         
         val = self.data[voxelLoc[0], voxelLoc[1], voxelLoc[2]]
 
@@ -274,4 +282,13 @@ class ProbabilisticAtlas(Atlas):
         
     def proportions(self, worldLoc):
         voxelLoc = transform.transform([worldLoc], self.worldToVoxMat.T)[0]
+
+        if voxelLoc[0] <  0             or \
+           voxelLoc[1] <  0             or \
+           voxelLoc[2] <  0             or \
+           voxelLoc[0] >= self.shape[0] or \
+           voxelLoc[1] >= self.shape[1] or \
+           voxelLoc[2] >= self.shape[2]:
+            return np.nan
+        
         return self.data[voxelLoc[0], voxelLoc[1], voxelLoc[2], :]
diff --git a/fsl/fslview/gl/__init__.py b/fsl/fslview/gl/__init__.py
index a61e4a663..78def2c1a 100644
--- a/fsl/fslview/gl/__init__.py
+++ b/fsl/fslview/gl/__init__.py
@@ -273,7 +273,7 @@ class OSMesaCanvasTarget(object):
         pass
 
 
-    def _draw(self):
+    def _draw(self, *a):
         """Must be provided by subclasses."""
         raise NotImplementedError()
 
@@ -350,7 +350,7 @@ class WXGLCanvasTarget(object):
         raise NotImplementedError()
 
 
-    def _draw(self):
+    def _draw(self, *a):
         """Must be implemented by subclasses.
 
         This method should implement the OpenGL drawing logic.
@@ -402,7 +402,7 @@ class WXGLCanvasTarget(object):
         # because, when running over ssh under X11,
         # this doesn't seem to force a redraw. Calling
         # the draw code directly seems to do the trick
-        self._draw()
+        self.Refresh()
 
         
     def _postDraw(self):
diff --git a/fsl/fslview/gl/slicecanvas.py b/fsl/fslview/gl/slicecanvas.py
index 6ca8a9004..d9f930dab 100644
--- a/fsl/fslview/gl/slicecanvas.py
+++ b/fsl/fslview/gl/slicecanvas.py
@@ -276,14 +276,12 @@ class SliceCanvas(props.HasProperties):
 
         # when any of the properties of this
         # canvas change, we need to redraw
-        def refresh(*a): self._refresh()
-
         self.addListener('zax',           self.name, self._zAxisChanged)
-        self.addListener('pos',           self.name, refresh)
-        self.addListener('showCursor',    self.name, refresh)
-        self.addListener('displayBounds', self.name, refresh)
-        self.addListener('invertX',       self.name, refresh)
-        self.addListener('invertY',       self.name, refresh)
+        self.addListener('pos',           self.name, self._draw)
+        self.addListener('showCursor',    self.name, self._refresh)
+        self.addListener('displayBounds', self.name, self._refresh)
+        self.addListener('invertX',       self.name, self._refresh)
+        self.addListener('invertY',       self.name, self._refresh)
         self.addListener('zoom',
                          self.name,
                          lambda *a: self._updateDisplayBounds())
@@ -685,7 +683,7 @@ class SliceCanvas(props.HasProperties):
         self._annotations.line(yverts[0], yverts[1], colour=(0, 1, 0))
 
 
-    def _draw(self):
+    def _draw(self, *a):
         """Draws the current scene to the canvas. 
 
         Ths actual drawing is managed by the OpenGL version-dependent
-- 
GitLab