Skip to content

Commit 1a50a48

Browse files
committed
Improve error output of mesh checks
1 parent 43797f6 commit 1a50a48

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

splashsurf/src/reconstruction.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{io, logging};
22
use anyhow::{anyhow, Context};
33
use clap::value_parser;
44
use indicatif::{ProgressBar, ProgressStyle};
5-
use log::info;
5+
use log::{error, info, warn};
66
use rayon::prelude::*;
77
use splashsurf_lib::mesh::{AttributeData, Mesh3d, MeshAttribute, MeshWithData};
88
use splashsurf_lib::nalgebra::{Unit, Vector3};
@@ -897,6 +897,10 @@ pub(crate) fn reconstruction_pipeline_generic<I: Index, R: Real>(
897897
) -> Result<(), anyhow::Error> {
898898
profile!("surface reconstruction");
899899

900+
let check_mesh = postprocessing.check_mesh_closed
901+
|| postprocessing.check_mesh_manifold
902+
|| postprocessing.check_mesh_debug;
903+
900904
// Load particle positions and attributes to interpolate
901905
let (particle_positions, attributes) = io::read_particle_positions_with_attributes(
902906
&paths.input_file,
@@ -948,7 +952,6 @@ pub(crate) fn reconstruction_pipeline_generic<I: Index, R: Real>(
948952
// Perform post-processing
949953
{
950954
profile!("postprocessing");
951-
952955
let mut vertex_connectivity = None;
953956

954957
if postprocessing.mesh_cleanup {
@@ -1272,10 +1275,6 @@ pub(crate) fn reconstruction_pipeline_generic<I: Index, R: Real>(
12721275
// Store the surface mesh
12731276
{
12741277
profile!("write surface mesh to file");
1275-
info!(
1276-
"Writing surface mesh to \"{}\"...",
1277-
paths.output_file.display()
1278-
);
12791278

12801279
match (&tri_mesh, &tri_quad_mesh) {
12811280
(Some(mesh), None) => {
@@ -1293,13 +1292,9 @@ pub(crate) fn reconstruction_pipeline_generic<I: Index, R: Real>(
12931292
paths.output_file.display()
12941293
)
12951294
})?;
1296-
info!("Done.");
12971295
}
12981296

1299-
if postprocessing.check_mesh_closed
1300-
|| postprocessing.check_mesh_manifold
1301-
|| postprocessing.check_mesh_debug
1302-
{
1297+
if check_mesh {
13031298
if let Err(err) = match (&tri_mesh, &tri_quad_mesh) {
13041299
(Some(mesh), None) => splashsurf_lib::marching_cubes::check_mesh_consistency(
13051300
grid,
@@ -1314,7 +1309,11 @@ pub(crate) fn reconstruction_pipeline_generic<I: Index, R: Real>(
13141309
}
13151310
_ => unreachable!(),
13161311
} {
1317-
return Err(anyhow!("{}", err));
1312+
error!("Checked mesh for problems (holes: {}, non-manifold edges/vertices: {}), problems were found!", postprocessing.check_mesh_closed, postprocessing.check_mesh_manifold);
1313+
error!("{}", err);
1314+
return Err(anyhow!("{}", err))
1315+
.context(format!("Checked mesh for problems (holes: {}, non-manifold edges/vertices: {}), problems were found!", postprocessing.check_mesh_closed, postprocessing.check_mesh_manifold))
1316+
.context(format!("Problem found with mesh file \"{}\"", paths.output_file.display()));
13181317
} else {
13191318
info!("Checked mesh for problems (holes: {}, non-manifold edges/vertices: {}), no problems were found.", postprocessing.check_mesh_closed, postprocessing.check_mesh_manifold);
13201319
}

splashsurf_lib/src/marching_cubes.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub fn check_mesh_consistency<I: Index, R: Real>(
155155
return Ok(());
156156
}
157157

158-
let add_edge_errors = |error_string: &mut String, edge: ([usize; 2], usize, usize)| {
158+
let add_edge_errors = |error_strings: &mut Vec<String>, edge: ([usize; 2], usize, usize)| {
159159
let (edge, tri_idx, _) = edge;
160160

161161
let v0 = mesh.vertices[edge[0]];
@@ -169,45 +169,46 @@ pub fn check_mesh_consistency<I: Index, R: Real>(
169169
let cell_center = grid.point_coordinates(&point_index)
170170
+ Vector3::repeat(grid.cell_size().times_f64(0.5));
171171

172-
*error_string += &format!("\n\tTriangle {}, boundary edge {:?} is located in cell with {:?} with center coordinates {:?} and edge length {}.", tri_idx, edge, cell_index, cell_center, grid.cell_size());
172+
error_strings.push(format!("\n\tTriangle {}, boundary edge {:?} is located in cell with {:?} with center coordinates {:?} and edge length {}.", tri_idx, edge, cell_index, cell_center, grid.cell_size()));
173173
} else {
174-
*error_string += &format!(
174+
error_strings.push(format!(
175175
"\n\tCannot get cell index for edge {:?} of triangle {}",
176176
edge, tri_idx
177-
);
177+
));
178178
}
179179
};
180180

181-
let mut error_string = String::new();
181+
let mut error_strings = Vec::new();
182182

183183
if check_closed && !boundary_edges.is_empty() {
184-
error_string += &format!("Mesh is not closed. It has {} boundary edges (edges that are connected to only one triangle).", boundary_edges.len());
184+
error_strings.push(format!("Mesh is not closed. It has {} boundary edges (edges that are connected to only one triangle).", boundary_edges.len()));
185185
if debug {
186186
for e in boundary_edges {
187-
add_edge_errors(&mut error_string, e);
187+
add_edge_errors(&mut error_strings, e);
188188
}
189189
}
190-
error_string += "\n";
191190
}
192191

193192
if check_manifold && !non_manifold_edges.is_empty() {
194-
error_string += &format!("Mesh is not manifold. It has {} non-manifold edges (edges that are connected to more than twi triangles).", non_manifold_edges.len());
193+
error_strings.push(format!("Mesh is not manifold. It has {} non-manifold edges (edges that are connected to more than twi triangles).", non_manifold_edges.len()));
195194
if debug {
196195
for e in non_manifold_edges {
197-
add_edge_errors(&mut error_string, e);
196+
add_edge_errors(&mut error_strings, e);
198197
}
199198
}
200-
error_string += "\n";
201199
}
202200

203201
if check_manifold && !non_manifold_vertices.is_empty() {
204-
error_string += &format!("Mesh is not manifold. It has {} non-manifold vertices (vertices with more than one triangle fan).", non_manifold_vertices.len());
202+
error_strings.push(format!("Mesh is not manifold. It has {} non-manifold vertices (vertices with more than one triangle fan).", non_manifold_vertices.len()));
205203
if debug {
206-
error_string += &format!("\n\t{:?}", non_manifold_vertices);
204+
error_strings.push(format!(
205+
"\tNon-manifold vertices: {:?}",
206+
non_manifold_vertices
207+
));
207208
}
208-
error_string += "\n";
209209
}
210210

211+
let error_string = error_strings.join("\n");
211212
Err(error_string)
212213
}
213214

splashsurf_lib/src/mesh.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -991,9 +991,9 @@ impl<R: Real> TriMesh3d<R> {
991991
/// A non-manifold vertex is generated by pinching two surface sheets together at that vertex
992992
/// such that the vertex is incident to more than one fan of triangles.
993993
///
994-
/// Note: This function assumes that all edges in the mesh are manifold edges! If there are non-
995-
/// manifold edges, it is possible to connect two triangle fans using a third fan which is not
996-
/// detected by this function.
994+
/// Note: This function assumes that all edges in the mesh are manifold edges! If there are
995+
/// non-manifold edges, it is possible to connect two triangle fans using a third fan which is
996+
/// not detected by this function.
997997
pub fn find_non_manifold_vertices(&self) -> Vec<usize> {
998998
let mut non_manifold_verts = Vec::new();
999999
let mut tri_fan = Vec::new();

0 commit comments

Comments
 (0)