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
)
| 486 | |
| 487 | @verbose |
| 488 | def 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: |
no test coverage detected