Пример #1
0
def project(smov):
    '''
    Project vertices of moving sphere into reference sphere and
    then project the vertices of the native moving vertices into the native
    reference mesh
    '''
    # smov is eigen, dimensions nverts * 3
    global Vref, Sref, Fref
    # compute closest points of smv in Sref
    sqrD = igl.eigen.MatrixXd()
    I = igl.eigen.MatrixXi()
    C = igl.eigen.MatrixXd()
    igl.point_mesh_squared_distance(smov, Sref, Fref, sqrD, I, C)
    # get barycentric coordinates
    Vx = igl.eigen.MatrixXd()
    Vy = igl.eigen.MatrixXd()
    Vz = igl.eigen.MatrixXd()
    xyz = p2e(np.array([0, 1, 2]))
    V = igl.eigen.MatrixXd()
    F = igl.eigen.MatrixXi()
    igl.slice(Fref, I, xyz, F)
    igl.slice(Sref, F.col(0), xyz, Vx)
    igl.slice(Sref, F.col(1), xyz, Vy)
    igl.slice(Sref, F.col(2), xyz, Vz)
    B = igl.eigen.MatrixXd()
    igl.barycentric_coordinates(C, Vx, Vy, Vz, B)
    # get coordinates in Vref space
    igl.slice(Vref, F.col(0), xyz, Vx)
    igl.slice(Vref, F.col(1), xyz, Vy)
    igl.slice(Vref, F.col(2), xyz, Vz)
    V = igl.eigen.MatrixXd(smov)
    for i in range(smov.rows()):
        V.setRow(
            i,
            Vx.row(i) * B[i, 0] + Vy.row(i) * B[i, 1] + Vz.row(i) * B[i, 2])

    return V  # V is eigen
Пример #2
0
    update_visualization(viewer)
    return True


print("Press [space] to toggle showing surface.")
print("Press '.'/',' to push back/pull forward slicing plane.")

# Load mesh: (V,T) tet-mesh of convex hull, F contains original surface triangles
igl.readMESH(TUTORIAL_SHARED_PATH + "bunny.mesh", V, T, F)

# Call to point_mesh_squared_distance to determine bounds
sqrD = igl.eigen.MatrixXd()
I = igl.eigen.MatrixXi()
C = igl.eigen.MatrixXd()
igl.point_mesh_squared_distance(V, V, F, sqrD, I, C)
max_distance = math.sqrt(sqrD.maxCoeff())

# Precompute signed distance AABB tree
tree.init(V, F)

# Precompute vertex, edge and face normals
igl.per_face_normals(V, F, FN)
igl.per_vertex_normals(V, F, igl.PER_VERTEX_NORMALS_WEIGHTING_TYPE_ANGLE, FN,
                       VN)
igl.per_edge_normals(V, F, igl.PER_EDGE_NORMALS_WEIGHTING_TYPE_UNIFORM, FN, EN,
                     E, EMAP)

# Plot the generated mesh
update_visualization(viewer)
viewer.callback_key_down = key_down
Пример #3
0
def setup_deformation_transfer(source, target, use_normals=False):
    rows = np.zeros(3 * target.v.shape[0])
    cols = np.zeros(3 * target.v.shape[0])
    coeffs_v = np.zeros(3 * target.v.shape[0])
    coeffs_n = np.zeros(3 * target.v.shape[0])

    print("Computing nearest vertices")

    P = p2e(target.v)
    V = p2e(source.v)
    F = p2e(source.f)

    sqrD = igl.eigen.MatrixXd()
    nearest_faces = igl.eigen.MatrixXi()
    nearest_vertices = igl.eigen.MatrixXd()
    igl.point_mesh_squared_distance(P, V, F, sqrD, nearest_faces,
                                    nearest_vertices)

    print("Computing barycentric coordinates")

    coeffs_v = igl.eigen.MatrixXd()
    Va, Vb, Vc = igl.eigen.MatrixXd(), igl.eigen.MatrixXd(
    ), igl.eigen.MatrixXd()
    F2 = igl.eigen.MatrixXi()
    xyz = p2e(np.array([0, 1, 2]))

    igl.slice(F, nearest_faces, xyz, F2)
    igl.slice(V, F2.col(0), xyz, Va)
    igl.slice(V, F2.col(1), xyz, Vb)
    igl.slice(V, F2.col(2), xyz, Vc)

    igl.barycentric_coordinates(nearest_vertices, Va, Vb, Vc, coeffs_v)

    nearest_faces = e2p(nearest_faces)
    coeffs_v = e2p(coeffs_v).ravel()

    rows = np.array([i for i in range(target.v.shape[0]) for _ in range(3)])
    cols = source.f[nearest_faces].ravel()
    """
    nearest_faces, nearest_parts, nearest_vertices = source.compute_aabb_tree().nearest(target.v, True)
    nearest_faces = nearest_faces.ravel().astype(np.int64)
    nearest_parts = nearest_parts.ravel().astype(np.int64)
    nearest_vertices = nearest_vertices.ravel()

    for i in range(target.v.shape[0]):
        # Closest triangle index
        f_id = nearest_faces[i]
        # Closest triangle vertex ids
        nearest_f = source.f[f_id]

        # Closest surface point
        nearest_v = nearest_vertices[3 * i:3 * i + 3]
        # Distance vector to the closest surface point
        dist_vec = target.v[i] - nearest_v

        rows[3 * i:3 * i + 3] = i * np.ones(3)
        cols[3 * i:3 * i + 3] = nearest_f

        n_id = nearest_parts[i]
        if n_id == 0:
            # Closest surface point in triangle
            A = np.vstack((source.v[nearest_f])).T
            coeffs_v[3 * i:3 * i + 3] = np.linalg.lstsq(A, nearest_v)[0]
        elif n_id > 0 and n_id <= 3:
            # Closest surface point on edge
            A = np.vstack((source.v[nearest_f[n_id - 1]], source.v[nearest_f[n_id % 3]])).T
            tmp_coeffs = np.linalg.lstsq(A, target.v[i])[0]
            coeffs_v[3 * i + n_id - 1] = tmp_coeffs[0]
            coeffs_v[3 * i + n_id % 3] = tmp_coeffs[1]
        else:
            # Closest surface point a vertex
            coeffs_v[3 * i + n_id - 4] = 1.0
        """

    #    if use_normals:
    #        A = np.vstack((vn[nearest_f])).T
    #        coeffs_n[3 * i:3 * i + 3] = np.linalg.lstsq(A, dist_vec)[0]

    #coeffs = np.hstack((coeffs_v, coeffs_n))
    #rows = np.hstack((rows, rows))
    #cols = np.hstack((cols, source.v.shape[0] + cols))
    matrix = sp.csc_matrix((coeffs_v, (rows, cols)),
                           shape=(target.v.shape[0], source.v.shape[0]))
    return matrix
Пример #4
0
    update_visualization(viewer)
    return True


print("Press [space] to toggle showing surface.")
print("Press '.'/',' to push back/pull forward slicing plane.")

# Load mesh: (V,T) tet-mesh of convex hull, F contains original surface triangles
igl.readMESH(TUTORIAL_SHARED_PATH + "bunny.mesh", V, T, F)

# Call to point_mesh_squared_distance to determine bounds
sqrD = igl.eigen.MatrixXd()
I = igl.eigen.MatrixXi()
C = igl.eigen.MatrixXd()
igl.point_mesh_squared_distance(V, V, F, sqrD, I, C)
max_distance = math.sqrt(sqrD.maxCoeff())

# Precompute signed distance AABB tree
tree.init(V, F)

# Precompute vertex, edge and face normals
igl.per_face_normals(V, F, FN)
igl.per_vertex_normals(V, F, igl.PER_VERTEX_NORMALS_WEIGHTING_TYPE_ANGLE, FN, VN)
igl.per_edge_normals(V, F, igl.PER_EDGE_NORMALS_WEIGHTING_TYPE_UNIFORM, FN, EN, E, EMAP)

# Plot the generated mesh
update_visualization(viewer)
viewer.callback_key_down = key_down
viewer.core.show_lines = False
viewer.launch()