meshlabxml/transform.py
def vert_function(script, x_func='x', y_func='y', z_func='z', selected=False):
    """Geometric function using muparser lib to generate new Coordinates

    You can change x, y, z for every vertex according to the function specified.

    See help(mlx.muparser_ref) for muparser reference documentation.
    It's possible to use the following per-vertex variables in the expression:

    Variables (per vertex):
        x, y, z (coordinates)
        nx, ny, nz (normal)
        r, g, b, a (color)
        q (quality)
        rad (radius)
        vi (vertex index)
        vtu, vtv (texture coordinates)
        ti (texture index)
        vsel (is the vertex selected? 1 yes, 0 no)
        and all custom vertex attributes already defined by user.

    Args:
        x_func (str): function to generate new coordinates for x
        y_func (str): function to generate new coordinates for y
        z_func (str): function to generate new coordinates for z
        selected (bool): if True, only affects selected vertices (ML ver 2016.12 & up)

    Layer stack:
        No impacts

    MeshLab versions:
        2016.12
        1.3.4BETA
    """
    if script.ml_version == '1.3.4BETA':
        filter_xml = ''.join([
            '  <filter name="Geometric Function">\n',
            '    <Param name="x" ',
            'value="{}" '.format(str(x_func).replace('&', '&amp;').replace('<', '&lt;')),
            'description="func x = " ',
            'type="RichString" ',
            '/>\n',
            '    <Param name="y" ',
            'value="{}" '.format(str(y_func).replace('&', '&amp;').replace('<', '&lt;')),
            'description="func y = " ',
            'type="RichString" ',
            '/>\n',
            '    <Param name="z" ',
            'value="{}" '.format(str(z_func).replace('&', '&amp;').replace('<', '&lt;')),
            'description="func z = " ',
            'type="RichString" ',
            '/>\n',
            '  </filter>\n'])
    else:
        filter_xml = ''.join([
            '  <filter name="Per Vertex Geometric Function">\n',
            '    <Param name="x" ',
            'value="{}" '.format(str(x_func).replace('&', '&amp;').replace('<', '&lt;')),
            'description="func x = " ',
            'type="RichString" ',
            '/>\n',
            '    <Param name="y" ',
            'value="{}" '.format(str(y_func).replace('&', '&amp;').replace('<', '&lt;')),
            'description="func y = " ',
            'type="RichString" ',
            '/>\n',
            '    <Param name="z" ',
            'value="{}" '.format(str(z_func).replace('&', '&amp;').replace('<', '&lt;')),
            'description="func z = " ',
            'type="RichString" ',
            '/>\n',
            '    <Param name="onselected" ',
            'value="%s" ' % str(selected).lower(),
            'description="only on selection" ',
            'type="RichBool" ',
            '/>\n',
            '  </filter>\n'])
    util.write_filter(script, filter_xml)
    return None
def vert_function(script, x_func='x', y_func='y', z_func='z', selected=False):
    """Geometric function using muparser lib to generate new Coordinates

    You can change x, y, z for every vertex according to the function specified.

    See help(mlx.muparser_ref) for muparser reference documentation.
    It's possible to use the following per-vertex variables in the expression:

    Variables (per vertex):
        x, y, z (coordinates)
        nx, ny, nz (normal)
        r, g, b, a (color)
        q (quality)
        rad (radius)
        vi (vertex index)
        vtu, vtv (texture coordinates)
        ti (texture index)
        vsel (is the vertex selected? 1 yes, 0 no)
        and all custom vertex attributes already defined by user.

    Args:
        x_func (str): function to generate new coordinates for x
        y_func (str): function to generate new coordinates for y
        z_func (str): function to generate new coordinates for z
        selected (bool): if True, only affects selected vertices (ML ver 2016.12 & up)

    Layer stack:
        No impacts

    MeshLab versions:
        2016.12
        1.3.4BETA
    """
    if script.ml_version == '1.3.4BETA':
        filter_xml = ''.join([
            '  <filter name="Geometric Function">\n',
            '    <Param name="x" ',
            'value="{}" '.format(str(x_func).replace('&', '&amp;').replace('<', '&lt;')),
            'description="func x = " ',
            'type="RichString" ',
            '/>\n',
            '    <Param name="y" ',
            'value="{}" '.format(str(y_func).replace('&', '&amp;').replace('<', '&lt;')),
            'description="func y = " ',
            'type="RichString" ',
            '/>\n',
            '    <Param name="z" ',
            'value="{}" '.format(str(z_func).replace('&', '&amp;').replace('<', '&lt;')),
            'description="func z = " ',
            'type="RichString" ',
            '/>\n',
            '  </filter>\n'])
    else:
        filter_xml = ''.join([
            '  <filter name="Per Vertex Geometric Function">\n',
            '    <Param name="x" ',
            'value="{}" '.format(str(x_func).replace('&', '&amp;').replace('<', '&lt;')),
            'description="func x = " ',
            'type="RichString" ',
            '/>\n',
            '    <Param name="y" ',
            'value="{}" '.format(str(y_func).replace('&', '&amp;').replace('<', '&lt;')),
            'description="func y = " ',
            'type="RichString" ',
            '/>\n',
            '    <Param name="z" ',
            'value="{}" '.format(str(z_func).replace('&', '&amp;').replace('<', '&lt;')),
            'description="func z = " ',
            'type="RichString" ',
            '/>\n',
            '    <Param name="onselected" ',
            'value="%s" ' % str(selected).lower(),
            'description="only on selection" ',
            'type="RichBool" ',
            '/>\n',
            '  </filter>\n'])
    util.write_filter(script, filter_xml)
    return None
def vert_function ( script , x_func = 'x' , y_func = 'y' , z_func = 'z' , selected = False ) : if script . ml_version == '1.3.4BETA' : filter_xml = '' . join ( [ '  <filter name="Geometric Function">\n' , '    <Param name="x" ' , 'value="{}" ' . format ( str ( x_func ) . replace ( '&' , '&amp;' ) . replace ( '<' , '&lt;' ) ) , 'description="func x = " ' , 'type="RichString" ' , '/>\n' , '    <Param name="y" ' , 'value="{}" ' . format ( str ( y_func ) . replace ( '&' , '&amp;' ) . replace ( '<' , '&lt;' ) ) , 'description="func y = " ' , 'type="RichString" ' , '/>\n' , '    <Param name="z" ' , 'value="{}" ' . format ( str ( z_func ) . replace ( '&' , '&amp;' ) . replace ( '<' , '&lt;' ) ) , 'description="func z = " ' , 'type="RichString" ' , '/>\n' , '  </filter>\n' ] ) else : filter_xml = '' . join ( [ '  <filter name="Per Vertex Geometric Function">\n' , '    <Param name="x" ' , 'value="{}" ' . format ( str ( x_func ) . replace ( '&' , '&amp;' ) . replace ( '<' , '&lt;' ) ) , 'description="func x = " ' , 'type="RichString" ' , '/>\n' , '    <Param name="y" ' , 'value="{}" ' . format ( str ( y_func ) . replace ( '&' , '&amp;' ) . replace ( '<' , '&lt;' ) ) , 'description="func y = " ' , 'type="RichString" ' , '/>\n' , '    <Param name="z" ' , 'value="{}" ' . format ( str ( z_func ) . replace ( '&' , '&amp;' ) . replace ( '<' , '&lt;' ) ) , 'description="func z = " ' , 'type="RichString" ' , '/>\n' , '    <Param name="onselected" ' , 'value="%s" ' % str ( selected ) . lower ( ) , 'description="only on selection" ' , 'type="RichBool" ' , '/>\n' , '  </filter>\n' ] ) util . write_filter ( script , filter_xml ) return None
Geometric function using muparser lib to generate new Coordinates

    You can change x, y, z for every vertex according to the function specified.

    See help(mlx.muparser_ref) for muparser reference documentation.
    It's possible to use the following per-vertex variables in the expression:

    Variables (per vertex):
        x, y, z (coordinates)
        nx, ny, nz (normal)
        r, g, b, a (color)
        q (quality)
        rad (radius)
        vi (vertex index)
        vtu, vtv (texture coordinates)
        ti (texture index)
        vsel (is the vertex selected? 1 yes, 0 no)
        and all custom vertex attributes already defined by user.

    Args:
        x_func (str): function to generate new coordinates for x
        y_func (str): function to generate new coordinates for y
        z_func (str): function to generate new coordinates for z
        selected (bool): if True, only affects selected vertices (ML ver 2016.12 & up)

    Layer stack:
        No impacts

    MeshLab versions:
        2016.12
        1.3.4BETA
Geometric function using muparser lib to generate new Coordinates