GLLinePLotItem accepts array of colors (thanks Felix!)

This commit is contained in:
Luke Campagnola 2013-07-13 16:42:36 -04:00
parent 6131427dea
commit 3eeffd3b1d
2 changed files with 15 additions and 3 deletions

View File

@ -12,6 +12,7 @@ Contributors:
Christian Gavin Christian Gavin
Michael Cristopher Hogg Michael Cristopher Hogg
Ulrich Leutner Ulrich Leutner
Felix Schill
Requirements: Requirements:
PyQt 4.7+ or PySide PyQt 4.7+ or PySide

View File

@ -30,8 +30,9 @@ class GLLinePlotItem(GLGraphicsItem):
Arguments: Arguments:
------------------------------------------------------------------------ ------------------------------------------------------------------------
pos (N,3) array of floats specifying point locations. pos (N,3) array of floats specifying point locations.
color tuple of floats (0.0-1.0) specifying color (N,4) array of floats (0.0-1.0) or
a color for the entire item. tuple of floats specifying
a single color for the entire item.
width float specifying line width width float specifying line width
antialias enables smooth line drawing antialias enables smooth line drawing
==================== ================================================== ==================== ==================================================
@ -71,9 +72,18 @@ class GLLinePlotItem(GLGraphicsItem):
self.setupGLState() self.setupGLState()
glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_VERTEX_ARRAY)
try: try:
glVertexPointerf(self.pos) glVertexPointerf(self.pos)
glColor4f(*self.color)
if isinstance(self.color, np.ndarray):
glEnableClientState(GL_COLOR_ARRAY)
glColorPointerf(self.color)
else:
if isinstance(self.color, QtGui.QColor):
glColor4f(*fn.glColor(self.color))
else:
glColor4f(*self.color)
glLineWidth(self.width) glLineWidth(self.width)
#glPointSize(self.width) #glPointSize(self.width)
@ -85,6 +95,7 @@ class GLLinePlotItem(GLGraphicsItem):
glDrawArrays(GL_LINE_STRIP, 0, self.pos.size / self.pos.shape[-1]) glDrawArrays(GL_LINE_STRIP, 0, self.pos.size / self.pos.shape[-1])
finally: finally:
glDisableClientState(GL_COLOR_ARRAY)
glDisableClientState(GL_VERTEX_ARRAY) glDisableClientState(GL_VERTEX_ARRAY)