diff --git a/Surface_mesh_simplification/examples/Surface_mesh_simplification/LT_edge_collapse_polyhedron.cpp b/Surface_mesh_simplification/examples/Surface_mesh_simplification/LT_edge_collapse_polyhedron.cpp index 7024da32525..2a136087b0f 100644 --- a/Surface_mesh_simplification/examples/Surface_mesh_simplification/LT_edge_collapse_polyhedron.cpp +++ b/Surface_mesh_simplification/examples/Surface_mesh_simplification/LT_edge_collapse_polyhedron.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include #include // === EXAMPLE SPECIFIC HEADERS BEGINS HERE === diff --git a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Detail/Edge_collapse.h b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Detail/Edge_collapse.h index 1c44030a4dc..56e9e9b713f 100644 --- a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Detail/Edge_collapse.h +++ b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Detail/Edge_collapse.h @@ -28,7 +28,6 @@ #include #include -#include CGAL_BEGIN_NAMESPACE @@ -72,19 +71,20 @@ public: typedef boost::graph_traits GraphTraits ; typedef boost::graph_traits ConstGraphTraits ; - typedef Halfedge_graph_traits HalfedgeGraphTraits ; + typedef halfedge_graph_traits HalfedgeGraphTraits ; - typedef typename GraphTraits::vertex_descriptor vertex_descriptor ; - typedef typename GraphTraits::vertex_iterator vertex_iterator ; - typedef typename GraphTraits::edge_descriptor edge_descriptor ; - typedef typename GraphTraits::edge_iterator edge_iterator ; - typedef typename GraphTraits::out_edge_iterator out_edge_iterator ; - typedef typename GraphTraits::in_edge_iterator in_edge_iterator ; - typedef typename GraphTraits::traversal_category traversal_category ; - typedef typename GraphTraits::edges_size_type size_type ; + typedef typename GraphTraits::vertex_descriptor vertex_descriptor ; + typedef typename GraphTraits::vertex_iterator vertex_iterator ; + typedef typename GraphTraits::edge_descriptor edge_descriptor ; + typedef typename GraphTraits::edge_iterator edge_iterator ; + typedef typename GraphTraits::out_edge_iterator out_edge_iterator ; + typedef typename GraphTraits::in_edge_iterator in_edge_iterator ; + typedef typename GraphTraits::traversal_category traversal_category ; + typedef typename GraphTraits::edges_size_type size_type ; typedef typename ConstGraphTraits::vertex_descriptor const_vertex_descriptor ; typedef typename ConstGraphTraits::edge_descriptor const_edge_descriptor ; + typedef typename ConstGraphTraits::in_edge_iterator const_in_edge_iterator ; typedef typename HalfedgeGraphTraits::undirected_edge_iterator undirected_edge_iterator ; typedef typename HalfedgeGraphTraits::Point Point ; @@ -131,7 +131,7 @@ public: { public : - Edge_cache() : mPQHandle() {} + Edge_data() : mPQHandle() {} Cache const& cache() const { return mCache ; } Cache & cache() { return mCache ; } @@ -159,7 +159,7 @@ public: , ShouldStop const& aShouldStop , VertexPointMap const& aVertex_point_map , VertexIsFixedMap const& aVertex_is_fixed_map - , EdgeIndxMap const& aEdge_index_map + , EdgeIndexMap const& aEdge_index_map , EdgeIsBorderMap const& aEdge_is_border_map , SetCache const& aSetCache , GetCost const& aGetCost @@ -179,11 +179,11 @@ private: void Collapse( edge_descriptor const& aEdge ) ; void Update_neighbors( vertex_descriptor const& aKeptV ) ; - size_type get_id ( edge_descriptor const& aEdge ) const { return get(Edge_index_map,aEdge); } + size_type get_id ( const_edge_descriptor const& aEdge ) const { return Edge_index_map[aEdge]; } - bool is_vertex_fixed ( const_vertex_descriptor const& aV ) const { return get(Vertex_is_fixed_map,aV) ; } + bool is_vertex_fixed ( const_vertex_descriptor const& aV ) const { return Vertex_is_fixed_map[aV] ; } - bool is_border ( const_edge_descriptor const& aEdge ) const { return get(Edge_is_border_map,aEdge) ; } + bool is_border ( const_edge_descriptor const& aEdge ) const { return Edge_is_border_map[aEdge] ; } bool is_undirected_edge_a_border ( const_edge_descriptor const& aEdge ) const { @@ -250,25 +250,22 @@ private: return get_id(aEdgeA) < get_id(aEdgeB); } - void insert_in_PQ( edge_descriptor const& aEdge, Edge_data_ptr aData ) + void insert_in_PQ( edge_descriptor const& aEdge, Edge_data& aData ) { - CGAL_precondition(aData); - CGAL_precondition(!aData->is_in_PQ()); - aData->set_PQ_handle(mPQ->push(aEdge)); + CGAL_precondition(!aData.is_in_PQ()); + aData.set_PQ_handle(mPQ->push(aEdge)); } - void update_in_PQ( edge_descriptor const& aEdge, Edge_data_ptr aData ) + void update_in_PQ( edge_descriptor const& aEdge, Edge_data& aData ) { - CGAL_precondition(aData); - CGAL_precondition(aData->is_in_PQ()); - aData->set_PQ_handle(mPQ->update(aEdge,aData->PQ_handle())) ; + CGAL_precondition(aData.is_in_PQ()); + aData.set_PQ_handle(mPQ->update(aEdge,aData.PQ_handle())) ; } - void remove_from_PQ( edge_descriptor const& aEdge, Edge_data_ptr aData ) + void remove_from_PQ( edge_descriptor const& aEdge, Edge_data& aData ) { - CGAL_precondition(aData); - CGAL_precondition(aData->is_in_PQ()); - aData->set_PQ_handle(mPQ->erase(aEdge,aData->PQ_handle())); + CGAL_precondition(aData.is_in_PQ()); + aData.set_PQ_handle(mPQ->erase(aEdge,aData.PQ_handle())); } optional pop_from_PQ() @@ -296,8 +293,6 @@ private: private: - Collapse_triangulation_edge Collapse_triangulation_edge ; - Edge_data_array mEdgeDataArray ; boost::scoped_ptr mPQ ; @@ -308,7 +303,7 @@ private: CGAL_ECMS_DEBUG_CODE ( unsigned mStep ; ) } ; -} // namespace Triangulated_surface_mesh::Simplification::edge_collapse +} // namespace Surface_mesh_simplification CGAL_END_NAMESPACE diff --git a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Detail/Edge_collapse_impl.h b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Detail/Edge_collapse_impl.h index 1bcdf48cfbd..59f1469c2df 100644 --- a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Detail/Edge_collapse_impl.h +++ b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Detail/Edge_collapse_impl.h @@ -26,7 +26,7 @@ namespace Surface_mesh_simplification template EdgeCollapse::EdgeCollapse( ECM& aSurface , ShouldStop const& aShould_stop - , VertexPoinntMap const& aVertex_point_map + , VertexPointMap const& aVertex_point_map , VertexIsFixedMap const& aVertex_is_fixed_map , EdgeIndexMap const& aEdge_index_map , EdgeIsBorderMap const& aEdge_is_border_map @@ -52,9 +52,7 @@ EdgeCollapse::EdgeCollapse( ECM& ,Visitor (aVisitor) { - CGAL_ECMS_TRACE(0,"EdgeCollapse of ECM with " << num_undirected_edges(aSurface) << " edges" ); - - CGAL_assertion( num_undirected_edges(aSurface) * 2 == num_edges(aSurface) ) ; + CGAL_ECMS_TRACE(0,"EdgeCollapse of ECM with " << (num_edges(aSurface)/2) << " edges" ); CGAL_ECMS_DEBUG_CODE ( mStep = 0 ; ) @@ -104,7 +102,7 @@ void EdgeCollapse::Collect() Equal_3 equal_points = Kernel().equal_3_object(); - size_type lSize = num_undirected_edges(mSurface) ; + size_type lSize = num_edges(mSurface) / 2 ; mInitialEdgeCount = mCurrentEdgeCount = lSize; @@ -122,7 +120,7 @@ void EdgeCollapse::Collect() bool lIsFixed = is_vertex_fixed(p) || is_vertex_fixed(q) ; - if ( p == q || equal_points( get_point(p,mSurface), get_point(q,mSurface)) ) + if ( p == q || equal_points( get_point(p), get_point(q)) ) lIsFixed = true ; // But in the case of fixed edges the edge data is left default constructed @@ -195,14 +193,14 @@ void EdgeCollapse::Loop() } template -bool EdgeCollapse::is_border( const_vertex_descriptor const& aV ) +bool EdgeCollapse::is_border( const_vertex_descriptor const& aV ) const { bool rR = false ; - in_edge_iterator eb, ee ; + const_in_edge_iterator eb, ee ; for ( tie(eb,ee) = in_edges(aV,mSurface) ; eb != ee ; ++ eb ) { - edge_descriptor lEdge = *eb ; + const_edge_descriptor lEdge = *eb ; if ( is_undirected_edge_a_border(lEdge) ) { rR = true ; @@ -330,7 +328,7 @@ void EdgeCollapse::Collapse( edge_descrip Optional_placement_type lPlacement = get_placement(aEdgePQ); if ( Visitor ) - Visitor->OnCollapsing(*lEdge,mSurface,lPlacement); + Visitor->OnCollapsing(aEdgePQ,mSurface,lPlacement); if ( lPlacement ) { @@ -404,7 +402,7 @@ void EdgeCollapse::Collapse( edge_descrip // It's REQUIRED to remove ONLY 1 vertex (P or Q) and edges PQ,PT and QB (PT and QB are removed if they are not null). // All other edges must be kept. // All directed edges incident to vertex removed are relink to the vertex kept. - rResult = Collapse_triangulation_edge(aEdgePQ,mSurface); + rResult = collapse_triangulation_edge(aEdgePQ,mSurface); CGAL_ECMS_TRACE(1,"V" << rResult->ID << " kept." ) ; @@ -414,7 +412,7 @@ void EdgeCollapse::Collapse( edge_descrip CGAL_ECMS_TRACE(2, edge_to_string(*eb1) ) ; #endif - set_point(rResult,mSurface,*lPlacement) ; + put(vertex_point,mSurface,rResult,*lPlacement) ; Update_neighbors(rResult) ; } @@ -424,8 +422,6 @@ void EdgeCollapse::Collapse( edge_descrip } CGAL_ECMS_DEBUG_CODE ( ++mStep ; ) - - return rResult ; } template diff --git a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/HalfedgeGraph_Polyhedron_3.h b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/HalfedgeGraph_Polyhedron_3.h index 143cc2cd00a..36150f57525 100644 --- a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/HalfedgeGraph_Polyhedron_3.h +++ b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/HalfedgeGraph_Polyhedron_3.h @@ -22,7 +22,7 @@ #include #include #include -#include +#include #endif // CGAL_SURFACE_MESH_SIMPLIFICATION_HALFEDGEGRAPH_POLYHEDRON_3_H // EOF // diff --git a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Detail/Lindstrom_Turk_core.h b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Detail/Lindstrom_Turk_core.h index 6dfcf213571..9df9901d7fa 100644 --- a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Detail/Lindstrom_Turk_core.h +++ b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Detail/Lindstrom_Turk_core.h @@ -52,7 +52,7 @@ public: typedef LindstromTurk_params Params ; - typedef typename halfedge_graph_traits::Point Point ; + typedef typename halfedge_graph_traits::Point Point ; typedef typename Kernel_traits::Kernel Kernel ; @@ -143,7 +143,7 @@ private : return is_border(edge) || is_border(opposite_edge(edge,mSurface)) ; } - Point const& get_point ( const_vertex_descriptor const& v ) const + Point const& get_point ( vertex_descriptor const& v ) const { return get(vertex_point,mSurface,v); } diff --git a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Detail/Lindstrom_Turk_core_impl.h b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Detail/Lindstrom_Turk_core_impl.h index 0df04568ca3..48bb7f7ee2f 100644 --- a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Detail/Lindstrom_Turk_core_impl.h +++ b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Detail/Lindstrom_Turk_core_impl.h @@ -78,8 +78,8 @@ typename LindstromTurkCore::result_type LindstromTurkCore::compute() Extract_boundary_edges(lBdry); - Point const& lP = get_point(mP,mSurface) ; - Point const& lQ = get_point(mQ,mSurface) ; + Point const& lP = get_point(mP) ; + Point const& lQ = get_point(mQ) ; Optional_vector lOptionalV ; @@ -182,8 +182,8 @@ void LindstromTurkCore::Extract_boundary_edge( edge_descriptor edge, Bounda vertex_descriptor sv = source(face_edge,mSurface); vertex_descriptor tv = target(face_edge,mSurface); - Point const& sp = get_point(sv,mSurface); - Point const& tp = get_point(tv,mSurface); + Point const& sp = get_point(sv); + Point const& tp = get_point(tv); Vector v = tp - sp ; Vector n = Point_cross_product(tp,sp) ; @@ -233,9 +233,9 @@ typename LindstromTurkCore::Triangle LindstromTurkCore::Get_triangle( , vertex_descriptor const& v2 ) { - Point const& p0 = get_point(v0,mSurface); - Point const& p1 = get_point(v1,mSurface); - Point const& p2 = get_point(v2,mSurface); + Point const& p0 = get_point(v0); + Point const& p1 = get_point(v1); + Point const& p2 = get_point(v2); Vector v01 = p1 - p0 ; Vector v02 = p2 - p0 ; @@ -440,7 +440,7 @@ void LindstromTurkCore::Add_boundary_and_volume_optimization_constrians( Bo // // Weighted average // - FT lScaledBoundaryWeight = FT(9) * mParams.BoundaryWeight * squared_distance ( get_point(mP,mSurface), get_point(mQ,mSurface) ) ; + FT lScaledBoundaryWeight = FT(9) * mParams.BoundaryWeight * squared_distance ( get_point(mP), get_point(mQ) ) ; H *= mParams.VolumeWeight ; c = c * mParams.VolumeWeight ; @@ -468,7 +468,7 @@ void LindstromTurkCore::Add_shape_optimization_constrians( Link const& aLin Vector c = NULL_VECTOR ; for( typename Link::const_iterator it = aLink.begin(), eit = aLink.end() ; it != eit ; ++it ) - c = c + (ORIGIN - get_point(*it,mSurface)) ; + c = c + (ORIGIN - get_point(*it)) ; CGAL_ECMS_LT_TRACE(2,"Adding shape optimization constrians: Shape vector: " << xyz_to_string(c) ); @@ -515,7 +515,7 @@ LindstromTurkCore::Compute_shape_cost( Point const& p, Link const& aLink ) FT rCost(0); for( typename Link::const_iterator it = aLink.begin(), eit = aLink.end() ; it != eit ; ++it ) - rCost += squared_distance(p,get_point(*it,mSurface)) ; + rCost += squared_distance(p,get_point(*it)) ; return rCost ; } diff --git a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/LindstromTurk_placement.h b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/LindstromTurk_placement.h index 44d1abf8a76..2373578d9ea 100644 --- a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/LindstromTurk_placement.h +++ b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/LindstromTurk_placement.h @@ -60,8 +60,8 @@ public: LindstromTurkCore core(*aParams,aEdge,aSurface,false); - optional lCost ; - optional lPlacement ; + optional lCost ; + optional lPlacement ; tie(lCost,lPlacement) = core.compute(); return lPlacement ; diff --git a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/collapse_triangulation_edge_Polyhedron_3.h b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/collapse_triangulation_edge_Polyhedron_3.h index f344df82a07..52c25ecaee6 100644 --- a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/collapse_triangulation_edge_Polyhedron_3.h +++ b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/collapse_triangulation_edge_Polyhedron_3.h @@ -38,16 +38,20 @@ collapse_triangulation_edge( typename boost::graph_traits< Polyhedron_3& aSurface ) { + typedef Polyhedron_3 Surface ; + + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor ; + typedef typename boost::graph_traits::edge_descriptor edge_descriptor ; + edge_descriptor qp = opposite_edge(pq,aSurface); + edge_descriptor pt = opposite_edge(prev_edge(pq,aSurface),aSurface); + edge_descriptor qb = opposite_edge(prev_edge(qp,aSurface),aSurface); bool lTopFaceExists = !pq->is_border() ; bool lBottomFaceExists = !qp->is_border() ; bool lTopLeftFaceExists = lTopFaceExists && !pt->is_border() ; bool lBottomRightFaceExists = lBottomFaceExists && !qb->is_border() ; - edge_descriptor pq = opposite_edge(prev_edge(pq,aSurface),aSurface); - edge_descriptor qb = opposite_edge(prev_edge(qp,aSurface),aSurface); - CGAL_precondition( !lTopFaceExists || (lTopFaceExists && ( pt->vertex()->vertex_degree() > 2 ) ) ) ; CGAL_precondition( !lBottomFaceExists || (lBottomFaceExists && ( qb->vertex()->vertex_degree() > 2 ) ) ) ; @@ -115,7 +119,7 @@ collapse_triangulation_edge( typename boost::graph_traits< Polyhedron_3 -int edge_collapse ( ECM& aSurface, ShouldStop const& aShould_stop, cgal_bgl_named_params const& aParams ) +namespace detail { - using boost::choose_pmap ; + + template + inline + boost::put_get_helper const& + choose_index_pmap( boost::put_get_helper const& imap) { return imap; } + + template + inline + typename boost::property_map::const_type + choose_index_pmap( Surface const& s) { return boost::get(edge_external_index,s); } + +} +template +int edge_collapse ( ECM& aSurface + , ShouldStop const& aShould_stop + , cgal_bgl_named_params const& aParams + ) +{ + using boost::choose_param ; + using boost::choose_const_pmap ; using boost::get_param ; + using detail::choose_index_pmap ; + LindstromTurk_params lPolicyParams ; + boost::graph_visitor_t visitor ; + + return edge_collapse(aSurface ,aShould_stop - ,choose_pmap (get_param(aParams,vertex_point),aSurface,vertex_point) - ,choose_pmap (get_param(aParams,vertex_point),aSurface,vertex_is_fixed) - ,choose_pmap (get_param(aParams,vertex_point),aSurface,boost::edge_index) - ,choose_pmap (get_param(aParams,vertex_point),aSurface,edge_is_border) - ,choose_param(get_param(aParams,set_cache_policy), LindstromTurk_set_cost_cache()) - ,choose_param(get_param(aParams,get_cost_policy), Cached_cost()) - ,choose_param(get_param(aParams,get_placement_policy), LindstromTurk_placement()) - ,choose_param(get_param(aParams,get_cost_policy_params), &PolicyParmas) - ,choose_param(get_param(aParams,get_placement_policy_params), &PolicyParams) - ,choose_param(get_param(aParams,graph_visitor), ((Dummy_visitor*)0)) + ,choose_const_pmap (get_param(aParams,vertex_point),aSurface,vertex_point) + ,choose_param (get_param(aParams,vertex_is_fixed),Vertex_is_fixed_property_map_always_false()) + ,choose_index_pmap (get_param(aParams,boost::edge_index)) + ,choose_const_pmap (get_param(aParams,edge_is_border),aSurface,edge_is_border) + ,choose_param (get_param(aParams,set_cache_policy), LindstromTurk_set_cost_cache()) + ,choose_param (get_param(aParams,get_cost_policy), Cached_cost()) + ,choose_param (get_param(aParams,get_placement_policy), LindstromTurk_placement()) + ,choose_param (get_param(aParams,get_cost_policy_params), &lPolicyParams) + ,choose_param (get_param(aParams,get_placement_policy_params), &lPolicyParams) + ,choose_param (get_param(aParams,visitor), ((Dummy_visitor*)0)) ) ; -} // namespace Surface_mesh_simplification +} +template +int edge_collapse ( ECM& aSurface, ShouldStop const& aShould_stop ) +{ + return edge_collapse(aSurface,aShould_stop, edge_index_map(get(boost::edge_index,aSurface))); +} + +} // namespace Surface_mesh_simplification CGAL_END_NAMESPACE