Update doc for Random_points_on_triangle_mesh_2

This commit is contained in:
Maxime Gimeno 2016-07-12 11:11:13 +02:00 committed by Sébastien Loriot
parent 7a1c2037fd
commit 04f589e97d
5 changed files with 137 additions and 17 deletions

View File

@ -326,32 +326,95 @@ typedef const Point_2* pointer;
*/ */
typedef const Point_2& reference; 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<Point_2>`
\sa `CGAL::Random_points_in_disc_2<Point_2, Creator>`
\sa `CGAL::Random_points_on_segment_2<Point_2, Creator>`
\sa `CGAL::Random_points_on_square_2<Point_2, Creator>`
\sa `CGAL::Random_points_in_cube_3<Point_3, Creator>`
\sa `CGAL::Random_points_in_triangle_3<Point_2, Creator>`
\sa `CGAL::Random_points_in_tetrahedron_3<Point_2, Creator>`
\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 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 distributed between the triangles of the triangulation. Each triangle has a propability to be chosen to hold the point depending on its area.
\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 = Random_points_on_triangle_mesh_2(Triangulation triangulation, Random& rnd =
get_default_random()); 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());
/// @} /// @}
}; /* end Random_points_in_triangle_2 */ }; /* end Random_points_on_triangle_mesh_2 */
/*! /*!

View File

@ -6,7 +6,7 @@ namespace CGAL {
\anchor Chapter_Geometric_Object_Generators \anchor Chapter_Geometric_Object_Generators
\anchor chapterGenerators \anchor chapterGenerators
\cgalAutoToc \cgalAutoToc
\authors Pedro M. M. de Castro, Olivier Devillers, Susan Hert, Michael Hoffmann, Lutz Kettner, Sven Sch&ouml;nherr, and Alexandru Tifrea \authors Pedro M. M. de Castro, Olivier Devillers, Susan Hert, Michael Hoffmann, Lutz Kettner, Sven Sch&ouml;nherr, Alexandru Tifrea, and Maxime Gimeno
\section GeneratorIntroduction Introduction \section GeneratorIntroduction Introduction

View File

@ -1,4 +1,5 @@
Manual Manual
Mesh_2
Kernel_23 Kernel_23
STL_Extension STL_Extension
Algebraic_foundations Algebraic_foundations

View File

@ -15,4 +15,5 @@
\example Generator/random_convex_hull_2.cpp \example Generator/random_convex_hull_2.cpp
\example Generator/random_points_triangle_2.cpp \example Generator/random_points_triangle_2.cpp
\example Generator/random_points_tetrahedron_and_triangle_3.cpp \example Generator/random_points_tetrahedron_and_triangle_3.cpp
\example Generator/random_points_on_triangle_mesh_2.cpp
*/ */

View File

@ -0,0 +1,55 @@
#include <CGAL/Polygon_2.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/Triangulation_face_base_with_info_2.h>
#include <CGAL/Delaunay_mesh_face_base_2.h>
#include <CGAL/point_generators_2.h>
#include <iostream>
#include <fstream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_vertex_base_2<K> Vb;
typedef CGAL::Delaunay_mesh_face_base_2<K> Fb;
typedef CGAL::Triangulation_data_structure_2<Vb, Fb> Tds;
typedef CGAL::Constrained_Delaunay_triangulation_2<K, Tds> CDT;
typedef CDT::Point Point;
typedef CGAL::Polygon_2<K> Polygon_2;
using namespace CGAL;
int main()
{
// Generated points are in that vector
std::vector<Point> 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<Point, CDT>
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;
}