2828
2929#ifndef CGAL_POINT_GENERATORS_2_H
3030#define CGAL_POINT_GENERATORS_2_H 1
31+
3132#include < CGAL/generators.h>
32- #include < iterator>
3333#include < CGAL/number_type_basic.h>
3434#include < CGAL/internal/Generic_random_point_generator.h>
3535#include < CGAL/iterator.h>
3636
37+ #include < iterator>
38+
3739namespace CGAL {
3840
3941template < class P , class Creator =
@@ -547,6 +549,7 @@ void Random_points_in_triangle_2<P, Creator>::generate_point() {
547549}
548550
549551namespace internal {
552+
550553// Functor returning Triangle_2 from Triangulation_2 Faces
551554template <class T >
552555class Triangle_from_face_2
@@ -556,38 +559,75 @@ class Triangle_from_face_2
556559 typedef Triangle result_type;
557560 Triangle_from_face_2 () {}
558561
559- Triangle operator ()(typename T::Face_handle face)const {
562+ Triangle operator ()(typename T::Finite_faces_iterator face) const {
560563 return Triangle (face->vertex (0 )->point (), face->vertex (1 )->point (), face->vertex (2 )->point ());
561564 }
562565};
566+
567+ struct Is_not_in_domain
568+ {
569+ typedef bool result_type;
570+
571+ template <class FH >
572+ result_type operator ()(const FH fh) const {
573+ return (!fh->is_in_domain ());
574+ }
575+ };
576+
577+ template <class T >
578+ class In_domain_finite_faces_iterator
579+ : public Filter_iterator<typename T::Finite_faces_iterator, Is_not_in_domain>
580+ {
581+ typedef CGAL::Filter_iterator<typename T::Finite_faces_iterator, Is_not_in_domain> Base;
582+ typedef In_domain_finite_faces_iterator<T> Self;
583+
584+ typedef typename T::Face_handle Face_handle;
585+ typedef typename T::Finite_faces_iterator Finite_faces_iterator;
586+
587+ public:
588+ In_domain_finite_faces_iterator () : Base() {}
589+ In_domain_finite_faces_iterator (const Base &b) : Base(b) {}
590+ Self & operator ++() { Base::operator ++(); return *this ; }
591+ Self & operator --() { Base::operator --(); return *this ; }
592+ Self operator ++(int ) { Self tmp (*this ); ++(*this ); return tmp; }
593+ Self operator --(int ) { Self tmp (*this ); --(*this ); return tmp; }
594+ operator Finite_faces_iterator () const { return Base::base (); }
595+ operator Face_handle () const { return Face_handle (Base::base ()); }
596+ };
597+
563598}// end namespace internal
599+
564600template <class P ,
565601 class T ,
566- class Creator =
567- Creator_uniform_2< typename Kernel_traits<P>::Kernel::RT,P>
568- >
569- class Random_points_in_triangle_mesh_2 : public Generic_random_point_generator <
570- typename T::Face_handle ,
571- internal::Triangle_from_face_2<T>,
572- Random_points_in_triangle_2<P> , P> {
602+ class Creator = Creator_uniform_2< typename Kernel_traits<P>::Kernel::RT, P> >
603+ class Random_points_in_triangle_mesh_2
604+ : public Generic_random_point_generator<internal::In_domain_finite_faces_iterator<T>,
605+ internal::Triangle_from_face_2<T>,
606+ Random_points_in_triangle_2<P, Creator> ,
607+ P>
608+ {
573609public:
574- typedef Generic_random_point_generator<typename T::Face_handle ,
610+ typedef Generic_random_point_generator<internal::In_domain_finite_faces_iterator<T> ,
575611 internal::Triangle_from_face_2<T>,
576612 Random_points_in_triangle_2<P, Creator>,
577613 P> Base;
578614 typedef typename T::Face_handle Id;
579- typedef P result_type;
615+ typedef P result_type;
580616 typedef Random_points_in_triangle_mesh_2<P, T, Creator> This;
581617
582-
583- Random_points_in_triangle_mesh_2 ( const T& triangulation, Random& rnd = get_default_random())
584- : Base( CGAL::make_prevent_deref_range(triangulation.finite_faces_begin(),
585- triangulation.finite_faces_end()),
586- internal::Triangle_from_face_2<T>(),
587- typename Kernel_traits<P>::Kernel::Compute_area_2(),
588- rnd )
618+ Random_points_in_triangle_mesh_2 (const T& triangulation, Random& rnd = get_default_random())
619+ : Base(CGAL::make_prevent_deref_range(
620+ CGAL::filter_iterator (triangulation.finite_faces_end(),
621+ internal::Is_not_in_domain(),
622+ triangulation.finite_faces_begin()),
623+ CGAL::filter_iterator(triangulation.finite_faces_end(),
624+ internal::Is_not_in_domain())),
625+ internal::Triangle_from_face_2<T>(),
626+ typename Kernel_traits<P>::Kernel::Compute_area_2(),
627+ rnd)
589628 {
590629 }
630+
591631 This& operator ++() {
592632 Base::generate_point ();
593633 return *this ;
0 commit comments