summaryrefslogtreecommitdiff
path: root/src/Bottleneck_distance/include/gudhi/Neighbors_finder.h
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2017-01-04 08:39:18 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2017-01-04 08:39:18 +0000
commit64dd2a2b0eec1374ed23ca079f86b312125d03f7 (patch)
treef22c13edb5f6d2980c0af4ec21a6a9b8910990de /src/Bottleneck_distance/include/gudhi/Neighbors_finder.h
parent67c34d7b506efe6445a24380b3ad0743e09ef334 (diff)
Move bottleneck_chrono in benchmark
Add test in cmake for basic example Move CGAL gudhi patches for bottleneck in dedicated directory Fix cpplint syntax issue git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/bottleneck_integration@1920 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 24671facf791de93dc6fd94bb39ca7362bb22959
Diffstat (limited to 'src/Bottleneck_distance/include/gudhi/Neighbors_finder.h')
-rw-r--r--src/Bottleneck_distance/include/gudhi/Neighbors_finder.h172
1 files changed, 87 insertions, 85 deletions
diff --git a/src/Bottleneck_distance/include/gudhi/Neighbors_finder.h b/src/Bottleneck_distance/include/gudhi/Neighbors_finder.h
index 792925b7..96ece360 100644
--- a/src/Bottleneck_distance/include/gudhi/Neighbors_finder.h
+++ b/src/Bottleneck_distance/include/gudhi/Neighbors_finder.h
@@ -4,7 +4,7 @@
*
* Author: Francois Godi
*
- * Copyright (C) 2015 INRIA (France)
+ * Copyright (C) 2015 INRIA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -24,10 +24,9 @@
#define NEIGHBORS_FINDER_H_
// Inclusion order is important for CGAL patch
-#include "CGAL/Kd_tree_node.h"
-#include "CGAL/Kd_tree.h"
-#include "CGAL/Orthogonal_k_neighbor_search.h"
-
+#include <CGAL/Kd_tree.h>
+#include <CGAL/Kd_tree_node.h>
+#include <CGAL/Orthogonal_k_neighbor_search.h>
#include <CGAL/Weighted_Minkowski_distance.h>
#include <CGAL/Search_traits.h>
@@ -43,123 +42,126 @@ namespace persistence_diagram {
/** \internal \brief data structure used to find any point (including projections) in V near to a query point from U
* (which can be a projection).
*
- * V points have to be added manually using their index and before the first pull. A neighbor pulled is automatically removed.
+ * V points have to be added manually using their index and before the first pull. A neighbor pulled is automatically
+ * removed.
*
* \ingroup bottleneck_distance
*/
class Neighbors_finder {
-
- typedef CGAL::Dimension_tag<2> D;
- typedef CGAL::Search_traits<double, Internal_point, const double*, Construct_coord_iterator, D> Traits;
- typedef CGAL::Weighted_Minkowski_distance<Traits> Distance;
- typedef CGAL::Orthogonal_k_neighbor_search<Traits, Distance> K_neighbor_search;
- typedef K_neighbor_search::Tree Kd_tree;
-
-public:
- /** \internal \brief Constructor taking the near distance definition as parameter. */
- Neighbors_finder(const Persistence_graph& g, double r);
- /** \internal \brief A point added will be possibly pulled. */
- void add(int v_point_index);
- /** \internal \brief Returns and remove a V point near to the U point given as parameter, null_point_index() if there isn't such a point. */
- int pull_near(int u_point_index);
- /** \internal \brief Returns and remove all the V points near to the U point given as parameter. */
- std::vector<int> pull_all_near(int u_point_index);
-
-private:
- const Persistence_graph& g;
- const double r;
- Kd_tree kd_t;
- std::unordered_set<int> projections_f;
+ typedef CGAL::Dimension_tag<2> D;
+ typedef CGAL::Search_traits<double, Internal_point, const double*, Construct_coord_iterator, D> Traits;
+ typedef CGAL::Weighted_Minkowski_distance<Traits> Distance;
+ typedef CGAL::Orthogonal_k_neighbor_search<Traits, Distance> K_neighbor_search;
+ typedef K_neighbor_search::Tree Kd_tree;
+
+ public:
+ /** \internal \brief Constructor taking the near distance definition as parameter. */
+ Neighbors_finder(const Persistence_graph& g, double r);
+ /** \internal \brief A point added will be possibly pulled. */
+ void add(int v_point_index);
+ /** \internal \brief Returns and remove a V point near to the U point given as parameter, null_point_index() if
+ * there isn't such a point. */
+ int pull_near(int u_point_index);
+ /** \internal \brief Returns and remove all the V points near to the U point given as parameter. */
+ std::vector<int> pull_all_near(int u_point_index);
+
+ private:
+ const Persistence_graph& g;
+ const double r;
+ Kd_tree kd_t;
+ std::unordered_set<int> projections_f;
};
/** \internal \brief data structure used to find any point (including projections) in V near to a query point from U
* (which can be a projection) in a layered graph layer given as parmeter.
*
- * V points have to be added manually using their index and before the first pull. A neighbor pulled is automatically removed.
+ * V points have to be added manually using their index and before the first pull. A neighbor pulled is automatically
+ * removed.
*
* \ingroup bottleneck_distance
*/
class Layered_neighbors_finder {
-public:
- /** \internal \brief Constructor taking the near distance definition as parameter. */
- Layered_neighbors_finder(const Persistence_graph& g, double r);
- /** \internal \brief A point added will be possibly pulled. */
- void add(int v_point_index, int vlayer);
- /** \internal \brief Returns and remove a V point near to the U point given as parameter, null_point_index() if there isn't such a point. */
- int pull_near(int u_point_index, int vlayer);
- /** \internal \brief Returns the number of layers. */
- int vlayers_number() const;
-
-private:
- const Persistence_graph& g;
- const double r;
- std::vector<std::unique_ptr<Neighbors_finder>> neighbors_finder;
+ public:
+ /** \internal \brief Constructor taking the near distance definition as parameter. */
+ Layered_neighbors_finder(const Persistence_graph& g, double r);
+ /** \internal \brief A point added will be possibly pulled. */
+ void add(int v_point_index, int vlayer);
+ /** \internal \brief Returns and remove a V point near to the U point given as parameter, null_point_index() if
+ * there isn't such a point. */
+ int pull_near(int u_point_index, int vlayer);
+ /** \internal \brief Returns the number of layers. */
+ int vlayers_number() const;
+
+ private:
+ const Persistence_graph& g;
+ const double r;
+ std::vector<std::unique_ptr<Neighbors_finder>> neighbors_finder;
};
inline Neighbors_finder::Neighbors_finder(const Persistence_graph& g, double r) :
g(g), r(r), kd_t(), projections_f() { }
inline void Neighbors_finder::add(int v_point_index) {
- if (g.on_the_v_diagonal(v_point_index))
- projections_f.emplace(v_point_index);
- else
- kd_t.insert(g.get_v_point(v_point_index));
+ if (g.on_the_v_diagonal(v_point_index))
+ projections_f.emplace(v_point_index);
+ else
+ kd_t.insert(g.get_v_point(v_point_index));
}
inline int Neighbors_finder::pull_near(int u_point_index) {
- int tmp;
- int c = g.corresponding_point_in_v(u_point_index);
- if (g.on_the_u_diagonal(u_point_index) && !projections_f.empty()){
- //Any pair of projection is at distance 0
- tmp = *projections_f.cbegin();
- projections_f.erase(tmp);
- }
- else if (projections_f.count(c) && (g.distance(u_point_index, c) <= r)){
- //Is the query point near to its projection ?
- tmp = c;
- projections_f.erase(tmp);
- }
- else{
- //Is the query point near to a V point in the plane ?
- Internal_point u_point = g.get_u_point(u_point_index);
- std::array<double, 2> w = { {1., 1.} };
- K_neighbor_search search(kd_t, u_point, 1, 0., true, Distance(0, 2, w.begin(), w.end()));
- auto it = search.begin();
- if(it==search.end() || g.distance(u_point_index, it->first.point_index) > r)
- return null_point_index();
- tmp = it->first.point_index;
- kd_t.remove(g.get_v_point(tmp));
- }
- return tmp;
+ int tmp;
+ int c = g.corresponding_point_in_v(u_point_index);
+ if (g.on_the_u_diagonal(u_point_index) && !projections_f.empty()) {
+ // Any pair of projection is at distance 0
+ tmp = *projections_f.cbegin();
+ projections_f.erase(tmp);
+ } else if (projections_f.count(c) && (g.distance(u_point_index, c) <= r)) {
+ // Is the query point near to its projection ?
+ tmp = c;
+ projections_f.erase(tmp);
+ } else {
+ // Is the query point near to a V point in the plane ?
+ Internal_point u_point = g.get_u_point(u_point_index);
+ std::array<double, 2> w = {
+ {1., 1.}
+ };
+ K_neighbor_search search(kd_t, u_point, 1, 0., true, Distance(0, 2, w.begin(), w.end()));
+ auto it = search.begin();
+ if (it == search.end() || g.distance(u_point_index, it->first.point_index) > r)
+ return null_point_index();
+ tmp = it->first.point_index;
+ kd_t.remove(g.get_v_point(tmp));
+ }
+ return tmp;
}
inline std::vector<int> Neighbors_finder::pull_all_near(int u_point_index) {
- std::vector<int> all_pull;
- int last_pull = pull_near(u_point_index);
- while (last_pull != null_point_index()) {
- all_pull.emplace_back(last_pull);
- last_pull = pull_near(u_point_index);
- }
- return all_pull;
+ std::vector<int> all_pull;
+ int last_pull = pull_near(u_point_index);
+ while (last_pull != null_point_index()) {
+ all_pull.emplace_back(last_pull);
+ last_pull = pull_near(u_point_index);
+ }
+ return all_pull;
}
inline Layered_neighbors_finder::Layered_neighbors_finder(const Persistence_graph& g, double r) :
g(g), r(r), neighbors_finder() { }
inline void Layered_neighbors_finder::add(int v_point_index, int vlayer) {
- for (int l = neighbors_finder.size(); l <= vlayer; l++)
- neighbors_finder.emplace_back(std::unique_ptr<Neighbors_finder>(new Neighbors_finder(g, r)));
- neighbors_finder.at(vlayer)->add(v_point_index);
+ for (int l = neighbors_finder.size(); l <= vlayer; l++)
+ neighbors_finder.emplace_back(std::unique_ptr<Neighbors_finder>(new Neighbors_finder(g, r)));
+ neighbors_finder.at(vlayer)->add(v_point_index);
}
inline int Layered_neighbors_finder::pull_near(int u_point_index, int vlayer) {
- if (static_cast<int> (neighbors_finder.size()) <= vlayer)
- return null_point_index();
- return neighbors_finder.at(vlayer)->pull_near(u_point_index);
+ if (static_cast<int> (neighbors_finder.size()) <= vlayer)
+ return null_point_index();
+ return neighbors_finder.at(vlayer)->pull_near(u_point_index);
}
inline int Layered_neighbors_finder::vlayers_number() const {
- return static_cast<int>(neighbors_finder.size());
+ return static_cast<int> (neighbors_finder.size());
}
} // namespace persistence_diagram