CGAL 5.6 - 2D Triangulations
Loading...
Searching...
No Matches
Triangulation_2/polygon_triangulation.cpp
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/draw_triangulation_2.h>
#include <CGAL/mark_domain_in_triangulation.h>
#include <CGAL/Polygon_2.h>
#include <iostream>
#include <unordered_map>
#include <boost/property_map/property_map.hpp>
typedef CDT::Face_handle Face_handle;
typedef CDT::Point Point;
typedef CGAL::Polygon_2<K> Polygon_2;
int main( )
{
//construct two non-intersecting nested polygons
Polygon_2 polygon1;
polygon1.push_back(Point(0,0));
polygon1.push_back(Point(2,0));
polygon1.push_back(Point(2,2));
polygon1.push_back(Point(1,1.75));
polygon1.push_back(Point(0,2));
Polygon_2 polygon2;
polygon2.push_back(Point(0.5,0.5));
polygon2.push_back(Point(1.5,0.5));
polygon2.push_back(Point(1.5,1.5));
polygon2.push_back(Point(0.5,1.5));
//Insert the polygons into a constrained triangulation
CDT cdt;
cdt.insert_constraint(polygon1.vertices_begin(), polygon1.vertices_end(), true);
cdt.insert_constraint(polygon2.vertices_begin(), polygon2.vertices_end(), true);
cdt.insert_constraint(Point(0.25, 0.25), Point(0.25, 1.75));
std::unordered_map<Face_handle, bool> in_domain_map;
boost::associative_property_map< std::unordered_map<Face_handle,bool> >
in_domain(in_domain_map);
//Mark facets that are inside the domain bounded by the polygon
unsigned int count=0;
for (Face_handle f : cdt.finite_face_handles())
{
if ( get(in_domain, f) ) ++count;
}
std::cout << "There are " << count << " faces in the domain." << std::endl;
assert(count > 0);
assert(count < cdt.number_of_faces());
CGAL::draw(cdt, in_domain);
return 0;
}
A constrained Delaunay triangulation is a triangulation with constrained edges which tries to be as m...
Definition: Constrained_Delaunay_triangulation_2.h:96
The class Constrained_triangulation_face_base_2 is the default model for the concept ConstrainedTrian...
Definition: Constrained_triangulation_face_base_2.h:34
void push_back(const Point_2 &x)
The class Triangulation_vertex_base_2 is the default model for the concept TriangulationVertexBase_2.
Definition: Triangulation_vertex_base_2.h:34
void draw(const T3 &at3)
void mark_domain_in_triangulation(CT &ct, InDomainPmap ipm)
marks faces connected with non constrained edges as inside of the domain based on the nesting level.
Intersection tag for constrained triangulations, if the geometric traits provides exact predicates bu...
Definition: Constrained_triangulation_2.h:51