def local_holes_transformation(self, mesh_object, nb_holes, hole_size,write_ply = False, path = "base"): mesh_object = copy.deepcopy(mesh_object) reject_groups = np.random.randint(mesh_object.points.shape[0], size=nb_holes) tree = KDTree(mesh_object.points, leaf_size=2) complete_rejected_indices = [] for reject_index in reject_groups: indices = tree.query_radius(mesh_object.points[reject_index].reshape(1,-1), r=hole_size)[0] complete_rejected_indices.extend(indices.tolist()) complete_rejected_indices.append(reject_index.tolist()) delete_index = list(set(complete_rejected_indices)) new_points = np.delete(mesh_object.points, delete_index, axis = 0) print("After deletion, nb_points remaining : {}".format(new_points.shape)) holes_mesh = base.Meshgrid(new_points) interest_points_holes = holes_mesh.get_interest_points(sel_mod =self.sel_mod,\ sel_args = self.sel_args,neigh_flag = self.neigh_flag, neigh_args = self.neigh_args,\ k_harris = self.k_harris) if write_ply: ply.write_ply(path + "_all", holes_mesh.points, ['x','y','z']) if write_ply: ply.write_ply(path + "_int", interest_points_holes, ['x','y','z']) return interest_points_holes
def __init__(self,path_file, sel_mod = "rel", self_args = {'thresh': 0.01},\ neigh_args = {'k':10}, neigh_flag = "k", k_harris = 0.04, graph_use = True): pos, G = self.move_data(path_file) if graph_use: #The original graph (mesh of the object) should be used self.mesh_objects =base.Meshgrid(pos, G) else: #Create the graph with Delauda print("Don't use the original graph") self.mesh_objects =base.Meshgrid(pos) self.repeatbiliy_thresh = self.mesh_objects.diameter * self_args['thresh'] self.sel_mod = sel_mod self.sel_args = self_args self.neigh_args = neigh_args self.neigh_flag = neigh_flag self.k_harris = k_harris
def __init__(self,path_file, sel_mod = "rel", self_args = {'thresh': 0.01},\ neigh_args = {'k':10}, neigh_flag = "k", k_harris = 0.04): data = ply.read_ply(path_file) pos = np.stack([data['x'],data['y'], data['z']]).T #Positions: Nx3 self.mesh_objects =base.Meshgrid(pos) self.repeatbiliy_thresh = self.mesh_objects.diameter * self_args['thresh'] self.sel_mod = sel_mod self.sel_args = self_args self.neigh_args = neigh_args self.neigh_flag = neigh_flag self.k_harris = k_harris assert not np.all(np.isnan(pos)) and not np.all(np.isinf(pos))
def grid_subsampling_transformation(self, mesh_object, grid_size,write_ply = False, path = "base"): mesh_object = copy.deepcopy(mesh_object) subsampled_points = self.grid_subsampling(mesh_object.points, grid_size) subsampled_mesh = base.Meshgrid(subsampled_points) interest_points_original = subsampled_mesh.get_interest_points(sel_mod =self.sel_mod,\ sel_args = self.sel_args,neigh_flag = self.neigh_flag, neigh_args = self.neigh_args,\ k_harris = self.k_harris) if write_ply: ply.write_ply(path + "_all", subsampled_mesh.points, ['x','y','z']) if write_ply: ply.write_ply(path + "_int", interest_points_original, ['x','y','z']) return interest_points_original
def test_pipeline_move(self, path_file_tmps = [],write_ply = False, keep_diameter=False): #Used to test the non-rigid transformations interest_points, _ = self.mesh_objects.get_interest_points(sel_mod =self.sel_mod,\ sel_args = self.sel_args,neigh_flag = self.neigh_flag, neigh_args = self.neigh_args,\ k_harris = self.k_harris, index = True) basename = path_file_tmps[0].split("/")[-1] basename = os.path.join("visualisation", basename) print(basename) if write_ply: ply.write_ply(basename, interest_points, ['x', 'y', 'z']) move_list = [] for path_file_tmp in path_file_tmps: print("Path file tmp {}".format(path_file_tmp)) pos_tmp, G_tmp = self.move_data(path_file_tmp) if keep_diameter: mesh_object_tmp =base.Meshgrid(pos_tmp, G_tmp, diameter_set = self.mesh_objects.diameter) else: mesh_object_tmp =base.Meshgrid(pos_tmp, G_tmp) assert not np.all(np.isnan(pos_tmp)) and not np.all(np.isinf(pos_tmp)) ip_moved, interest_points_index = mesh_object_tmp.get_interest_points(sel_mod =self.sel_mod,\ sel_args = self.sel_args,neigh_flag = self.neigh_flag, neigh_args = self.neigh_args,\ k_harris = self.k_harris, index = True) basename = path_file_tmp.split("/")[-1] basename = os.path.join("visualisation", basename) if write_ply: ply.write_ply(basename, ip_moved, ['x', 'y', 'z']) interest_points_moved = self.mesh_objects.np_position_array[interest_points_index] rep = self.calc_repeatability_reverse(interest_points, interest_points_moved,self.repeatbiliy_thresh) print("Rep {}".format(rep)) move_list.append(rep) return move_list
def scale_transformation(self, mesh_object, scale_factor,write_ply = False, path = "base"): #angle = [alpha, beta, gamma] #Rotation Transformation #Apply Scaling #Only work on a copy of the original mesh_object = copy.deepcopy(mesh_object) scaled_mesh = base.Meshgrid(scale_factor * mesh_object.points) interest_points_scaled = scaled_mesh.get_interest_points(sel_mod =self.sel_mod,\ sel_args = self.sel_args,neigh_flag = self.neigh_flag, neigh_args = self.neigh_args,\ k_harris = self.k_harris) if write_ply: ply.write_ply(path + "_all", scaled_mesh.points, ['x','y','z']) if write_ply: ply.write_ply(path + "_int", interest_points_scaled, ['x','y','z']) interest_points_original = interest_points_scaled / scale_factor return interest_points_original
def roation_transformation(self, mesh_object, angle,write_ply = False, path = "base"): #angle = [alpha, beta, gamma] #Rotation Transformation #Apply Rotation #Only work on a copy of the original mesh_object = copy.deepcopy(mesh_object) rotations = angle inverse_rotations = [-rotations[2],-rotations[1],-rotations[0]] r = R.from_euler('xyz',rotations, degrees=True) r_inverse = R.from_euler('zyx', inverse_rotations, degrees=True) rotated_mesh = base.Meshgrid(r.apply(mesh_object.points)) interest_points = rotated_mesh.get_interest_points(sel_mod =self.sel_mod,\ sel_args = self.sel_args,neigh_flag = self.neigh_flag, neigh_args = self.neigh_args,\ k_harris = self.k_harris) if write_ply: ply.write_ply(path + "_all", rotated_mesh.points, ['x','y','z']) if write_ply: ply.write_ply(path + "_int", interest_points, ['x','y','z']) interest_points_original = r_inverse.apply(interest_points) return interest_points_original
def gaus_noise_transformation(self, mesh_object, noise_level, absolute_noise_factor,write_ply = False, path = "base"): #noise level: std of the gaussian additive noise #absolute noise factor --> to make the absolute value of the noise in the range of the size #--> factor which is multiplied with the diameter of the object mesh_object = copy.deepcopy(mesh_object) noise_x = np.random.normal(0,noise_level,mesh_object.points.shape[0]) * mesh_object.width * absolute_noise_factor noise_y = np.random.normal(0,noise_level,mesh_object.points.shape[0]) * mesh_object.height * absolute_noise_factor noise_z = np.random.normal(0,noise_level,mesh_object.points.shape[0]) * mesh_object.depth * absolute_noise_factor noise = np.stack([noise_x,noise_y,noise_z]).T noised_points = mesh_object.points + noise if write_ply: ply.write_ply(path + "_all", noised_points, ['x','y','z']) noise_mesh = base.Meshgrid(noised_points) interest_points_original = noise_mesh.get_interest_points(sel_mod =self.sel_mod,\ sel_args = self.sel_args,neigh_flag = self.neigh_flag, neigh_args = self.neigh_args,\ k_harris = self.k_harris) if write_ply: ply.write_ply(path + "_ip", interest_points_original, ['x','y','z']) return interest_points_original