mirror of https://github.com/CGAL/cgal
introduce named parameters in keep_largest_connected_components
This commit is contained in:
parent
cbfef8b105
commit
8d60913c43
|
|
@ -93,7 +93,7 @@ int main(int argc, char* argv[])
|
|||
std::cerr << "- We keep the two largest components" << std::endl;
|
||||
CGAL::Polygon_mesh_processing::keep_largest_connected_components(mesh,
|
||||
2,
|
||||
Constraint<Mesh>(mesh, bound));
|
||||
CGAL::Polygon_mesh_processing::parameters::edge_is_constrained_map(Constraint<Mesh>(mesh, bound)));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -565,32 +565,15 @@ connected_components(const PolygonMesh& pmesh,
|
|||
* \return the number of connected components erased (ignoring isolated vertices).
|
||||
*/
|
||||
template <typename PolygonMesh
|
||||
, typename EdgeConstraintMap
|
||||
, typename VertexIndexMap
|
||||
#ifdef DOXYGEN_RUNNING
|
||||
= typename boost::property_map<PolygonMesh, CGAL::vertex_index_t>::type
|
||||
#endif
|
||||
, typename FaceIndexMap
|
||||
#ifdef DOXYGEN_RUNNING
|
||||
= typename boost::property_map<PolygonMesh, CGAL::face_index_t>::type
|
||||
#endif
|
||||
>
|
||||
, typename NamedParameters>
|
||||
std::size_t keep_largest_connected_components(PolygonMesh& pmesh
|
||||
, std::size_t nb_components_to_keep
|
||||
, EdgeConstraintMap ecmap
|
||||
#ifdef DOXYGEN_RUNNING
|
||||
= CGAL::Default()
|
||||
#endif
|
||||
, VertexIndexMap vim
|
||||
#ifdef DOXYGEN_RUNNING
|
||||
= get(CGAL::vertex_index_t, pmesh)
|
||||
#endif
|
||||
,FaceIndexMap fim
|
||||
#ifdef DOXYGEN_RUNNING
|
||||
= get(CGAL::face_index_t, pmesh)
|
||||
#endif
|
||||
)
|
||||
, const NamedParameters& np)
|
||||
{
|
||||
using boost::choose_param;
|
||||
using boost::get_param;
|
||||
using boost::choose_const_pmap;
|
||||
|
||||
typedef typename boost::graph_traits<PolygonMesh>::vertex_descriptor vertex_descriptor;
|
||||
typedef typename boost::graph_traits<PolygonMesh>::vertex_iterator vertex_iterator;
|
||||
typedef typename boost::graph_traits<PolygonMesh>::face_descriptor face_descriptor;
|
||||
|
|
@ -598,8 +581,39 @@ std::size_t keep_largest_connected_components(PolygonMesh& pmesh
|
|||
typedef typename boost::graph_traits<PolygonMesh>::halfedge_descriptor halfedge_descriptor;
|
||||
typedef typename boost::graph_traits<PolygonMesh>::edge_descriptor edge_descriptor;
|
||||
typedef typename boost::graph_traits<PolygonMesh>::edge_iterator edge_iterator;
|
||||
|
||||
//EdgeConstraintMap
|
||||
typedef typename boost::lookup_named_param_def <
|
||||
CGAL::edge_is_constrained_t,
|
||||
NamedParameters,
|
||||
internal::No_constraint<PolygonMesh>//default
|
||||
> ::type EdgeConstraintMap;
|
||||
EdgeConstraintMap ecmap = choose_param(get_param(np, edge_is_constrained),
|
||||
EdgeConstraintMap());
|
||||
|
||||
//FaceIndexMap
|
||||
typedef typename boost::lookup_named_param_def <
|
||||
boost::face_index_t,
|
||||
NamedParameters,
|
||||
boost::property_map < PolygonMesh, boost::face_index_t>::type //default
|
||||
> ::type FaceIndexMap;
|
||||
FaceIndexMap fim = choose_const_pmap(get_param(np, boost::face_index),
|
||||
pmesh,
|
||||
boost::face_index);
|
||||
|
||||
//vector_property_map
|
||||
boost::vector_property_map<std::size_t, FaceIndexMap> face_cc(fim);
|
||||
|
||||
//VertexIndexMap
|
||||
typedef typename boost::lookup_named_param_def <
|
||||
boost::vertex_index_t,
|
||||
NamedParameters,
|
||||
boost::property_map < PolygonMesh, boost::vertex_index_t>::type //default
|
||||
> ::type VertexIndexMap;
|
||||
VertexIndexMap vim = choose_const_pmap(get_param(np, boost::vertex_index),
|
||||
pmesh,
|
||||
boost::vertex_index);
|
||||
|
||||
std::size_t num = connected_components(pmesh, face_cc,
|
||||
CGAL::Polygon_mesh_processing::parameters::edge_is_constrained_map(ecmap).
|
||||
face_index_map(fim));
|
||||
|
|
@ -741,55 +755,16 @@ std::size_t keep_largest_connected_components(PolygonMesh& pmesh
|
|||
return num - nb_components_to_keep;
|
||||
}
|
||||
|
||||
template <typename PolygonMesh
|
||||
, typename VertexIndexMap
|
||||
, typename FaceIndexMap>
|
||||
std::size_t keep_largest_connected_components(PolygonMesh& pmesh
|
||||
, std::size_t nb_components_to_keep
|
||||
, CGAL::Default
|
||||
, VertexIndexMap vim
|
||||
, FaceIndexMap fim)
|
||||
{
|
||||
return keep_largest_connected_components(pmesh, nb_components_to_keep,
|
||||
internal::No_constraint<PolygonMesh>(),
|
||||
vim,
|
||||
fim);
|
||||
}
|
||||
|
||||
template <typename PolygonMesh, typename EdgeConstraintMap, typename VertexIndexMap>
|
||||
std::size_t keep_largest_connected_components(PolygonMesh& pmesh,
|
||||
std::size_t nb_components_to_keep,
|
||||
EdgeConstraintMap ecmap,
|
||||
VertexIndexMap vim)
|
||||
{
|
||||
return keep_largest_connected_components(pmesh, nb_components_to_keep, ecmap, vim,
|
||||
get(boost::face_index, pmesh));
|
||||
}
|
||||
|
||||
template <typename PolygonMesh, typename EdgeConstraintMap>
|
||||
std::size_t keep_largest_connected_components(PolygonMesh& pmesh,
|
||||
std::size_t nb_components_to_keep,
|
||||
EdgeConstraintMap ecmap)
|
||||
{
|
||||
return keep_largest_connected_components(pmesh, nb_components_to_keep, ecmap,
|
||||
get(boost::vertex_index, pmesh),
|
||||
get(boost::face_index, pmesh));
|
||||
}
|
||||
|
||||
template <typename PolygonMesh>
|
||||
std::size_t keep_largest_connected_components(PolygonMesh& pmesh,
|
||||
std::size_t nb_components_to_keep)
|
||||
{
|
||||
return keep_largest_connected_components(pmesh,
|
||||
nb_components_to_keep,
|
||||
internal::No_constraint<PolygonMesh>(),
|
||||
get(boost::vertex_index, pmesh),
|
||||
get(boost::face_index, pmesh));
|
||||
CGAL::Polygon_mesh_processing::parameters::all_default());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Polygon_mesh_processing
|
||||
|
||||
} // namespace CGAL
|
||||
|
|
|
|||
|
|
@ -146,6 +146,15 @@ namespace CGAL{
|
|||
return Params(p, *this);
|
||||
}
|
||||
|
||||
//overload
|
||||
template <typename IndexMap>
|
||||
pmp_bgl_named_params<IndexMap, boost::vertex_index_t, self>
|
||||
vertex_index_map(const IndexMap& p) const
|
||||
{
|
||||
typedef pmp_bgl_named_params<IndexMap, boost::vertex_index_t, self> Params;
|
||||
return Params(p, *this);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
namespace Polygon_mesh_processing{
|
||||
|
|
@ -232,6 +241,7 @@ namespace parameters{
|
|||
return Params(em);
|
||||
}
|
||||
|
||||
//overload
|
||||
template <typename EdgeIsConstrainedParams>
|
||||
pmp_bgl_named_params<EdgeIsConstrainedParams, edge_is_constrained_params_t>
|
||||
edge_is_constrained_map_params(const EdgeIsConstrainedParams& em)
|
||||
|
|
@ -241,6 +251,7 @@ namespace parameters{
|
|||
return Params(em);
|
||||
}
|
||||
|
||||
//overload
|
||||
template <typename IndexMap>
|
||||
pmp_bgl_named_params<IndexMap, boost::face_index_t>
|
||||
face_index_map(IndexMap const& p)
|
||||
|
|
@ -249,7 +260,14 @@ namespace parameters{
|
|||
return Params(p);
|
||||
}
|
||||
|
||||
|
||||
//overload
|
||||
template <typename IndexMap>
|
||||
pmp_bgl_named_params<IndexMap, boost::vertex_index_t>
|
||||
vertex_index_map(const IndexMap& p)
|
||||
{
|
||||
typedef pmp_bgl_named_params<IndexMap, boost::vertex_index_t> Params;
|
||||
return Params(p);
|
||||
}
|
||||
|
||||
} //namespace parameters
|
||||
} //namespace Polygon_mesh_processing
|
||||
|
|
|
|||
|
|
@ -97,9 +97,8 @@ void mesh_no_id(char* argv1)
|
|||
|
||||
PMP::keep_largest_connected_components(sm
|
||||
, 2
|
||||
, CGAL::Default()
|
||||
, vim
|
||||
, fim);
|
||||
, PMP::parameters::vertex_index_map(vim).
|
||||
face_index_map(fim));
|
||||
|
||||
std::cout << "mesh:\n" << sm << std::endl;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue