def test_remove_mesh_boundary_faces(self): mesh_a = self.cutSphere_A.copy() mesh_a_save = mesh_a.copy() boundary = stop.mesh_boundary(mesh_a) mesh_processed = stop.remove_mesh_boundary_faces(mesh_a, face_vertex_number=1) # Non modification assert (mesh_a.vertices == mesh_a_save.vertices).all() # Correctness # check that when removing all faces with any vertex on the boundary, # all the boundary vertices are removed from the mesh print(len(boundary[0])) print(len(mesh_a.vertices)) print(len(mesh_processed.vertices)) assert (len(mesh_processed.vertices) == len(mesh_a.vertices) - len(boundary[0]))
def generate_paraboloid_regular(A, nstep=50, ax=1, ay=1, random_sampling=False, random_distribution_type='gaussian', ratio=0.1): """ generate a regular paraboloid mesh Z=K*Y^2 ratio and random_distribution_type parameters are unused if random_sampling is set to False :param A: amplitude of the paraboloid :param nstep: nstepx or the sampling step stepx as a float ! :param ax: half length of the domain :param ay: half width of the domain :param random_sampling: :param random_distribution_type: :param ratio: :return: """ # Parameters xmin, xmax = [-ax, ax] ymax = ay # ymin, ymax = [-ay, ay] # Define the sampling if isinstance(nstep, int): stepx = (xmax - xmin) / nstep else: stepx = nstep # Coordinates x = np.arange(xmin, xmax, stepx) # To generate y y, curve_samples = adaptive_sampling(ymax, A, stepx) X, Y = np.meshgrid(x, y) X[::2] += stepx / 2 X = X.flatten() Y = Y.flatten() # Random perturbation if random_sampling: sigma = stepx * ratio # characteristic size of the mesh * ratio nb_vert = len(x) * len(y) if random_distribution_type == 'gamma': theta = np.random.rand(nb_vert, ) * np.pi * 2 mean = sigma variance = sigma ** 2 radius = \ np.random.gamma(mean ** 2 / variance, variance / mean, nb_vert) X = X + radius * np.cos(theta) Y = Y + radius * np.sin(theta) elif random_distribution_type == 'uniform': X = X + np.random.uniform(-1, 1, 100) Y = Y + np.random.uniform(-1, 1, 100) else: X = X + sigma * np.random.randn(nb_vert, ) Y = Y + sigma * np.random.randn(nb_vert, ) # Delaunay triangulation: be careful, to do on the curvilinear aspects to # avoid triangle flips Xtmp, S = np.meshgrid(x, curve_samples) S = S.flatten() # faces_tri = Triangulation(X, S) faces_tri = Delaunay(np.vstack((X, S)).T, qhull_options='QJ Qt Qbb') # alternative setting? 'Qbb Qc Qz Qj' Z = quadric(0, A)(X, Y) coords = np.array([X, Y, Z]).transpose() paraboloid_mesh = trimesh.Trimesh(faces=faces_tri.simplices, vertices=coords, process=False) # remove the faces having any vertex on the boundary to avoid # atypical faces geometry due to Delaunay triangulation in 2D # TO DO: same boundary removal as for generate_quadric return stop.remove_mesh_boundary_faces(paraboloid_mesh, face_vertex_number=1)
visb_sc = splt.visbrain_plot(mesh=open_mesh, caption='open mesh') # create points with vispy for bound in open_mesh_boundary: points = open_mesh.vertices[bound] s_rad = SourceObj('rad', points, color='red', symbol='square', radius_min=10) visb_sc.add_to_subplot(s_rad) lines = Line(pos=open_mesh.vertices[bound], width=10, color='b') # wrap the vispy object using visbrain l_obj = VispyObj('line', lines) visb_sc.add_to_subplot(l_obj) visb_sc.preview() ############################################################################### # eroding the mesh by removing the faces having 3 vertices on the boundary eroded_mesh = stop.remove_mesh_boundary_faces(open_mesh, face_vertex_number=1) ############################################################################### # show the result visb_sc2 = splt.visbrain_plot(mesh=eroded_mesh, caption='eroded mesh') # show again the boundary of original mesh which have been removed with # corresponding faces by the erosion for bound in open_mesh_boundary: points = open_mesh.vertices[bound] s_rad = SourceObj('rad', points, color='red', symbol='square', radius_min=10) visb_sc2.add_to_subplot(s_rad) lines = Line(pos=open_mesh.vertices[bound], width=10, color='b') # wrap the vispy object using visbrain l_obj = VispyObj('line', lines) visb_sc2.add_to_subplot(l_obj)