Easy3D 2.6.1
Loading...
Searching...
No Matches
surface_mesh_hole_filling.h
1/********************************************************************
2 * Copyright (C) 2020-2021 by Liangliang Nan <liangliang.nan@gmail.com>
3 * Copyright (C) 2011-2020 the Polygon Mesh Processing Library developers.
4 *
5 * The code in this file is adapted from the PMP (Polygon Mesh Processing
6 * Library) with modifications.
7 * https://github.com/pmp-library/pmp-library
8 * The original code was distributed under a MIT-style license, see
9 * https://github.com/pmp-library/pmp-library/blob/master/LICENSE.txt
10 ********************************************************************/
11
12#ifndef EASY3D_ALGO_SURFACE_MESH_HOLE_FILLING_H
13#define EASY3D_ALGO_SURFACE_MESH_HOLE_FILLING_H
14
15#include <vector>
16#include <cfloat>
17
18#include <easy3d/core/surface_mesh.h>
19
20
21namespace easy3d {
22
32 public:
37 explicit SurfaceMeshHoleFilling(SurfaceMesh *mesh);
38
45
52 int fill_holes(int size = 500);
53
54 private:
55 struct Weight {
56 explicit Weight(float _angle = FLT_MAX, float _area = FLT_MAX)
57 : angle(_angle), area(_area) {
58 }
59
60 Weight operator+(const Weight &_rhs) const {
61 return Weight(std::max(angle, _rhs.angle), area + _rhs.area);
62 }
63
64 bool operator<(const Weight &_rhs) const {
65 return (angle < _rhs.angle ||
66 (angle == _rhs.angle && area < _rhs.area));
67 }
68
69 float angle;
70 float area;
71 };
72
73 private:
74 // compute optimal triangulation of hole
75 bool triangulate_hole(SurfaceMesh::Halfedge h);
76
77 // compute the weight of the triangle (i,j,k).
78 Weight compute_weight(int i, int j, int k) const;
79
80 // refine triangulation (isotropic remeshing)
81 void refine();
82
83 void split_long_edges(float lmax);
84
85 void collapse_short_edges(float lmin);
86
87 void flip_edges();
88
89 void relaxation();
90
91 void fairing();
92
93 private:
94 // return i'th vertex of hole
95 SurfaceMesh::Vertex hole_vertex(unsigned int i) const {
96 if (i < hole_.size())
97 return mesh_->target(hole_[i]);
98 else {
99 LOG(ERROR) << "index of hole edge is out of range";
100 return SurfaceMesh::Vertex{};
101 }
102 }
103
104 // return vertex opposite edge (i-1,i)
105 SurfaceMesh::Vertex opposite_vertex(unsigned int i) const {
106 if (i < hole_.size())
107 return mesh_->target(mesh_->next(mesh_->opposite(hole_[i])));
108 else {
109 LOG(ERROR) << "index of hole edge is out of range";
110 return SurfaceMesh::Vertex{};
111 }
112 }
113
114 // does interior edge (_a,_b) exist already?
115 bool is_interior_edge(SurfaceMesh::Vertex _a, SurfaceMesh::Vertex _b) const;
116
117 // triangle area
118 float compute_area(SurfaceMesh::Vertex _a, SurfaceMesh::Vertex _b, SurfaceMesh::Vertex _c) const;
119
120 // triangle normal
121 vec3 compute_normal(SurfaceMesh::Vertex _a, SurfaceMesh::Vertex _b, SurfaceMesh::Vertex _c) const;
122
123 // dihedral angle
124 float compute_angle(const vec3 &_n1, const vec3 &_n2) const;
125
126 private:
127 // mesh and properties
128 SurfaceMesh *mesh_;
129 SurfaceMesh::VertexProperty <vec3> points_;
132
133 std::vector<SurfaceMesh::Halfedge> hole_;
134
135 // data for computing optimal triangulation
136 std::vector<std::vector<Weight>> weight_;
137 std::vector<std::vector<int>> index_;
138 };
139
140}
141
142#endif // EASY3D_ALGO_SURFACE_MESH_HOLE_FILLING_H
Edge property of type T.
Definition surface_mesh.h:327
Vertex property of type T.
Definition surface_mesh.h:255
SurfaceMeshHoleFilling(SurfaceMesh *mesh)
Construct with mesh.
Definition surface_mesh_hole_filling.cpp:26
int fill_holes(int size=500)
Fill all holes with size smaller than the specified size.
Definition surface_mesh_hole_filling.cpp:99
bool fill_hole(SurfaceMesh::Halfedge h)
Fill the hole specified by halfedge h.
Definition surface_mesh_hole_filling.cpp:64
A halfedge data structure for polygonal meshes of 2-manifold.
Definition surface_mesh.h:51
Definition collider.cpp:182
Matrix< FT > operator+(const Matrix< FT > &, const FT &)
Definition matrix.h:1010
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition types.h:44
bool operator<(const Vec< N, T > &a, const Vec< N, T > &b)
Lexicographic comparison of two vectors.
Definition vec.h:1008
This type represents a halfedge (internally it is basically an index).
Definition surface_mesh.h:155
This type represents a vertex (internally it is basically an index).
Definition surface_mesh.h:135