def test_save_filter_script(): print('\n') base_path = samples_common.samples_absolute_path() output_path = samples_common.test_output_path() ms = ml.MeshSet() ms.load_new_mesh(base_path + "cube.obj") # remeshing isotropic explicit filter ms.apply_filter('remeshing_isotropic_explicit_remeshing') ms.apply_filter('remeshing_isotropic_explicit_remeshing') # compute per face quality ms.apply_filter( 'per_face_quality_according_to_triangle_shape_and_aspect_ratio') # colorize faces by face quality ms.apply_filter('colorize_by_face_quality') # save the mesh with all the default components ms.save_current_mesh(output_path + 'col_rem_cube.ply') # save the mesh without face color ms.save_current_mesh(output_path + 'nocol_rem_cube.ply', save_face_color=False) # save the filter script ms.save_filter_script(output_path + 'test_saved_script.mlx')
def example_user_defined_mesh_attributes(): # lines needed to run this specific example print('\n') from . import samples_common base_path = samples_common.samples_absolute_path() output_path = samples_common.test_output_path() # create a new MeshSet ms = pymeshlab.MeshSet() ms.load_new_mesh(base_path + "cube.obj") # save a reference to the current mesh of the MeshSet m = ms.current_mesh() # create a new per vertex attribute called v_attr # each value is the sum of the x, y and z coords of the vertex ms.apply_filter("define_new_per_vertex_attribute", name="v_attr", expr="x+y+z") # save the values of the attribute v_attr in a numpy array v_attr = m.vertex_scalar_attribute_array('v_attr') # create a new per face attribute called f_attr # each value is the sum of the vertex indices that form the face ms.apply_filter("define_new_per_face_attribute", name="f_attr", expr="vi0+vi1+vi2") # save the values of the attribute f_attr in a numpy array f_attr = m.face_scalar_attribute_array('f_attr') print(v_attr) print(f_attr)
def example_get_mesh_values(): # lines needed to run this specific example print('\n') from . import samples_common base_path = samples_common.samples_absolute_path() output_path = samples_common.test_output_path() # create a new MeshSet ms = pymeshlab.MeshSet() ms.load_new_mesh(base_path + 'chameleon.pts') # applying some filters... ms.point_cloud_simplification() ms.surface_reconstruction_ball_pivoting() ms.parametrization_trivial_per_triangle(textdim=1024) ms.save_current_mesh(output_path + 'chameleon_simplified.obj') ms.transfer_vertex_color_to_texture(textname='chameleon_simplified.png') # get a reference to the current mesh m = ms.current_mesh() # get numpy arrays of vertices and faces of the current mesh vertex_array_matrix = m.vertex_matrix() face_array_matrix = m.face_matrix()
def test_delete_small_components(): print('\n') base_path = samples_common.samples_absolute_path() output_path = samples_common.test_output_path() ms = ml.MeshSet() ms.load_new_mesh(base_path + "rangemaps/face000.ply") assert ms.number_meshes() == 1 assert ms.current_mesh().face_number() == 166259 # select small disconnected component with a given face ratio ms.select_small_disconnected_component(nbfaceratio=0.01) assert ms.current_mesh().selected_face_number() == 485 # delete selected faces ms.delete_selected_faces() assert ms.current_mesh().selected_face_number() == 0 assert ms.current_mesh().face_number() == 165774 assert ms.current_mesh().vertex_number() == 85849 # remove unreferenced vertices ms.remove_unreferenced_vertices() assert ms.current_mesh().vertex_number() == 84777 ms.save_current_mesh(output_path + 'face000_clean.ply')
def main(): argv = sys.argv argv = argv[argv.index("--") + 1:] # get all args after "--" inputPath1 = argv[0] outputExt = argv[4] for fileName in os.listdir(inputPath1): if fileName.endswith(argv[1]): url = os.path.join(inputPath1, fileName) newPathBase = fileName.split(argv[1])[0] inputPath2 = os.path.join(argv[2], newPathBase + argv[3]) outputPath = os.path.join(argv[2], newPathBase + outputExt) ms = ml.MeshSet() ms.load_new_mesh( os.path.abspath(url)) # pymeshlab needs absolute paths ms.load_new_mesh( os.path.abspath(inputPath2)) # pymeshlab needs absolute paths # https://pymeshlab.readthedocs.io/en/latest/filter_list.html ms.apply_filter("vertex_attribute_transfer", sourcemesh=0, targetmesh=1) ms.save_current_mesh( os.path.abspath(outputPath)) # pymeshlab needs absolute paths
def example_apply_filter_output(): # lines needed to run this specific example print('\n') from . import samples_common base_path = samples_common.samples_absolute_path() # create a new MeshSet ms = pymeshlab.MeshSet() ms.load_new_mesh(base_path + "bone.ply") # compute the geometric measures of the current mesh # and save the results in the out_dict dictionary out_dict = ms.apply_filter('compute_geometric_measures') # get the average edge length from the dictionary avg_edge_length = out_dict['avg_edge_length'] # get the total edge length total_edge_length = out_dict['total_edge_length'] # get the mesh volume mesh_volume = out_dict['mesh_volume'] # get the surface area surf_area = out_dict['surface_area'] # checks with bounds (for numerical errors) assert (0.023 < avg_edge_length < 0.024) assert (105.343 < total_edge_length < 105.344) assert (0.025 < mesh_volume < 0.026) assert (0.694 < surf_area < 0.695)
def test_load_meshes(): print('\n') base_path = samples_common.samples_absolute_path() ms = ml.MeshSet() ms.load_new_mesh(base_path + "bone.ply") print(ms.number_meshes()) ms.load_new_mesh(base_path + "airplane.obj") print(ms.number_meshes()) assert ms.number_meshes() == 2 ms.set_current_mesh(0) print(ms.current_mesh().vertex_number()) assert ms.current_mesh().vertex_number() == 1872 ms.set_current_mesh(1) print(ms.current_mesh().vertex_number()) assert ms.current_mesh().vertex_number() == 7017
def example_apply_filter(): # lines needed to run this specific example print('\n') from . import samples_common base_path = samples_common.samples_absolute_path() output_path = samples_common.test_output_path() # create a new MeshSet ms = pymeshlab.MeshSet() # load mesh ms.load_new_mesh(base_path + "airplane.obj") # apply convex hull filter to the current selected mesh (last loaded) ms.convex_hull() # alternatively: # ms.apply_filter('convex_hull') assert ms.number_meshes() == 2 # save the current selected mesh ms.save_current_mesh(output_path + "convex_hull.obj") # get a reference to the current selected mesh m = ms.current_mesh() print(m.vertex_number()) assert m.vertex_number() == 455
def example_apply_filter_parameters_percentage(): # lines needed to run this specific example print('\n') from . import samples_common base_path = samples_common.samples_absolute_path() output_path = samples_common.test_output_path() # create a new MeshSet ms = pymeshlab.MeshSet() ms.load_new_mesh(base_path + "rangemaps/face000.ply") assert ms.number_meshes() == 1 assert ms.current_mesh().face_number() == 166259 # create a new object of type Percentage, with value 50% p = pymeshlab.Percentage(50) # apply the filter that will remove connected components having diameter less than 50% # of the diameter of the entire mesh ms.apply_filter('remove_isolated_pieces_wrt_diameter', mincomponentdiag=p) assert ms.current_mesh().face_number() == 161606 ms.save_current_mesh(output_path + 'face000_clean_by_diameter.ply')
def example_filter_script_create_and_save(): # lines needed to run this specific example print('\n') from . import samples_common base_path = samples_common.samples_absolute_path() output_path = samples_common.test_output_path() # create a new MeshSet ms = pymeshlab.MeshSet() # load a new mesh ms.load_new_mesh(base_path + "cube.obj") # applying some filter to the mesh... # every apply_filter saves in the filter script stored in the MeshSet # the applied filter with their parameters ms.apply_filter('remeshing_isotropic_explicit_remeshing') ms.apply_filter('remeshing_isotropic_explicit_remeshing') ms.apply_filter( 'per_face_quality_according_to_triangle_shape_and_aspect_ratio') ms.apply_filter('colorize_by_face_quality') # save the mesh ms.save_current_mesh(output_path + 'col_rem_cube.ply') # save the current filter script, containing all the filters with their parameters # that have been applied in the MeshSet ms. ms.save_filter_script(output_path + 'test_saved_script.mlx')
def main(args): # Create directories dirs = ["0_in", "1_scaled", "1_transform", "2_depth", "2_watertight", "4_points", "4_pointcloud", "4_watertight_scaled"] for dir_name in dirs: dir_pth = os.path.join(args.ycb_out, dir_name) if not os.path.exists(dir_pth): os.makedirs(dir_pth) # Convert to off for obj_name in os.listdir(args.ycb_in): ply_pth = os.path.join(args.ycb_in, obj_name, "google_{}k".format(args.vertices), 'nontextured.ply') if os.path.exists(ply_pth): out_pth = os.path.join(args.ycb_out, "0_in", f"{obj_name}.off") ms = pymeshlab.MeshSet() ms.load_new_mesh(ply_pth) # Scale object ms.transform_scale_normalize(axisx=args.scale, uniformflag=True) ms.save_current_mesh(out_pth, save_vertex_color=False, save_vertex_coord=False, save_face_color=False)
def main(): points_file = sys.argv[1] distance = float(sys.argv[2]) ms = pymeshlab.MeshSet() ms.load_new_mesh(points_file) ms.merge_close_vertices(threshold=pymeshlab.AbsoluteValue(distance)) ms.save_current_mesh(points_file, save_vertex_normal=False)
def surface_reconstruction_screened_poisson(path): ms = pymeshlab.MeshSet() ms.load_new_mesh(path) ms.compute_normals_for_point_sets() ms.surface_reconstruction_screened_poisson() ms.save_current_mesh(path) filtered_mesh = o3d.io.read_point_cloud(path) return filtered_mesh
def test_noisy_isosurface(): print('\n') output_path = samples_common.test_output_path() ms = ml.MeshSet() ms.apply_filter('noisy_isosurface', resolution=128) ms.save_current_mesh(output_path + 'noisy_isosurface' + str(128) + '.ply')
def example_import_mesh_from_arrays(): # lines needed to run this specific example print('\n') from . import samples_common output_path = samples_common.test_output_path() # create a numpy 8x3 array of vertices # columns are the coordinates (x, y, z) # every row represents a vertex verts = numpy.array([[-0.5, -0.5, -0.5], [0.5, -0.5, -0.5], [-0.5, 0.5, -0.5], [0.5, 0.5, -0.5], [-0.5, -0.5, 0.5], [0.5, -0.5, 0.5], [-0.5, 0.5, 0.5], [0.5, 0.5, 0.5]]) # create a numpy 12x3 array of faces # every row represents a face (trianlge in this case) # for every triangle, the index of the vertex # in the vertex array faces = numpy.array([[2, 1, 0], [1, 2, 3], [4, 2, 0], [2, 4, 6], [1, 4, 0], [4, 1, 5], [6, 5, 7], [5, 6, 4], [3, 6, 7], [6, 3, 2], [5, 3, 7], [3, 5, 1]]) # create a new Mesh with the two arrays m = pymeshlab.Mesh(verts, faces) assert m.vertex_number() == 8 assert m.face_number() == 12 # create a new MeshSet ms = pymeshlab.MeshSet() # add the mesh to the MeshSet ms.add_mesh(m, "cube_mesh") # save the current mesh ms.save_current_mesh(output_path + "saved_cube_from_array.ply") # create a 1D numpy array of 8 elements to store per vertex quality vert_quality = numpy.array([1, 2, 3, 4, 5, 6, 7, 8]) # create a 1D numpy array of 12 elements to store per face quality face_quality = numpy.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) # create a new mesh with the selected arrays m1 = pymeshlab.Mesh(vertex_matrix=verts, face_matrix=faces, v_quality_array=vert_quality, f_quality_array=face_quality) # add the mesh to the MeshSet ms.add_mesh(m1, "cube_quality_mesh") # colorize the cube according to the per face and per vertex quality ms.colorize_by_vertex_quality() ms.colorize_by_face_quality() # save the mesh ms.save_current_mesh(output_path + "colored_cube_from_array.ply")
def test_save_meshes(): print('\n') base_path = samples_common.samples_absolute_path() output_path = samples_common.test_output_path() ms = ml.MeshSet() ms.load_new_mesh(base_path + "bone.ply") ms.save_current_mesh(output_path + "bone_saved.obj")
def test_save_projects(): print('\n') base_path = samples_common.samples_absolute_path() output_path = samples_common.test_output_path() ms = ml.MeshSet() ms.load_new_mesh(base_path + "bone.ply") ms.save_project(output_path + "project_saved.mlp")
def test_laplacian_smoothing(): print('\n') output_path = samples_common.test_output_path() ms = ml.MeshSet() ms.create_noisy_isosurface() ms.apply_coord_laplacian_smoothing() ms.save_current_mesh(output_path + 'smoothed_noisy_isosurface.ply')
def __init__(self, point_cloud_file="", output_file="", filter_script_file="", clean_up=True): self.mesh_set = pymeshlab.MeshSet() self.point_cloud = pymeshlab.Mesh() self.mesh = pymeshlab.Mesh() super().__init__(point_cloud_file, output_file, filter_script_file, clean_up)
def test_texture_map_defragmentation(): print('\n') base_path = samples_common.samples_absolute_path() output_path = samples_common.test_output_path() ms = ml.MeshSet() ms.load_new_mesh(base_path + "bunny10k_textured.obj") ms.apply_texmap_defragmentation() ms.save_current_mesh(output_path + "bunny_text_defrag.obj")
def test_ambient_occlusion(): print('\n') base_path = samples_common.samples_absolute_path() output_path = samples_common.test_output_path() ms = ml.MeshSet() ms.load_new_mesh(base_path + "bunny.obj") ms.compute_scalar_ambient_occlusion() ms.save_current_mesh(output_path + 'bunny_ao.ply')
def surface_reconstruction_screened_poisson(input_path): ms = pymeshlab.MeshSet() ms.load_new_mesh(input_path) ms.compute_normals_for_point_sets() ms.surface_reconstruction_screened_poisson() cm = ms.current_mesh() print(cm) output_path = input_path.split('.')[0] + "_filtered.ply" ms.save_current_mesh(output_path) filtered_mesh = o3d.io.read_point_cloud(output_path) return filtered_mesh
def test_load_apply_filter_script(): print('\n') base_path = samples_common.samples_absolute_path() output_path = samples_common.test_output_path() ms = ml.MeshSet() ms.load_filter_script(base_path + "sample_filter_script.mlx") ms.apply_filter_script() ms.save_current_mesh(output_path + "cube_cc.ply")
def test_merge_meshes(): print('\n') base_path = samples_common.samples_absolute_path() output_path = samples_common.test_output_path() ms = ml.MeshSet() ms.load_new_mesh(base_path + "bone.ply") ms.load_new_mesh(base_path + "airplane.obj") ms.generate_by_merging_visible_meshes() ms.save_current_mesh(output_path + "merged.obj")
def test_merge_meshes(): print('\n') base_path = samples_common.samples_absolute_path() output_path = samples_common.test_output_path() ms = ml.MeshSet() ms.load_new_mesh(base_path + "bone.ply") ms.load_new_mesh(base_path + "airplane.obj") ms.apply_filter("flatten_visible_layers") ms.save_current_mesh(output_path + "merged.obj")
def wrl2gltf(inname, outname): # Use meshlab to read the WRL ms = ml.MeshSet() ms.load_new_mesh(inname) # Save a temporary PLY file ms.save_current_mesh('tempmesh.ply') ply2gltf.ply2gltf('tempmesh.ply', outname) # Clean up the temp PLY file os.remove('tempmesh.ply')
def example_import_mesh_from_arrays(): # lines needed to run this specific example print('\n') from . import samples_common output_path = samples_common.test_output_path() # create a numpy 8x3 array of vertices # columns are the coordinates (x, y, z) # every row represents a vertex verts = numpy.array([ [-0.5, -0.5, -0.5], [0.5, -0.5, -0.5], [-0.5, 0.5, -0.5], [0.5, 0.5, -0.5], [-0.5, -0.5, 0.5], [0.5, -0.5, 0.5], [-0.5, 0.5, 0.5], [0.5, 0.5, 0.5]]) # create a numpy 12x3 array of faces # every row represents a face (trianlge in this case) # for every triangle, the index of the vertex # in the vertex array faces = numpy.array([ [2, 1, 0], [1, 2, 3], [4, 2, 0], [2, 4, 6], [1, 4, 0], [4, 1, 5], [6, 5, 7], [5, 6, 4], [3, 6, 7], [6, 3, 2], [5, 3, 7], [3, 5, 1]]) # create a new Mesh with the two arrays m = pymeshlab.Mesh(verts, faces) assert m.vertex_number() == 8 assert m.face_number() == 12 # create a new MeshSet ms = pymeshlab.MeshSet() # add the mesh to the MeshSet ms.add_mesh(m, "cube_mesh") # save the current mesh ms.save_current_mesh(output_path + "saved_cube_from_array.ply")
def example_custom_mesh_attributes(): # lines needed to run this specific example print('\n') from . import samples_common base_path = samples_common.samples_absolute_path() output_path = samples_common.test_output_path() # create a new MeshSet ms = pymeshlab.MeshSet() ms.load_new_mesh(base_path + "cube.obj") # save a reference to the current mesh of the MeshSet m = ms.current_mesh() # create a new per vertex custom scalar attribute called v_attr # each value is the sum of the x, y and z coords of the vertex ms.compute_new_custom_scalar_attribute_per_vertex(name="v_attr", expr="x+y+z") # save the values of the custom attribute v_attr in a numpy array v_attr = m.vertex_custom_scalar_attribute_array('v_attr') # create a new per face custom scalar attribute called f_attr # each value is the sum of the vertex indices that form the face ms.compute_new_custom_scalar_attribute_per_face(name="f_attr", expr="vi0+vi1+vi2") # save the values of the custom attribute f_attr in a numpy array f_attr = m.face_custom_scalar_attribute_array('f_attr') print(v_attr) print(f_attr) # create a new per vertex custom point (3 scalars) attribute called vp_attr # values are the x, y and z coords of the vertex (useful to save coordinates # before some geometry processing) ms.compute_new_custom_point_attribute_per_vertex(name="vp_attr", x_expr="x", y_expr="y", z_expr="z") # save the values of the custom attribute vp_attr in a numpy array vp_attr = m.vertex_custom_point_attribute_matrix('vp_attr') print(vp_attr) # save the cube in ply format, including also the 'v_attr' custom attribute # custom attribute can be saved through boolean parameters named with lowercase names and with the prefix # that depends on the type of custom attribute: # - __ca_vs__: Custom Attribute Vertex Scalar; # - __ca_vp__: Custom Attribute Vertex Point; # - __ca_fs__: Custom Attribute Face Scalar; # - __ca_fp__: Custom Attribute Face Point; ms.save_current_mesh(output_path + 'cube_custom_attr.ply', binary=False, __ca_vs__v_attr=True)
def test_mesh_booleans(): print('\n') base_path = samples_common.samples_absolute_path() output_path = samples_common.test_output_path() ms = ml.MeshSet() ms.load_new_mesh(base_path + "cow.obj") # id: 0 ms.load_new_mesh(base_path + "bone.ply") # id: 1, just for test id on mesh parameter ms.load_new_mesh(base_path + "airplane.obj") # id: 2 ms.generate_boolean_union(first_mesh=0, second_mesh=2) ms.save_current_mesh(output_path + 'cow_with_wings.obj')
def test_csg(): print('\n') base_path = samples_common.samples_absolute_path() output_path = samples_common.test_output_path() ms = ml.MeshSet() ms.load_new_mesh(base_path + "cow.obj") # id: 0 ms.load_new_mesh(base_path + "bone.ply") # id: 1, just for test id on mesh parameter ms.load_new_mesh(base_path + "airplane.obj") # id: 2 ms.csg_operation(firstmesh=0, secondmesh=2, operator='Union') ms.save_current_mesh(output_path + 'cow_with_wings.obj')