Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fast-csg] Support for upcoming CGAL remeshing #4107

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Expand Up @@ -65,6 +65,7 @@ if(APPLE)
endif()

option(ENABLE_TESTS "Run testsuite after building." ON)
option(ENABLE_CGAL_REMESHING "Enable usage of CGAL's branch-experimental remeshing (https://github.com/CGAL/cgal/pull/5461)" OFF)
set(SUFFIX "" CACHE STRING "Installation suffix for binary (e.g. 'nightly')")
set(STACKSIZE 8388608 CACHE STRING "Stack size (default is 8MB)")

Expand Down Expand Up @@ -303,6 +304,9 @@ target_compile_definitions(OpenSCAD PRIVATE ENABLE_CGAL)
# on bad geometry input.
target_compile_definitions(OpenSCAD PRIVATE CGAL_DEBUG)
target_compile_definitions(OpenSCAD PRIVATE CGAL_USE_GMPXX)
if(ENABLE_CGAL_REMESHING)
target_compile_definitions(OpenSCAD PRIVATE ENABLE_CGAL_REMESHING)
endif()
if(TARGET CGAL::CGAL)
list(APPEND COMMON_LIBRARIES CGAL::CGAL CGAL::CGAL_Core)
message(STATUS "CGAL: Using target CGAL::CGAL CGAL::CGAL_Core")
Expand Down Expand Up @@ -719,6 +723,7 @@ set(CGAL_SOURCES
src/cgalutils-orient.cc
src/cgalutils-polyhedron.cc
src/cgalutils-project.cc
src/cgalutils-repair.cc
src/cgalutils-tess.cc
src/cgalutils-triangulate.cc
src/export_nef.cc
Expand Down
1 change: 1 addition & 0 deletions src/CGALHybridPolyhedron.cc
Expand Up @@ -5,6 +5,7 @@
#include "hash.h"
#include <CGAL/Surface_mesh.h>
#include <CGAL/boost/graph/helpers.h>
#include <CGAL/Polygon_mesh_processing/corefinement.h>
#include <fstream>
#include <sstream>
#include <stdio.h>
Expand Down
7 changes: 7 additions & 0 deletions src/cgalutils-mesh.cc
Expand Up @@ -125,6 +125,13 @@ template void convertNefPolyhedronToTriangleMesh(const CGAL::Nef_polyhedron_3<CG
void cleanupMesh(CGAL::Surface_mesh<CGAL::Point_3<CGAL_HybridKernel3>>& mesh, bool is_corefinement_result)
{
mesh.collect_garbage();

#ifdef ENABLE_CGAL_REMESHING
if (is_corefinement_result && Feature::ExperimentalFastCsgRemesh.is_enabled()) {
CGALUtils::remeshPlanarPatches(mesh);
}
#endif // ENABLE_CGAL_REMESHING

#if FAST_CSG_KERNEL_IS_LAZY
// If exact corefinement callbacks are enabled, no need to make numbers exact here again.
auto make_exact =
Expand Down
21 changes: 21 additions & 0 deletions src/cgalutils-repair.cc
@@ -0,0 +1,21 @@
// Portions of this file are Copyright 2021 Google LLC, and licensed under GPL2+. See COPYING.
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#ifdef ENABLE_CGAL_REMESHING
#include <CGAL/Polygon_mesh_processing/remesh_planar_patches.h>
#endif
#include <CGAL/Surface_mesh.h>

namespace CGALUtils {

#ifdef ENABLE_CGAL_REMESHING
template <typename M>
bool remeshPlanarPatches(M &mesh)
{
CGAL::Polygon_mesh_processing::remesh_planar_patches(mesh);
}

template bool remeshPlanarPatches(CGAL::Surface_mesh<CGAL::Point_3<CGAL::Epeck>> &mesh);
#endif

} // namespace CGALUtils

4 changes: 4 additions & 0 deletions src/cgalutils.h
Expand Up @@ -143,6 +143,10 @@ template <typename K>
bool corefineAndComputeIntersection(CGAL::Surface_mesh<CGAL::Point_3<K>>& lhs, CGAL::Surface_mesh<CGAL::Point_3<K>>& rhs, CGAL::Surface_mesh<CGAL::Point_3<K>>& out);
template <typename K>
bool corefineAndComputeDifference(CGAL::Surface_mesh<CGAL::Point_3<K>>& lhs, CGAL::Surface_mesh<CGAL::Point_3<K>>& rhs, CGAL::Surface_mesh<CGAL::Point_3<K>>& out);
#ifdef ENABLE_CGAL_REMESHING
template <typename M>
bool remeshPlanarPatches(M &mesh);
#endif

template <typename K>
void convertNefPolyhedronToTriangleMesh(const CGAL::Nef_polyhedron_3<K>& nef, CGAL::Surface_mesh<CGAL::Point_3<K>>& mesh);
Expand Down
3 changes: 3 additions & 0 deletions src/feature.cc
Expand Up @@ -37,6 +37,9 @@ const Feature Feature::ExperimentalFastCsgDebug("fast-csg-debug", "Debug mode fo
const Feature Feature::ExperimentalFastCsgExact("fast-csg-exact", "Force lazy numbers to exact after each CSG operation.");
const Feature Feature::ExperimentalFastCsgExactCorefinementCallback("fast-csg-exact-callbacks", "Same as fast-csg-exact but even forces exact numbers inside corefinement callbacks rather than at the end of each operation.");
#endif // FAST_CSG_KERNEL_IS_LAZY
#ifdef ENABLE_CGAL_REMESHING
const Feature Feature::ExperimentalFastCsgRemesh("fast-csg-remesh", "Simplify meshes after each corefinement operation. HIGHLY RECOMMENDED esp for models that are hanging.");
#endif // ENABLE_CGAL_REMESHING
const Feature Feature::ExperimentalRoof("roof", "Enable <code>roof</code>");
const Feature Feature::ExperimentalInputDriverDBus("input-driver-dbus", "Enable DBus input drivers (requires restart)");
const Feature Feature::ExperimentalLazyUnion("lazy-union", "Enable lazy unions.");
Expand Down
1 change: 1 addition & 0 deletions src/feature.h
Expand Up @@ -18,6 +18,7 @@ class Feature
static const Feature ExperimentalFastCsgTrustCorefinement;
static const Feature ExperimentalFastCsgDebug;
static const Feature ExperimentalFastCsgExact;
static const Feature ExperimentalFastCsgRemesh;
static const Feature ExperimentalFastCsgExactCorefinementCallback;
static const Feature ExperimentalRoof;
static const Feature ExperimentalInputDriverDBus;
Expand Down