From 04f589e97d8d56ff3bc39cc26b7222c135173c9c Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 12 Jul 2016 11:11:13 +0200 Subject: [PATCH] Update doc for Random_points_on_triangle_mesh_2 --- .../doc/Generator/CGAL/point_generators_2.h | 95 +++++++++++++++---- Generator/doc/Generator/Generator.txt | 2 +- Generator/doc/Generator/dependencies | 1 + Generator/doc/Generator/examples.txt | 1 + .../random_points_on_triangle_mesh_2.cpp | 55 +++++++++++ 5 files changed, 137 insertions(+), 17 deletions(-) create mode 100644 Generator/examples/Generator/random_points_on_triangle_mesh_2.cpp diff --git a/Generator/doc/Generator/CGAL/point_generators_2.h b/Generator/doc/Generator/CGAL/point_generators_2.h index ef301deffca..a10f56132d9 100644 --- a/Generator/doc/Generator/CGAL/point_generators_2.h +++ b/Generator/doc/Generator/CGAL/point_generators_2.h @@ -326,32 +326,95 @@ typedef const Point_2* pointer; */ typedef const Point_2& reference; + /*! + Creates an input iterator `g` generating points of type `Point_2` uniformly + distributed inside the triangle with vertices \f$ p, q \f$ and \f$ r \f$, i.e., \f$*g = \alpha p + \beta q + \gamma r \f$, for some + \f$ \alpha, \beta, \gamma \in [0, 1] \f$ and \f$ \alpha + \beta + \gamma = 1 \f$. + Two random numbers are needed from `rnd` for each point. + + */ + Random_points_in_triangle_2(Point_2& p, Point_2& q, Point_2& r, Random& rnd = + default_random); + + /*! + Creates an input iterator `g` generating points of type `Point_2` uniformly + distributed inside a triangle \f$t\f$ with vertices \f$ p, q \f$ and \f$ r \f$, i.e., \f$*g = \alpha p + \beta q + \gamma r \f$, for some + \f$ \alpha, \beta, \gamma \in [0, 1] \f$ and \f$ \alpha + \beta + \gamma = 1 \f$. + Two random numbers are needed from `rnd` for each point. + + */ + Random_points_in_triangle_2(Triangle_2& t, Random& rnd = + default_random); + + /// @} + + }; /* end Random_points_in_triangle_2 */ + + /*! + + The class `Random_points_on_triangle_mesh_2` is an input iterator creating points uniformly + distributed inside a Triangulation_2. The Triangulation_2 must have a face model refining `DelaunayMeshFaceBase_2`. + The sampled model is the union of the faces for which `DelaunayMeshFaceBase_2::is_in_domain()` returns `true`. + \cgalModels `InputIterator` + \cgalModels `PointGenerator` + + \sa `CGAL::cpp11::copy_n()` + \sa `CGAL::Counting_iterator` + \sa `CGAL::Points_on_segment_2` + \sa `CGAL::Random_points_in_disc_2` + \sa `CGAL::Random_points_on_segment_2` + \sa `CGAL::Random_points_on_square_2` + \sa `CGAL::Random_points_in_cube_3` + \sa `CGAL::Random_points_in_triangle_3` + \sa `CGAL::Random_points_in_tetrahedron_3` + \sa `std::random_shuffle` + + */ + template< typename Point_2, typename Triangulation > + class Random_points_on_triangle_mesh_2 { + public: + + /// \name Types + /// @{ + + /*! + + */ + typedef std::input_iterator_tag iterator_category; + + /*! + + */ + typedef Point_2 value_type; + + /*! + + */ + typedef std::ptrdiff_t difference_type; + + /*! + + */ + typedef const Point_2* pointer; + + /*! + + */ + typedef const Point_2& reference; /*! Creates an input iterator `g` generating points of type `Point_2` uniformly -distributed inside the triangle with vertices \f$ p, q \f$ and \f$ r \f$, i.e., \f$*g = \alpha p + \beta q + \gamma r \f$, for some -\f$ \alpha, \beta, \gamma \in [0, 1] \f$ and \f$ \alpha + \beta + \gamma = 1 \f$. -Two random numbers are needed from `rnd` for each point. +distributed between the triangles of the triangulation. Each triangle has a propability to be chosen to hold the point depending on its area. */ -Random_points_in_triangle_2(Point_2& p, Point_2& q, Point_2& r, Random& rnd = -get_default_random()); - -/*! -Creates an input iterator `g` generating points of type `Point_2` uniformly -distributed inside a triangle \f$t\f$ with vertices \f$ p, q \f$ and \f$ r \f$, i.e., \f$*g = \alpha p + \beta q + \gamma r \f$, for some -\f$ \alpha, \beta, \gamma \in [0, 1] \f$ and \f$ \alpha + \beta + \gamma = 1 \f$. -Two random numbers are needed from `rnd` for each point. - -*/ -Random_points_in_triangle_2(Triangle_2& t, Random& rnd = -get_default_random()); +Random_points_on_triangle_mesh_2(Triangulation triangulation, Random& rnd = +default_random); /// @} -}; /* end Random_points_in_triangle_2 */ +}; /* end Random_points_on_triangle_mesh_2 */ /*! diff --git a/Generator/doc/Generator/Generator.txt b/Generator/doc/Generator/Generator.txt index 705450ab9c7..24e3000d99a 100644 --- a/Generator/doc/Generator/Generator.txt +++ b/Generator/doc/Generator/Generator.txt @@ -6,7 +6,7 @@ namespace CGAL { \anchor Chapter_Geometric_Object_Generators \anchor chapterGenerators \cgalAutoToc -\authors Pedro M. M. de Castro, Olivier Devillers, Susan Hert, Michael Hoffmann, Lutz Kettner, Sven Schönherr, and Alexandru Tifrea +\authors Pedro M. M. de Castro, Olivier Devillers, Susan Hert, Michael Hoffmann, Lutz Kettner, Sven Schönherr, Alexandru Tifrea, and Maxime Gimeno \section GeneratorIntroduction Introduction diff --git a/Generator/doc/Generator/dependencies b/Generator/doc/Generator/dependencies index a4d5f76715e..16d9d4a1765 100644 --- a/Generator/doc/Generator/dependencies +++ b/Generator/doc/Generator/dependencies @@ -1,4 +1,5 @@ Manual +Mesh_2 Kernel_23 STL_Extension Algebraic_foundations diff --git a/Generator/doc/Generator/examples.txt b/Generator/doc/Generator/examples.txt index 294e181ccaf..8acc590f99c 100644 --- a/Generator/doc/Generator/examples.txt +++ b/Generator/doc/Generator/examples.txt @@ -15,4 +15,5 @@ \example Generator/random_convex_hull_2.cpp \example Generator/random_points_triangle_2.cpp \example Generator/random_points_tetrahedron_and_triangle_3.cpp +\example Generator/random_points_on_triangle_mesh_2.cpp */ diff --git a/Generator/examples/Generator/random_points_on_triangle_mesh_2.cpp b/Generator/examples/Generator/random_points_on_triangle_mesh_2.cpp new file mode 100644 index 00000000000..fc146a28f4a --- /dev/null +++ b/Generator/examples/Generator/random_points_on_triangle_mesh_2.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include +#include + +#include +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; +typedef CGAL::Triangulation_vertex_base_2 Vb; +typedef CGAL::Delaunay_mesh_face_base_2 Fb; +typedef CGAL::Triangulation_data_structure_2 Tds; +typedef CGAL::Constrained_Delaunay_triangulation_2 CDT; +typedef CDT::Point Point; +typedef CGAL::Polygon_2 Polygon_2; + + +using namespace CGAL; +int main() +{ + // Generated points are in that vector + std::vector points; + //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(0,2)); + ::Polygon_2 polygon2; + polygon2.push_back(Point(4.0,-2.0)); + polygon2.push_back(Point(4.0,2.0)); + polygon2.push_back(Point(6.0,0.0)); + + //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); + + // Create the generator, input is the Triangulation_2 cdt + Random_points_on_triangle_mesh_2 + g(cdt); + + // Get 100 random points in cdt + CGAL::cpp11::copy_n( g, 100, std::back_inserter(points)); + + // Check that we have really created 100 points. + assert( points.size() == 100); + + // print the first point that was generated + std::cout << points[0] << std::endl; + + return 0; +}