MCPcopy
hub / github.com/mne-tools/mne-python / complete_surface_info

Function complete_surface_info

mne/surface.py:488–567  ·  view source on GitHub ↗

Complete surface information. Parameters ---------- surf : dict The surface. do_neighbor_vert : bool If True (default False), add neighbor vertex information. copy : bool If True (default), make a copy. If False, operate in-place. do_neighbor_tri : bo

(
    surf, do_neighbor_vert=False, copy=True, do_neighbor_tri=True, *, verbose=None
)

Source from the content-addressed store, hash-verified

486
487@verbose
488def complete_surface_info(
489 surf, do_neighbor_vert=False, copy=True, do_neighbor_tri=True, *, verbose=None
490):
491 """Complete surface information.
492
493 Parameters
494 ----------
495 surf : dict
496 The surface.
497 do_neighbor_vert : bool
498 If True (default False), add neighbor vertex information.
499 copy : bool
500 If True (default), make a copy. If False, operate in-place.
501 do_neighbor_tri : bool
502 If True (default), compute triangle neighbors.
503 %(verbose)s
504
505 Returns
506 -------
507 surf : dict
508 The transformed surface.
509 """
510 if copy:
511 surf = deepcopy(surf)
512 # based on mne_source_space_add_geometry_info() in mne_add_geometry_info.c
513
514 # Main triangulation [mne_add_triangle_data()]
515 surf["ntri"] = surf.get("ntri", len(surf["tris"]))
516 surf["np"] = surf.get("np", len(surf["rr"]))
517 surf["tri_area"] = np.zeros(surf["ntri"])
518 r1 = surf["rr"][surf["tris"][:, 0], :]
519 r2 = surf["rr"][surf["tris"][:, 1], :]
520 r3 = surf["rr"][surf["tris"][:, 2], :]
521 surf["tri_cent"] = (r1 + r2 + r3) / 3.0
522 surf["tri_nn"] = fast_cross_3d((r2 - r1), (r3 - r1))
523
524 # Triangle normals and areas
525 surf["tri_area"] = _normalize_vectors(surf["tri_nn"]) / 2.0
526 zidx = np.where(surf["tri_area"] == 0)[0]
527 if len(zidx) > 0:
528 logger.info(f" Warning: zero size triangles: {zidx}")
529
530 # Find neighboring triangles, accumulate vertex normals, normalize
531 logger.info(" Triangle neighbors and vertex normals...")
532 surf["nn"] = _accumulate_normals(
533 surf["tris"].astype(int), surf["tri_nn"], surf["np"]
534 )
535 _normalize_vectors(surf["nn"])
536
537 # Check for topological defects
538 if do_neighbor_tri:
539 surf["neighbor_tri"] = _triangle_neighbors(surf["tris"], surf["np"])
540 zero, fewer = list(), list()
541 for ni, n in enumerate(surf["neighbor_tri"]):
542 if len(n) < 3:
543 if len(n) == 0:
544 zero.append(ni)
545 else:

Callers 11

_read_surfaceFunction · 0.85
_setup_bemMethod · 0.85
compute_areaMethod · 0.85
_check_complete_surfaceFunction · 0.85
get_meg_helmet_surfFunction · 0.85
_scale_helmet_to_sensorsFunction · 0.85
_create_surf_spacingFunction · 0.85
_complete_sphere_surfFunction · 0.85
morph_source_spacesFunction · 0.85
load_geometryMethod · 0.85

Calls 7

fast_cross_3dFunction · 0.85
_normalize_vectorsFunction · 0.85
_accumulate_normalsFunction · 0.85
_triangle_neighborsFunction · 0.85
_get_surf_neighborsFunction · 0.85
infoMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected