Skip to content

Commit 97ef3b7

Browse files
committed
using Mixins
1 parent d32a6ea commit 97ef3b7

12 files changed

Lines changed: 645 additions & 270 deletions

File tree

sphedron/__init__.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,27 @@
1010
This software is provided "as is", without warranty of any kind.
1111
"""
1212

13-
from .triangular import Icosphere
14-
from .triangular import Octasphere
15-
from .triangular import NestedIcospheres
16-
from .triangular import NestedOctaspheres
13+
from .mesh import Icosphere
14+
from .mesh import Octasphere
15+
from .mesh import Cubesphere
16+
from .mesh import NodesOnlyMesh
17+
from .mesh import UniformMesh
1718

18-
from .rectangular import Cubesphere
19-
from .rectangular import NestedCubespheres
19+
from .mesh import NestedIcospheres
20+
from .mesh import NestedOctaspheres
21+
from .mesh import NestedCubespheres
2022

21-
from .mesh_transfer import MeshTransfer
23+
from .transfer import MeshTransfer
2224

2325

2426
__all__ = [
2527
"Icosphere",
2628
"Octasphere",
29+
"Cubesphere",
30+
"NodesOnlyMesh",
31+
"UniformMesh",
2732
"NestedIcospheres",
2833
"NestedOctaspheres",
29-
"Cubesphere",
3034
"NestedCubespheres",
3135
"MeshTransfer",
3236
]
Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
This software is provided "as is", without warranty of any kind.
1111
"""
1212

13-
from typing import List
13+
from typing import List, Tuple
1414
from numpy.typing import NDArray
1515
import numpy as np
1616
from scipy.spatial.transform import Rotation
17-
from scipy.spatial import cKDTree # type: ignore
17+
from scipy.spatial import cKDTree # type: ignore
1818

1919

2020
def faces_to_edges(faces: NDArray) -> NDArray:
@@ -42,8 +42,39 @@ def faces_to_edges(faces: NDArray) -> NDArray:
4242
def query_nearest(
4343
references_xyz: NDArray,
4444
nodes_xyz: NDArray,
45-
radius: float = -1.0,
46-
n_neighbors: int = -1,
45+
n_neighbors: int,
46+
) -> Tuple[NDArray, NDArray]:
47+
"""
48+
Find the nearest neighbors for a set of nodes based on given reference
49+
points.
50+
51+
This function returns the indices of the nearest reference neighbors
52+
for each point in `nodes_xyz`. The neighbors can be determined either by
53+
a specified number of neighbors (`n_neighbors`) or by a specified
54+
radius (`radius`). If both parameters are set, the function will
55+
prioritize the radius.
56+
57+
Args:
58+
references_xyz: reference points, shape (N, 3)
59+
nodes_xyz: nodes for which to find nearest neighbors, shape (M, 3)
60+
radius: The radius to consider for finding the neighbors.
61+
n_neighbors: The number of nearest neighbors to return for each node.
62+
63+
Returns:
64+
An array of arrays of indices of the nearest neighbors,
65+
of shape (M, n_neighbors) when n_neighbors is set
66+
"""
67+
68+
distances, indices = cKDTree(references_xyz).query(
69+
x=nodes_xyz, k=n_neighbors, workers=-1
70+
)
71+
return distances, indices
72+
73+
74+
def query_radius(
75+
references_xyz: NDArray,
76+
nodes_xyz: NDArray,
77+
radius: float,
4778
) -> NDArray:
4879
"""
4980
Find the nearest neighbors for a set of nodes based on given reference
@@ -65,22 +96,10 @@ def query_nearest(
6596
An array of arrays of indices of the nearest neighbors,
6697
of shape (M, n_neighbors) when n_neighbors is set
6798
"""
68-
# either n_neighbors or radius should be used but not both
69-
# assert n_neighbors * radius < 0
70-
if radius > 0:
71-
indices = cKDTree(references_xyz).query_ball_point(
72-
x=nodes_xyz, r=radius, workers=-1
73-
)
74-
else:
75-
if n_neighbors < 0:
76-
raise ValueError(
77-
"Either radius or n_neighbors should be provided,"
78-
f"(n_neighbors, radius)=({n_neighbors}, {radius}) "
79-
)
80-
81-
_, indices = cKDTree(references_xyz).query(
82-
x=nodes_xyz, k=n_neighbors, workers=-1
83-
)
99+
100+
indices = cKDTree(references_xyz).query_ball_point(
101+
x=nodes_xyz, r=radius, workers=-1
102+
)
84103
return indices
85104

86105

0 commit comments

Comments
 (0)