def plot_solution(base_file, I):
    plt.figure(1)
    plt.clf()
    
    iterfile = base_file + '.' + str(I)
    meshfile = iterfile + '.mesh'
    solfile = iterfile + '.sol'
    assert os.path.isfile(meshfile) 
    assert os.path.isfile(solfile)

    print ""

    mesh = read_medit_mesh(meshfile)
    unarch = Unarchiver(solfile)
    f = unarch.p
    A = 3
    assert 0 == f.size % A
    N = f.size / A
    F = np.reshape(f,(N,A),'F')
    
    for a in xrange(A):
        plt.subplot(3,2,a+1,projection='3d')
        if a == 0:
            alpha_fn = lambda x: 0.5 * (1 - x)**1.5
            cmap = 'spectral_r'
            f = F[:-1,0]
        else:
            alpha_fn = lambda x: 0.1
            cmap = 'jet'
            f = np.argmax(F[:-1,1:],1)
            f = f.astype(np.double)
            f[f != (a-1)] = np.nan
        sg.plot_mesh(f,*mesh,
                     cmap=cmap,
                     alpha_fn = alpha_fn)
    plt.suptitle(base_file + str(I))
Exemplo n.º 2
0
import os.path



if __name__ == "__main__":    
    parser = argparse.ArgumentParser(
        description='Display the faces of a tetrahedral mesh.')
    parser.add_argument('mesh', metavar='F', type=str,
                        help='Mesh input file (INRIA .mesh)')
    args = parser.parse_args()

    meshfile = args.mesh
    (base,ext) = meshfile.rsplit('.',1)
    assert ext == 'mesh'
    
    tet_mesh = read_medit_mesh(meshfile)
    (vertices,edges,triangles,tetrahedra) = tet_mesh
    
    vertices = tet_mesh[0]
    V = vertices.shape[0]
    T = tetrahedra.shape[0]
    print 'Reading INRIA .mesh file',meshfile
    print '\tFound', V, 'vertices'
    print '\tFound', T, 'tetrahedra'

    bbox = np.empty((3,2))
    for i in xrange(3):
        bbox[i,0] = np.min(vertices[:,i])
        bbox[i,1] = np.max(vertices[:,i])
        
    kernel = stats.gaussian_kde(vertices.T,0.1)