meshlabxml/compute.py
def parse_topology(ml_log, log=None, ml_version='1.3.4BETA', print_output=False):
    """Parse the ml_log file generated by the measure_topology function.

    Args:
        ml_log (str): MeshLab log file to parse
        log (str): filename to log output

    Returns:
        dict: dictionary with the following keys:
            vert_num (int): number of vertices
            edge_num (int): number of edges
            face_num (int): number of faces
            unref_vert_num (int): number or unreferenced vertices
            boundry_edge_num (int): number of boundary edges
            part_num (int): number of parts (components) in the mesh.
            manifold (bool): True if mesh is two-manifold, otherwise false.
            non_manifold_edge (int): number of non_manifold edges.
            non_manifold_vert (int): number of non-manifold verices
            genus (int or str): genus of the mesh, either a number or
                'undefined' if the mesh is non-manifold.
            holes (int or str): number of holes in the mesh, either a number
                or 'undefined' if the mesh is non-manifold.

    """
    topology = {'manifold': True, 'non_manifold_E': 0, 'non_manifold_V': 0}
    with open(ml_log) as fread:
        for line in fread:
            if 'V:' in line:
                vert_edge_face = line.replace('V:', ' ').replace('E:', ' ').replace('F:', ' ').split()
                topology['vert_num'] = int(vert_edge_face[0])
                topology['edge_num'] = int(vert_edge_face[1])
                topology['face_num'] = int(vert_edge_face[2])
            if 'Unreferenced Vertices' in line:
                topology['unref_vert_num'] = int(line.split()[2])
            if 'Boundary Edges' in line:
                topology['boundry_edge_num'] = int(line.split()[2])
            if 'Mesh is composed by' in line:
                topology['part_num'] = int(line.split()[4])
            if 'non 2-manifold mesh' in line:
                topology['manifold'] = False
            if 'non two manifold edges' in line:
                topology['non_manifold_edge'] = int(line.split()[2])
            if 'non two manifold vertexes' in line:
                topology['non_manifold_vert'] = int(line.split()[2])
            if 'Genus is' in line:  # undefined or int
                topology['genus'] = line.split()[2]
                if topology['genus'] != 'undefined':
                    topology['genus'] = int(topology['genus'])
            if 'holes' in line:
                topology['hole_num'] = line.split()[2]
                if topology['hole_num'] == 'a':
                    topology['hole_num'] = 'undefined'
                else:
                    topology['hole_num'] = int(topology['hole_num'])
    for key, value in topology.items():
        if log is not None:
            log_file = open(log, 'a')
            log_file.write('{:16} = {}\n'.format(key, value))
            log_file.close()
        elif print_output:
            print('{:16} = {}'.format(key, value))

    return topology
def parse_topology(ml_log, log=None, ml_version='1.3.4BETA', print_output=False):
    topology = {'manifold': True, 'non_manifold_E': 0, 'non_manifold_V': 0}
    with open(ml_log) as fread:
        for line in fread:
            if 'V:' in line:
                vert_edge_face = line.replace('V:', ' ').replace('E:', ' ').replace('F:', ' ').split()
                topology['vert_num'] = int(vert_edge_face[0])
                topology['edge_num'] = int(vert_edge_face[1])
                topology['face_num'] = int(vert_edge_face[2])
            if 'Unreferenced Vertices' in line:
                topology['unref_vert_num'] = int(line.split()[2])
            if 'Boundary Edges' in line:
                topology['boundry_edge_num'] = int(line.split()[2])
            if 'Mesh is composed by' in line:
                topology['part_num'] = int(line.split()[4])
            if 'non 2-manifold mesh' in line:
                topology['manifold'] = False
            if 'non two manifold edges' in line:
                topology['non_manifold_edge'] = int(line.split()[2])
            if 'non two manifold vertexes' in line:
                topology['non_manifold_vert'] = int(line.split()[2])
            if 'Genus is' in line:  # undefined or int
                topology['genus'] = line.split()[2]
                if topology['genus'] != 'undefined':
                    topology['genus'] = int(topology['genus'])
            if 'holes' in line:
                topology['hole_num'] = line.split()[2]
                if topology['hole_num'] == 'a':
                    topology['hole_num'] = 'undefined'
                else:
                    topology['hole_num'] = int(topology['hole_num'])
    for key, value in topology.items():
        if log is not None:
            log_file = open(log, 'a')
            log_file.write('{:16} = {}\n'.format(key, value))
            log_file.close()
        elif print_output:
            print('{:16} = {}'.format(key, value))

    return topology
def parse_topology ( ml_log , log = None , ml_version = '1.3.4BETA' , print_output = False ) : topology = { 'manifold' : True , 'non_manifold_E' : 0 , 'non_manifold_V' : 0 } with open ( ml_log ) as fread : for line in fread : if 'V:' in line : vert_edge_face = line . replace ( 'V:' , ' ' ) . replace ( 'E:' , ' ' ) . replace ( 'F:' , ' ' ) . split ( ) topology [ 'vert_num' ] = int ( vert_edge_face [ 0 ] ) topology [ 'edge_num' ] = int ( vert_edge_face [ 1 ] ) topology [ 'face_num' ] = int ( vert_edge_face [ 2 ] ) if 'Unreferenced Vertices' in line : topology [ 'unref_vert_num' ] = int ( line . split ( ) [ 2 ] ) if 'Boundary Edges' in line : topology [ 'boundry_edge_num' ] = int ( line . split ( ) [ 2 ] ) if 'Mesh is composed by' in line : topology [ 'part_num' ] = int ( line . split ( ) [ 4 ] ) if 'non 2-manifold mesh' in line : topology [ 'manifold' ] = False if 'non two manifold edges' in line : topology [ 'non_manifold_edge' ] = int ( line . split ( ) [ 2 ] ) if 'non two manifold vertexes' in line : topology [ 'non_manifold_vert' ] = int ( line . split ( ) [ 2 ] ) if 'Genus is' in line : # undefined or int topology [ 'genus' ] = line . split ( ) [ 2 ] if topology [ 'genus' ] != 'undefined' : topology [ 'genus' ] = int ( topology [ 'genus' ] ) if 'holes' in line : topology [ 'hole_num' ] = line . split ( ) [ 2 ] if topology [ 'hole_num' ] == 'a' : topology [ 'hole_num' ] = 'undefined' else : topology [ 'hole_num' ] = int ( topology [ 'hole_num' ] ) for key , value in topology . items ( ) : if log is not None : log_file = open ( log , 'a' ) log_file . write ( '{:16} = {}\n' . format ( key , value ) ) log_file . close ( ) elif print_output : print ( '{:16} = {}' . format ( key , value ) ) return topology
Parse the ml_log file generated by the measure_topology function.

    Args:
        ml_log (str): MeshLab log file to parse
        log (str): filename to log output

    Returns:
        dict: dictionary with the following keys:
            vert_num (int): number of vertices
            edge_num (int): number of edges
            face_num (int): number of faces
            unref_vert_num (int): number or unreferenced vertices
            boundry_edge_num (int): number of boundary edges
            part_num (int): number of parts (components) in the mesh.
            manifold (bool): True if mesh is two-manifold, otherwise false.
            non_manifold_edge (int): number of non_manifold edges.
            non_manifold_vert (int): number of non-manifold verices
            genus (int or str): genus of the mesh, either a number or
                'undefined' if the mesh is non-manifold.
            holes (int or str): number of holes in the mesh, either a number
                or 'undefined' if the mesh is non-manifold.
Parse the ml_log file generated by the measure_topology function .