corefine_and_compute_union() returns true but the output Surface_mesh has a non-manifold vertex (is_valid_polygon_mesh() is false)
Maintainers usually reply within 3 days
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 12/100
Research direction
The repro is the main_ program in the issue body, run with box.off and corner.off, and the failing check is is_valid_polygon_mesh on the output of corefine_and_compute_union in Polygon_mesh_processing/corefinement.h. Start from the output-building step that decides whether a shared vertex at the concave edge of corner.off should be duplicated, and check the documented return value against the manifoldness helpers in Polygon_mesh_processing/manifoldness.h. Done means the output is valid or the return value and documentation agree with the non-manifold result.
Written by the indexing model from the issue text.
Description
Issue Details
The documentation of corefine_and_compute_union() says:
@return
trueif the output surface mesh is manifold and is put intotm_out.
With the two closed, valid, self-intersection-free meshes below, the function returns true, but the
output has a non-manifold (pinched) vertex: is_non_manifold_vertex() is true for one vertex and
is_valid_polygon_mesh() is false ("counting halfedges via vertices failed: 215 vs 222").
The input meshes:
box.off: a box (12 triangles), volume 124.4937.corner.off: a small closed solid (28 triangles), volume 6.0000, whose boundary contains a concave
edge (a tilted "floor" and a vertical "wall").
They do not overlap in volume: the volume of the union is exactly the sum, 130.4937. They touch:
- the box rests on the other solid: 7 pairs of coplanar triangles overlap (checked with exact
predicates); - one corner of the box, (43.12392044067383, 210.3898010253906, -61.54164123535156), lies exactly on
two faces ofcorner.off, on its concave edge.
The output vertex at that box corner is non-manifold.
Output with CGAL 6.0.1 and 6.2:
input: 12 faces, valid 1, closed 1, self-intersects 0, bounds a volume 1
input: 28 faces, valid 1, closed 1, self-intersects 0, bounds a volume 1
corefine_and_compute_union returned true
non-manifold vertex at 43.123920440673828 210.38980102539062 -61.541641235351562
counting halfedges via vertices failed: 215 vs 222
Halfedge Graph Structure is NOT VALID.
output: 74 faces, closed true, is_valid_polygon_mesh false
In our application the output of one union is the input of the next one (we merge several touching
bodies). With CGAL assertions enabled, the next corefine_and_compute_union() fails the precondition
CGAL::is_valid_polygon_mesh(tm) (Polygon_mesh_processing/orientation.h). In a release build the
precondition is not checked and the process crashes (access violation on Windows / MSVC).
We work around it by checking is_non_manifold_vertex() / is_valid_polygon_mesh() on every output
and calling duplicate_non_manifold_vertices() when it is the last union (and by merging the bodies in
an order that avoids the pinch in intermediate results).
We are not sure which of these is intended:
- the exact union really is non-manifold at that point, and the function should return
falseas
documented; - the union is manifold there, and the output builder should produce it (or duplicate the vertex, as
it seems to do for simpler point contacts: two cubes sharing only a corner, or the apex of a
tetrahedron touching an edge or a face of a cube, give a valid output); trueonly guarantees manifold edges. Then a note in the documentation would help, together with
a pointer toduplicate_non_manifold_vertices().
Source Code
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/IO/OFF.h>
#include <CGAL/Polygon_mesh_processing/corefinement.h>
#include <CGAL/Polygon_mesh_processing/manifoldness.h>
#include <CGAL/Polygon_mesh_processing/orientation.h>
#include <CGAL/Polygon_mesh_processing/self_intersections.h>
#include <CGAL/boost/graph/helpers.h>
#include <CGAL/version.h>
#include <iomanip>
#include <iostream>
namespace PMP = CGAL::Polygon_mesh_processing;
using K = CGAL::Exact_predicates_inexact_constructions_kernel;
using Mesh = CGAL::Surface_mesh<K::Point_3>;
int main(int argc, char** argv)
{
std::cout << "CGAL " << CGAL_VERSION_STR << "\n";
Mesh a, b, out;
if (argc < 3 || !CGAL::IO::read_OFF(argv[1], a) || !CGAL::IO::read_OFF(argv[2], b))
return 1;
for (const Mesh* m : {&a, &b})
std::cout << "input: " << num_faces(*m) << " faces, valid " << CGAL::is_valid_polygon_mesh(*m)
<< ", closed " << CGAL::is_closed(*m) << ", self-intersects "
<< PMP::does_self_intersect(*m) << ", bounds a volume "
<< PMP::does_bound_a_volume(*m) << "\n";
bool ok = PMP::corefine_and_compute_union(a, b, out);
std::cout << "corefine_and_compute_union returned " << std::boolalpha << ok << "\n";
for (auto v : vertices(out))
if (PMP::is_non_manifold_vertex(v, out))
std::cout << "non-manifold vertex at " << std::setprecision(17) << out.point(v) << "\n";
std::cout << "output: " << num_faces(out) << " faces, closed " << CGAL::is_closed(out)
<< ", is_valid_polygon_mesh " << CGAL::is_valid_polygon_mesh(out, true) << "\n";
return 0;
}
Run as ./repro box.off corner.off.
box.off:
OFF
8 12 0
47.558551788330078 214.37379455566406 -60.891750335693359
43.123920440673828 210.38980102539062 -61.541641235351562
46.547618865966797 214.37379455566406 -53.993431091308594
43.123920440673828 214.37379455566406 -61.541629791259766
42.112991333007812 210.38980102539062 -54.643318176269531
46.547618865966797 210.38980102539062 -53.993431091308594
47.558551788330078 210.38980102539062 -60.891750335693359
42.112991333007812 214.37379455566406 -54.643318176269531
3 1 0 6
3 1 3 0
3 3 2 0
3 3 7 2
3 5 1 6
3 5 4 1
3 2 4 5
3 2 7 4
3 5 6 2
3 0 2 6
3 4 7 1
3 1 7 3
corner.off:
OFF
16 28 0
43.123923806345644 211.38980102539062 -61.541637869679747
44.123920440673828 210.53634905484103 -61.395093205901176
42.123920440673828 211.38980102539062 -61.688185971410775
44.123920440673828 211.38980102539062 -61.395090754411044
42.123920440673828 210.38980102539062 -60.541641235351562
43.123920440673828 210.38980102539062 -60.541641235351562
42.123920440673828 210.38980102539062 -61.541641235351562
44.123920440673828 210.38980102539062 -60.541641235351562
44.123920440673828 210.38980102539062 -61.395093626851704
42.123920440673828 210.38980102539062 -61.688188843851421
44.123920440673828 211.38980102539062 -62.541641235351562
42.123920440673828 209.38980102539062 -60.541641235351562
42.123920440673828 211.38980102539062 -62.541641235351562
42.123920440673828 209.38980102539062 -62.541641235351562
44.123920440673828 209.38980102539062 -62.541641235351562
44.123920440673828 209.38980102539062 -60.541641235351562
3 9 0 2
3 1 3 0
3 0 8 1
3 4 5 6
3 5 7 8
3 6 5 8
3 6 8 9
3 13 12 10
3 1 10 3
3 13 14 15
3 0 10 12
3 5 15 7
3 10 14 13
3 7 15 8
3 15 11 13
3 4 6 11
3 10 1 14
3 15 5 11
3 2 0 12
3 3 10 0
3 6 13 11
3 5 4 11
3 2 12 9
3 9 12 13
3 6 9 13
3 14 1 8
3 14 8 15
3 0 9 8
Environment
- Operating system: Linux (Ubuntu 24.04, WSL2), 64 bits. Also seen on Windows 11 (MSVC 14.51), where
chaining the next union crashes in release. - Compiler: GCC 13,
-O2 -std=c++17 -frounding-math -DNDEBUG - Release or debug mode: release (the precondition failure in the chained union appears in debug)
- Specific flags used (if any): see above
- CGAL version: 6.0.1 and 6.2
- Boost version: 1.83
- Other libraries versions if used (Eigen, TBB, etc.): GMP 6.3, MPFR 4.2 (Sequential_tag, no TBB)
- Dominant language
- C++
- Stars
- 6.1k
- Forks
- 1.6k
- Avg merge
- 3d 19h
- Merged PRs (30d)
- 55
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from CGAL/cgal
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Maintainers usually reply within 3 days
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
Maintainers usually reply within 3 days
-
Allow cancellable CGAL operationsPossibly taken @AbhaySharma2009 claimed this 9 days ago. Open
Difficulty 5/5 Over a week Newbie friendliness 25/100
Maintainers usually reply within 3 days
-
Snap_rounding_2: kd-tree query returns mostly false hot-pixel candidates for diagonal segments, and each query is costly with EpeckPossibly taken @LeoValque claimed this 9 days ago. OpenPkg::Snap_rounding_2
Maintainers usually reply within 3 days
-
Pkg::Kernel_23
Difficulty 4/5 3-5 days Newbie friendliness 25/100
CGAL/cgal#9814 · 11 comments ·
Maintainers usually reply within 3 days
Similar issues
-
RTL-SDR: re-enumerating while streaming removes the in-use entry from the device selection dialogPossibly taken @dpc00 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
throneproj/Throne#2227 ·
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
deepseek-ai/DeepGEMM-Ascend#49 ·
Maintainers usually reply within 1 day
-
bug needs testing platform:windows topic:buildsystem topic:platforms
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
godotengine/godot#126110 · 1 comment ·
Maintainers usually reply within 1 day