[voxelize] correct include_outside=True indexing
This commit is contained in:
parent
1999b24b0c
commit
4ec8f5d414
2 changed files with 17 additions and 3 deletions
|
|
@ -47,6 +47,19 @@ def test_voxelization(poly_order: int, grid_resolution: int | None = None) -> No
|
||||||
warnings.warn('Moments failed tolerance in voxels', stacklevel=1)
|
warnings.warn('Moments failed tolerance in voxels', stacklevel=1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_voxelization_include_outside_keeps_axis_assignment() -> None:
|
||||||
|
poly = adze.build_box([[-1, 0, 0], [2, 1, 1]])
|
||||||
|
edges = [numpy.array([0.0, 1.0]) for _ in range(3)]
|
||||||
|
|
||||||
|
grid = adze.voxelize(poly, edges, include_outside=True, order=0)
|
||||||
|
voxels = grid[..., 0]
|
||||||
|
|
||||||
|
assert voxels.shape == (3, 3, 3)
|
||||||
|
assert_allclose(voxels.sum(axis=(1, 2)), [1.0, 1.0, 1.0])
|
||||||
|
assert_allclose(voxels.sum(axis=(0, 2)), [0.0, 3.0, 0.0])
|
||||||
|
assert_allclose(voxels.sum(axis=(0, 1)), [0.0, 3.0, 0.0])
|
||||||
|
|
||||||
|
|
||||||
def visualize_isosurface(
|
def visualize_isosurface(
|
||||||
grid: NDArray[numpy.float64],
|
grid: NDArray[numpy.float64],
|
||||||
edges: NDArray[numpy.int64],
|
edges: NDArray[numpy.int64],
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,10 @@ def voxelize(
|
||||||
|
|
||||||
if include_outside:
|
if include_outside:
|
||||||
grid_shape = num_planes + 1
|
grid_shape = num_planes + 1
|
||||||
if not include_outside:
|
grid_offset = 0
|
||||||
|
else:
|
||||||
grid_shape = num_planes - 1
|
grid_shape = num_planes - 1
|
||||||
|
grid_offset = -1
|
||||||
for face in planes_from_box([[p[0] for p in aplanes],
|
for face in planes_from_box([[p[0] for p in aplanes],
|
||||||
[p[-1] for p in aplanes]]):
|
[p[-1] for p in aplanes]]):
|
||||||
poly = clip(poly, face)
|
poly = clip(poly, face)
|
||||||
|
|
@ -75,7 +77,7 @@ def voxelize(
|
||||||
# Base case 2: calculate moments for single voxel
|
# Base case 2: calculate moments for single voxel
|
||||||
if not num_planes_remaining.any():
|
if not num_planes_remaining.any():
|
||||||
moments = get_moments(poly, order)
|
moments = get_moments(poly, order)
|
||||||
i, j, k = slices[:, 0] - 1
|
i, j, k = slices[:, 0] + grid_offset
|
||||||
grid[i, j, k, :] = moments
|
grid[i, j, k, :] = moments
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
@ -95,4 +97,3 @@ def voxelize(
|
||||||
stack.append((poly_left, slices_left))
|
stack.append((poly_left, slices_left))
|
||||||
stack.append((poly_right, slices_right))
|
stack.append((poly_right, slices_right))
|
||||||
return grid
|
return grid
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue