Exemplo n.º 1
0
bnd_uv = igl.eigen.MatrixXd()
igl.map_vertices_to_circle(V, bnd, bnd_uv)

igl.harmonic(V, F, bnd, bnd_uv, 1, initial_guess)

# Add dynamic regularization to avoid to specify boundary conditions
arap_data = igl.ARAPData()
arap_data.with_dynamics = True
b = igl.eigen.MatrixXi.Zero(0, 0)
bc = igl.eigen.MatrixXd.Zero(0, 0)

# Initialize ARAP
arap_data.max_iter = 100

# 2 means that we're going to *solve* in 2d
igl.arap_precomputation(V, F, 2, b, arap_data)

# Solve arap using the harmonic map as initial guess
V_uv = igl.eigen.MatrixXd(initial_guess)  # important, make a copy of it!

igl.arap_solve(bc, arap_data, V_uv)

# Scale UV to make the texture more clear
V_uv *= 20

# Plot the mesh
viewer = igl.glfw.Viewer()
viewer.data().set_mesh(V, F)
viewer.data().set_uv(V_uv)
viewer.callback_key_down = key_down
Exemplo n.º 2
0
bnd_uv = igl.eigen.MatrixXd()
igl.map_vertices_to_circle(V, bnd, bnd_uv)

igl.harmonic(V, F, bnd, bnd_uv, 1, initial_guess)

# Add dynamic regularization to avoid to specify boundary conditions
arap_data = igl.ARAPData()
arap_data.with_dynamics = True
b = igl.eigen.MatrixXi.Zero(0, 0)
bc = igl.eigen.MatrixXd.Zero(0, 0)

# Initialize ARAP
arap_data.max_iter = 100

# 2 means that we're going to *solve* in 2d
igl.arap_precomputation(V, F, 2, b, arap_data)

# Solve arap using the harmonic map as initial guess
V_uv = igl.eigen.MatrixXd(initial_guess)  # important, make a copy of it!

igl.arap_solve(bc, arap_data, V_uv)

# Scale UV to make the texture more clear
V_uv *= 20

# Plot the mesh
viewer = igl.viewer.Viewer()
viewer.data.set_mesh(V, F)
viewer.data.set_uv(V_uv)
viewer.callback_key_down = key_down
Exemplo n.º 3
0

igl.readOFF(TUTORIAL_SHARED_PATH + "decimated-knight.off", V, F)
U = igl.eigen.MatrixXd(V)
igl.readDMAT(TUTORIAL_SHARED_PATH + "decimated-knight-selection.dmat", S)

# Vertices in selection

b = igl.eigen.MatrixXd([[t[0] for t in [(i, S[i]) for i in range(0, V.rows())] if t[1] >= 0]]).transpose().castint()

# Centroid
mid = 0.5 * (V.colwiseMaxCoeff() + V.colwiseMinCoeff())

# Precomputation
arap_data.max_iter = 100
igl.arap_precomputation(V, F, V.cols(), b, arap_data)

# Set color based on selection
C = igl.eigen.MatrixXd(F.rows(), 3)
purple = igl.eigen.MatrixXd([[80.0 / 255.0, 64.0 / 255.0, 255.0 / 255.0]])
gold = igl.eigen.MatrixXd([[255.0 / 255.0, 228.0 / 255.0, 58.0 / 255.0]])

for f in range(0, F.rows()):
    if S[F[f, 0]] >= 0 and S[F[f, 1]] >= 0 and S[F[f, 2]] >= 0:
        C.setRow(f, purple)
    else:
        C.setRow(f, gold)

# Plot the mesh with pseudocolors
viewer = igl.glfw.Viewer()
viewer.data().set_mesh(U, F)
Exemplo n.º 4
0
igl.readOFF(TUTORIAL_SHARED_PATH + "decimated-knight.off", V, F)
U = igl.eigen.MatrixXd(V)
igl.readDMAT(TUTORIAL_SHARED_PATH + "decimated-knight-selection.dmat", S)

# Vertices in selection

b = igl.eigen.MatrixXd([[
    t[0] for t in [(i, S[i]) for i in range(0, V.rows())] if t[1] >= 0
]]).transpose().castint()

# Centroid
mid = 0.5 * (V.colwiseMaxCoeff() + V.colwiseMinCoeff())

# Precomputation
arap_data.max_iter = 100
igl.arap_precomputation(V, F, V.cols(), b, arap_data)

# Set color based on selection
C = igl.eigen.MatrixXd(F.rows(), 3)
purple = igl.eigen.MatrixXd([[80.0 / 255.0, 64.0 / 255.0, 255.0 / 255.0]])
gold = igl.eigen.MatrixXd([[255.0 / 255.0, 228.0 / 255.0, 58.0 / 255.0]])

for f in range(0, F.rows()):
    if S[F[f, 0]] >= 0 and S[F[f, 1]] >= 0 and S[F[f, 2]] >= 0:
        C.setRow(f, purple)
    else:
        C.setRow(f, gold)

# Plot the mesh with pseudocolors
viewer = igl.glfw.Viewer()
viewer.data().set_mesh(U, F)
Exemplo n.º 5
0
def LaplacianDeform(depth_in, handle_3d, intrinsic=None, vis=False):
    """depth_ctrl is a reference Nx3 depth map
    Args:
        depth_in: the depth predicted by network
        handle_3d: the control sparse points, in [x, y, z]
        intrinsic: the intrinsic matrix
        vis: whether visualize using igl

    Output:
        depth: the warpped depth through asap
    """

    height, width = depth_in.shape[0], depth_in.shape[1]
    depth_in, y, x, handle_3d = ReScale(depth_in,
                                        handle_3d,
                                        intrinsic,
                                        get_image_coor=True)

    point_3d = uts_3d.depth2xyz(depth_in, intrinsic, False)
    select_id = y * width + x
    # test_id = range(10)
    # select_id = select_id[test_id]
    one_hot = np.zeros((point_3d.shape[0]), dtype=np.int32)
    one_hot[select_id] = 1
    mesh_idx = uts_3d.grid_mesh(height, width)

    V = igl.eigen.MatrixXd(np.float64(point_3d))
    U = V
    F = igl.eigen.MatrixXi(np.int32(mesh_idx))
    S = igl.eigen.MatrixXd(np.float64(one_hot))
    b = igl.eigen.MatrixXi(np.int32(select_id))

    P_origin = igl.eigen.MatrixXd(np.float64(point_3d[select_id, :]))
    P = igl.eigen.MatrixXd(np.float64(handle_3d))

    bc = igl.eigen.MatrixXd(np.float64(handle_3d))
    arap_data = igl.ARAPData()

    # Set color based on selection
    # C = igl.eigen.MatrixXd(F.rows(), 3)
    # purple = igl.eigen.MatrixXd([[80.0 / 255.0, 64.0 / 255.0, 255.0 / 255.0]])
    # gold = igl.eigen.MatrixXd([[255.0 / 255.0, 228.0 / 255.0, 58.0 / 255.0]])

    # pdb.set_trace()
    # for f in range(0, F.rows()):
    #     if S[F[f, 0]] > 0 or S[F[f, 1]] > 0 or S[F[f, 2]] > 0:
    #         C.setRow(f, purple)
    #     else:
    #         C.setRow(f, gold)

    # # Plot the mesh with pseudocolors
    # viewer = igl.viewer.Viewer()
    # viewer.data.set_mesh(V, F)
    # viewer.data.set_colors(C)
    # viewer.core.is_animating = False
    # viewer.launch()
    if vis:
        viewer = igl.viewer.Viewer()
        viewer.data.set_mesh(U, F)
        viewer.data.add_points(P, igl.eigen.MatrixXd([[1, 0, 0]]))
        viewer.core.is_animating = False
        viewer.launch()

    # start compute deform
    arap_data.max_iter = 30
    arap_data.ym = 450
    igl.arap_precomputation(V, F, V.cols(), b, arap_data)
    igl.arap_solve(bc, arap_data, U)

    if vis:
        viewer = igl.viewer.Viewer()
        viewer.data.set_mesh(V, F)
        # viewer.data.add_points(P_origin, igl.eigen.MatrixXd([[0, 0, 1]]))
        # viewer.data.add_points(P, igl.eigen.MatrixXd([[0, 1, 0]]))
        viewer.core.is_animating = False
        viewer.launch()

    point_3d_new = np.float32(np.array(U, dtype='float64', order='C'))
    depth = uts_3d.xyz2depth(point_3d_new, intrinsic, depth_in.shape)

    mask = depth <= 0
    max_depth = np.max(depth)
    depth_inpaint = cv2.inpaint(np.uint8(depth / max_depth * 255),
                                np.uint8(mask), 5, cv2.INPAINT_TELEA)
    depth[mask] = np.float32(depth_inpaint[mask]) * max_depth / 255

    return depth