This commit is contained in:
Maxime Gimeno 2020-02-14 14:25:28 +01:00
parent 002a3ac218
commit 249eb85060
2 changed files with 65 additions and 1 deletions

View File

@ -123,6 +123,64 @@ using boost::face_external_index;
namespace CGAL{
namespace helpers {
//check that an existing map is initialized/valid
template <class PolygonMesh, class FaceIndexMap>
bool is_face_index_map_valid(PolygonMesh& pm,
FaceIndexMap& fid)
{
typedef typename boost::property_traits<FaceIndexMap>::value_type Id_type;
const std::size_t num_f = num_faces(pm);
std::set<Id_type> indices;
for(typename boost::graph_traits<PolygonMesh>::face_descriptor fd :
faces(pm))
{
Id_type id = get(fid, fd);
if(static_cast<std::size_t>(id) >=static_cast<std::size_t>(num_f)) //also covers the case where the id is < 0 as size_t(-1) = max_int or smthg.
return false;
if(!indices.insert(id).second)
return false;
}
return true;
}
template <class PolygonMesh, class HalfedgeIndexMap>
bool is_halfedge_index_map_valid(PolygonMesh& pm,
HalfedgeIndexMap& fid)
{
typedef typename boost::property_traits<HalfedgeIndexMap>::value_type Id_type;
const std::size_t num_hd = num_halfedges(pm);
std::set<Id_type> indices;
for(typename boost::graph_traits<PolygonMesh>::halfedge_descriptor hd :
halfedges(pm))
{
Id_type id = get(fid, hd);
if(static_cast<std::size_t>(id) >=static_cast<std::size_t>(num_hd)) //also covers the case where the id is < 0 as size_t(-1) = max_int or smthg.
return false;
if(!indices.insert(id).second)
return false;
}
return true;
}
template <class PolygonMesh, class VertexIndexMap>
bool is_vertex_index_map_valid(PolygonMesh& pm,
VertexIndexMap& fid)
{
typedef typename boost::property_traits<VertexIndexMap>::value_type Id_type;
const std::size_t num_v= num_vertices(pm);
std::set<Id_type> indices;
for(typename boost::graph_traits<PolygonMesh>::vertex_descriptor vd :
vertices(pm))
{
Id_type id = get(fid, vd);
if(static_cast<std::size_t>(id) >=static_cast<std::size_t>(num_v)) //also covers the case where the id is < 0 as size_t(-1) = max_int or smthg.
return false;
if(!indices.insert(id).second)
return false;
}
return true;
}
// matches read-write property maps
template <class PolygonMesh, class FaceIndexMap, class Tag>
void init_face_indices(PolygonMesh& pm,
@ -130,6 +188,8 @@ void init_face_indices(PolygonMesh& pm,
boost::read_write_property_map_tag,
Tag)
{
if(is_face_index_map_valid(pm, fid))
return;
typename boost::property_traits<FaceIndexMap>::value_type i = 0;
for(typename boost::graph_traits<PolygonMesh>::face_descriptor fd :
faces(pm))
@ -144,6 +204,8 @@ void init_vertex_indices(PolygonMesh& pm,
boost::read_write_property_map_tag,
Tag)
{
if(is_vertex_index_map_valid(pm, vid))
return;
typename boost::property_traits<VertexIndexMap>::value_type i = 0;
for(typename boost::graph_traits<PolygonMesh>::vertex_descriptor vd :
vertices(pm))
@ -158,6 +220,8 @@ void init_halfedge_indices(PolygonMesh& pm,
boost::read_write_property_map_tag,
Tag)
{
if(is_halfedge_index_map_valid(pm, hid))
return;
typename boost::property_traits<HalfedgeIndexMap>::value_type i = 0;
for(typename boost::graph_traits<PolygonMesh>::halfedge_descriptor hd :
halfedges(pm))

View File

@ -152,7 +152,7 @@ namespace Polygon_mesh_processing {
* but `face(h, pmesh)` does not belong to the patch.
*
* @tparam PolygonMesh model of `HalfedgeGraph`. If `PolygonMesh`
* has an internal not writable property map
* has an internal non mutable property map
* for `CGAL::face_index_t` and no `face_index_map` is given
* as a named parameter, then the internal one must be initialized; else, it will be.
* @tparam FaceRange range of