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

Render was not setting canvas background colours correctly. And now that

SliceCanvas has a bgColour attribute, there is no longer a need for the
OSMesaCanvasTarget to maintain its own bgColour.
parent 77bdc0a6
No related branches found
No related tags found
No related merge requests found
......@@ -330,24 +330,21 @@ class OSMesaCanvasTarget(object):
OSMesa.
"""
def __init__(self, width, height, bgColour=(0, 0, 0, 255)):
def __init__(self, width, height):
"""Creates an off-screen buffer to be used as the render target.
:arg width: Width in pixels
:arg height: Height in pixels
:arg bgColour: Background colour as an RGBA tuple
(e.g. (255, 255, 255, 255))
"""
import OpenGL.arrays as glarrays
self._width = width
self._height = height
self._bgColour = bgColour
self._buffer = glarrays.GLubyteArray.zeros((height, width, 4))
self.__width = width
self.__height = height
self.__buffer = glarrays.GLubyteArray.zeros((height, width, 4))
def _getSize(self):
"""Returns a tuple containing the canvas width and height."""
return self._width, self._height
return self.__width, self.__height
def _setGLContext(self):
......@@ -355,10 +352,10 @@ class OSMesaCanvasTarget(object):
import OpenGL.raw.osmesa.mesa as osmesa
"""Configures the GL context to render to this canvas. """
osmesa.OSMesaMakeCurrent(getOSMesaContext(),
self._buffer,
self.__buffer,
gl.GL_UNSIGNED_BYTE,
self._width,
self._height)
self.__width,
self.__height)
return True
......@@ -383,11 +380,8 @@ class OSMesaCanvasTarget(object):
subclasses.
"""
import OpenGL.GL as gl
self._initGL()
self._setGLContext()
gl.glClearColor(*self._bgColour)
self._draw()
......@@ -404,12 +398,12 @@ class OSMesaCanvasTarget(object):
bmp = gl.glReadPixels(
0, 0,
self._width, self._height,
self.__width, self.__height,
gl.GL_RGBA,
gl.GL_UNSIGNED_BYTE)
bmp = np.fromstring(bmp, dtype=np.uint8)
bmp = bmp.reshape((self._height, self._width, 4))
bmp = bmp.reshape((self.__height, self.__width, 4))
bmp = np.flipud(bmp)
return bmp
......
......@@ -28,20 +28,16 @@ class OSMesaLightBoxCanvas(lightboxcanvas.LightBoxCanvas,
displayCtx,
zax=0,
width=0,
height=0,
bgColour=(0, 0, 0, 255)):
height=0):
"""See the :class:`.LightBoxCanvas` constructor for details on the other
parameters.
:arg width: Canvas width in pixels
:arg height: Canvas height in pixels
:arg bgColour: Canvas background colour
"""
fslgl.OSMesaCanvasTarget .__init__(self, width, height, bgColour)
fslgl.OSMesaCanvasTarget .__init__(self, width, height)
lightboxcanvas.LightBoxCanvas.__init__(self,
overlayList,
displayCtx,
......
......@@ -28,17 +28,14 @@ class OSMesaSliceCanvas(sc.SliceCanvas,
displayCtx,
zax=0,
width=0,
height=0,
bgColour=(0, 0, 0, 255)):
height=0):
"""See the :class:`.SliceCanvas` constructor for details on the other
parameters.
:arg width: Canvas width in pixels
:arg height: Canvas height in pixels
:arg bgColour: Canvas background colour
"""
fslgl.OSMesaCanvasTarget.__init__(self, width, height, bgColour)
fslgl.OSMesaCanvasTarget.__init__(self, width, height)
sc.SliceCanvas .__init__(self, overlayList, displayCtx, zax)
......@@ -136,7 +136,7 @@ def buildLabelBitmaps(overlayList,
height=height,
fontSize=12,
fgColour=fgColour,
bgColour=map(lambda c: c / 255.0, bgColour),
bgColour=bgColour,
alpha=alpha)
labelBmps.append(allLabels)
......@@ -184,7 +184,7 @@ def buildColourBarBitmap(overlayList,
display.name,
orient,
labelSide,
bgColour=map(lambda c: c / 255.0, bgColour))
bgColour=bgColour)
# The colourBarBitmap function returns a w*h*4
# array, but the fsl.utils.layout.Bitmap (see
......@@ -345,8 +345,7 @@ def run(args, context):
displayCtx,
zax=sceneOpts.zax,
width=width,
height=height,
bgColour=args.bgColour)
height=height)
props.applyArguments(c, args)
canvases.append(c)
......@@ -405,8 +404,7 @@ def run(args, context):
displayCtx,
zax=zax,
width=int(width),
height=int(height),
bgColour=args.bgColour)
height=int(height))
if zoom is not None: c.zoom = zoom
c.centreDisplayAt(*centre)
......@@ -416,7 +414,8 @@ def run(args, context):
# properties that are common to both ortho and
# lightbox canvases) and render them one by one
for i, c in enumerate(canvases):
c.bgColour = sceneOpts.bgColour
c.showCursor = sceneOpts.showCursor
if c.zax == 0: c.pos.xyz = displayCtx.location.yzx
elif c.zax == 1: c.pos.xyz = displayCtx.location.xzy
......@@ -435,8 +434,8 @@ def run(args, context):
displayCtx,
canvasAxes,
canvases,
args.bgColour[:3],
args.bgColour[ 3])
sceneOpts.bgColour[:3],
sceneOpts.bgColour[ 3])
# layout
if args.scene == 'lightbox':
......@@ -456,7 +455,7 @@ def run(args, context):
cbarHeight,
sceneOpts.colourBarLocation,
sceneOpts.colourBarLabelSide,
args.bgColour)
sceneOpts.bgColour)
if cbarBmp is not None:
layout = buildColourBarLayout(layout,
cbarBmp,
......@@ -467,7 +466,8 @@ def run(args, context):
if args.outfile is not None:
import matplotlib.image as mplimg
bitmap = fsllayout.layoutToBitmap(layout, args.bgColour)
bitmap = fsllayout.layoutToBitmap(
layout, [c * 255 for c in sceneOpts.bgColour])
mplimg.imsave(args.outfile, bitmap)
......@@ -511,8 +511,6 @@ def context(args):
overlayList = fsloverlay.OverlayList()
displayCtx = displaycontext.DisplayContext(overlayList)
# TODO rewrite for non-volumetric
#
# The handleOverlayArgs function uses the
# fsl.fsleyes.overlay.loadOverlays function,
# which will call these functions as it
......
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