add a random generator on edges of a mesh

This commit is contained in:
Sébastien Loriot 2016-12-27 16:30:08 +01:00
parent 3e018b4d1a
commit 1d1b0301fe
1 changed files with 77 additions and 7 deletions

View File

@ -271,8 +271,24 @@ public:
(std::max)(to_double(p.z()), to_double(q.z()))), (std::max)(to_double(p.z()), to_double(q.z()))),
rnd) , _p(p), _q(q) rnd) , _p(p), _q(q)
{ {
generate_point(); generate_point();
} }
template <class Segment_3>
Random_points_on_segment_3( const Segment_3& s,
Random& rnd = CGAL::get_default_random())
// g is an input iterator creating points of type `P' uniformly
// distributed on the segment from p to q except q, i.e. `*g' ==
// \lambda p + (1-\lambda)\, q where 0 <= \lambda < 1 . A single
// random number is needed from `rnd' for each point.
: Random_generator_base<P>( (std::max)( (std::max)( (std::max)(to_double(s[0].x()), to_double(s[1].x())),
(std::max)(to_double(s[0].y()), to_double(s[1].y()))),
(std::max)(to_double(s[0].z()), to_double(s[1].z()))),
rnd) , _p(s[0]), _q(s[1])
{
generate_point();
}
const P& source() const { return _p; } const P& source() const { return _p; }
const P& target() const { return _q; } const P& target() const { return _q; }
This& operator++() { This& operator++() {
@ -373,13 +389,11 @@ struct Random_points_in_triangle_mesh_3
typedef typename boost::property_traits<VertexPointMap>::value_type P; typedef typename boost::property_traits<VertexPointMap>::value_type P;
typedef Generic_random_point_generator< typedef Generic_random_point_generator<
typename boost::graph_traits <TriangleMesh>::face_descriptor , typename boost::graph_traits <TriangleMesh>::face_descriptor ,
CGAL::Property_map_to_unary_function<typename CGAL::Triangle_from_face_descriptor_map< CGAL::Property_map_to_unary_function<CGAL::Triangle_from_face_descriptor_map<
TriangleMesh,VertexPointMap> >, TriangleMesh,VertexPointMap> >,
Random_points_in_triangle_3<P, Creator> , P> Base; Random_points_in_triangle_3<P, Creator> , P> Base;
typedef typename CGAL::Triangle_from_face_descriptor_map< typedef typename CGAL::Triangle_from_face_descriptor_map<
TriangleMesh,VertexPointMap> Pmap; TriangleMesh,VertexPointMap> Object_from_id;
typedef typename CGAL::Triangle_from_face_descriptor_map<
TriangleMesh,VertexPointMap> Object_from_id_map;
typedef typename boost::graph_traits<TriangleMesh>::face_descriptor Id; typedef typename boost::graph_traits<TriangleMesh>::face_descriptor Id;
typedef P result_type; typedef P result_type;
typedef Random_points_in_triangle_mesh_3< TriangleMesh, VertexPointMap, Creator> This; typedef Random_points_in_triangle_mesh_3< TriangleMesh, VertexPointMap, Creator> This;
@ -387,14 +401,14 @@ struct Random_points_in_triangle_mesh_3
Random_points_in_triangle_mesh_3( const TriangleMesh& mesh,Random& rnd = get_default_random()) Random_points_in_triangle_mesh_3( const TriangleMesh& mesh,Random& rnd = get_default_random())
: Base( faces(mesh), : Base( faces(mesh),
CGAL::Property_map_to_unary_function<Pmap>(Pmap(&mesh, get(vertex_point, mesh))), CGAL::Property_map_to_unary_function<Object_from_id>(Object_from_id(&mesh, get(vertex_point, mesh))),
internal::Apply_approx_sqrt<typename Kernel_traits<P>::Kernel::Compute_squared_area_3>(), internal::Apply_approx_sqrt<typename Kernel_traits<P>::Kernel::Compute_squared_area_3>(),
rnd ) rnd )
{ {
} }
Random_points_in_triangle_mesh_3( const TriangleMesh& mesh, VertexPointMap vpm, Random& rnd = get_default_random()) Random_points_in_triangle_mesh_3( const TriangleMesh& mesh, VertexPointMap vpm, Random& rnd = get_default_random())
: Base( faces(mesh), : Base( faces(mesh),
CGAL::Property_map_to_unary_function<Pmap>(Pmap(&mesh, vpm)), CGAL::Property_map_to_unary_function<Object_from_id>(Object_from_id(&mesh, vpm)),
internal::Apply_approx_sqrt<typename Kernel_traits<P>::Kernel::Compute_squared_area_3>(), internal::Apply_approx_sqrt<typename Kernel_traits<P>::Kernel::Compute_squared_area_3>(),
rnd ) rnd )
{ {
@ -414,6 +428,62 @@ struct Random_points_in_triangle_mesh_3
} }
}; };
template <class EdgeListGraph,
class VertexPointMap = typename boost::property_map<EdgeListGraph,
CGAL::vertex_point_t>::const_type,
class Creator = Creator_uniform_3<
typename Kernel_traits< typename boost::property_traits<VertexPointMap>::value_type >::Kernel::RT,
typename boost::property_traits<VertexPointMap>::value_type >
>
struct Random_points_on_edge_list_graph_3
: public Generic_random_point_generator<
typename boost::graph_traits <EdgeListGraph>::edge_descriptor,
CGAL::Property_map_to_unary_function<CGAL::Segment_from_edge_descriptor_map<
EdgeListGraph, VertexPointMap > >,
Random_points_on_segment_3<typename boost::property_traits<VertexPointMap>::value_type, Creator>,
typename boost::property_traits<VertexPointMap>::value_type>
{
typedef typename boost::property_traits<VertexPointMap>::value_type P;
typedef Generic_random_point_generator<
typename boost::graph_traits <EdgeListGraph>::edge_descriptor,
CGAL::Property_map_to_unary_function<CGAL::Segment_from_edge_descriptor_map<
EdgeListGraph, VertexPointMap > >,
Random_points_on_segment_3<P, Creator> , P> Base;
typedef typename CGAL::Segment_from_edge_descriptor_map<
EdgeListGraph,VertexPointMap> Object_from_id;
typedef typename boost::graph_traits<EdgeListGraph>::edge_descriptor Id;
typedef P result_type;
typedef Random_points_on_edge_list_graph_3< EdgeListGraph, VertexPointMap, Creator> This;
Random_points_on_edge_list_graph_3( const EdgeListGraph& mesh,Random& rnd = get_default_random())
: Base( edges(mesh),
CGAL::Property_map_to_unary_function<Object_from_id>(Object_from_id(&mesh, get(vertex_point, mesh))),
internal::Apply_approx_sqrt<typename Kernel_traits<P>::Kernel::Compute_squared_length_3>(),
rnd )
{
}
Random_points_on_edge_list_graph_3( const EdgeListGraph& mesh, VertexPointMap vpm, Random& rnd = get_default_random())
: Base( edges(mesh),
CGAL::Property_map_to_unary_function<Object_from_id>(Object_from_id(&mesh, vpm)),
internal::Apply_approx_sqrt<typename Kernel_traits<P>::Kernel::Compute_squared_length_3>(),
rnd )
{
}
This& operator++() {
Base::generate_point();
return *this;
}
This operator++(int) {
This tmp = *this;
++(*this);
return tmp;
}
double mesh_length() const
{
return this->sum_of_weights();
}
};
namespace internal namespace internal
{ {