Skip to content
Snippets Groups Projects
Commit 735a0e58 authored by Paul McCarthy's avatar Paul McCarthy
Browse files

GL buffer handle is now stored in fslimage.Image object. Removed notion of...

GL buffer handle is now stored in fslimage.Image object. Removed notion of 'master' canvas from SliceCanvas - a shared GL context may be passed in directly. BUT if a shared context is not used, and the program attempts to share image buffers, it will segfault. Need to think about that one.
parent 11311c9c
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python
#
# fslimage.py - Classes representing a 3D image, and the display
# properties of a 3D image.
# fslimage.py - Classes representing a 3D image, the display
# properties of a 3D image, and a collection of 3D images.
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
......@@ -51,6 +51,8 @@ class Image(object):
self.ylen = ylen
self.zlen = zlen
self.glBuffer = None
class ImageDisplay(props.HasProperties):
"""
......@@ -107,3 +109,14 @@ class ImageDisplay(props.HasProperties):
self.dataMax = self.image.data.max()
self.displayMin = self.dataMin # use cal_min/cal_max instead?
self.displayMax = self.dataMax
class ImageList(object):
def __init__(self, images=None, displays=None):
if images is None: images = []
if displays is None: displays = []
self._images = images
self._displays = displays
......@@ -51,9 +51,9 @@ class ImageView(wx.Panel):
self.xcanvas = slicecanvas.SliceCanvas(
self.canvasPanel, self.imageDisplay, zax=0)
self.ycanvas = slicecanvas.SliceCanvas(
self.canvasPanel, self.imageDisplay, zax=1, master=self.xcanvas)
self.canvasPanel, self.imageDisplay, zax=1, context=self.xcanvas.context)
self.zcanvas = slicecanvas.SliceCanvas(
self.canvasPanel, self.imageDisplay, zax=2, master=self.xcanvas)
self.canvasPanel, self.imageDisplay, zax=2, context=self.xcanvas.context)
self.mainSizer = wx.BoxSizer(wx.VERTICAL)
self.canvasSizer = wx.BoxSizer(wx.HORIZONTAL)
......
......@@ -39,8 +39,7 @@ import fsl.data.fslimage as fslimage
# The third buffer, the 'image buffer' contains the image data itself,
# scaled to lie between 0.0 and 1.0. It is used to calculate voxel
# colours, and may be shared between multiple SliceCanvas objects
# which are displaying the same image - see the 'master' parameter to
# the SliceCanvas constructor.
# which are displaying the same image.
#
# Finally, the texture, the 'colour buffer', is used to store a
# lookup table containing colours.
......@@ -190,7 +189,8 @@ class SliceCanvas(wxgl.GLCanvas):
self._colourResolution = colourResolution
def __init__(self, parent, image, zax=0, zpos=None, master=None, **kwargs):
def __init__(
self, parent, image, zax=0, zpos=None, context=None, **kwargs):
"""
Creates a canvas object. The OpenGL data buffers are set up in
_initGLData the first time that the canvas is displayed/drawn.
......@@ -204,12 +204,11 @@ class SliceCanvas(wxgl.GLCanvas):
zax - Axis perpendicular to the plane to be displayed
(the 'depth' axis), default 0.
context -
zpos - Initial slice to be displayed. If not provided, the
middle slice is used.
master - Another SliceCanvas object with which to share the
GL context and the image buffer data.
"""
realImage = None
......@@ -229,10 +228,8 @@ class SliceCanvas(wxgl.GLCanvas):
wxgl.GLCanvas.__init__(self, parent, **kwargs)
if master is not None: context = master.context
else: context = wxgl.GLContext(self)
if context is None: context = wxgl.GLContext(self)
self.master = master
self.context = context
# TODO Currently, the displayed x/horizontal and
......@@ -267,11 +264,10 @@ class SliceCanvas(wxgl.GLCanvas):
self._colourResolution = 256
# these attributes are created by _initGLData,
# which is called on the first EVT_PAINT event
self.geomBuffer = None
self.positionBuffer = None
self.imageBuffer = None
# This flag is set by the _initGLData method
# when it has finished initialising the OpenGL
# data buffers
self.glReady = False
self.Bind(wx.EVT_PAINT, self.draw)
......@@ -360,6 +356,8 @@ class SliceCanvas(wxgl.GLCanvas):
self.colourBuffer = gl.glGenTextures(1)
self.updateColourBuffer()
self.glReady = True
def _initImageBuffer(self):
"""
......@@ -370,8 +368,8 @@ class SliceCanvas(wxgl.GLCanvas):
# If a master canvas was passed to the
# constructor, let's share its image data.
if self.master is not None:
return self.master.imageBuffer
if self.image.glBuffer is not None:
return self.image.glBuffer
# The image data is cast to single precision floating
# point, and normalised to lie between 0.0 and 1.0
......@@ -385,6 +383,8 @@ class SliceCanvas(wxgl.GLCanvas):
imageData = imageData.ravel(order='F')
imageBuffer = vbo.VBO(imageData, gl.GL_STATIC_DRAW)
self.image.glBuffer = imageBuffer
return imageBuffer
......@@ -473,7 +473,7 @@ class SliceCanvas(wxgl.GLCanvas):
"""
# image data has not been initialised.
if not self.imageBuffer:
if not self.glReady:
wx.CallAfter(self._initGLData)
return
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment