def compute_v2(v, gt_mesh): new_v = igl.eigen.MatrixXd(np.array(v, dtype=np.double)) S = igl.eigen.MatrixXd() I = igl.eigen.MatrixXi() C = igl.eigen.MatrixXd() N = igl.eigen.MatrixXd() igl.signed_distance(new_v, gt_mesh.v, gt_mesh.f, igl.SignedDistanceType.SIGNED_DISTANCE_TYPE_UNSIGNED, S, I, C, N) distance = np.array(S) return np.average(distance)
def query(self, queries): """Returns numpy array of SDF values for each point in queries""" queryV = iglhelpers.p2e(queries) S = igl.eigen.MatrixXd() B = igl.eigen.MatrixXd() I = igl.eigen.MatrixXi() C = igl.eigen.MatrixXd() N = igl.eigen.MatrixXd() if self._precomputed and self._signType == igl.SIGNED_DISTANCE_TYPE_FAST_WINDING_NUMBER: # generate samples from precomputed bvh's print("[INFO] Generating SDFs") igl.signed_distance_fast_winding_number(queryV, self._V, self._F, self._tree, self._fwn_bvh, S) print("[INFO] SDFs done") else: igl.signed_distance(queryV, self._V, self._F, self._signType, S, I, C, N) return iglhelpers.e2p(S)
z = lerp(res, Vmin, Vmax, zi, 2) for yi in range(res[1]): y = lerp(res, Vmin, Vmax, yi, 1) for xi in range(res[0]): x = lerp(res, Vmin, Vmax, xi, 0) GV.setRow(xi + res[0] * (yi + res[1] * zi), igl.eigen.MatrixXd([[x, y, z]])) # compute values print("Computing distances...") S = igl.eigen.MatrixXd() B = igl.eigen.MatrixXd() I = igl.eigen.MatrixXi() C = igl.eigen.MatrixXd() N = igl.eigen.MatrixXd() igl.signed_distance(GV, V, F, igl.SIGNED_DISTANCE_TYPE_PSEUDONORMAL, S, I, C, N) # Convert distances to binary inside-outside data --> aliasing artifacts B = S.copy() for e in range(B.rows()): if B[e] > 0: B[e] = 1 else: if B[e] < 0: B[e] = -1 else: B[e] = 0 print("Marching cubes...") SV = igl.eigen.MatrixXd() BV = igl.eigen.MatrixXd() SF = igl.eigen.MatrixXi()
for yi in range(res[1]): y = lerp(res, Vmin, Vmax, yi, 1) for xi in range(res[0]): x = lerp(res, Vmin, Vmax, xi, 0) GV.setRow(xi + res[0] * (yi + res[1] * zi), igl.eigen.MatrixXd([[x, y, z]])) # compute values print("Computing distances...") S = igl.eigen.MatrixXd() B = igl.eigen.MatrixXd() I = igl.eigen.MatrixXi() C = igl.eigen.MatrixXd() N = igl.eigen.MatrixXd() igl.signed_distance(GV, V, F, igl.SIGNED_DISTANCE_TYPE_PSEUDONORMAL, S, I, C, N) # Convert distances to binary inside-outside data --> aliasing artifacts B = S.copy() for e in range(B.rows()): if B[e] > 0: B[e] = 1 else: if B[e] < 0: B[e] = -1 else: B[e] = 0 print("Marching cubes...") SV = igl.eigen.MatrixXd() BV = igl.eigen.MatrixXd() SF = igl.eigen.MatrixXi()
for i, index in enumerate(np.random.permutation(opt.lighting.shape[0])): tic = time.time() optimizer.zero_grad() loss = rendering.loss_func_parallel(index, gt_transient, mesh, mesh_optimization, opt, render_opt, device) loss.backward() optimizer.step() mesh.v = igl.eigen.MatrixXd(mesh_optimization.v.cpu().data.numpy()) S = igl.eigen.MatrixXd() I = igl.eigen.MatrixXi() C = igl.eigen.MatrixXd() N = igl.eigen.MatrixXd() igl.signed_distance(mesh.v, space_carving_mesh.v, space_carving_mesh.f, igl.SignedDistanceType(0), S, I, C, N) for x in list(compress(range(mesh.v.rows()), S > 0)): mesh.v.setRow(x, C.row(x)) igl.per_face_normals(mesh.v, mesh.f, mesh.fn) l2, transient = rendering.evaluate_L2(gt_transient, mesh, render_opt) print('%05d update time: %5.5f L2 loss: %5.5f ' % (t * opt.lighting.shape[0] + i, time.time() - tic, l2)) l2_record[t * opt.lighting.shape[0] + i] = l2 filename = folder_name + '%05d.mat' % (t * opt.lighting.shape[0] + i) scipy.io.savemat(filename, mdict={ 'v': np.array(mesh.v), 'transient': transient, 'l2': l2,