11from typing import List
22
33import numpy as np
4- import tqdm
54from napari .types import LayerDataTuple , SurfaceData
65from napari_tools_menu import register_function
76
87from .._utils .frame_by_frame import frame_by_frame
98
109
11- def geodesic_distance_matrix (
12- surface : SurfaceData , show_progress : bool = False
13- ) -> np .ndarray :
10+ def geodesic_distance_matrix (surface : SurfaceData ) -> np .ndarray :
1411 """
1512 Calculate a pairwise distance matrix for vertices of a surface.
1613
@@ -28,27 +25,16 @@ def geodesic_distance_matrix(
2825 at `distance_matrix[i, j]`
2926
3027 """
31- from pygeodesic import geodesic
28+ import gdist
29+ from .._utils import sanitize_faces
3230
33- geoalg = geodesic .PyGeodesicAlgorithmExact (surface [0 ], surface [1 ])
31+ # Reorder the faces of the surface to ensure consistent orientation
32+ sanitized_surface = sanitize_faces (surface )
33+ vertices = sanitized_surface [0 ]
34+ faces = sanitized_surface [1 ]
3435
35- n_points = len (surface [0 ])
36- distance_matrix = np .zeros ((n_points , n_points ))
37- points = surface [0 ]
38-
39- if show_progress :
40- iterator = tqdm .tqdm (
41- enumerate (points ), desc = "Calculating geodesic distances"
42- )
43- else :
44- iterator = enumerate (points )
45-
46- for idx , pt in iterator :
47- distances , _ = geoalg .geodesicDistances (
48- [idx ], np .arange (idx + 1 , n_points )
49- )
50- distance_matrix [idx , idx + 1 :] = distances
51- distance_matrix [idx + 1 :, idx ] = distances
36+ distance_matrix = gdist .local_gdist_matrix (
37+ vertices , faces , max_distance = 1e9 ).toarray ()
5238
5339 return distance_matrix
5440
@@ -77,10 +63,15 @@ def geodesic_path(
7763 coordinates, the second dimension is the vector from point to point.
7864
7965 """
80- from pygeodesic import geodesic
66+ import potpourri3d as pp3d
67+ from .._utils import sanitize_faces
8168
82- geoalg = geodesic .PyGeodesicAlgorithmExact (surface [0 ], surface [1 ])
83- distances , path = geoalg .geodesicDistance (index_1 , index_2 )
69+ sanitized_surface = sanitize_faces (surface )
70+ vertices = sanitized_surface [0 ]
71+ faces = sanitized_surface [1 ]
72+
73+ path_solver = pp3d .EdgeFlipGeodesicSolver (vertices , faces )
74+ path = path_solver .find_geodesic_path (index_1 , index_2 )
8475
8576 # convert points to vectors from point to point
8677 vectors = []
@@ -240,8 +231,10 @@ def local_extrema_analysis(
240231 - `min_max_pair_distances`: Distances between all pairs of local minima and maxima.
241232 - `min_max_pair_anisotropies`: Difference in input value `(vertices, faces, values)` between all pairs of local minima and maxima.
242233 """
243- triangles = surface [ 1 ]
234+ from .. _utils import sanitize_faces
244235 feature = surface [2 ]
236+ surface = sanitize_faces (surface )
237+ triangles = surface [1 ]
245238
246239 quad_fit = len (feature )
247240
0 commit comments