Example #1
0
def plot_mesh_nrosy(viewer, V, F, N, PD1, S, b):
    # Clear the mesh
    viewer.data.clear()
    viewer.data.set_mesh(V, F)

    # Expand the representative vectors in the full vector set and plot them as lines
    avg = igl.avg_edge_length(V, F)
    Y = igl.eigen.MatrixXd()
    representative_to_nrosy(V, F, PD1, N, Y)

    B = igl.eigen.MatrixXd()
    igl.barycenter(V, F, B)

    Be = igl.eigen.MatrixXd(B.rows() * N, 3)
    for i in range(0, B.rows()):
        for j in range(0, N):
            Be.setRow(i * N + j, B.row(i))

    viewer.data.add_edges(Be, Be + Y * (avg / 2), igl.eigen.MatrixXd([[0, 0, 1]]))

    # Plot the singularities as colored dots (red for negative, blue for positive)
    for i in range(0, S.size()):
        if S[i] < -0.001:
            viewer.data.add_points(V.row(i), igl.eigen.MatrixXd([[1, 0, 0]]))
        elif S[i] > 0.001:
            viewer.data.add_points(V.row(i), igl.eigen.MatrixXd([[0, 1, 0]]));

    # Highlight in red the constrained faces
    C = igl.eigen.MatrixXd.Constant(F.rows(), 3, 1)
    for i in range(0, b.size()):
        C.setRow(b[i], igl.eigen.MatrixXd([[1, 0, 0]]))
    viewer.data.set_colors(C)
Example #2
0
def key_pressed(viewer, key, modifier):
    global V
    global U
    global F
    global L

    if key == ord('r') or key == ord('R'):
        U = V
    elif key == ord(' '):

        # Recompute just mass matrix on each step
        M = igl.eigen.SparseMatrixd()

        igl.massmatrix(U, F, igl.MASSMATRIX_TYPE_BARYCENTRIC, M)

        # Solve (M-delta*L) U = M*U
        S = (M - 0.001 * L)

        solver = igl.eigen.SimplicialLLTsparse(S)

        U = solver.solve(M * U)

        # Compute centroid and subtract (also important for numerics)
        dblA = igl.eigen.MatrixXd()
        igl.doublearea(U, F, dblA)

        print(dblA.sum())

        area = 0.5 * dblA.sum()
        BC = igl.eigen.MatrixXd()
        igl.barycenter(U, F, BC)
        centroid = igl.eigen.MatrixXd([[0.0, 0.0, 0.0]])

        for i in range(0, BC.rows()):
            centroid += 0.5 * dblA[i, 0] / area * BC.row(i)

        U -= centroid.replicate(U.rows(), 1)

        # Normalize to unit surface area (important for numerics)
        U = U / math.sqrt(area)
    else:
        return False

    # Send new positions, update normals, recenter
    viewer.data.set_vertices(U)
    viewer.data.compute_normals()
    viewer.core.align_camera_center(U, F)
    return True
Example #3
0
def key_pressed(viewer, key, modifier):
    global V
    global U
    global F
    global L

    if key == ord('r') or key == ord('R'):
        U = V;
    elif key == ord(' '):

        # Recompute just mass matrix on each step
        M = igl.eigen.SparseMatrixd()

        igl.massmatrix(U,F,igl.MASSMATRIX_TYPE_BARYCENTRIC,M);

        # Solve (M-delta*L) U = M*U
        S = (M - 0.001*L)

        solver = igl.eigen.SimplicialLLTsparse(S)

        U = solver.solve(M*U)

        # Compute centroid and subtract (also important for numerics)
        dblA = igl.eigen.MatrixXd()
        igl.doublearea(U,F,dblA)

        print(dblA.sum())

        area = 0.5*dblA.sum()
        BC = igl.eigen.MatrixXd()
        igl.barycenter(U,F,BC)
        centroid = igl.eigen.MatrixXd([[0.0,0.0,0.0]])

        for i in range(0,BC.rows()):
            centroid += 0.5*dblA[i,0]/area*BC.row(i)

        U -= centroid.replicate(U.rows(),1)

        # Normalize to unit surface area (important for numerics)
        U = U / math.sqrt(area)
    else:
        return False

    # Send new positions, update normals, recenter
    viewer.data.set_vertices(U)
    viewer.data.compute_normals()
    viewer.core.align_camera_center(U,F)
    return True
Example #4
0
        viewer.data().show_texture = True

    viewer.data().set_colors(igl.eigen.MatrixXd([[1, 1, 1]]))

    viewer.data().set_texture(texture_R, texture_B, texture_G)

    viewer.core.align_camera_center(viewer.data().V, viewer.data().F)

    return False


# Load a mesh in OFF format
igl.readOFF(TUTORIAL_SHARED_PATH + "3holes.off", V, F)

# Compute face barycenters
igl.barycenter(V, F, B)

# Compute scale for visualizing fields
global_scale = .5 * igl.avg_edge_length(V, F)

# Contrain one face
b = igl.eigen.MatrixXd([[0]]).castint()
bc = igl.eigen.MatrixXd([[1, 0, 0]])

# Create a smooth 4-RoSy field
S = igl.eigen.MatrixXd()

igl.comiso.nrosy(V, F, b, bc, igl.eigen.MatrixXi(), igl.eigen.MatrixXd(), igl.eigen.MatrixXd(), 4, 0.5, X1, S)

# Find the orthogonal vector
B1 = igl.eigen.MatrixXd()
        viewer.core.show_texture = True

    viewer.data.set_colors(igl.eigen.MatrixXd([[1, 1, 1]]))

    viewer.data.set_texture(texture_R, texture_B, texture_G)

    viewer.core.align_camera_center(viewer.data.V, viewer.data.F)

    return False


# Load a mesh in OFF format
igl.readOFF(TUTORIAL_SHARED_PATH + "3holes.off", V, F)

# Compute face barycenters
igl.barycenter(V, F, B)

# Compute scale for visualizing fields
global_scale = .5 * igl.avg_edge_length(V, F)

# Contrain one face
b = igl.eigen.MatrixXi([[0]])
bc = igl.eigen.MatrixXd([[1, 0, 0]])

# Create a smooth 4-RoSy field
S = igl.eigen.MatrixXd()

igl.comiso.nrosy(V, F, b, bc, igl.eigen.MatrixXi(), igl.eigen.MatrixXd(), igl.eigen.MatrixXd(), 4, 0.5, X1, S)

# Find the the orthogonal vector
B1 = igl.eigen.MatrixXd()
Example #6
0
# Compute gradient magnitude
GU_mag = GU.rowwiseNorm()

viewer = igl.glfw.Viewer()
viewer.data().set_mesh(V, F)

# Compute pseudocolor for original function
C = igl.eigen.MatrixXd()

igl.jet(U, True, C)

# Or for gradient magnitude
# igl.jet(GU_mag,True,C)

viewer.data().set_colors(C)

# Average edge length divided by average gradient (for scaling)
max_size = igl.avg_edge_length(V, F) / GU_mag.mean()

# Draw a black segment in direction of gradient at face barycenters
BC = igl.eigen.MatrixXd()
igl.barycenter(V, F, BC)

black = igl.eigen.MatrixXd([[0.0, 0.0, 0.0]])
viewer.data().add_edges(BC, BC + max_size * GU, black)

# Hide wireframe
viewer.data().show_lines = False

viewer.launch()
Example #7
0
from shared import TUTORIAL_SHARED_PATH, check_dependencies

dependencies = ["viewer"]
check_dependencies(dependencies)


V = igl.eigen.MatrixXd()
F = igl.eigen.MatrixXi()

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

# Sort barycenters lexicographically
BC = igl.eigen.MatrixXd()
sorted_BC = igl.eigen.MatrixXd()

igl.barycenter(V, F, BC)

I = igl.eigen.MatrixXi()
J = igl.eigen.MatrixXi()

# sorted_BC = BC(I,:)
igl.sortrows(BC, True, sorted_BC, I)

# Get sorted "place" from sorted indices
J.resize(I.rows(), 1)
# J(I) = 1:numel(I)

igl.slice_into(igl.coloni(0, I.size() - 1), I, J)

# Pseudo-color based on sorted place
C = igl.eigen.MatrixXd()
Example #8
0
    V = igl.eigen.MatrixXd()
    BC = igl.eigen.MatrixXd()
    W = igl.eigen.MatrixXd()
    T = igl.eigen.MatrixXi()
    F = igl.eigen.MatrixXi()
    G = igl.eigen.MatrixXi()

    slice_z = 0.5
    overlay = 0

    # Load mesh: (V,T) tet-mesh of convex hull, F contains facets of input
    # surface mesh _after_ self-intersection resolution
    igl.readMESH(TUTORIAL_SHARED_PATH + "big-sigcat.mesh", V, T, F)

    # Compute barycenters of all tets
    igl.barycenter(V, T, BC)

    # Compute generalized winding number at all barycenters
    print("Computing winding number over all %i tets..." % T.rows())
    igl.winding_number(V, F, BC, W)

    # Extract interior tets
    Wt = sum(W > 0.5)
    CT = igl.eigen.MatrixXi(Wt, 4)
    k = 0
    for t in range(T.rows()):
        if W[t] > 0.5:
            CT.setRow(k, T.row(t))
            k += 1

    # find bounary facets of interior tets
Example #9
0
            V_temp.setRow(i * 4 + 3, TV.row(TT[s[i], 3]))

            F_temp.setRow(i * 4 + 0, igl.eigen.MatrixXd([[(i*4)+0, (i*4)+1, (i*4)+3]]).castint())
            F_temp.setRow(i * 4 + 1, igl.eigen.MatrixXd([[(i*4)+0, (i*4)+2, (i*4)+1]]).castint())
            F_temp.setRow(i * 4 + 2, igl.eigen.MatrixXd([[(i*4)+3, (i*4)+2, (i*4)+0]]).castint())
            F_temp.setRow(i * 4 + 3, igl.eigen.MatrixXd([[(i*4)+1, (i*4)+2, (i*4)+3]]).castint())

        viewer.data().clear()
        viewer.data().set_mesh(V_temp, F_temp)
        viewer.data().set_face_based(True)

    else:
        return False

    return True


# Load a surface mesh
igl.readOFF(TUTORIAL_SHARED_PATH + "fertility.off", V, F)

# Tetrahedralize the interior
igl.tetgen.tetrahedralize(V, F, "pq1.414Y", TV, TT, TF)

# Compute barycenters
igl.barycenter(TV, TT, B)

# Plot the generated mesh
key_down(viewer, ord('5'), 0)
viewer.callback_key_down = key_down
viewer.launch()
Example #10
0
    V = igl.eigen.MatrixXd()
    BC = igl.eigen.MatrixXd()
    W = igl.eigen.MatrixXd()
    T = igl.eigen.MatrixXi()
    F = igl.eigen.MatrixXi()
    G = igl.eigen.MatrixXi()

    slice_z = 0.5
    overlay = 0

    # Load mesh: (V,T) tet-mesh of convex hull, F contains facets of input
    # surface mesh _after_ self-intersection resolution
    igl.readMESH(TUTORIAL_SHARED_PATH + "big-sigcat.mesh", V, T, F)

    # Compute barycenters of all tets
    igl.barycenter(V, T, BC)

    # Compute generalized winding number at all barycenters
    print("Computing winding number over all %i tets..." % T.rows())
    igl.winding_number(V, F, BC, W)

    # Extract interior tets
    Wt = sum(W > 0.5)
    CT = igl.eigen.MatrixXi(Wt, 4)
    k = 0
    for t in range(T.rows()):
        if W[t] > 0.5:
            CT.setRow(k, T.row(t))
            k += 1

    # find bounary facets of interior tets
Example #11
0
                igl.eigen.MatrixXd([[(i * 4) + 3, (i * 4) + 2,
                                     (i * 4) + 0]]).castint())
            F_temp.setRow(
                i * 4 + 3,
                igl.eigen.MatrixXd([[(i * 4) + 1, (i * 4) + 2,
                                     (i * 4) + 3]]).castint())

        viewer.data().clear()
        viewer.data().set_mesh(V_temp, F_temp)
        viewer.data().set_face_based(True)

    else:
        return False

    return True


# Load a surface mesh
igl.readOFF(TUTORIAL_SHARED_PATH + "fertility.off", V, F)

# Tetrahedralize the interior
igl.tetgen.tetrahedralize(V, F, "pq1.414Y", TV, TT, TF)

# Compute barycenters
igl.barycenter(TV, TT, B)

# Plot the generated mesh
key_down(viewer, ord('5'), 0)
viewer.callback_key_down = key_down
viewer.launch()