Apply Filter Parameters: Ranged Percentage

This example shows how to pass a ranged percentage as a parameter to a filter. This is useful when you have no clue on the size or the units used and you want to perform some computations that depends on theactual size of the object. Typical example is the size small floating pieces that you want to delete in a noisy mesh.

This type of values can actually be passed in two different ways: as an PureValue (e.g. the actual size of the object you want to be reomved) or as a PercentageValue like 10.0 that, in that specific case, will denote that you will remove the object whose size is 10% of the diagonal of the bounding box of the affected mesh. The range on which the filter operates is automatically computed by the filter itself and described in the documentation of the filter.

Note: before version 2022.xx, name of these classes was Percentage and AbsoluteValue.

See PercentageValue and PureValue for more details.

This script can be executed by running the following command:

pytest --pyargs pymeshlab -k 'apply_filter_parameters_percentage'

tests/example_apply_filter_parameters_percentage.py

import pymeshlab


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.mesh_number() == 1

    assert ms.current_mesh().face_number() == 166259

    # create a new object of type PercentageValue, with value 50%
    p = pymeshlab.PercentageValue(50)

    # apply the filter that will remove connected components having diameter less than 50%
    # of the diameter of the entire mesh
    ms.meshing_remove_connected_component_by_diameter(mincomponentdiag=p)

    # There is the possibility to use an PureValue instead of a Percentage:
    #   av = pymeshlab.PureValue(0.5)
    #   ms.meshing_remove_connected_component_by_diameter(mincomponentdiag=av)

    assert ms.current_mesh().face_number() == 161606

    ms.save_current_mesh(output_path + 'face000_clean_by_diameter.ply')