Easy3D 2.6.1
Loading...
Searching...
No Matches
surface_mesh_remeshing.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_REMESHING_H
13#define EASY3D_ALGO_SURFACE_MESH_REMESHING_H
14
15#include <easy3d/core/surface_mesh.h>
16
17namespace easy3d {
18
20
32 public:
37 explicit SurfaceMeshRemeshing(SurfaceMesh *mesh);
42
47 void uniform_remeshing(float edge_length, unsigned int iterations = 10,
48 bool use_projection = true);
49
56 void adaptive_remeshing(float min_edge_length, float max_edge_length,
57 float approx_error, unsigned int iterations = 10,
58 bool use_projection = true);
59
60 private:
61 void preprocessing();
62 void postprocessing();
63 void split_long_edges();
64 void collapse_short_edges();
65 void flip_edges();
66 void tangential_smoothing(unsigned int iterations);
67 void remove_caps();
68 vec3 minimize_squared_areas(SurfaceMesh::Vertex v);
69 vec3 weighted_centroid(SurfaceMesh::Vertex v);
70 void project_to_reference(SurfaceMesh::Vertex v);
71 bool is_too_long(SurfaceMesh::Vertex v0, SurfaceMesh::Vertex v1) const {
72 return distance(points_[v0], points_[v1]) >
73 4.0 / 3.0 * std::min(vsizing_[v0], vsizing_[v1]);
74 }
75
76 bool is_too_short(SurfaceMesh::Vertex v0, SurfaceMesh::Vertex v1) const {
77 return distance(points_[v0], points_[v1]) <
78 4.0 / 5.0 * std::min(vsizing_[v0], vsizing_[v1]);
79 }
80
81 private:
82 SurfaceMesh *mesh_;
83 SurfaceMesh *refmesh_;
84
85 bool use_projection_;
86 TriangleMeshKdTree *kd_tree_;
87
88 bool uniform_;
89 float target_edge_length_;
90 float min_edge_length_;
91 float max_edge_length_;
92 float approx_error_;
93
94 SurfaceMesh::VertexProperty <vec3> points_;
95 SurfaceMesh::VertexProperty <vec3> vnormal_;
96 SurfaceMesh::VertexProperty<bool> vfeature_;
97 SurfaceMesh::EdgeProperty<bool> efeature_;
98 SurfaceMesh::VertexProperty<bool> vlocked_;
99 SurfaceMesh::EdgeProperty<bool> elocked_;
100 SurfaceMesh::VertexProperty<float> vsizing_;
101
102 SurfaceMesh::VertexProperty <vec3> refpoints_;
103 SurfaceMesh::VertexProperty <vec3> refnormals_;
104 SurfaceMesh::VertexProperty<float> refsizing_;
105 };
106
107} // namespace easy3d
108
109#endif // EASY3D_ALGO_SURFACE_MESH_REMESHING_H
A halfedge data structure for polygonal meshes of 2-manifold.
Definition surface_mesh.h:51
SurfaceMeshRemeshing(SurfaceMesh *mesh)
Constructor that initializes the remeshing with a given mesh.
Definition surface_mesh_remeshing.cpp:24
void adaptive_remeshing(float min_edge_length, float max_edge_length, float approx_error, unsigned int iterations=10, bool use_projection=true)
Perform adaptive remeshing.
Definition surface_mesh_remeshing.cpp:70
~SurfaceMeshRemeshing()
Destructor.
void uniform_remeshing(float edge_length, unsigned int iterations=10, bool use_projection=true)
Perform uniform remeshing.
Definition surface_mesh_remeshing.cpp:37
A k-d tree for triangular surface meshes.
Definition triangle_mesh_kdtree.h:24
Definition collider.cpp:182
T distance(const Vec< N, T > &v1, const Vec< N, T > &v2)
Computes the distance between two vectors/points.
Definition vec.h:295
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition types.h:44
This type represents a vertex (internally it is basically an index).
Definition surface_mesh.h:135