1 #include <iostream>
2 #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
3 #include <CGAL/point_generators_3.h>
4 #include <CGAL/Random.h>
5 
6 typedef CGAL::Exact_predicates_inexact_constructions_kernel                 K;
7 typedef K::Point_3                                                                                                         Point_3;
8 typedef K::Triangle_3                                                                                                 Triangle_3;
9 typedef K::Tetrahedron_3                                                                                         Tetrahedron_3;
10 typedef CGAL::Random_points_in_triangle_3<Point_3>                                         Point_generator_i;
11 typedef CGAL::Random_points_in_tetrahedron_3<Point_3>                                 Point_generator_ii;
12 
main()13 int main() {
14         std::cout << "This example does two things:" << std::endl;
15         std::cout << "  (i) it creates 100 random points in a triangle in 3D; and" << std::endl;
16         std::cout << "  (ii) it creates 100 random points in a tetrahedron in 3D." << std::endl;
17 
18         // The input triangle is as follows
19         Triangle_3 tri(Point_3(0,0,0),Point_3(1,0,0),Point_3(0,1,0));
20         Tetrahedron_3 tet(Point_3(0,0,0),Point_3(1,0,0),Point_3(0,1,0),Point_3(0,0,1));
21 
22         // we get output points in these containers
23         std::vector<Point_3> points_in_tri, points_in_tet;
24 
25         // creating the first generator, input is the Triangle_3 tri
26         Point_generator_i g_i(tri);
27 
28         // creating the second generator, input is the Tetrahedron_3 tet
29         Point_generator_ii g_ii(tet);
30 
31         // get 100 random points in tri
32         std::copy_n(g_i, 100, std::back_inserter(points_in_tri));
33 
34         // get 100 random points in tet
35         std::copy_n(g_ii, 100, std::back_inserter(points_in_tet));
36 
37         // Check that we have really created 100 points.
38         assert( points_in_tri.size() == 100);
39 
40         // Check that we have really created 100 points.
41         assert( points_in_tet.size() == 100);
42 
43         // print the first points
44         std::cout << "In triangle: " << points_in_tri[0] << std::endl;
45         std::cout << "In tetrahedron: " << points_in_tet[0] << std::endl;
46 
47         return 0;
48 }
49 
50