@@ -17,7 +17,7 @@ use crate::marching_cubes_impl::{get_offset, interpolate, march_cube};
17
17
use crate :: marching_cubes_tables:: EDGE_CONNECTION ;
18
18
use crate :: math:: Vec3 ;
19
19
use crate :: morton:: Morton ;
20
- use crate :: source:: { HermiteSource , Source } ;
20
+ use crate :: source:: { HermiteSource , Norm , Source } ;
21
21
use std:: collections:: HashMap ;
22
22
23
23
// Morton cube corners are ordered differently to the marching cubes tables, so remap them to match.
@@ -43,15 +43,29 @@ impl Edge {
43
43
/// Extracts meshes from distance fields using marching cubes over a linear hashed octree.
44
44
pub struct LinearHashedMarchingCubes {
45
45
max_depth : usize ,
46
+ norm : Norm ,
46
47
}
47
48
48
49
impl LinearHashedMarchingCubes {
49
50
/// Create a new LinearHashedMarchingCubes.
50
51
///
51
52
/// 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.
53
55
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 }
55
69
}
56
70
57
71
/// Extracts a mesh from the given [`Source`](../source/trait.Source.html).
@@ -119,6 +133,13 @@ impl LinearHashedMarchingCubes {
119
133
self . extract_surface ( & octree, & primal_vertices, indices, & mut base_index, extract) ;
120
134
}
121
135
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
+
122
143
fn build_octree < S > ( & mut self , source : & S ) -> LinearHashedOctree < f32 >
123
144
where
124
145
S : Source ,
@@ -130,7 +151,7 @@ impl LinearHashedMarchingCubes {
130
151
|key : Morton , distance : & f32 | {
131
152
let level = key. level ( ) ;
132
153
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) )
134
155
} ,
135
156
|key : Morton | {
136
157
let p = key. center ( ) ;
0 commit comments