Apply Filter Parameters: PercentageΒΆ
This example shows how to pass a Percentage as a parameter to a filter. This type of values can actually be passed in two different ways: as an AbsoluteValue or as a Percentage of something else. Before version 2021.10, instead of AbsoluteValue, the type float was used, leading to unwanted errors by the users. The usage of the class AbsoluteValue makes sure that the user knows what type of value is passing to parameters that could accept both absolute values or percentages w.r.t. some other measures. See Percentage and AbsoluteValue 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.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.meshing_remove_connected_component_by_diameter(mincomponentdiag=p)
# There is the possibility to use an AbsoluteValue instead of a Percentage:
# av = pymeshlab.AbsoluteValue(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')