fl_bench_file = parse_feat(file_yml) fl_bench = igl.read_dmat(fl_bench_file) v_bench, f_bench = igl.read_triangle_mesh(file_bench) v_ini, f_ini = igl.read_triangle_mesh("bench.mesh__sf.obj") prob_mat_ini, fl_ini_temp = pbc.project_face_labels(v_bench, f_bench.astype('int32'), fl_bench.astype('int32'), v_ini, f_ini.astype('int32')) fl_ini = pbc.refine_labels(v_ini, f_ini.astype('int32'), prob_mat_ini, fl_ini_temp.astype('int32'), 1) # mp.plot(v_ini, f_ini, fl_ini_temp[:,0]) # mp.plot(v_ini, f_ini, fl_ini[:,0]) eps = 0.1 # v_dict, f_dict =separate_surfaces(v_bench, f_bench, fl_bench) v_dict, f_dict = separate_surfaces(v_ini, f_ini, fl_ini[:, 0]) v_bad, f_bad, fl_bad = perturb_and_union(v_dict, f_dict, eps) # mp.plot(v_bad, f_bad, fl_bad[:,0], shading={"wireframe":True}) eps_file_name = file_root + "/" + str(eps) + "pertb.obj" igl.write_obj(eps_file_name, v_bad, f_bad) v_good, f_good = igl.read_triangle_mesh(file_root + "/" + "out.mesh__sf.obj") print("py0") print("called") prob_mat, fl_good_proj = pbc.project_face_labels(v_bad, f_bad.astype('int32'), fl_bad[:, 0].astype('int32'), v_good, f_good.astype('int32')) print("first") # prob_mat, fl_good_proj = pbc.project_face_labels(v_bad, f_bad.astype('int32'), fl_bad[:,0].astype('int32'), v_good, f_good.astype('int32')) print("second") # igl.write_dmat(file_root+"/"+"feat_cut.dmat",fl_good_proj)
import igl import solver import constraint import transform import open3d as o3d import mesh as m cons = constraint.Constraint() cons.add_constraint(0, [0, 0, 0]) # slvr = solver.Sovler() if __name__ == "__main__": V, F = igl.read_triangle_mesh("cube.obj") mesh = m.Mesh(V, F) slvr = solver.Sovler(mesh, cons) slvr.precompute() V, F = slvr.solve() igl.write_obj("cube_remake", V, F)
filename = opt.mesh # load mesh V, _, _, F, _, _ = igl.read_obj(filename) # init optim context ctx = Context() # normalize mesh V = normalize(V) U = np.array(V) # set a constrained point ctx.set_constrain(V, F) ctx.set_parameters(V, F) ctx.set_lambda(opt.plambda) # optim loop maxIter = 1000 stopRelativeDeltaV = 1e-3 start = timeit.default_timer() for iter in range(0, maxIter): ctx.optim_step(V, U) print("Iter at", iter, "Energy", ctx.energy, "RelativeDeltaV", ctx.relativeDeltaV) if ctx.relativeDeltaV < stopRelativeDeltaV: break stop = timeit.default_timer() print('Time: ', stop - start) output_name = os.path.splitext(filename) tmp = "_cubic_{:.4}".format(opt.plambda) output_filename = tmp.join(output_name) normalized_filename = "_norm".join(output_name) igl.write_obj(normalized_filename, V, F) igl.write_obj(output_filename, U, F)
def rotate_ribbon(omega, skipped_frames, dt): with open(input_json) as f: input_data = json.load(f) handles = [0, 3] # handle vertices rest_mesh_path = file_prefix + input_data['rest_mesh'] rest_pos, _, _, faces, _, _ = igl.read_obj(rest_mesh_path) cur_vel = np.zeros(rest_pos.shape) np.savetxt(file_prefix + input_data['current_velocity'], cur_vel) # save rest mesh cur_pos = rest_pos mesh_path = output_folder + '/mesh/mesh_0.obj' igl.write_obj(mesh_path, rest_pos, faces) #save init vel vel_path = output_folder + '/velocity/vel_0.txt' np.savetxt(vel_path, cur_vel) kp = 0.1 kd = 2 * math.sqrt(kp) fmin = -0.01 fmax = 0.01 for i in range(250): cur_time = i * dt * skipped_frames print('iter: ', i) theta = omega * cur_time ref_theta = omega * (i * dt * skipped_frames + dt) # generate force file clampedDOFs = np.zeros((len(handles), 4)) for j in range(len(handles)): vid = handles[j] r = np.linalg.norm(rest_pos[vid]) clampedDOFs[j][0] = vid clampedDOFs[j][2] = r * math.sin(ref_theta) clampedDOFs[j][3] = r * math.cos(ref_theta) print('clamped dofs on vertex:', vid, clampedDOFs[j]) save_clamped_dofs(file_prefix + input_data['clamped_DOFs'], clampedDOFs) cur_data = input_data cur_data['cur_mesh'] = '/ribbon_dynamic/mesh/mesh_' + str(i) + '.obj' cur_data['curedge_DOFs'] = '/ribbon_dynamic/mesh/edgedofs_' + str(i) + 'txt' cur_data['current_velocity'] = '/ribbon_dynamic/velocity/vel_' + str(i) + '.txt' cur_data['clamped_DOFs'] = '/ribbon_dynamic/mesh/clampedDOFs_' + str(i) + '.txt' #save clamped dofs save_clamped_dofs(file_prefix + cur_data['clamped_DOFs'], clampedDOFs) with open(cur_json, 'w') as json_file: json.dump(cur_data, json_file, indent = 4, sort_keys=True) args = [exe_path, '--input', cur_json, '--output', file_prefix, '--numSteps', str(4), '--timeStep', str(0.005)] subprocess.check_call(args) # save files cur_pos, _, _, faces, _, _ = igl.read_obj(file_prefix + 'mesh_simulated.obj') mesh_path = output_folder + '/mesh/mesh_' + str(i+1) + '.obj' igl.write_obj(mesh_path, cur_pos, faces) #save vel cur_vel = np.loadtxt(file_prefix + 'vel_simulated.txt') vel_path = output_folder + '/velocity/vel_' + str(i+1) + '.txt' np.savetxt(vel_path, cur_vel) #save edge dofs cur_edgedofs = np.loadtxt(file_prefix + 'edgedofs_simulated.txt') edge_path = output_folder + '/mesh/edgedofs_' + str(i+1) + 'txt' np.savetxt(edge_path, cur_edgedofs)
def test_write_obj(self): suc = igl.write_obj("test.obj", self.v, self.f) self.assertTrue(suc) self.assertTrue(os.path.isfile("test.obj"))
def main(): try: V, F, _, _ = mio.read_obj('nonexistent_file.obj') except FileNotFoundError: print('Successfully failed when nonexistent file is given') print('v only') V, F, VT, FT, VN, FN = mio.read_obj('resource/v.obj') print(V.shape) print(V) print(F.shape) print(F) print(VT.shape) print(VT) print(FT.shape) print(FT) print(VN.shape) print(VN) print(FN.shape) print(FN) print('v+vt') V, F, VT, FT, VN, FN = mio.read_obj('resource/v_vt.obj') print(V.shape) print(V) print(F.shape) print(F) print(VT.shape) print(VT) print(FT.shape) print(FT) print(VN.shape) print(VN) print(FN.shape) print(FN) print('v+vn') V, F, VT, FT, VN, FN = mio.read_obj('resource/v_vn.obj') print(V.shape) print(V) print(F.shape) print(F) print(VT.shape) print(VT) print(FT.shape) print(FT) print(VN.shape) print(VN) print(FN.shape) print(FN) print('v+vt+vn') V, F, VT, FT, VN, FN = mio.read_obj('resource/v_vt_vn.obj') print(V.shape) print(V) print(F.shape) print(F) print(VT.shape) print(VT) print(FT.shape) print(FT) print(VN.shape) print(VN) print(FN.shape) print(FN) print('wow_tex.obj with texture') mio.write_obj('wow_tex.obj', V, F, VT, FT, VN, FN, 'wow_tex.jpg') if IGL_FOUND: # On Ryzen 7 3950x # cython: 9.520554542541504 ms # igl(C++): 21.706414222717285 ms print('benchmark-read') start = time.time() for i in range(10): mio.read_obj('resource/v_vt_vn.obj') end = time.time() print('cython: {} ms'.format((end - start) * 100)) start = time.time() for i in range(10): igl.read_obj('resource/v_vt_vn.obj') end = time.time() print('igl: {} ms'.format((end - start) * 100)) # On Ryzen 7 3950x # cython: 8.391046524047852 ms # igl(C++): 10.899710655212402 ms print('benchmark-write') start = time.time() for i in range(10): mio.write_obj('resource/buffer.obj', V, F) end = time.time() print('cython: {} ms'.format((end - start) * 100)) start = time.time() for i in range(10): igl.write_obj('resource/buffer.obj', V, F) end = time.time() print('igl: {} ms'.format((end - start) * 100))
def save(self, fp): igl.write_obj(fp, self.V, self.F)