From 1f11dfa00493124d9c9c702a963cd63e237b802a Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Fri, 8 Sep 2017 18:34:36 +0200 Subject: [PATCH] Use cache when computing furthest neighbors (incremental seach) --- .../Orthogonal_incremental_neighbor_search.h | 48 +++++-------------- 1 file changed, 13 insertions(+), 35 deletions(-) diff --git a/Spatial_searching/include/CGAL/Orthogonal_incremental_neighbor_search.h b/Spatial_searching/include/CGAL/Orthogonal_incremental_neighbor_search.h index 13f65c8aa5a..af3cf93e1ee 100644 --- a/Spatial_searching/include/CGAL/Orthogonal_incremental_neighbor_search.h +++ b/Spatial_searching/include/CGAL/Orthogonal_incremental_neighbor_search.h @@ -268,11 +268,11 @@ namespace CGAL { template - bool search_in_leaf(typename Tree::Leaf_node_const_handle node); + bool search_in_leaf(typename Tree::Leaf_node_const_handle node, bool search_furthest); // With cache template<> - bool search_in_leaf(typename Tree::Leaf_node_const_handle node) + bool search_in_leaf(typename Tree::Leaf_node_const_handle node, bool search_furthest) { typename Tree::iterator it_node_point = node->begin(), it_node_point_end = node->end(); typename std::vector::const_iterator cache_point_begin = m_tree.cache_begin() + m_dim*(it_node_point - m_tree.begin()); @@ -297,9 +297,9 @@ namespace CGAL { if (!(PriorityQueue.empty())) { rd = CGAL::cpp11::get<1>(*PriorityQueue.top()); - next_neighbour_found = - (multiplication_factor*rd > - Item_PriorityQueue.top()->second); + next_neighbour_found = (search_furthest ? + multiplication_factor*rd < Item_PriorityQueue.top()->second + : multiplication_factor*rd > Item_PriorityQueue.top()->second); } else // priority queue empty => last neighbour found { @@ -312,7 +312,7 @@ namespace CGAL { // Without cache template<> - bool search_in_leaf(typename Tree::Leaf_node_const_handle node) + bool search_in_leaf(typename Tree::Leaf_node_const_handle node, bool search_furthest) { typename Tree::iterator it_node_point = node->begin(), it_node_point_end = node->end(); @@ -333,9 +333,9 @@ namespace CGAL { if (!(PriorityQueue.empty())) { rd = CGAL::cpp11::get<1>(*PriorityQueue.top()); - next_neighbour_found = - (multiplication_factor*rd > - Item_PriorityQueue.top()->second); + next_neighbour_found = (search_furthest ? + multiplication_factor*rd < Item_PriorityQueue.top()->second + : multiplication_factor*rd > Item_PriorityQueue.top()->second); } else // priority queue empty => last neighbour found { @@ -405,7 +405,7 @@ namespace CGAL { number_of_leaf_nodes_visited++; if (node->size() > 0) next_neighbour_found = - search_in_leaf::type::value>::value>(node); + search_in_leaf::type::value>::value>(node, false); } // next_neighbour_found or priority queue is empty // in the latter case also the item priority quee is empty } @@ -466,31 +466,9 @@ namespace CGAL { typename Tree::Leaf_node_const_handle node = static_cast(N); number_of_leaf_nodes_visited++; - if (node->size() > 0) { - for (typename Tree::iterator it=node->begin(); it != node->end(); it++) { - number_of_items_visited++; - FT distance_to_query_point= - orthogonal_distance_instance.transformed_distance(query_point,*it); - Point_with_transformed_distance *NN_Candidate= - new Point_with_transformed_distance(*it,distance_to_query_point); - Item_PriorityQueue.push(NN_Candidate); - } - // old top of PriorityQueue has been processed, - // hence update rd - - if (!(PriorityQueue.empty())) { - rd = CGAL::cpp11::get<1>(*PriorityQueue.top()); - next_neighbour_found = - (multiplication_factor*rd < - Item_PriorityQueue.top()->second); - } - else // priority queue empty => last neighbour found - { - next_neighbour_found=true; - } - - number_of_neighbours_computed++; - } + if (node->size() > 0) + next_neighbour_found = + search_in_leaf::type::value>::value>(node, true); } // next_neighbour_found or priority queue is empty // in the latter case also the item priority quee is empty }