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

Function _find_nearest_tri_pts

mne/surface.py:1637–1731  ·  view source on GitHub ↗

Find nearest point mapping to a set of triangles. If run_all is False, if the point lies within a triangle, it stops. If run_all is True, edges of other triangles are checked in case those (somehow) are closer.

(
    rrs,
    pt_triss,
    pt_lens,
    a,
    b,
    c,
    nn,
    r1,
    r12,
    r13,
    r1213,
    mat,
    run_all=True,
    reproject=False,
)

Source from the content-addressed store, hash-verified

1635
1636@jit(parallel=True)
1637def _find_nearest_tri_pts(
1638 rrs,
1639 pt_triss,
1640 pt_lens,
1641 a,
1642 b,
1643 c,
1644 nn,
1645 r1,
1646 r12,
1647 r13,
1648 r1213,
1649 mat,
1650 run_all=True,
1651 reproject=False,
1652): # pragma: no cover
1653 """Find nearest point mapping to a set of triangles.
1654
1655 If run_all is False, if the point lies within a triangle, it stops.
1656 If run_all is True, edges of other triangles are checked in case
1657 those (somehow) are closer.
1658 """
1659 # The following dense code is equivalent to the following:
1660 # rr = r1[pt_tris] - to_pts[ii]
1661 # v1s = np.sum(rr * r12[pt_tris], axis=1)
1662 # v2s = np.sum(rr * r13[pt_tris], axis=1)
1663 # aas = a[pt_tris]
1664 # bbs = b[pt_tris]
1665 # ccs = c[pt_tris]
1666 # dets = aas * bbs - ccs * ccs
1667 # pp = (bbs * v1s - ccs * v2s) / dets
1668 # qq = (aas * v2s - ccs * v1s) / dets
1669 # pqs = np.array(pp, qq)
1670
1671 weights = np.empty((len(rrs), 3))
1672 tri_idx = np.empty(len(rrs), np.int64)
1673 for ri in prange(len(rrs)):
1674 rr = np.reshape(rrs[ri], (1, 3))
1675 start, stop = pt_lens[ri : ri + 2]
1676 if start == stop == 0: # use all
1677 drs = rr - r1
1678 tri_nn = nn
1679 mats = mat
1680 r1213s = r1213
1681 reindex = False
1682 else:
1683 pt_tris = pt_triss[start:stop]
1684 drs = rr - r1[pt_tris]
1685 tri_nn = nn[pt_tris]
1686 mats = mat[pt_tris]
1687 r1213s = r1213[pt_tris]
1688 reindex = True
1689 use = np.ones(len(drs), np.int64)
1690 pqs = np.empty((len(drs), 2))
1691 dists = np.empty(len(drs))
1692 dist = np.inf
1693 # make life easier for numba var typing
1694 p, q, pt = np.float64(0.0), np.float64(1.0), np.int64(0)

Callers 2

_make_morph_map_hemiFunction · 0.85
_project_onto_surfaceFunction · 0.85

Calls 2

_nearest_tri_edgeFunction · 0.85
_triangle_coordsFunction · 0.85

Tested by

no test coverage detected