Beispiel #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)
Beispiel #2
0
def update_visualization(viewer):
    global V, F, T, tree, FN, VN, EN, E, EMAP, max_distance, slice_z, overlay
    plane = igl.eigen.MatrixXd([
        0.0, 0.0, 1.0,
        -((1 - slice_z) * V.col(2).minCoeff() + slice_z * V.col(2).maxCoeff())
    ])
    V_vis = igl.eigen.MatrixXd()
    F_vis = igl.eigen.MatrixXi()

    # Extract triangle mesh slice through volume mesh and subdivide nasty triangles
    J = igl.eigen.MatrixXi()
    bary = igl.eigen.SparseMatrixd()
    igl.marching_tets(V, T, plane, V_vis, F_vis, J, bary)
    max_l = 0.03
    while True:
        l = igl.eigen.MatrixXd()
        igl.edge_lengths(V_vis, F_vis, l)
        l /= (V_vis.colwiseMaxCoeff() - V_vis.colwiseMinCoeff()).norm()

        if l.maxCoeff() < max_l:
            break

        bad = l.rowwiseMaxCoeff() > max_l
        notbad = l.rowwiseMaxCoeff() <= max_l  # TODO replace by ~ operator
        F_vis_bad = igl.eigen.MatrixXi()
        F_vis_good = igl.eigen.MatrixXi()
        igl.slice_mask(F_vis, bad, 1, F_vis_bad)
        igl.slice_mask(F_vis, notbad, 1, F_vis_good)
        igl.upsample(V_vis, F_vis_bad)
        F_vis = igl.cat(1, F_vis_bad, F_vis_good)

    # Compute signed distance
    S_vis = igl.eigen.MatrixXd()
    I = igl.eigen.MatrixXi()
    N = igl.eigen.MatrixXd()
    C = igl.eigen.MatrixXd()

    # Bunny is a watertight mesh so use pseudonormal for signing
    igl.signed_distance_pseudonormal(V_vis, V, F, tree, FN, VN, EN, EMAP,
                                     S_vis, I, C, N)

    # push to [0,1] range
    S_vis = 0.5 * (S_vis / max_distance) + 0.5
    C_vis = igl.eigen.MatrixXd()
    # color without normalizing
    igl.parula(S_vis, False, C_vis)

    if overlay:
        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.core.lighting_factor = overlay
Beispiel #3
0
def update_visualization(viewer):
    global V, F, T, tree, FN, VN, EN, E, EMAP, max_distance, slice_z, overlay
    plane = igl.eigen.MatrixXd([0.0, 0.0, 1.0, -((1 - slice_z) * V.col(2).minCoeff() + slice_z * V.col(2).maxCoeff())])
    V_vis = igl.eigen.MatrixXd()
    F_vis = igl.eigen.MatrixXi()

    # Extract triangle mesh slice through volume mesh and subdivide nasty triangles
    J = igl.eigen.MatrixXi()
    bary = igl.eigen.SparseMatrixd()
    igl.slice_tets(V, T, plane, V_vis, F_vis, J, bary)
    max_l = 0.03
    while True:
        l = igl.eigen.MatrixXd()
        igl.edge_lengths(V_vis, F_vis, l)
        l /= (V_vis.colwiseMaxCoeff() - V_vis.colwiseMinCoeff()).norm()

        if l.maxCoeff() < max_l:
            break

        bad = l.rowwiseMaxCoeff() > max_l
        notbad = l.rowwiseMaxCoeff() <= max_l  # TODO replace by ~ operator
        F_vis_bad = igl.eigen.MatrixXi()
        F_vis_good = igl.eigen.MatrixXi()
        igl.slice_mask(F_vis, bad, 1, F_vis_bad)
        igl.slice_mask(F_vis, notbad, 1, F_vis_good)
        igl.upsample(V_vis, F_vis_bad)
        F_vis = igl.cat(1, F_vis_bad, F_vis_good)

    # Compute signed distance
    S_vis = igl.eigen.MatrixXd()
    I = igl.eigen.MatrixXi()
    N = igl.eigen.MatrixXd()
    C = igl.eigen.MatrixXd()

    # Bunny is a watertight mesh so use pseudonormal for signing
    igl.signed_distance_pseudonormal(V_vis, V, F, tree, FN, VN, EN, EMAP, S_vis, I, C, N)

    # push to [0,1] range
    S_vis = 0.5 * (S_vis / max_distance) + 0.5
    C_vis = igl.eigen.MatrixXd()
    # color without normalizing
    igl.parula(S_vis, False, C_vis)

    if overlay:
        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.core.lighting_factor = overlay
def key_down(viewer, key, mod):
    global U, c

    if key == ord(' '):
        U = U.rightCols(k)

        # Rescale eigen vectors for visualization
        Z = bbd * 0.5 * U.col(c)
        C = igl.eigen.MatrixXd()
        igl.parula(U.col(c), False, C)
        c = (c + 1) % U.cols()

        if twod:
            V.setcol(2, Z)

        viewer.data.set_mesh(V, F)
        viewer.data.compute_normals()
        viewer.data.set_colors(C)
        return True
def key_down(viewer, key, mod):
    global U, c

    if key == ord(' '):
        U = U.rightCols(k)

        # Rescale eigen vectors for visualization
        Z = bbd * 0.5 * U.col(c)
        C = igl.eigen.MatrixXd()
        igl.parula(U.col(c), False, C)
        c = (c + 1) % U.cols()

        if twod:
            V.setcol(2, Z)

        viewer.data.set_mesh(V, F)
        viewer.data.compute_normals()
        viewer.data.set_colors(C)
        return True
Beispiel #6
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)
def pre_draw(viewer):
    if not viewer.core.is_animating:
        return False

    global anim_t
    global start_point
    global end_point

    igl.streamlines_next(V, F, data, state)

    value = (anim_t % 100) / 100.0

    if value > 0.5:
        value = 1 - value
    value /= 0.5
    r, g, b = igl.parula(value)
    viewer.data.add_edges(state.start_point, state.end_point, igl.eigen.MatrixXd([[r, g, b]]))

    anim_t += anim_t_dir

    return False
def pre_draw(viewer):
    if not viewer.core().is_animating:
        return False

    global anim_t
    global start_point
    global end_point

    igl.streamlines_next(V, F, data, state)

    value = (anim_t % 100) / 100.0

    if value > 0.5:
        value = 1 - value
    value /= 0.5
    r, g, b = igl.parula(value)
    viewer.data().add_edges(state.start_point, state.end_point, igl.eigen.MatrixXd([[r, g, b]]))

    anim_t += anim_t_dir

    return False
Beispiel #9
0
PD2 = igl.eigen.MatrixXd()

PV1 = igl.eigen.MatrixXd()
PV2 = igl.eigen.MatrixXd()

igl.principal_curvature(V, F, PD1, PD2, PV1, PV2)

# Mean curvature
H = 0.5 * (PV1 + PV2)

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

# Compute pseudocolor
C = igl.eigen.MatrixXd()
igl.parula(H, True, C)

viewer.data().set_colors(C)

# Average edge length for sizing
avg = igl.avg_edge_length(V, F)

# Draw a blue segment parallel to the minimal curvature direction
red = igl.eigen.MatrixXd([[0.8, 0.2, 0.2]])
blue = igl.eigen.MatrixXd([[0.2, 0.2, 0.8]])

viewer.data().add_edges(V + PD1 * avg, V - PD1 * avg, blue)

# Draw a red segment parallel to the maximal curvature direction
viewer.data().add_edges(V + PD2 * avg, V - PD2 * avg, red)
PD2 = igl.eigen.MatrixXd()

PV1 = igl.eigen.MatrixXd()
PV2 = igl.eigen.MatrixXd()

igl.principal_curvature(V, F, PD1, PD2, PV1, PV2)

# Mean curvature
H = 0.5 * (PV1 + PV2)

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

# Compute pseudocolor
C = igl.eigen.MatrixXd()
igl.parula(H, True, C)

viewer.data().set_colors(C)

# Average edge length for sizing
avg = igl.avg_edge_length(V, F)

# Draw a blue segment parallel to the minimal curvature direction
red = igl.eigen.MatrixXd([[0.8, 0.2, 0.2]])
blue = igl.eigen.MatrixXd([[0.2, 0.2, 0.8]])

viewer.data().add_edges(V + PD1 * avg, V - PD1 * avg, blue)

# Draw a red segment parallel to the maximal curvature direction
viewer.data().add_edges(V + PD2 * avg, V - PD2 * avg, red)