mostly comments, but broke something
This commit is contained in:
parent
fc82bc255c
commit
3f8b9bef06
1 changed files with 366 additions and 127 deletions
|
|
@ -1,5 +1,7 @@
|
|||
from typing import Tuple
|
||||
import numpy
|
||||
|
||||
from . import poly_t, plane_t
|
||||
from .split import split
|
||||
from .moments import get_moments, number_of_moments
|
||||
|
||||
|
|
@ -12,12 +14,21 @@ except NameError:
|
|||
|
||||
|
||||
@profile
|
||||
def voxelize(poly, d, box=None, poly_order=0):
|
||||
def voxelize(poly: poly_t,
|
||||
d: numpy.ndarray,
|
||||
box: numpy.ndarray = None,
|
||||
order: int = 0
|
||||
) -> numpy.ndarray:
|
||||
'''
|
||||
Voxelize a Schelegel-representation polyhedron
|
||||
|
||||
|
||||
'''
|
||||
box = get_box(poly, d) if box is None else numpy.array(box, dtype=int)
|
||||
d = numpy.array(d)
|
||||
|
||||
grid_shape = box[1] - box[0]
|
||||
dest_grid = numpy.zeros((*grid_shape, number_of_moments(poly_order)), dtype=float)
|
||||
dest_grid = numpy.zeros((*grid_shape, number_of_moments(order)), dtype=float)
|
||||
|
||||
if poly is None or poly['vertices'].shape[0] == 0 or (grid_shape <= 0).any():
|
||||
return dest_grid
|
||||
|
|
@ -37,7 +48,7 @@ def voxelize(poly, d, box=None, poly_order=0):
|
|||
|
||||
# Base case 2: calculate moments for single voxel
|
||||
if max_dist == 1:
|
||||
moments = get_moments(c_poly, poly_order)
|
||||
moments = get_moments(c_poly, order)
|
||||
offset = (c_box[0] - box[0])
|
||||
dest_grid[offset[0], offset[1], offset[2], :] += moments
|
||||
continue
|
||||
|
|
@ -59,13 +70,17 @@ def voxelize(poly, d, box=None, poly_order=0):
|
|||
return dest_grid
|
||||
|
||||
|
||||
def get_box(poly, d):
|
||||
def get_box(poly: poly_t, d: numpy.ndarray) -> numpy.ndarray:
|
||||
min_box = numpy.floor(numpy.min(poly['vertices'], axis=0) / d)
|
||||
max_box = numpy.ceil(numpy.max(poly['vertices'], axis=0) / d)
|
||||
return numpy.array((min_box, max_box), dtype=int)
|
||||
|
||||
|
||||
def clamp_box(poly, box, clampbox, d):
|
||||
def clamp_box(poly: poly_t,
|
||||
box: numpy.ndarray,
|
||||
clampbox: numpy.ndarray,
|
||||
d: numpy.ndarray
|
||||
) -> Tuple[poly_t, numpy.ndarray]:
|
||||
faces = box_faces_from_verts(clampbox)
|
||||
for face in faces:
|
||||
poly = clip(poly, face)
|
||||
|
|
|
|||
Loading…
Reference in a new issue