def drawPolygons(x,e,mode,color=None,alpha=1.0,normals=None,objtype=-1): """Draw a collection of polygon elements. This function is like drawPolygons, but the vertices of the polygons are specified by: coords (npts,3) : the coordinates of the points elems (nels,nplex): the connectivity of nels polygons of plexitude nplex objtype sets the OpenGL drawing mode. The default (-1) will select the appropriate value depending on the plexitude of the elements: 1: point, 2: line, 3: triangle, 4: quad, >4: polygon. The value can be set to GL.GL_LINE_LOOP to draw the element's circumference independent from the drawing mode. """ pf.debug("drawPolygons") if e is None: nelems = x.shape[0] else: nelems = e.shape[0] n = None if mode.startswith('smooth') and objtype==-1: if normals is None: pf.debug("Computing normals") if mode == 'smooth_avg' and e is not None: n = interpolateNormals(x,e,treshold=pf.cfg['render/avgnormaltreshold']) mode = 'smooth' else: if e is None: n = polygonNormals(x) else: n = polygonNormals(x[e]) pf.debug("NORMALS:%s" % str(n.shape)) else: try: n = asarray(normals) if not (n.ndim in [2,3] and n.shape[0] == nelems and n.shape[-1] == 3): raise except: raise ValueError,"""Invalid normals specified""" if pf.options.safelib: x = x.astype(float32) if e is not None: e = e.astype(int32) if n is not None: n = n.astype(float32) if color is not None: color = color.astype(float32) pf.debug("COLORS:%s" % str(color.shape)) if (color.shape[0] != nelems or color.shape[-1] != 3): color = None if e is None: drawgl.draw_polygons(x,n,color,alpha,objtype) else: drawgl.draw_polygon_elems(x,e,n,color,alpha,objtype)
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.draw_polygons(x,None,color,alpha,-1)