mirror of https://github.com/CGAL/cgal
introduce named parameters in keep_largest_connected_components
This commit is contained in:
parent
cbfef8b105
commit
8d60913c43
|
|
@ -78,7 +78,7 @@ int main(int argc, char* argv[])
|
||||||
std::size_t num = CGAL::Polygon_mesh_processing::connected_components(mesh,
|
std::size_t num = CGAL::Polygon_mesh_processing::connected_components(mesh,
|
||||||
fccmap,
|
fccmap,
|
||||||
CGAL::Polygon_mesh_processing::parameters::edge_is_constrained_map(Constraint<Mesh>(mesh, bound)));
|
CGAL::Polygon_mesh_processing::parameters::edge_is_constrained_map(Constraint<Mesh>(mesh, bound)));
|
||||||
|
|
||||||
std::cerr << "- The graph has " << num << " connected components (face connectivity)" << std::endl;
|
std::cerr << "- The graph has " << num << " connected components (face connectivity)" << std::endl;
|
||||||
typedef std::map<std::size_t/*index of CC*/, unsigned int/*nb*/> Components_size;
|
typedef std::map<std::size_t/*index of CC*/, unsigned int/*nb*/> Components_size;
|
||||||
Components_size nb_per_cc;
|
Components_size nb_per_cc;
|
||||||
|
|
@ -92,8 +92,8 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
std::cerr << "- We keep the two largest components" << std::endl;
|
std::cerr << "- We keep the two largest components" << std::endl;
|
||||||
CGAL::Polygon_mesh_processing::keep_largest_connected_components(mesh,
|
CGAL::Polygon_mesh_processing::keep_largest_connected_components(mesh,
|
||||||
2,
|
2,
|
||||||
Constraint<Mesh>(mesh, bound));
|
CGAL::Polygon_mesh_processing::parameters::edge_is_constrained_map(Constraint<Mesh>(mesh, bound)));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -522,8 +522,8 @@ connected_components(const PolygonMesh& pmesh,
|
||||||
fcm,
|
fcm,
|
||||||
boost::vertex_index_map(
|
boost::vertex_index_map(
|
||||||
choose_const_pmap(get_param(np, boost::face_index),
|
choose_const_pmap(get_param(np, boost::face_index),
|
||||||
pmesh,
|
pmesh,
|
||||||
boost::face_index)
|
boost::face_index)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -565,32 +565,15 @@ connected_components(const PolygonMesh& pmesh,
|
||||||
* \return the number of connected components erased (ignoring isolated vertices).
|
* \return the number of connected components erased (ignoring isolated vertices).
|
||||||
*/
|
*/
|
||||||
template <typename PolygonMesh
|
template <typename PolygonMesh
|
||||||
, typename EdgeConstraintMap
|
, typename NamedParameters>
|
||||||
, 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
|
|
||||||
>
|
|
||||||
std::size_t keep_largest_connected_components(PolygonMesh& pmesh
|
std::size_t keep_largest_connected_components(PolygonMesh& pmesh
|
||||||
, std::size_t nb_components_to_keep
|
, std::size_t nb_components_to_keep
|
||||||
, EdgeConstraintMap ecmap
|
, const NamedParameters& np)
|
||||||
#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
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
|
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_descriptor vertex_descriptor;
|
||||||
typedef typename boost::graph_traits<PolygonMesh>::vertex_iterator vertex_iterator;
|
typedef typename boost::graph_traits<PolygonMesh>::vertex_iterator vertex_iterator;
|
||||||
typedef typename boost::graph_traits<PolygonMesh>::face_descriptor face_descriptor;
|
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>::halfedge_descriptor halfedge_descriptor;
|
||||||
typedef typename boost::graph_traits<PolygonMesh>::edge_descriptor edge_descriptor;
|
typedef typename boost::graph_traits<PolygonMesh>::edge_descriptor edge_descriptor;
|
||||||
typedef typename boost::graph_traits<PolygonMesh>::edge_iterator edge_iterator;
|
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);
|
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,
|
std::size_t num = connected_components(pmesh, face_cc,
|
||||||
CGAL::Polygon_mesh_processing::parameters::edge_is_constrained_map(ecmap).
|
CGAL::Polygon_mesh_processing::parameters::edge_is_constrained_map(ecmap).
|
||||||
face_index_map(fim));
|
face_index_map(fim));
|
||||||
|
|
@ -741,55 +755,16 @@ std::size_t keep_largest_connected_components(PolygonMesh& pmesh
|
||||||
return num - nb_components_to_keep;
|
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>
|
template <typename PolygonMesh>
|
||||||
std::size_t keep_largest_connected_components(PolygonMesh& pmesh,
|
std::size_t keep_largest_connected_components(PolygonMesh& pmesh,
|
||||||
std::size_t nb_components_to_keep)
|
std::size_t nb_components_to_keep)
|
||||||
{
|
{
|
||||||
return keep_largest_connected_components(pmesh,
|
return keep_largest_connected_components(pmesh,
|
||||||
nb_components_to_keep,
|
nb_components_to_keep,
|
||||||
internal::No_constraint<PolygonMesh>(),
|
CGAL::Polygon_mesh_processing::parameters::all_default());
|
||||||
get(boost::vertex_index, pmesh),
|
|
||||||
get(boost::face_index, pmesh));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Polygon_mesh_processing
|
} // namespace Polygon_mesh_processing
|
||||||
|
|
||||||
} // namespace CGAL
|
} // namespace CGAL
|
||||||
|
|
|
||||||
|
|
@ -140,12 +140,21 @@ namespace CGAL{
|
||||||
//overload
|
//overload
|
||||||
template <typename IndexMap>
|
template <typename IndexMap>
|
||||||
pmp_bgl_named_params<IndexMap, boost::face_index_t, self>
|
pmp_bgl_named_params<IndexMap, boost::face_index_t, self>
|
||||||
face_index_map(const IndexMap& p) const
|
face_index_map(const IndexMap& p) const
|
||||||
{
|
{
|
||||||
typedef pmp_bgl_named_params<IndexMap, boost::face_index_t, self> Params;
|
typedef pmp_bgl_named_params<IndexMap, boost::face_index_t, self> Params;
|
||||||
return Params(p, *this);
|
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{
|
namespace Polygon_mesh_processing{
|
||||||
|
|
@ -232,6 +241,7 @@ namespace parameters{
|
||||||
return Params(em);
|
return Params(em);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//overload
|
||||||
template <typename EdgeIsConstrainedParams>
|
template <typename EdgeIsConstrainedParams>
|
||||||
pmp_bgl_named_params<EdgeIsConstrainedParams, edge_is_constrained_params_t>
|
pmp_bgl_named_params<EdgeIsConstrainedParams, edge_is_constrained_params_t>
|
||||||
edge_is_constrained_map_params(const EdgeIsConstrainedParams& em)
|
edge_is_constrained_map_params(const EdgeIsConstrainedParams& em)
|
||||||
|
|
@ -241,6 +251,7 @@ namespace parameters{
|
||||||
return Params(em);
|
return Params(em);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//overload
|
||||||
template <typename IndexMap>
|
template <typename IndexMap>
|
||||||
pmp_bgl_named_params<IndexMap, boost::face_index_t>
|
pmp_bgl_named_params<IndexMap, boost::face_index_t>
|
||||||
face_index_map(IndexMap const& p)
|
face_index_map(IndexMap const& p)
|
||||||
|
|
@ -249,7 +260,14 @@ namespace parameters{
|
||||||
return Params(p);
|
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 parameters
|
||||||
} //namespace Polygon_mesh_processing
|
} //namespace Polygon_mesh_processing
|
||||||
|
|
|
||||||
|
|
@ -95,11 +95,10 @@ void mesh_no_id(char* argv1)
|
||||||
std::cout << &*f << " in connected component " << fccmap[f] << std::endl;
|
std::cout << &*f << " in connected component " << fccmap[f] << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
PMP::keep_largest_connected_components(sm
|
PMP::keep_largest_connected_components(sm
|
||||||
, 2
|
, 2
|
||||||
, CGAL::Default()
|
, PMP::parameters::vertex_index_map(vim).
|
||||||
, vim
|
face_index_map(fim));
|
||||||
, fim);
|
|
||||||
|
|
||||||
std::cout << "mesh:\n" << sm << std::endl;
|
std::cout << "mesh:\n" << sm << std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue