コード例 #1
0
ファイル: drawable.py プロジェクト: gunnups/pyFormex
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.
    """
    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,None,alpha,-1)
コード例 #2
0
ファイル: drawable.py プロジェクト: gunnups/pyFormex
def multi_draw_polygons(x,n,color,t,alpha,objtype,nproc=-1):
    from multi import multitask,cpu_count
    if nproc < 1:
        nproc = cpu_count()

    print("MULTIDRAW %s" % nproc)

    if nproc == 1:
        drawgl.draw_polygons(x,n,color,t,alpha,objtype)

    else:
        xblocks = splitar(x,nproc)
        n = t = color = None
        print([xb.shape for xb in xblocks])
        #[ drawgl.draw_polygons(xb,n,color,t,alpha,objtype) for xb in xblocks]

        tasks = [(drawgl.draw_polygons,(xb,n,color,t,alpha,objtype)) for xb in xblocks]
        multitask(tasks,nproc)
コード例 #3
0
ファイル: drawable.py プロジェクト: gunnups/pyFormex
def drawPolygons(x,e,color=None,alpha=1.0,texture=None,t=None,normals=None,lighting=False,avgnormals=False,objtype=-1):
    """Draw a collection of polygons.

    The polygons can either be specified as a Formex model or as a Mesh model.

    Parameters:

    - `x`: coordinates of the points. Shape is (nelems,nplex,3) for Formex
      model, of (nnodes,3) for Mesh model.
    - `e`: None for a Formex model, definition of the elements (nelems,nplex)
      for a Mesh model.
    - `color`: either None or an RGB color array with shape (3,), (nelems,3)
      or (nelems,nplex,3).
    - `objtype`: 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.
      This value can be set to GL.GL_LINE_LOOP to draw the element's
      circumference independent from the drawing mode.
    """
    pf.debug("drawPolygons",pf.DEBUG.DRAW)
    if e is None:
        nelems = x.shape[0]
    else:
        nelems = e.shape[0]
    n = None
    #print("LIGHTING %s, AVGNORMALS %s" % (lighting,avgnormals))
    if lighting and objtype==-1:
        if normals is None:
            pf.debug("Computing normals",pf.DEBUG.DRAW)
            if avgnormals and e is not None:
                n = geomtools.averageNormals(x,e,treshold=pf.cfg['render/avgnormaltreshold'])
            else:
                if e is None:
                    n = geomtools.polygonNormals(x)
                else:
                    n = geomtools.polygonNormals(x[e])
                #pf.debug("NORMALS:%s" % str(n.shape),pf.DEBUG.DRAW)
        else:
            #print("NORMALS=%s"% normals)
            n = checkArray(normals,(nelems,-1,3),'f')

    # Texture
    if texture is not None:
        glTexture(texture)
        if t is None:
            t = array([[0.,0.],[1.,0.],[1.,1.],[0.,1.]])
    else:
        t = None


    # Sanitize data before calling library function
    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),pf.DEBUG.DRAW)
        if color.shape[-1] != 3 or (
            color.ndim > 1 and color.shape[0] != nelems) :
            pf.debug("INCOMPATIBLE COLOR SHAPE: %s, while nelems=%s" % (str(color.shape),nelems),pf.DEBUG.DRAW)
            color = None
    if t is not None:
        t = t.astype(float32)

    # Call library function
    if e is None:
        drawgl.draw_polygons(x,n,color,t,alpha,objtype)
        #multi_draw_polygons(x,n,color,t,alpha,objtype)
    else:
        drawgl.draw_polygon_elems(x,e,n,color,t,alpha,objtype)
コード例 #4
0
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

    color is either None or an RGB color array with shape (3,), (nels,3) or
    (nels,nplex,3).

    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 = geomtools.polygonNormals(x)
                else:
                    n = geomtools.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"""

    # Sanitize data before calling library function
    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[-1] != 3 or (color.ndim > 1 and color.shape[0] != nelems):
            pf.debug("INCOMPATIBLE COLOR SHAPE: %s, while nelems=%s" % (str(color.shape), nelems))
            color = None

    # Call library function
    if e is None:
        drawgl.draw_polygons(x, n, color, alpha, objtype)
    else:
        drawgl.draw_polygon_elems(x, e, n, color, alpha, objtype)