From b716cab8b75626bff0f3e8a221d6f628a6a85a7d Mon Sep 17 00:00:00 2001 From: Michael Hemmer Date: Tue, 17 Dec 2013 00:21:42 +0100 Subject: [PATCH] improve rotational sweep by using non geometric compare for edges in edx --- .../CGAL/Rotational_sweep_visibility_2.h | 28 +++++++++++++---- .../Visibility_2/include/CGAL/test_utils.h | 31 ------------------- 2 files changed, 22 insertions(+), 37 deletions(-) diff --git a/Visibility_2/include/CGAL/Rotational_sweep_visibility_2.h b/Visibility_2/include/CGAL/Rotational_sweep_visibility_2.h index 3ec7ab216f0..f42591ff9ee 100644 --- a/Visibility_2/include/CGAL/Rotational_sweep_visibility_2.h +++ b/Visibility_2/include/CGAL/Rotational_sweep_visibility_2.h @@ -25,6 +25,7 @@ #include #include #include +#include namespace CGAL { @@ -73,10 +74,11 @@ private: if (e1 == e2) return false; else { - if (e1->source() == e2->source()) - return Visibility_2::compare_xy_2(geom_traits, e1->target()->point(), e2->target()->point()) == SMALLER; - else - return Visibility_2::compare_xy_2(geom_traits, e1->source()->point(), e2->source()->point()) == SMALLER; + return &(*e1)<&(*e2); +// if (e1->source() == e2->source()) +// return Visibility_2::compare_xy_2(geom_traits, e1->target()->point(), e2->target()->point()) == SMALLER; +// else +// return Visibility_2::compare_xy_2(geom_traits, e1->source()->point(), e2->source()->point()) == SMALLER; } } }; @@ -90,16 +92,29 @@ private: if (v1 == v2) return false; else - return Visibility_2::compare_xy_2(geom_traits, v1->point(), v2->point()) == SMALLER; + // I know this is dirty but it speeds up by 25%. Michael + return &(*v1)<&(*v2); +// return Visibility_2::compare_xy_2(geom_traits, v1->point(), v2->point()) == SMALLER; } }; + +// Using hash_map or edx causes a seg fault, did not have the time to see why. Michael +// class Hash_edge: public std::unary_function::result_type> { +// public: +// typename boost::hash::result_type +// operator() (const EH e1) const { +// return boost::hash()(&(e1->curve())); +// } +// }; + const Geometry_traits_2 *geom_traits; const Arrangement_2 *p_arr; Point_2 q; //query point Points polygon; //visibility polygon std::map incident_edges; //the edges that are std::map edx; //index of active edges in the heap + // boost::unordered_map edx; //index of active edges in the heap EHs active_edges; //a heap of edges that intersect the current vision ray. VHs vs; //angular sorted vertices EHs bad_edges; //edges that pass the query point @@ -321,7 +336,8 @@ private: polygon.clear(); active_edges.clear(); incident_edges = std::map(Less_vertex(geom_traits)); - edx = std::map(Less_edge(geom_traits)); + + edx = std::map(Less_edge(geom_traits)); EHs relevant_edges; //all edges that can affect the visibility of query point. Arrangement_2 bbox; diff --git a/Visibility_2/test/Visibility_2/include/CGAL/test_utils.h b/Visibility_2/test/Visibility_2/include/CGAL/test_utils.h index b0f42ddd594..5c2b90eb488 100644 --- a/Visibility_2/test/Visibility_2/include/CGAL/test_utils.h +++ b/Visibility_2/test/Visibility_2/include/CGAL/test_utils.h @@ -544,37 +544,6 @@ void create_arrangement_from_file(_Arrangement_2 &arr, std::ifstream& input) { } } -void convert_poly_to_env_file() { - - std::ofstream norway; - norway.open("norway.env"); - std::ifstream input; - input.open("norway.poly"); - - if (input && norway) { - std::string line; - while (!input.eof()) { - std::getline(input, line); - std::vector vertices; - line.erase(line.find_last_not_of(" \n\r\t")+1); - - while (line != "POLYGON" && !input.eof()) { - vertices.push_back(line); - std::getline(input, line); - line.erase(line.find_last_not_of(" \n\r\t")+1); - } - if (vertices.size() != 0) { - norway << vertices.size() << std::endl; - for (int j = 0 ; j < vertices.size() ; j++) { - norway << vertices[j] << std::endl; - } - } - } - } - else { - std::cout<<"Can't open the file. Check the file name."; - } -} template void create_arrangement_from_env_file(_Arrangement_2 &arr, std::ifstream& input) {