From 69b2f7079a01df328a506af9639a1b3f65fc0949 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Loriot?=
Date: Thu, 5 Jan 2012 09:45:15 +0000
Subject: [PATCH] BUGFIX: incremental neighbor search classes were storing a
nested ref_counted iterator for begin() which implies that a call to
operator++ on a copy of an iterator increment the internal copy of the class
(cannot make several pass). There is still a problem in case of copy outside
of the class but this is a first step (a deep_copy method should be provided
for iterators which would need a small feature).
---
Installation/changes.html | 2 ++
.../CGAL/Incremental_neighbor_search.h | 29 ++++++++-----------
.../Orthogonal_incremental_neighbor_search.h | 22 +++++++-------
3 files changed, 25 insertions(+), 28 deletions(-)
diff --git a/Installation/changes.html b/Installation/changes.html
index 2bce1ad2e84..e42d73dff36 100644
--- a/Installation/changes.html
+++ b/Installation/changes.html
@@ -138,6 +138,8 @@ CGAL 3.10 offers the following improvements and new functionality :
The class Kd_tree is now guaranteed to be read-only thread-safe. As usual in CGAL,
this small overhead introduced for thread-safety can be deactivated by defining CGAL_HAS_NO_THREADS.
+ Bug-fix in Orthogonal_incremental_neighbor_search and Incremental_neighbor_search classes. Several calls to begin()
+ now allow to make several nearest neighbor search queries independently.
STL extension
diff --git a/Spatial_searching/include/CGAL/Incremental_neighbor_search.h b/Spatial_searching/include/CGAL/Incremental_neighbor_search.h
index c7216bd2e23..b6e01171579 100644
--- a/Spatial_searching/include/CGAL/Incremental_neighbor_search.h
+++ b/Spatial_searching/include/CGAL/Incremental_neighbor_search.h
@@ -86,43 +86,38 @@ namespace CGAL {
typedef std::vector Point_with_distance_vector;
typedef std::vector Distance_vector;
- iterator *start;
- iterator *past_the_end;
+ //data members
+ const Tree& m_tree;
+ Query_item m_query;
+ Distance m_dist;
+ FT m_Eps;
+ bool m_search_nearest;
public:
// constructor
Incremental_neighbor_search(const Tree& tree, const Query_item& q,
FT Eps=FT(0.0), bool search_nearest=true,
- const Distance& tr=Distance())
- {
- start = new iterator(tree,q,tr,Eps,search_nearest);
- past_the_end = new iterator();
- }
-
- // destructor
- ~Incremental_neighbor_search()
- {
- delete start;
- delete past_the_end;
- }
+ const Distance& tr=Distance()):
+ m_tree(tree),m_query(q),m_dist(tr),m_Eps(Eps),m_search_nearest(search_nearest)
+ {}
iterator
begin() const
{
- return *start;
+ return iterator(m_tree,m_query,m_dist,m_Eps,m_search_nearest);
}
iterator
end() const
{
- return *past_the_end;
+ return iterator();
}
std::ostream&
statistics(std::ostream& s)
{
- start->statistics(s);
+ begin()->statistics(s);
return s;
}
diff --git a/Spatial_searching/include/CGAL/Orthogonal_incremental_neighbor_search.h b/Spatial_searching/include/CGAL/Orthogonal_incremental_neighbor_search.h
index f200f66b670..142324680c8 100644
--- a/Spatial_searching/include/CGAL/Orthogonal_incremental_neighbor_search.h
+++ b/Spatial_searching/include/CGAL/Orthogonal_incremental_neighbor_search.h
@@ -352,27 +352,26 @@ namespace CGAL {
// constructor
Orthogonal_incremental_neighbor_search(const Tree& tree,
const Query_item& q, FT Eps = FT(0.0),
- bool search_nearest=true, const Distance& tr=Distance())
- : start(tree,q,tr,Eps,search_nearest),
- past_the_end()
+ bool search_nearest=true, const Distance& tr=Distance())
+ : m_tree(tree),m_query(q),m_dist(tr),m_Eps(Eps),m_search_nearest(search_nearest)
{}
iterator
begin()
{
- return start;
+ return iterator(m_tree,m_query,m_dist,m_Eps,m_search_nearest);
}
iterator
end()
{
- return past_the_end;
+ return iterator();
}
std::ostream&
statistics(std::ostream& s)
{
- start.statistics(s);
+ begin()->statistics(s);
return s;
}
@@ -504,11 +503,12 @@ namespace CGAL {
}; // class iterator
-
- iterator start;
- iterator past_the_end;
-
-
+ //data members
+ const Tree& m_tree;
+ Query_item m_query;
+ Distance m_dist;
+ FT m_Eps;
+ bool m_search_nearest;
}; // class
template