corefine_and_compute_union() returns true but the output Surface_mesh has a non-manifold vertex (is_valid_polygon_mesh() is false)

Open
#9,892 5 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 3 days

@sloriot is already working on this.

Since Nov 29, 2026.

  • #9916 by @AlphaSparrow — open

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
12/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
cpp
Domain
cli

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

Doc Not a bug Pkg::PMP

Issue Details

The documentation of corefine_and_compute_union() says:

@return true if the output surface mesh is manifold and is put into tm_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 of corner.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:

  1. the exact union really is non-manifold at that point, and the function should return false as
    documented;
  2. 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);
  3. true only guarantees manifold edges. Then a note in the documentation would help, together with
    a pointer to duplicate_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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from CGAL/cgal

All issues in CGAL/cgal

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.