Easy3D 2.6.1
Loading...
Searching...
No Matches
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
47 class OverlappingFaces
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
82 unsigned int remove(
83 SurfaceMesh *mesh,
84 bool folding_faces = false,
85 double dist_threshold = 1e-6
86 );
87
88 private:
89 typedef CGAL::Simple_cartesian<double> Kernel;
90
91 typedef CGAL::Point_3<Kernel> Point_3;
92 typedef CGAL::Vector_3<Kernel> Vector_3;
93 typedef CGAL::Triangle_3<Kernel> Triangle_3;
94
95 struct Triangle {
96 Triangle(const Point_3& a, const Point_3& b, const Point_3& c, SurfaceMesh::Face f) : triangle(a, b, c), face(f) {}
97 Triangle_3 triangle;
99 std::vector<SurfaceMesh::Vertex> vertices;
100 };
101
102 // Axis-align boxes for all-pairs self-intersection detection
103 typedef std::vector<Triangle> Triangles;
104 typedef Triangles::iterator TrianglesIterator;
105 typedef CGAL::Box_intersection_d::Box_with_handle_d<double, 3, TrianglesIterator> Box;
106
107 private:
108 Triangles mesh_to_cgal_triangle_list(SurfaceMesh* esh);
109
110 // test if two triangles duplicate
111 enum OverlapType {OT_NONE, OT_SAME, OT_FOLDING};
112 OverlapType do_overlap(const Triangle& A, const Triangle& B, double sqr_eps);
113
114 Triangles triangle_faces_;
115 };
116
117} // namespace easy3d
118
119#endif // EASY_ALGO_EXT_OVERLAPPING_FACES_H
unsigned int remove(SurfaceMesh *mesh, bool folding_faces=false, double dist_threshold=1e-6)
Removes duplicate faces 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:51
Definition collider.cpp:182
Definition surface_mesh.h:191