Easy3D 2.6.1
Loading...
Searching...
No Matches
delaunay_2d.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_2D_H
12#define EASY3D_ALGO_DELAUNAY_2D_H
13
14#include <easy3d/algo/delaunay.h>
15
16
17struct triangulateio;
18
19namespace easy3d {
20
21
30 class Delaunay2 : public Delaunay {
31 public:
33 Delaunay2();
34
36 ~Delaunay2() override;
37
45 void set_vertices(unsigned int nb_vertices, const float *pts) override;
46
51 void set_vertices(const std::vector<vec2> &vertices) {
52 set_vertices(static_cast<unsigned int>(vertices.size()), vertices[0]);
53 }
54
60 unsigned int nearest_vertex(const float *p) const override {
62 }
63
69 unsigned int nearest_vertex(const vec2 &p) const {
70 return nearest_vertex(p.data());
71 }
72
78 const vec2 &vertex(unsigned int i) const {
79 return *reinterpret_cast<const vec2 *>(vertex_ptr(i));
80 }
81
86 const int *tri_to_v() const { return cell_to_v(); }
87
92 const int *tri_to_tri() const { return cell_to_cell(); }
93
99 int vertex_tri(int v) const { return vertex_cell(v); }
100
105 unsigned int nb_triangles() const { return nb_cells(); }
106
113 int tri_vertex(unsigned int t, unsigned int lv) const {
114 return cell_vertex(t, lv);
115 }
116
123 int tri_adjacent(unsigned int t, unsigned int le) const {
124 return cell_adjacent(t, le);
125 }
126
127 protected:
128 triangulateio *triangle_out_;
129 triangulateio *triangle_in_;
130 };
131
132
133
134
135
136/*
137 * The commented one is enough for basic 2D Delaunay implementation.
138 * The above one is verbose for easy understanding of the interface APIs.
139 */
140//class MATH_API Delaunay2 : public Delaunay {
141//public:
142// Delaunay2() ;
143// virtual ~Delaunay2() ;
144// virtual void set_vertices(unsigned int nb_vertices, const double* vertices) ;
145//
146//protected:
147// struct triangulateio* triangle_out_ ;
148// struct triangulateio* triangle_in_ ;
149//} ;
150
151} // namespace easy3d
152
153#endif // EASY3D_ALGO_DELAUNAY_2D_H
154
155
void set_vertices(const std::vector< vec2 > &vertices)
Sets the vertices from an array of 2D points.
Definition delaunay_2d.h:51
int tri_adjacent(unsigned int t, unsigned int le) const
Returns the index of the triangle adjacent to the le-th edge of the t-th triangle.
Definition delaunay_2d.h:123
unsigned int nb_triangles() const
Returns the number of triangles.
Definition delaunay_2d.h:105
const vec2 & vertex(unsigned int i) const
Returns the coordinates of the vertex with index i.
Definition delaunay_2d.h:78
int tri_vertex(unsigned int t, unsigned int lv) const
Returns the index of the lv-th vertex in the t-th triangle.
Definition delaunay_2d.h:113
const int * tri_to_tri() const
Returns the pointer to the triangle-to-triangle mapping.
Definition delaunay_2d.h:92
unsigned int nearest_vertex(const vec2 &p) const
Finds the index of the nearest vertex to a given 2D point.
Definition delaunay_2d.h:69
void set_vertices(unsigned int nb_vertices, const float *pts) override
Sets the vertices from an array of floating point numbers, in which each consecutive number pair deno...
Definition delaunay_2d.cpp:62
int vertex_tri(int v) const
Returns the index of a triangle containing the vertex v.
Definition delaunay_2d.h:99
unsigned int nearest_vertex(const float *p) const override
Finds the index of the nearest vertex to a given point.
Definition delaunay_2d.h:60
Delaunay2()
Default constructor.
Definition delaunay_2d.cpp:47
~Delaunay2() override
Destructor.
Definition delaunay_2d.cpp:55
const int * tri_to_v() const
Returns the pointer to the triangle-to-vertex mapping.
Definition delaunay_2d.h:86
const int * cell_to_cell() const
Returns a pointer to the cell-to-cell mapping.
Definition delaunay.h:98
unsigned int nb_cells() const
Returns the number of cells.
Definition delaunay.h:86
int vertex_cell(unsigned int v) const
Returns the index of a cell containing the vertex v.
Definition delaunay.h:136
int cell_adjacent(unsigned int c, unsigned int lf) const
Returns the index of the cell adjacent to the lf-th face of the c-th cell.
Definition delaunay.h:125
virtual unsigned int nearest_vertex(const float *p) const
Finds the index of the nearest vertex to a given point.
Definition delaunay.cpp:74
unsigned int nb_vertices() const
Returns the number of vertices.
Definition delaunay.h:80
const float * vertex_ptr(unsigned int i) const
Returns a pointer to the vertex of index i.
Definition delaunay.h:71
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:113
const int * cell_to_v() const
Returns a pointer to the cell-to-vertex mapping.
Definition delaunay.h:92
Delaunay(unsigned int dimension)
Constructor.
Definition delaunay.cpp:34
T * data()
Returns the memory address of the vector.
Definition vec.h:82
Definition collider.cpp:182
Vec< 2, float > vec2
A 2D point/vector of float type.
Definition types.h:42