cgal icon indicating copy to clipboard operation
cgal copied to clipboard

Assertion Failure in `CGAL::Polygon_mesh_processing::clip` at clip.h:150

Open chudonghao opened this issue 1 month ago • 1 comments

Issue Details

When using CGAL::Polygon_mesh_processing::clip() to clip a hollow box mesh with a plane and clip_volume(true) parameter, an assertion failure occurs at line 150 in clip.h:

CGAL_assertion(Euler::can_add_face(vrts, tm));

Source Code

Here is a minimal reproducible example:

#include <gtest/gtest.h>

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Plane_3.h>
#include <CGAL/Polygon_mesh_processing/clip.h>
#include <CGAL/Surface_mesh.h>

TEST(cgal, clip) {
  using Kernel = CGAL::Epick;

  CGAL::Surface_mesh<Kernel::Point_3> mesh;
  
  // Outer vertices (bottom)
  auto vbo0 = mesh.add_vertex({-2, -2, -2});
  auto vbo1 = mesh.add_vertex({2, -2, -2});
  auto vbo2 = mesh.add_vertex({2, 2, -2});
  auto vbo3 = mesh.add_vertex({-2, 2, -2});
  
  // Inner vertices (bottom)
  auto vbi0 = mesh.add_vertex({-1, -1, -2});
  auto vbi1 = mesh.add_vertex({1, -1, -2});
  auto vbi2 = mesh.add_vertex({1, 1, -2});
  auto vbi3 = mesh.add_vertex({-1, 1, -2});

  // Outer vertices (top)
  auto vto0 = mesh.add_vertex({-2, -2, 2});
  auto vto1 = mesh.add_vertex({2, -2, 2});
  auto vto2 = mesh.add_vertex({2, 2, 2});
  auto vto3 = mesh.add_vertex({-2, 2, 2});
  
  // Inner vertices (top)
  auto vti0 = mesh.add_vertex({-1, -1, 2});
  auto vti1 = mesh.add_vertex({1, -1, 2});
  auto vti2 = mesh.add_vertex({1, 1, 2});
  auto vti3 = mesh.add_vertex({-1, 1, 2});

  // Bottom faces (hollow square)
  mesh.add_face(vbo1, vbo0, vbi0, vbi1);
  mesh.add_face(vbo2, vbo1, vbi1, vbi2);
  mesh.add_face(vbo3, vbo2, vbi2, vbi3);
  mesh.add_face(vbo0, vbo3, vbi3, vbi0);

  // Outer side faces
  mesh.add_face(vbo0, vbo1, vto1, vto0);
  mesh.add_face(vbo1, vbo2, vto2, vto1);
  mesh.add_face(vbo2, vbo3, vto3, vto2);
  mesh.add_face(vbo3, vbo0, vto0, vto3);

  // Top faces (hollow square)
  mesh.add_face(vto0, vto1, vti1, vti0);
  mesh.add_face(vto1, vto2, vti2, vti1);
  mesh.add_face(vto2, vto3, vti3, vti2);
  mesh.add_face(vto3, vto0, vti0, vti3);

  // Inner side faces
  mesh.add_face(vbi1, vbi0, vti0, vti1);
  mesh.add_face(vbi2, vbi1, vti1, vti2);
  mesh.add_face(vbi3, vbi2, vti2, vti3);
  mesh.add_face(vbi0, vbi3, vti3, vti0);

  CGAL::Polygon_mesh_processing::triangulate_faces(mesh);

  Kernel::Plane_3 plane(0, -1, 0, -1);

  // Assertion fails here
  CGAL::Polygon_mesh_processing::clip(mesh, plane, CGAL::parameters::clip_volume(true));
}

Mesh Description: The mesh is a hollow box (a box with a rectangular hole through it). The plane (0, -1, 0, -1) cuts horizontally through the mesh at y = -1.

Environment

  • CGAL version: 6.1

chudonghao avatar Dec 02 '25 09:12 chudonghao

Thanks a lot for the report. It should be fixed by https://github.com/CGAL/cgal/pull/9142

sloriot avatar Dec 10 '25 15:12 sloriot