ENH: Add Sharp Bounding Box Edges option to M3C surface meshing - #1735
ENH: Add Sharp Bounding Box Edges option to M3C surface meshing#1735imikejackson wants to merge 2 commits into
Conversation
M3C places every vertex on a cell edge, face center, or body center, so the marching squares that straddle a bounding box edge (one real corner, three ghost corners) join their edge midpoints with a diagonal. Every box edge and corner therefore came out with a 45 degree chamfer half a cell deep, which downstream FEA mesh preparation (e.g. Gmsh) cannot use without hand repair. * Add a "Sharp Bounding Box Edges" BoolParameter (default on) and bump the filter parameters version to 3; older pipelines take the default. * Add a post-pass in finalizeMesh that snaps the outermost row of wall nodes onto the neighbouring wall plane, merges the nodes that coincide on the box edge lines and corners, and drops the collapsed chamfer triangles. The pass works on the integer half-cell node lattice, so it is exact for any spacing and origin. One-cell-thick axes are left chamfered (ambiguous). * Add tests: exterior triangles are coplanar with a single wall, all eight box corners exist, no coincident vertices, single-feature box is watertight, one-cell-thick volume stays well formed, and Small IN100. * Document the option with before/after screenshots and update the demo pipeline. Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>
Issue BlueQuartzSoftware#1706 reported that M3C emitted vertices no triangle references (about 144 on a 12^3 volume, and a non-zero vertex count on an all-background volume once every face was pruned). Those orphans were a product of the six distinct ghost-shell sentinels: neighbouring ghost cells looked like a material interface to each other and marked candidate nodes whose triangles were never built. The single shared ghost sentinel introduced in BlueQuartzSoftware#1718 removed the cause. Re-measuring on the cylinder, all-background, polycrystal, porosity, toy, and Small IN100 datasets, in both Bounding Box Skin modes, now gives zero orphan vertices everywhere. * CheckMeshIntegrity now requires every emitted vertex to be referenced by a triangle, so a regression is caught by every M3C test that uses it. * The all-background skin test requires zero vertices instead of measuring a "pre-existing orphan" count, and the newly-orphaned check also requires zero unreferenced vertices overall. * Remove the orphan-vertex notes from the filter documentation and the stale comments in the algorithm and tests. Closes BlueQuartzSoftware#1706 Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>
| { | ||
| for(const SiteId nodeId : triangle.node_id) | ||
| { | ||
| touched.erase(nodeId); |
There was a problem hiding this comment.
I don't know how many of the triangles are actually touched in practice so this unordered_set may be more efficient, but a std::vector of bool is bit packed whereas the unordered set of SiteId which is probably uint64_t meaning you would have to be hitting fewer than 1 in 64 to make this more space efficient (which is not impossible if your only touching corners or smtg). You know the algorithm better just thought I would point it out.
There was a problem hiding this comment.
Good point. Let me run a memory analysis. Also, std::vector is only bit packed on Windows I think? Maybe I am remembering that incorrectly.
There was a problem hiding this comment.
I measured this against the candidate-space and edge-space bounds. I was remembering std::vector<bool> incorrectly: libc++, libstdc++, and MSVC all use packed-bit representations.
The important distinction here is scaling. A dense mask needs 7 * (x + 2) * (y + 2) * (z + 2) bits, while touched is limited to nodes along the box edges and grows roughly as O(x + y + z). Using the geometric upper bound for touched, the allocations on the current macOS/libc++ build were:
- 4 x 3 x 5:
vector<bool>184 B;unordered_set4,072 B - Small IN100 (51 x 26 x 51):
vector<bool>68,824 B;unordered_set37,544 B - 100 cubed:
vector<bool>928,560 B;unordered_set83,416 B
The tiny test volume favors the bit vector, but realistic volumes increasingly favor the sparse set. The set also fits the final pass: erase every surviving node ID, then iterate only the remaining orphans. A dense mask would require scanning every candidate ID or maintaining a second sparse list.
I am going to retain the unordered_set. If this becomes a measurable hot spot, the next representation I would compare is a sorted sparse vector<SiteId> plus a touched-sized flag vector.
Summary
M3C places every vertex on a cell edge, face center, or body center, so the marching squares that straddle a bounding box edge (one real corner, three ghost corners) join their edge midpoints with a diagonal. Every box edge and corner therefore came out with a 45 degree chamfer half a cell deep on each wall, which downstream FEA mesh preparation (Gmsh) cannot use without hand repair. Development builds of the port produced sharp edges; the chamfer appeared in the released version.
BoolParameter(default on) toM3CSurfaceMeshingFilterand bump the parameters version to 3. Older pipelines take the default.finalizeMeshthat snaps the outermost row of wall nodes onto the neighbouring wall plane, merges the nodes that coincide on the box edge lines and corners, and drops the collapsed chamfer triangles. The pass works on the integer half-cell node lattice, so it is exact for any spacing and origin. One-cell-thick axes are left chamfered since the single wall row is half a cell from both bounding planes.M3C_Demo.d3dpipeline.CheckMeshIntegritynow requires every emitted vertex to be referenced by a triangle, the all-background skin test requires zero vertices, and the orphan notes are removed from the docs and comments.Closes #1706
Test Plan
M3CSurfaceMeshingandBounding Box Skintests pass