Merge pull request #7712 from sloriot/BGL-dynamic_with_default

Adding a default to dynamic property maps
This commit is contained in:
Laurent Rineau 2024-04-05 14:25:20 +02:00
commit 4677ece3da
12 changed files with 69 additions and 73 deletions

View File

@ -510,11 +510,12 @@ Dynamic property tags, such as `dynamic_vertex_property_t`, are a generalization
value type of the dynamic property map, and a default value.
`boost::property_map<G,T>::%type` is used to obtain the
type of the dynamic property map for a graph of type `G`, for a
dynamic property tag `T`. This type must be default constructible and assignable.
dynamic property tag `T`. This type must be assignable, and if no
default is provided it must be default constructible.
As for ordinary properties, the function `%get()` is overloaded and
serves for retrieving a property map for a given graph and dynamic
property tag, as well as for retrieving a value for a given key and
property map.
property map. The default value is provided as third parameter.
The following example shows how to attach a `string` property to vertices and
a `double` value to the halfedges of a graph.

View File

@ -21,6 +21,7 @@
#include <memory>
#include <CGAL/boost/graph/internal/Has_member_id.h>
#include <CGAL/Distance_3/Point_3_Point_3.h>
#include <CGAL/Dynamic_property_map.h>
namespace CGAL {
@ -126,11 +127,20 @@ typename boost::property_map<CGAL_HDS_CLASS, PropertyTag >::type
get(PropertyTag,CGAL_HDS_CLASS&)
{ return typename boost::property_map<CGAL_HDS_CLASS, PropertyTag >::type(); }
// generalized 3-ary get functions
template<class CGAL_HDS_TMPLT, class PropertyTag, class Key>
template<class CGAL_HDS_TMPLT, class PropertyTag, class Key,
class F = std::enable_if_t<!std::is_same_v<PropertyTag, dynamic_vertex_property_t<Key>> &&
!std::is_same_v<PropertyTag, dynamic_halfedge_property_t<Key>> &&
!std::is_same_v<PropertyTag, dynamic_edge_property_t<Key>> &&
!std::is_same_v<PropertyTag, dynamic_face_property_t<Key>>
>
>
typename boost::property_traits< typename boost::property_map<CGAL_HDS_CLASS, PropertyTag >::type >::reference
get(PropertyTag p,CGAL_HDS_CLASS& g, const Key& key)
{ return get(get(p, g), key); }
{
return get(get(p, g), key);
}
template<class CGAL_HDS_TMPLT, class PropertyTag, class Key>
typename boost::property_traits< typename boost::property_map<CGAL_HDS_CLASS, PropertyTag >::const_type >::reference
@ -139,13 +149,13 @@ get(PropertyTag p,CGAL_HDS_CLASS const& g, const Key& key)
#define DECLARE_HDS_DYNAMIC_PM(TAG, DESCRIPTOR) \
#define DECLARE_HDS_DYNAMIC_PM(TAG, DESCRIPTOR) \
template <typename CGAL_HDS_TMPLT, class T> \
typename boost::property_map<CGAL_HDS_CLASS, TAG >::const_type \
get(const TAG&, const CGAL_HDS_CLASS&) \
{ \
get(const TAG&, const CGAL_HDS_CLASS&, const T& dv = T()) \
{ \
typedef typename boost::graph_traits< CGAL_HDS_CLASS >::DESCRIPTOR descriptor; \
return internal::Dynamic_property_map<descriptor,T>(); \
return internal::Dynamic_property_map<descriptor,T>(dv); \
}
DECLARE_HDS_DYNAMIC_PM(dynamic_vertex_property_t<T>, vertex_descriptor)

View File

@ -75,6 +75,7 @@ struct Non_manifold_feature_map
halfedge_descriptor hd = halfedge(ed, pm);
// an edge can be non-manifold only if both its vertices are non-manifold
// THIS IS NOT TRUE!
if ( get(v_nm_id, source(hd, pm))==std::size_t(-1) ||
get(v_nm_id, target(hd, pm))==std::size_t(-1) ) continue;

View File

@ -134,7 +134,6 @@ void angle_and_area_smoothing(const FaceRange& faces,
TriangleMesh& tmesh,
const NamedParameters& np = parameters::default_values())
{
typedef typename boost::graph_traits<TriangleMesh>::vertex_descriptor vertex_descriptor;
typedef typename boost::graph_traits<TriangleMesh>::halfedge_descriptor halfedge_descriptor;
typedef typename boost::graph_traits<TriangleMesh>::edge_descriptor edge_descriptor;
typedef typename boost::graph_traits<TriangleMesh>::face_descriptor face_descriptor;
@ -209,14 +208,7 @@ void angle_and_area_smoothing(const FaceRange& faces,
const bool use_Delaunay_flips = choose_parameter(get_parameter(np, internal_np::use_Delaunay_flips), true);
VCMap vcmap = choose_parameter(get_parameter(np, internal_np::vertex_is_constrained),
get(Vertex_property_tag(), tmesh));
// If it's the default vcmap, manually set everything to false because the dynamic pmap has no default initialization
if((std::is_same<VCMap, Default_VCMap>::value))
{
for(vertex_descriptor v : vertices(tmesh))
put(vcmap, v, false);
}
get(Vertex_property_tag(), tmesh, false));
ECMap ecmap = choose_parameter(get_parameter(np, internal_np::edge_is_constrained),
Static_boolean_property_map<edge_descriptor, false>());

View File

@ -154,11 +154,8 @@ public:
typedef typename boost::property_map<TriangleMesh,
Edge_property_tag>::type Marked_edges_map;
Marked_edges_map marks = get(Edge_property_tag(), mesh_);
Marked_edges_map marks = get(Edge_property_tag(), mesh_, false);
// dynamic pmaps do not have default values...
for(edge_descriptor e : edges(mesh_))
put(marks, e, false);
for(edge_descriptor e : edge_range)
put(marks, e, true);
#ifdef CGAL_PMP_SMOOTHING_DEBUG

View File

@ -105,9 +105,7 @@ void simplify_range(HalfedgeRange& halfedge_range,
typedef CGAL::dynamic_halfedge_property_t<bool> Halfedge_bool_tag;
typedef typename boost::property_map<TriangleMesh, Halfedge_bool_tag>::type Range_halfedges;
Range_halfedges range_halfedges = get(Halfedge_bool_tag(), tm);
for(halfedge_descriptor h : halfedge_range)
put(range_halfedges, h, true);
Range_halfedges range_halfedges = get(Halfedge_bool_tag(), tm, false);
CGAL_postcondition_code(const std::size_t initial_n = halfedge_range.size();)
@ -1234,10 +1232,10 @@ std::size_t snap_non_conformal(HalfedgeRange& halfedge_range_A,
// We keep in memory pairs of source/target edges that are stitchable after vertex-vertex snapping
// --> these halfedges should not be considered as targets in non-conformal snapping
// Similarly, matching vertices whose incident edges have matching directions are also locked
Locked_vertices locked_vertices_A = get(Vertex_bool_tag(), tm_A);
Locked_vertices locked_vertices_B = get(Vertex_bool_tag(), tm_B);
Locked_halfedges locked_halfedges_A = get(Halfedge_bool_tag(), tm_A);
Locked_halfedges locked_halfedges_B = get(Halfedge_bool_tag(), tm_B);
Locked_vertices locked_vertices_A = get(Vertex_bool_tag(), tm_A, false);
Locked_vertices locked_vertices_B = get(Vertex_bool_tag(), tm_B, false);
Locked_halfedges locked_halfedges_A = get(Halfedge_bool_tag(), tm_A, false);
Locked_halfedges locked_halfedges_B = get(Halfedge_bool_tag(), tm_B, false);
std::vector<std::pair<vertex_descriptor, vertex_descriptor> > locked_vertices;
std::vector<halfedge_descriptor> locked_halfedges_A_vector, locked_halfedges_B_vector;

View File

@ -58,9 +58,7 @@ bool is_non_manifold_vertex(typename boost::graph_traits<PolygonMesh>::vertex_de
typedef typename boost::property_map<PolygonMesh, Halfedge_property_tag>::const_type Visited_halfedge_map;
// Dynamic pmaps do not have default initialization values (yet)
Visited_halfedge_map visited_halfedges = get(Halfedge_property_tag(), pm);
for(halfedge_descriptor h : halfedges(pm))
put(visited_halfedges, h, false);
Visited_halfedge_map visited_halfedges = get(Halfedge_property_tag(), pm, false);
std::size_t incident_null_faces_counter = 0;
for(halfedge_descriptor h : halfedges_around_target(v, pm))
@ -324,20 +322,11 @@ OutputIterator non_manifold_vertices(const PolygonMesh& pm,
typedef CGAL::dynamic_halfedge_property_t<bool> Halfedge_property_tag;
typedef typename boost::property_map<PolygonMesh, Halfedge_property_tag>::const_type Visited_halfedge_map;
Known_manifold_vertex_map known_nm_vertices = get(Vertex_bool_tag(), pm);
Visited_vertex_map visited_vertices = get(Vertex_halfedge_tag(), pm);
Visited_halfedge_map visited_halfedges = get(Halfedge_property_tag(), pm);
halfedge_descriptor null_h = boost::graph_traits<PolygonMesh>::null_halfedge();
// Dynamic pmaps do not have default initialization values (yet)
for(vertex_descriptor v : vertices(pm))
{
put(known_nm_vertices, v, false);
put(visited_vertices, v, null_h);
}
for(halfedge_descriptor h : halfedges(pm))
put(visited_halfedges, h, false);
Known_manifold_vertex_map known_nm_vertices = get(Vertex_bool_tag(), pm, false);
Visited_vertex_map visited_vertices = get(Vertex_halfedge_tag(), pm, null_h);
Visited_halfedge_map visited_halfedges = get(Halfedge_property_tag(), pm, false);
for(halfedge_descriptor h : halfedges(pm))
{

View File

@ -639,7 +639,7 @@ bool remove_almost_degenerate_faces(const FaceRange& face_range,
// Vertex property map that combines the VCM and the fact that extremities of a constrained edge should be constrained
typedef CGAL::dynamic_vertex_property_t<bool> Vertex_property_tag;
typedef typename boost::property_map<TriangleMesh, Vertex_property_tag>::type DVCM;
DVCM vcm = get(Vertex_property_tag(), tmesh);
DVCM vcm = get(Vertex_property_tag(), tmesh, false);
// parameters
const double cap_threshold =

View File

@ -190,7 +190,7 @@ struct Boundary_cycle_rep_maintainer
Boundary_cycle_rep_maintainer(PolygonMesh& pmesh)
: m_pmesh(pmesh)
{
m_candidate_halfedges = get(Candidate_tag(), pmesh);
m_candidate_halfedges = get(Candidate_tag(), pmesh, false);
}
public:

View File

@ -15,16 +15,24 @@ int main()
CGAL::make_triangle(Point_3(0,0,0),Point_3(1,0,0),Point_3(1,1,0), mesh);
typedef boost::property_map<Mesh, CGAL::dynamic_vertex_property_t<std::string> >::type VertexNameMap;
VertexNameMap vnm = get(CGAL::dynamic_vertex_property_t<std::string>(), mesh);
VertexNameMap vnm = get(CGAL::dynamic_vertex_property_t<std::string>(), mesh, std::string("default"));
put(vnm, *(vertices(mesh).first), "Paris");
assert(get(vnm, *(vertices(mesh).first))=="Paris");
assert(get(vnm, *(std::next(vertices(mesh).first)))=="default");
std::cout << get(vnm, *(vertices(mesh).first)) << std::endl;
std::cout << get(vnm, *(std::next(vertices(mesh).first))) << std::endl;
typedef boost::property_map<Mesh, CGAL::dynamic_halfedge_property_t<double> >::type TrafficDensityMap;
TrafficDensityMap tdm = get(CGAL::dynamic_halfedge_property_t<double>(), mesh);
TrafficDensityMap tdm = get(CGAL::dynamic_halfedge_property_t<double>(), mesh, -1.);
put(tdm, *(halfedges(mesh).first), 0.7);
assert(get(tdm, *(halfedges(mesh).first))==0.7);
assert(get(tdm, *(std::next(halfedges(mesh).first)))==-1.);
std::cout << get(tdm, *(halfedges(mesh).first)) << std::endl;
std::cout << get(tdm, *(std::next(halfedges(mesh).first))) << std::endl;
return 0;
}

View File

@ -135,8 +135,8 @@ struct Dynamic_with_index
: m_values()
{}
Dynamic_with_index(std::size_t num_features)
: m_values( new std::vector<value_type>(num_features) )
Dynamic_with_index(std::size_t num_features, Value default_value = Value())
: m_values( new std::vector<value_type>(num_features, default_value) )
{}
friend reference get(const Dynamic_with_index& m, const key_type& k)
@ -228,34 +228,34 @@ namespace CGAL {
template <typename T, typename G>
typename boost::property_map<G, dynamic_vertex_property_t<T> >::const_type
get(const CGAL::dynamic_vertex_property_t<T>&, const G&)
get(const CGAL::dynamic_vertex_property_t<T>&, const G&, const T& default_value = T())
{
typedef typename boost::graph_traits<G>::vertex_descriptor vertex_descriptor;
return internal::Dynamic_property_map<vertex_descriptor,T>();
return internal::Dynamic_property_map<vertex_descriptor,T>(default_value);
}
template <typename T, typename G>
typename boost::property_map<G, dynamic_halfedge_property_t<T> >::const_type
get(const CGAL::dynamic_halfedge_property_t<T>&, const G&)
get(const CGAL::dynamic_halfedge_property_t<T>&, const G&, const T& default_value = T())
{
typedef typename boost::graph_traits<G>::halfedge_descriptor halfedge_descriptor;
return internal::Dynamic_property_map<halfedge_descriptor,T>();
return internal::Dynamic_property_map<halfedge_descriptor,T>(default_value);
}
template <typename T, typename G>
typename boost::property_map<G, dynamic_edge_property_t<T> >::const_type
get(const CGAL::dynamic_edge_property_t<T>&, const G&)
get(const CGAL::dynamic_edge_property_t<T>&, const G&, const T& default_value = T())
{
typedef typename boost::graph_traits<G>::edge_descriptor edge_descriptor;
return internal::Dynamic_property_map<edge_descriptor,T>();
return internal::Dynamic_property_map<edge_descriptor,T>(default_value);
}
template <typename T, typename G>
typename boost::property_map<G, dynamic_face_property_t<T> >::const_type
get(const CGAL::dynamic_face_property_t<T>&, const G&)
get(const CGAL::dynamic_face_property_t<T>&, const G&, const T& default_value = T())
{
typedef typename boost::graph_traits<G>::face_descriptor face_descriptor;
return internal::Dynamic_property_map<face_descriptor,T>();
return internal::Dynamic_property_map<face_descriptor,T>(default_value);
}
template<typename G, typename Descriptor, typename T>

View File

@ -353,67 +353,67 @@ namespace CGAL {
// get functions for dynamic properties of mutable Surface_mesh
template <typename Point, typename T>
typename boost::property_map<CGAL::Surface_mesh<Point>, dynamic_vertex_property_t<T> >::type
get(dynamic_vertex_property_t<T>, Surface_mesh<Point>& sm)
get(dynamic_vertex_property_t<T>, Surface_mesh<Point>& sm, const T& default_value = T())
{
typedef typename boost::property_map<Surface_mesh<Point>, dynamic_vertex_property_t<T> >::SMPM SMPM;
typedef typename boost::property_map<Surface_mesh<Point>, dynamic_vertex_property_t<T> >::type DPM;
return DPM(sm, new SMPM(sm.template add_property_map<typename Surface_mesh<Point>::Vertex_index, T>(std::string()).first));
return DPM(sm, new SMPM(sm.template add_property_map<typename Surface_mesh<Point>::Vertex_index, T>(std::string(), default_value).first));
}
template <typename Point, typename T>
typename boost::property_map<Surface_mesh<Point>, dynamic_face_property_t<T> >::type
get(dynamic_face_property_t<T>, Surface_mesh<Point>& sm)
get(dynamic_face_property_t<T>, Surface_mesh<Point>& sm, const T& default_value = T())
{
typedef typename boost::property_map<Surface_mesh<Point>, dynamic_face_property_t<T> >::SMPM SMPM;
typedef typename boost::property_map<Surface_mesh<Point>, dynamic_face_property_t<T> >::type DPM;
return DPM(sm, new SMPM(sm.template add_property_map<typename Surface_mesh<Point>::Face_index, T>(std::string()).first));
return DPM(sm, new SMPM(sm.template add_property_map<typename Surface_mesh<Point>::Face_index, T>(std::string(), default_value).first));
}
template <typename Point, typename T>
typename boost::property_map<Surface_mesh<Point>, dynamic_edge_property_t<T> >::type
get(dynamic_edge_property_t<T>, Surface_mesh<Point>& sm)
get(dynamic_edge_property_t<T>, Surface_mesh<Point>& sm, const T& default_value = T())
{
typedef typename boost::property_map<Surface_mesh<Point>, dynamic_edge_property_t<T> >::SMPM SMPM;
typedef typename boost::property_map<Surface_mesh<Point>, dynamic_edge_property_t<T> >::type DPM;
return DPM(sm, new SMPM(sm.template add_property_map<typename Surface_mesh<Point>::Edge_index, T>(std::string()).first));
return DPM(sm, new SMPM(sm.template add_property_map<typename Surface_mesh<Point>::Edge_index, T>(std::string(), default_value).first));
}
template <typename Point, typename T>
typename boost::property_map<Surface_mesh<Point>, dynamic_halfedge_property_t<T> >::type
get(dynamic_halfedge_property_t<T>, Surface_mesh<Point>& sm)
get(dynamic_halfedge_property_t<T>, Surface_mesh<Point>& sm, const T& default_value = T())
{
typedef typename boost::property_map<Surface_mesh<Point>, dynamic_halfedge_property_t<T> >::SMPM SMPM;
typedef typename boost::property_map<Surface_mesh<Point>, dynamic_halfedge_property_t<T> >::type DPM;
return DPM(sm, new SMPM(sm.template add_property_map<typename Surface_mesh<Point>::Halfedge_index, T>(std::string()).first));
return DPM(sm, new SMPM(sm.template add_property_map<typename Surface_mesh<Point>::Halfedge_index, T>(std::string(), default_value).first));
}
// get functions for dynamic properties of const Surface_mesh
template <typename Point, typename T>
typename boost::property_map<Surface_mesh<Point>, dynamic_vertex_property_t<T> >::const_type
get(dynamic_vertex_property_t<T>, const Surface_mesh<Point>& sm)
get(dynamic_vertex_property_t<T>, const Surface_mesh<Point>& sm, const T& default_value = T())
{
return CGAL::internal::Dynamic_with_index<typename Surface_mesh<Point>::Vertex_index, T>(num_vertices(sm));
return CGAL::internal::Dynamic_with_index<typename Surface_mesh<Point>::Vertex_index, T>(num_vertices(sm), default_value);
}
template <typename Point, typename T>
typename boost::property_map<Surface_mesh<Point>, dynamic_face_property_t<T> >::const_type
get(dynamic_face_property_t<T>, const Surface_mesh<Point>& sm)
get(dynamic_face_property_t<T>, const Surface_mesh<Point>& sm, const T& default_value = T())
{
return CGAL::internal::Dynamic_with_index<typename Surface_mesh<Point>::Face_index, T>(num_faces(sm));
return CGAL::internal::Dynamic_with_index<typename Surface_mesh<Point>::Face_index, T>(num_faces(sm), default_value);
}
template <typename Point, typename T>
typename boost::property_map<Surface_mesh<Point>, dynamic_halfedge_property_t<T> >::const_type
get(dynamic_halfedge_property_t<T>, const Surface_mesh<Point>& sm)
get(dynamic_halfedge_property_t<T>, const Surface_mesh<Point>& sm, const T& default_value = T())
{
return CGAL::internal::Dynamic_with_index<typename Surface_mesh<Point>::Halfedge_index, T>(num_halfedges(sm));
return CGAL::internal::Dynamic_with_index<typename Surface_mesh<Point>::Halfedge_index, T>(num_halfedges(sm), default_value);
}
template <typename Point, typename T>
typename boost::property_map<Surface_mesh<Point>, dynamic_edge_property_t<T> >::const_type
get(dynamic_edge_property_t<T>, const Surface_mesh<Point>& sm)
get(dynamic_edge_property_t<T>, const Surface_mesh<Point>& sm, const T& default_value = T())
{
return CGAL::internal::Dynamic_with_index<typename Surface_mesh<Point>::Edge_index, T>(num_edges(sm));
return CGAL::internal::Dynamic_with_index<typename Surface_mesh<Point>::Edge_index, T>(num_edges(sm), default_value);
}
// implementation detail: required by Dynamic_property_map_deleter