def _mesh_transformation(self, edge_length_threshold=0.02): ffd_dataset = get_template_ffd(self.preprocessed_data_path, self.cat_id, edge_length_threshold) template_ids, bs, ps = zip(*self.get_ffd_data(ffd_dataset)) mesh_dataset = get_thresholded_template_mesh( self.preprocessed_data_path, self.cat_id, edge_length_threshold) with mesh_dataset: all_faces = [] all_vertices = [] for k in template_ids: sg = mesh_dataset[k] all_faces.append(np.array(sg['faces'])) all_vertices.append(np.array(sg['vertices'])) def transform_predictions(probs, dp): i = np.argmax(probs) vertices = np.matmul(bs[i], ps[i] + dp[i]) faces = all_faces[i] original_vertices = all_vertices[i] return dict(vertices=vertices, faces=faces, original_vertices=original_vertices, attrs=dict(template_id=template_ids[i])) return transform_predictions
def get_source_dataset(self): base = get_thresholded_template_mesh(self._base_path, self._cat_id, self._edge_length_threshold) def map_fn(base): vertices, faces = (np.array(base[k]) for k in ('vertices', 'faces')) b, p = calculate_ffd(vertices, faces, self._n, self._n_samples) return dict(b=b, p=p) return base.map(map_fn)
from deformations.meshDeformation import get_thresholded_template_mesh from mayavi import mlab import numpy as np from graphicUtils.visualizer.mayaviVisualizer import visualize_mesh, visualize_point_cloud ds = get_template_ffd("/media/saurabh/e56e40fb-030d-4f7f-9e63-42ed5f7f6c711/preprocessing_new", desc_to_id("pistol"), edge_length_threshold=None, n_samples=16384) key = "1f646ff59cabdddcd810dcd63f342aca" with ds: b = np.array(ds[key]['b']) p = np.array(ds[key]['p']) mesh_dataset = get_thresholded_template_mesh("/media/saurabh/e56e40fb-030d-4f7f-9e63-42ed5f7f6c711/preprocessing_new", desc_to_id("pistol"), None) with mesh_dataset: f = np.array(mesh_dataset[key]['faces']) v_orignal = np.array(mesh_dataset[key]['vertices']) # print(b) # visualize_mesh(v_orignal, f) # mlab.show() visualize_mesh(np.matmul(b, p), f) mlab.show() visualize_point_cloud(np.matmul(b, p)) mlab.show()