From a89899150c4bdf9d877f51b391483faae3981cb3 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Sat, 20 Jul 2024 07:56:15 +1000 Subject: [PATCH] speed up join close components --- .gitignore | 3 +++ kimimaro/postprocess.py | 14 +++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 4d08e2b..8769af1 100644 --- a/.gitignore +++ b/.gitignore @@ -106,4 +106,7 @@ venv.bak/ test.py .DS_Store +# Itelli J +.idea/ + ext/skeletontricks/skeletontricks.cpp diff --git a/kimimaro/postprocess.py b/kimimaro/postprocess.py index a66cf0f..edb23a7 100644 --- a/kimimaro/postprocess.py +++ b/kimimaro/postprocess.py @@ -107,15 +107,11 @@ def join_close_components(skeletons, radius=None): while len(skels) > 1: N = len(skels) - radii_matrix = np.zeros( (N, N), dtype=np.float32 ) + np.inf - index_matrix = np.zeros( (N, N, 2), dtype=np.uint32 ) + -1 - - for i in range(len(skels)): - for j in range(len(skels)): - if i == j: - continue - elif radii_matrix[i,j] != np.inf: - continue + radii_matrix = np.full( (N, N), np.inf, dtype=np.float32 ) + index_matrix = np.full( (N, N, 2), -1, dtype=np.uint32 ) + + for i in range(N): + for j in range(i + 1, N): # compute upper triangle only s1, s2 = skels[i], skels[j] dist_matrix = scipy.spatial.distance.cdist(s1.vertices, s2.vertices)