Beispiel #1
0
def registerIgarashi():
    global xy, triangles, pins, pinPoses, nVertices, nEdges, edges, heVectors, heIndices
    global A1top, A2top, G
    xy, triangles = planemesh.build(n, scale)
    xy -= 0.5*scale
    pinPoses = xy[pins, :]
    halfedges = halfedge.build(triangles)
    heVectors = np.asarray([xy[he.ivertex, :] - xy[he.prev().ivertex, :] for he in halfedges])
    edges, heIndices = halfedge.toEdge(halfedges)
    nVertices = xy.shape[0]
    nEdges = edges.shape[0]
    A1top, G = igarashi.buildA1top(heVectors, halfedges, edges, heIndices, nVertices)
    A2top = igarashi.buildA2top(edges, nVertices)
Beispiel #2
0
def test2():
    n = 10
    scale = 10
    xy, triangles = planemesh.build(n, scale)
    halfedges = halfedge.build(triangles)
    heVectors = np.asarray(
        [xy[he.ivertex, :] - xy[he.prev().ivertex, :] for he in halfedges])
    pins = np.asarray([0, n])
    #pinPoses = xy[pins, :]
    pinPoses = np.asarray(((-scale, 0), (0, 0)))
    w = 1000.0
    nVertices = xy.shape[0]
    edges, heIndices = halfedge.toEdge(halfedges)
    nEdges = edges.shape[0]

    A1top, G = buildA1top(heVectors, halfedges, edges, heIndices, nVertices)
    A1bottom = buildA1bottom(pins, w, nVertices)
    b1 = buildB1(pins, pinPoses, w, nEdges)
    A1 = sp.vstack((A1top, A1bottom))
    tA1 = A1.transpose()
    v1 = spla.spsolve(tA1 * A1, tA1 * b1)

    A2top = buildA2top(edges, nVertices)
    A2bottom = buildA2bottom(pins, w, nVertices)
    b2 = buildB2(heVectors, heIndices, edges, pinPoses, w, G, v1)
    A2 = sp.vstack((A2top, A2bottom))
    tA2 = A2.transpose()
    v2x = spla.spsolve(tA2 * A2, tA2 * b2[:, 0])
    v2y = spla.spsolve(tA2 * A2, tA2 * b2[:, 1])
    v2 = np.vstack((v2x, v2y)).T

    if n == 1:
        answerA1top = np.asarray(
            ((0, 0, -0.25, 0.25, -0.25, -0.25, 0.5,
              0), (0, 0, -0.25, -0.25, 0.25, -0.25, 0,
                   0.5), (-0.333, 0.333, 0.666, 0, 0, 0, -0.333, -0.333),
             (-0.333, -0.333, 0, 0.666, 0, 0, 0.333,
              -0.333), (0.5, 0, -0.5, -0.5, 0, 0, 0, 0.5), (0, 0.5, 0.5, -0.5,
                                                            0, 0, -0.5, 0),
             (-0.333, -0.333, 0, 0, 0.666, 0, -0.333,
              0.333), (0.333, -0.333, 0, 0, 0, 0.666, -0.333,
                       -0.333), (0, 0.5, 0, 0, -0.5, -0.5, 0.5,
                                 0), (-0.5, 0, 0, 0, 0.5, -0.5, 0, 0.5)))
        print "Error of G : %e" % la.norm(A1top - answerA1top, np.Inf)
        #print "Full A1top : ", A1top.todense()

    v1 = v1.reshape(-1, 2)
    plt.figure()
    plt.gca().set_aspect('equal')
    plt.triplot(v2[:, 0], v2[:, 1], triangles)
    plt.show()
Beispiel #3
0
def test2():
    n = 10
    scale = 10
    xy, triangles = planemesh.build(n, scale)
    halfedges = halfedge.build(triangles)
    heVectors = np.asarray([xy[he.ivertex, :] - xy[he.prev().ivertex, :] for he in halfedges])
    pins = np.asarray([0, n])
    #pinPoses = xy[pins, :]
    pinPoses = np.asarray(( (-scale, 0), (0, 0) ))
    w = 1000.0
    nVertices = xy.shape[0]
    edges, heIndices = halfedge.toEdge(halfedges)
    nEdges = edges.shape[0]
    
    A1top, G = buildA1top(heVectors, halfedges, edges, heIndices, nVertices)
    A1bottom = buildA1bottom(pins, w, nVertices)
    b1 = buildB1(pins, pinPoses, w, nEdges)
    A1 = sp.vstack((A1top, A1bottom))
    tA1 = A1.transpose()
    v1 = spla.spsolve(tA1 * A1, tA1 * b1)
    
    A2top = buildA2top(edges, nVertices)
    A2bottom = buildA2bottom(pins, w, nVertices)
    b2 = buildB2(heVectors, heIndices, edges, pinPoses, w, G, v1)
    A2 = sp.vstack((A2top, A2bottom))
    tA2 = A2.transpose()
    v2x = spla.spsolve(tA2 * A2, tA2 * b2[:, 0])
    v2y = spla.spsolve(tA2 * A2, tA2 * b2[:, 1])
    v2 = np.vstack((v2x, v2y)).T
    
    if n == 1:
        answerA1top = np.asarray(( (     0,      0, -0.25,  0.25, -0.25, -0.25,    0.5,      0),
                                   (     0,      0, -0.25, -0.25,  0.25, -0.25,      0,    0.5),
                                   (-0.333,  0.333, 0.666,     0,     0,     0, -0.333, -0.333),
                                   (-0.333, -0.333,     0, 0.666,     0,     0,  0.333, -0.333),
                                   (   0.5,      0,  -0.5,  -0.5,     0,     0,      0,    0.5),
                                   (     0,    0.5,   0.5,  -0.5,     0,     0,   -0.5,      0),
                                   (-0.333, -0.333,     0,     0, 0.666,     0, -0.333,  0.333),
                                   ( 0.333, -0.333,     0,     0,     0, 0.666, -0.333, -0.333),
                                   (     0,    0.5,     0,     0,  -0.5,  -0.5,    0.5,      0),
                                   (  -0.5,      0,     0,     0,   0.5,  -0.5,      0,    0.5)
                                  ))
        print "Error of G : %e" % la.norm(A1top - answerA1top, np.Inf)
        #print "Full A1top : ", A1top.todense()

    v1 = v1.reshape(-1, 2)
    plt.figure()
    plt.gca().set_aspect('equal')
    plt.triplot(v2[:,0], v2[:,1], triangles)
    plt.show()