11#ifndef EASY3D_ALGO_DELAUNAY_3D_H
12#define EASY3D_ALGO_DELAUNAY_3D_H
17#include <easy3d/algo/delaunay.h>
44 if (vertices.capacity() - vertices.size() < 8) {
45 const_cast<std::vector<vec3> &
>(vertices).reserve(vertices.size() + 8);
47 set_vertices((
unsigned int) vertices.size(), &vertices[0].x);
53 const int *tet_to_v()
const {
return cell_to_v(); }
55 const int *tet_to_tet()
const {
return cell_to_cell(); }
57 int vertex_tet(
int v)
const {
return vertex_cell(v); }
59 unsigned int nearest_vertex(
const float *p)
const override {
60 return Delaunay::nearest_vertex(p);
63 unsigned int nearest_vertex(
const vec3 &p)
const {
64 return nearest_vertex(p.data());
67 const vec3 &vertex(
unsigned int i)
const {
76 int tet_adjacent(
unsigned int t,
unsigned int lf)
const {
77 return cell_adjacent(t, lf);
80 int tet_facet_vertex(
unsigned int t,
unsigned int lf,
unsigned int lv)
const {
86 int next_around_halfedge(
int t,
unsigned int lv1,
unsigned int lv2)
const {
92 return tet_adjacent(t, next_around_halfedge_[lv1][lv2]);
95 int prev_around_halfedge(
int t,
unsigned int lv1,
unsigned int lv2)
const {
96 return next_around_halfedge(t, lv2, lv1);
99 vec3 facet_normal(
unsigned int t,
unsigned int f)
const {
109 vec3 tet_circumcenter(
unsigned int t)
const {
119 unsigned int v, VoronoiCell3d &cell,
bool geometry =
true
123 void get_voronoi_facet(
124 VoronoiCell3d &cell,
unsigned int t,
125 unsigned int lv1,
unsigned int lv2,
bool geometry
128 static unsigned int other_in_face(
129 unsigned int f,
unsigned int lv1,
unsigned int lv2
134 unsigned int ov1 = facet_vertex_[f][0];
135 unsigned int ov2 = facet_vertex_[f][1];
136 unsigned int ov3 = facet_vertex_[f][2];
137 if (lv1 == ov1 && lv2 == ov2) {
return ov3; }
138 if (lv1 == ov2 && lv2 == ov1) {
return ov3; }
139 if (lv1 == ov1 && lv2 == ov3) {
return ov2; }
140 if (lv1 == ov3 && lv2 == ov1) {
return ov2; }
141 if (lv1 == ov2 && lv2 == ov3) {
return ov1; }
142 if (lv1 == ov3 && lv2 == ov2) {
return ov1; }
143 DCHECK(
false) <<
"should not have reached here";
148 static unsigned int next_around_halfedge_[4][4];
149 static unsigned int facet_vertex_[4][3];
152 tetgenio *tetgen_out_;
153 tetgenio *tetgen_in_;
172 facet_ptr_.resize(0);
173 facet_bisector_.resize(0);
174 edge_bisector_.resize(0);
177 facet_ptr_.push_back(0);
180 unsigned int nb_facets()
const {
181 return (
unsigned int) facet_ptr_.size() - 1;
184 unsigned int facet_begin(
unsigned int f)
const {
185 assert(f < nb_facets());
186 return facet_ptr_[f];
189 unsigned int facet_end(
unsigned int f)
const {
190 assert(f < nb_facets());
191 return facet_ptr_[f + 1];
194 unsigned int nb_vertices(
unsigned int f)
const {
195 assert(f < nb_facets());
196 return facet_end(f) - facet_begin(f);
199 unsigned int next_around_facet(
unsigned int f,
unsigned int i)
const {
200 assert(i >= facet_begin(f) && i < facet_end(f));
201 return (i + 1 == facet_end(f) ? facet_begin(f) : i + 1);
204 unsigned int prev_around_facet(
unsigned int f,
unsigned int i)
const {
205 assert(i >= facet_begin(f) && i < facet_end(f));
206 return (i == facet_begin(f) ? facet_end(f) - 1 : i - 1);
215 assert(f < nb_facets());
216 return facet_bisector_[f];
234 assert(i < edge_bisector_.size());
235 return edge_bisector_[i];
244 assert(i < vertex_.size());
248 bool vertex_is_infinite(
unsigned int i)
const {
249 assert(i < infinite_.size());
253 void begin_facet(
unsigned int f_bisector) {
254 facet_bisector_.push_back(f_bisector);
258 int e_bisector,
const vec3 &v,
bool infinite
260 edge_bisector_.push_back(e_bisector);
261 vertex_.push_back(v);
262 infinite_.push_back(infinite);
266 int e_bisector,
bool infinite
268 edge_bisector_.push_back(e_bisector);
269 infinite_.push_back(infinite);
273 facet_ptr_.push_back((
unsigned int) edge_bisector_.size());
276 unsigned int find_facet(
unsigned int bisector) {
277 for (
unsigned int i = 0; i < facet_bisector_.size(); i++) {
278 if (facet_bisector_[i] == bisector) {
284 std::cerr <<
"bisector = " << bisector;
285 std::cerr <<
" facet = [";
286 for (
auto fb : facet_bisector_) {
287 std::cerr << fb <<
" ";
289 std::cerr <<
"]" << std::endl;
290 DCHECK(
false) <<
"should not have reached here";
295 std::vector<unsigned int> facet_ptr_;
296 std::vector<unsigned int> facet_bisector_;
297 std::vector<int> edge_bisector_;
298 std::vector<vec3> vertex_;
299 std::vector<bool> infinite_;
3D Delaunay triangulation, using Hang Si's tetgen.
Definition: delaunay_3d.h:31
unsigned int nb_tets() const
Returns the number of tetrahedra.
Definition: delaunay_3d.h:51
void set_vertices(const std::vector< vec3 > &vertices)
Sets the vertices from an array of 3D points.
Definition: delaunay_3d.h:42
void set_vertices(unsigned int nb_vertices, const float *vertices) override
Sets the vertices from an array of floating point numbers in which each consecutive number triple den...
Definition: delaunay_3d.cpp:33
void get_voronoi_cell(unsigned int v, VoronoiCell3d &cell, bool geometry=true) const
Returns the Voronoi cell associated with vertex v.
Definition: delaunay_3d.cpp:120
int tet_vertex(unsigned int t, unsigned int lv) const
Returns the index of the lv_th vertex in the t_th tetrahedron.
Definition: delaunay_3d.h:72
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
A data structure for 3D Voronoi cells.
Definition: delaunay_3d.h:167
int edge_bisector(unsigned int i) const
Definition: delaunay_3d.h:233
const vec3 & vertex(unsigned int i) const
Definition: delaunay_3d.h:243
unsigned int facet_bisector(unsigned int f) const
Definition: delaunay_3d.h:214
vec3 tetra_circum_center(const vec3 &p, const vec3 &q, const vec3 &r, const vec3 &s)
Computes the circum center of a tetrahedron.
Definition: collider.cpp:182
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition: types.h:45
Vec< 3, T > cross(const Vec< 3, T > &v1, const Vec< 3, T > &v2)
Compute the cross product of two 3D vectors.
Definition: vec.h:534