def drawPolygons(x,mode,color=None,alpha=1.0): """Draw a collection of polygons. mode is either 'flat' or 'smooth' : in 'smooth' mode the normals for the lighting are calculated and set """ n = None if mode.startswith('smooth'): ni = arange(x.shape[1]) nj = roll(ni,1) nk = roll(ni,-1) v1 = x-x[:,nj] v2 = x[:,nk]-x n = vectorPairNormals(v1.reshape(-1,3),v2.reshape(-1,3)).reshape(x.shape) 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 LD.drawPolygons(x,n,color,alpha)
def drawTriangles(x,mode,color=None,alpha=1.0): """Draw a collection of triangles. x is a (ntri,3*n,3) shaped array of coordinates. Each row contains n triangles drawn with the same color. If color is given it is an (npoly,3) array of RGB values. mode is either 'flat' or 'smooth' : in 'smooth' mode the normals for the lighting are calculated and set """ x = x.reshape(-1,3,3) n = None if mode.startswith('smooth'): n = vectorPairNormals(x[:,1] - x[:,0], x[:,2] - x[:,1]) 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 LD.drawPolygons(x,n,color,alpha)
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 = computeNormals(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 LD.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) LD.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 LD.drawPolygons(x,None,color,alpha)