def _ico_downsample(surf, dest_grade):
 n_tri = surf['ntri']
 found = (-1)
 bad_msg = ('A surface with %d triangles cannot be isomorphic with a subdivided icosahedron.' % surf['ntri'])
 if ((n_tri % 20) != 0):
  raise RuntimeError(bad_msg)
 n_tri = (n_tri // 20)
 found = int(round((np.log(n_tri) / np.log(4))))
 if (n_tri != (4 ** found)):
  raise RuntimeError(bad_msg)
 del n_tri
 if (dest_grade > found):
  raise RuntimeError(('For this surface, decimation grade should be %d or less, not %s.' % (found, dest_grade)))
 source = _get_ico_surface(found)
 dest = _get_ico_surface(dest_grade, patch_stats=True)
 del dest['tri_cent']
 del dest['tri_nn']
 del dest['neighbor_tri']
 del dest['tri_area']
 if (not np.array_equal(source['tris'], surf['tris'])):
  raise RuntimeError('The source surface has a matching number of triangles but ordering is wrong')
 logger.info(('Going from %dth to %dth subdivision of an icosahedron (n_tri: %d -> %d)' % (found, dest_grade, surf['ntri'], dest['ntri'])))
 dest['rr'] = surf['rr'][_get_ico_map(source, dest)]
 return dest

def _ico_downsample ( surf , dest_grade ) : n_tri = surf [ 'ntri' ] found = ( - 1 ) bad_msg = ( 'A surface with %d triangles cannot be isomorphic with a subdivided icosahedron.' % surf [ 'ntri' ] ) if ( ( n_tri % 20 ) != 0 ) : raise RuntimeError ( bad_msg ) n_tri = ( n_tri // 20 ) found = int ( round ( ( np . log ( n_tri ) / np . log ( 4 ) ) ) ) if ( n_tri != ( 4 ** found ) ) : raise RuntimeError ( bad_msg ) del n_tri if ( dest_grade > found ) : raise RuntimeError ( ( 'For this surface, decimation grade should be %d or less, not %s.' % ( found , dest_grade ) ) ) source = _get_ico_surface ( found ) dest = _get_ico_surface ( dest_grade , patch_stats = True ) del dest [ 'tri_cent' ] del dest [ 'tri_nn' ] del dest [ 'neighbor_tri' ] del dest [ 'tri_area' ] if ( not np . array_equal ( source [ 'tris' ] , surf [ 'tris' ] ) ) : raise RuntimeError ( 'The source surface has a matching number of triangles but ordering is wrong' ) logger . info ( ( 'Going from %dth to %dth subdivision of an icosahedron (n_tri: %d -> %d)' % ( found , dest_grade , surf [ 'ntri' ] , dest [ 'ntri' ] ) ) ) dest [ 'rr' ] = surf [ 'rr' ] [ _get_ico_map ( source , dest ) ] return dest
downsample the surface if isomorphic to a subdivided icosahedron .