Fixed random_points_in_triangle_mesh_2 to actually filter out-of-domain faces

This commit is contained in:
Mael Rouxel-Labbé 2018-02-16 16:09:30 +01:00
parent 861838bf2e
commit 55b928b08c
1 changed files with 58 additions and 18 deletions

View File

@ -28,12 +28,14 @@
#ifndef CGAL_POINT_GENERATORS_2_H #ifndef CGAL_POINT_GENERATORS_2_H
#define CGAL_POINT_GENERATORS_2_H 1 #define CGAL_POINT_GENERATORS_2_H 1
#include <CGAL/generators.h> #include <CGAL/generators.h>
#include <iterator>
#include <CGAL/number_type_basic.h> #include <CGAL/number_type_basic.h>
#include <CGAL/internal/Generic_random_point_generator.h> #include <CGAL/internal/Generic_random_point_generator.h>
#include <CGAL/iterator.h> #include <CGAL/iterator.h>
#include <iterator>
namespace CGAL { namespace CGAL {
template < class P, class Creator = template < class P, class Creator =
@ -547,6 +549,7 @@ void Random_points_in_triangle_2<P, Creator>::generate_point() {
} }
namespace internal { namespace internal {
//Functor returning Triangle_2 from Triangulation_2 Faces //Functor returning Triangle_2 from Triangulation_2 Faces
template <class T> template <class T>
class Triangle_from_face_2 class Triangle_from_face_2
@ -556,38 +559,75 @@ public:
typedef Triangle result_type; typedef Triangle result_type;
Triangle_from_face_2() {} Triangle_from_face_2() {}
Triangle operator()(typename T::Face_handle face)const { Triangle operator()(typename T::Finite_faces_iterator face) const {
return Triangle(face->vertex(0)->point(), face->vertex(1)->point(), face->vertex(2)->point()); return Triangle(face->vertex(0)->point(), face->vertex(1)->point(), face->vertex(2)->point());
} }
}; };
struct Is_not_in_domain
{
typedef bool result_type;
template <class FH>
result_type operator()(const FH fh) const {
return (!fh->is_in_domain());
}
};
template <class T>
class In_domain_finite_faces_iterator
: public Filter_iterator<typename T::Finite_faces_iterator, Is_not_in_domain>
{
typedef CGAL::Filter_iterator<typename T::Finite_faces_iterator, Is_not_in_domain> Base;
typedef In_domain_finite_faces_iterator<T> Self;
typedef typename T::Face_handle Face_handle;
typedef typename T::Finite_faces_iterator Finite_faces_iterator;
public:
In_domain_finite_faces_iterator() : Base() {}
In_domain_finite_faces_iterator(const Base &b) : Base(b) {}
Self & operator++() { Base::operator++(); return *this; }
Self & operator--() { Base::operator--(); return *this; }
Self operator++(int) { Self tmp(*this); ++(*this); return tmp; }
Self operator--(int) { Self tmp(*this); --(*this); return tmp; }
operator Finite_faces_iterator() const { return Base::base(); }
operator Face_handle() const { return Face_handle(Base::base()); }
};
}//end namespace internal }//end namespace internal
template <class P, template <class P,
class T, class T,
class Creator = class Creator = Creator_uniform_2<typename Kernel_traits<P>::Kernel::RT, P> >
Creator_uniform_2<typename Kernel_traits<P>::Kernel::RT,P> class Random_points_in_triangle_mesh_2
> : public Generic_random_point_generator<internal::In_domain_finite_faces_iterator<T>,
class Random_points_in_triangle_mesh_2 : public Generic_random_point_generator< internal::Triangle_from_face_2<T>,
typename T::Face_handle , Random_points_in_triangle_2<P, Creator>,
internal::Triangle_from_face_2<T>, P>
Random_points_in_triangle_2<P> , P> { {
public: public:
typedef Generic_random_point_generator<typename T::Face_handle, typedef Generic_random_point_generator<internal::In_domain_finite_faces_iterator<T>,
internal::Triangle_from_face_2<T>, internal::Triangle_from_face_2<T>,
Random_points_in_triangle_2<P, Creator>, Random_points_in_triangle_2<P, Creator>,
P> Base; P> Base;
typedef typename T::Face_handle Id; typedef typename T::Face_handle Id;
typedef P result_type; typedef P result_type;
typedef Random_points_in_triangle_mesh_2<P, T, Creator> This; typedef Random_points_in_triangle_mesh_2<P, T, Creator> This;
Random_points_in_triangle_mesh_2(const T& triangulation, Random& rnd = get_default_random())
Random_points_in_triangle_mesh_2( const T& triangulation, Random& rnd = get_default_random()) : Base(CGAL::make_prevent_deref_range(
: Base( CGAL::make_prevent_deref_range(triangulation.finite_faces_begin(), CGAL::filter_iterator(triangulation.finite_faces_end(),
triangulation.finite_faces_end()), internal::Is_not_in_domain(),
internal::Triangle_from_face_2<T>(), triangulation.finite_faces_begin()),
typename Kernel_traits<P>::Kernel::Compute_area_2(), CGAL::filter_iterator(triangulation.finite_faces_end(),
rnd ) internal::Is_not_in_domain())),
internal::Triangle_from_face_2<T>(),
typename Kernel_traits<P>::Kernel::Compute_area_2(),
rnd)
{ {
} }
This& operator++() { This& operator++() {
Base::generate_point(); Base::generate_point();
return *this; return *this;