11#ifndef EASY3D_ALGO_DELAUNAY_3D_H
12#define EASY3D_ALGO_DELAUNAY_3D_H
17#include <easy3d/algo/delaunay.h>
18#include <easy3d/algo/export.h>
58 if (vertices.capacity() - vertices.size() < 8) {
59 const_cast<std::vector<vec3> &
>(vertices).reserve(vertices.size() + 8);
61 set_vertices(
static_cast<unsigned int>(vertices.size()), vertices[0]);
162 return tet_adjacent(t, next_around_halfedge_[lv1][lv2]);
222 void get_voronoi_facet(
VoronoiCell3d &cell,
unsigned int t,
unsigned int lv1,
unsigned int lv2,
bool geometry)
const;
231 static unsigned int other_in_face(
unsigned int f,
unsigned int lv1,
unsigned int lv2) {
235 unsigned int ov1 = facet_vertex_[f][0];
236 unsigned int ov2 = facet_vertex_[f][1];
237 unsigned int ov3 = facet_vertex_[f][2];
238 if (lv1 == ov1 && lv2 == ov2) {
return ov3; }
239 if (lv1 == ov2 && lv2 == ov1) {
return ov3; }
240 if (lv1 == ov1 && lv2 == ov3) {
return ov2; }
241 if (lv1 == ov3 && lv2 == ov1) {
return ov2; }
242 if (lv1 == ov2 && lv2 == ov3) {
return ov1; }
243 if (lv1 == ov3 && lv2 == ov2) {
return ov1; }
244 DCHECK(
false) <<
"should not have reached here";
249 static EASY3D_ALGO_EXPORT
unsigned int next_around_halfedge_[4][4];
250 static EASY3D_ALGO_EXPORT
unsigned int facet_vertex_[4][3];
253 tetgenio *tetgen_out_;
254 tetgenio *tetgen_in_;
275 facet_ptr_.resize(0);
276 facet_bisector_.resize(0);
277 edge_bisector_.resize(0);
280 facet_ptr_.push_back(0);
288 return static_cast<unsigned int>(facet_ptr_.size() - 1);
298 return facet_ptr_[f];
308 return facet_ptr_[f + 1];
352 return facet_bisector_[f];
369 assert(i < edge_bisector_.size());
370 return edge_bisector_[i];
381 assert(i < vertex_.size());
391 assert(i < infinite_.size());
400 facet_bisector_.push_back(f_bisector);
410 edge_bisector_.push_back(e_bisector);
411 vertex_.push_back(v);
412 infinite_.push_back(infinite);
421 edge_bisector_.push_back(e_bisector);
422 infinite_.push_back(infinite);
429 facet_ptr_.push_back(
static_cast<unsigned int>(edge_bisector_.size()));
438 for (
unsigned int i = 0; i < facet_bisector_.size(); i++) {
439 if (facet_bisector_[i] == bisector) {
445 std::cerr <<
"bisector = " << bisector;
446 std::cerr <<
" facet = [";
447 for (
auto fb : facet_bisector_) {
448 std::cerr << fb <<
" ";
450 std::cerr <<
"]" << std::endl;
451 DCHECK(
false) <<
"should not have reached here";
456 std::vector<unsigned int> facet_ptr_;
457 std::vector<unsigned int> facet_bisector_;
458 std::vector<int> edge_bisector_;
459 std::vector<vec3> vertex_;
460 std::vector<bool> infinite_;
const int * tet_to_v() const
Returns the pointer to the tetrahedron-to-vertex mapping.
Definition delaunay_3d.h:74
unsigned int nb_tets() const
Returns the number of tetrahedra.
Definition delaunay_3d.h:68
int prev_around_halfedge(int t, unsigned int lv1, unsigned int lv2) const
Returns the previous tetrahedron around the halfedge defined by vertices lv1 and lv2 in tetrahedron t...
Definition delaunay_3d.h:172
void set_vertices(const std::vector< vec3 > &vertices)
Sets the vertices from an array of 3D points.
Definition delaunay_3d.h:56
int tet_adjacent(unsigned int t, unsigned int lf) const
Returns the index of the tetrahedron adjacent to the lf-th face of the t-th tetrahedron.
Definition delaunay_3d.h:132
vec3 tet_circumcenter(unsigned int t) const
Computes the circumcenter of the t-th tetrahedron.
Definition delaunay_3d.h:197
int tet_facet_vertex(unsigned int t, unsigned int lf, unsigned int lv) const
Returns the index of the lv-th vertex in the lf-th face of the t-th tetrahedron.
Definition delaunay_3d.h:143
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 de...
Definition delaunay_3d.cpp:33
vec3 facet_normal(unsigned int t, unsigned int f) const
Computes the normal vector of the f-th face of the t-th tetrahedron.
Definition delaunay_3d.h:182
unsigned int nearest_vertex(const vec3 &p) const
Finds the index of the nearest vertex to a given 3D point.
Definition delaunay_3d.h:103
void get_voronoi_cell(unsigned int v, VoronoiCell3d &cell, bool geometry=true) const
Computes the Voronoi cell associated with vertex v.
Definition delaunay_3d.cpp:120
Delaunay3()
Default constructor.
Definition delaunay_3d.cpp:20
unsigned int nearest_vertex(const float *p) const override
Finds the index of the nearest vertex to a given point.
Definition delaunay_3d.h:94
int vertex_tet(int v) const
Returns the index of a tetrahedron containing the vertex v.
Definition delaunay_3d.h:87
~Delaunay3() override
Destructor.
Definition delaunay_3d.cpp:28
int next_around_halfedge(int t, unsigned int lv1, unsigned int lv2) const
Returns the next tetrahedron around the halfedge defined by vertices lv1 and lv2 in tetrahedron t.
Definition delaunay_3d.h:156
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:122
const vec3 & vertex(unsigned int i) const
Returns the coordinates of the vertex with index i.
Definition delaunay_3d.h:112
const int * tet_to_tet() const
Returns the pointer to the tetrahedron-to-tetrahedron mapping.
Definition delaunay_3d.h:80
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
A data structure for 3D Voronoi cells.
Definition delaunay_3d.h:268
bool vertex_is_infinite(unsigned int i) const
Checks if vertex i is at infinity.
Definition delaunay_3d.h:390
unsigned int find_facet(unsigned int bisector) const
Finds the index of the facet with the given bisector vertex.
Definition delaunay_3d.h:437
unsigned int nb_facets() const
Returns the number of facets in the Voronoi cell.
Definition delaunay_3d.h:287
unsigned int facet_end(unsigned int f) const
Returns the ending index of the vertices for facet f.
Definition delaunay_3d.h:306
void end_facet()
Ends the current facet.
Definition delaunay_3d.h:428
void begin_facet(unsigned int f_bisector)
Begins a new facet with the given bisector vertex.
Definition delaunay_3d.h:399
int edge_bisector(unsigned int i) const
Returns the edge bisector for vertex i.
Definition delaunay_3d.h:368
unsigned int next_around_facet(unsigned int f, unsigned int i) const
Returns the next vertex index around facet f starting from vertex i.
Definition delaunay_3d.h:327
VoronoiCell3d()
Default constructor.
Definition delaunay_3d.h:271
unsigned int facet_begin(unsigned int f) const
Returns the starting index of the vertices for facet f.
Definition delaunay_3d.h:296
unsigned int nb_vertices(unsigned int f) const
Returns the number of vertices in facet f.
Definition delaunay_3d.h:316
void add_to_facet(int e_bisector, bool infinite)
Adds a vertex to the current facet without specifying coordinates.
Definition delaunay_3d.h:420
void clear()
Clears the Voronoi cell.
Definition delaunay_3d.h:274
unsigned int prev_around_facet(unsigned int f, unsigned int i) const
Returns the previous vertex index around facet f starting from vertex i.
Definition delaunay_3d.h:338
const vec3 & vertex(unsigned int i) const
Returns the coordinates of vertex i.
Definition delaunay_3d.h:380
void add_to_facet(int e_bisector, const vec3 &v, bool infinite)
Adds a vertex to the current facet.
Definition delaunay_3d.h:409
unsigned int facet_bisector(unsigned int f) const
Returns the bisector vertex for facet f.
Definition delaunay_3d.h:350
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:44
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:685