@@ -17,7 +17,7 @@ use crate::marching_cubes_impl::{get_offset, interpolate, march_cube};
1717use crate :: marching_cubes_tables:: EDGE_CONNECTION ;
1818use crate :: math:: Vec3 ;
1919use crate :: morton:: Morton ;
20- use crate :: source:: { HermiteSource , Source } ;
20+ use crate :: source:: { HermiteSource , Norm , Source } ;
2121use std:: collections:: HashMap ;
2222
2323// Morton cube corners are ordered differently to the marching cubes tables, so remap them to match.
@@ -43,15 +43,29 @@ impl Edge {
4343/// Extracts meshes from distance fields using marching cubes over a linear hashed octree.
4444pub struct LinearHashedMarchingCubes {
4545 max_depth : usize ,
46+ norm : Norm ,
4647}
4748
4849impl LinearHashedMarchingCubes {
4950 /// Create a new LinearHashedMarchingCubes.
5051 ///
5152 /// The depth of the internal octree will be at most `max_depth`, causing the tree to span the
52- /// equivalent of a cubic grid at most `2.pow(max_depth)` in either direction.
53+ /// equivalent of a cubic grid at most `2.pow(max_depth)` in either direction. Distances
54+ /// will be evaluated in Euclidean space.
5355 pub fn new ( max_depth : usize ) -> Self {
54- Self { max_depth }
56+ Self {
57+ max_depth,
58+ norm : Norm :: Euclidean ,
59+ }
60+ }
61+
62+ /// Create a new LinearHashedMarchingCubes.
63+ ///
64+ /// The depth of the internal octree will be at most `max_depth`, causing the tree to span the
65+ /// equivalent of a cubic grid at most `2.pow(max_depth)` in either direction. Distances will
66+ /// be evaluated in accordance with the provided Norm.
67+ pub fn with_norm ( max_depth : usize , norm : Norm ) -> Self {
68+ Self { max_depth, norm }
5569 }
5670
5771 /// Extracts a mesh from the given [`Source`](../source/trait.Source.html).
@@ -119,6 +133,13 @@ impl LinearHashedMarchingCubes {
119133 self . extract_surface ( & octree, & primal_vertices, indices, & mut base_index, extract) ;
120134 }
121135
136+ fn diagonal ( & self , distance : f32 ) -> f32 {
137+ match self . norm {
138+ Norm :: Euclidean => distance * SQRT_OF_3 ,
139+ Norm :: Max => distance,
140+ }
141+ }
142+
122143 fn build_octree < S > ( & mut self , source : & S ) -> LinearHashedOctree < f32 >
123144 where
124145 S : Source ,
@@ -130,7 +151,7 @@ impl LinearHashedMarchingCubes {
130151 |key : Morton , distance : & f32 | {
131152 let level = key. level ( ) ;
132153 let size = key. size ( ) ;
133- level < 2 || ( level < max_depth && distance. abs ( ) <= size * SQRT_OF_3 )
154+ level < 2 || ( level < max_depth && distance. abs ( ) <= self . diagonal ( size) )
134155 } ,
135156 |key : Morton | {
136157 let p = key. center ( ) ;
0 commit comments