|
| 1 | +use nalgebra::Vector3; |
| 2 | +use splashsurf_lib::marching_cubes::check_mesh_consistency; |
| 3 | +use splashsurf_lib::{ |
| 4 | + reconstruct_surface, Aabb3d, GridDecompositionParameters, Parameters, Real, |
| 5 | + SpatialDecomposition, |
| 6 | +}; |
| 7 | + |
| 8 | +enum Strategy { |
| 9 | + Global, |
| 10 | + SubdomainGrid, |
| 11 | +} |
| 12 | + |
| 13 | +fn params_with_aabb<R: Real>( |
| 14 | + particle_radius: R, |
| 15 | + compact_support_radius: R, |
| 16 | + cube_size: R, |
| 17 | + iso_surface_threshold: R, |
| 18 | + domain_aabb: Option<Aabb3d<R>>, |
| 19 | + strategy: Strategy, |
| 20 | +) -> Parameters<R> { |
| 21 | + let compact_support_radius = particle_radius * compact_support_radius; |
| 22 | + let cube_size = particle_radius * cube_size; |
| 23 | + |
| 24 | + let mut parameters = Parameters { |
| 25 | + particle_radius, |
| 26 | + rest_density: R::from_f64(1000.0).unwrap(), |
| 27 | + compact_support_radius, |
| 28 | + cube_size, |
| 29 | + iso_surface_threshold, |
| 30 | + particle_aabb: domain_aabb, |
| 31 | + enable_multi_threading: false, |
| 32 | + spatial_decomposition: None, |
| 33 | + global_neighborhood_list: false, |
| 34 | + }; |
| 35 | + |
| 36 | + match strategy { |
| 37 | + Strategy::Global => {} |
| 38 | + Strategy::SubdomainGrid => { |
| 39 | + parameters.spatial_decomposition = Some(SpatialDecomposition::UniformGrid( |
| 40 | + GridDecompositionParameters { |
| 41 | + subdomain_num_cubes_per_dim: 64, |
| 42 | + }, |
| 43 | + )) |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + parameters |
| 48 | +} |
| 49 | + |
| 50 | +fn params<R: Real>( |
| 51 | + particle_radius: R, |
| 52 | + compact_support_radius: R, |
| 53 | + cube_size: R, |
| 54 | + iso_surface_threshold: R, |
| 55 | + strategy: Strategy, |
| 56 | +) -> Parameters<R> { |
| 57 | + params_with_aabb( |
| 58 | + particle_radius, |
| 59 | + compact_support_radius, |
| 60 | + cube_size, |
| 61 | + iso_surface_threshold, |
| 62 | + None, |
| 63 | + strategy, |
| 64 | + ) |
| 65 | +} |
| 66 | + |
| 67 | +/// This tests ensures that a surface is reconstructed properly if a single edge is above the threshold |
| 68 | +/// on one side but outside the compact support on the other side. |
| 69 | +#[test] |
| 70 | +fn test_edge_above_threshold_to_outside_of_compact_support_global() { |
| 71 | + let particle_positions: Vec<Vector3<f32>> = vec![Vector3::new(0.01, 0.0, 0.0)]; |
| 72 | + let parameters = params(1.0, 1.0, 1.0, 0.1, Strategy::Global); |
| 73 | + let reconstruction = |
| 74 | + reconstruct_surface::<i64, _>(particle_positions.as_slice(), ¶meters).unwrap(); |
| 75 | + |
| 76 | + println!( |
| 77 | + "Reconstructed mesh from {} particles has {} triangles.", |
| 78 | + particle_positions.len(), |
| 79 | + reconstruction.mesh().triangles.len() |
| 80 | + ); |
| 81 | + |
| 82 | + assert_eq!( |
| 83 | + reconstruction.mesh().vertices.len(), |
| 84 | + 6, |
| 85 | + "Number of vertices" |
| 86 | + ); |
| 87 | + assert_eq!( |
| 88 | + reconstruction.mesh().triangles.len(), |
| 89 | + 8, |
| 90 | + "Number of triangles" |
| 91 | + ); |
| 92 | + |
| 93 | + // Ensure that the mesh does not have a boundary |
| 94 | + if let Err(e) = check_mesh_consistency( |
| 95 | + reconstruction.grid(), |
| 96 | + reconstruction.mesh(), |
| 97 | + true, |
| 98 | + true, |
| 99 | + true, |
| 100 | + ) { |
| 101 | + eprintln!("{}", e); |
| 102 | + panic!("Mesh contains topological/manifold errors"); |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | +#[test] |
| 107 | +fn test_edge_above_threshold_to_outside_of_compact_support_subdomains() { |
| 108 | + let particle_positions: Vec<Vector3<f32>> = vec![Vector3::new(0.01, 0.0, 0.0)]; |
| 109 | + let parameters = params(1.0, 1.0, 1.0, 0.1, Strategy::SubdomainGrid); |
| 110 | + let reconstruction = |
| 111 | + reconstruct_surface::<i64, _>(particle_positions.as_slice(), ¶meters).unwrap(); |
| 112 | + |
| 113 | + println!( |
| 114 | + "Reconstructed mesh from {} particles has {} triangles.", |
| 115 | + particle_positions.len(), |
| 116 | + reconstruction.mesh().triangles.len() |
| 117 | + ); |
| 118 | + |
| 119 | + assert_eq!( |
| 120 | + reconstruction.mesh().vertices.len(), |
| 121 | + 6, |
| 122 | + "Number of vertices" |
| 123 | + ); |
| 124 | + assert_eq!( |
| 125 | + reconstruction.mesh().triangles.len(), |
| 126 | + 8, |
| 127 | + "Number of triangles" |
| 128 | + ); |
| 129 | + |
| 130 | + // Ensure that the mesh does not have a boundary |
| 131 | + if let Err(e) = check_mesh_consistency( |
| 132 | + reconstruction.grid(), |
| 133 | + reconstruction.mesh(), |
| 134 | + true, |
| 135 | + true, |
| 136 | + true, |
| 137 | + ) { |
| 138 | + eprintln!("{}", e); |
| 139 | + panic!("Mesh contains topological/manifold errors"); |
| 140 | + } |
| 141 | +} |
0 commit comments