Skip to content

Commit 86aed1b

Browse files
use faster point distribution in octree
1 parent dca8c25 commit 86aed1b

File tree

1 file changed

+8
-31
lines changed

1 file changed

+8
-31
lines changed

octreelib/internal/point.py

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,6 @@
2121

2222

2323
class CloudManager:
24-
class Voxel:
25-
def __init__(self, min_corner, edge_length):
26-
self.corner_min = min_corner
27-
self.corner_max = min_corner + edge_length
28-
self.edge_length = edge_length
29-
30-
def is_point_geometrically_inside(self, point: RawPoint) -> bool:
31-
return bool((point >= self.corner_min).all()) and bool(
32-
(point <= self.corner_max).all()
33-
)
34-
3524
def __init__(self):
3625
raise TypeError("This class is not intended to be instantiated")
3726

@@ -72,27 +61,15 @@ def distribute_grid(cls, points, voxel_size, grid_start):
7261
def distribute(
7362
cls, points: RawPointCloud, corner_min, edge_length
7463
) -> List[RawPointCloud]:
75-
# TODO: implement this smarter 🙄
76-
def __generate_children():
77-
child_edge_length = edge_length / np.float_(2)
78-
children_corners_offsets = itertools.product(
79-
[0, child_edge_length], repeat=3
80-
)
81-
return [
82-
CloudManager.Voxel(
83-
corner_min + offset,
84-
child_edge_length,
85-
)
86-
for internal_position, offset in enumerate(children_corners_offsets)
87-
]
88-
8964
clouds = []
9065

91-
for child in __generate_children():
92-
new_cloud = cls.empty()
93-
for point in points:
94-
if child.is_point_geometrically_inside(point):
95-
new_cloud = cls.add(new_cloud, point.reshape((1, 3)))
96-
clouds.append(new_cloud)
66+
for offset in itertools.product([0, edge_length / 2], repeat=3):
67+
child_corner_min = corner_min + np.array(offset)
68+
child_corner_max = child_corner_min + edge_length / 2
69+
mask = np.all(
70+
(points >= child_corner_min) & (points < child_corner_max), axis=1
71+
)
72+
child_points = points[mask]
73+
clouds.append(child_points)
9774

9875
return clouds

0 commit comments

Comments
 (0)