def save_new_edges(filename): opt = BaseOptions() opt.initialize() opt.num_aug = 1 mesh = from_scratch(filename, opt) print(dir(mesh)) edges = np.array(mesh.edges) edge_file = filename.replace('.obj', '.edges') np.savetxt(edge_file, edges, fmt='%d') vs = np.array(mesh.vs) v_file = filename.replace('.obj', '.vs') np.savetxt(v_file, vs, fmt='%f')
def make_soft_eseg(obj_path, eseg_path, seseg_path, nclasses=4): if not os.path.isdir(seseg_path): os.makedirs(seseg_path) files = glob.glob(os.path.join(obj_path, '*.obj')) opt = BaseOptions() opt.initialize() opt.num_aug = 1 for file in files: mesh = from_scratch(file, opt) gemm_edges = np.array(mesh.gemm_edges) obj_id = os.path.splitext(os.path.basename(file))[0] seg_file = os.path.join(eseg_path, obj_id + '.eseg') edge_seg = np.array(read_seg(seg_file).squeeze(), dtype='int32') - 1 s_eseg = -1 * np.ones((mesh.edges_count, nclasses), dtype='float64') for ei in range(mesh.edges_count): prob = np.zeros(nclasses) seg_ids, counts = np.unique(edge_seg[gemm_edges[ei]], return_counts=True) prob[seg_ids] = counts / float(len(gemm_edges[ei])) s_eseg[ei, :] = prob s_eseg_file = os.path.join(seseg_path, obj_id + '.seseg') np.savetxt(s_eseg_file, s_eseg, fmt='%f')