make surface_nets generic enough to take TransformMap<Array3> as input
@@ -69,8 +69,9 @@ impl SurfaceNetsBuffer {
///
/// The set of corners sampled is exactly the set of points in `extent`. `sdf` must contain all of
/// those points.
-pub fn surface_nets<T>(sdf: &Array3<T>, extent: &Extent3i, output: &mut SurfaceNetsBuffer)
+pub fn surface_nets<V, T>(sdf: &V, extent: &Extent3i, output: &mut SurfaceNetsBuffer)
where
+ V: Array<[i32; 3]> + GetUncheckedRefRelease<Stride, T>,
T: SignedDistance,
{
output.reset(sdf.extent().num_points());
@@ -81,8 +82,9 @@ where
// Find all vertex positions and normals. Also generate a map from grid position to vertex index
// to be used to look up vertices when generating quads.
-fn estimate_surface<T>(sdf: &Array3<T>, extent: &Extent3i, output: &mut SurfaceNetsBuffer)
+fn estimate_surface<V, T>(sdf: &V, extent: &Extent3i, output: &mut SurfaceNetsBuffer)
where
+ V: Array<[i32; 3]> + GetUncheckedRefRelease<Stride, T>,
T: SignedDistance,
{
// Precalculate these offsets to do faster linear indexing.
@@ -130,12 +132,13 @@ const CUBE_EDGES: [(usize, usize); 12] = [
//
// This is done by estimating, for each cube edge, where the isosurface crosses the edge (if it
// does at all). Then the estimated surface point is the average of these edge crossings.
-fn estimate_surface_in_voxel<T>(
- sdf: &Array3<T>,
+fn estimate_surface_in_voxel<V, T>(
+ sdf: &V,
point: &Point3i,
corner_strides: &[Stride],
) -> Option<([f32; 3], [f32; 3])>
where
+ V: GetUncheckedRefRelease<Stride, T>,
T: SignedDistance,
{
// Get the signed distance values at each corner of this cube.
@@ -213,8 +216,9 @@ fn estimate_surface_edge_intersection(
// touching that surface. The "centers" are actually the vertex positions found earlier. Also,
// make sure the triangles are facing the right way. See the comments on `maybe_make_quad` to help
// with understanding the indexing.
-fn make_all_quads<T>(sdf: &Array3<T>, extent: &Extent3i, output: &mut SurfaceNetsBuffer)
+fn make_all_quads<V, T>(sdf: &V, extent: &Extent3i, output: &mut SurfaceNetsBuffer)
where
+ V: Array<[i32; 3]> + GetUncheckedRefRelease<Stride, T>,
T: SignedDistance,
{
let mut xyz_strides = [Stride(0); 3];
@@ -307,8 +311,8 @@ where
// then we must find the other 3 quad corners by moving along the other two axes (those orthogonal
// to A) in the negative directions; these are axis B and axis C.
#[allow(clippy::too_many_arguments)]
-fn maybe_make_quad<T>(
- sdf: &Array3<T>,
+fn maybe_make_quad<V, T>(
+ sdf: &V,
stride_to_index: &[usize],
positions: &[[f32; 3]],
p1: Stride,
@@ -317,6 +321,7 @@ fn maybe_make_quad<T>(
axis_c_stride: Stride,
indices: &mut Vec<usize>,
) where
+ V: GetUncheckedRefRelease<Stride, T>,
T: SignedDistance,
{
let voxel1 = sdf.get_unchecked_ref_release(p1);
