Exemplo n.º 1
0
 def adjacency(self):
     """Find the elems adjacent to elems."""
     if self.adj is None:
         nfaces = self.nfaces()
         rfaces = connectivity.reverseIndex(self.faces)
         # this gives all adjacent elements including element itself
         adj = rfaces[self.faces].reshape((nfaces,-1))
         fnr = arange(nfaces).reshape((nfaces,-1))
         # remove the element itself
         self.adj = adj[adj != fnr].reshape((nfaces,-1))
     return self.adj
Exemplo n.º 2
0
 def pointNormals(self):
     """Compute the normal vectors in each point of a collection of triangles.
     
     The normal vector in a point is the average of the normal vectors of the neighbouring triangles.
     The normal vectors are normalized.
     """
     con = connectivity.reverseIndex(self.getElems())
     NP = self.areaNormals()[1][con] #self.normal doesn't work here???
     w = where(con == -1)
     NP[w] = 0.
     NPA = NP.sum(axis=1)
     NPA /= sqrt((NPA*NPA).sum(axis=-1)).reshape(-1,1)
     return NPA
Exemplo n.º 3
0
    def drawGL(self,mode,color=None,alpha=None):
        """Draw the surface."""
        print "SURFACE.DRAWGL"
        if mode.endswith('wire'):
            self.drawGL(mode[:-4],color=color)
            self.drawGL('wireframe',color=asarray(black))
            return

        if alpha is None:
            alpha = self.alpha           

        if color == None:
            color = self.color

##                 if mode == 'wireframe':
##                     # adapt color array to edgeselect
##                     color = concatenate([self.color,self.color,self.color],axis=-1)
##                     color = color.reshape((-1,2))[self.edgeselect]
        
        if color is None:  # no color
            pass
        
        elif color.dtype.kind == 'f' and color.ndim == 1:  # single color
            GL.glColor(append(color,alpha))
            color = None

        elif color.dtype.kind == 'i': # color index
            color = self.colormap[color]

        else: # a full color array : use as is
            pass

        #print "SURFACE COLOR = %s" % str(color)

        if self.linewidth is not None:
            GL.glLineWidth(self.linewidth)

        t = timer.Timer()
        if mode=='wireframe' :
            #print color.shape
            #print self.edges.shape
            #print self.faces.shape
            rev = reverseIndex(self.faces)
            if color is not None:
                color = color[rev[:,-1]]
            drawLineElems(self.coords,self.edges,color)
        else:
            self.refresh()
            drawTriangleElems(self.coords,self.elems,mode,color,alpha)
        GD.message("Drawing time: %s seconds" % t.seconds())
Exemplo n.º 4
0
    def drawGL(self,mode='wireframe',color=None,colormap=None,alpha=None):
        """Draw the surface."""

        if mode.endswith('wire'):
            self.drawGL(mode='wireframe',color=asarray(black),colormap=None)
            self.drawGL(mode=mode[:-4],color=color,colormap=colormap,alpha=alpha)
            return

        if alpha is None:
            alpha = self.alpha           

        if color is None:  
            color,colormap = self.color,self.colormap
        else:
            color,colormap = saneColorSet(color,colormap,self.nelems())
        
        if color is None:  # no color
            pass
        
        elif color.dtype.kind == 'f' and color.ndim == 1:  # single color
            GL.glColor(append(color,alpha))
            color = None

        elif color.dtype.kind == 'i': # color index
            color = colormap[color]

        else: # a full color array : use as is
            pass

        if self.linewidth is not None:
            GL.glLineWidth(self.linewidth)

        t = timer.Timer()
        if mode=='wireframe' :
            rev = reverseIndex(self.faces)
            if color is not None:
                color = color[rev[:,-1]]
            drawLineElems(self.coords,self.edges,color)
        else:
            self.refresh()
            drawPolygonElems(self.coords,self.elems,mode,color,alpha)
        GD.debug("Drawing time: %s seconds" % t.seconds())
Exemplo n.º 5
0
def removeTriangles(elems):
    """Remove the triangles from the centerline.
    
    This is a clean-up function for the centerline.
    Triangles appearing in the centerline are removed by this function.
    Both input and output are the connectivity of the centerline.
    """
    rev = connectivity.reverseIndex(elems)
    if rev.shape[1] > 2:
        w =  where(rev[:,-3] != -1)[0]
        for i in w:
            el = rev[i].compress(rev[i] != -1)
            u = unique(elems[el].reshape(-1))
            NB = u.compress(u != i)
            int = intersect1d(w,NB)
            if int.shape[0] == 2:
                tri = append(int,i)
                w1 = where(tri != tri.min())[0]
                t = (elems[:,0] == tri[w1[0]])*(elems[:,1] == tri[w1[1]])
                elems[t] = -1
    w2 = where(elems[:,0] != -1)[0]
    return elems[w2]
Exemplo n.º 6
0
 def nodeConnections(self):
     """Find the elems connected to nodes."""
     if self.conn is None:
         self.refresh()
         self.conn = connectivity.reverseIndex(self.elems)
     return self.conn
Exemplo n.º 7
0
 def edgeConnections(self):
     """Find the elems connected to edges."""
     if self.econn is None:
         self.econn = connectivity.reverseIndex(self.faces)
     return self.econn