meshlabxml/compute.py
def parse_geometry(ml_log, log=None, ml_version='2016.12', print_output=False):
    """Parse the ml_log file generated by the measure_geometry function.

    Warnings: Not all keys may exist if mesh is not watertight or manifold

    Args:
        ml_log (str): MeshLab log file to parse
        log (str): filename to log output
    """
    # TODO: read more than one occurrence per file. Record in list.
    aabb = {}
    geometry = {'aabb':aabb}
    with open(ml_log) as fread:
        for line in fread:
            if 'Mesh Bounding Box min' in line: #2016.12
                geometry['aabb']['min'] = (line.split()[4:7])
                geometry['aabb']['min'] = [util.to_float(val) for val in geometry['aabb']['min']]
            if 'Mesh Bounding Box max' in line: #2016.12
                geometry['aabb']['max'] = (line.split()[4:7])
                geometry['aabb']['max'] = [util.to_float(val) for val in geometry['aabb']['max']]
            if 'Mesh Bounding Box Size' in line: #2016.12
                geometry['aabb']['size'] = (line.split()[4:7])
                geometry['aabb']['size'] = [util.to_float(val) for val in geometry['aabb']['size']]
            if 'Mesh Bounding Box Diag' in line: #2016.12
                geometry['aabb']['diagonal'] = util.to_float(line.split()[4])
            if 'Mesh Volume' in line:
                geometry['volume_mm3'] = util.to_float(line.split()[3])
                geometry['volume_cm3'] = geometry['volume_mm3'] * 0.001
            if 'Mesh Surface' in line:
                if ml_version == '1.3.4BETA':
                    geometry['area_mm2'] = util.to_float(line.split()[3])
                else:
                    geometry['area_mm2'] = util.to_float(line.split()[4])
                geometry['area_cm2'] = geometry['area_mm2'] * 0.01
            if 'Mesh Total Len of' in line:
                if 'including faux edges' in line:
                    geometry['total_edge_length_incl_faux'] = util.to_float(
                        line.split()[7])
                else:
                    geometry['total_edge_length'] = util.to_float(
                        line.split()[7])
            if 'Thin shell barycenter' in line:
                geometry['barycenter'] = (line.split()[3:6])
                geometry['barycenter'] = [util.to_float(val) for val in geometry['barycenter']]
            if 'Thin shell (faces) barycenter' in line: #2016.12
                geometry['barycenter'] = (line.split()[4:7])
                geometry['barycenter'] = [util.to_float(val) for val in geometry['barycenter']]
            if 'Vertices barycenter' in line: #2016.12
                geometry['vert_barycenter'] = (line.split()[2:5])
                geometry['vert_barycenter'] = [util.to_float(val) for val in geometry['vert_barycenter']]
            if 'Center of Mass' in line:
                geometry['center_of_mass'] = (line.split()[4:7])
                geometry['center_of_mass'] = [util.to_float(val) for val in geometry['center_of_mass']]
            if 'Inertia Tensor' in line:
                geometry['inertia_tensor'] = []
                for val in range(3):
                    row = (next(fread, val).split()[1:4])
                    row = [util.to_float(b) for b in row]
                    geometry['inertia_tensor'].append(row)
            if 'Principal axes' in line:
                geometry['principal_axes'] = []
                for val in range(3):
                    row = (next(fread, val).split()[1:4])
                    row = [util.to_float(b) for b in row]
                    geometry['principal_axes'].append(row)
            if 'axis momenta' in line:
                geometry['axis_momenta'] = (next(fread).split()[1:4])
                geometry['axis_momenta'] = [util.to_float(val) for val in geometry['axis_momenta']]
                break  # stop after we find the first match
    for key, value in geometry.items():
        if log is not None:
            log_file = open(log, 'a')
            log_file.write('{:27} = {}\n'.format(key, value))
            log_file.close()
        elif print_output:
            print('{:27} = {}'.format(key, value))
    return geometry
def parse_geometry(ml_log, log=None, ml_version='2016.12', print_output=False):
    """Parse the ml_log file generated by the measure_geometry function.

    Warnings: Not all keys may exist if mesh is not watertight or manifold

    Args:
        ml_log (str): MeshLab log file to parse
        log (str): filename to log output
    """
    # TODO: read more than one occurrence per file. Record in list.
    aabb = {}
    geometry = {'aabb':aabb}
    with open(ml_log) as fread:
        for line in fread:
            if 'Mesh Bounding Box min' in line: #2016.12
                geometry['aabb']['min'] = (line.split()[4:7])
                geometry['aabb']['min'] = [util.to_float(val) for val in geometry['aabb']['min']]
            if 'Mesh Bounding Box max' in line: #2016.12
                geometry['aabb']['max'] = (line.split()[4:7])
                geometry['aabb']['max'] = [util.to_float(val) for val in geometry['aabb']['max']]
            if 'Mesh Bounding Box Size' in line: #2016.12
                geometry['aabb']['size'] = (line.split()[4:7])
                geometry['aabb']['size'] = [util.to_float(val) for val in geometry['aabb']['size']]
            if 'Mesh Bounding Box Diag' in line: #2016.12
                geometry['aabb']['diagonal'] = util.to_float(line.split()[4])
            if 'Mesh Volume' in line:
                geometry['volume_mm3'] = util.to_float(line.split()[3])
                geometry['volume_cm3'] = geometry['volume_mm3'] * 0.001
            if 'Mesh Surface' in line:
                if ml_version == '1.3.4BETA':
                    geometry['area_mm2'] = util.to_float(line.split()[3])
                else:
                    geometry['area_mm2'] = util.to_float(line.split()[4])
                geometry['area_cm2'] = geometry['area_mm2'] * 0.01
            if 'Mesh Total Len of' in line:
                if 'including faux edges' in line:
                    geometry['total_edge_length_incl_faux'] = util.to_float(
                        line.split()[7])
                else:
                    geometry['total_edge_length'] = util.to_float(
                        line.split()[7])
            if 'Thin shell barycenter' in line:
                geometry['barycenter'] = (line.split()[3:6])
                geometry['barycenter'] = [util.to_float(val) for val in geometry['barycenter']]
            if 'Thin shell (faces) barycenter' in line: #2016.12
                geometry['barycenter'] = (line.split()[4:7])
                geometry['barycenter'] = [util.to_float(val) for val in geometry['barycenter']]
            if 'Vertices barycenter' in line: #2016.12
                geometry['vert_barycenter'] = (line.split()[2:5])
                geometry['vert_barycenter'] = [util.to_float(val) for val in geometry['vert_barycenter']]
            if 'Center of Mass' in line:
                geometry['center_of_mass'] = (line.split()[4:7])
                geometry['center_of_mass'] = [util.to_float(val) for val in geometry['center_of_mass']]
            if 'Inertia Tensor' in line:
                geometry['inertia_tensor'] = []
                for val in range(3):
                    row = (next(fread, val).split()[1:4])
                    row = [util.to_float(b) for b in row]
                    geometry['inertia_tensor'].append(row)
            if 'Principal axes' in line:
                geometry['principal_axes'] = []
                for val in range(3):
                    row = (next(fread, val).split()[1:4])
                    row = [util.to_float(b) for b in row]
                    geometry['principal_axes'].append(row)
            if 'axis momenta' in line:
                geometry['axis_momenta'] = (next(fread).split()[1:4])
                geometry['axis_momenta'] = [util.to_float(val) for val in geometry['axis_momenta']]
                break  # stop after we find the first match
    for key, value in geometry.items():
        if log is not None:
            log_file = open(log, 'a')
            log_file.write('{:27} = {}\n'.format(key, value))
            log_file.close()
        elif print_output:
            print('{:27} = {}'.format(key, value))
    return geometry
def parse_geometry ( ml_log , log = None , ml_version = '2016.12' , print_output = False ) : # TODO: read more than one occurrence per file. Record in list. aabb = { } geometry = { 'aabb' : aabb } with open ( ml_log ) as fread : for line in fread : if 'Mesh Bounding Box min' in line : #2016.12 geometry [ 'aabb' ] [ 'min' ] = ( line . split ( ) [ 4 : 7 ] ) geometry [ 'aabb' ] [ 'min' ] = [ util . to_float ( val ) for val in geometry [ 'aabb' ] [ 'min' ] ] if 'Mesh Bounding Box max' in line : #2016.12 geometry [ 'aabb' ] [ 'max' ] = ( line . split ( ) [ 4 : 7 ] ) geometry [ 'aabb' ] [ 'max' ] = [ util . to_float ( val ) for val in geometry [ 'aabb' ] [ 'max' ] ] if 'Mesh Bounding Box Size' in line : #2016.12 geometry [ 'aabb' ] [ 'size' ] = ( line . split ( ) [ 4 : 7 ] ) geometry [ 'aabb' ] [ 'size' ] = [ util . to_float ( val ) for val in geometry [ 'aabb' ] [ 'size' ] ] if 'Mesh Bounding Box Diag' in line : #2016.12 geometry [ 'aabb' ] [ 'diagonal' ] = util . to_float ( line . split ( ) [ 4 ] ) if 'Mesh Volume' in line : geometry [ 'volume_mm3' ] = util . to_float ( line . split ( ) [ 3 ] ) geometry [ 'volume_cm3' ] = geometry [ 'volume_mm3' ] * 0.001 if 'Mesh Surface' in line : if ml_version == '1.3.4BETA' : geometry [ 'area_mm2' ] = util . to_float ( line . split ( ) [ 3 ] ) else : geometry [ 'area_mm2' ] = util . to_float ( line . split ( ) [ 4 ] ) geometry [ 'area_cm2' ] = geometry [ 'area_mm2' ] * 0.01 if 'Mesh Total Len of' in line : if 'including faux edges' in line : geometry [ 'total_edge_length_incl_faux' ] = util . to_float ( line . split ( ) [ 7 ] ) else : geometry [ 'total_edge_length' ] = util . to_float ( line . split ( ) [ 7 ] ) if 'Thin shell barycenter' in line : geometry [ 'barycenter' ] = ( line . split ( ) [ 3 : 6 ] ) geometry [ 'barycenter' ] = [ util . to_float ( val ) for val in geometry [ 'barycenter' ] ] if 'Thin shell (faces) barycenter' in line : #2016.12 geometry [ 'barycenter' ] = ( line . split ( ) [ 4 : 7 ] ) geometry [ 'barycenter' ] = [ util . to_float ( val ) for val in geometry [ 'barycenter' ] ] if 'Vertices barycenter' in line : #2016.12 geometry [ 'vert_barycenter' ] = ( line . split ( ) [ 2 : 5 ] ) geometry [ 'vert_barycenter' ] = [ util . to_float ( val ) for val in geometry [ 'vert_barycenter' ] ] if 'Center of Mass' in line : geometry [ 'center_of_mass' ] = ( line . split ( ) [ 4 : 7 ] ) geometry [ 'center_of_mass' ] = [ util . to_float ( val ) for val in geometry [ 'center_of_mass' ] ] if 'Inertia Tensor' in line : geometry [ 'inertia_tensor' ] = [ ] for val in range ( 3 ) : row = ( next ( fread , val ) . split ( ) [ 1 : 4 ] ) row = [ util . to_float ( b ) for b in row ] geometry [ 'inertia_tensor' ] . append ( row ) if 'Principal axes' in line : geometry [ 'principal_axes' ] = [ ] for val in range ( 3 ) : row = ( next ( fread , val ) . split ( ) [ 1 : 4 ] ) row = [ util . to_float ( b ) for b in row ] geometry [ 'principal_axes' ] . append ( row ) if 'axis momenta' in line : geometry [ 'axis_momenta' ] = ( next ( fread ) . split ( ) [ 1 : 4 ] ) geometry [ 'axis_momenta' ] = [ util . to_float ( val ) for val in geometry [ 'axis_momenta' ] ] break # stop after we find the first match for key , value in geometry . items ( ) : if log is not None : log_file = open ( log , 'a' ) log_file . write ( '{:27} = {}\n' . format ( key , value ) ) log_file . close ( ) elif print_output : print ( '{:27} = {}' . format ( key , value ) ) return geometry
Parse the ml_log file generated by the measure_geometry function.

    Warnings: Not all keys may exist if mesh is not watertight or manifold

    Args:
        ml_log (str): MeshLab log file to parse
        log (str): filename to log output
Parse the ml_log file generated by the measure_geometry function .