-
After an unsuccessful attempt to perform a Boolean union operation via C++ code, I tried to perform it via CGAL_PMP.exe , but apparently I get similar results there[18:45:06] WARNING: The result of the requested operation is not manifold and has not been computed.Source CodeI'm trying to use this:typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Polyhedron_3<K, CGAL::Polyhedron_items_with_id_3> Mesh;
namespace PMP = CGAL::Polygon_mesh_processing;
PMP::corefine_and_compute_union(mesh1, mesh2, out) But it for this two meshes - 59-one and 59-two.zip<59-one.off - mesh1><59-two.off - mesh2>always returns false, because insidecorefine_and_compute_boolean_operations(... ...){
...
return CGAL::make_array( //410
ob.union_is_valid(), //411 - returns false
ob.intersection_is_valid(), //412
ob.tm1_minus_tm2_is_valid(), //413
ob.tm2_minus_tm1_is_valid()); //414
} Previously, I have already checked mesh1 and mesh2 in the special FixMesh.h methodtypedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Polyhedron_3<K, CGAL::Polyhedron_items_with_id_3> Mesh;
namespace PMP = CGAL::Polygon_mesh_processing;
int FixMesh(Mesh& mesh, bool logExept = false) {
// Сшивание граничных рёбер
PMP::stitch_borders(mesh);
// Исправление самопересечений
std::vector<std::pair<Mesh::Facet_const_handle, Mesh::Facet_const_handle>> self_intersections;
std::cout << "e/p/i [" << mesh.edges().size() << "/" << mesh.points().size();
PMP::self_intersections(mesh, std::back_inserter(self_intersections));
std::cerr << "/" << self_intersections.size() << "] ";
if (!self_intersections.empty()) {
try {
if (PMP::remove_degenerate_faces(mesh)) {
std::cout << "deg_faces: success ";
}
else{
std::cout << "deg_faces: failed!" << std::endl;
return 1;
}
if (PMP::remove_degenerate_edges(mesh)) {
std::cout << "deg_edges: success ";
}
else {
std::cout << "deg_edges: failed!" << std::endl;
return 1;
}
if (PMP::experimental::autorefine_and_remove_self_intersections(mesh, CGAL::parameters::preserve_genus(false))) {
std::cout << "perair: success ";
}
else {
std::cout << "perair: failed!" << std::endl;
return 1;
}
}
catch (const std::exception& e) {
std::cout << "perair: exception!" << std::endl;
if (logExept) {
std::cerr << e.what();
}
return 1;
}
}
// Исправление ориентации
if (!PMP::is_outward_oriented(mesh)) {
std::cerr << "Mesh is not outward oriented. Attempting to orient..." << std::endl;
PMP::orient(mesh);
}
// Проверка корректности после обработки
if (!CGAL::is_valid(mesh)) {
std::cerr << "Mesh is not valid after processing." << std::endl;
}
return 0;
} Environment
Can I correct the input data using some additional method to get the result of the union?Thanks!Updated (07.08)At the moment, I managed to get rid of the error of performing a Boolean operation on a Mesh only by applying this method with all its methods inside for both meshes as well as for the result. This is very strong (especially the PMP::experimental::autorefine(mesh) method) performance was hit.#pragma once
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Polyhedron_items_with_id_3.h>
#include <CGAL/Polygon_mesh_processing/corefinement.h>
#include <CGAL/Polygon_mesh_processing/stitch_borders.h>
#include <CGAL/Polygon_mesh_processing/orientation.h>
#include <CGAL/Polygon_mesh_processing/self_intersections.h>
#include <CGAL/Polygon_mesh_processing/repair_self_intersections.h>
#include <CGAL/Polygon_mesh_processing/stitch_borders.h>
#include <CGAL/Polygon_mesh_processing/merge_border_vertices.h>
#include <CGAL/Polygon_mesh_processing/manifoldness.h>
#include <vector>
#include <iostream>
#include <CGAL/Polygon_mesh_processing/repair.h>
#include <CGAL/Polygon_mesh_processing/polygon_mesh_to_polygon_soup.h>
#include <CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h>
#include "my_timer.h"
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Polyhedron_3<K, CGAL::Polyhedron_items_with_id_3> Mesh;
namespace PMP = CGAL::Polygon_mesh_processing;
bool fix_mesh(Mesh& mesh) {
std::vector<std::array<FT, 3> > points;
std::vector<std::vector<int>> polygons;
PMP::polygon_mesh_to_polygon_soup(mesh, points, polygons);
PMP::repair_polygon_soup(points, polygons, CGAL::parameters::geom_traits(Array_traits()));
if (!PMP::is_polygon_soup_a_polygon_mesh(polygons)) {
return false;
}
mesh.clear();
PMP::polygon_soup_to_polygon_mesh(points, polygons, mesh);
PMP::stitch_borders(mesh);
PMP::duplicate_non_manifold_vertices(mesh);
PMP::merge_duplicated_vertices_in_boundary_cycles(mesh);
PMP::remove_connected_components_of_negligible_size(mesh);
PMP::remove_isolated_vertices(mesh);
PMP::remove_degenerate_faces(mesh);
PMP::remove_degenerate_edges(mesh);
if (PMP::does_self_intersect(mesh)) {
if (!PMP::experimental::remove_self_intersections(mesh)) {
return false;
}
}
if (!PMP::is_outward_oriented(mesh)) {
PMP::orient(mesh);
}
PMP::experimental::autorefine(mesh);
return CGAL::is_valid_polygon_mesh(mesh);
}
Is there a better way (equally reliable, but less costly) to correct geometry before and after a Boolean operation? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
As you pointed out, the union is returning The input are not invalid so there is nothing to "fix". I don't understand why you are using the experimental Or even the one operating on triangle soups: |
Beta Was this translation helpful? Give feedback.
-
I get |
Beta Was this translation helpful? Give feedback.
-
The problem was solved by using union rather than difference, as well as using bounding_box for some complex Meshes |
Beta Was this translation helpful? Give feedback.
The problem was solved by using union rather than difference, as well as using bounding_box for some complex Meshes