diff --git a/.gitattributes b/.gitattributes index 48f87dfe916..130d68c8e57 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3278,9 +3278,6 @@ Polyline_simplification_2/doc_tex/Polyline_simplification_2_ref/Stop_below_count Polyline_simplification_2/doc_tex/Polyline_simplification_2_ref/Stop_below_count_threshold.tex -text Polyline_simplification_2/doc_tex/Polyline_simplification_2_ref/intro.tex -text Polyline_simplification_2/doc_tex/Polyline_simplification_2_ref/main.tex -text -Polyline_simplification_2/examples/Polyline_simplification_2/Polyline_simplification_2_basic_example.cpp -text -Polyline_simplification_2/examples/Polyline_simplification_2/Polyline_simplification_2_example_from_original.cpp -text -Polyline_simplification_2/examples/Polyline_simplification_2/Polyline_simplification_2_example_with_visitor.cpp -text Polyline_simplification_2/include/CGAL/Polyline_simplification_2/reference_manual_concepts/CostFunction_concept.h -text Polyline_simplification_2/include/CGAL/Polyline_simplification_2/reference_manual_concepts/PolylineNode_concept.h -text Polyline_simplification_2/include/CGAL/Polyline_simplification_2/reference_manual_concepts/StopPredicate_concept.h -text diff --git a/Polyline_simplification_2/examples/Polyline_simplification_2/Polyline_simplification_2_basic_example.cpp b/Polyline_simplification_2/examples/Polyline_simplification_2/Polyline_simplification_2_basic_example.cpp deleted file mode 100644 index d8fae0d2020..00000000000 --- a/Polyline_simplification_2/examples/Polyline_simplification_2/Polyline_simplification_2_basic_example.cpp +++ /dev/null @@ -1,80 +0,0 @@ -// Recommended kernel -#include - -// The simplification data structure -#include - -// Stop predicate -#include - -// Cost function -#include - -typedef CGAL::Exact_predicates_inexact_constructions_kernel K; - -typedef K::Point_2 Point ; - -typedef CGAL::Simplify_polylines_2 PS; - -int main( int argc, char** argv ) -{ - PS ps ; - - Point points[] = { Point(0,1) - , Point(1,2) - , Point(2,1) - , Point(3,3) - , Point(4,1) - , Point(5,4) - , Point(6,1) - , Point(3,0) - } ; - - // Insert polygon into simplification class - PS::Closed_polyline_handle poly = ps.insert_polygon(points,points+8); - - std::cout << "Before simplification" << std::endl ; - std::cout << std::endl ; - - // Iterate over the vertices of the inserted polygon before simplification - PS::Closed_polyline::Circulator head = poly->circulator(); - PS::Closed_polyline::Circulator cit = head; - - do - { - std::cout << cit->point() << std::endl ; - } - while ( ++ cit != head ) ; - - // Define the stop predicate to finish when the number of vertices drops - // below half the initial amount - CGAL::Polyline_simplification_2::Stop_below_count_ratio_threshold stop(0.5); - - // Use the scaled squared distance cost function - CGAL::Polyline_simplification_2::Scaled_squared_distance_cost cost; - - // Proceed with the simplification - ps.simplify(stop, cost) ; - - // Continue with the simplification from the previously simplified set - ps.simplify(stop, cost) ; - - // And again... - ps.simplify(stop, cost) ; - - std::cout << "After simplification" << std::endl ; - std::cout << std::endl ; - - // Iterate over the now simplified polyline showing the remaning vertices - head = poly->circulator(); - cit = head; - do - { - std::cout << cit->point() << std::endl ; - } - while ( ++ cit != head ) ; - - return 0 ; -} - - diff --git a/Polyline_simplification_2/examples/Polyline_simplification_2/Polyline_simplification_2_example_from_original.cpp b/Polyline_simplification_2/examples/Polyline_simplification_2/Polyline_simplification_2_example_from_original.cpp deleted file mode 100644 index c0673adad72..00000000000 --- a/Polyline_simplification_2/examples/Polyline_simplification_2/Polyline_simplification_2_example_from_original.cpp +++ /dev/null @@ -1,92 +0,0 @@ -// Recommended kernel -#include - -// The simplification data structure -#include - -// Stop predicate -#include - -// Cost functions -#include -#include - -typedef CGAL::Exact_predicates_inexact_constructions_kernel K; - -typedef K::Point_2 Point ; - -typedef CGAL::Simplify_polylines_2 PS; - -int main( int argc, char** argv ) -{ - PS ps ; - - Point points[] = { Point(0,1) - , Point(1,2) - , Point(2,1) - , Point(3,3) - , Point(4,1) - , Point(5,4) - , Point(6,1) - , Point(3,0) - } ; - - // Insert polygon into simplification class - PS::Closed_polyline_handle poly = ps.insert_polygon(points,points+8); - - std::cout << "Before simplification" << std::endl ; - std::cout << std::endl ; - - // Iterate over the vertices of the inserted polygon before simplification - PS::Closed_polyline::Circulator head = poly->circulator(); - PS::Closed_polyline::Circulator cit = head; - - do - { - std::cout << cit->point() << std::endl ; - } - while ( ++ cit != head ) ; - - // Define the stop predicate to finish when the number of vertices drops - // below half the initial amount - CGAL::Polyline_simplification_2::Stop_below_count_ratio_threshold stop(0.5); - - CGAL::Polyline_simplification_2::Scaled_squared_distance_cost cost1; - CGAL::Polyline_simplification_2::Squared_distance_cost cost2; - - // Proceed with the simplification - ps.simplify(stop, cost1) ; - - std::cout << "Using the scaled squared distance" << std::endl ; - std::cout << std::endl ; - - // Iterate over the now simplified polyline showing the remaining vertices - head = poly->circulator(); - cit = head; - - do - { - std::cout << cit->point() << std::endl ; - } - while ( ++ cit != head ) ; - - // Start again but using the other cost function - ps.simplify_original(stop, cost2) ; - - std::cout << "Using the absolute squared distance" << std::endl ; - std::cout << std::endl ; - - // Iterate over the now simplified polyline showing the remaning vertices - head = poly->circulator(); - cit = head; - - do - { - std::cout << cit->point() << std::endl ; - } - while ( ++ cit != head ) ; - - return 0 ; -} - - diff --git a/Polyline_simplification_2/examples/Polyline_simplification_2/Polyline_simplification_2_example_with_visitor.cpp b/Polyline_simplification_2/examples/Polyline_simplification_2/Polyline_simplification_2_example_with_visitor.cpp deleted file mode 100644 index 0f12a7a4f41..00000000000 --- a/Polyline_simplification_2/examples/Polyline_simplification_2/Polyline_simplification_2_example_with_visitor.cpp +++ /dev/null @@ -1,77 +0,0 @@ -// Recommended kernel -#include - -// The simplification data structure -#include - -// Stop predicate -#include - -// Cost function -#include - -// Helper visitor base -#include - -typedef CGAL::Exact_predicates_inexact_constructions_kernel K; - -typedef K::Point_2 Point ; - -typedef CGAL::Simplify_polylines_2 PS; - -// Create a custom visitor using the helper base class and overriding only one function -struct My_visitor : CGAL::Polyline_simplification_2::Visitor_base -{ - void OnSelected( Vertex_handle const& v, boost::optional const& cost, unsigned icount , unsigned ccount ) const - { - std::cout << "step [" << ccount << "/" << icount << "]: " << "V" << v->id() << " with cost " << cost << " selected" << std::endl ; - } - -} ; - -int main( int argc, char** argv ) -{ - PS ps ; - - Point points[] = { Point(0,1) - , Point(1,2) - , Point(2,1) - , Point(3,3) - , Point(4,1) - , Point(5,4) - , Point(6,1) - , Point(3,0) - } ; - - // Insert polygon into simplification class - PS::Closed_polyline_handle poly = ps.insert_polygon(points,points+8); - - std::cout << "Before simplification" << std::endl ; - std::cout << std::endl ; - - // Iterate over the vertices of the inserted polygon before simplification - PS::Closed_polyline::Circulator head = poly->circulator(); - PS::Closed_polyline::Circulator cit = head; - - do - { - std::cout << cit->point() << std::endl ; - } - while ( ++ cit != head ) ; - - // Define the stop predicate to finish when the number of vertices drops - // below half the initial amount - CGAL::Polyline_simplification_2::Stop_below_count_ratio_threshold stop(0.5); - - // Use the scaled squared distance cost function - CGAL::Polyline_simplification_2::Scaled_squared_distance_cost cost; - - // Proceed with the simplification tracking the process - My_visitor visitor ; - - ps.simplify(stop, cost, visitor) ; - - return 0 ; -} - - diff --git a/Polyline_simplification_2/examples/Polyline_simplification_2/simplify.cpp b/Polyline_simplification_2/examples/Polyline_simplification_2/simplify.cpp index 8abd39712ac..df94394821c 100755 --- a/Polyline_simplification_2/examples/Polyline_simplification_2/simplify.cpp +++ b/Polyline_simplification_2/examples/Polyline_simplification_2/simplify.cpp @@ -39,7 +39,7 @@ int main( ) pct.vertices_in_constraint_begin(*cit); vit != pct.vertices_in_constraint_end(*cit); ++vit) - std::cout << vit->point << std::endl; + std::cout << vit->point() << std::endl; } return 0; } diff --git a/Polyline_simplification_2/include/CGAL/Polyline_simplification_2/mark_vertices_unremovable.h b/Polyline_simplification_2/include/CGAL/Polyline_simplification_2/mark_vertices_unremovable.h index 72b773c7287..3dc4b742352 100644 --- a/Polyline_simplification_2/include/CGAL/Polyline_simplification_2/mark_vertices_unremovable.h +++ b/Polyline_simplification_2/include/CGAL/Polyline_simplification_2/mark_vertices_unremovable.h @@ -46,7 +46,7 @@ mark_vertices_unremovable(CGAL::Polyline_constrained_triangulation_2& pct, if(it->point.y() > t->point().y()) t = *it; } l->fixed = r->fixed = t->fixed = b->fixed = true; - } +} // Fix the leftmost, rightmost, topmost and bottommost vertex diff --git a/Polyline_simplification_2/include/CGAL/Polyline_simplification_2/simplify.h b/Polyline_simplification_2/include/CGAL/Polyline_simplification_2/simplify.h index 54e77ad8b4f..94e5d33aae2 100644 --- a/Polyline_simplification_2/include/CGAL/Polyline_simplification_2/simplify.h +++ b/Polyline_simplification_2/include/CGAL/Polyline_simplification_2/simplify.h @@ -75,8 +75,8 @@ public: bool operator() ( Vertices_in_constraint_iterator const& x, Vertices_in_constraint_iterator const& y ) const { - return x->cost < y->cost; - } + return x->vertex->cost < y->vertex->cost; + } } ; struct Id_map : public boost::put_get_helper @@ -112,7 +112,7 @@ public: Id_map idm; mpq = new MPQ(m, cc, idm); initialize_costs(cid); -} + } @@ -129,17 +129,17 @@ public: for(Vertices_in_constraint_iterator it = pct.vertices_in_constraint_begin(cid); it != pct.vertices_in_constraint_end(cid); ++it){ - if(! it->fixed && ! it->removed){ + if(! it->vertex->fixed){ Vertices_in_constraint_iterator u = boost::prior(it); Vertices_in_constraint_iterator w = boost::next(it); boost::optional dist = cost(pct, u, it, w); if(dist){ - it->cost = *dist; + it->vertex->cost = *dist; (*mpq).push(it); ++n; } else { - it->cost = (std::numeric_limits::max)(); + it->vertex->cost = (std::numeric_limits::max)(); std::cerr << "could not compute a cost" << std::endl; } } @@ -162,7 +162,7 @@ public: is_removable(Vertices_in_constraint_iterator it) { typedef typename PCT::Geom_traits Geom_traits; - if( it->removed || it->fixed){ + if(it->vertex->fixed) { return false; } @@ -237,26 +237,26 @@ operator()() Vertices_in_constraint_iterator u = boost::prior(v), w = boost::next(v); pct.simplify(u,v,w, keep_points); - if(! u->fixed){ + if(! u->vertex->fixed){ Vertices_in_constraint_iterator uu = boost::prior(u); boost::optional dist = cost(pct, uu,u,w); if(! dist){ std::cerr << "undefined cost not handled yet" << std::endl; } else { - u->cost = *dist; + u->vertex->cost = *dist; if((*mpq).contains(u)){ (*mpq).update(u, true); } } } - if(! w->fixed){ + if(! w->vertex->fixed){ Vertices_in_constraint_iterator ww = boost::next(w); boost::optional dist = cost(pct, u,w,ww); if(! dist){ std::cerr << "undefined cost not handled yet" << std::endl; } else { - w->cost = *dist; + w->vertex->cost = *dist; if((*mpq).contains(w)){ (*mpq).update(w, true); } diff --git a/STL_Extension/include/CGAL/Skiplist.h b/STL_Extension/include/CGAL/Skiplist.h index 81e289f23de..823da2cc258 100644 --- a/STL_Extension/include/CGAL/Skiplist.h +++ b/STL_Extension/include/CGAL/Skiplist.h @@ -160,6 +160,13 @@ public: return boost::make_iterator_range(skip_begin(), skip_end()); } + /// The elements pointed to by it are no longer in the range + /// [skip_begin(), skip_end()). + void skip(skip_iterator it) + { + skip_.erase(it.base()); + } + /// The elements pointed to by it are no longer in the range /// [skip_begin(), skip_end()). /// diff --git a/Triangulation_2/include/CGAL/Polyline_constraint_hierarchy_2.h b/Triangulation_2/include/CGAL/Polyline_constraint_hierarchy_2.h index afd65e3d37e..7747386c59c 100644 --- a/Triangulation_2/include/CGAL/Polyline_constraint_hierarchy_2.h +++ b/Triangulation_2/include/CGAL/Polyline_constraint_hierarchy_2.h @@ -498,18 +498,17 @@ remove_constraint(Constraint_id hvl){ // and for the case that the constrained edge u,w has no intersections template void Polyline_constraint_hierarchy_2::simplify(H_vertex_it uc, - H_vertex_it vc, - H_vertex_it wc) + H_vertex_it vc, + H_vertex_it wc) { - CGAL_assertion(vc->fixed != true); - CGAL_assertion(vc->removed != true); + CGAL_assertion(vc->vertex->fixed != true); Vertex_handle u = uc->vertex, v = vc->vertex, w = wc->vertex; typename H_sc_to_c_map::iterator uv_sc_iter = sc_to_c_map.find(make_edge(u, v)); CGAL_assertion_msg( uv_sc_iter != sc_to_c_map.end(), "not a subconstraint" ); H_context_list* uv_hcl = uv_sc_iter->second; CGAL_assertion_msg(uv_hcl->size() == 1, "more than one constraint passing through the subconstraint" ); - if((uv_hcl->front().current())->vertex != u){ + if((uv_hcl->front().current())->vertex != u) { std::swap(u,w); uv_sc_iter = sc_to_c_map.find(make_edge(u, v)); CGAL_assertion_msg( uv_sc_iter != sc_to_c_map.end(), "not a subconstraint" ); @@ -524,7 +523,8 @@ void Polyline_constraint_hierarchy_2::simplify(H_vertex_it uc, H_vertex_list* vertex_list = uv_hcl->front().id(); CGAL_assertion_msg(vertex_list == vw_hcl->front().id(), "subconstraints from different polyline constraints" ); // Remove the list item which points to v - vc->removed = true; + vertex_list->skip(vc); + // Remove the entries for [u,v] and [v,w] sc_to_c_map.erase(uv_sc_iter); sc_to_c_map.erase(vw_sc_iter); @@ -539,7 +539,7 @@ int Polyline_constraint_hierarchy_2::remove_points_from_constraint(Constraint_id cid) { int n=0; - for(H_all_it it = cid->begin(); it != cid->end(); ++it) { + for(H_all_it it = cid->all_begin(); it != cid->all_end(); ++it) { if(cid->is_skipped(it)) { it = cid->erase(it); ++n;