def drawPolygons(x,mode,color=None,alpha=1.0,normals=None): """Draw a collection of polygons. mode is either 'flat' or 'smooth' : in 'smooth' mode the normals for the lighting are calculated and set, or they can be specified in normals """ n = None if mode.startswith('smooth'): if normals is None: n = polygonNormals(x) else: try: n = asarray(normals) if not (n.ndim in [2,3] and n.shape[0] == x.shape[0] and n.shape[-1] == 3): raise except: raise ValueError,"""Invalid normals specified""" if GD.options.safelib: x = x.astype(float32) if n is not None: n = n.astype(float32) if color is not None: color = color.astype(float32) if (color.shape[0] != x.shape[0] or color.shape[-1] != 3): color = None drawgl.drawPolygons(x,n,color,alpha)
def drawPoints(x,color=None,alpha=1.0,size=None): """Draw a collection of points with default or given size and color. x is a (npoints,3) shaped array of coordinates. If size (float) is given, it specifies the point size. If color is given it is an (npoints,3) array of RGB values. """ if GD.options.safelib: x = x.astype(float32).reshape(-1,3) if color is not None: color = resize(color.astype(float32),x.shape) if size: GL.glPointSize(size) x = x.reshape(-1,1,3) drawgl.drawPolygons(x,None,color,alpha)
def drawLines(x,color=None,alpha=1.0): """Draw a collection of lines. x is a (nlines,2,3) shaped array of coordinates. If color is given it is an (nlines,3), (nlines,1,3) or (nlines,2,3) array of RGB values. If two colors are given, make sure that smooth shading is on, or the color rendering will be flat with the second color. """ if GD.options.safelib: x = x.astype(float32) if color is not None: color = color.astype(float32) if (color.shape[0] != x.shape[0] or color.shape[-1] != 3): color = None drawgl.drawPolygons(x,None,color,alpha)