def _testColor(value, canBeScalar=True): """ _testColor(value, canBeScalar=True) Tests a color whether it is a sequence of 3 or 4 values. It returns a 4 element tuple or raises an error if the suplied data is incorrect. """ # Deal with named colors if isinstance(value, basestring): value = misc.getColor(value) # Value can be a scalar if canBeScalar and isinstance(value, (int, float)): if value <= 0: value = 0.0 if value >= 1: value = 1.0 return value # Otherwise it must be a sequence of 3 or 4 elements elif not hasattr(value, '__len__'): raise ValueError("Given value can not represent a color.") elif len(value) == 4: return (value[0], value[1], value[2], value[3]) elif len(value) == 3: return (value[0], value[1], value[2], 1.0) else: raise ValueError("Given value can not represent a color.")
def fset(self, value): value = getColor(value, 'setting textColor') if value != self._textColor: self._textColor = value # Update existing self._label.textColor = value for label in self._labelPool.values(): label.textColor = value self.Draw()
def _DrawLines(self): # set stipple style if not self.ls in lineStyles: stipple = False else: stipple = lineStyles[self.ls] # if stipple and self.lw: gl.glEnable(gl.GL_LINE_STIPPLE) gl.glLineStipple(int(round(self.lw)), stipple) else: gl.glDisable(gl.GL_LINE_STIPPLE) # init vertex array gl.glEnableClientState(gl.GL_VERTEX_ARRAY) gl.glVertexPointerf(self._points.data) # linepieces drawn on top of other should draw just fine. See issue #95 gl.glDepthFunc(gl.GL_LEQUAL) # init blending. Only use constant blendfactor when alpha<1 gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) if self._alpha1 < 1: #if len(self._points) < 1000: if getOpenGlCapable('1.4', 'transparant points and lines'): gl.glBlendFunc(gl.GL_CONSTANT_ALPHA, gl.GL_ONE_MINUS_CONSTANT_ALPHA) gl.glBlendColor(0.0, 0.0, 0.0, self._alpha1) gl.glDisable(gl.GL_DEPTH_TEST) # get color clr = getColor(self.lc) if clr and self._alpha1 > 0: # set width and color gl.glLineWidth(self.lw) gl.glColor3f(clr[0], clr[1], clr[2]) # draw method = gl.GL_LINE_STRIP if self.ls == '+': method = gl.GL_LINES gl.glDrawArrays(method, 0, len(self._points)) # flush! gl.glFlush() # clean up gl.glDisable(gl.GL_LINE_STIPPLE) gl.glLineStipple(int(round(self.lw)), int('1111111111111111', 2)) gl.glEnable(gl.GL_DEPTH_TEST) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glDisableClientState(gl.GL_VERTEX_ARRAY) gl.glDepthFunc(gl.GL_LESS)
def _DrawLines(self): # set stipple style if not self.ls in lineStyles: stipple = False else: stipple = lineStyles[self.ls] # if stipple and self.lw: gl.glEnable(gl.GL_LINE_STIPPLE) gl.glLineStipple(int(round(self.lw)), stipple) else: gl.glDisable(gl.GL_LINE_STIPPLE) # init vertex array gl.glEnableClientState(gl.GL_VERTEX_ARRAY) gl.glVertexPointerf(self._points.data) # init blending. Only use constant blendfactor when alpha<1 gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) if self._alpha1<1: if getOpenGlCapable('1.4','transparant points and lines'): gl.glBlendFunc(gl.GL_CONSTANT_ALPHA, gl.GL_ONE_MINUS_CONSTANT_ALPHA) gl.glBlendColor(0.0,0.0,0.0, self._alpha1) gl.glDisable(gl.GL_DEPTH_TEST) # get color clr = getColor( self.lc ) if clr and self._alpha1>0: # set width and color gl.glLineWidth(self.lw) gl.glColor3f(clr[0], clr[1], clr[2]) # draw method = gl.GL_LINE_STRIP if self.ls == '+': method = gl.GL_LINES gl.glDrawArrays(method, 0, len(self._points)) # flush! gl.glFlush() # clean up gl.glDisable(gl.GL_LINE_STIPPLE) gl.glLineStipple(int(round(self.lw)), int('1111111111111111',2)) gl.glEnable(gl.GL_DEPTH_TEST) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glDisableClientState(gl.GL_VERTEX_ARRAY)
def fset(self, value): # None? if value is None: self._bgcolors = None return # Check try: if len(value) not in [2,4]: raise ValueError('bgcolors must have 2 or 4 elements.') except Exception: # not an iterable raise ValueError('bgcolors must be None, or tuple/list/string.') # Apply colors = [getColor(val, 'setting bgcolors') for val in value] self._bgcolors = tuple(colors)
def fset(self, value): # None? if value is None: self._bgcolors = None return # Check try: if len(value) not in [2, 4]: raise ValueError('bgcolors must have 2 or 4 elements.') except Exception: # not an iterable raise ValueError( 'bgcolors must be None, or tuple/list/string.') # Apply colors = [getColor(val, 'setting bgcolors') for val in value] self._bgcolors = tuple(colors)
def OnDrawShape(self, clr): # Draw the shape of the line so we can detect mouse actions # disable anti aliasing and blending gl.glDisable(gl.GL_LINE_SMOOTH) gl.glDisable(gl.GL_BLEND) # no stippling, square points gl.glDisable(gl.GL_LINE_STIPPLE) gl.glDisable(gl.GL_POINT_SMOOTH) # init vertex array gl.glEnableClientState(gl.GL_VERTEX_ARRAY) gl.glVertexPointerf(self._points.data) # detect which parts to draw drawLine, drawMarker = False, False if self.lw and self.ls and getColor(self.lc): drawLine = True if self.mw and self.ms: drawMarker = True if drawLine: # set width and color gl.glLineWidth(self.lw) gl.glColor3f(clr[0], clr[1], clr[2]) # draw gl.glDrawArrays(gl.GL_LINE_STRIP, 0, len(self._points)) gl.glFlush() if drawMarker: w = self.mw if self.mec: w += self.mew # set width and color gl.glColor3f(clr[0], clr[1], clr[2]) gl.glPointSize(w) # draw gl.glDrawArrays(gl.GL_POINTS, 0, len(self._points)) gl.glFlush() # clean up gl.glDisableClientState(gl.GL_VERTEX_ARRAY)
def OnDrawShape(self, clr): # Draw the shape of the line so we can detect mouse actions # disable anti aliasing and blending gl.glDisable(gl.GL_LINE_SMOOTH) gl.glDisable(gl.GL_BLEND) # no stippling, square points gl.glDisable(gl.GL_LINE_STIPPLE) gl.glDisable(gl.GL_POINT_SMOOTH) # init vertex array gl.glEnableClientState(gl.GL_VERTEX_ARRAY) gl.glVertexPointerf(self._points.data) # detect which parts to draw drawLine, drawMarker = False, False if self.lw and self.ls and getColor(self.lc): drawLine = True if self.mw and self.ms: drawMarker = True if drawLine: # set width and color gl.glLineWidth(self.lw) gl.glColor3f(clr[0], clr[1], clr[2]) # draw gl.glDrawArrays(gl.GL_LINE_STRIP, 0, len(self._points)) gl.glFlush() if drawMarker: w = self.mw if self.mec: w += self.mew # set width and color gl.glColor3f(clr[0],clr[1],clr[2]) gl.glPointSize(w) # draw gl.glDrawArrays(gl.GL_POINTS, 0, len(self._points)) gl.glFlush() # clean up gl.glDisableClientState(gl.GL_VERTEX_ARRAY)
def __init__(self, parent, data, axis=0, index=0): BaseTexture.__init__(self, parent, data) self._ndim = 3 # Init parameters self._axis = axis self._index = index # create texture self._texture1 = TextureObjectToVisualize(2, data) # init shader self._InitShader() # set data (data to textureToV. only for min/max) self.SetData(data) # init interpolation self._texture1._interpolate = True # For edge self._edgeColor = None self._edgeColor2 = getColor('g') self._edgeWidth = 3.0 # For interaction self._interact_over = False self._interact_down = False self._screenVec = None self._refPos = (0,0) self._refIndex = 0 # self.hitTest = True # self.eventEnter.Bind(self._OnMouseEnter) self.eventLeave.Bind(self._OnMouseLeave) self.eventMouseDown.Bind(self._OnMouseDown) self.eventMouseUp.Bind(self._OnMouseUp) self.eventMotion.Bind(self._OnMouseMotion)
def fset(self, value): self._edgeColor = misc.getColor(value, 'setting edgeColor')
def fset(self, value): self._edgeColor2 = getColor(value)
def fset(self, value): value = getColor(value,'setting textColor') if value != self._color: self._color = value self.Draw()
def _DrawPoints(self): # get colors (use color from edge or face if not present) clr1 = getColor(self.mc) clr2 = getColor(self.mec) # draw face or edge? drawFace = bool(self.mc) # if not ms or mw we would not get here drawEdge = self.mec and self.mew if not drawFace and not drawEdge: return # get figure f = self.GetFigure() if not f: return # init blending. Only use constant blendfactor when alpha<1 gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) if self._alpha1 < 1: if getOpenGlCapable('1.4', 'transparant points and lines'): gl.glBlendFunc(gl.GL_CONSTANT_ALPHA, gl.GL_ONE_MINUS_CONSTANT_ALPHA) gl.glBlendColor(0.0, 0.0, 0.0, self._alpha1) gl.glDisable(gl.GL_DEPTH_TEST) # init vertex array gl.glEnableClientState(gl.GL_VERTEX_ARRAY) gl.glVertexPointerf(self._points.data) # points drawn on top of points should draw (because we draw # the face and edge seperately) gl.glDepthFunc(gl.GL_LEQUAL) # Enable alpha test, such that fragments with 0 alpha # will not update the z-buffer. gl.glEnable(gl.GL_ALPHA_TEST) gl.glAlphaFunc(gl.GL_GREATER, 0.01) if self.ms in ['o', '.', 's'] and not drawEdge: # Use standard OpenGL points, faster and anti-aliased # Pure filled points or squares always work. # choose style if self.ms == 's': gl.glDisable(gl.GL_POINT_SMOOTH) else: gl.glEnable(gl.GL_POINT_SMOOTH) # draw faces only if drawFace: gl.glColor3f(clr1[0], clr1[1], clr1[2]) gl.glPointSize(self.mw) gl.glDrawArrays(gl.GL_POINTS, 0, len(self._points)) elif self.ms in ['o', '.', 's'] and drawFace and self.alpha == 1: # Use standard OpenGL points, faster and anti-aliased # If alpha=1 and we have a filled marker, we can draw in two steps. # choose style if self.ms == 's': gl.glDisable(gl.GL_POINT_SMOOTH) else: gl.glEnable(gl.GL_POINT_SMOOTH) # draw edges if drawEdge: gl.glColor3f(clr2[0], clr2[1], clr2[2]) gl.glPointSize(self.mw + self.mew * 2) gl.glDrawArrays(gl.GL_POINTS, 0, len(self._points)) # draw faces if drawFace: gl.glColor3f(clr1[0], clr1[1], clr1[2]) gl.glPointSize(self.mw) gl.glDrawArrays(gl.GL_POINTS, 0, len(self._points)) #elif self.alpha>0: else: # Use sprites # get sprites tmp = f._markerManager.GetSprites(self.ms, self.mw, self.mew) pSize, sprite1, sprite2 = tmp gl.glPointSize(pSize) # draw points for the edges if drawEdge: sprite2.Enable() gl.glColor3f(clr2[0], clr2[1], clr2[2]) gl.glDrawArrays(gl.GL_POINTS, 0, len(self._points)) # draw points for the faces if drawFace: sprite1.Enable() gl.glColor3f(clr1[0], clr1[1], clr1[2]) gl.glDrawArrays(gl.GL_POINTS, 0, len(self._points)) # disable sprites sprite1.Disable() # Could as well have used sprite2 # clean up gl.glDisable(gl.GL_ALPHA_TEST) gl.glEnable(gl.GL_DEPTH_TEST) gl.glDisableClientState(gl.GL_VERTEX_ARRAY) gl.glDepthFunc(gl.GL_LESS) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
def fset(self, value): self._bgcolor = misc.getColor(value, 'setting bgcolor')
def fset(self, value): value = getColor(value, 'lineColor') self._lc = value
def fset(self, value): self._mc = getColor(value, 'markerColor')
def fset(self, value): value = getColor(value, 'setting textColor') if value != self._color: self._color = value self.Draw()
def _DrawPoints(self): # get colors (use color from edge or face if not present) clr1 = getColor(self.mc) clr2 = getColor(self.mec) # draw face or edge? drawFace = bool(self.mc) # if not ms or mw we would not get here drawEdge = self.mec and self.mew if not drawFace and not drawEdge: return # get figure f = self.GetFigure() if not f: return # init blending. Only use constant blendfactor when alpha<1 gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) if self._alpha1<1: if getOpenGlCapable('1.4','transparant points and lines'): gl.glBlendFunc(gl.GL_CONSTANT_ALPHA, gl.GL_ONE_MINUS_CONSTANT_ALPHA) gl.glBlendColor(0.0,0.0,0.0, self._alpha1) gl.glDisable(gl.GL_DEPTH_TEST) # init vertex array gl.glEnableClientState(gl.GL_VERTEX_ARRAY) gl.glVertexPointerf(self._points.data) # points drawn on top of points should draw (because we draw # the face and edge seperately) gl.glDepthFunc(gl.GL_LEQUAL) # Enable alpha test, such that fragments with 0 alpha # will not update the z-buffer. gl.glEnable(gl.GL_ALPHA_TEST) gl.glAlphaFunc(gl.GL_GREATER, 0.01) if self.ms in ['o','.','s'] and not drawEdge: # Use standard OpenGL points, faster and anti-aliased # Pure filled points or squares always work. # choose style if self.ms == 's': gl.glDisable(gl.GL_POINT_SMOOTH) else: gl.glEnable(gl.GL_POINT_SMOOTH) # draw faces only if drawFace: gl.glColor3f(clr1[0],clr1[1],clr1[2]) gl.glPointSize(self.mw) gl.glDrawArrays(gl.GL_POINTS, 0, len(self._points)) elif self.ms in ['o','.','s'] and drawFace and self.alpha==1: # Use standard OpenGL points, faster and anti-aliased # If alpha=1 and we have a filled marker, we can draw in two steps. # choose style if self.ms == 's': gl.glDisable(gl.GL_POINT_SMOOTH) else: gl.glEnable(gl.GL_POINT_SMOOTH) # draw edges if drawEdge: gl.glColor3f(clr2[0],clr2[1],clr2[2]) gl.glPointSize(self.mw+self.mew*2) gl.glDrawArrays(gl.GL_POINTS, 0, len(self._points)) # draw faces if drawFace: gl.glColor3f(clr1[0],clr1[1],clr1[2]) gl.glPointSize(self.mw) gl.glDrawArrays(gl.GL_POINTS, 0, len(self._points)) #elif self.alpha>0: else: # Use sprites # get sprites tmp = f._markerManager.GetSprites(self.ms, self.mw, self.mew) pSize, sprite1, sprite2 = tmp gl.glPointSize(pSize) # draw points for the edges if drawEdge: sprite2.Enable() gl.glColor3f(clr2[0],clr2[1],clr2[2]) gl.glDrawArrays(gl.GL_POINTS, 0, len(self._points)) # draw points for the faces if drawFace: sprite1.Enable() gl.glColor3f(clr1[0],clr1[1],clr1[2]) gl.glDrawArrays(gl.GL_POINTS, 0, len(self._points)) # disable sprites sprite1.Disable() # Could as well have used sprite2 # clean up gl.glDisable(gl.GL_ALPHA_TEST) gl.glEnable(gl.GL_DEPTH_TEST) gl.glDisableClientState(gl.GL_VERTEX_ARRAY) gl.glDepthFunc(gl.GL_LESS) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
def fset(self, value): self._mec = getColor(value, 'markerEdgeColor')