Skip to content

Commit fcd2069

Browse files
committed
Fix bug in triangulation emitting only 4 out of 5 possible triangles
1 parent 62de85f commit fcd2069

File tree

2 files changed

+20
-31
lines changed

2 files changed

+20
-31
lines changed

splashsurf_lib/src/marching_cubes/marching_cubes_lut.rs

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ static MARCHING_CUBES_TABLE: [[i32; 16]; 256] = [
302302

303303
/// Returns a reference into the marching cubes LUT to the case corresponding to the given vertex configuration
304304
pub fn get_marching_cubes_triangulation_raw(vertices_inside: &[bool; 8]) -> &'static [i32; 16] {
305-
&MARCHING_CUBES_TABLE[flags_to_index(vertices_inside)]
305+
let index = flags_to_index(vertices_inside);
306+
&MARCHING_CUBES_TABLE[index]
306307
}
307308

308309
/// Returns the marching cubes triangulation corresponding to the given vertex configuration
@@ -314,7 +315,7 @@ pub fn marching_cubes_triangulation_iter(
314315
vertices_inside: &[bool; 8],
315316
) -> impl Iterator<Item = [i32; 3]> {
316317
let triangulation = get_marching_cubes_triangulation_raw(vertices_inside);
317-
(0..4)
318+
(0..5)
318319
.into_iter()
319320
.map(move |i| triangulation_to_triangle(triangulation, i))
320321
.flatten()
@@ -398,43 +399,32 @@ mod test_lut {
398399
}
399400
}
400401

401-
/*
402402
#[test]
403-
fn test_marching_cubes_cases() {
403+
fn test_get_marching_cubes_triangulation_iter() {
404404
assert_eq!(MARCHING_CUBES_TABLE.len(), 256);
405405

406406
for i in 0..256 {
407407
let flags = index_to_flags(i);
408-
let flags_inverse = inverse_flags(&flags);
409-
let i_inverse = flags_to_index(&flags_inverse);
408+
let raw = get_marching_cubes_triangulation_raw(&flags);
410409

411-
let case = MARCHING_CUBES_TABLE[i];
412-
let case_inverse = MARCHING_CUBES_TABLE[i_inverse];
410+
let mut tri_counter = 0;
411+
for tri in marching_cubes_triangulation_iter(&flags) {
412+
let mut vec_raw = raw[3 * tri_counter..3 * tri_counter + 3].to_vec();
413+
let mut vec_tri = tri.to_vec();
413414

414-
let triangles: Vec<_> = (0..4)
415-
.into_iter()
416-
.map(|i| triangulation_to_triangle(&case, i))
417-
.flatten()
418-
.collect();
419-
420-
let triangles_inverse: Vec<_> = (0..4)
421-
.into_iter()
422-
.map(|i| triangulation_to_triangle(&case_inverse, i))
423-
.flatten()
424-
.collect();
415+
vec_raw.sort();
416+
vec_tri.sort();
417+
assert_eq!(vec_raw, vec_tri);
418+
tri_counter += 1;
419+
}
425420

426421
assert_eq!(
427-
triangles.len(),
428-
triangles_inverse.len(),
429-
"Case {} and inverse case {} don't have the same number of triangles ({:?} vs {:?})",
430-
i,
431-
i_inverse,
432-
triangles,
433-
triangles_inverse
434-
);
422+
raw[3 * tri_counter],
423+
-1,
424+
"There are more triangles in the raw case then returned by the iterator!"
425+
)
435426
}
436427
}
437-
*/
438428

439429
#[test]
440430
fn test_marching_cubes_triangulation_iter() {
@@ -449,7 +439,6 @@ mod test_lut {
449439
true, false, false, false, false, false, false, false
450440
])
451441
.collect::<Vec<_>>(),
452-
//vec![[0, 8, 3]]
453442
vec![[3, 8, 0]]
454443
);
455444

splashsurf_lib/tests/integration_tests/test_full.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,5 @@ generate_test!(f32, surface_reconstruction_hilbert_stitching, "hilbert_46843_par
126126
generate_test!(f32, surface_reconstruction_hilbert2_stitching, "hilbert2_7954_particles.vtk" => "reconstruct_surface_hilbert2_par_stitching.vtk", params(0.025, 4.0, 1.1, Strategy::OctreeStitching), 80000, 130000);
127127
generate_test!(f32, surface_reconstruction_octocat_stitching, "octocat_32614_particles.vtk" => "reconstruct_surface_octocat_par_stitching.vtk", params(0.025, 4.0, 0.75, Strategy::OctreeStitching), 150000, 210000);
128128

129-
//generate_test!(f32, surface_reconstruction_knot_global, "sailors_knot_19539_particles.vtk" => "reconstruct_surface_knot_par_global.vtk", params(0.025, 4.0, 1.1, Strategy::Global), 50000, 100000);
130-
//generate_test!(f32, surface_reconstruction_knot_stitching, "sailors_knot_19539_particles.vtk" => "reconstruct_surface_knot_par_stitching.vtk", params(0.025, 4.0, 1.1, Strategy::OctreeStitching), 50000, 100000);
129+
generate_test!(f32, surface_reconstruction_knot_global, "sailors_knot_19539_particles.vtk" => "reconstruct_surface_knot_par_global.vtk", params(0.025, 4.0, 1.1, Strategy::Global), 50000, 100000);
130+
generate_test!(f32, surface_reconstruction_knot_stitching, "sailors_knot_19539_particles.vtk" => "reconstruct_surface_knot_par_stitching.vtk", params(0.025, 4.0, 1.1, Strategy::OctreeStitching), 50000, 100000);

0 commit comments

Comments
 (0)