Easy3D 2.5.3
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
25
26 class Delaunay2 : public Delaunay {
27 public:
28 Delaunay2();
29
30 ~Delaunay2() override;
31
34 void set_vertices(unsigned int nb_vertices, const float *pts) override;
35
37 void set_vertices(const std::vector<vec2> &vertices) {
38 set_vertices((unsigned int) vertices.size(), &vertices[0].x);
39 }
40
41 unsigned int nearest_vertex(const float *p) const override {
42 return Delaunay::nearest_vertex(p);
43 }
44
45 unsigned int nearest_vertex(const vec2 &p) const {
46 return nearest_vertex(p.data());
47 }
48
49 const vec2 &vertex(unsigned int i) const {
50 return *(const vec2 *) vertex_ptr(i);
51 }
52
53 const int *tri_to_v() const { return cell_to_v(); }
54
55 const int *tri_to_tri() const { return cell_to_cell(); }
56
57 int vertex_tri(int v) const { return vertex_cell(v); }
58
60 unsigned int nb_triangles() const { return nb_cells(); }
61
63 int tri_vertex(unsigned int t, unsigned int lv) const {
64 return cell_vertex(t, lv);
65 }
66
67 int tri_adjacent(unsigned int t, unsigned int le) const {
68 return cell_adjacent(t, le);
69 }
70
71 protected:
72 struct triangulateio *triangle_out_;
73 struct triangulateio *triangle_in_;
74 };
75
76
77
78
79
80/*
81 * The commented one is enough for basic 2D Delaunay implementation.
82 * The above one is verbose for easy understanding of the interface APIs.
83 */
84//class MATH_API Delaunay2 : public Delaunay {
85//public:
86// Delaunay2() ;
87// virtual ~Delaunay2() ;
88// virtual void set_vertices(unsigned int nb_vertices, const double* vertices) ;
89//
90//protected:
91// struct triangulateio* triangle_out_ ;
92// struct triangulateio* triangle_in_ ;
93//} ;
94
95} // namespace easy3d
96
97#endif // EASY3D_ALGO_DELAUNAY_2D_H
98
99
2D Delaunay triangulation, using Jonathan Richard Shewchuk's "triangle" implementation.
Definition: delaunay_2d.h:26
void set_vertices(const std::vector< vec2 > &vertices)
Sets the vertices from an array of 2D points.
Definition: delaunay_2d.h:37
unsigned int nb_triangles() const
Returns the number of triangles.
Definition: delaunay_2d.h:60
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:63
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 denot...
Definition: delaunay_2d.cpp:62
Base class for Delaunay triangulation.
Definition: delaunay.h:25
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
Definition: collider.cpp:182
Vec< 2, float > vec2
A 2D point/vector of float type.
Definition: types.h:43