Easy3D 2.5.3
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:
34 explicit SurfaceMeshHoleFilling(SurfaceMesh *mesh);
35
38
39 private:
40 struct Weight {
41 explicit Weight(float _angle = FLT_MAX, float _area = FLT_MAX)
42 : angle(_angle), area(_area) {
43 }
44
45 Weight operator+(const Weight &_rhs) const {
46 return Weight(std::max(angle, _rhs.angle), area + _rhs.area);
47 }
48
49 bool operator<(const Weight &_rhs) const {
50 return (angle < _rhs.angle ||
51 (angle == _rhs.angle && area < _rhs.area));
52 }
53
54 float angle;
55 float area;
56 };
57
58 private:
59 // compute optimal triangulation of hole
60 bool triangulate_hole(SurfaceMesh::Halfedge h);
61
62 // compute the weight of the triangle (i,j,k).
63 Weight compute_weight(int i, int j, int k) const;
64
65 // refine triangulation (isotropic remeshing)
66 void refine();
67
68 void split_long_edges(float lmax);
69
70 void collapse_short_edges(float lmin);
71
72 void flip_edges();
73
74 void relaxation();
75
76 void fairing();
77
78 private:
79 // return i'th vertex of hole
80 SurfaceMesh::Vertex hole_vertex(unsigned int i) const {
81 if (i < hole_.size())
82 return mesh_->target(hole_[i]);
83 else {
84 LOG(ERROR) << "index of hole edge is out of range";
85 return SurfaceMesh::Vertex{};
86 }
87 }
88
89 // return vertex opposite edge (i-1,i)
90 SurfaceMesh::Vertex opposite_vertex(unsigned int i) const {
91 if (i < hole_.size())
92 return mesh_->target(mesh_->next(mesh_->opposite(hole_[i])));
93 else {
94 LOG(ERROR) << "index of hole edge is out of range";
95 return SurfaceMesh::Vertex{};
96 }
97 }
98
99 // does interior edge (_a,_b) exist already?
100 bool is_interior_edge(SurfaceMesh::Vertex _a, SurfaceMesh::Vertex _b) const;
101
102 // triangle area
103 float compute_area(SurfaceMesh::Vertex _a, SurfaceMesh::Vertex _b, SurfaceMesh::Vertex _c) const;
104
105 // triangle normal
106 vec3 compute_normal(SurfaceMesh::Vertex _a, SurfaceMesh::Vertex _b, SurfaceMesh::Vertex _c) const;
107
108 // dihedral angle
109 float compute_angle(const vec3 &_n1, const vec3 &_n2) const;
110
111 private:
112 // mesh and properties
113 SurfaceMesh *mesh_;
117
118 std::vector<SurfaceMesh::Halfedge> hole_;
119
120 // data for computing optimal triangulation
121 std::vector<std::vector<Weight>> weight_;
122 std::vector<std::vector<int>> index_;
123 };
124
125}
126
127#endif // EASY3D_ALGO_SURFACE_MESH_HOLE_FILLING_H
Definition: surface_mesh.h:233
Definition: surface_mesh.h:185
This class closes simple holes in a surface mesh.
Definition: surface_mesh_hole_filling.h:31
SurfaceMeshHoleFilling(SurfaceMesh *mesh)
construct with mesh
Definition: surface_mesh_hole_filling.cpp:26
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:52
Halfedge opposite(Halfedge h) const
returns the opposite halfedge of h
Definition: surface_mesh.h:1260
Vertex target(Halfedge h) const
returns the vertex the halfedge h points to
Definition: surface_mesh.h:1211
Halfedge next(Halfedge h) const
returns the next halfedge within the incident face
Definition: surface_mesh.h:1241
Definition: collider.cpp:182
Matrix< FT > operator+(const Matrix< FT > &, const FT &)
Definition: matrix.h:990
bool operator<(const Vec< N, T > &a, const Vec< N, T > &b)
Lexicographic comparison of two vectors.
Definition: vec.h:782
Definition: surface_mesh.h:114
Definition: surface_mesh.h:104