Commit 216d3233 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

RF: decouple tractogram from canvas

parent c166c157
......@@ -54,7 +54,7 @@ def compileShaders(self):
self.shaders[colourMode][clipMode].append(shader)
def draw2D(self, axes, mvp):
def draw2D(self, canvas, mvp):
"""Called by :class:`.GLTractogram.draw2D`. """
opts = self.opts
......@@ -66,7 +66,7 @@ def draw2D(self, axes, mvp):
# each vertex is drawn as a circle,
# using instanced rendering.
vertices = glroutines.unitCircle(res)
scales = self.normalisedLineWidth(mvp)
scales = self.normalisedLineWidth(canvas, mvp)
vertices[:, :2] *= scales[:2]
gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL)
......@@ -80,9 +80,8 @@ def draw2D(self, axes, mvp):
len(self.vertices))
def draw3D(self, xform=None):
def draw3D(self, canvas, xform=None):
"""Called by :class:`.GLTractogram.draw3D`. """
canvas = self.canvas
opts = self.opts
ovl = self.overlay
display = self.display
......
......@@ -86,13 +86,13 @@ def compileShaders(self):
self.shaders[colourMode][clipMode].extend(progs)
def draw2D(self, axes, mvp):
def draw2D(self, canvas, mvp):
"""Called by :class:`.GLTractogram.draw2D`. """
opts = self.opts
colourMode = opts.effectiveColourMode
clipMode = opts.effectiveClipMode
shader = self.shaders[colourMode][clipMode][0]
scales = self.normalisedLineWidth(mvp)
scales = self.normalisedLineWidth(canvas, mvp)
gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL)
......@@ -103,10 +103,9 @@ def draw2D(self, axes, mvp):
shader.draw(gl.GL_POINTS, 0, len(self.vertices))
def draw3D(self, xform=None):
def draw3D(self, canvas, xform=None):
"""Called by :class:`.GLTractogram.draw3D`. """
canvas = self.canvas
opts = self.opts
ovl = self.overlay
display = self.display
......@@ -118,7 +117,7 @@ def draw3D(self, xform=None):
lighting = canvas.opts.light
lightPos = affine.transform(canvas.lightPos, mvp)
nstrms = ovl.nstreamlines
lineWidth = self.normalisedLineWidth(mvp)
lineWidth = self.normalisedLineWidth(canvas, mvp)
offsets = self.offsets
counts = self.counts
nstrms = len(offsets)
......
......@@ -28,10 +28,10 @@ class GLTractogram(globject.GLObject):
overlays.
"""
def __init__(self, overlay, overlayList, displayCtx, canvas, threedee):
def __init__(self, overlay, overlayList, displayCtx, threedee):
"""Create a :meth:`GLTractogram`. """
globject.GLObject.__init__(
self, overlay, overlayList, displayCtx, canvas, threedee)
self, overlay, overlayList, displayCtx, threedee)
# Shaders are created in compileShaders.
# imageTexture created in refreshImageTexture
......@@ -234,7 +234,7 @@ class GLTractogram(globject.GLObject):
self.opts.bounds.getHi())
def normalisedLineWidth(self, mvp):
def normalisedLineWidth(self, canvas, mvp):
"""Returns :attr:`lineWidth`, scaled so that it is with respect to
normalised device coordinates. Streamline lines/tubes (in 3D) and
vertices (in 2D) are drawn such that the width/radius is fixed w.r.t.
......@@ -242,7 +242,8 @@ class GLTractogram(globject.GLObject):
lines/tubes/circles will be small when zoomed out, and big when
zoomed in.
:arg mvp: Current MVP matrix
:arg canvas: Canvas being drawn on
:arg mvp: Current MVP matrix
"""
# Line width is fixed at 0.1 in world
# units. Below we convert it so it is
......@@ -258,7 +259,6 @@ class GLTractogram(globject.GLObject):
# the future, as the ortho3D function is a bit
# nuts in how it handles depth (caused my my
# lack of understanding of near/far clipping).
canvas = self.canvas
scaling = affine.concat(canvas.projectionMatrix,
canvas.viewScale)
lineWidth = [lineWidth * scaling[0, 0],
......@@ -634,7 +634,7 @@ class GLTractogram(globject.GLObject):
self.clipImageTexture.bindTexture(gl.GL_TEXTURE3)
def draw2D(self, zpos, axes, xform=None):
def draw2D(self, canvas, zpos, axes, xform=None):
"""Draws a 2D slice through the tractogram. Calls
:func:`.gl21.gltractogram_funcs.draw2D` or
:func:`.gl33.gltractogram_funcs.draw2D`.
......@@ -643,9 +643,8 @@ class GLTractogram(globject.GLObject):
if xform is None:
xform = np.eye(4)
canvas = self.canvas
opts = self.opts
zax = axes[2]
opts = self.opts
zax = axes[2]
# We draw a 2D slice through the tractogram by
# manipulating the projection matrix so that z
......@@ -670,14 +669,14 @@ class GLTractogram(globject.GLObject):
strm2disp = opts.displayTransform
mvp = affine.concat(projmat, viewmat, xform, strm2disp)
fslgl.gltractogram_funcs.draw2D(self, axes, mvp)
fslgl.gltractogram_funcs.draw2D(self, canvas, mvp)
def draw3D(self, xform=None):
def draw3D(self, *args, **kwargs):
"""Calls :func:`.gl21.gltractogram_funcs.draw3D` or
:func:`.gl33.gltractogram_funcs.draw3D`.
"""
fslgl.gltractogram_funcs.draw3D(self, xform)
fslgl.gltractogram_funcs.draw3D(self, *args, **kwargs)
def postDraw(self):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment