Easy3D 2.5.3
delaunay.h
1/********************************************************************
2 * Copyright (C) 2015-2021 by Liangliang Nan <liangliang.nan@gmail.com>
3 * Copyright (C) 2000-2005 INRIA - Project ALICE
4 *
5 * The code in this file is partly from OGF/Graphite (2.0 alpha-4) with
6 * modifications and enhancement:
7 * https://gforge.inria.fr/forum/forum.php?forum_id=11459
8 * The original code was distributed under the GNU GPL license.
9 ********************************************************************/
10
11#ifndef EASY3D_ALGO_DELAUNAY_H
12#define EASY3D_ALGO_DELAUNAY_H
13
14#include <cassert>
15
16#include <easy3d/core/types.h>
17
18
19namespace easy3d {
20
24
25 class Delaunay {
26
27 public:
30 explicit Delaunay(unsigned int dimension);
31
32 virtual ~Delaunay();
33
35 unsigned int dimension() const { return dimension_; }
36
38 unsigned int cell_size() const { return cell_size_; }
39
41 virtual void set_vertices(unsigned int nb_vertices, const float *vertices);
42
44 const float *vertices_ptr() const { return vertices_; }
45
47 const float *vertex_ptr(unsigned int i) const {
48 assert(i < nb_vertices());
49 return vertices_ + dimension() * i;
50 }
51
53 unsigned int nb_vertices() const { return nb_vertices_; }
54
56 unsigned int nb_cells() const { return nb_cells_; }
57
58 const int *cell_to_v() const { return cell_to_v_; }
59
60 const int *cell_to_cell() const { return cell_to_cell_; }
61
62 virtual unsigned int nearest_vertex(const float *p) const;
63
65 int cell_vertex(unsigned int c, unsigned int lv) const {
66 assert(c < nb_cells());
67 assert(lv < cell_size());
68 return cell_to_v_[c * cell_v_stride_ + lv];
69 }
70
71 int cell_adjacent(unsigned int c, unsigned int lf) const {
72 assert(c < nb_cells());
73 assert(lf < cell_size());
74 return cell_to_cell_[c * cell_neigh_stride_ + lf];
75 }
76
77 int vertex_cell(unsigned int v) const {
78 assert(v < nb_vertices());
79 assert(v < v_to_cell_.size());
80 return v_to_cell_[v];
81 }
82
83 unsigned int index(unsigned int c, int v) const {
84 assert(c < nb_cells());
85 assert(v < (int) nb_vertices());
86 for (unsigned int iv = 0; iv < cell_size(); iv++) {
87 if (cell_vertex(c, iv) == v) { return iv; }
88 }
89 DCHECK(false) << "should not have reached here";
90 return cell_size();
91 }
92
93 unsigned int adjacent_index(unsigned int c1, unsigned int c2) const {
94 assert(c1 < nb_cells());
95 assert(c2 < nb_cells());
96 for (unsigned int f = 0; f < cell_size(); f++) {
97 if (cell_adjacent(c1, f) == c2) { return f; }
98 }
99 DCHECK(false) << "should not have reached here";
100 return cell_size();
101 }
102
103 unsigned int next_around_vertex(unsigned int c, unsigned int lv) const {
104 assert(c < nb_cells());
105 assert(lv < cell_size());
106 return cicl_[cell_size() * c + lv];
107 }
108
112 virtual void get_neighbors(unsigned int v, std::vector<unsigned int> &neighbors) const;
113
114
120
121 protected:
122
123 void get_neighbors_internal(
124 unsigned int v, std::vector<unsigned int> &neighbors
125 ) const;
126
127 virtual void set_arrays(
128 unsigned int nb_cells, const int *cell_to_v, const int *cell_to_cell
129 );
130
131 void update_v_to_cell();
132
133 void update_cicl();
134
135 void update_neighbors();
136
137 void set_next_around_vertex(
138 unsigned int c1, unsigned int lv, unsigned int c2
139 ) {
140 assert(c1 < nb_cells());
141 assert(c2 < nb_cells());
142 assert(lv < cell_size());
143 cicl_[cell_size() * c1 + lv] = static_cast<int>(c2);
144 }
145
146 protected:
147 unsigned int dimension_;
148 unsigned int cell_size_;
149 unsigned int cell_v_stride_;
150 unsigned int cell_neigh_stride_;
151 const float *vertices_;
152 unsigned int nb_vertices_;
153 unsigned int nb_cells_;
154 const int *cell_to_v_;
155 const int *cell_to_cell_;
156 std::vector<int> v_to_cell_;
157 std::vector<int> cicl_;
158 std::vector <std::vector<unsigned int>> neighbors_;
159 bool is_locked_;
160 };
161
162} // namespace easy3d
163
164
165#endif // EASY3D_ALGO_DELAUNAY_H
166
Base class for Delaunay triangulation.
Definition: delaunay.h:25
const float * vertices_ptr() const
Returns the pointer to the vertices.
Definition: delaunay.h:44
unsigned int nb_cells() const
Returns the number of cells.
Definition: delaunay.h:56
unsigned int nb_vertices() const
Returns the number of vertices.
Definition: delaunay.h:53
const float * vertex_ptr(unsigned int i) const
Returns the pointer to the vertex of index i.
Definition: delaunay.h:47
int cell_vertex(unsigned int c, unsigned int lv) const
Returns the index of the lv_th vertex in the c_th cell.
Definition: delaunay.h:65
Delaunay(unsigned int dimension)
Constructor.
Definition: delaunay.cpp:34
bool check_duplicate_vertices()
Checks for duplicate vertices in stored neighbor lists. Returns true if there where some duplicate ve...
Definition: delaunay.cpp:221
unsigned int dimension() const
Returns the dimension.
Definition: delaunay.h:35
virtual void set_vertices(unsigned int nb_vertices, const float *vertices)
Sets the vertices.
Definition: delaunay.cpp:51
virtual void get_neighbors(unsigned int v, std::vector< unsigned int > &neighbors) const
Retrieves the one-ring neighbors of vertex v.
Definition: delaunay.cpp:90
unsigned int cell_size() const
Returns the size of the cell.
Definition: delaunay.h:38
Definition: collider.cpp:182