mirror of https://github.com/CGAL/cgal
Implementation and changes
- Change Generic_random_point_generator to use a Functor instead of a property_map - Change Random_points_on_triangle_mesh_3 to use a functor wrapping around a PMAP instead of the PMAP - Implement a random point generator on a Triangulation_2
This commit is contained in:
parent
7bdd704de2
commit
ce9d373760
|
|
@ -34,7 +34,7 @@ template <typename Id, class ObjectFromIdMap, class GeneratorOnObject, class P>
|
|||
class Generic_random_point_generator : public Random_generator_base<P>
|
||||
{
|
||||
typedef Generic_random_point_generator<Id, ObjectFromIdMap, GeneratorOnObject, P> This;
|
||||
typedef typename boost::property_traits<ObjectFromIdMap>::reference Geometric_object_ref;
|
||||
typedef typename ObjectFromIdMap::reference Geometric_object_ref;
|
||||
typedef typename cpp11::result_of<GeneratorOnObject(Id)>::type result_type;
|
||||
|
||||
std::vector<Id> 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<Id, ObjectFromIdMap, GeneratorOnObject, P>:
|
|||
);
|
||||
|
||||
// generate the points
|
||||
GeneratorOnObject pointCreator(get(object_from_id_map,ids[target]));
|
||||
GeneratorOnObject pointCreator(object_from_id_map(ids[target]));
|
||||
this->d_item = *pointCreator;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,12 +23,16 @@
|
|||
// Author(s) : Lutz Kettner <kettner@inf.ethz.ch>
|
||||
// Pedro Machado Manhaes de Castro <pmmc@cin.ufpe.br>
|
||||
// Alexandru Tifrea
|
||||
// Maxime Gimeno
|
||||
|
||||
|
||||
#ifndef CGAL_POINT_GENERATORS_2_H
|
||||
#define CGAL_POINT_GENERATORS_2_H 1
|
||||
#include <CGAL/generators.h>
|
||||
#include <iterator>
|
||||
#include <CGAL/number_type_basic.h>
|
||||
#include <CGAL/internal/Generic_random_point_generator.h>
|
||||
#include <CGAL/boost/graph/graph_traits_HalfedgeDS.h>
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
|
|
@ -542,6 +546,55 @@ void Random_points_in_triangle_2<P, Creator>::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 T>
|
||||
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 P, class T>
|
||||
class Random_points_on_triangle_mesh_2 : public Generic_random_point_generator<
|
||||
typename T::Face_handle ,
|
||||
internal::Triangle_from_face_2<T>,
|
||||
Random_points_in_triangle_2<P> , P> {
|
||||
public:
|
||||
typedef Generic_random_point_generator<
|
||||
typename T::Face_handle,
|
||||
internal::Triangle_from_face_2<T>,
|
||||
Random_points_in_triangle_2<P> , P> Base;
|
||||
typedef typename T::Face_handle Id;
|
||||
typedef P result_type;
|
||||
typedef Random_points_on_triangle_mesh_2<P, T> This;
|
||||
|
||||
|
||||
Random_points_on_triangle_mesh_2( T& triangulation,Random& rnd = default_random)
|
||||
: Base( make_range( internal::Prevent_deref<typename T::Finite_faces_iterator>(triangulation.finite_faces_begin()),
|
||||
internal::Prevent_deref<typename T::Finite_faces_iterator>(triangulation.finite_faces_end())),
|
||||
internal::Triangle_from_face_2<T>(),
|
||||
typename Kernel_traits<P>::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 //
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
// Author(s) : Lutz Kettner <kettner@inf.ethz.ch>
|
||||
// Pedro Machado Manhaes de Castro <pmmc@cin.ufpe.br>
|
||||
// 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<P, Creator>::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 Mesh, typename Id>
|
||||
class Triangle_from_face_3
|
||||
{
|
||||
typedef typename boost::property_map<Mesh,
|
||||
CGAL::vertex_point_t>::type Vertex_point_map;
|
||||
typedef typename CGAL::Triangle_from_face_descriptor_map<
|
||||
Mesh,Vertex_point_map> PMAP;
|
||||
typedef typename boost::property_traits<PMAP>::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 P, class Mesh>
|
||||
class Random_points_on_triangle_mesh_3 : public Generic_random_point_generator<
|
||||
typename boost::graph_traits <Mesh>::face_descriptor ,
|
||||
CGAL::Triangle_from_face_descriptor_map<Mesh,typename boost::property_map<Mesh, CGAL::vertex_point_t>::type >,
|
||||
internal::Triangle_from_face_3<Mesh,
|
||||
typename boost::graph_traits<Mesh>::face_descriptor>,
|
||||
Random_points_in_triangle_3<P> , P> {
|
||||
public:
|
||||
typedef Generic_random_point_generator<
|
||||
typename boost::graph_traits <Mesh>::face_descriptor ,
|
||||
CGAL::Triangle_from_face_descriptor_map<Mesh,typename boost::property_map<Mesh, CGAL::vertex_point_t>::type >,
|
||||
internal::Triangle_from_face_3<Mesh,
|
||||
typename boost::graph_traits<Mesh>::face_descriptor>,
|
||||
Random_points_in_triangle_3<P> , P> Base;
|
||||
typedef typename boost::property_map<Mesh,
|
||||
CGAL::vertex_point_t>::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<Mesh, Id>(Object_from_id_map(&mesh)),
|
||||
typename Kernel_traits<P>::Kernel::Compute_area_3(),
|
||||
rnd )
|
||||
{
|
||||
|
|
@ -345,7 +370,6 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
} //namespace CGAL
|
||||
|
||||
#endif // CGAL_POINT_GENERATORS_3_H //
|
||||
|
|
|
|||
|
|
@ -1,49 +1,80 @@
|
|||
#include <CGAL/internal/Generic_random_point_generator.h>
|
||||
#include <CGAL/point_generators_3.h>
|
||||
#include <CGAL/boost/graph/property_maps.h>
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/Surface_mesh.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/Polygon_2.h>
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace CGAL;
|
||||
|
||||
int
|
||||
main( )
|
||||
void test_volume_mesh()
|
||||
{
|
||||
typedef Simple_cartesian<double> R;
|
||||
typedef R::Point_3 Point;
|
||||
typedef R::FT FT;
|
||||
typedef Polyhedron_3<R> Polyhedron;
|
||||
typedef Surface_mesh<Point> Surface_mesh;
|
||||
typedef boost::property_map<Polyhedron,
|
||||
vertex_point_t>::type Vertex_point_pmap;
|
||||
typedef boost::property_map<Surface_mesh,
|
||||
vertex_point_t>::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<Point> Creator;
|
||||
typedef boost::graph_traits<Polyhedron>::face_descriptor face_iterator;
|
||||
typedef boost::graph_traits<Surface_mesh>::face_descriptor face_iterator_sm;
|
||||
|
||||
|
||||
|
||||
std::vector<Point> 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<Point, Surface_mesh>
|
||||
g(sm);
|
||||
CGAL::cpp11::copy_n( g, 3000, std::back_inserter(points));
|
||||
for (std::size_t i = 0; i<points.size(); ++i)
|
||||
std::cerr<<points[i]<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
|
||||
|
||||
void test_T2()
|
||||
{
|
||||
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);
|
||||
|
||||
Random_points_on_triangle_mesh_2<Point, CDT>
|
||||
g(cdt);
|
||||
CGAL::cpp11::copy_n( g, 300, std::back_inserter(points));
|
||||
for (std::size_t i = 0; i<points.size(); ++i)
|
||||
std::cerr<<points[i]<<std::endl;
|
||||
|
||||
|
||||
}
|
||||
int
|
||||
main( )
|
||||
{
|
||||
test_volume_mesh();
|
||||
//test_T2();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue