Esempio n. 1
0
def update(viewer):
    global V, F, T, W, slice_z, overlay
    plane = igl.eigen.MatrixXd([
        0, 0, 1,
        -((1 - slice_z) * V.col(2).minCoeff() + slice_z * V.col(2).maxCoeff())
    ])
    V_vis = igl.eigen.MatrixXd()
    F_vis = igl.eigen.MatrixXi()
    J = igl.eigen.MatrixXi()
    bary = igl.eigen.SparseMatrixd()
    igl.slice_tets(V, T, plane, V_vis, F_vis, J, bary)
    W_vis = igl.eigen.MatrixXd()
    igl.slice(W, J, W_vis)
    C_vis = igl.eigen.MatrixXd()
    igl.parula(W_vis, False, C_vis)

    if overlay == 1:  # OVERLAY_INPUT
        append_mesh(C_vis, F_vis, V_vis, V, F,
                    igl.eigen.MatrixXd([[1., 0.894, 0.227]]))
    elif overlay == 2:  # OVERLAY_OUTPUT
        append_mesh(C_vis, F_vis, V_vis, V, F,
                    igl.eigen.MatrixXd([[0.8, 0.8, 0.8]]))

    viewer.data.clear()
    viewer.data.set_mesh(V_vis, F_vis)
    viewer.data.set_colors(C_vis)
    viewer.data.set_face_based(True)
Esempio n. 2
0
def scramble_colors():
    global C, viewer, RGBcolors
    for p in range(2):
        R = igl.eigen.MatrixXi()
        igl.randperm(C[p].maxCoeff() + 1, R)
        C[p] = igl.slice(R, igl.eigen.MatrixXi(C[p]))
        HSV = igl.eigen.MatrixXd(C[p].rows(), 3)
        HSV.setCol(0, 360.0 * C[p].castdouble() / C[p].maxCoeff())
        HSVright = igl.eigen.MatrixXd(HSV.rows(), 2)
        HSVright.setConstant(1.0)
        HSV.setRightCols(2, HSVright)
        igl.hsv_to_rgb(HSV, RGBcolors[p])
    viewer.data.set_colors(RGBcolors[facetwise])
Esempio n. 3
0
def update(viewer):
    global V, F, T, W, slice_z, overlay
    plane = igl.eigen.MatrixXd([0, 0, 1, -((1 - slice_z) * V.col(2).minCoeff() + slice_z * V.col(2).maxCoeff())])
    V_vis = igl.eigen.MatrixXd()
    F_vis = igl.eigen.MatrixXi()
    J = igl.eigen.MatrixXi()
    bary = igl.eigen.SparseMatrixd()
    igl.marching_tets(V, T, plane, V_vis, F_vis, J, bary)
    W_vis = igl.eigen.MatrixXd()
    igl.slice(W, J, W_vis)
    C_vis = igl.eigen.MatrixXd()
    igl.parula(W_vis, False, C_vis)

    if overlay == 1:  # OVERLAY_INPUT
        append_mesh(C_vis, F_vis, V_vis, V, F, igl.eigen.MatrixXd([[1., 0.894, 0.227]]))
    elif overlay == 2:  # OVERLAY_OUTPUT
        append_mesh(C_vis, F_vis, V_vis, V, F, igl.eigen.MatrixXd([[0.8, 0.8, 0.8]]))

    viewer.data().clear()
    viewer.data().set_mesh(V_vis, F_vis)
    viewer.data().set_colors(C_vis)
    viewer.data().set_face_based(True)
Esempio n. 4
0
def scramble_colors():
    global C, viewer, RGBcolors
    for p in range(2):
        R = igl.eigen.MatrixXi()
        igl.randperm(C[p].maxCoeff() + 1, R)
        C[p] = igl.slice(R, igl.eigen.MatrixXi(C[p]))
        HSV = igl.eigen.MatrixXd(C[p].rows(), 3)
        HSV.setCol(0, 360.0 * C[p].castdouble() / C[p].maxCoeff())
        HSVright = igl.eigen.MatrixXd(HSV.rows(), 2)
        HSVright.setConstant(1.0)
        HSV.setRightCols(2, HSVright)
        igl.hsv_to_rgb(HSV, RGBcolors[p])
    viewer.data().set_colors(RGBcolors[facetwise])
Esempio n. 5
0
FQCtri.resize(2 * FQC.rows(), 3)

FQCtriUpper = igl.eigen.MatrixXi(FQC.rows(), 3)
FQCtriLower = igl.eigen.MatrixXi(FQC.rows(), 3)

FQCtriUpper.setCol(0, FQC.col(0))
FQCtriUpper.setCol(1, FQC.col(1))
FQCtriUpper.setCol(2, FQC.col(2))
FQCtriLower.setCol(0, FQC.col(2))
FQCtriLower.setCol(1, FQC.col(3))
FQCtriLower.setCol(2, FQC.col(0))

FQCtri.setTopRows(FQCtriUpper.rows(), FQCtriUpper)
FQCtri.setBottomRows(FQCtriLower.rows(), FQCtriLower)

igl.slice(VQC, FQC.col(0), 1, PQC0)
igl.slice(VQC, FQC.col(1), 1, PQC1)
igl.slice(VQC, FQC.col(2), 1, PQC2)
igl.slice(VQC, FQC.col(3), 1, PQC3)

# Planarize it
igl.planarize_quad_mesh(VQC, FQC, 100, 0.005, VQCplan)

# Convert the planarized mesh to triangles
igl.slice(VQCplan, FQC.col(0), 1, PQC0plan)
igl.slice(VQCplan, FQC.col(1), 1, PQC1plan)
igl.slice(VQCplan, FQC.col(2), 1, PQC2plan)
igl.slice(VQCplan, FQC.col(3), 1, PQC3plan)

# Launch the viewer
key_down(viewer, ord('2'), 0)
# List of all vertex indices
vall = igl.eigen.MatrixXi()
vin = igl.eigen.MatrixXi()

igl.coloni(0, V.rows() - 1, vall)

# List of interior indices
igl.setdiff(vall, b, vin, IA)

# Construct and slice up Laplacian
L = igl.eigen.SparseMatrixd()
L_in_in = igl.eigen.SparseMatrixd()
L_in_b = igl.eigen.SparseMatrixd()

igl.cotmatrix(V, F, L)
igl.slice(L, vin, vin, L_in_in)
igl.slice(L, vin, b, L_in_b)

# Dirichlet boundary conditions from z-coordinate
bc = igl.eigen.MatrixXd()
Z = V.col(2)
igl.slice(Z, b, bc)

# Solve PDE
solver = igl.eigen.SimplicialLLTsparse(-L_in_in)
Z_in = solver.solve(L_in_b * bc)

# slice into solution
igl.slice_into(Z_in, vin, Z)

# Alternative, short hand
Esempio n. 7
0
# List of all vertex indices
vall  = igl.eigen.MatrixXi()
vin   = igl.eigen.MatrixXi()

igl.coloni(0,V.rows()-1,vall)

# List of interior indices
igl.setdiff(vall,b,vin,IA)

# Construct and slice up Laplacian
L = igl.eigen.SparseMatrixd()
L_in_in = igl.eigen.SparseMatrixd()
L_in_b = igl.eigen.SparseMatrixd()

igl.cotmatrix(V,F,L)
igl.slice(L,vin,vin,L_in_in)
igl.slice(L,vin,b,L_in_b)

# Dirichlet boundary conditions from z-coordinate
bc = igl.eigen.MatrixXd()
Z = V.col(2)
igl.slice(Z,b,bc)

# Solve PDE
solver = igl.eigen.SimplicialLLTsparse(-L_in_in)
Z_in = solver.solve(L_in_b*bc)

# slice into solution
igl.slice_into(Z_in,vin,Z)

# Alternative, short hand
Esempio n. 8
0
V = igl.eigen.MatrixXd()
F = igl.eigen.MatrixXi()

igl.readOFF(TUTORIAL_SHARED_PATH + "decimated-knight.off", V, F)

# 100 random indices into rows of F
I = igl.eigen.MatrixXi()
igl.floor((0.5 * (igl.eigen.MatrixXd.Random(100, 1) + 1.) * F.rows()), I)

# 50 random indices into rows of I
J = igl.eigen.MatrixXi()
igl.floor((0.5 * (igl.eigen.MatrixXd.Random(50, 1) + 1.) * I.rows()), J)

# K = I(J);
K = igl.eigen.MatrixXi()
igl.slice(I, J, K)

# default green for all faces
# C = p2e(np.array([[0.4,0.8,0.3]])).replicate(F.rows(),1)
C = igl.eigen.MatrixXd([[0.4, 0.8, 0.3]]).replicate(F.rows(), 1)

# Red for each in K
R = igl.eigen.MatrixXd([[1.0, 0.3, 0.3]]).replicate(K.rows(), 1)
# C(K,:) = R
igl.slice_into(R, K, 1, C)

# Plot the mesh with pseudocolors
viewer = igl.glfw.Viewer()
viewer.data().set_mesh(V, F)
viewer.data().set_colors(C)
viewer.launch()
class Geom():
    def __init__(self, s=None):
        self.V = igl.eigen.MatrixXd()
        self.F = igl.eigen.MatrixXi()
        if s is not None:
            igl.read_triangle_mesh(s, self.V, self.F)


# Picking Largest Component
from scipy import stats
for path in scans:
    Inmodel = Geom(path)
    C = igl.eigen.MatrixXi()
    igl.facet_components(Inmodel.F, C)

    C = (e2p(C)).flatten()
    modeC, mode_count = stats.mode(C)

    if mode_count == Inmodel.F.rows():
        print(f"Already Fit  {path[-15:-12]}")
        igl.write_triangle_mesh(path[:-12] + '_single.obj', Inmodel.V,
                                Inmodel.F)
    else:
        Fid = p2e(np.where(C == modeC)[0])
        F = igl.slice(Inmodel.F, Fid, 1)
        Outmodel = Geom()
        I, J = igl.eigen.MatrixXi(), igl.eigen.MatrixXi()
        igl.remove_unreferenced(Inmodel.V, F, Outmodel.V, Outmodel.F, I, J)
        igl.write_triangle_mesh(path[:-12] + '_single.obj', Outmodel.V,
                                Outmodel.F)
        print(f'Written { path[-15:-12]}')
Esempio n. 10
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
Esempio n. 11
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
FQCtri.resize(2 * FQC.rows(), 3)

FQCtriUpper = igl.eigen.MatrixXi(FQC.rows(), 3)
FQCtriLower = igl.eigen.MatrixXi(FQC.rows(), 3)

FQCtriUpper.setCol(0, FQC.col(0))
FQCtriUpper.setCol(1, FQC.col(1))
FQCtriUpper.setCol(2, FQC.col(2))
FQCtriLower.setCol(0, FQC.col(2))
FQCtriLower.setCol(1, FQC.col(3))
FQCtriLower.setCol(2, FQC.col(0))

FQCtri.setTopRows(FQCtriUpper.rows(), FQCtriUpper)
FQCtri.setBottomRows(FQCtriLower.rows(), FQCtriLower)

igl.slice(VQC, FQC.col(0), 1, PQC0)
igl.slice(VQC, FQC.col(1), 1, PQC1)
igl.slice(VQC, FQC.col(2), 1, PQC2)
igl.slice(VQC, FQC.col(3), 1, PQC3)

# Planarize it
igl.planarize_quad_mesh(VQC, FQC, 100, 0.005, VQCplan)

# Convert the planarized mesh to triangles
igl.slice(VQCplan, FQC.col(0), 1, PQC0plan)
igl.slice(VQCplan, FQC.col(1), 1, PQC1plan)
igl.slice(VQCplan, FQC.col(2), 1, PQC2plan)
igl.slice(VQCplan, FQC.col(3), 1, PQC3plan)

# Launch the viewer
key_down(viewer, ord('2'), 0)
Esempio n. 13
0
F = igl.eigen.MatrixXi()


igl.readOFF(TUTORIAL_SHARED_PATH + "decimated-knight.off", V, F)

# 100 random indices into rows of F
I = igl.eigen.MatrixXi()
igl.floor((0.5 * (igl.eigen.MatrixXd.Random(100, 1) + 1.) * F.rows()), I)

# 50 random indices into rows of I
J = igl.eigen.MatrixXi()
igl.floor((0.5 * (igl.eigen.MatrixXd.Random(50, 1) + 1.) * I.rows()), J)

# K = I(J);
K = igl.eigen.MatrixXi()
igl.slice(I, J, K)

# default green for all faces
# C = p2e(np.array([[0.4,0.8,0.3]])).replicate(F.rows(),1)
C = igl.eigen.MatrixXd([[0.4, 0.8, 0.3]]).replicate(F.rows(), 1)

# Red for each in K
R = igl.eigen.MatrixXd([[1.0, 0.3, 0.3]]).replicate(K.rows(), 1)
# C(K,:) = R
igl.slice_into(R, K, 1, C)

# Plot the mesh with pseudocolors
viewer = igl.glfw.Viewer()
viewer.data().set_mesh(V, F)
viewer.data().set_colors(C)
viewer.launch()