diff --git a/fsl/data/atlases.py b/fsl/data/atlases.py index c148916da2f4de86f23fa0732ad9ef87f9fdd8cf..41e7e0905afef577e62a151fd8779d404dd5e748 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 a61e4a663bd3c01a6e4548838ae12247aebb3712..78def2c1a48c65cb9bb06329d2c3c6383d97eaa1 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 6ca8a9004e41b85d2e0c7dadc2b734837f434807..d9f930dabf31882b4785b7f549e9785b75b9d7bf 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