From ab6c280bd1de67a533d5ed357c39d798c1cf30c3 Mon Sep 17 00:00:00 2001 From: skachano Date: Sat, 21 Jan 2017 11:02:41 +0000 Subject: Added the Euclidean files -_- git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1981 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: e7b06da298f5cf07658dc20302eb1da9a08b424c --- .../include/gudhi/Euclidean_witness_complex.h | 233 +++++++++++++++++++++ 1 file changed, 233 insertions(+) create mode 100644 src/Witness_complex/include/gudhi/Euclidean_witness_complex.h (limited to 'src/Witness_complex/include/gudhi/Euclidean_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Euclidean_witness_complex.h b/src/Witness_complex/include/gudhi/Euclidean_witness_complex.h new file mode 100644 index 00000000..7045dc02 --- /dev/null +++ b/src/Witness_complex/include/gudhi/Euclidean_witness_complex.h @@ -0,0 +1,233 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Siargey Kachanovich + * + * Copyright (C) 2015 INRIA (France) + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef EUCLIDEAN_WITNESS_COMPLEX_H_ +#define EUCLIDEAN_WITNESS_COMPLEX_H_ + +#include +#include +#include + +#include +#include +#include +#include + +namespace Gudhi { + +namespace witness_complex { + +/** + * \private + * \class Euclidean_witness_complex + * \brief Constructs (weak) witness complex for given sets of witnesses and landmarks in Euclidean space. + * \ingroup witness_complex + * + * \tparam Kernel_ requires a CGAL::Epick_d class. +*/ +template< class Kernel_ > +class Euclidean_witness_complex { +private: + typedef Kernel_ K; + typedef typename K::Point_d Point_d; + typedef typename K::FT FT; + typedef std::vector Point_range; + typedef Gudhi::spatial_searching::Kd_tree_search Kd_tree; + typedef typename Kd_tree::INS_range Nearest_landmark_range; + + typedef FT Filtration_value; + + + typedef std::size_t Witness_id; + typedef typename Nearest_landmark_range::Point_with_transformed_distance Id_distance_pair; + typedef typename Id_distance_pair::first_type Landmark_id; + typedef Active_witness ActiveWitness; + typedef std::list< ActiveWitness > ActiveWitnessList; + typedef std::vector< Landmark_id > typeVectorVertex; + + typedef Landmark_id Vertex_handle; + + private: + Point_range witnesses_, landmarks_; + Kd_tree landmark_tree_; + + public: + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /* @name Constructor + */ + + //@{ + + /** + * \brief Initializes member variables before constructing simplicial complex. + * \details Records landmarks from the range 'landmarks' into a + * table internally, as well as witnesses from the range 'witnesses'. + * Both ranges should have value_type Kernel_::Point_d. + */ + template< typename LandmarkRange, + typename WitnessRange > + Euclidean_witness_complex(const LandmarkRange & landmarks, + const WitnessRange & witnesses) + : witnesses_(witnesses), landmarks_(landmarks), landmark_tree_(landmarks_) + { + } + + /** \brief Returns the point corresponding to the given vertex. + * @param[in] vertex Vertex handle of the point to retrieve. + */ + Point_d get_point( Vertex_handle vertex ) const + { + return landmarks_[vertex]; + } + + /** \brief Outputs the (weak) witness complex of relaxation 'max_alpha_square' + * in a simplicial complex data structure. + * \details The function returns true if the construction is successful and false otherwise. + * @param[out] complex Simplicial complex data structure compatible which is a model of + * SimplicialComplexForWitness concept. + * @param[in] max_alpha_square Maximal squared relaxation parameter. + * @param[in] limit_dimension Represents the maximal dimension of the simplicial complex + * (default value = no limit). + */ + template < typename SimplicialComplexForWitness > + bool create_complex(SimplicialComplexForWitness& complex, + FT max_alpha_square, + Landmark_id limit_dimension = std::numeric_limits::max()) + { + if (complex.num_vertices() > 0) { + std::cerr << "Euclidean witness complex cannot create complex - complex is not empty.\n"; + return false; + } + if (max_alpha_square < 0) { + std::cerr << "Euclidean witness complex cannot create complex - squared relaxation parameter must be non-negative.\n"; + return false; + } + if (limit_dimension < 0) { + std::cerr << "Euclidean witness complex cannot create complex - limit dimension must be non-negative.\n"; + return false; + } + typeVectorVertex vv; + ActiveWitnessList active_witnesses; + Landmark_id k = 0; /* current dimension in iterative construction */ + for (auto w: witnesses_) + active_witnesses.push_back(ActiveWitness(landmark_tree_.query_incremental_nearest_neighbors(w))); + ActiveWitness aw_copy(active_witnesses.front()); + while (!active_witnesses.empty() && k <= limit_dimension ) { + typename ActiveWitnessList::iterator aw_it = active_witnesses.begin(); + std::vector simplex; + simplex.reserve(k+1); + while (aw_it != active_witnesses.end()) { + bool ok = add_all_faces_of_dimension(k, + max_alpha_square, + std::numeric_limits::infinity(), + aw_it->begin(), + simplex, + complex, + aw_it->end()); + assert(simplex.empty()); + if (!ok) + active_witnesses.erase(aw_it++); //First increase the iterator and then erase the previous element + else + aw_it++; + } + k++; + } + complex.set_dimension(k-1); + return true; + } + + //@} + + private: + /* \brief Adds recursively all the faces of a certain dimension dim witnessed by the same witness. + * Iterator is needed to know until how far we can take landmarks to form simplexes. + * simplex is the prefix of the simplexes to insert. + * The output value indicates if the witness rests active or not. + */ + template < typename SimplicialComplexForWitness > + bool add_all_faces_of_dimension(int dim, + double alpha2, + double norelax_dist2, + typename ActiveWitness::iterator curr_l, + std::vector& simplex, + SimplicialComplexForWitness& sc, + typename ActiveWitness::iterator end) const + { + if (curr_l == end) + return false; + bool will_be_active = false; + typename ActiveWitness::iterator l_it = curr_l; + if (dim > 0) + for (; l_it->second - alpha2 <= norelax_dist2 && l_it != end; ++l_it) { + simplex.push_back(l_it->first); + if (sc.find(simplex) != sc.null_simplex()) { + typename ActiveWitness::iterator next_it = l_it; + will_be_active = add_all_faces_of_dimension(dim-1, + alpha2, + norelax_dist2, + ++next_it, + simplex, + sc, + end) || will_be_active; + } + assert(!simplex.empty()); + simplex.pop_back(); + // If norelax_dist is infinity, change to first omitted distance + if (l_it->second <= norelax_dist2) + norelax_dist2 = l_it->second; + typename ActiveWitness::iterator next_it = l_it; + will_be_active = add_all_faces_of_dimension(dim, + alpha2, + norelax_dist2, + ++next_it, + simplex, + sc, + end) || will_be_active; + } + else if (dim == 0) + for (; l_it->second - alpha2 <= norelax_dist2 && l_it != end; ++l_it) { + simplex.push_back(l_it->first); + double filtration_value = 0; + // if norelax_dist is infinite, relaxation is 0. + if (l_it->second > norelax_dist2) + filtration_value = l_it->second - norelax_dist2; + if (all_faces_in(simplex, &filtration_value, sc)) { + will_be_active = true; + sc.insert_simplex(simplex, filtration_value); + } + assert(!simplex.empty()); + simplex.pop_back(); + // If norelax_dist is infinity, change to first omitted distance + if (l_it->second < norelax_dist2) + norelax_dist2 = l_it->second; + } + return will_be_active; + } + +}; + +} // namespace witness_complex + +} // namespace Gudhi + +#endif // EUCLIDEAN_WITNESS_COMPLEX_H_ -- cgit v1.2.3 From 3ec8a40aaf7e34116e0d4f422994d5aee109c2b3 Mon Sep 17 00:00:00 2001 From: skachano Date: Mon, 30 Jan 2017 10:29:32 +0000 Subject: The new class design compiles. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@2023 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 8243073046081f51ae6725aa3d7dc921dea450e1 --- .../gudhi/Euclidean_strong_witness_complex.h | 120 ++-------------- .../include/gudhi/Euclidean_witness_complex.h | 151 ++------------------- .../include/gudhi/Strong_witness_complex.h | 7 +- .../include/gudhi/Witness_complex.h | 6 +- 4 files changed, 32 insertions(+), 252 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Euclidean_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Euclidean_strong_witness_complex.h b/src/Witness_complex/include/gudhi/Euclidean_strong_witness_complex.h index 38fa5c22..a5947219 100644 --- a/src/Witness_complex/include/gudhi/Euclidean_strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Euclidean_strong_witness_complex.h @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -45,33 +46,23 @@ namespace witness_complex { * href="http://doc.cgal.org/latest/Kernel_d/classCGAL_1_1Epick__d.html">CGAL::Epick_d class. */ template< class Kernel_ > -class Euclidean_strong_witness_complex { +class Euclidean_strong_witness_complex : public Strong_witness_complex>::INS_range>> { private: typedef Kernel_ K; typedef typename K::Point_d Point_d; - typedef typename K::FT FT; typedef std::vector Point_range; typedef Gudhi::spatial_searching::Kd_tree_search Kd_tree; typedef typename Kd_tree::INS_range Nearest_landmark_range; typedef typename std::vector Nearest_landmark_table; - typedef typename Nearest_landmark_range::iterator Nearest_landmark_row_iterator; - - typedef FT Filtration_value; - - typedef std::size_t Witness_id; typedef typename Nearest_landmark_range::Point_with_transformed_distance Id_distance_pair; typedef typename Id_distance_pair::first_type Landmark_id; - typedef Active_witness ActiveWitness; - typedef std::list< ActiveWitness > ActiveWitnessList; - typedef std::vector< Landmark_id > typeVectorVertex; - typedef std::pair< typeVectorVertex, Filtration_value> typeSimplex; - typedef Landmark_id Vertex_handle; private: - Point_range witnesses_, landmarks_; + Point_range landmarks_; Kd_tree landmark_tree_; + using Strong_witness_complex::nearest_landmark_table_; public: ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -89,9 +80,11 @@ private: template< typename LandmarkRange, typename WitnessRange > Euclidean_strong_witness_complex(const LandmarkRange & landmarks, - const WitnessRange & witnesses) - : witnesses_(witnesses), landmarks_(landmarks), landmark_tree_(landmarks_) - { + const WitnessRange & witnesses) + : landmarks_(landmarks), landmark_tree_(landmarks_) + { + for (auto w: witnesses) + nearest_landmark_table_.push_back(landmark_tree_.query_incremental_nearest_neighbors(w)); } @@ -103,101 +96,6 @@ private: return landmarks_[vertex]; } - /** \brief Outputs the strong witness complex of relaxation 'max_alpha_square' - * in a simplicial complex data structure. - * \details The function returns true if the construction is successful and false otherwise. - * @param[out] complex Simplicial complex data structure, which is a model of - * SimplicialComplexForWitness concept. - * @param[in] max_alpha_square Maximal squared relaxation parameter. - * @param[in] limit_dimension Represents the maximal dimension of the simplicial complex - * (default value = no limit). - */ - template < typename SimplicialComplexForWitness > - bool create_complex(SimplicialComplexForWitness& complex, - FT max_alpha_square, - Landmark_id limit_dimension = std::numeric_limits::max()-1) - { - Landmark_id complex_dim = 0; - if (complex.num_vertices() > 0) { - std::cerr << "Euclidean strong witness complex cannot create complex - complex is not empty.\n"; - return false; - } - if (max_alpha_square < 0) { - std::cerr << "Euclidean strong witness complex cannot create complex - squared relaxation parameter must be non-negative.\n"; - return false; - } - if (limit_dimension < 0) { - std::cerr << "Euclidean strong witness complex cannot create complex - limit dimension must be non-negative.\n"; - return false; - } - for (auto w: witnesses_) { - ActiveWitness aw(landmark_tree_.query_incremental_nearest_neighbors(w)); - typeVectorVertex simplex; - typename ActiveWitness::iterator aw_it = aw.begin(); - float lim_dist2 = aw.begin()->second + max_alpha_square; - while ((Landmark_id)simplex.size() < limit_dimension + 1 && aw_it != aw.end() && aw_it->second < lim_dist2) { - simplex.push_back(aw_it->first); - complex.insert_simplex_and_subfaces(simplex, aw_it->second - aw.begin()->second); - aw_it++; - } - // continue inserting limD-faces of the following simplices - typeVectorVertex& vertices = simplex; //'simplex' now will be called vertices - while (aw_it != aw.end() && aw_it->second < lim_dist2) { - typeVectorVertex facet = {}; - add_all_faces_of_dimension(limit_dimension, vertices, vertices.begin(), aw_it, aw_it->second - aw.begin()->second, facet, complex); - vertices.push_back(aw_it->first); - aw_it++; - } - if ((Landmark_id)simplex.size() - 1 > complex_dim) - complex_dim = simplex.size() - 1; - } - complex.set_dimension(complex_dim); - return true; - } - -private: - - /* \brief Adds recursively all the faces of a certain dimension dim-1 witnessed by the same witness. - * Iterator is needed to know until how far we can take landmarks to form simplexes. - * simplex is the prefix of the simplexes to insert. - * The landmark pointed by aw_it is added to all formed simplices. - */ - template < typename SimplicialComplexForWitness > - void add_all_faces_of_dimension(Landmark_id dim, - typeVectorVertex& vertices, - typename typeVectorVertex::iterator curr_it, - typename ActiveWitness::iterator aw_it, - FT filtration_value, - typeVectorVertex& simplex, - SimplicialComplexForWitness& sc) const - { - if (dim > 0) - while (curr_it != vertices.end()) { - simplex.push_back(*curr_it); - typename typeVectorVertex::iterator next_it = ++curr_it; - add_all_faces_of_dimension(dim-1, - vertices, - next_it, - aw_it, - filtration_value, - simplex, - sc); - simplex.pop_back(); - add_all_faces_of_dimension(dim, - vertices, - next_it, - aw_it, - filtration_value, - simplex, - sc); - } - else if (dim == 0) { - simplex.push_back(aw_it->first); - sc.insert_simplex_and_subfaces(simplex, filtration_value); - simplex.pop_back(); - } - } - //@} }; diff --git a/src/Witness_complex/include/gudhi/Euclidean_witness_complex.h b/src/Witness_complex/include/gudhi/Euclidean_witness_complex.h index 7045dc02..9845808e 100644 --- a/src/Witness_complex/include/gudhi/Euclidean_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Euclidean_witness_complex.h @@ -23,6 +23,7 @@ #ifndef EUCLIDEAN_WITNESS_COMPLEX_H_ #define EUCLIDEAN_WITNESS_COMPLEX_H_ +#include #include #include #include @@ -44,34 +45,27 @@ namespace witness_complex { * * \tparam Kernel_ requires a CGAL::Epick_d class. -*/ + */ template< class Kernel_ > -class Euclidean_witness_complex { +class Euclidean_witness_complex : public Witness_complex>::INS_range>> { private: typedef Kernel_ K; typedef typename K::Point_d Point_d; - typedef typename K::FT FT; typedef std::vector Point_range; typedef Gudhi::spatial_searching::Kd_tree_search Kd_tree; typedef typename Kd_tree::INS_range Nearest_landmark_range; + typedef typename std::vector Nearest_landmark_table; - typedef FT Filtration_value; - - - typedef std::size_t Witness_id; typedef typename Nearest_landmark_range::Point_with_transformed_distance Id_distance_pair; typedef typename Id_distance_pair::first_type Landmark_id; - typedef Active_witness ActiveWitness; - typedef std::list< ActiveWitness > ActiveWitnessList; - typedef std::vector< Landmark_id > typeVectorVertex; - typedef Landmark_id Vertex_handle; private: - Point_range witnesses_, landmarks_; + Point_range landmarks_; Kd_tree landmark_tree_; - - public: + using Witness_complex::nearest_landmark_table_; + +public: ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /* @name Constructor */ @@ -88,8 +82,10 @@ private: typename WitnessRange > Euclidean_witness_complex(const LandmarkRange & landmarks, const WitnessRange & witnesses) - : witnesses_(witnesses), landmarks_(landmarks), landmark_tree_(landmarks_) - { + : landmarks_(landmarks), landmark_tree_(landmarks) + { + for (auto w: witnesses) + nearest_landmark_table_.push_back(landmark_tree_.query_incremental_nearest_neighbors(w)); } /** \brief Returns the point corresponding to the given vertex. @@ -99,131 +95,8 @@ private: { return landmarks_[vertex]; } - - /** \brief Outputs the (weak) witness complex of relaxation 'max_alpha_square' - * in a simplicial complex data structure. - * \details The function returns true if the construction is successful and false otherwise. - * @param[out] complex Simplicial complex data structure compatible which is a model of - * SimplicialComplexForWitness concept. - * @param[in] max_alpha_square Maximal squared relaxation parameter. - * @param[in] limit_dimension Represents the maximal dimension of the simplicial complex - * (default value = no limit). - */ - template < typename SimplicialComplexForWitness > - bool create_complex(SimplicialComplexForWitness& complex, - FT max_alpha_square, - Landmark_id limit_dimension = std::numeric_limits::max()) - { - if (complex.num_vertices() > 0) { - std::cerr << "Euclidean witness complex cannot create complex - complex is not empty.\n"; - return false; - } - if (max_alpha_square < 0) { - std::cerr << "Euclidean witness complex cannot create complex - squared relaxation parameter must be non-negative.\n"; - return false; - } - if (limit_dimension < 0) { - std::cerr << "Euclidean witness complex cannot create complex - limit dimension must be non-negative.\n"; - return false; - } - typeVectorVertex vv; - ActiveWitnessList active_witnesses; - Landmark_id k = 0; /* current dimension in iterative construction */ - for (auto w: witnesses_) - active_witnesses.push_back(ActiveWitness(landmark_tree_.query_incremental_nearest_neighbors(w))); - ActiveWitness aw_copy(active_witnesses.front()); - while (!active_witnesses.empty() && k <= limit_dimension ) { - typename ActiveWitnessList::iterator aw_it = active_witnesses.begin(); - std::vector simplex; - simplex.reserve(k+1); - while (aw_it != active_witnesses.end()) { - bool ok = add_all_faces_of_dimension(k, - max_alpha_square, - std::numeric_limits::infinity(), - aw_it->begin(), - simplex, - complex, - aw_it->end()); - assert(simplex.empty()); - if (!ok) - active_witnesses.erase(aw_it++); //First increase the iterator and then erase the previous element - else - aw_it++; - } - k++; - } - complex.set_dimension(k-1); - return true; - } //@} - - private: - /* \brief Adds recursively all the faces of a certain dimension dim witnessed by the same witness. - * Iterator is needed to know until how far we can take landmarks to form simplexes. - * simplex is the prefix of the simplexes to insert. - * The output value indicates if the witness rests active or not. - */ - template < typename SimplicialComplexForWitness > - bool add_all_faces_of_dimension(int dim, - double alpha2, - double norelax_dist2, - typename ActiveWitness::iterator curr_l, - std::vector& simplex, - SimplicialComplexForWitness& sc, - typename ActiveWitness::iterator end) const - { - if (curr_l == end) - return false; - bool will_be_active = false; - typename ActiveWitness::iterator l_it = curr_l; - if (dim > 0) - for (; l_it->second - alpha2 <= norelax_dist2 && l_it != end; ++l_it) { - simplex.push_back(l_it->first); - if (sc.find(simplex) != sc.null_simplex()) { - typename ActiveWitness::iterator next_it = l_it; - will_be_active = add_all_faces_of_dimension(dim-1, - alpha2, - norelax_dist2, - ++next_it, - simplex, - sc, - end) || will_be_active; - } - assert(!simplex.empty()); - simplex.pop_back(); - // If norelax_dist is infinity, change to first omitted distance - if (l_it->second <= norelax_dist2) - norelax_dist2 = l_it->second; - typename ActiveWitness::iterator next_it = l_it; - will_be_active = add_all_faces_of_dimension(dim, - alpha2, - norelax_dist2, - ++next_it, - simplex, - sc, - end) || will_be_active; - } - else if (dim == 0) - for (; l_it->second - alpha2 <= norelax_dist2 && l_it != end; ++l_it) { - simplex.push_back(l_it->first); - double filtration_value = 0; - // if norelax_dist is infinite, relaxation is 0. - if (l_it->second > norelax_dist2) - filtration_value = l_it->second - norelax_dist2; - if (all_faces_in(simplex, &filtration_value, sc)) { - will_be_active = true; - sc.insert_simplex(simplex, filtration_value); - } - assert(!simplex.empty()); - simplex.pop_back(); - // If norelax_dist is infinity, change to first omitted distance - if (l_it->second < norelax_dist2) - norelax_dist2 = l_it->second; - } - return will_be_active; - } - }; } // namespace witness_complex diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index b2bf1b7d..f9d1d681 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -58,7 +58,7 @@ private: typedef Landmark_id Vertex_handle; - private: + protected: Nearest_landmark_table_ nearest_landmark_table_; public: @@ -68,6 +68,11 @@ private: //@{ + Strong_witness_complex() + { + } + + /** * \brief Initializes member variables before constructing simplicial complex. * \details Records nearest landmark table. diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index 52c638c5..33c6c5d2 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -59,7 +59,7 @@ private: typedef Landmark_id Vertex_handle; - private: + protected: Nearest_landmark_table_ nearest_landmark_table_; public: @@ -69,6 +69,10 @@ private: //@{ + Witness_complex() + { + } + /** * \brief Initializes member variables before constructing simplicial complex. * \details Records nearest landmark table. -- cgit v1.2.3 From d563e5184b10c49aaf61b17fc9f7a04e36db1836 Mon Sep 17 00:00:00 2001 From: skachano Date: Wed, 1 Feb 2017 10:01:47 +0000 Subject: Added std::begin and end git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@2039 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 7b1c85ff29b26fb1d0ffbac8f0b2e1f47166f466 --- src/Witness_complex/include/gudhi/Euclidean_strong_witness_complex.h | 2 +- src/Witness_complex/include/gudhi/Euclidean_witness_complex.h | 2 +- src/Witness_complex/include/gudhi/Strong_witness_complex.h | 2 +- src/Witness_complex/include/gudhi/Witness_complex.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Euclidean_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Euclidean_strong_witness_complex.h b/src/Witness_complex/include/gudhi/Euclidean_strong_witness_complex.h index a5947219..56e4bce2 100644 --- a/src/Witness_complex/include/gudhi/Euclidean_strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Euclidean_strong_witness_complex.h @@ -81,7 +81,7 @@ private: typename WitnessRange > Euclidean_strong_witness_complex(const LandmarkRange & landmarks, const WitnessRange & witnesses) - : landmarks_(landmarks), landmark_tree_(landmarks_) + : landmarks_(std::begin(landmarks), std::end(landmarks)), landmark_tree_(landmarks_) { for (auto w: witnesses) nearest_landmark_table_.push_back(landmark_tree_.query_incremental_nearest_neighbors(w)); diff --git a/src/Witness_complex/include/gudhi/Euclidean_witness_complex.h b/src/Witness_complex/include/gudhi/Euclidean_witness_complex.h index 9845808e..c0be5512 100644 --- a/src/Witness_complex/include/gudhi/Euclidean_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Euclidean_witness_complex.h @@ -82,7 +82,7 @@ public: typename WitnessRange > Euclidean_witness_complex(const LandmarkRange & landmarks, const WitnessRange & witnesses) - : landmarks_(landmarks), landmark_tree_(landmarks) + : landmarks_(std::begin(landmarks), std::end(landmarks)), landmark_tree_(landmarks) { for (auto w: witnesses) nearest_landmark_table_.push_back(landmark_tree_.query_incremental_nearest_neighbors(w)); diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index aae1bb43..ca1c4db8 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -80,7 +80,7 @@ private: * The range of nearest landmarks should admit a member type 'iterator'. The dereference type * of the nearest landmark range iterator needs to be 'std::pair'. */ Strong_witness_complex(Nearest_landmark_table_ const & nearest_landmark_table) - : nearest_landmark_table_(nearest_landmark_table) + : nearest_landmark_table_(std::begin(nearest_landmark_table), std::end(nearest_landmark_table)) { } diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index 6741acde..05a26f7f 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -82,7 +82,7 @@ private: */ Witness_complex(Nearest_landmark_table_ const & nearest_landmark_table) - : nearest_landmark_table_(nearest_landmark_table) + : nearest_landmark_table_(std::begin(nearest_landmark_table), std::end(nearest_landmark_table)) { } -- cgit v1.2.3 From 1f3217ef28ff163fdce9c7500b1e428247de820f Mon Sep 17 00:00:00 2001 From: skachano Date: Wed, 1 Feb 2017 10:03:15 +0000 Subject: Added std::begin and end git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@2040 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 985782c21e31296bbd7395357b513c438b3034f3 --- src/Witness_complex/include/gudhi/Euclidean_strong_witness_complex.h | 1 + src/Witness_complex/include/gudhi/Euclidean_witness_complex.h | 1 + 2 files changed, 2 insertions(+) (limited to 'src/Witness_complex/include/gudhi/Euclidean_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Euclidean_strong_witness_complex.h b/src/Witness_complex/include/gudhi/Euclidean_strong_witness_complex.h index 56e4bce2..aad05547 100644 --- a/src/Witness_complex/include/gudhi/Euclidean_strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Euclidean_strong_witness_complex.h @@ -83,6 +83,7 @@ private: const WitnessRange & witnesses) : landmarks_(std::begin(landmarks), std::end(landmarks)), landmark_tree_(landmarks_) { + nearest_landmark_table_.reserve(boost::size(witnesses)); for (auto w: witnesses) nearest_landmark_table_.push_back(landmark_tree_.query_incremental_nearest_neighbors(w)); } diff --git a/src/Witness_complex/include/gudhi/Euclidean_witness_complex.h b/src/Witness_complex/include/gudhi/Euclidean_witness_complex.h index c0be5512..1ab48097 100644 --- a/src/Witness_complex/include/gudhi/Euclidean_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Euclidean_witness_complex.h @@ -84,6 +84,7 @@ public: const WitnessRange & witnesses) : landmarks_(std::begin(landmarks), std::end(landmarks)), landmark_tree_(landmarks) { + nearest_landmark_table_.reserve(boost::size(witnesses)); for (auto w: witnesses) nearest_landmark_table_.push_back(landmark_tree_.query_incremental_nearest_neighbors(w)); } -- cgit v1.2.3 From d7b82999427c89d3c326cfc71bdff488caf2704a Mon Sep 17 00:00:00 2001 From: skachano Date: Fri, 24 Feb 2017 10:43:17 +0000 Subject: Removed all_faces_in include git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@2101 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 7d56b8c508be289dc84fe58c381596f4da45d0a2 --- src/Witness_complex/include/gudhi/Euclidean_witness_complex.h | 1 - 1 file changed, 1 deletion(-) (limited to 'src/Witness_complex/include/gudhi/Euclidean_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Euclidean_witness_complex.h b/src/Witness_complex/include/gudhi/Euclidean_witness_complex.h index 1ab48097..146271f7 100644 --- a/src/Witness_complex/include/gudhi/Euclidean_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Euclidean_witness_complex.h @@ -26,7 +26,6 @@ #include #include #include -#include #include #include -- cgit v1.2.3 From fda43b1fde4774909c632a0604ae7ad05a660d3a Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 1 Mar 2017 06:03:29 +0000 Subject: Fix cppcheck git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@2122 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 92d11c064056138ce4aa8cbe3a42df29a8a5ca7d --- .../example/example_strong_witness_persistence.cpp | 3 +- .../example_witness_complex_persistence.cpp | 35 ++++++++++------------ .../gudhi/Active_witness/Active_witness_iterator.h | 11 ++++--- .../gudhi/Euclidean_strong_witness_complex.h | 6 ++-- .../include/gudhi/Euclidean_witness_complex.h | 20 ++++++------- .../include/gudhi/Strong_witness_complex.h | 17 +++++------ .../include/gudhi/Witness_complex.h | 2 +- 7 files changed, 45 insertions(+), 49 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Euclidean_witness_complex.h') diff --git a/src/Witness_complex/example/example_strong_witness_persistence.cpp b/src/Witness_complex/example/example_strong_witness_persistence.cpp index 5efe69fd..f786fe7b 100644 --- a/src/Witness_complex/example/example_strong_witness_persistence.cpp +++ b/src/Witness_complex/example/example_strong_witness_persistence.cpp @@ -126,13 +126,14 @@ void program_options(int argc, char * argv[] "Name of file containing a point set in off format."); po::options_description visible("Allowed options", 100); + Filtration_value default_alpha = std::numeric_limits::infinity(); visible.add_options() ("help,h", "produce help message") ("landmarks,l", po::value(&nbL), "Number of landmarks to choose from the point cloud.") ("output-file,o", po::value(&filediag)->default_value(std::string()), "Name of file in which the persistence diagram is written. Default print in std::cout") - ("max-sq-alpha,a", po::value(&max_squared_alpha)->default_value(std::numeric_limits::infinity()), + ("max-sq-alpha,a", po::value(&max_squared_alpha)->default_value(default_alpha), "Maximal squared relaxation parameter.") ("field-charac,p", po::value(&p)->default_value(11), "Characteristic p of the coefficient field Z/pZ for computing homology.") diff --git a/src/Witness_complex/example/example_witness_complex_persistence.cpp b/src/Witness_complex/example/example_witness_complex_persistence.cpp index 364a114a..a1146922 100644 --- a/src/Witness_complex/example/example_witness_complex_persistence.cpp +++ b/src/Witness_complex/example/example_witness_complex_persistence.cpp @@ -34,18 +34,17 @@ #include #include // infinity -using namespace Gudhi; -using namespace Gudhi::persistent_cohomology; +using K = CGAL::Epick_d; +using Point_d = K::Point_d; -typedef CGAL::Epick_d K; -typedef typename K::Point_d Point_d; +using Point_vector = std::vector; +using Witness_complex = Gudhi::witness_complex::Euclidean_witness_complex; +using SimplexTree = Gudhi::Simplex_tree<>; -typedef typename std::vector Point_vector; -typedef typename Gudhi::witness_complex::Euclidean_witness_complex Witness_complex; -typedef Gudhi::Simplex_tree<> SimplexTree; +using Filtration_value = SimplexTree::Filtration_value; -typedef int Vertex_handle; -typedef double Filtration_value; +using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; +using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; void program_options(int argc, char * argv[] , int & nbL @@ -83,9 +82,9 @@ int main(int argc, char * argv[]) { // Compute witness complex Witness_complex witness_complex(landmarks, witnesses); - + witness_complex.create_complex(simplex_tree, max_squared_alpha, lim_d); - + std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices \n"; std::cout << " and has dimension " << simplex_tree.dimension() << " \n"; @@ -93,7 +92,7 @@ int main(int argc, char * argv[]) { simplex_tree.initialize_filtration(); // Compute the persistence diagram of the complex - persistent_cohomology::Persistent_cohomology pcoh(simplex_tree); + Persistent_cohomology pcoh(simplex_tree); // initializes the coefficient field for homology pcoh.init_coefficients(p); @@ -120,15 +119,14 @@ void program_options(int argc, char * argv[] , int & p , int & dim_max , Filtration_value & min_persistence) { - namespace po = boost::program_options; - + po::options_description hidden("Hidden options"); hidden.add_options() ("input-file", po::value(&file_name), "Name of file containing a point set in off format."); - + Filtration_value default_alpha = std::numeric_limits::infinity(); po::options_description visible("Allowed options", 100); visible.add_options() ("help,h", "produce help message") @@ -136,7 +134,7 @@ void program_options(int argc, char * argv[] "Number of landmarks to choose from the point cloud.") ("output-file,o", po::value(&filediag)->default_value(std::string()), "Name of file in which the persistence diagram is written. Default print in std::cout") - ("max-sq-alpha,a", po::value(&max_squared_alpha)->default_value(std::numeric_limits::infinity()), + ("max-sq-alpha,a", po::value(&max_squared_alpha)->default_value(default_alpha), "Maximal squared relaxation parameter.") ("field-charac,p", po::value(&p)->default_value(11), "Characteristic p of the coefficient field Z/pZ for computing homology.") @@ -144,7 +142,7 @@ void program_options(int argc, char * argv[] "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals") ("cpx-dimension,d", po::value(&dim_max)->default_value(std::numeric_limits::max()), "Maximal dimension of the weak witness complex we want to compute."); - + po::positional_options_description pos; pos.add("input-file", 1); @@ -155,7 +153,7 @@ void program_options(int argc, char * argv[] po::store(po::command_line_parser(argc, argv). options(all).positional(pos).run(), vm); po::notify(vm); - + if (vm.count("help") || !vm.count("input-file")) { std::cout << std::endl; std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; @@ -171,4 +169,3 @@ void program_options(int argc, char * argv[] std::abort(); } } - diff --git a/src/Witness_complex/include/gudhi/Active_witness/Active_witness_iterator.h b/src/Witness_complex/include/gudhi/Active_witness/Active_witness_iterator.h index 4e29a40d..0a05173a 100644 --- a/src/Witness_complex/include/gudhi/Active_witness/Active_witness_iterator.h +++ b/src/Witness_complex/include/gudhi/Active_witness/Active_witness_iterator.h @@ -36,7 +36,6 @@ namespace witness_complex { * If all the landmarks are present in the list, iterator returns the specific end value * of the corresponding 'Active_witness' object. */ - template< typename Active_witness, typename Id_distance_pair, typename INS_iterator > @@ -47,15 +46,14 @@ class Active_witness_iterator Id_distance_pair const> { friend class boost::iterator_core_access; - //typedef Active_witness Active_witness; typedef typename std::list::iterator Pair_iterator; typedef typename Gudhi::witness_complex::Active_witness_iterator Iterator; Active_witness *aw_; - Pair_iterator lh_; // landmark handle - bool is_end_; // true only if the pointer is end and there are no more neighbors to add + Pair_iterator lh_; // landmark handle + bool is_end_; // true only if the pointer is end and there are no more neighbors to add public: Active_witness_iterator(Active_witness* aw) @@ -87,7 +85,8 @@ class Active_witness_iterator void increment() { // the neighbor search can't be at the end iterator of a list - GUDHI_CHECK(!is_end_ && lh_ != aw_->nearest_landmark_table_.end(), std::logic_error("Wrong active witness increment.")); + GUDHI_CHECK(!is_end_ && lh_ != aw_->nearest_landmark_table_.end(), + std::logic_error("Wrong active witness increment.")); // if the id of the current landmark is the same as the last one lh_++; @@ -105,5 +104,5 @@ class Active_witness_iterator } // namespace witness_complex } // namespace Gudhi - + #endif // ACTIVE_WITNESS_ACTIVE_WITNESS_ITERATOR_H_ diff --git a/src/Witness_complex/include/gudhi/Euclidean_strong_witness_complex.h b/src/Witness_complex/include/gudhi/Euclidean_strong_witness_complex.h index 6870c183..fb669ef8 100644 --- a/src/Witness_complex/include/gudhi/Euclidean_strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Euclidean_strong_witness_complex.h @@ -83,13 +83,13 @@ class Euclidean_strong_witness_complex const WitnessRange & witnesses) : landmarks_(std::begin(landmarks), std::end(landmarks)), landmark_tree_(landmarks_) { nearest_landmark_table_.reserve(boost::size(witnesses)); - for (auto w: witnesses) + for (auto w : witnesses) nearest_landmark_table_.push_back(landmark_tree_.query_incremental_nearest_neighbors(w)); } /** \brief Returns the point corresponding to the given vertex. */ - template + template Point_d get_point(Vertex_handle vertex) const { return landmarks_[vertex]; } @@ -101,4 +101,4 @@ class Euclidean_strong_witness_complex } // namespace Gudhi -#endif // EUCLIDEAN_STRONG_WITNESS_COMPLEX_H_ +#endif // EUCLIDEAN_STRONG_WITNESS_COMPLEX_H_ diff --git a/src/Witness_complex/include/gudhi/Euclidean_witness_complex.h b/src/Witness_complex/include/gudhi/Euclidean_witness_complex.h index 146271f7..6afe9a5d 100644 --- a/src/Witness_complex/include/gudhi/Euclidean_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Euclidean_witness_complex.h @@ -33,7 +33,7 @@ #include namespace Gudhi { - + namespace witness_complex { /** @@ -46,8 +46,10 @@ namespace witness_complex { * href="http://doc.cgal.org/latest/Kernel_d/classCGAL_1_1Epick__d.html">CGAL::Epick_d class. */ template< class Kernel_ > -class Euclidean_witness_complex : public Witness_complex>::INS_range>> { -private: +class Euclidean_witness_complex + : public Witness_complex>::INS_range>> { + private: typedef Kernel_ K; typedef typename K::Point_d Point_d; typedef std::vector Point_range; @@ -64,7 +66,7 @@ private: Kd_tree landmark_tree_; using Witness_complex::nearest_landmark_table_; -public: + public: ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /* @name Constructor */ @@ -81,24 +83,22 @@ public: typename WitnessRange > Euclidean_witness_complex(const LandmarkRange & landmarks, const WitnessRange & witnesses) - : landmarks_(std::begin(landmarks), std::end(landmarks)), landmark_tree_(landmarks) - { + : landmarks_(std::begin(landmarks), std::end(landmarks)), landmark_tree_(landmarks) { nearest_landmark_table_.reserve(boost::size(witnesses)); - for (auto w: witnesses) + for (auto w : witnesses) nearest_landmark_table_.push_back(landmark_tree_.query_incremental_nearest_neighbors(w)); } /** \brief Returns the point corresponding to the given vertex. * @param[in] vertex Vertex handle of the point to retrieve. */ - Point_d get_point( Vertex_handle vertex ) const - { + Point_d get_point(Vertex_handle vertex) const { return landmarks_[vertex]; } //@} }; - + } // namespace witness_complex } // namespace Gudhi diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index 3fbbb366..6708ac29 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -79,8 +79,8 @@ class Strong_witness_complex { * The range of pairs must admit a member type 'iterator'. The dereference type * of the pair range iterator needs to be 'std::pair'. */ - Strong_witness_complex(Nearest_landmark_table_ const & nearest_landmark_table) - : nearest_landmark_table_(std::begin(nearest_landmark_table), std::end(nearest_landmark_table)) { + Strong_witness_complex(Nearest_landmark_table_ const & nearest_landmark_table) + : nearest_landmark_table_(std::begin(nearest_landmark_table), std::end(nearest_landmark_table)) { } /** \brief Outputs the strong witness complex of relaxation 'max_alpha_square' @@ -110,7 +110,7 @@ class Strong_witness_complex { std::cerr << "Strong witness complex cannot create complex - limit dimension must be non-negative.\n"; return false; } - for (auto w: nearest_landmark_table_) { + for (auto w : nearest_landmark_table_) { ActiveWitness aw(w); typeVectorVertex simplex; typename ActiveWitness::iterator aw_it = aw.begin(); @@ -121,7 +121,7 @@ class Strong_witness_complex { aw_it++; } // continue inserting limD-faces of the following simplices - typeVectorVertex& vertices = simplex; //'simplex' now will be called vertices + typeVectorVertex& vertices = simplex; // 'simplex' now will be called vertices while (aw_it != aw.end() && aw_it->second < lim_dist2) { typeVectorVertex facet = {}; add_all_faces_of_dimension(limit_dimension, vertices, vertices.begin(), aw_it, @@ -153,7 +153,7 @@ class Strong_witness_complex { if (dim > 0) { while (curr_it != vertices.end()) { simplex.push_back(*curr_it); - ++curr_it; + ++curr_it; add_all_faces_of_dimension(dim-1, vertices, curr_it, @@ -169,14 +169,13 @@ class Strong_witness_complex { filtration_value, simplex, sc); - } + } } else if (dim == 0) { simplex.push_back(aw_it->first); sc.insert_simplex_and_subfaces(simplex, filtration_value); simplex.pop_back(); - } - } - + } + } //@} }; diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index c0506367..a79bf294 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -183,7 +183,7 @@ class Witness_complex { simplex.push_back(l_it->first); double filtration_value = 0; // if norelax_dist is infinite, relaxation is 0. - if (l_it->second > norelax_dist2) + if (l_it->second > norelax_dist2) filtration_value = l_it->second - norelax_dist2; if (all_faces_in(simplex, &filtration_value, sc)) { will_be_active = true; -- cgit v1.2.3