def pre_draw(viewer): global anim_t bc = igl.eigen.MatrixXd(b.size(), V.cols()) for i in range(0, b.size()): bc.setRow(i, V.row(b[i])) if S[b[i]] == 0: r = mid[0] * 0.25 bc[i, 0] += r * sin(0.5 * anim_t * 2. * pi) bc[i, 1] = bc[i, 1] - r + r * cos(pi + 0.5 * anim_t * 2. * pi) elif S[b[i]] == 1: r = mid[1] * 0.15 bc[i, 1] = bc[i, 1] + r + r * cos(pi + 0.15 * anim_t * 2. * pi) bc[i, 2] -= r * sin(0.15 * anim_t * 2. * pi) elif S[b[i]] == 2: r = mid[1] * 0.15 bc[i, 2] = bc[i, 2] + r + r * cos(pi + 0.35 * anim_t * 2. * pi) bc[i, 0] += r * sin(0.35 * anim_t * 2. * pi) igl.arap_solve(bc, arap_data, U) viewer.data().set_vertices(U) viewer.data().compute_normals() if viewer.core.is_animating: anim_t += anim_t_dir return False
# 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 # Disable wireframe viewer.data().show_lines = False # Draw checkerboard texture viewer.data().show_texture = True
# 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 # Disable wireframe viewer.core.show_lines = False # Draw checkerboard texture viewer.core.show_texture = True
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