build_gallery.py 2 KB
Newer Older
1 2 3 4 5 6 7
import os
import numpy as np
import matplotlib.pyplot as plt

imgtypes = ['.pdf','.png']

def plot_sketch(fname):
8
    fname += '.oesk'
9 10 11 12 13 14 15 16 17 18
    print('Sketch: ' +fname)
    data = np.genfromtxt(fname, dtype=float, delimiter=',')
    plt.plot(data[:,0], data[:,1])
    plt.grid(True)
    plt.axes().set_aspect('equal','datalim')
    for ext in imgtypes:
        plt.savefig(fname+ext)
    plt.clf()

def plot_mesh(fname):
19
    fname += '.oeme'
20 21 22 23 24 25 26 27 28 29 30
    print('Mesh: '+fname)
    data = np.genfromtxt(fname, dtype=float, delimiter=',')
    x = data[:,[0,1,2,0]].transpose()
    y = data[:,[3,4,5,3]].transpose()
    plt.plot(x,y,'b')
    plt.grid(True)
    plt.axes().set_aspect('equal','datalim')
    for ext in imgtypes:
        plt.savefig(fname+ext)
    plt.clf()

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
def plot_scalar(fname):
    fname += '.oesc'
    print('Scalar: '+fname)
    
    tris = np.genfromtxt(fname, dtype=int, delimiter=',',skip_header=0,max_rows=1)
    tris = np.genfromtxt(fname, dtype=int, delimiter=',',skip_header=tris[0],max_rows=tris[1])

    nodes = np.genfromtxt(fname, dtype=int, delimiter=',',skip_header=1,max_rows=1)
    nodes = np.genfromtxt(fname, dtype=float, delimiter=',',skip_header=nodes[0],max_rows=nodes[1])

    vals = np.genfromtxt(fname, dtype=int, delimiter=',',skip_header=2,max_rows=1)
    vals = np.genfromtxt(fname, dtype=float, delimiter=',',skip_header=vals[0],max_rows=vals[1])

    plt.figure()
    plt.set_cmap('viridis')
    plt.gca().set_aspect('equal')
    plt.tripcolor(nodes[:,0],nodes[:,1],tris,vals,edgecolors='k')
    plt.colorbar()
    plt.grid(True)
    plt.axes().set_aspect('equal','datalim')
    for ext in imgtypes:
        plt.savefig(fname+ext)
    plt.clf()

55 56 57 58 59
root = os.getcwd()
root += '/build/test/output/'

for path, _, files in os.walk(root):
    for name in files:
60
        name, fext = os.path.splitext(name)
61
        fpath = os.path.join(path, name)
62
        if fext == '.oesk': 
63 64
            plot_sketch(fpath)
        elif fext == '.oeme':
65 66 67
            plot_mesh(fpath)
        elif fext == '.oesc':
            plot_scalar(fpath)