Apply Filter: OutputΒΆ
This example shows how to extract the output of a filter from the pmeshlab.MeshSet.apply_filter()
function.
The output of this method is a python dictionary, often empty because most of the filters do not need to return anything.
When the output dictionary is not empty, it is always on the form [key - value]
, where the key
is of str
type and the value
can be a boolean
, int
, float
or a numpy.array
depending on what is best to represent the returned value.
Right now the List of Filters documentation lacks on if and what type of values a filter returns (we are sorry about that!). We will expand the documentation in the future; in the meantime we suggest to look for the name and type of values returned by running the desired filter from a python console.
This script can be executed by running the following command:
pytest --pyargs pymeshlab -k 'apply_filter_output'
tests/example_apply_filter_output.py
import pymeshlab
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)