Apply Filter Parameters: PercentageΒΆ

This example shows how to pass a Percentage as a parameter to a filter through the pmeshlab.MeshSet.apply_filter() function. This type of values can actually be passed in two different ways: as an absolute value or as a Percentage of something else. See Percentage for more details.

This script can be executed by running the following command:

pytest --pyargs pymeshlab -k 'apply_filter_parameters_percentage'


import pymeshlab

def example_apply_filter_parameters_percentage():
    # lines needed to run this specific example
    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')