Skip to content

Instantly share code, notes, and snippets.

@ochafik
Last active March 1, 2022 22:54
Show Gist options
  • Select an option

  • Save ochafik/61568f7f547bc67a0f2ecec8ad5f9ce6 to your computer and use it in GitHub Desktop.

Select an option

Save ochafik/61568f7f547bc67a0f2ecec8ad5f9ce6 to your computer and use it in GitHub Desktop.
Repro test case for suspicion of T-junctions in CGAL corefinement output; probably just "nearly-degenerate" faces though
// Copyright 2021 Google LLC.
// SPDX-License-Identifier: Apache-2.0
// Context: https://github.com/openscad/openscad/pull/4117#issuecomment-1053731672
/*
g++ -stdlib=libc++ -std=c++1y -lgmp -lmpfr repro-tjunctions-union.cc -o repro-tju && ./repro-tju > tjunct.off
*/
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Polygon_mesh_processing/repair.h>
#include <CGAL/Polygon_mesh_processing/corefinement.h>
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
#include <CGAL/Surface_mesh.h>
#include <fstream>
namespace PMP = CGAL::Polygon_mesh_processing;
int main(int argc, char *argv[])
{
typedef CGAL::Epeck Kernel;
typedef CGAL::Surface_mesh<CGAL::Point_3<Kernel>> Mesh;
typedef boost::graph_traits<Mesh> GT;
typedef typename GT::face_descriptor face_descriptor;
typedef typename GT::halfedge_descriptor halfedge_descriptor;
typedef typename GT::edge_descriptor edge_descriptor;
typedef typename GT::vertex_descriptor vertex_descriptor;
typedef typename CGAL::Kernel_traits<typename Mesh::Point>::Kernel Kernel;
auto read = [&](auto&mesh, auto source) {
std::stringstream ss;
ss << source;
ss >> mesh;
assert(CGAL::is_closed(mesh));
assert(CGAL::is_valid_halfedge_graph(mesh, /* verb */ false));
};
Mesh lhs, rhs;
read(lhs, "OFF\n\
8 12 0\n\
\n\
0.517599 -0.00842033 0.990969\n\
1.51729 0.00902941 0.973517\n\
1.50015 1.00873 0.990967\n\
0.500454 0.99128 1.00842\n\
0.482702 1.00843 0.00872355\n\
1.4824 1.02588 -0.00872886\n\
1.49954 0.0261746 -0.0261786\n\
0.499848 0.00872487 -0.0087262\n\
3 3 0 1\n\
3 7 4 5\n\
3 0 7 6\n\
3 1 6 5\n\
3 2 5 4\n\
3 0 3 4\n\
3 1 2 3\n\
3 5 6 7\n\
3 6 1 0\n\
3 5 2 1\n\
3 4 3 2\n\
3 4 7 0\n\
");
read(rhs, "OFF\n\
8 12 0\n\
\n\
0.0177517 -0.0171452 0.999695\n\
1.01745 0.00030454 0.982243\n\
1.0003 1.00001 0.999693\n\
0.000606469 0.982556 1.01715\n\
-0.0171452 0.999701 0.0174497\n\
0.98255 1.01715 -2.65809e-06\n\
0.999695 0.0174497 -0.0174524\n\
0 0 0\n\
3 2 3 0\n\
3 7 4 5\n\
3 0 7 6\n\
3 1 6 5\n\
3 3 2 5\n\
3 3 4 7\n\
3 0 1 2\n\
3 5 6 7\n\
3 6 1 0\n\
3 5 2 1\n\
3 5 4 3\n\
3 7 0 3\n\
");
auto result = PMP::corefine_and_compute_union(lhs, rhs, lhs);
assert(result);
// No effect: its already triangular
// PMP::triangulate_faces(lhs);
// Output closed and valid
assert(CGAL::is_closed(lhs));
assert(CGAL::is_valid_halfedge_graph(lhs, /* verb */ false));
// No self-intersections
std::vector<std::pair<face_descriptor, face_descriptor>> selfIntersectionPairs;
PMP::self_intersections(lhs.faces(), lhs, back_inserter(selfIntersectionPairs));
assert(selfIntersectionPairs.empty());
// No non-manifold vertices detected
auto addedVertexCount = PMP::duplicate_non_manifold_vertices(lhs);
assert(addedVertexCount == 0);
std::cout << lhs;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment