replace vector with range in stitch_borders

and start fixing PackageDescription.txt
This commit is contained in:
Jane Tournois 2015-04-03 12:45:22 +02:00
parent db614217c3
commit 0e674d879f
1 changed files with 60 additions and 60 deletions

View File

@ -25,14 +25,16 @@
#include <CGAL/Modifier_base.h> #include <CGAL/Modifier_base.h>
#include <CGAL/HalfedgeDS_decorator.h> #include <CGAL/HalfedgeDS_decorator.h>
#include <CGAL/boost/graph/helpers.h> #include <CGAL/boost/graph/helpers.h>
#include <CGAL/Default.h>
#include <CGAL/boost/graph/properties.h> #include <CGAL/boost/graph/properties.h>
#include <CGAL/Polygon_mesh_processing/internal/named_function_params.h> #include <CGAL/Polygon_mesh_processing/internal/named_function_params.h>
#include <CGAL/Polygon_mesh_processing/internal/named_params_helper.h> #include <CGAL/Polygon_mesh_processing/internal/named_params_helper.h>
#include <vector>
#include <set> #include <set>
#include <vector>
#include <utility>
#include <boost/range.hpp>
#include <boost/foreach.hpp>
namespace CGAL{ namespace CGAL{
@ -96,15 +98,16 @@ detect_duplicated_boundary_edges
return out; return out;
} }
template <class PM, typename VertexPointMap> template <class PM, typename VertexPointMap, typename HalfedgePairsRange>
struct Naive_border_stitching_modifier struct Naive_border_stitching_modifier
: CGAL::Modifier_base<PM> : CGAL::Modifier_base<PM>
{ {
typedef typename boost::graph_traits<PM>::vertex_descriptor vertex_descriptor; typedef typename boost::graph_traits<PM>::vertex_descriptor vertex_descriptor;
typedef typename boost::graph_traits<PM>::halfedge_descriptor halfedge_descriptor; typedef typename boost::graph_traits<PM>::halfedge_descriptor halfedge_descriptor;
typedef typename std::pair<halfedge_descriptor, halfedge_descriptor> halfedges_pair;
typedef typename PM::Point Point; typedef typename PM::Point Point;
typedef std::vector< std::pair<halfedge_descriptor, halfedge_descriptor> > To_stitch; typedef HalfedgePairsRange To_stitch;
Naive_border_stitching_modifier(To_stitch& to_stitch_, Naive_border_stitching_modifier(To_stitch& to_stitch_,
VertexPointMap vpmap_) VertexPointMap vpmap_)
@ -125,17 +128,16 @@ struct Naive_border_stitching_modifier
void operator()(PM& pmesh) void operator()(PM& pmesh)
{ {
std::size_t nb_hedges = to_stitch.size();
/// Merge the vertices /// Merge the vertices
std::vector<vertex_descriptor> vertices_to_delete; std::vector<vertex_descriptor> vertices_to_delete;
// since there might be several vertices with identical point // since there might be several vertices with identical point
// we use the following map to choose one vertex per point // we use the following map to choose one vertex per point
std::map<Point, vertex_descriptor> vertices_kept; std::map<Point, vertex_descriptor> vertices_kept;
for (std::size_t k = 0; k < nb_hedges; ++k)
BOOST_FOREACH(halfedges_pair hk, to_stitch)
{ {
halfedge_descriptor h1 = to_stitch[k].first; halfedge_descriptor h1 = hk.first;
halfedge_descriptor h2 = to_stitch[k].second; halfedge_descriptor h2 = hk.second;
CGAL_assertion(CGAL::is_border(h1, pmesh)); CGAL_assertion(CGAL::is_border(h1, pmesh));
CGAL_assertion(CGAL::is_border(h2, pmesh)); CGAL_assertion(CGAL::is_border(h2, pmesh));
@ -147,10 +149,10 @@ struct Naive_border_stitching_modifier
//update vertex pointers: target of h1 vs source of h2 //update vertex pointers: target of h1 vs source of h2
vertex_descriptor v_to_keep = h1_tgt; vertex_descriptor v_to_keep = h1_tgt;
std::pair< std::pair<typename std::map<Point, vertex_descriptor>::iterator, bool >
typename std::map<Point, vertex_descriptor>::iterator, insert_res =
bool > insert_res =
vertices_kept.insert( std::make_pair(vpmap[v_to_keep], v_to_keep) ); vertices_kept.insert( std::make_pair(vpmap[v_to_keep], v_to_keep) );
if (!insert_res.second && v_to_keep != insert_res.first->second) if (!insert_res.second && v_to_keep != insert_res.first->second)
{ {
v_to_keep = insert_res.first->second; v_to_keep = insert_res.first->second;
@ -196,10 +198,10 @@ struct Naive_border_stitching_modifier
/// In order to avoid having to maintain a set with halfedges to stitch /// In order to avoid having to maintain a set with halfedges to stitch
/// we do on purpose next-prev linking that might not be useful but that /// we do on purpose next-prev linking that might not be useful but that
/// is harmless and still less expensive than doing queries in a set /// is harmless and still less expensive than doing queries in a set
for (std::size_t k=0; k < nb_hedges; ++k) BOOST_FOREACH(halfedges_pair hk, to_stitch)
{ {
halfedge_descriptor h1 = to_stitch[k].first; halfedge_descriptor h1 = hk.first;
halfedge_descriptor h2 = to_stitch[k].second; halfedge_descriptor h2 = hk.second;
//link h2->prev() to h1->next() //link h2->prev() to h1->next()
halfedge_descriptor pr = prev(h2, pmesh); halfedge_descriptor pr = prev(h2, pmesh);
@ -214,10 +216,10 @@ struct Naive_border_stitching_modifier
/// update HDS connectivity, removing the second halfedge /// update HDS connectivity, removing the second halfedge
/// of each the pair and its opposite /// of each the pair and its opposite
for (std::size_t k=0; k<nb_hedges; ++k) BOOST_FOREACH(halfedges_pair hk, to_stitch)
{ {
halfedge_descriptor h1 = to_stitch[k].first; halfedge_descriptor h1 = hk.first;
halfedge_descriptor h2 = to_stitch[k].second; halfedge_descriptor h2 = hk.second;
///Set face-halfedge relationship ///Set face-halfedge relationship
//h2 and its opposite will be removed //h2 and its opposite will be removed
@ -249,39 +251,41 @@ private:
/// \ingroup stitching_grp /*!
/// Stitches together border halfedges in a polygon mesh. * \ingroup stitching_grp
/// The halfedges to be stitched are provided in `hedge_pairs_to_stitch`. * Stitches together border halfedges in a polygon mesh.
/// For each pair `p` in this vector, p.second and its opposite will be removed * The halfedges to be stitched are provided in `hedge_pairs_to_stitch`.
/// from `pmesh`. * For each pair `p` in this vector, p.second and its opposite will be removed
/// * from `pmesh`.
/// The vertices that get removed from `pmesh` are selected as follows: *
/// The pair of halfedges in `hedge_pairs_to_stitch` are processed linearly. * The vertices that get removed from `pmesh` are selected as follows:
/// Let `p` be such a pair. * The pair of halfedges in `hedge_pairs_to_stitch` are processed linearly.
/// If the target of `p.first` has not been marked for deletion, * Let `p` be such a pair.
/// then the source of `p.second` is. * If the target of `p.first` has not been marked for deletion,
/// If the target of `p.second` has not been marked for deletion, * then the source of `p.second` is.
/// then the source of `p.first` is. * If the target of `p.second` has not been marked for deletion,
/// * then the source of `p.first` is.
/// @tparam PolygonMesh a model of `FaceListGraph` and `MutableFaceGraph` *
/// that has a property map for `boost::vertex_point_t` * @tparam PolygonMesh a model of `FaceListGraph` and `MutableFaceGraph`
/// @tparam NamedParameters a sequence of \ref namedparameters * that has a property map for `boost::vertex_point_t`
/// * @tparam HalfedgePairsRange a model of `SinglePassRange`
/// @param pmesh the polygon mesh to be modified by stitching * holding objects of type
/// @param hedge_pairs_to_stitch a `std::vector` filled with `std::pair`s of halfedges to be stitched together * `std::pair<boost::graph_traits<PolygonMesh>::%halfedge_descriptor, boost::graph_traits<PolygonMesh>::%halfedge_descriptor>`
/// @param np optional \ref namedparameters described below * @tparam NamedParameters a sequence of \ref namedparameters
/// *
/// \cgalNamedParamsBegin * @param pmesh the polygon mesh to be modified by stitching
/// \cgalParamBegin{vertex_point_map} the property map with the points associated to the vertices of `pmesh` \cgalParamEnd * @param hedge_pairs_to_stitch a `std::vector` filled with `std::pair`s of halfedges to be stitched together
/// \cgalNamedParamsEnd * @param np optional \ref namedparameters described below
/// *
template <typename PolygonMesh, class NamedParameters> * \cgalNamedParamsBegin
void stitch_borders( * \cgalParamBegin{vertex_point_map} the property map with the points associated to the vertices of `pmesh` \cgalParamEnd
PolygonMesh& pmesh, * \cgalNamedParamsEnd
std::vector <std::pair< */
typename boost::graph_traits<PolygonMesh>::halfedge_descriptor, template <typename PolygonMesh,
typename boost::graph_traits<PolygonMesh>::halfedge_descriptor> >& typename HalfedgePairsRange,
hedge_pairs_to_stitch, typename NamedParameters>
void stitch_borders(PolygonMesh& pmesh,
HalfedgePairsRange& hedge_pairs_to_stitch,
const NamedParameters& np) const NamedParameters& np)
{ {
using boost::choose_param; using boost::choose_param;
@ -292,20 +296,16 @@ void stitch_borders(
pmesh, pmesh,
boost::vertex_point); boost::vertex_point);
internal::Naive_border_stitching_modifier<PolygonMesh, VPMap> internal::Naive_border_stitching_modifier<PolygonMesh, VPMap, HalfedgePairsRange>
modifier(hedge_pairs_to_stitch, vpm); modifier(hedge_pairs_to_stitch, vpm);
modifier(pmesh); modifier(pmesh);
} }
///\cond SKIP_IN_MANUAL ///\cond SKIP_IN_MANUAL
template <typename PolygonMesh> template <typename PolygonMesh, typename HalfedgePairsRange>
void stitch_borders( void stitch_borders(PolygonMesh& pmesh,
PolygonMesh& pmesh, HalfedgePairsRange& hedge_pairs_to_stitch)
std::vector < std::pair <
typename boost::graph_traits<PolygonMesh>::halfedge_descriptor,
typename boost::graph_traits<PolygonMesh>::halfedge_descriptor > > &
hedge_pairs_to_stitch)
{ {
stitch_borders(pmesh, hedge_pairs_to_stitch, stitch_borders(pmesh, hedge_pairs_to_stitch,
CGAL::Polygon_mesh_processing::parameters::all_default()); CGAL::Polygon_mesh_processing::parameters::all_default());