def __getitem__(self, index): # LOAD a training sample points = self.datas[index].squeeze() # Clone it to keep the cached data safe points = points.clone() rot_matrix = 0 # apply random rotation of Z axis if self.data_augmentation_Z_rotation: # Uniform random Rotation of axis Y points, rot_matrix = pointcloud_processor.uniform_rotation_axis(points, axis=1, normals=self.normal, range_rot=self.data_augmentation_Z_rotation_range) points, _, _ = pointcloud_processor.center_bounding_box(points) # apply random 3D rotation if self.data_augmentation_3D_rotation: # Uniform random 3D rotation of the sphere. points, rot_matrix = pointcloud_processor.uniform_rotation_sphere(points, normals=self.normal) points, _, _ = pointcloud_processor.center_bounding_box(points) # Add small random translation if self.train: points = pointcloud_processor.add_random_translation(points, scale=0.03) # Resample according to triangles area random_sample = 0 if self.regular_sampling: random_sample = np.random.choice(6890, size=self.npoints, p=self.prop) points = points[random_sample] return points, random_sample, rot_matrix, index
def load_template(self): if not os.path.exists("./data/template/template.ply"): os.system("chmod +x ./data/download_template.sh") os.system("./data/download_template.sh") mesh = trimesh.load("./data/template/template.ply", process=False) self.mesh = mesh point_set = mesh.vertices point_set, _, _ = pointcloud_processor.center_bounding_box(point_set) mesh_HR = trimesh.load("./data/template/template_dense.ply", process=False) self.mesh_HR = mesh_HR point_set_HR = mesh_HR.vertices point_set_HR, _, _ = pointcloud_processor.center_bounding_box(point_set_HR) self.vertex = torch.from_numpy(point_set).cuda().float() self.vertex_HR = torch.from_numpy(point_set_HR).cuda().float() self.num_vertex = self.vertex.size(0) self.num_vertex_HR = self.vertex_HR.size(0) self.prop = pointcloud_processor.get_vertex_normalised_area(mesh) assert (np.abs(np.sum(self.prop) - 1) < 0.001), "Propabilities do not sum to 1!)" self.prop = torch.from_numpy(self.prop).cuda().unsqueeze(0).float() red = self.red_LR green = self.green_LR blue = self.blue_LR mesh_ref = self.mesh_ref_LR self.save(mesh,mesh_ref,path=self.save_path,red=red,green=green,blue=blue)
def load_template(self): if not os.path.exists("./data/template/template.ply"): os.system("chmod +x ./data/download_template.sh") os.system("./data/download_template.sh") mesh = trimesh.load("./data/template/template.ply", process=False) self.mesh = mesh point_set = mesh.vertices point_set, _, _ = pointcloud_processor.center_bounding_box(point_set) mesh_HR = trimesh.load("./data/template/template_dense.ply", process=False) self.mesh_HR = mesh_HR point_set_HR = mesh_HR.vertices point_set_HR, _, _ = pointcloud_processor.center_bounding_box( point_set_HR) self.vertex = torch.from_numpy(point_set).cuda().float() self.vertex_HR = torch.from_numpy(point_set_HR).cuda().float() self.num_vertex = self.vertex.size(0) self.num_vertex_HR = self.vertex_HR.size(0) self.prop = pointcloud_processor.get_vertex_normalised_area(mesh) assert (np.abs(np.sum(self.prop) - 1) < 0.001), "Propabilities do not sum to 1!)" self.prop = torch.from_numpy(self.prop).cuda().unsqueeze(0).float() self.Rig_list = [] head = np.load("./data/output/head_indices.npy") self.Rig_list.append(head) left_arm_down = np.load("./data/output/left_arm_down_indices.npy") self.Rig_list.append(left_arm_down) left_arm = np.load("./data/output/left_arm_indices.npy") self.Rig_list.append(left_arm) left_foot = np.load("./data/output/left_foot_indices.npy") self.Rig_list.append(left_foot) left_hand = np.load("./data/output/left_hand_indices.npy") self.Rig_list.append(left_hand) left_leg_down = np.load("./data/output/left_leg_down_indices.npy") self.Rig_list.append(left_leg_down) left_leg = np.load("./data/output/left_leg_indices.npy") self.Rig_list.append(left_leg) right_arm_down = np.load("./data/output/right_arm_down_indices.npy") self.Rig_list.append(right_arm_down) right_arm = np.load("./data/output/right_arm_indices.npy") self.Rig_list.append(right_arm) right_foot = np.load("./data/output/right_foot_indices.npy") self.Rig_list.append(right_foot) right_hand = np.load("./data/output/right_hand_indices.npy") self.Rig_list.append(right_hand) right_leg_down = np.load("./data/output/right_leg_down_indices.npy") self.Rig_list.append(right_leg_down) right_leg = np.load("./data/output/right_leg_indices.npy") self.Rig_list.append(right_leg) torso = np.load("./data/output/torso_indices.npy") self.Rig_list.append(torso) self.Rig_HD_list = [] '''
def load_template(): if not os.path.exists("./data/template/template.ply"): os.system("chmod +x ./data/download_template.sh") os.system("./data/download_template.sh") mesh = trimesh.load("./data/template/template.ply", process=False) point_set = mesh.vertices point_set, _, _ = pointcloud_processor.center_bounding_box(point_set) #print("vertex size is ", point_set.size()) mesh_HR = trimesh.load("./data/template/template_dense.ply", process=False) point_set_HR = mesh_HR.vertices point_set_HR, _, _ = pointcloud_processor.center_bounding_box(point_set_HR) vertex = torch.from_numpy(point_set).float() return vertex
def init_template(self): if not os.path.exists("./data/template/template.ply"): os.system("chmod +x ./data/download_template.sh") os.system("./data/download_template.sh") mesh = trimesh.load("./data/template/template.ply", process=False) self.mesh = mesh point_set = mesh.vertices point_set, _, _ = pointcloud_processor.center_bounding_box(point_set) mesh_HR = trimesh.load("./data/template/template_dense.ply", process=False) self.mesh_HR = mesh_HR point_set_HR = mesh_HR.vertices point_set_HR, _, _ = pointcloud_processor.center_bounding_box(point_set_HR) self.vertex = torch.from_numpy(point_set).cuda().float() self.vertex_HR = torch.from_numpy(point_set_HR).cuda().float() self.num_vertex = self.vertex.size(0) self.num_vertex_HR = self.vertex_HR.size(0) self.prop = pointcloud_processor.get_vertex_normalised_area(mesh) assert (np.abs(np.sum(self.prop) - 1) < 0.001), "Propabilities do not sum to 1!)" self.prop = torch.from_numpy(self.prop).cuda().unsqueeze(0).float() print(f"Using template to initialize template")
def init_template(self, dataset_train, device): self.mesh = trimesh.load(dataset_train, process=False) point_set = self.mesh.vertices point_set, _, _ = pointcloud_processor.center_bounding_box(point_set) self.mesh_HR = trimesh.load(dataset_train, process=False) point_set_HR = self.mesh_HR.vertices point_set_HR, _, _ = pointcloud_processor.center_bounding_box( point_set_HR) vertex = torch.from_numpy(point_set).float() self.vertex = vertex.to(device) vertex_HR = torch.from_numpy(point_set_HR).float() self.vertex_HR = vertex_HR.to(device) self.num_vertex = self.vertex.size(0) self.num_vertex_HR = self.vertex_HR.size(0) self.prop = pointcloud_processor.get_vertex_normalised_area(self.mesh) assert (np.abs(np.sum(self.prop) - 1) < 0.001), "Propabilities do not sum to 1!)" self.prop = torch.from_numpy(self.prop).unsqueeze(0).float() self.prop = self.prop.to(device) print(f"Using template to initialize template")
def init_sphere(self, device, radius=1, num_of_points=6890): z = np.random.random(num_of_points) * 2 * radius - radius phi = np.random.random(num_of_points) * 2 * np.pi x = np.sqrt(radius - z**2) * np.cos(phi) y = np.sqrt(radius - z**2) * np.sin(phi) points = np.stack([x, y, z]).transpose() mesh = trimesh.Trimesh(points, faces=np.array([0, 1, 2]), process=False) self.mesh = mesh point_set = mesh.vertices point_set, _, _ = pointcloud_processor.center_bounding_box(point_set) vertex = torch.from_numpy(point_set).float() self.vertex = vertex.to(device) self.num_vertex = self.vertex.size(0) print('using sphere as template')