Skip to content

Commit e462a9c

Browse files
committed
Remove getter functions from SurfaceReconstruction
1 parent 6745a82 commit e462a9c

File tree

8 files changed

+41
-79
lines changed

8 files changed

+41
-79
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The following changes are present in the `main` branch of the repository and are
99
- Lib: Add support for "dense" `DensityMap` (borrowed & owned) as input for the marching cubes triangulation, useful for the Python bindings
1010
- Lib: Replace usage of `DiscreteSquaredDistanceCubicKernel` by standard `CubicSplineKernel` for SPH interpolation (no noticeable performance difference)
1111
- Lib: Enforce that `Index` types are signed integers implementing the `num_traits::Signed` trait. Currently, the reconstruction does not work (correctly) with unsigned integers.
12-
- Lib: Make most fields of `SurfaceReconstruction` public
12+
- Lib: Make most fields of `SurfaceReconstruction` public, remove previous getter functions
1313
- CLI: Add some tests for the `reconstruction_pipeline` function
1414
- CLI: Fix post-processing when particle AABB filtering is enabled
1515
- Lib: Support subdomain "ghost particle" margins to be up to the size of the subdomain itself (previously limited to half the size)

splashsurf/src/reconstruct.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,8 +1040,8 @@ pub fn reconstruction_pipeline<'a, I: Index, R: Real>(
10401040
}
10411041
}
10421042

1043-
let grid = reconstruction.grid();
1044-
let mut mesh_with_data = MeshWithData::new(Cow::Borrowed(reconstruction.mesh()));
1043+
let grid = &reconstruction.grid;
1044+
let mut mesh_with_data = MeshWithData::new(Cow::Borrowed(&reconstruction.mesh));
10451045

10461046
// Perform post-processing
10471047
{
@@ -1054,7 +1054,7 @@ pub fn reconstruction_pipeline<'a, I: Index, R: Real>(
10541054
let verts_before = mesh_with_data.mesh.vertices.len();
10551055
vertex_connectivity = Some(splashsurf_lib::postprocessing::marching_cubes_cleanup(
10561056
mesh_with_data.mesh.to_mut(),
1057-
reconstruction.grid(),
1057+
&reconstruction.grid,
10581058
postprocessing
10591059
.mesh_cleanup_snap_dist
10601060
.map(|d| R::from_float(d)),
@@ -1092,7 +1092,10 @@ pub fn reconstruction_pipeline<'a, I: Index, R: Real>(
10921092
// TODO: Re-use filtered particles from reconstruction?
10931093
filtered_quantity(
10941094
particle_positions,
1095-
reconstruction.particle_inside_aabb().map(Vec::as_slice),
1095+
reconstruction
1096+
.particle_inside_aabb
1097+
.as_ref()
1098+
.map(Vec::as_slice),
10961099
)
10971100
} else {
10981101
Cow::Borrowed(particle_positions)
@@ -1114,7 +1117,7 @@ pub fn reconstruction_pipeline<'a, I: Index, R: Real>(
11141117
let particle_rest_mass = particle_rest_volume * particle_rest_density;
11151118

11161119
let particle_densities = reconstruction
1117-
.particle_densities()
1120+
.particle_densities.as_ref()
11181121
.ok_or_else(|| anyhow::anyhow!("Particle densities were not returned by surface reconstruction but are required for SPH normal computation"))?
11191122
.as_slice();
11201123
assert_eq!(
@@ -1150,7 +1153,7 @@ pub fn reconstruction_pipeline<'a, I: Index, R: Real>(
11501153

11511154
// Global neighborhood search
11521155
let nl = reconstruction
1153-
.particle_neighbors()
1156+
.particle_neighbors.as_ref()
11541157
.map(Cow::Borrowed)
11551158
.unwrap_or_else(||
11561159
{
@@ -1337,7 +1340,10 @@ pub fn reconstruction_pipeline<'a, I: Index, R: Real>(
13371340
{
13381341
info!("Interpolating attribute \"{}\"...", attribute.name);
13391342

1340-
let particles_inside = reconstruction.particle_inside_aabb().map(Vec::as_slice);
1343+
let particles_inside = reconstruction
1344+
.particle_inside_aabb
1345+
.as_ref()
1346+
.map(Vec::as_slice);
13411347
match &attribute.data {
13421348
AttributeData::ScalarReal(values) => {
13431349
let filtered_values = filtered_quantity(&values, particles_inside);
@@ -1532,7 +1538,7 @@ pub fn reconstruction_pipeline<'a, I: Index, R: Real>(
15321538
} = mesh;
15331539

15341540
// Avoid copy if original mesh was not modified
1535-
let (mesh, take_mesh) = if std::ptr::eq(mesh.as_ref(), reconstruction.mesh())
1541+
let (mesh, take_mesh) = if std::ptr::eq(mesh.as_ref(), &reconstruction.mesh)
15361542
&& !postprocessing.output_raw_mesh
15371543
{
15381544
// Ensure that borrow of reconstruction is dropped
@@ -1602,7 +1608,7 @@ pub(crate) fn reconstruction_pipeline_from_path<I: Index, R: Real>(
16021608
if postprocessing.output_raw_mesh {
16031609
profile!("write surface mesh to file");
16041610

1605-
let mesh = reconstruction.mesh();
1611+
let mesh = &reconstruction.mesh;
16061612

16071613
let output_path = paths
16081614
.output_file

splashsurf/tests/test_pipeline.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn test_basic_pipeline() -> Result<(), Box<dyn std::error::Error>> {
2727
.as_ref()
2828
.expect("reconstruction should produce a triangle mesh")
2929
.mesh;
30-
let raw_mesh = reconstruction.raw_reconstruction.mesh();
30+
let raw_mesh = &reconstruction.raw_reconstruction.mesh;
3131
vtk_format::write_vtk(mesh, "../out/bunny_test_basic_pipeline.vtk", "mesh")?;
3232

3333
// Compare raw and final mesh
@@ -203,7 +203,7 @@ fn test_basic_pipeline_postprocessing() -> Result<(), Box<dyn std::error::Error>
203203
.as_ref()
204204
.expect("reconstruction should produce a triangle mesh")
205205
.mesh;
206-
let raw_mesh = reconstruction.raw_reconstruction.mesh();
206+
let raw_mesh = &reconstruction.raw_reconstruction.mesh;
207207
vtk_format::write_vtk(
208208
mesh,
209209
"../out/bunny_test_basic_pipeline_postprocessing.vtk",
@@ -286,7 +286,7 @@ fn test_basic_pipeline_postprocessing_with_aabb() -> Result<(), Box<dyn std::err
286286
.as_ref()
287287
.expect("reconstruction should produce a triangle mesh")
288288
.mesh;
289-
let raw_mesh = reconstruction.raw_reconstruction.mesh();
289+
let raw_mesh = &reconstruction.raw_reconstruction.mesh;
290290
vtk_format::write_vtk(
291291
mesh,
292292
"../out/bunny_test_basic_pipeline_postprocessing_aabb.vtk",

splashsurf_lib/benches/benches/bench_full.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ pub fn surface_reconstruction_double_dam_break_inplace(c: &mut Criterion) {
268268
group.finish();
269269

270270
write_vtk(
271-
reconstruction.mesh(),
271+
reconstruction.mesh,
272272
"../out/reconstruct_surface_double_dam_break.vtk",
273273
"mesh",
274274
)

splashsurf_lib/benches/benches/bench_mesh.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn reconstruct_particles<P: AsRef<Path>>(particle_file: P) -> SurfaceReconstruct
3636
pub fn mesh_vertex_normals(c: &mut Criterion) {
3737
//let reconstruction = reconstruct_particles("../../canyon_13353401_particles.vtk");
3838
let reconstruction = reconstruct_particles("../data/hilbert_46843_particles.bgeo");
39-
let mesh = reconstruction.mesh();
39+
let mesh = &reconstruction.mesh;
4040

4141
let mut group = c.benchmark_group("mesh");
4242
group.sample_size(50);
@@ -56,7 +56,7 @@ pub fn mesh_vertex_normals(c: &mut Criterion) {
5656
pub fn mesh_vertex_normals_parallel(c: &mut Criterion) {
5757
//let reconstruction = reconstruct_particles("../../canyon_13353401_particles.vtk");
5858
let reconstruction = reconstruct_particles("../data/hilbert_46843_particles.bgeo");
59-
let mesh = reconstruction.mesh();
59+
let mesh = &reconstruction.mesh;
6060

6161
let mut group = c.benchmark_group("mesh");
6262
group.sample_size(50);

splashsurf_lib/src/lib.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -266,34 +266,6 @@ impl<I: Index, R: Real> Default for SurfaceReconstruction<I, R> {
266266
}
267267
}
268268

269-
// TODO: Remove these functions
270-
impl<I: Index, R: Real> SurfaceReconstruction<I, R> {
271-
/// Returns a reference to the surface mesh that is the result of the reconstruction
272-
pub fn mesh(&self) -> &TriMesh3d<R> {
273-
&self.mesh
274-
}
275-
276-
/// Returns a reference to the global particle density vector if computed during the reconstruction (currently, all reconstruction approaches return this)
277-
pub fn particle_densities(&self) -> Option<&Vec<R>> {
278-
self.particle_densities.as_ref()
279-
}
280-
281-
/// Returns a reference to the per input particle boolean vector indicating whether the particle was inside the specified AABB (if any)
282-
pub fn particle_inside_aabb(&self) -> Option<&Vec<bool>> {
283-
self.particle_inside_aabb.as_ref()
284-
}
285-
286-
/// Returns a reference to the global list of per-particle neighborhood lists if computed during the reconstruction (`None` if not specified in the parameters)
287-
pub fn particle_neighbors(&self) -> Option<&Vec<Vec<usize>>> {
288-
self.particle_neighbors.as_ref()
289-
}
290-
291-
/// Returns a reference to the virtual background grid that was used for marching cubes
292-
pub fn grid(&self) -> &UniformGrid<I, R> {
293-
&self.grid
294-
}
295-
}
296-
297269
impl<I: Index, R: Real> From<SurfaceReconstruction<I, R>> for TriMesh3d<R> {
298270
/// Extracts the reconstructed mesh
299271
fn from(result: SurfaceReconstruction<I, R>) -> Self {

splashsurf_lib/tests/integration_tests/test_full.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,33 +104,33 @@ macro_rules! generate_test {
104104
let reconstruction =
105105
reconstruct_surface::<i64, _>(particle_positions.as_slice(), &parameters).unwrap();
106106

107-
write_vtk(reconstruction.mesh(), &output_file, "mesh").unwrap();
107+
write_vtk(&reconstruction.mesh, &output_file, "mesh").unwrap();
108108

109109
println!(
110110
"Reconstructed mesh '{}' from particle file '{}' with {} particles has {} triangles.",
111111
output_file.display(),
112112
$input_file,
113113
particle_positions.len(),
114-
reconstruction.mesh().triangles.len()
114+
reconstruction.mesh.triangles.len()
115115
);
116116

117117
// Ensure that the number of triangles is roughly correct
118118
assert!(
119-
reconstruction.mesh().triangles.len() > $min_triangles,
119+
reconstruction.mesh.triangles.len() > $min_triangles,
120120
"Mesh has probably too few triangles (min expected: {}, is: {})",
121121
$min_triangles,
122-
reconstruction.mesh().triangles.len()
122+
reconstruction.mesh.triangles.len()
123123
);
124124
assert!(
125-
reconstruction.mesh().triangles.len() < $max_triangles,
125+
reconstruction.mesh.triangles.len() < $max_triangles,
126126
"Mesh has probably too many triangles (max expected: {}, is: {})",
127127
$max_triangles,
128-
reconstruction.mesh().triangles.len()
128+
reconstruction.mesh.triangles.len()
129129
);
130130

131131
if test_for_boundary(&parameters) {
132132
// Ensure that the mesh does not have a boundary
133-
if let Err(e) = check_mesh_consistency(reconstruction.grid(), reconstruction.mesh(), true, true, true)
133+
if let Err(e) = check_mesh_consistency(&reconstruction.grid, &reconstruction.mesh, true, true, true)
134134
{
135135
eprintln!("{}", e);
136136
panic!("Mesh contains topological/manifold errors");

splashsurf_lib/tests/integration_tests/test_simple.rs

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -76,28 +76,20 @@ fn test_edge_above_threshold_to_outside_of_compact_support_global() {
7676
println!(
7777
"Reconstructed mesh from {} particles has {} triangles.",
7878
particle_positions.len(),
79-
reconstruction.mesh().triangles.len()
79+
reconstruction.mesh.triangles.len()
8080
);
8181

82+
assert_eq!(reconstruction.mesh.vertices.len(), 6, "Number of vertices");
8283
assert_eq!(
83-
reconstruction.mesh().vertices.len(),
84-
6,
85-
"Number of vertices"
86-
);
87-
assert_eq!(
88-
reconstruction.mesh().triangles.len(),
84+
reconstruction.mesh.triangles.len(),
8985
8,
9086
"Number of triangles"
9187
);
9288

9389
// 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-
) {
90+
if let Err(e) =
91+
check_mesh_consistency(&reconstruction.grid, &reconstruction.mesh, true, true, true)
92+
{
10193
eprintln!("{}", e);
10294
panic!("Mesh contains topological/manifold errors");
10395
}
@@ -113,28 +105,20 @@ fn test_edge_above_threshold_to_outside_of_compact_support_subdomains() {
113105
println!(
114106
"Reconstructed mesh from {} particles has {} triangles.",
115107
particle_positions.len(),
116-
reconstruction.mesh().triangles.len()
108+
reconstruction.mesh.triangles.len()
117109
);
118110

111+
assert_eq!(reconstruction.mesh.vertices.len(), 6, "Number of vertices");
119112
assert_eq!(
120-
reconstruction.mesh().vertices.len(),
121-
6,
122-
"Number of vertices"
123-
);
124-
assert_eq!(
125-
reconstruction.mesh().triangles.len(),
113+
reconstruction.mesh.triangles.len(),
126114
8,
127115
"Number of triangles"
128116
);
129117

130118
// 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-
) {
119+
if let Err(e) =
120+
check_mesh_consistency(&reconstruction.grid, &reconstruction.mesh, true, true, true)
121+
{
138122
eprintln!("{}", e);
139123
panic!("Mesh contains topological/manifold errors");
140124
}

0 commit comments

Comments
 (0)