32#ifndef RCSC_GEOM_DELAUNAY_TRIANGULATION_H
33#define RCSC_GEOM_DELAUNAY_TRIANGULATION_H
39#include <unordered_map>
187 const Vertex * M_vertices[2];
206 std::fill_n( M_triangles, 2,
nullptr );
222 if ( M_triangles[0] == tri )
227 M_triangles[0] =
nullptr;
229 if ( M_triangles[1] == tri )
234 M_triangles[1] =
nullptr;
249 if ( M_triangles[0] == tri )
return;
250 if ( M_triangles[1] == tri )
return;
252 if ( ! M_triangles[0] )
257 M_triangles[0] = tri;
259 else if ( ! M_triangles[1] )
264 M_triangles[1] = tri;
285 return M_vertices[i];
295 return M_triangles[i];
305 return ( M_vertices[0] == v
306 || M_vertices[1] == v );
320 std::array< const Vertex *, 3 > M_vertices;
322 std::array< EdgePtr, 3 > M_edges;
325 double M_circumradius;
352 M_edges[0]->removeTriangle(
this );
353 M_edges[1]->removeTriangle(
this );
354 M_edges[2]->removeTriangle(
this );
379 return M_vertices[i];
399 return M_circumcenter;
408 return M_circumradius;
417 return M_voronoi_vertex;
427 return pos.
dist2( M_circumcenter ) < M_circumradius * M_circumradius;
437 return ( v == M_vertices[0]
438 || v == M_vertices[1]
439 || v == M_vertices[2] );
449 return ( M_edges[0] == e
451 || M_edges[2] == e );
464 for ( std::size_t i = 0; i < 3; ++i )
466 if ( M_vertices[i] != v1
467 && M_vertices[i] != v2 )
469 return M_vertices[i];
496 for ( std::size_t i = 0; i < 3; ++i )
514 for ( std::size_t i = 0; i < 3; ++i )
529 typedef std::unordered_map< int, EdgePtr >
EdgeCont;
540 Vertex M_initial_vertex[3];
574 createInitialTriangle( region );
590 createInitialTriangle( region );
698 void createInitialTriangle(
const Rect2D & region );
703 void createInitialTriangle();
708 void removeInitialVertices();
715 bool updateContainedVertex(
const Vertex * vertex,
724 bool updateOnlineVertex(
const Vertex * vertex,
736 const Vertex * new_vertex,
752 void removeEdge(
int id )
754 EdgeCont::iterator it = M_edges.find(
id );
755 if ( it != M_edges.end() )
766 void removeEdge( Edge * edge )
770 removeEdge( edge->id() );
778 void removeTriangle(
int id )
780 TriangleCont::iterator it = M_triangles.find(
id );
781 if ( it != M_triangles.end() )
789 M_triangles.erase( it );
801 removeTriangle( tri->id() );
811 EdgePtr createEdge(
const Vertex * v0,
814 EdgePtr ptr =
new Edge( M_edge_count++, v0, v1 );
815 M_edges.insert( EdgeCont::value_type( ptr->id(), ptr ) );
831 TrianglePtr ptr =
new Triangle( M_tri_count++, e0, e1, e2 );
832 M_triangles.insert( TriangleCont::value_type( ptr->id(), ptr ) );
triangle's edge data.
Definition: delaunay_triangulation.h:184
Triangle * triangle(const std::size_t i) const
get the raw pointer to the triangle that this edge belongs to
Definition: delaunay_triangulation.h:293
int id() const
get Id number of this edge
Definition: delaunay_triangulation.h:272
const Vertex * vertex(const std::size_t i) const
get the raw pointer to the vertex that this edge has
Definition: delaunay_triangulation.h:283
void setTriangle(TrianglePtr tri)
set the triangle that this edge belongs to.
Definition: delaunay_triangulation.h:247
bool hasVertex(const Vertex *v) const
check if this edge has the specified vertex or not.
Definition: delaunay_triangulation.h:303
~Edge()
nothing to do
Definition: delaunay_triangulation.h:212
Edge(const int id, const Vertex *v0, const Vertex *v1)
create edge with two vertices. vertices must not be NULL.
Definition: delaunay_triangulation.h:197
void removeTriangle(TrianglePtr tri)
remove pointer to the triangle that this edge belongs to. This edge is NOT removed.
Definition: delaunay_triangulation.h:220
triangle data
Definition: delaunay_triangulation.h:315
Edge * getEdgeExclude(const Vertex *v) const
get the pointer to the edge that does not have the specified vertex.
Definition: delaunay_triangulation.h:512
void updateVoronoiVertex()
update the voronoi vertex point (intersection of perpendicular bisectors)
Edge * edge(std::size_t i) const
get the raw pointer to the edge that this triangle has
Definition: delaunay_triangulation.h:387
~Triangle()
remove this triangle from all edges.
Definition: delaunay_triangulation.h:350
Edge * getEdgeInclude(const Vertex *v1, const Vertex *v2) const
get the pointer to the edge that has the specified vertices.
Definition: delaunay_triangulation.h:493
const Vertex * vertex(std::size_t i) const
get the raw pointer to the vertex that this triangle has
Definition: delaunay_triangulation.h:377
bool contains(const Vector2D &pos) const
check if circumcircle contains the specified point
Definition: delaunay_triangulation.h:425
bool hasVertex(const Vertex *v) const
check if this triangle has the specified vertex.
Definition: delaunay_triangulation.h:435
const Vector2D & voronoiVertex() const
get the voronoi vertex point
Definition: delaunay_triangulation.h:415
Triangle(const int id, EdgePtr e0, EdgePtr e1, EdgePtr e2)
create triangle with index and edges
const Vector2D & circumcenter() const
get the circumcenter point of this triangle
Definition: delaunay_triangulation.h:397
const Vertex * getVertexExclude(const Vertex *v1, const Vertex *v2) const
get the pointer to the vertex that is different from the specified vertices.
Definition: delaunay_triangulation.h:461
const Vertex * getVertexExclude(const Edge *edge) const
get the pointer to the vertex that does not belong to the specified edge.
Definition: delaunay_triangulation.h:481
int id() const
get the Id of this triangle
Definition: delaunay_triangulation.h:366
bool hasEdge(const EdgePtr e) const
check if this triangle has the specified edge.
Definition: delaunay_triangulation.h:447
double circumradius() const
get the radius of the circumcircle of this triangle
Definition: delaunay_triangulation.h:406
triangle's vertex data. This is handled as kernel point for the Voronoi diagram..
Definition: delaunay_triangulation.h:71
Vertex(const int id)
create vertex with Id
Definition: delaunay_triangulation.h:89
Vertex(const int id, const double x, const double y)
create vertex with Id & coordinates
Definition: delaunay_triangulation.h:117
Vertex()
create vertex with Id number 0
Definition: delaunay_triangulation.h:80
int id() const
get the Id of this vertex
Definition: delaunay_triangulation.h:156
Vertex & assign(const int id, const double x, const double y)
assign data
Definition: delaunay_triangulation.h:143
Vertex(const int id, const Vector2D &p)
create vertex with Id & coordinates
Definition: delaunay_triangulation.h:105
const Vector2D & pos() const
get the coordinates of the kernel point
Definition: delaunay_triangulation.h:166
virtual ~Vertex()
nothing to do
Definition: delaunay_triangulation.h:97
Vertex & assign(const int id, const Vector2D &p)
assign data
Definition: delaunay_triangulation.h:129
Delaunay triangulation.
Definition: delaunay_triangulation.h:49
const VertexCont & vertices() const
get vertices
Definition: delaunay_triangulation.h:608
std::unordered_map< int, EdgePtr > EdgeCont
edge pointer container type
Definition: delaunay_triangulation.h:529
const TriangleCont & triangles() const
get triangle set
Definition: delaunay_triangulation.h:628
void clear()
clear all vertices and all computed results.
void addVertices(const std::vector< Vector2D > &v)
set vertices.
void compute()
compute the Delaunay Triangulation
Edge * EdgePtr
alias of Edge pointer
Definition: delaunay_triangulation.h:177
static const double EPSILON
tolerance threshold
Definition: delaunay_triangulation.h:52
const EdgeCont & edges() const
get edge set
Definition: delaunay_triangulation.h:618
void updateVoronoiVertex()
calculate voronoi vertex point for each triangle
void clearResults()
clear all computed results
~DelaunayTriangulation()
destruct
DelaunayTriangulation(const Rect2D ®ion)
construct with considerable rectangle region
Definition: delaunay_triangulation.h:571
int addVertex(const Vector2D &p)
add new vertex
Definition: delaunay_triangulation.h:647
const Vertex * getVertex(const int id) const
get the const pointer to vertex specified by Id number.
const Triangle * findTriangleContains(const Vector2D &pos) const
find triangle that contains pos from the computed triangle set.
std::vector< Vertex > VertexCont
vertex container type
Definition: delaunay_triangulation.h:528
const Vertex * findNearestVertex(const Vector2D &pos) const
find the vertex nearest to the specified point
void init(const Rect2D ®ion)
initialize with target field rectangle data. All data are cleared. Initial triangle is crated.
Definition: delaunay_triangulation.h:587
int addVertex(const double x, const double y)
add new vertex
DelaunayTriangulation()=default
nothing to do
std::unordered_map< int, TrianglePtr > TriangleCont
triangle pointer container type
Definition: delaunay_triangulation.h:530
ContainedType
containment type in triangles
Definition: delaunay_triangulation.h:59
Triangle * TrianglePtr
alias of Triangle pointer
Definition: delaunay_triangulation.h:178
2D rectangle regin class.
Definition: rect_2d.h:59
2D point vector class
Definition: vector_2d.h:46
Vector2D & assign(const double xx, const double yy)
assign XY value directly.
Definition: vector_2d.h:100
double y
Y coordinate.
Definition: vector_2d.h:64
double dist2(const Vector2D &p) const
get the squared distance from this to 'p'.
Definition: vector_2d.h:347
double x
X coordinate.
Definition: vector_2d.h:63
2D rectangle region Header File.
2d vector class Header File.