Easy3D 2.5.3
surface_mesh_geodesic.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_GEODESIC_H
13#define EASY3D_ALGO_SURFACE_MESH_GEODESIC_H
14
15#include <easy3d/core/surface_mesh.h>
16#include <vector>
17#include <set>
18#include <cfloat>
19#include <climits>
20
21namespace easy3d {
22
32 public:
37 explicit SurfaceMeshGeodesic(SurfaceMesh *mesh, bool use_virtual_edges = true);
38
39 // destructor
41
51 unsigned int compute(const std::vector<SurfaceMesh::Vertex> &seed,
52 float max_dist = FLT_MAX,
53 unsigned int max_num = INT_MAX,
54 std::vector<SurfaceMesh::Vertex> *neighbors = nullptr);
55
62 float operator()(SurfaceMesh::Vertex v) const { return distance_[v]; }
63
69
70 private: // private types
71 // functor for comparing two vertices w.r.t. their geodesic distance
72 class VertexCmp {
73 public:
74 explicit VertexCmp(const SurfaceMesh::VertexProperty<float> &dist) : dist_(dist) {}
75
76 bool operator()(SurfaceMesh::Vertex v0, SurfaceMesh::Vertex v1) const {
77 return ((dist_[v0] == dist_[v1]) ? (v0 < v1)
78 : (dist_[v0] < dist_[v1]));
79 }
80
81 private:
82 const SurfaceMesh::VertexProperty<float> &dist_;
83 };
84
85 // priority queue using geodesic distance as sorting criterion
86 typedef std::set<SurfaceMesh::Vertex, VertexCmp> PriorityQueue;
87
88 // virtual edges for walking through obtuse triangles
89 struct VirtualEdge {
90 VirtualEdge(SurfaceMesh::Vertex v, float l) : vertex(v), length(l) {}
91
92 SurfaceMesh::Vertex vertex;
93 float length;
94 };
95
96 // set for storing virtual edges
97 typedef std::map<SurfaceMesh::Halfedge, VirtualEdge> VirtualEdges;
98
99 private: // private methods
100 void find_virtual_edges();
101
102 unsigned int init_front(const std::vector<SurfaceMesh::Vertex> &seed,
103 std::vector<SurfaceMesh::Vertex> *neighbors);
104
105 unsigned int propagate_front(float max_dist, unsigned int max_num,
106 std::vector<SurfaceMesh::Vertex> *neighbors);
107
108 void heap_vertex(SurfaceMesh::Vertex v);
109
110 float distance(SurfaceMesh::Vertex v0, SurfaceMesh::Vertex v1, SurfaceMesh::Vertex v2, float r0 = FLT_MAX,
111 float r1 = FLT_MAX);
112
113 private: // private data
114 SurfaceMesh *mesh_;
115
116 bool use_virtual_edges_;
117 VirtualEdges virtual_edges_;
118
119 PriorityQueue *front_;
120
121 SurfaceMesh::VertexProperty<float> distance_;
122 SurfaceMesh::VertexProperty<bool> processed_;
123 };
124
125} // namespace easy3d
126
127
128#endif // EASY3D_ALGO_SURFACE_MESH_GEODESIC_H
This class computes geodesic distance from a set of seed vertices.
Definition: surface_mesh_geodesic.h:31
float operator()(SurfaceMesh::Vertex v) const
Access the computed geodesic distance.
Definition: surface_mesh_geodesic.h:62
void distance_to_texture_coordinates()
Use the normalized distances as texture coordinates.
Definition: surface_mesh_geodesic.cpp:387
unsigned int compute(const std::vector< SurfaceMesh::Vertex > &seed, float max_dist=FLT_MAX, unsigned int max_num=INT_MAX, std::vector< SurfaceMesh::Vertex > *neighbors=nullptr)
Compute geodesic distances from specified seed points.
Definition: surface_mesh_geodesic.cpp:134
SurfaceMeshGeodesic(SurfaceMesh *mesh, bool use_virtual_edges=true)
Construct from mesh.
Definition: surface_mesh_geodesic.cpp:17
A halfedge data structure for polygonal meshes of 2-manifold.
Definition: surface_mesh.h:52
Definition: collider.cpp:182
T length(const Vec< N, T > &v)
Computes the length/magnitude of a vector.
Definition: vec.h:289
Definition: surface_mesh.h:104