|
21 | 21 |
|
22 | 22 |
|
23 | 23 | 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 |
| - |
35 | 24 | def __init__(self):
|
36 | 25 | raise TypeError("This class is not intended to be instantiated")
|
37 | 26 |
|
@@ -72,27 +61,15 @@ def distribute_grid(cls, points, voxel_size, grid_start):
|
72 | 61 | def distribute(
|
73 | 62 | cls, points: RawPointCloud, corner_min, edge_length
|
74 | 63 | ) -> 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 |
| - |
89 | 64 | clouds = []
|
90 | 65 |
|
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) |
97 | 74 |
|
98 | 75 | return clouds
|
0 commit comments