def merge_mesh( x1, ngroups1, conns1, x2, ngroups2, conns2, cmap, eps = 1e-8 ):
    """Merge two meshes in common coordinates found in x1, x2."""
    n1 = x1.shape[0]
    n2 = x2.shape[0]

    err = nm.sum( nm.sum( nm.abs( x1[cmap[:,0],:-1] - x2[cmap[:,1],:-1] ) ) )
    if abs( err ) > (10.0 * eps):
        print 'nonmatching meshes!', err
        raise ValueError

    mask = nm.ones( (n2,), dtype = nm.int32 )
    mask[cmap[:,1]] = 0
#    print mask, nm.cumsum( mask )
    remap = nm.cumsum( mask ) + n1 - 1
    remap[cmap[:,1]] = cmap[:,0]
#    print remap

    i2 = nm.setdiff1d( nm.arange(  n2, dtype = nm.int32 ),
                       cmap[:,1] )
    xx = nm.r_[x1, x2[i2]]
    ngroups = nm.r_[ngroups1, ngroups2[i2]]

    conns = []
    for ii in xrange( len( conns1 ) ):
        conn = nm.vstack( (conns1[ii], remap[conns2[ii]]) )
        conns.append( conn )
    
    return xx, ngroups, conns
def merge_mesh ( x1 , ngroups1 , conns1 , x2 , ngroups2 , conns2 , cmap , eps = 1e-8 ) : n1 = x1 . shape [ 0 ] n2 = x2 . shape [ 0 ] err = nm . sum ( nm . sum ( nm . abs ( x1 [ cmap [ : , 0 ] , : - 1 ] - x2 [ cmap [ : , 1 ] , : - 1 ] ) ) ) if abs ( err ) > ( 10.0 * eps ) : print 'nonmatching meshes!' , err raise ValueError mask = nm . ones ( ( n2 , ) , dtype = nm . int32 ) mask [ cmap [ : , 1 ] ] = 0 remap = nm . cumsum ( mask ) + n1 - 1 remap [ cmap [ : , 1 ] ] = cmap [ : , 0 ] i2 = nm . setdiff1d ( nm . arange ( n2 , dtype = nm . int32 ) , cmap [ : , 1 ] ) xx = nm . r_ [ x1 , x2 [ i2 ] ] ngroups = nm . r_ [ ngroups1 , ngroups2 [ i2 ] ] conns = [ ] for ii in xrange ( len ( conns1 ) ) : conn = nm . vstack ( ( conns1 [ ii ] , remap [ conns2 [ ii ] ] ) ) conns . append ( conn ) return xx , ngroups , conns
Merge two meshes in common coordinates found in x1, x2.