Project points onto (scalp) surface.
(
rrs, surf, project_rrs=False, return_nn=False, method="accurate"
)
| 444 | |
| 445 | |
| 446 | def _project_onto_surface( |
| 447 | rrs, surf, project_rrs=False, return_nn=False, method="accurate" |
| 448 | ): |
| 449 | """Project points onto (scalp) surface.""" |
| 450 | if method == "accurate": |
| 451 | surf_geom = _get_tri_supp_geom(surf) |
| 452 | pt_tris = np.empty((0,), int) |
| 453 | pt_lens = np.zeros(len(rrs) + 1, int) |
| 454 | out = _find_nearest_tri_pts(rrs, pt_tris, pt_lens, reproject=True, **surf_geom) |
| 455 | if project_rrs: # |
| 456 | out += (np.einsum("ij,ijk->ik", out[0], surf["rr"][surf["tris"][out[1]]]),) |
| 457 | if return_nn: |
| 458 | out += (surf_geom["nn"][out[1]],) |
| 459 | else: # nearest neighbor |
| 460 | assert project_rrs |
| 461 | idx = _compute_nearest(surf["rr"], rrs) |
| 462 | out = (None, None, surf["rr"][idx]) |
| 463 | if return_nn: |
| 464 | surf_geom = _get_tri_supp_geom(surf) |
| 465 | nn = _accumulate_normals( |
| 466 | surf["tris"].astype(int), surf_geom["nn"], len(surf["rr"]) |
| 467 | ) |
| 468 | nn = nn[idx] |
| 469 | _normalize_vectors(nn) |
| 470 | out += (nn,) |
| 471 | return out |
| 472 | |
| 473 | |
| 474 | def _normal_orth(nn): |