meshlabxml/compute.py
def section(script, axis='z', offset=0.0, surface=False, custom_axis=None,
            planeref=2):
    """ Compute the polyline representing a planar section (a slice) of a mesh.

    If the resulting polyline is closed the result can be filled with a
    triangular mesh representing the section.

    Args:
        script: the mlx.FilterScript object or script filename to write
            the filter to.
        axis (str): The slicing plane is perpendicular to this axis. Accepted
            values are 'x', 'y', or 'z'; any other input will be interpreted
            as a custom axis (although using 'custom' is recommended
            for clarity). Upper or lowercase values are accepted.
        offset (float): Specify an offset of the cross-plane. The offset
            corresponds to the distance along 'axis' from the point specified
            in 'planeref'.
        surface (bool): If True, in addition to a layer with the section
            polyline, also a layer with a triangulated version of the section
            polyline will be created. This only works if the section polyline
            is closed.
        custom_axis (3 component list or tuple): Specify a custom axis as
            a 3 component vector (x, y, z); this is ignored unless 'axis' is
            set  to 'custom'.
        planeref (int): Specify the reference from which the planes are
            shifted. Valid values are:
            0 - Bounding box center
            1 - Bounding box min
            2 - Origin (default)

    Layer stack:
        Creates a new layer '{label}_sect_{axis_name}_{offset}', where
            'axis_name' is one of [X, Y, Z, custom] and 'offest' is
            truncated 'offset'
        If surface is True, create a new layer '{label}_sect_{axis}_{offset}_mesh'
        Current layer is changed to the last (newly created) layer

    MeshLab versions:
        2016.12
        1.3.4BETA
    """
    # Convert axis name into number
    if axis.lower() == 'x':
        axis_num = 0
        axis_name = 'X'
    elif axis.lower() == 'y':
        axis_num = 1
        axis_name = 'Y'
    elif axis.lower() == 'z':
        axis_num = 2
        axis_name = 'Z'
    else:  # custom axis
        axis_num = 3
        axis_name = 'custom'
        if custom_axis is None:
            print('WARNING: a custom axis was selected, however',
                  '"custom_axis" was not provided. Using default (Z).')
    if custom_axis is None:
        custom_axis = (0.0, 0.0, 1.0)

    filter_xml = ''.join([
        '  <filter name="Compute Planar Section">\n',
        '    <Param name="planeAxis" ',
        'value="{:d}" '.format(axis_num),
        'description="Plane perpendicular to" ',
        'enum_val0="X Axis" ',
        'enum_val1="Y Axis" ',
        'enum_val2="Z Axis" ',
        'enum_val3="Custom Axis" ',
        'enum_cardinality="4" ',
        'type="RichEnum" ',
        '/>\n',
        '    <Param name="customAxis" ',
        'x="{}" y="{}" z="{}" '.format(custom_axis[0], custom_axis[1],
                                       custom_axis[2]),
        'description="Custom axis" ',
        'type="RichPoint3f" ',
        '/>\n',
        '    <Param name="planeOffset" ',
        'value="{}" '.format(offset),
        'description="Cross plane offset" ',
        'type="RichFloat" ',
        '/>\n',
        '    <Param name="relativeTo" ',
        'value="{:d}" '.format(planeref),
        'description="plane reference" ',
        'enum_val0="Bounding box center" ',
        'enum_val1="Bounding box min" ',
        'enum_val2="Origin" ',
        'enum_cardinality="3" ',
        'type="RichEnum" ',
        '/>\n',
        '    <Param name="createSectionSurface" ',
        'value="{}" '.format(str(surface).lower()),
        'description="Create also section surface" ',
        'type="RichBool" ',
        '/>\n',
        '  </filter>\n'])
    util.write_filter(script, filter_xml)
    if isinstance(script, mlx.FilterScript):
        current_layer_label = script.layer_stack[script.current_layer()]
        script.add_layer('{}_sect_{}_{}'.format(current_layer_label, axis_name,
                                                int(offset)))
        if surface:
            script.add_layer('{}_sect_{}_{}_mesh'.format(current_layer_label,
                                                         axis_name, int(offset)))
    return None
def section(script, axis='z', offset=0.0, surface=False, custom_axis=None,
            planeref=2):
    """ Compute the polyline representing a planar section (a slice) of a mesh.

    If the resulting polyline is closed the result can be filled with a
    triangular mesh representing the section.

    Args:
        script: the mlx.FilterScript object or script filename to write
            the filter to.
        axis (str): The slicing plane is perpendicular to this axis. Accepted
            values are 'x', 'y', or 'z'; any other input will be interpreted
            as a custom axis (although using 'custom' is recommended
            for clarity). Upper or lowercase values are accepted.
        offset (float): Specify an offset of the cross-plane. The offset
            corresponds to the distance along 'axis' from the point specified
            in 'planeref'.
        surface (bool): If True, in addition to a layer with the section
            polyline, also a layer with a triangulated version of the section
            polyline will be created. This only works if the section polyline
            is closed.
        custom_axis (3 component list or tuple): Specify a custom axis as
            a 3 component vector (x, y, z); this is ignored unless 'axis' is
            set  to 'custom'.
        planeref (int): Specify the reference from which the planes are
            shifted. Valid values are:
            0 - Bounding box center
            1 - Bounding box min
            2 - Origin (default)

    Layer stack:
        Creates a new layer '{label}_sect_{axis_name}_{offset}', where
            'axis_name' is one of [X, Y, Z, custom] and 'offest' is
            truncated 'offset'
        If surface is True, create a new layer '{label}_sect_{axis}_{offset}_mesh'
        Current layer is changed to the last (newly created) layer

    MeshLab versions:
        2016.12
        1.3.4BETA
    """
    # Convert axis name into number
    if axis.lower() == 'x':
        axis_num = 0
        axis_name = 'X'
    elif axis.lower() == 'y':
        axis_num = 1
        axis_name = 'Y'
    elif axis.lower() == 'z':
        axis_num = 2
        axis_name = 'Z'
    else:  # custom axis
        axis_num = 3
        axis_name = 'custom'
        if custom_axis is None:
            print('WARNING: a custom axis was selected, however',
                  '"custom_axis" was not provided. Using default (Z).')
    if custom_axis is None:
        custom_axis = (0.0, 0.0, 1.0)

    filter_xml = ''.join([
        '  <filter name="Compute Planar Section">\n',
        '    <Param name="planeAxis" ',
        'value="{:d}" '.format(axis_num),
        'description="Plane perpendicular to" ',
        'enum_val0="X Axis" ',
        'enum_val1="Y Axis" ',
        'enum_val2="Z Axis" ',
        'enum_val3="Custom Axis" ',
        'enum_cardinality="4" ',
        'type="RichEnum" ',
        '/>\n',
        '    <Param name="customAxis" ',
        'x="{}" y="{}" z="{}" '.format(custom_axis[0], custom_axis[1],
                                       custom_axis[2]),
        'description="Custom axis" ',
        'type="RichPoint3f" ',
        '/>\n',
        '    <Param name="planeOffset" ',
        'value="{}" '.format(offset),
        'description="Cross plane offset" ',
        'type="RichFloat" ',
        '/>\n',
        '    <Param name="relativeTo" ',
        'value="{:d}" '.format(planeref),
        'description="plane reference" ',
        'enum_val0="Bounding box center" ',
        'enum_val1="Bounding box min" ',
        'enum_val2="Origin" ',
        'enum_cardinality="3" ',
        'type="RichEnum" ',
        '/>\n',
        '    <Param name="createSectionSurface" ',
        'value="{}" '.format(str(surface).lower()),
        'description="Create also section surface" ',
        'type="RichBool" ',
        '/>\n',
        '  </filter>\n'])
    util.write_filter(script, filter_xml)
    if isinstance(script, mlx.FilterScript):
        current_layer_label = script.layer_stack[script.current_layer()]
        script.add_layer('{}_sect_{}_{}'.format(current_layer_label, axis_name,
                                                int(offset)))
        if surface:
            script.add_layer('{}_sect_{}_{}_mesh'.format(current_layer_label,
                                                         axis_name, int(offset)))
    return None
Compute the polyline representing a planar section (a slice) of a mesh.

    If the resulting polyline is closed the result can be filled with a
    triangular mesh representing the section.

    Args:
        script: the mlx.FilterScript object or script filename to write
            the filter to.
        axis (str): The slicing plane is perpendicular to this axis. Accepted
            values are 'x', 'y', or 'z'; any other input will be interpreted
            as a custom axis (although using 'custom' is recommended
            for clarity). Upper or lowercase values are accepted.
        offset (float): Specify an offset of the cross-plane. The offset
            corresponds to the distance along 'axis' from the point specified
            in 'planeref'.
        surface (bool): If True, in addition to a layer with the section
            polyline, also a layer with a triangulated version of the section
            polyline will be created. This only works if the section polyline
            is closed.
        custom_axis (3 component list or tuple): Specify a custom axis as
            a 3 component vector (x, y, z); this is ignored unless 'axis' is
            set  to 'custom'.
        planeref (int): Specify the reference from which the planes are
            shifted. Valid values are:
            0 - Bounding box center
            1 - Bounding box min
            2 - Origin (default)

    Layer stack:
        Creates a new layer '{label}_sect_{axis_name}_{offset}', where
            'axis_name' is one of [X, Y, Z, custom] and 'offest' is
            truncated 'offset'
        If surface is True, create a new layer '{label}_sect_{axis}_{offset}_mesh'
        Current layer is changed to the last (newly created) layer

    MeshLab versions:
        2016.12
        1.3.4BETA