Easy3D 2.5.3
overlapping_faces.h
1/********************************************************************
2 * Copyright (C) 2015 Liangliang Nan <liangliang.nan@gmail.com>
3 * https://3d.bk.tudelft.nl/liangliang/
4 *
5 * This file is part of Easy3D. If it is useful in your research/work,
6 * I would be grateful if you show your appreciation by citing it:
7 * ------------------------------------------------------------------
8 * Liangliang Nan.
9 * Easy3D: a lightweight, easy-to-use, and efficient C++ library
10 * for processing and rendering 3D data.
11 * Journal of Open Source Software, 6(64), 3255, 2021.
12 * ------------------------------------------------------------------
13 *
14 * Easy3D is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License Version 3
16 * as published by the Free Software Foundation.
17 *
18 * Easy3D is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ********************************************************************/
26
27#ifndef EASY_ALGO_EXT_OVERLAPPING_FACES_H
28#define EASY_ALGO_EXT_OVERLAPPING_FACES_H
29
30
31#include <vector>
32
33// Use this instead to mute errors resulting from bad CGAL assertions
34//#define CGAL_KERNEL_NO_ASSERTIONS
35
36#include <CGAL/Simple_cartesian.h>
37#include <CGAL/intersections.h> // Triangle-triangle intersection
38#include <CGAL/box_intersection_d.h>
39
40#include <easy3d/core/surface_mesh.h>
41
42
43namespace easy3d {
44
48 {
49 public:
50 OverlappingFaces() = default;
51 ~OverlappingFaces() = default;
52
64 void detect(
65 SurfaceMesh *mesh,
66 std::vector<std::pair<SurfaceMesh::Face, SurfaceMesh::Face > > &duplicate_faces,
67 std::vector<std::pair<SurfaceMesh::Face, SurfaceMesh::Face > > &folding_faces,
68 double dist_threshold = 1e-6
69 );
70
81 unsigned int remove(
82 SurfaceMesh *mesh,
83 bool folding_faces = false,
84 double dist_threshold = 1e-6
85 );
86
87 private:
88 typedef CGAL::Simple_cartesian<double> Kernel;
89
90 typedef CGAL::Point_3<Kernel> Point_3;
91 typedef CGAL::Vector_3<Kernel> Vector_3;
92 typedef CGAL::Triangle_3<Kernel> Triangle_3;
93
94 private:
95 struct Triangle {
96 public:
97 Triangle(const Point_3& a, const Point_3& b, const Point_3& c, SurfaceMesh::Face f) : triangle(a, b, c), face(f) {}
98 Triangle_3 triangle;
100 std::vector<SurfaceMesh::Vertex> vertices;
101 };
102
103 // Axis-align boxes for all-pairs self-intersection detection
104 typedef std::vector<Triangle> Triangles;
105 typedef typename Triangles::iterator TrianglesIterator;
106 typedef CGAL::Box_intersection_d::Box_with_handle_d<double, 3, TrianglesIterator> Box;
107
108 private:
109 Triangles mesh_to_cgal_triangle_list(SurfaceMesh* esh);
110
111 // test if two triangles duplicate
112 enum OverlapType {OT_NONE, OT_SAME, OT_FOLDING};
113 OverlapType do_overlap(const Triangle& A, const Triangle& B, double sqr_eps);
114
115 Triangles triangle_faces_;
116 };
117
118} // namespace easy3d
119
120#endif // EASY_ALGO_EXT_OVERLAPPING_FACES_H
Detects/Removes duplicate and folding faces for a triangle mesh.
Definition: overlapping_faces.h:48
unsigned int remove(SurfaceMesh *mesh, bool folding_faces=false, double dist_threshold=1e-6)
Removes duplicate faces and and folding faces.
Definition: overlapping_faces.cpp:188
void detect(SurfaceMesh *mesh, std::vector< std::pair< SurfaceMesh::Face, SurfaceMesh::Face > > &duplicate_faces, std::vector< std::pair< SurfaceMesh::Face, SurfaceMesh::Face > > &folding_faces, double dist_threshold=1e-6)
Detects duplicate faces and folding faces.
Definition: overlapping_faces.cpp:143
A halfedge data structure for polygonal meshes of 2-manifold.
Definition: surface_mesh.h:52
Definition: collider.cpp:182
Definition: surface_mesh.h:134