Exemplo n.º 1
0
def main():

  # Global options
  np.set_printoptions(precision=3, suppress=True, linewidth=100)

  ###########################
  # Generate Ordinary Patch #
  ###########################

  X = example_extraordinary_patch(6) # BSpline
  B = loop.bspline_to_bezier_conversion(6).dot(X)

  #################
  # Check corners #
  #################

  assert(np.allclose(B[0] - X[1], np.zeros(X.shape)))
  assert(np.allclose(B[1] - X[6], np.zeros(X.shape)))
  assert(np.allclose(B[2] - X[0], np.zeros(X.shape)))

  ##############################
  # Check points in the middle #
  ##############################

  bezier_position = bezier_position_function()

  for a in np.arange(0.1, 1.0, 0.1):
    for b in np.arange(0.1, 1 - a, 0.1):
      bezier = B.transpose() * bezier_position.subs( { r : 1 - a - b, s : a, t : b } )
      bezier = np.array(bezier.tolist()).astype(np.float64).transpose()[0,:]
      bspline = loop.recursive_evaluate(0,
                                        loop.triangle_bspline_position_basis,
                                        6,
                                        (a,b),
                                        X)
      assert(np.allclose(bezier - bspline,np.zeros(bezier.shape)))

  #####################
  # Thin plate energy #
  #####################

  M = bezier_thin_plate_matrix()

  print "M*2560 =\n"
  sp.pprint(M*2560)

  M = np.array(M.tolist()).astype(np.float64)

  B = B.flatten('F')
  M_Block = np.zeros((M.shape[0]*2, M.shape[1]*2))
  M_Block[0:M.shape[0], 0:M.shape[1]] = M
  M_Block[M.shape[0]:, M.shape[1]:] = M

  tp = B.dot(M_Block).dot(B)
  assert(np.allclose(tp, [[0]]))
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('N', nargs='?', type=int, default=6)
    parser.add_argument('n', nargs='?', type=int, default=16)
    parser.add_argument('--seed', type=int, default=-1)
    args = parser.parse_args()

    # Generate example extraordinary patch with an extraordinary face of `N`
    # sides.
    # Use `seed < 0` to signal evaluating the linear weights only
    # (i.e. `X = None`).
    print 'N:', args.N
    print 'seed:', args.seed
    if args.seed >= 0:
        X = example_extraordinary_patch(args.N)
        np.random.seed(args.seed)
        X += 0.1 * np.random.randn(X.size).reshape(X.shape)
        print 'X:', X.shape
    else:
        X = None
        print 'X: None'

    # Evaluate with basis functions for small `u` with `v = 0`.
    powers_and_basis_functions = [(1, doosabin.biquadratic_bspline_du_basis),
                                  (2, doosabin.biquadratic_bspline_du_du_basis)
                                  ]
    u = 2.0**(-np.arange(1, args.n + 1))
    U = np.c_[u, [0.0] * u.size]

    f, axs = plt.subplots(2, 1)

    for ax, (p, b) in zip(axs, powers_and_basis_functions):
        print '%s:' % b.func_name

        norms = []
        for u in U:
            q = doosabin.recursive_evaluate(p, b, args.N, u, X)
            n = np.linalg.norm(q)
            norms.append(n)

            print('  (2^%d, %g) ->' % (np.around(np.log2(u[0])), u[1])),
            if X is not None:
                print('(%+.3e, %+.3e)' % (q[0], q[1])),
            print '<%.3e>' % n

        ax.plot(norms, 'o-')
        for i, n in enumerate(norms):
            ax.text(i, n, '$%.3e$' % n, horizontalalignment='center')
        set_xaxis_ticks(ax, ['$2^{%d}$' % (-(i + 1)) for i in range(args.n)])
        ax.set_yticks([])

    axs[0].set_title(r'$N = %d\;|\partial u|$' % args.N)
    axs[1].set_title(r'$N = %d\;|\partial u^2|$' % args.N)

    plt.show()
Exemplo n.º 3
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('N', nargs='?', type=int, default=5)
    parser.add_argument('n', nargs='?', type=int, default=16)
    parser.add_argument('--seed', type=int, default=-1)
    args = parser.parse_args()

    # Generate example extraordinary patch with an extraordinary face of `N`
    # sides.
    # Use `seed < 0` to signal evaluating the linear weights only
    # (i.e. `X = None`).
    print 'N:', args.N
    print 'seed:', args.seed
    if args.seed >= 0:
        X = example_extraordinary_patch(args.N)
        np.random.seed(args.seed)
        X += 0.1 * np.random.randn(X.size).reshape(X.shape)
        print 'X:', X.shape
    else:
        X = None
        print 'X: None'

    # Evaluate with basis functions for small `u` with `v = 0`.
    powers_and_basis_functions = [
        (1, loop.triangle_bspline_du_basis),
        (2, loop.triangle_bspline_du_du_basis)]
    u = 2.0 ** (-np.arange(1, args.n + 1))
    U = np.c_[u, [0.0] * u.size]

    f, axs = plt.subplots(2, 1)

    for ax, (p, b) in zip(axs, powers_and_basis_functions):
        print '%s:' % b.func_name

        norms = []
        for u in U:
            q = loop.recursive_evaluate(p, b, args.N, u, X)
            n = np.linalg.norm(q)
            norms.append(n)

            print ('  (2^%d, %g) ->' % (np.around(np.log2(u[0])), u[1])),
            if X is not None:
                print ('(%+.3e, %+.3e)' % (q[0], q[1])),
            print '<%.3e>' % n

        ax.plot(norms, 'o-')
        for i, n in enumerate(norms):
            ax.text(i, n, '$%.3e$' % n, horizontalalignment='center')
        set_xaxis_ticks(ax, ['$2^{%d}$' % (-(i + 1)) for i in range(args.n)])
        ax.set_yticks([])

    axs[0].set_title(r'$N = %d\;|\partial u|$' % args.N)
    axs[1].set_title(r'$N = %d\;|\partial u^2|$' % args.N)

    plt.show()
Exemplo n.º 4
0
def main():
    parser = argparse.ArgumentParser()
    # Valency of the vertex of interest.
    parser.add_argument('N', nargs='?', type=int, default=5)
    # Number of levels of subdivision.
    parser.add_argument('n', nargs='?', type=int, default=2)
    # Sampling density along each parametric axis.
    parser.add_argument('m', nargs='?', type=int, default=21)
    args = parser.parse_args()

    # Generate example extraordinary patch with an extraordinary vertex of valency `N`.
    X = example_extraordinary_patch(args.N)

    # Visualise `n` "levels" of subdivision.
    A = loop.extended_subdivision_matrix(args.N)
    A_ = loop.bigger_subdivision_matrix(args.N)
    Xs, Xs_ = [X], []
    for i in range(args.n):
        Xi = Xs[-1]
        Xs.append(np.dot(A, Xi))
        Xs_.append(np.dot(A_, Xi))

    colours = cm.Set1(np.linspace(0.0, 1.0, 9, endpoint=True))[:, :3]
    f, ax = plt.subplots()
    ax.set_aspect('equal')
    ax.set_xticks([])
    ax.set_yticks([])
    for i, Xi in enumerate(Xs):
        x, y = Xi.T
        c = colours[i % colours.shape[0]]
        ax.plot(x, y, 'o-', c=c)
        if i >= 1:
            x1, y1 = Xs_[i - 1][-6:].T
            ax.plot(x1, y1, 'o-', c=c)
            ax.plot([x[-1], x1[0]], [y[-1], y1[0]], '--', c=c)

    # Evaluate points on the patch using recursive subdivision and the position
    # basis functions.
    t, step = np.linspace(0.0, 1.0, args.m, endpoint=False, retstep=True)
    t += 0.5 * step
    U = np.dstack(np.broadcast_arrays(t[:, np.newaxis], t)).reshape(-1, 2)
    U = U[np.sum(U, axis=1) <= 1.0 - 1e-8]
    P = np.array([loop.recursive_evaluate(
                    0, loop.triangle_bspline_position_basis,
                    args.N, u, X)
                  for u in U])
    x, y = P.T
    ax.plot(x, y, 'k.')
    ax.set_title('N = %d, n = %d, # = %d' % (args.N, args.n, len(P)))

    plt.show()
Exemplo n.º 5
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('N', nargs='?', type=int, default=6)
    parser.add_argument('n', nargs='?', type=int, default=2)
    parser.add_argument('m', nargs='?', type=int, default=21)
    args = parser.parse_args()

    # Generate example extraordinary patch with an extraordinary face of `N`
    # sides.
    X = example_extraordinary_patch(args.N)

    # Visualise `n` "levels" of subdivision.
    A = doosabin.extended_subdivision_matrix(args.N)
    A_ = doosabin.bigger_subdivision_matrix(args.N)
    Xs, Xs_ = [X], []
    for i in range(args.n):
        Xi = Xs[-1]
        Xs.append(np.dot(A, Xi))
        Xs_.append(np.dot(A_, Xi))

    colours = cm.Set1(np.linspace(0.0, 1.0, 9, endpoint=True))[:, :3]
    f, ax = plt.subplots()
    ax.set_aspect('equal')
    ax.set_xticks([])
    ax.set_yticks([])
    for i, Xi in enumerate(Xs):
        x, y = Xi.T
        c = colours[i % colours.shape[0]]
        ax.plot(x, y, 'o-', c=c)
        if i >= 1:
            x1, y1 = Xs_[i - 1][-7:].T
            ax.plot(x1, y1, 'o-', c=c)
            ax.plot([x[-1], x1[0]], [y[-1], y1[0]], '--', c=c)

    # Evaluate points on the patch using recursive subdivision and the position
    # basis functions.
    t, step = np.linspace(0.0, 1.0, args.m, endpoint=False, retstep=True)
    t += 0.5 * step
    U = np.dstack(np.broadcast_arrays(t[:, np.newaxis], t)).reshape(-1, 2)
    P = np.array([
        doosabin.recursive_evaluate(
            0, doosabin.biquadratic_bspline_position_basis, args.N, u, X)
        for u in U
    ])
    x, y = P.T
    ax.plot(x, y, 'k.')
    ax.set_title('N = %d, n = %d, # = %d' % (args.N, args.n, len(P)))

    plt.show()
Exemplo n.º 6
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('N', nargs='?', type=int, default=6)
    parser.add_argument('n', nargs='?', type=int, default=2)
    parser.add_argument('m', nargs='?', type=int, default=21)
    args = parser.parse_args()

    # Generate example extraordinary patch with an extraordinary face of `N`
    # sides.
    X = example_extraordinary_patch(args.N)

    # Visualise `n` "levels" of subdivision.
    A = doosabin.extended_subdivision_matrix(args.N)
    A_ = doosabin.bigger_subdivision_matrix(args.N)
    Xs, Xs_ = [X], []
    for i in range(args.n):
        Xi = Xs[-1]
        Xs.append(np.dot(A, Xi))
        Xs_.append(np.dot(A_, Xi))

    colours = cm.Set1(np.linspace(0.0, 1.0, 9, endpoint=True))[:, :3]
    f, ax = plt.subplots()
    ax.set_aspect('equal')
    ax.set_xticks([])
    ax.set_yticks([])
    for i, Xi in enumerate(Xs):
        x, y = Xi.T
        c = colours[i % colours.shape[0]]
        ax.plot(x, y, 'o-', c=c)
        if i >= 1:
            x1, y1 = Xs_[i - 1][-7:].T
            ax.plot(x1, y1, 'o-', c=c)
            ax.plot([x[-1], x1[0]], [y[-1], y1[0]], '--', c=c)

    # Evaluate points on the patch using recursive subdivision and the position
    # basis functions.
    t, step = np.linspace(0.0, 1.0, args.m, endpoint=False, retstep=True)
    t += 0.5 * step
    U = np.dstack(np.broadcast_arrays(t[:, np.newaxis], t)).reshape(-1, 2)
    P = np.array([doosabin.recursive_evaluate(
                    0, doosabin.biquadratic_bspline_position_basis,
                    args.N, u, X)
                  for u in U])
    x, y = P.T
    ax.plot(x, y, 'k.')
    ax.set_title('N = %d, n = %d, # = %d' % (args.N, args.n, len(P)))

    plt.show()
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('N', nargs='?', type=int, default=6)
    parser.add_argument('n', nargs='?', type=int, default=16)
    parser.add_argument('--seed', type=int, default=-1)
    args = parser.parse_args()

    # Generate example extraordinary patch with an extraordinary face of `N`
    # sides.
    # Use `seed < 0` to signal evaluating the linear weights only
    # (i.e. `X = None`).
    print 'N:', args.N
    print 'seed:', args.seed
    if args.seed >= 0:
        X = example_extraordinary_patch(args.N)
        np.random.seed(args.seed)
        X += 0.1 * np.random.randn(X.size).reshape(X.shape)
        print 'X:', X.shape
    else:
        X = None
        print 'X: None'

    generators_and_subs = [('biquadratic_bspline_du_basis', du_k_0, {
        u: 1
    }), ('biquadratic_bspline_du_du_basis', du_du_k_0, {})]

    f, axs = plt.subplots(2, 1)

    for ax, (name, g, subs) in zip(axs, generators_and_subs):
        print '%s:' % name

        # Ignore first subdivision so that the reported results correspond with
        # those generated by derivatives_numeric.py (which implicitly skips the
        # first subdivision due to the calculation for `n` in
        # `transform_u_to_subdivided_patch`).
        g = g(args.N)
        next(g)

        norms = []
        for i in range(args.n):
            b = next(g).subs(subs)
            q = map(np.float64, b)
            if X is not None:
                q = np.dot(q, X)
            n = np.linalg.norm(q)
            norms.append(n)

            print('  (2^%d, 0) ->' % (-(i + 1))),
            if X is not None:
                print('(%+.3e, %+.3e)' % (q[0], q[1])),
            print '<%.3e>' % n

        ax.plot(norms, 'o-')
        for i, n in enumerate(norms):
            ax.text(i, n, '$%.3e$' % n, horizontalalignment='center')
        set_xaxis_ticks(ax, ['$2^{%d}$' % (-(i + 1)) for i in range(args.n)])
        ax.set_yticks([])

    axs[0].set_title(r'$|N = %d, \partial u|$' % args.N)
    axs[1].set_title(r'$|N = %d, \partial u^2|$' % args.N)

    plt.show()
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('N', nargs='?', type=int, default=6)
    parser.add_argument('n', nargs='?', type=int, default=16)
    parser.add_argument('--seed', type=int, default=-1)
    args = parser.parse_args()

    # Generate example extraordinary patch with an extraordinary face of `N`
    # sides.
    # Use `seed < 0` to signal evaluating the linear weights only
    # (i.e. `X = None`).
    print 'N:', args.N
    print 'seed:', args.seed
    if args.seed >= 0:
        X = example_extraordinary_patch(args.N)
        np.random.seed(args.seed)
        X += 0.1 * np.random.randn(X.size).reshape(X.shape)
        print 'X:', X.shape
    else:
        X = None
        print 'X: None'

    generators_and_subs = [('biquadratic_bspline_du_basis', du_k_0, {u : 1}),
                           ('biquadratic_bspline_du_du_basis', du_du_k_0, {})]

    f, axs = plt.subplots(2, 1)

    for ax, (name, g, subs) in zip(axs, generators_and_subs):
        print '%s:' % name

        # Ignore first subdivision so that the reported results correspond with
        # those generated by derivatives_numeric.py (which implicitly skips the
        # first subdivision due to the calculation for `n` in
        # `transform_u_to_subdivided_patch`).
        g = g(args.N)
        next(g)

        norms = []
        for i in range(args.n):
            b = next(g).subs(subs)
            q = map(np.float64, b)
            if X is not None:
                q = np.dot(q, X)
            n = np.linalg.norm(q)
            norms.append(n)

            print ('  (2^%d, 0) ->' % (-(i + 1))),
            if X is not None:
                print ('(%+.3e, %+.3e)' % (q[0], q[1])),
            print '<%.3e>' % n

        ax.plot(norms, 'o-')
        for i, n in enumerate(norms):
            ax.text(i, n, '$%.3e$' % n, horizontalalignment='center')
        set_xaxis_ticks(ax, ['$2^{%d}$' % (-(i + 1)) for i in range(args.n)])
        ax.set_yticks([])

    axs[0].set_title(r'$|N = %d, \partial u|$' % args.N)
    axs[1].set_title(r'$|N = %d, \partial u^2|$' % args.N)

    plt.show()