diff --git a/Generator/include/CGAL/internal/Generic_random_point_generator.h b/Generator/include/CGAL/internal/Generic_random_point_generator.h index 853344604b0..9c9d6ad752a 100644 --- a/Generator/include/CGAL/internal/Generic_random_point_generator.h +++ b/Generator/include/CGAL/internal/Generic_random_point_generator.h @@ -34,7 +34,7 @@ template class Generic_random_point_generator : public Random_generator_base

{ typedef Generic_random_point_generator This; - typedef typename boost::property_traits::reference Geometric_object_ref; + typedef typename ObjectFromIdMap::reference Geometric_object_ref; typedef typename cpp11::result_of::type result_type; std::vector ids; @@ -65,7 +65,7 @@ public: BOOST_FOREACH(Id id, input) { //create a geometric object - Geometric_object_ref object = get(object_from_id_map, id); + Geometric_object_ref object = object_from_id_map(id); ids.push_back(id); //compute the weight of a face total_weight += to_double( compute_weight(object) ); @@ -101,7 +101,7 @@ void Generic_random_point_generator: ); // generate the points - GeneratorOnObject pointCreator(get(object_from_id_map,ids[target])); + GeneratorOnObject pointCreator(object_from_id_map(ids[target])); this->d_item = *pointCreator; } diff --git a/Generator/include/CGAL/point_generators_2.h b/Generator/include/CGAL/point_generators_2.h index 8bb24a19b85..75d296b6573 100644 --- a/Generator/include/CGAL/point_generators_2.h +++ b/Generator/include/CGAL/point_generators_2.h @@ -23,12 +23,16 @@ // Author(s) : Lutz Kettner // Pedro Machado Manhaes de Castro // Alexandru Tifrea +// Maxime Gimeno + #ifndef CGAL_POINT_GENERATORS_2_H #define CGAL_POINT_GENERATORS_2_H 1 #include #include #include +#include +#include namespace CGAL { @@ -542,6 +546,55 @@ void Random_points_in_triangle_2::generate_point() { T(to_double(_p.y())*b1+to_double(_q.y())*b2+to_double(_r.y())*b3)); } +namespace internal{ +//Functor returning Triangle_2 from Triangulation_2 Faces +template +class Triangle_from_face_2 +{ + typedef typename T::Triangle Triangle; +public: + typedef Triangle reference; + Triangle_from_face_2(){} + + Triangle operator()(typename T::Face_handle face)const { + return Triangle(face->vertex(0)->point(), face->vertex(1)->point(), face->vertex(2)->point()); + } +}; +}//end namespace internal +template +class Random_points_on_triangle_mesh_2 : public Generic_random_point_generator< + typename T::Face_handle , + internal::Triangle_from_face_2, + Random_points_in_triangle_2

, P> { +public: + typedef Generic_random_point_generator< + typename T::Face_handle, + internal::Triangle_from_face_2, + Random_points_in_triangle_2

, P> Base; + typedef typename T::Face_handle Id; + typedef P result_type; + typedef Random_points_on_triangle_mesh_2 This; + + + Random_points_on_triangle_mesh_2( T& triangulation,Random& rnd = default_random) + : Base( make_range( internal::Prevent_deref(triangulation.finite_faces_begin()), + internal::Prevent_deref(triangulation.finite_faces_end())), + internal::Triangle_from_face_2(), + typename Kernel_traits

::Kernel::Compute_area_2(), + rnd ) + { + } + This& operator++() { + Base::generate_point(); + return *this; + } + This operator++(int) { + This tmp = *this; + ++(*this); + return tmp; + } +}; + } //namespace CGAL #endif // CGAL_POINT_GENERATORS_2_H // // EOF // diff --git a/Generator/include/CGAL/point_generators_3.h b/Generator/include/CGAL/point_generators_3.h index 2faff7c6440..15f64e9db97 100644 --- a/Generator/include/CGAL/point_generators_3.h +++ b/Generator/include/CGAL/point_generators_3.h @@ -23,6 +23,7 @@ // Author(s) : Lutz Kettner // Pedro Machado Manhaes de Castro // Alexandru Tifrea +// Maxime Gimeno #ifndef CGAL_POINT_GENERATORS_3_H #define CGAL_POINT_GENERATORS_3_H 1 @@ -303,19 +304,43 @@ void Random_points_in_tetrahedron_3::generate_point() { this->d_item = creator(ret[0],ret[1],ret[2]); } +namespace internal +{ +//Functor that wrapps a property map to get Triangle_3 from a vertex_point_map +template +class Triangle_from_face_3 +{ + typedef typename boost::property_map::type Vertex_point_map; + typedef typename CGAL::Triangle_from_face_descriptor_map< + Mesh,Vertex_point_map> PMAP; + typedef typename boost::property_traits::reference Triangle; +private: PMAP map; +public: + typedef Triangle reference; - + Triangle_from_face_3(PMAP map) + :map(map) + {} + Triangle operator()(Id id)const + { + return get(map, id); + } +}; +}//end namespace internal template class Random_points_on_triangle_mesh_3 : public Generic_random_point_generator< typename boost::graph_traits ::face_descriptor , - CGAL::Triangle_from_face_descriptor_map::type >, + internal::Triangle_from_face_3::face_descriptor>, Random_points_in_triangle_3

, P> { public: typedef Generic_random_point_generator< typename boost::graph_traits ::face_descriptor , - CGAL::Triangle_from_face_descriptor_map::type >, + internal::Triangle_from_face_3::face_descriptor>, Random_points_in_triangle_3

, P> Base; typedef typename boost::property_map::type Vertex_point_map; @@ -329,7 +354,7 @@ public: Random_points_on_triangle_mesh_3( Mesh& mesh,Random& rnd = default_random) : Base( faces(mesh), - Object_from_id_map(&mesh), + internal::Triangle_from_face_3(Object_from_id_map(&mesh)), typename Kernel_traits

::Kernel::Compute_area_3(), rnd ) { @@ -345,7 +370,6 @@ public: } }; - } //namespace CGAL #endif // CGAL_POINT_GENERATORS_3_H // diff --git a/Generator/test/Generator/generic_random_test.cpp b/Generator/test/Generator/generic_random_test.cpp index e499ebdc99d..1eb2aec53c8 100644 --- a/Generator/test/Generator/generic_random_test.cpp +++ b/Generator/test/Generator/generic_random_test.cpp @@ -1,49 +1,80 @@ -#include #include -#include #include -#include #include +#include +#include +#include +#include +#include +#include #include #include using namespace CGAL; - -int -main( ) +void test_volume_mesh() { typedef Simple_cartesian R; typedef R::Point_3 Point; typedef R::FT FT; - typedef Polyhedron_3 Polyhedron; typedef Surface_mesh Surface_mesh; - typedef boost::property_map::type Vertex_point_pmap; - typedef boost::property_map::type Vertex_point_pmap_sm; - typedef Triangle_from_face_descriptor_map< - Polyhedron,Vertex_point_pmap> Generator; - typedef Triangle_from_face_descriptor_map< - Surface_mesh,Vertex_point_pmap_sm> Generator_SM; - typedef Random_points_in_triangle_3 Creator; - typedef boost::graph_traits::face_descriptor face_iterator; - typedef boost::graph_traits::face_descriptor face_iterator_sm; - - std::vector points; - Polyhedron poly; Surface_mesh sm; std::ifstream in("../../../Polyhedron/demo/Polyhedron/data/star.off"); in >> sm; CGAL_assertion(in && !sm.is_empty()); - poly.make_tetrahedron(Point(0.0,0.2,0.0), Point(-0.2,0.0,0.0), Point(0.2,0.0,0.0), Point(0.0,0.0,0.2)); Random_points_on_triangle_mesh_3 g(sm); CGAL::cpp11::copy_n( g, 3000, std::back_inserter(points)); for (std::size_t i = 0; i 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; + + + +void test_T2() +{ + 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); + +Random_points_on_triangle_mesh_2 + g(cdt); +CGAL::cpp11::copy_n( g, 300, std::back_inserter(points)); +for (std::size_t i = 0; i