meshlabxml/sampling.py
def hausdorff_distance(script, sampled_layer=1, target_layer=0,
                       save_sample=False, sample_vert=True, sample_edge=True,
                       sample_faux_edge=False, sample_face=True,
                       sample_num=1000, maxdist=10):
    """ Compute the Hausdorff Distance between two meshes, sampling one of the
        two and finding for each sample the closest point over the other mesh.

    Args:
        script: the FilterScript object or script filename to write
            the filter to.
        sampled_layer (int): The mesh layer whose surface is sampled. For each
            sample we search the closest point on the target mesh layer.
        target_layer (int): The mesh that is sampled for the comparison.
        save_sample (bool): Save the position and distance of all the used
            samples on both the two surfaces, creating two new layers with two
            point clouds representing the used samples.
        sample_vert (bool): For the search of maxima it is useful to sample
            vertices and edges of the mesh with a greater care. It is quite
            probable that the farthest points falls along edges or on mesh
            vertexes, and with uniform montecarlo sampling approaches the
            probability of taking a sample over a vertex or an edge is
            theoretically null. On the other hand this kind of sampling could
            make the overall sampling distribution slightly biased and slightly
            affects the cumulative results.
        sample_edge (bool): see sample_vert
        sample_faux_edge (bool): see sample_vert
        sample_face (bool): see sample_vert
        sample_num (int): The desired number of samples. It can be smaller or
            larger than the mesh size, and according to the chosen sampling
            strategy it will try to adapt.
        maxdist (int): Sample points for which we do not find anything within
            this distance are rejected and not considered neither for averaging
            nor for max.

    Layer stack:
        If save_sample is True, two new layers are created: 'Hausdorff Closest
            Points' and 'Hausdorff Sample Point'; and the current layer is
            changed to the last newly created layer.
        If save_sample is False, no impacts

    MeshLab versions:
        2016.12
        1.3.4BETA
    """
    # MeshLab defaults:
    #  sample_num = number of vertices
    #  maxdist = 0.05 * AABB['diag'] #5% of AABB[diag]
    #  maxdist_max = AABB['diag']
    maxdist_max = 2*maxdist
    # TODO: parse output (min, max, mean, etc.)
    filter_xml = ''.join([
        '  <filter name="Hausdorff Distance">\n',
        '    <Param name="SampledMesh" ',
        'value="{:d}" '.format(sampled_layer),
        'description="Sampled Mesh" ',
        'type="RichMesh" ',
        '/>\n',
        '    <Param name="TargetMesh" ',
        'value="{:d}" '.format(target_layer),
        'description="Target Mesh" ',
        'type="RichMesh" ',
        '/>\n',
        '    <Param name="SaveSample" ',
        'value="{}" '.format(str(save_sample).lower()),
        'description="Save Samples" ',
        'type="RichBool" ',
        '/>\n',
        '    <Param name="SampleVert" ',
        'value="{}" '.format(str(sample_vert).lower()),
        'description="Sample Vertexes" ',
        'type="RichBool" ',
        '/>\n',
        '    <Param name="SampleEdge" ',
        'value="{}" '.format(str(sample_edge).lower()),
        'description="Sample Edges" ',
        'type="RichBool" ',
        '/>\n',
        '    <Param name="SampleFauxEdge" ',
        'value="{}" '.format(str(sample_faux_edge).lower()),
        'description="Sample FauxEdge" ',
        'type="RichBool" ',
        '/>\n',
        '    <Param name="SampleFace" ',
        'value="{}" '.format(str(sample_face).lower()),
        'value="%s" ' % str(sample_face).lower() +
        'description="Sample Faces" ',
        'type="RichBool" ',
        '/>\n',
        '    <Param name="SampleNum" ',
        'value="{:d}" '.format(sample_num),
        'description="Number of samples" ',
        'type="RichInt" ',
        '/>\n',
        '    <Param name="MaxDist" ',
        'value="{}" '.format(maxdist),
        'value="%s" ' % maxdist +
        'description="Max Distance" ',
        'min="0" ',
        'max="{}" '.format(maxdist_max),
        'type="RichAbsPerc" ',
        '/>\n',
        '  </filter>\n'])
    util.write_filter(script, filter_xml)
    if isinstance(script, FilterScript):
        script.parse_hausdorff = True
    if isinstance(script, FilterScript) and save_sample:
        script.add_layer('Hausdorff Closest Points')
        script.add_layer('Hausdorff Sample Point')
    return None
def hausdorff_distance(script, sampled_layer=1, target_layer=0,
                       save_sample=False, sample_vert=True, sample_edge=True,
                       sample_faux_edge=False, sample_face=True,
                       sample_num=1000, maxdist=10):
    """ Compute the Hausdorff Distance between two meshes, sampling one of the
        two and finding for each sample the closest point over the other mesh.

    Args:
        script: the FilterScript object or script filename to write
            the filter to.
        sampled_layer (int): The mesh layer whose surface is sampled. For each
            sample we search the closest point on the target mesh layer.
        target_layer (int): The mesh that is sampled for the comparison.
        save_sample (bool): Save the position and distance of all the used
            samples on both the two surfaces, creating two new layers with two
            point clouds representing the used samples.
        sample_vert (bool): For the search of maxima it is useful to sample
            vertices and edges of the mesh with a greater care. It is quite
            probable that the farthest points falls along edges or on mesh
            vertexes, and with uniform montecarlo sampling approaches the
            probability of taking a sample over a vertex or an edge is
            theoretically null. On the other hand this kind of sampling could
            make the overall sampling distribution slightly biased and slightly
            affects the cumulative results.
        sample_edge (bool): see sample_vert
        sample_faux_edge (bool): see sample_vert
        sample_face (bool): see sample_vert
        sample_num (int): The desired number of samples. It can be smaller or
            larger than the mesh size, and according to the chosen sampling
            strategy it will try to adapt.
        maxdist (int): Sample points for which we do not find anything within
            this distance are rejected and not considered neither for averaging
            nor for max.

    Layer stack:
        If save_sample is True, two new layers are created: 'Hausdorff Closest
            Points' and 'Hausdorff Sample Point'; and the current layer is
            changed to the last newly created layer.
        If save_sample is False, no impacts

    MeshLab versions:
        2016.12
        1.3.4BETA
    """
    # MeshLab defaults:
    #  sample_num = number of vertices
    #  maxdist = 0.05 * AABB['diag'] #5% of AABB[diag]
    #  maxdist_max = AABB['diag']
    maxdist_max = 2*maxdist
    # TODO: parse output (min, max, mean, etc.)
    filter_xml = ''.join([
        '  <filter name="Hausdorff Distance">\n',
        '    <Param name="SampledMesh" ',
        'value="{:d}" '.format(sampled_layer),
        'description="Sampled Mesh" ',
        'type="RichMesh" ',
        '/>\n',
        '    <Param name="TargetMesh" ',
        'value="{:d}" '.format(target_layer),
        'description="Target Mesh" ',
        'type="RichMesh" ',
        '/>\n',
        '    <Param name="SaveSample" ',
        'value="{}" '.format(str(save_sample).lower()),
        'description="Save Samples" ',
        'type="RichBool" ',
        '/>\n',
        '    <Param name="SampleVert" ',
        'value="{}" '.format(str(sample_vert).lower()),
        'description="Sample Vertexes" ',
        'type="RichBool" ',
        '/>\n',
        '    <Param name="SampleEdge" ',
        'value="{}" '.format(str(sample_edge).lower()),
        'description="Sample Edges" ',
        'type="RichBool" ',
        '/>\n',
        '    <Param name="SampleFauxEdge" ',
        'value="{}" '.format(str(sample_faux_edge).lower()),
        'description="Sample FauxEdge" ',
        'type="RichBool" ',
        '/>\n',
        '    <Param name="SampleFace" ',
        'value="{}" '.format(str(sample_face).lower()),
        'value="%s" ' % str(sample_face).lower() +
        'description="Sample Faces" ',
        'type="RichBool" ',
        '/>\n',
        '    <Param name="SampleNum" ',
        'value="{:d}" '.format(sample_num),
        'description="Number of samples" ',
        'type="RichInt" ',
        '/>\n',
        '    <Param name="MaxDist" ',
        'value="{}" '.format(maxdist),
        'value="%s" ' % maxdist +
        'description="Max Distance" ',
        'min="0" ',
        'max="{}" '.format(maxdist_max),
        'type="RichAbsPerc" ',
        '/>\n',
        '  </filter>\n'])
    util.write_filter(script, filter_xml)
    if isinstance(script, FilterScript):
        script.parse_hausdorff = True
    if isinstance(script, FilterScript) and save_sample:
        script.add_layer('Hausdorff Closest Points')
        script.add_layer('Hausdorff Sample Point')
    return None
Compute the Hausdorff Distance between two meshes, sampling one of the
        two and finding for each sample the closest point over the other mesh.

    Args:
        script: the FilterScript object or script filename to write
            the filter to.
        sampled_layer (int): The mesh layer whose surface is sampled. For each
            sample we search the closest point on the target mesh layer.
        target_layer (int): The mesh that is sampled for the comparison.
        save_sample (bool): Save the position and distance of all the used
            samples on both the two surfaces, creating two new layers with two
            point clouds representing the used samples.
        sample_vert (bool): For the search of maxima it is useful to sample
            vertices and edges of the mesh with a greater care. It is quite
            probable that the farthest points falls along edges or on mesh
            vertexes, and with uniform montecarlo sampling approaches the
            probability of taking a sample over a vertex or an edge is
            theoretically null. On the other hand this kind of sampling could
            make the overall sampling distribution slightly biased and slightly
            affects the cumulative results.
        sample_edge (bool): see sample_vert
        sample_faux_edge (bool): see sample_vert
        sample_face (bool): see sample_vert
        sample_num (int): The desired number of samples. It can be smaller or
            larger than the mesh size, and according to the chosen sampling
            strategy it will try to adapt.
        maxdist (int): Sample points for which we do not find anything within
            this distance are rejected and not considered neither for averaging
            nor for max.

    Layer stack:
        If save_sample is True, two new layers are created: 'Hausdorff Closest
            Points' and 'Hausdorff Sample Point'; and the current layer is
            changed to the last newly created layer.
        If save_sample is False, no impacts

    MeshLab versions:
        2016.12
        1.3.4BETA