From e061bc2e16e8fdb7368479f101642ae239ffc7dc Mon Sep 17 00:00:00 2001 From: skachano Date: Wed, 5 Oct 2016 08:57:58 +0000 Subject: Added the forgotten strong witness complex git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1640 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 19e4a60b7b6a71db6148bb99f11dbf10ff8cc248 --- .../include/gudhi/Strong_witness_complex.h | 198 +++++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100644 src/Witness_complex/include/gudhi/Strong_witness_complex.h (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h new file mode 100644 index 00000000..539c872d --- /dev/null +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -0,0 +1,198 @@ +/* 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 Sophia Antipolis-Méditerranée (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 STRONG_WITNESS_COMPLEX_H_ +#define STRONG_WITNESS_COMPLEX_H_ + +#include +#include +#include +#include +#include "gudhi/reader_utils.h" +#include "gudhi/distance_functions.h" +#include "gudhi/Simplex_tree.h" +#include +#include +#include +#include +#include +#include +#include +#include + +// Needed for nearest neighbours +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +// Needed for the adjacency graph in bad link search +#include +#include +#include + +namespace gss = Gudhi::spatial_searching; + +namespace Gudhi { + +namespace witness_complex { + +// /* +// * \private +// \class Witness_complex +// \brief Constructs the witness complex for the given set of witnesses and landmarks. +// \ingroup witness_complex +// */ +template< class Kernel_ > +class Strong_witness_complex { +private: + typedef Kernel_ K; + typedef typename K::Point_d Point_d; + typedef typename K::FT FT; + typedef std::vector Point_range; + typedef gss::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 std::vector> Nearest_landmarks; + + // struct Active_witness { + // int witness_id; + // int landmark_id; + + // Active_witness(int witness_id_, int landmark_id_) + // : witness_id(witness_id_), + // landmark_id(landmark_id_) { } + // }; + + typedef std::vector< double > Point_t; + typedef std::vector< Point_t > Point_Vector; + + typedef FT Filtration_value; + + + typedef std::ptrdiff_t Witness_id; + typedef std::ptrdiff_t Landmark_id; + typedef std::pair Id_distance_pair; + typedef Active_witness ActiveWitness; + typedef std::list< ActiveWitness > ActiveWitnessList; + typedef std::vector< Landmark_id > typeVectorVertex; + typedef std::pair< typeVectorVertex, Filtration_value> typeSimplex; + + private: + Point_range witnesses_, landmarks_; + Kd_tree landmark_tree_; + + public: + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /* @name Constructor + */ + + //@{ + + // Witness_range> + + /* + * \brief Iterative construction of the (weak) witness complex. + * \details The witness complex is written in sc_ basing on a matrix knn of + * nearest neighbours of the form {witnesses}x{landmarks}. + * + * The type KNearestNeighbors can be seen as + * Witness_range>, where + * Witness_range and Closest_landmark_range are random access ranges. + * + * Constructor takes into account at most (dim+1) + * first landmarks from each landmark range to construct simplices. + * + * Landmarks are supposed to be in [0,nbL_-1] + */ + template< typename InputIteratorLandmarks, + typename InputIteratorWitnesses > + Strong_witness_complex(InputIteratorLandmarks landmarks_first, + InputIteratorLandmarks landmarks_last, + InputIteratorWitnesses witnesses_first, + InputIteratorWitnesses witnesses_last) + : witnesses_(witnesses_first, witnesses_last), landmarks_(landmarks_first, landmarks_last), landmark_tree_(landmarks_) + { + } + + /** \brief Returns the point corresponding to the given vertex. + */ + Point_d get_point( std::size_t vertex ) const + { + return landmarks_[vertex]; + } + + /** \brief Outputs the (weak) witness complex with + * squared relaxation parameter 'max_alpha_square' + * to simplicial complex 'complex'. + */ + template < typename SimplicialComplexForWitness > + bool create_complex(SimplicialComplexForWitness& complex, + FT max_alpha_square) + { + unsigned nbL = landmarks_.size(); + if (complex.num_vertices() > 0) { + std::cerr << "Witness complex cannot create complex - complex is not empty.\n"; + return false; + } + if (max_alpha_square < 0) { + std::cerr << "Witness complex cannot create complex - squared relaxation parameter must be non-negative.\n"; + return false; + } + typeVectorVertex vv; + //ActiveWitnessList active_witnesses;// = new ActiveWitnessList(); + for (unsigned i = 0; i != nbL; ++i) { + // initial fill of 0-dimensional simplices + vv = {i}; + complex.insert_simplex(vv, Filtration_value(0.0)); + /* TODO Error if not inserted : normally no need here though*/ + } + for (auto w: witnesses_) { + ActiveWitness aw(landmark_tree_.query_incremental_nearest_neighbors(w)); + typeVectorVertex simplex; + typename ActiveWitness::iterator aw_it = aw.begin(); + float lim_d2 = aw.begin()->second + max_alpha_square; + while (aw_it != aw.end() && aw_it->second < lim_d2) { + simplex.push_back(aw_it->first); + complex.insert_simplex_and_subfaces(simplex, aw_it->second - aw.begin()->second); + aw_it++; + } + } + return true; + } + + //@} +}; + +} // namespace witness_complex + +} // namespace Gudhi + +#endif -- cgit v1.2.3 From 1de8ffacd531550f0ce5e871ec0f69924df3ee44 Mon Sep 17 00:00:00 2001 From: skachano Date: Wed, 5 Oct 2016 11:53:47 +0000 Subject: Minor tweaks git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1645 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 00b32608afa185b5f66679f556d8a4a892327b0b --- .../include/gudhi/Strong_witness_complex.h | 20 +-- .../include/gudhi/Witness_complex.h | 134 ++------------------- 2 files changed, 10 insertions(+), 144 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index 539c872d..f5633a98 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -63,12 +63,6 @@ namespace Gudhi { namespace witness_complex { -// /* -// * \private -// \class Witness_complex -// \brief Constructs the witness complex for the given set of witnesses and landmarks. -// \ingroup witness_complex -// */ template< class Kernel_ > class Strong_witness_complex { private: @@ -80,16 +74,6 @@ private: 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 std::vector> Nearest_landmarks; - - // struct Active_witness { - // int witness_id; - // int landmark_id; - - // Active_witness(int witness_id_, int landmark_id_) - // : witness_id(witness_id_), - // landmark_id(landmark_id_) { } - // }; typedef std::vector< double > Point_t; typedef std::vector< Point_t > Point_Vector; @@ -98,8 +82,8 @@ private: typedef std::ptrdiff_t Witness_id; - typedef std::ptrdiff_t Landmark_id; - typedef std::pair Id_distance_pair; + 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; diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index e939de34..e732cb18 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -67,16 +67,6 @@ private: 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 std::vector> Nearest_landmarks; - - // struct Active_witness { - // int witness_id; - // int landmark_id; - - // Active_witness(int witness_id_, int landmark_id_) - // : witness_id(witness_id_), - // landmark_id(landmark_id_) { } - // }; typedef std::vector< double > Point_t; typedef std::vector< Point_t > Point_Vector; @@ -84,9 +74,9 @@ private: typedef FT Filtration_value; - typedef std::ptrdiff_t Witness_id; - typedef std::ptrdiff_t Landmark_id; - typedef std::pair Id_distance_pair; + 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; @@ -103,8 +93,6 @@ private: //@{ - // Witness_range> - /* * \brief Iterative construction of the (weak) witness complex. * \details The witness complex is written in sc_ basing on a matrix knn of @@ -144,7 +132,7 @@ private: bool create_complex(SimplicialComplexForWitness& complex, FT max_alpha_square) { - unsigned nbL = landmarks_.size(); + std::size_t nbL = landmarks_.size(); if (complex.num_vertices() > 0) { std::cerr << "Witness complex cannot create complex - complex is not empty.\n"; return false; @@ -169,9 +157,9 @@ private: ActiveWitness aw_copy(active_witnesses.front()); while (!active_witnesses.empty() && k < nbL ) { typename ActiveWitnessList::iterator aw_it = active_witnesses.begin(); + std::vector simplex; + simplex.reserve(k+1); while (aw_it != active_witnesses.end()) { - std::vector simplex; - //simplex.reserve(k+1); bool ok = add_all_faces_of_dimension(k, max_alpha_square, std::numeric_limits::infinity(), @@ -179,9 +167,9 @@ private: simplex, complex, aw_it->end()); + assert(simplex.empty()); if (!ok) - //{aw_it++;} - active_witnesses.erase(aw_it++); //First increase the iterator and then erase the previous element + active_witnesses.erase(aw_it++); //First increase the iterator and then erase the previous element else aw_it++; } @@ -289,114 +277,8 @@ private: } return true; } - - // bool is_face(Simplex_handle face, Simplex_handle coface) - // { - // // vertex range is sorted in decreasing order - // auto fvr = sc.simplex_vertex_range(face); - // auto cfvr = sc.simplex_vertex_range(coface); - // auto fv_it = fvr.begin(); - // auto cfv_it = cfvr.begin(); - // while (fv_it != fvr.end() && cfv_it != cfvr.end()) { - // if (*fv_it < *cfv_it) - // ++cfv_it; - // else if (*fv_it == *cfv_it) { - // ++cfv_it; - // ++fv_it; - // } - // else - // return false; - - // } - // return (fv_it == fvr.end()); - // } - - - public: - template < typename SimplicialComplexForWitness > - void print_complex(SimplicialComplexForWitness& complex) - { - std::cout << complex << "\n"; - } - - template < typename Container > - void print_container(Container& container) - { - for (auto l: container) - std::cout << l << ", "; - std::cout << "\n"; - } - - // /* - // * \brief Verification if every simplex in the complex is witnessed by witnesses in knn. - // * \param print_output =true will print the witnesses for each simplex - // * \remark Added for debugging purposes. - // */ - // template< class KNearestNeighbors > - // bool is_witness_complex(KNearestNeighbors const & knn, bool print_output) { - // for (Simplex_handle sh : sc_.complex_simplex_range()) { - // bool is_witnessed = false; - // typeVectorVertex simplex; - // int nbV = 0; // number of verticed in the simplex - // for (Vertex_handle v : sc_.simplex_vertex_range(sh)) - // simplex.push_back(v); - // nbV = simplex.size(); - // for (typeVectorVertex w : knn) { - // bool has_vertices = true; - // for (Vertex_handle v : simplex) - // if (std::find(w.begin(), w.begin() + nbV, v) == w.begin() + nbV) { - // has_vertices = false; - // } - // if (has_vertices) { - // is_witnessed = true; - // if (print_output) { - // std::cout << "The simplex "; - // print_vector(simplex); - // std::cout << " is witnessed by the witness "; - // print_vector(w); - // std::cout << std::endl; - // } - // break; - // } - // } - // if (!is_witnessed) { - // if (print_output) { - // std::cout << "The following simplex is not witnessed "; - // print_vector(simplex); - // std::cout << std::endl; - // } - // assert(is_witnessed); - // return false; - // } - // } - // return true; - // } }; - /** - * \ingroup witness_complex - * \brief Iterative construction of the witness complex. - * \details The witness complex is written in simplicial complex sc_ - * basing on a matrix knn of - * nearest neighbours of the form {witnesses}x{landmarks}. - * - * The type KNearestNeighbors can be seen as - * Witness_range>, where - * Witness_range and Closest_landmark_range are random access ranges. - * - * Procedure takes into account at most (dim+1) - * first landmarks from each landmark range to construct simplices. - * - * Landmarks are supposed to be in [0,nbL_-1] - */ - // template - // void witness_complex(KNearestNeighbors const & knn, - // int nbL, - // int dim, - // SimplicialComplexForWitness & sc) { - // Witness_complex(knn, nbL, dim, sc); - // } - } // namespace witness_complex } // namespace Gudhi -- cgit v1.2.3 From 07e6b3d053144329a03bf7c8f52538d221e6ea6d Mon Sep 17 00:00:00 2001 From: skachano Date: Thu, 6 Oct 2016 18:11:50 +0000 Subject: Added persistence examples git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1670 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: c7762be9b79ba70cca84a378915c2deef13211fd --- src/Witness_complex/example/CMakeLists.txt | 7 +- .../example/example_strong_witness_persistence.cpp | 172 +++++++++++++++++++++ .../example/example_witness_complex_off.cpp | 3 +- .../example_witness_complex_persistence.cpp | 172 +++++++++++++++++++++ .../include/gudhi/Strong_witness_complex.h | 12 +- .../include/gudhi/Witness_complex.h | 2 +- 6 files changed, 361 insertions(+), 7 deletions(-) create mode 100644 src/Witness_complex/example/example_strong_witness_persistence.cpp create mode 100644 src/Witness_complex/example/example_witness_complex_persistence.cpp (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/example/CMakeLists.txt b/src/Witness_complex/example/CMakeLists.txt index 469c9aac..38cfa821 100644 --- a/src/Witness_complex/example/CMakeLists.txt +++ b/src/Witness_complex/example/CMakeLists.txt @@ -7,7 +7,12 @@ if(CGAL_FOUND) if (EIGEN3_FOUND) add_executable( Witness_complex_example_off example_witness_complex_off.cpp ) add_executable ( Witness_complex_example_sphere example_witness_complex_sphere.cpp ) - #add_executable ( relaxed_witness_persistence relaxed_witness_persistence.cpp ) + add_executable ( Witness_complex_example_witness_persistence example_witness_complex_persistence.cpp ) + target_link_libraries(Witness_complex_example_witness_persistence ${Boost_PROGRAM_OPTIONS_LIBRARY}) + add_test(Witness_complex_test_torus_persistence src/Witness_complex/example/Witness_complex_example_witncess_complex_persistence ../data/points/tore3D_1307.off -l 20 -a 0.5) + add_executable ( Witness_complex_example_strong_witness_persistence example_strong_witness_persistence.cpp ) + target_link_libraries(Witness_complex_example_strong_witness_persistence ${Boost_PROGRAM_OPTIONS_LIBRARY}) + add_test(Witness_complex_test_torus_persistence src/Witness_complex/example/Witness_complex_example_strong_witness_persistence ../data/points/tore3D_1307.off -l 20 -a 0.5) endif(EIGEN3_FOUND) endif (NOT CGAL_VERSION VERSION_LESS 4.6.0) endif() diff --git a/src/Witness_complex/example/example_strong_witness_persistence.cpp b/src/Witness_complex/example/example_strong_witness_persistence.cpp new file mode 100644 index 00000000..bf6b4011 --- /dev/null +++ b/src/Witness_complex/example/example_strong_witness_persistence.cpp @@ -0,0 +1,172 @@ +/* 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) 2016 INRIA Sophia Antipolis-Méditerranée (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 . + */ + +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include // infinity + +using namespace Gudhi; +using namespace Gudhi::persistent_cohomology; + +typedef CGAL::Epick_d K; +typedef typename K::Point_d Point_d; + +typedef typename std::vector Point_vector; +typedef typename Gudhi::witness_complex::Strong_witness_complex Strong_witness_complex; +typedef Gudhi::Simplex_tree<> SimplexTree; + +typedef int Vertex_handle; +typedef double Filtration_value; + +void program_options(int argc, char * argv[] + , int & nbL + , std::string & file_name + , std::string & filediag + , Filtration_value & max_squared_alpha + , int & p + , Filtration_value & min_persistence); + +int main(int argc, char * argv[]) { + std::string file_name; + std::string filediag; + Filtration_value max_squared_alpha; + int p, nbL; + Filtration_value min_persistence; + SimplexTree simplex_tree; + + program_options(argc, argv, nbL, file_name, filediag, max_squared_alpha, p, min_persistence); + + // Extract the points from the file file_name + Point_vector witnesses, landmarks; + Gudhi::Points_off_reader off_reader(file_name); + if (!off_reader.is_valid()) { + std::cerr << "Witness complex - Unable to read file " << file_name << "\n"; + exit(-1); // ----- >> + } + witnesses = Point_vector(off_reader.get_point_cloud()); + std::cout << "Successfully read " << witnesses.size() << " points.\n"; + std::cout << "Ambient dimension is " << witnesses[0].dimension() << ".\n"; + + // Choose landmarks from witnesses + Gudhi::subsampling::pick_n_random_points(witnesses, nbL, std::back_inserter(landmarks)); + + // Compute witness complex + Strong_witness_complex strong_witness_complex(landmarks.begin(), + landmarks.end(), + witnesses.begin(), + witnesses.end()); + + strong_witness_complex.create_complex(simplex_tree, max_squared_alpha); + + std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices \n"; + std::cout << " and has dimension " << simplex_tree.dimension() << " \n"; + + // Sort the simplices in the order of the filtration + simplex_tree.initialize_filtration(); + + // Compute the persistence diagram of the complex + persistent_cohomology::Persistent_cohomology pcoh(simplex_tree); + // initializes the coefficient field for homology + pcoh.init_coefficients(p); + + pcoh.compute_persistent_cohomology(min_persistence); + + // Output the diagram in filediag + if (filediag.empty()) { + pcoh.output_diagram(); + } else { + std::ofstream out(filediag); + pcoh.output_diagram(out); + out.close(); + } + + return 0; +} + + +void program_options(int argc, char * argv[] + , int & nbL + , std::string & file_name + , std::string & filediag + , Filtration_value & max_squared_alpha + , int & p + , 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."); + + + po::options_description visible("Allowed options", 100); + 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()), + "Maximal length of an edge for the Rips complex construction.") + ("field-charac,p", po::value(&p)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.") + ("min-persistence,m", po::value(&min_persistence)->default_value(0), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); + + po::positional_options_description pos; + pos.add("input-file", 1); + + po::options_description all; + all.add(visible).add(hidden); + po::variables_map vm; + + 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"; + std::cout << "of a Strong witness complex defined on a set of input points.\n \n"; + std::cout << "The output diagram contains one bar per line, written with the convention: \n"; + std::cout << " p dim b d \n"; + std::cout << "where dim is the dimension of the homological feature,\n"; + std::cout << "b and d are respectively the birth and death of the feature and \n"; + std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; + + std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; + std::cout << visible << std::endl; + std::abort(); + } +} + diff --git a/src/Witness_complex/example/example_witness_complex_off.cpp b/src/Witness_complex/example/example_witness_complex_off.cpp index 6b0060d9..849a0a40 100644 --- a/src/Witness_complex/example/example_witness_complex_off.cpp +++ b/src/Witness_complex/example/example_witness_complex_off.cpp @@ -53,8 +53,6 @@ int main(int argc, char * const argv[]) { int nbL = atoi(argv[2]); double alpha2 = atof(argv[3]); clock_t start, end; - - // Construct the Simplex Tree Gudhi::Simplex_tree<> simplex_tree; // Read the point file @@ -78,6 +76,7 @@ int main(int argc, char * const argv[]) { landmarks.end(), point_vector.begin(), point_vector.end()); + witness_complex.create_complex(simplex_tree, alpha2); end = clock(); std::cout << "Witness complex took " diff --git a/src/Witness_complex/example/example_witness_complex_persistence.cpp b/src/Witness_complex/example/example_witness_complex_persistence.cpp new file mode 100644 index 00000000..9b06b504 --- /dev/null +++ b/src/Witness_complex/example/example_witness_complex_persistence.cpp @@ -0,0 +1,172 @@ +/* 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) 2016 INRIA Sophia Antipolis-Méditerranée (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 . + */ + +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include // infinity + +using namespace Gudhi; +using namespace Gudhi::persistent_cohomology; + +typedef CGAL::Epick_d K; +typedef typename K::Point_d Point_d; + +typedef typename std::vector Point_vector; +typedef typename Gudhi::witness_complex::Witness_complex Witness_complex; +typedef Gudhi::Simplex_tree<> SimplexTree; + +typedef int Vertex_handle; +typedef double Filtration_value; + +void program_options(int argc, char * argv[] + , int & nbL + , std::string & file_name + , std::string & filediag + , Filtration_value & max_squared_alpha + , int & p + , Filtration_value & min_persistence); + +int main(int argc, char * argv[]) { + std::string file_name; + std::string filediag; + Filtration_value max_squared_alpha; + int p, nbL; + Filtration_value min_persistence; + SimplexTree simplex_tree; + + program_options(argc, argv, nbL, file_name, filediag, max_squared_alpha, p, min_persistence); + + // Extract the points from the file file_name + Point_vector witnesses, landmarks; + Gudhi::Points_off_reader off_reader(file_name); + if (!off_reader.is_valid()) { + std::cerr << "Witness complex - Unable to read file " << file_name << "\n"; + exit(-1); // ----- >> + } + witnesses = Point_vector(off_reader.get_point_cloud()); + std::cout << "Successfully read " << witnesses.size() << " points.\n"; + std::cout << "Ambient dimension is " << witnesses[0].dimension() << ".\n"; + + // Choose landmarks from witnesses + Gudhi::subsampling::pick_n_random_points(witnesses, nbL, std::back_inserter(landmarks)); + + // Compute witness complex + Witness_complex witness_complex(landmarks.begin(), + landmarks.end(), + witnesses.begin(), + witnesses.end()); + + witness_complex.create_complex(simplex_tree, max_squared_alpha); + + std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices \n"; + std::cout << " and has dimension " << simplex_tree.dimension() << " \n"; + + // Sort the simplices in the order of the filtration + simplex_tree.initialize_filtration(); + + // Compute the persistence diagram of the complex + persistent_cohomology::Persistent_cohomology pcoh(simplex_tree); + // initializes the coefficient field for homology + pcoh.init_coefficients(p); + + pcoh.compute_persistent_cohomology(min_persistence); + + // Output the diagram in filediag + if (filediag.empty()) { + pcoh.output_diagram(); + } else { + std::ofstream out(filediag); + pcoh.output_diagram(out); + out.close(); + } + + return 0; +} + + +void program_options(int argc, char * argv[] + , int & nbL + , std::string & file_name + , std::string & filediag + , Filtration_value & max_squared_alpha + , int & p + , 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."); + + + po::options_description visible("Allowed options", 100); + 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()), + "Maximal length of an edge for the Rips complex construction.") + ("field-charac,p", po::value(&p)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.") + ("min-persistence,m", po::value(&min_persistence)->default_value(0), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); + + po::positional_options_description pos; + pos.add("input-file", 1); + + po::options_description all; + all.add(visible).add(hidden); + po::variables_map vm; + + 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"; + std::cout << "of a Weak witness complex defined on a set of input points.\n \n"; + std::cout << "The output diagram contains one bar per line, written with the convention: \n"; + std::cout << " p dim b d \n"; + std::cout << "where dim is the dimension of the homological feature,\n"; + std::cout << "b and d are respectively the birth and death of the feature and \n"; + std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; + + std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; + std::cout << visible << std::endl; + std::abort(); + } +} + diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index f5633a98..3a862d71 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -27,9 +27,6 @@ #include #include #include -#include "gudhi/reader_utils.h" -#include "gudhi/distance_functions.h" -#include "gudhi/Simplex_tree.h" #include #include #include @@ -39,6 +36,11 @@ #include #include +#include "Active_witness/Active_witness.h" +#include +#include + + // Needed for nearest neighbours #include #include @@ -142,6 +144,7 @@ private: FT max_alpha_square) { unsigned nbL = landmarks_.size(); + unsigned complex_dim = 0; if (complex.num_vertices() > 0) { std::cerr << "Witness complex cannot create complex - complex is not empty.\n"; return false; @@ -168,7 +171,10 @@ private: complex.insert_simplex_and_subfaces(simplex, aw_it->second - aw.begin()->second); aw_it++; } + if (simplex.size() - 1 > complex_dim) + complex_dim = simplex.size() - 1; } + complex.set_dimension(complex_dim); return true; } diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index a16f9270..7d8fce86 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -31,7 +31,6 @@ #include #include "Active_witness/Active_witness.h" -#include #include #include @@ -175,6 +174,7 @@ private: } k++; } + complex.set_dimension(k-1); return true; } -- cgit v1.2.3 From 1bcd448f6e217655fae4bfbf62d8d3b6caa52503 Mon Sep 17 00:00:00 2001 From: skachano Date: Fri, 7 Oct 2016 09:49:47 +0000 Subject: Added the possibility to limit dimension git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1676 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 16ec8706ffb981ff892960468cc4b809e61612e2 --- .../example/example_strong_witness_persistence.cpp | 10 +++++++--- .../example/example_witness_complex_off.cpp | 6 +++--- .../example_witness_complex_persistence.cpp | 12 +++++++---- .../include/gudhi/Active_witness/Active_witness.h | 3 +++ .../gudhi/Active_witness/Active_witness_iterator.h | 7 +++++++ .../include/gudhi/Strong_witness_complex.h | 23 ++++++++++++++-------- .../include/gudhi/Witness_complex.h | 23 +++++++++++++--------- 7 files changed, 57 insertions(+), 27 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_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 bf6b4011..4e06867d 100644 --- a/src/Witness_complex/example/example_strong_witness_persistence.cpp +++ b/src/Witness_complex/example/example_strong_witness_persistence.cpp @@ -53,17 +53,18 @@ void program_options(int argc, char * argv[] , std::string & filediag , Filtration_value & max_squared_alpha , int & p + , int & dim_max , Filtration_value & min_persistence); int main(int argc, char * argv[]) { std::string file_name; std::string filediag; Filtration_value max_squared_alpha; - int p, nbL; + int p, nbL, lim_d; Filtration_value min_persistence; SimplexTree simplex_tree; - program_options(argc, argv, nbL, file_name, filediag, max_squared_alpha, p, min_persistence); + program_options(argc, argv, nbL, file_name, filediag, max_squared_alpha, p, lim_d, min_persistence); // Extract the points from the file file_name Point_vector witnesses, landmarks; @@ -119,6 +120,7 @@ void program_options(int argc, char * argv[] , std::string & filediag , Filtration_value & max_squared_alpha , int & p + , int & dim_max , Filtration_value & min_persistence) { namespace po = boost::program_options; @@ -141,7 +143,9 @@ void program_options(int argc, char * argv[] ("field-charac,p", po::value(&p)->default_value(11), "Characteristic p of the coefficient field Z/pZ for computing homology.") ("min-persistence,m", po::value(&min_persistence)->default_value(0), - "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); + "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 strong witness complex we want to compute."); po::positional_options_description pos; pos.add("input-file", 1); diff --git a/src/Witness_complex/example/example_witness_complex_off.cpp b/src/Witness_complex/example/example_witness_complex_off.cpp index 849a0a40..37646faf 100644 --- a/src/Witness_complex/example/example_witness_complex_off.cpp +++ b/src/Witness_complex/example/example_witness_complex_off.cpp @@ -45,12 +45,12 @@ typedef std::vector< Point_d > Point_vector; int main(int argc, char * const argv[]) { if (argc != 4) { std::cerr << "Usage: " << argv[0] - << " path_to_point_file nbL alpha^2\n"; + << " path_to_point_file number_of_landmarks max_squared_alpha limit_dimension\n"; return 0; } std::string file_name = argv[1]; - int nbL = atoi(argv[2]); + int nbL = atoi(argv[2]), lim_dim = atoi(argv[4]); double alpha2 = atof(argv[3]); clock_t start, end; Gudhi::Simplex_tree<> simplex_tree; @@ -77,7 +77,7 @@ int main(int argc, char * const argv[]) { point_vector.begin(), point_vector.end()); - witness_complex.create_complex(simplex_tree, alpha2); + witness_complex.create_complex(simplex_tree, alpha2, lim_dim); end = clock(); std::cout << "Witness complex took " << static_cast(end - start) / CLOCKS_PER_SEC << " s. \n"; diff --git a/src/Witness_complex/example/example_witness_complex_persistence.cpp b/src/Witness_complex/example/example_witness_complex_persistence.cpp index 9b06b504..a4388047 100644 --- a/src/Witness_complex/example/example_witness_complex_persistence.cpp +++ b/src/Witness_complex/example/example_witness_complex_persistence.cpp @@ -53,17 +53,18 @@ void program_options(int argc, char * argv[] , std::string & filediag , Filtration_value & max_squared_alpha , int & p + , int & dim_max , Filtration_value & min_persistence); int main(int argc, char * argv[]) { std::string file_name; std::string filediag; Filtration_value max_squared_alpha; - int p, nbL; + int p, nbL, lim_d; Filtration_value min_persistence; SimplexTree simplex_tree; - program_options(argc, argv, nbL, file_name, filediag, max_squared_alpha, p, min_persistence); + program_options(argc, argv, nbL, file_name, filediag, max_squared_alpha, p, lim_d, min_persistence); // Extract the points from the file file_name Point_vector witnesses, landmarks; @@ -119,6 +120,7 @@ void program_options(int argc, char * argv[] , std::string & filediag , Filtration_value & max_squared_alpha , int & p + , int & dim_max , Filtration_value & min_persistence) { namespace po = boost::program_options; @@ -141,8 +143,10 @@ void program_options(int argc, char * argv[] ("field-charac,p", po::value(&p)->default_value(11), "Characteristic p of the coefficient field Z/pZ for computing homology.") ("min-persistence,m", po::value(&min_persistence)->default_value(0), - "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); - + "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); diff --git a/src/Witness_complex/include/gudhi/Active_witness/Active_witness.h b/src/Witness_complex/include/gudhi/Active_witness/Active_witness.h index 9ae41a69..e52410e4 100644 --- a/src/Witness_complex/include/gudhi/Active_witness/Active_witness.h +++ b/src/Witness_complex/include/gudhi/Active_witness/Active_witness.h @@ -31,6 +31,9 @@ namespace Gudhi { namespace witness_complex { + /** \brief Class representing a list of nearest neighbors to a given witness. + * \detail Every element is a pair of a landmark identifier and the squared distance to it. + */ template< typename Id_distance_pair, typename INS_range > class Active_witness { 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 5d4f3d75..9c96f7e8 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 @@ -31,6 +31,13 @@ namespace Gudhi { namespace witness_complex { + /** \brief Iterator in the nearest landmark list. + * \detail After the iterator reaches the end of the list, + * the list is augmented by a (nearest landmark, distance) pair if possible. + * 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 > diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index 3a862d71..e125d307 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -138,19 +138,26 @@ private: /** \brief Outputs the (weak) witness complex with * squared relaxation parameter 'max_alpha_square' * to simplicial complex 'complex'. + * The parameter '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) + FT max_alpha_square, + Landmark_id limit_dimension = std::numeric_limits::max()) { - unsigned nbL = landmarks_.size(); - unsigned complex_dim = 0; + std::size_t nbL = landmarks_.size(); + Landmark_id complex_dim = 0; if (complex.num_vertices() > 0) { - std::cerr << "Witness complex cannot create complex - complex is not empty.\n"; + std::cerr << "Strong witness complex cannot create complex - complex is not empty.\n"; return false; } if (max_alpha_square < 0) { - std::cerr << "Witness complex cannot create complex - squared relaxation parameter must be non-negative.\n"; + std::cerr << "Strong witness complex cannot create complex - squared relaxation parameter must be non-negative.\n"; + return false; + } + if (limit_dimension < 0) { + std::cerr << "Strong witness complex cannot create complex - limit dimension must be non-negative.\n"; return false; } typeVectorVertex vv; @@ -165,13 +172,13 @@ private: ActiveWitness aw(landmark_tree_.query_incremental_nearest_neighbors(w)); typeVectorVertex simplex; typename ActiveWitness::iterator aw_it = aw.begin(); - float lim_d2 = aw.begin()->second + max_alpha_square; - while (aw_it != aw.end() && aw_it->second < lim_d2) { + 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++; } - if (simplex.size() - 1 > complex_dim) + if ((Landmark_id)simplex.size() - 1 > complex_dim) complex_dim = simplex.size() - 1; } complex.set_dimension(complex_dim); diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index 7d8fce86..2a89306d 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -129,7 +129,8 @@ private: */ template < typename SimplicialComplexForWitness > bool create_complex(SimplicialComplexForWitness& complex, - FT max_alpha_square) + FT max_alpha_square, + Landmark_id limit_dimension = std::numeric_limits::max()) { std::size_t nbL = landmarks_.size(); if (complex.num_vertices() > 0) { @@ -140,6 +141,10 @@ private: std::cerr << "Witness complex cannot create complex - squared relaxation parameter must be non-negative.\n"; return false; } + if (limit_dimension < 0) { + std::cerr << "Witness complex cannot create complex - limit dimension must be non-negative.\n"; + return false; + } typeVectorVertex vv; ActiveWitnessList active_witnesses;// = new ActiveWitnessList(); for (unsigned i = 0; i != nbL; ++i) { @@ -150,13 +155,13 @@ private: complex.insert_simplex(vv, Filtration_value(0.0)); /* TODO Error if not inserted : normally no need here though*/ } - unsigned k = 1; /* current dimension in iterative construction */ + Landmark_id k = 1; /* 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 < nbL ) { + while (!active_witnesses.empty() && k <= limit_dimension ) { typename ActiveWitnessList::iterator aw_it = active_witnesses.begin(); - std::vector simplex; + std::vector simplex; simplex.reserve(k+1); while (aw_it != active_witnesses.end()) { bool ok = add_all_faces_of_dimension(k, @@ -191,7 +196,7 @@ private: double alpha2, double norelax_dist2, typename ActiveWitness::iterator curr_l, - std::vector& simplex, + std::vector& simplex, SimplicialComplexForWitness& sc, typename ActiveWitness::iterator end) { @@ -251,17 +256,17 @@ private: * inserted_vertex is the handle of the (k+1)-th vertex witnessed by witness_id */ template < typename SimplicialComplexForWitness > - bool all_faces_in(std::vector& simplex, + bool all_faces_in(typeVectorVertex& simplex, double* filtration_value, SimplicialComplexForWitness& sc) { typedef typename SimplicialComplexForWitness::Simplex_handle Simplex_handle; - std::vector< int > facet; - for (std::vector::iterator not_it = simplex.begin(); not_it != simplex.end(); ++not_it) + typeVectorVertex facet; + for (typename typeVectorVertex::iterator not_it = simplex.begin(); not_it != simplex.end(); ++not_it) { facet.clear(); - for (std::vector::iterator it = simplex.begin(); it != simplex.end(); ++it) + for (typename typeVectorVertex::iterator it = simplex.begin(); it != simplex.end(); ++it) if (it != not_it) facet.push_back(*it); Simplex_handle facet_sh = sc.find(facet); -- cgit v1.2.3 From 78f1193dc1d9b5e03a2e4725f7b2fddda333b7ae Mon Sep 17 00:00:00 2001 From: skachano Date: Fri, 7 Oct 2016 10:29:09 +0000 Subject: Documented member functions git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1677 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 7946666e5b994a9c76c1d7dc8e9bcdb4526afddf --- .../include/gudhi/Strong_witness_complex.h | 48 ++-------------------- .../include/gudhi/Witness_complex.h | 32 +++------------ 2 files changed, 8 insertions(+), 72 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index e125d307..1ce050ad 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -23,42 +23,14 @@ #ifndef STRONG_WITNESS_COMPLEX_H_ #define STRONG_WITNESS_COMPLEX_H_ -#include -#include -#include #include #include #include -#include -#include #include -#include -#include -#include #include "Active_witness/Active_witness.h" -#include #include - -// Needed for nearest neighbours -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -// Needed for the adjacency graph in bad link search -#include -#include -#include - namespace gss = Gudhi::spatial_searching; namespace Gudhi { @@ -102,21 +74,9 @@ private: //@{ - // Witness_range> - /* - * \brief Iterative construction of the (weak) witness complex. - * \details The witness complex is written in sc_ basing on a matrix knn of - * nearest neighbours of the form {witnesses}x{landmarks}. - * - * The type KNearestNeighbors can be seen as - * Witness_range>, where - * Witness_range and Closest_landmark_range are random access ranges. - * - * Constructor takes into account at most (dim+1) - * first landmarks from each landmark range to construct simplices. - * - * Landmarks are supposed to be in [0,nbL_-1] + * \brief Initializes member variables before constructing simplicial complex. + * \details The parameters should satisfy InputIterator C++ concepts. */ template< typename InputIteratorLandmarks, typename InputIteratorWitnesses > @@ -135,7 +95,7 @@ private: return landmarks_[vertex]; } - /** \brief Outputs the (weak) witness complex with + /** \brief Outputs the (strong) witness complex with * squared relaxation parameter 'max_alpha_square' * to simplicial complex 'complex'. * The parameter 'limit_dimension' represents the maximal dimension of the simplicial complex @@ -161,12 +121,10 @@ private: return false; } typeVectorVertex vv; - //ActiveWitnessList active_witnesses;// = new ActiveWitnessList(); for (unsigned i = 0; i != nbL; ++i) { // initial fill of 0-dimensional simplices vv = {i}; complex.insert_simplex(vv, Filtration_value(0.0)); - /* TODO Error if not inserted : normally no need here though*/ } for (auto w: witnesses_) { ActiveWitness aw(landmark_tree_.query_incremental_nearest_neighbors(w)); diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index 2a89306d..7b46e1c0 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -23,25 +23,13 @@ #ifndef WITNESS_COMPLEX_H_ #define WITNESS_COMPLEX_H_ -// Needed for the adjacency graph in bad link search -#include -#include -#include - -#include - #include "Active_witness/Active_witness.h" #include -#include #include #include #include -#include -#include #include -#include -#include namespace gss = Gudhi::spatial_searching; @@ -93,18 +81,8 @@ private: //@{ /* - * \brief Iterative construction of the (weak) witness complex. - * \details The witness complex is written in sc_ basing on a matrix knn of - * nearest neighbours of the form {witnesses}x{landmarks}. - * - * The type KNearestNeighbors can be seen as - * Witness_range>, where - * Witness_range and Closest_landmark_range are random access ranges. - * - * Constructor takes into account at most (dim+1) - * first landmarks from each landmark range to construct simplices. - * - * Landmarks are supposed to be in [0,nbL_-1] + * \brief Initializes member variables before constructing simplicial complex. + * \details The parameters should satisfy InputIterator C++ concepts. */ template< typename InputIteratorLandmarks, typename InputIteratorWitnesses > @@ -126,6 +104,8 @@ private: /** \brief Outputs the (weak) witness complex with * squared relaxation parameter 'max_alpha_square' * to simplicial complex 'complex'. + * The parameter 'limit_dimension' represents the maximal dimension of the simplicial complex + * (default value = no limit). */ template < typename SimplicialComplexForWitness > bool create_complex(SimplicialComplexForWitness& complex, @@ -146,14 +126,12 @@ private: return false; } typeVectorVertex vv; - ActiveWitnessList active_witnesses;// = new ActiveWitnessList(); + ActiveWitnessList active_witnesses; for (unsigned i = 0; i != nbL; ++i) { // initial fill of 0-dimensional simplices // by doing it we don't assume that landmarks are necessarily witnesses themselves anymore - //counter++; vv = {i}; complex.insert_simplex(vv, Filtration_value(0.0)); - /* TODO Error if not inserted : normally no need here though*/ } Landmark_id k = 1; /* current dimension in iterative construction */ for (auto w: witnesses_) -- cgit v1.2.3 From 309d5aa575735acefabc33abade72637c52fb931 Mon Sep 17 00:00:00 2001 From: skachano Date: Fri, 7 Oct 2016 16:08:41 +0000 Subject: Added a big chunk of documentation. +small fixes git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1679 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: d3166034bf662121bc21583bb027c67f736e904c --- biblio/bibliography.bib | 7 ++++ .../concept/Simplicial_complex_for_witness.h | 2 +- src/Witness_complex/doc/Witness_complex_doc.h | 46 ++++++++++++++++------ .../include/gudhi/Active_witness/Active_witness.h | 7 ++-- .../gudhi/Active_witness/Active_witness_iterator.h | 12 +++--- .../include/gudhi/Strong_witness_complex.h | 40 +++++++++++++++---- .../include/gudhi/Witness_complex.h | 46 +++++++++++++++------- 7 files changed, 116 insertions(+), 44 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/biblio/bibliography.bib b/biblio/bibliography.bib index 9fc01a5d..a994ebef 100644 --- a/biblio/bibliography.bib +++ b/biblio/bibliography.bib @@ -954,3 +954,10 @@ pages={91-106}, language={English} } +@article{de2004topological, + title={Topological estimation using witness complexes}, + author={De Silva, Vin and Carlsson, Gunnar}, + journal={Proc. Sympos. Point-Based Graphics}, + pages={157--166}, + year={2004} +} \ No newline at end of file diff --git a/src/Witness_complex/concept/Simplicial_complex_for_witness.h b/src/Witness_complex/concept/Simplicial_complex_for_witness.h index caaf0db6..b47de809 100644 --- a/src/Witness_complex/concept/Simplicial_complex_for_witness.h +++ b/src/Witness_complex/concept/Simplicial_complex_for_witness.h @@ -29,7 +29,7 @@ namespace witness_complex { /** \brief The concept Simplicial_Complex describes the requirements * for a type to implement a simplicial complex, - * used for example to build a 'Witness_complex'. + * used for example to build a Witness_complex. */ struct SimplicialComplexForWitness { /** Handle to specify a simplex. */ diff --git a/src/Witness_complex/doc/Witness_complex_doc.h b/src/Witness_complex/doc/Witness_complex_doc.h index 60dfd27b..1d6e9da2 100644 --- a/src/Witness_complex/doc/Witness_complex_doc.h +++ b/src/Witness_complex/doc/Witness_complex_doc.h @@ -6,33 +6,55 @@ \author Siargey Kachanovich - \image html "Witness_complex_representation.png" "Witness complex representation" + \image html "Witness_complex_representation.png" "Witness complex representation in a Simplex tree (from \cite boissonnatmariasimplextreealgorithmica)" \section Definitions - Witness complex \f$ Wit(W,L) \f$ is a simplicial complex defined on two sets of points in \f$\mathbb{R}^D\f$: + Witness complex is a simplicial complex defined on two sets of points in \f$\mathbb{R}^D\f$: \li \f$W\f$ set of **witnesses** and - \li \f$L \subseteq W\f$ set of **landmarks**. + \li \f$L\f$ set of **landmarks**. + + Even though often the set of landmarks \f$L\f$ is a subset of the set of witnesses \f$ W\f$, it is not a requirement for the current implementation. The simplices are based on landmarks - and a simplex belongs to the witness complex if and only if it is witnessed, that is: + and witnesses help to decide on which simplices are inserted via a predicate "is witnessed". + + De Silva and Carlsson in their paper \cite de2004topological differentiate **weak witnessing** and **strong witnessing**: + + - *weak*: \f$ \sigma \subset L \f$ is witnessed by \f$ w \in W\f$ if \f$ \forall l \in \sigma,\ \forall l' \in L \setminus \sigma,\ d(w,l) \leq d(w,l') \f$ + - *strong*: \f$ \sigma \subset L \f$ is witnessed by \f$ w \in W\f$ if \f$ \forall l \in \sigma,\ \forall l' \in L,\ d(w,l) \leq d(w,l') \f$ + + where \f$ d(.,.) \f$ is a distance function. + + Both definitions can be relaxed by a real value \f$\alpha\f$: + + - *weak*: \f$ \sigma \subset L \f$ is \f$\alpha\f$-witnessed by \f$ w \in W\f$ if \f$ \forall l \in \sigma,\ \forall l' \in L \setminus \sigma,\ d(w,l)^2 \leq d(w,l')^2 + \alpha^2 \f$ + - *strong*: \f$ \sigma \subset L \f$ is \f$\alpha\f$-witnessed by \f$ w \in W\f$ if \f$ \forall l \in \sigma,\ \forall l' \in L,\ d(w,l)^2 \leq d(w,l')^2 + \alpha^2 \f$ - \f$ \sigma \subset L \f$ is witnessed if there exists a point \f$w \in W\f$ such that - w is closer to the vertices of \f$ \sigma \f$ than other points in \f$ L \f$ and all of its faces are witnessed as well. - - The data structure is described in \cite boissonnatmariasimplextreealgorithmica . + which leads to definitions of **weak relaxed witness complex** (or just relaxed witness complex for short) and **strong relaxed witness complex** respectively. \section Implementation + + The two complexes described above are implemented in the corresponding classes + - Gudhi::witness_complex::Witness_complex + - Gudhi::witness_complex::Strong_witness_complex + + The construction of both of them follow the same scheme: + 1. Construct a search tree on landmarks (for that Gudhi::spatial_searching::Kd_tree_search is used internally). + 2. Construct lists of nearest landmarks for each witness (special internal structure Gudhi::spatial_searching::Active_witness is used internally). + 3. Construct the witness complex for nearest landmark lists. + + The constructors take on the step 1, while the function 'create_complex' executes the steps 2 and 3. - The principal class of this module is Gudhi::Witness_complex. + \section Examples - In both cases, the constructor for this class takes a {witness}x{closest_landmarks} table, where each row represents a witness and consists of landmarks sorted by distance to this witness. - This table can be constructed by two additional classes Landmark_choice_by_furthest_point and Landmark_choice_by_random_point also included in the module. + Here is an example of constructing a strong witness complex filtration and computing persistence on it: + + \include Witness_complex/example_strong_witness_persistence.cpp *\image html "bench_Cy8.png" "Running time as function on number of landmarks" width=10cm *\image html "bench_sphere.png" "Running time as function on number of witnesses for |L|=300" width=10cm - \copyright GNU General Public License v3. diff --git a/src/Witness_complex/include/gudhi/Active_witness/Active_witness.h b/src/Witness_complex/include/gudhi/Active_witness/Active_witness.h index e52410e4..2ca76767 100644 --- a/src/Witness_complex/include/gudhi/Active_witness/Active_witness.h +++ b/src/Witness_complex/include/gudhi/Active_witness/Active_witness.h @@ -31,9 +31,10 @@ namespace Gudhi { namespace witness_complex { - /** \brief Class representing a list of nearest neighbors to a given witness. - * \detail Every element is a pair of a landmark identifier and the squared distance to it. - */ + // /** \class Active_witness + // * \brief Class representing a list of nearest neighbors to a given witness. + // * \details Every element is a pair of a landmark identifier and the squared distance to it. + // */ template< typename Id_distance_pair, typename INS_range > class Active_witness { 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 9c96f7e8..38c7adb2 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 @@ -31,12 +31,12 @@ namespace Gudhi { namespace witness_complex { - /** \brief Iterator in the nearest landmark list. - * \detail After the iterator reaches the end of the list, - * the list is augmented by a (nearest landmark, distance) pair if possible. - * If all the landmarks are present in the list, iterator returns the specific end value - * of the corresponding 'Active_witness' object. - */ + // /** \brief Iterator in the nearest landmark list. + // * \details After the iterator reaches the end of the list, + // * the list is augmented by a (nearest landmark, distance) pair if possible. + // * 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, diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index 1ce050ad..e64f8f20 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -37,6 +37,22 @@ namespace Gudhi { namespace witness_complex { +/** + * \private + * \class Strong_witness_complex + * \brief Constructs strong witness complex for the given sets of witnesses and landmarks. + * \ingroup witness_complex + * + * \tparam Kernel_ requires a CGAL::Epick_d class, which + * can be static if you know the ambiant dimension at compile-time, or dynamic if you don't. + * \tparam DimensionTag can be either Dimension_tag + * if you know the intrinsic dimension at compile-time, + * or CGAL::Dynamic_dimension_tag + * if you don't. + */ template< class Kernel_ > class Strong_witness_complex { private: @@ -55,7 +71,7 @@ private: typedef FT Filtration_value; - typedef std::ptrdiff_t Witness_id; + 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; @@ -63,6 +79,8 @@ private: typedef std::vector< Landmark_id > typeVectorVertex; typedef std::pair< typeVectorVertex, Filtration_value> typeSimplex; + typedef Landmark_id Vertex_handle; + private: Point_range witnesses_, landmarks_; Kd_tree landmark_tree_; @@ -74,9 +92,13 @@ private: //@{ - /* + /** * \brief Initializes member variables before constructing simplicial complex. - * \details The parameters should satisfy InputIterator C++ concepts. + * \details Records landmarks from the range [landmarks_first, landmarks_last) into a + * table internally, as well as witnesses from the range [witnesses_first, witnesses_last). + * All iterator parameters should satisfy InputIterator + * C++ concept. */ template< typename InputIteratorLandmarks, typename InputIteratorWitnesses > @@ -90,15 +112,17 @@ private: /** \brief Returns the point corresponding to the given vertex. */ - Point_d get_point( std::size_t vertex ) const + template + Point_d get_point( Vertex_handle vertex ) const { return landmarks_[vertex]; } - /** \brief Outputs the (strong) witness complex with - * squared relaxation parameter 'max_alpha_square' - * to simplicial complex 'complex'. - * The parameter 'limit_dimension' represents the maximal dimension of the simplicial complex + /** \brief Outputs the strong witness complex in a simplicial complex data structure. + * @param[out] complex Simplicial complex data structure compatible with 'find' and 'insert' operations. + * (Cf SimplicialComplexForWitness) + * @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 > diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index 7b46e1c0..6a944c43 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -37,12 +37,22 @@ namespace Gudhi { namespace witness_complex { -// /* -// * \private -// \class Witness_complex -// \brief Constructs the witness complex for the given set of witnesses and landmarks. -// \ingroup witness_complex -// */ +/** + * \private + * \class Witness_complex + * \brief Constructs (weak) witness complex for the given sets of witnesses and landmarks. + * \ingroup witness_complex + * + * \tparam Kernel_ requires a CGAL::Epick_d class, which + * can be static if you know the ambiant dimension at compile-time, or dynamic if you don't. + * \tparam DimensionTag can be either Dimension_tag + * if you know the intrinsic dimension at compile-time, + * or CGAL::Dynamic_dimension_tag + * if you don't. +*/ template< class Kernel_ > class Witness_complex { private: @@ -69,6 +79,8 @@ private: typedef std::vector< Landmark_id > typeVectorVertex; typedef std::pair< typeVectorVertex, Filtration_value> typeSimplex; + typedef Landmark_id Vertex_handle; + private: Point_range witnesses_, landmarks_; Kd_tree landmark_tree_; @@ -80,9 +92,13 @@ private: //@{ - /* + /** * \brief Initializes member variables before constructing simplicial complex. - * \details The parameters should satisfy InputIterator C++ concepts. + * \details Records landmarks from the range [landmarks_first, landmarks_last) into a + * table internally, as well as witnesses from the range [witnesses_first, witnesses_last). + * All iterator parameters should satisfy InputIterator + * C++ concept. */ template< typename InputIteratorLandmarks, typename InputIteratorWitnesses > @@ -95,16 +111,18 @@ private: } /** \brief Returns the point corresponding to the given vertex. + * @param[in] vertex Vertex handle of the point to retrieve. */ - Point_d get_point( std::size_t vertex ) const + Point_d get_point( Vertex_handle vertex ) const { return landmarks_[vertex]; } - /** \brief Outputs the (weak) witness complex with - * squared relaxation parameter 'max_alpha_square' - * to simplicial complex 'complex'. - * The parameter 'limit_dimension' represents the maximal dimension of the simplicial complex + /** \brief Outputs the (weak) witness complex in a simplicial complex data structure. + * @param[out] complex Simplicial complex data structure compatible with 'find' and 'insert' operations. + * (Cf SimplicialComplexForWitness) + * @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 > @@ -229,7 +247,7 @@ private: return will_be_active; } - /** \brief Check if the facets of the k-dimensional simplex witnessed + /* \brief Check if the facets of the k-dimensional simplex witnessed * by witness witness_id are already in the complex. * inserted_vertex is the handle of the (k+1)-th vertex witnessed by witness_id */ -- cgit v1.2.3 From d6c9231c55b273f50b870ce85c5fafefd4fe3cf6 Mon Sep 17 00:00:00 2001 From: skachano Date: Mon, 10 Oct 2016 15:20:40 +0000 Subject: Fixed the numerical_limits::max + 1 bug git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1685 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 31f100f0a7a56a81cc920768e07ecb001e6e1b26 --- src/Witness_complex/include/gudhi/Strong_witness_complex.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index e64f8f20..aa313c40 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -128,7 +128,7 @@ private: template < typename SimplicialComplexForWitness > bool create_complex(SimplicialComplexForWitness& complex, FT max_alpha_square, - Landmark_id limit_dimension = std::numeric_limits::max()) + Landmark_id limit_dimension = std::numeric_limits::max()-1) { std::size_t nbL = landmarks_.size(); Landmark_id complex_dim = 0; -- cgit v1.2.3 From fede2d266f2bc84f2c006240cc0a82a68c9069be Mon Sep 17 00:00:00 2001 From: skachano Date: Tue, 18 Oct 2016 12:21:53 +0000 Subject: Changed Active_witness includes git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1729 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 59d4ef32b8544ab16b61f367e17f641bb03fc33f --- src/Witness_complex/include/gudhi/Strong_witness_complex.h | 2 +- src/Witness_complex/include/gudhi/Witness_complex.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index aa313c40..73de580d 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -28,7 +28,7 @@ #include #include -#include "Active_witness/Active_witness.h" +#include #include namespace gss = Gudhi::spatial_searching; diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index 6a944c43..e336dc4f 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -23,7 +23,7 @@ #ifndef WITNESS_COMPLEX_H_ #define WITNESS_COMPLEX_H_ -#include "Active_witness/Active_witness.h" +#include #include #include -- cgit v1.2.3 From 4473c9fd8d23097ed7b5570b800db245539e91d2 Mon Sep 17 00:00:00 2001 From: skachano Date: Tue, 18 Oct 2016 12:32:40 +0000 Subject: Removed Sophia Antipolis from copyrights git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1731 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: f97758e943397259712ad76c4db117df3d3415b6 --- src/Witness_complex/example/example_strong_witness_persistence.cpp | 2 +- src/Witness_complex/example/example_witness_complex_off.cpp | 2 +- src/Witness_complex/example/example_witness_complex_persistence.cpp | 2 +- src/Witness_complex/example/example_witness_complex_sphere.cpp | 2 +- src/Witness_complex/include/gudhi/Active_witness/Active_witness.h | 2 +- .../include/gudhi/Active_witness/Active_witness_iterator.h | 2 +- src/Witness_complex/include/gudhi/Strong_witness_complex.h | 2 +- src/Witness_complex/include/gudhi/Witness_complex.h | 2 +- src/Witness_complex/test/test_simple_witness_complex.cpp | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_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 4e06867d..f43cba52 100644 --- a/src/Witness_complex/example/example_strong_witness_persistence.cpp +++ b/src/Witness_complex/example/example_strong_witness_persistence.cpp @@ -4,7 +4,7 @@ * * Author(s): Siargey Kachanovich * - * Copyright (C) 2016 INRIA Sophia Antipolis-Méditerranée (France) + * Copyright (C) 2016 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 diff --git a/src/Witness_complex/example/example_witness_complex_off.cpp b/src/Witness_complex/example/example_witness_complex_off.cpp index 37646faf..94088370 100644 --- a/src/Witness_complex/example/example_witness_complex_off.cpp +++ b/src/Witness_complex/example/example_witness_complex_off.cpp @@ -4,7 +4,7 @@ * * Author(s): Siargey Kachanovich * - * Copyright (C) 2015 INRIA Sophia Antipolis-Méditerranée (France) + * 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 diff --git a/src/Witness_complex/example/example_witness_complex_persistence.cpp b/src/Witness_complex/example/example_witness_complex_persistence.cpp index a4388047..b1b415fa 100644 --- a/src/Witness_complex/example/example_witness_complex_persistence.cpp +++ b/src/Witness_complex/example/example_witness_complex_persistence.cpp @@ -4,7 +4,7 @@ * * Author(s): Siargey Kachanovich * - * Copyright (C) 2016 INRIA Sophia Antipolis-Méditerranée (France) + * Copyright (C) 2016 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 diff --git a/src/Witness_complex/example/example_witness_complex_sphere.cpp b/src/Witness_complex/example/example_witness_complex_sphere.cpp index 8e2c5ff6..d21195fa 100644 --- a/src/Witness_complex/example/example_witness_complex_sphere.cpp +++ b/src/Witness_complex/example/example_witness_complex_sphere.cpp @@ -4,7 +4,7 @@ * * Author(s): Siargey Kachanovich * - * Copyright (C) 2015 INRIA Sophia Antipolis-Méditerranée (France) + * 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 diff --git a/src/Witness_complex/include/gudhi/Active_witness/Active_witness.h b/src/Witness_complex/include/gudhi/Active_witness/Active_witness.h index c6113442..fce7d3d1 100644 --- a/src/Witness_complex/include/gudhi/Active_witness/Active_witness.h +++ b/src/Witness_complex/include/gudhi/Active_witness/Active_witness.h @@ -4,7 +4,7 @@ * * Author(s): Siargey Kachanovich * - * Copyright (C) 2016 INRIA Sophia Antipolis-Méditerranée (France) + * Copyright (C) 2016 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 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 25897de6..ae051bea 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 @@ -4,7 +4,7 @@ * * Author(s): Siargey Kachanovich * - * Copyright (C) 2016 INRIA Sophia Antipolis-Méditerranée (France) + * Copyright (C) 2016 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 diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index 73de580d..7ef8d3e5 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -4,7 +4,7 @@ * * Author(s): Siargey Kachanovich * - * Copyright (C) 2015 INRIA Sophia Antipolis-Méditerranée (France) + * 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 diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index e336dc4f..ac0e8f66 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -4,7 +4,7 @@ * * Author(s): Siargey Kachanovich * - * Copyright (C) 2015 INRIA Sophia Antipolis-Méditerranée (France) + * 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 diff --git a/src/Witness_complex/test/test_simple_witness_complex.cpp b/src/Witness_complex/test/test_simple_witness_complex.cpp index 759ee14d..90b6cfa2 100644 --- a/src/Witness_complex/test/test_simple_witness_complex.cpp +++ b/src/Witness_complex/test/test_simple_witness_complex.cpp @@ -4,7 +4,7 @@ * * Author(s): Siargey Kachanovich * - * Copyright (C) 2016 INRIA Sophia Antipolis-Méditerranée (France) + * Copyright (C) 2016 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 -- cgit v1.2.3 From fe79f2dcfd8b1540485d8a81fa7cedd07f5c8fac Mon Sep 17 00:00:00 2001 From: skachano Date: Wed, 19 Oct 2016 08:19:49 +0000 Subject: Clément's remarks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1735 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: c3bc66a081a0bc73874246e1e12ab98c6bf2a53e --- src/Witness_complex/doc/Witness_complex_doc.h | 10 +++++-- .../example/example_strong_witness_persistence.cpp | 28 ++---------------- .../example/example_witness_complex_off.cpp | 28 ++---------------- .../example_witness_complex_persistence.cpp | 28 ++---------------- .../example/example_witness_complex_sphere.cpp | 27 ++--------------- .../include/gudhi/Strong_witness_complex.h | 27 ++++++++--------- .../include/gudhi/Witness_complex.h | 32 +++++++------------- .../test/test_simple_witness_complex.cpp | 34 +++------------------- 8 files changed, 43 insertions(+), 171 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/doc/Witness_complex_doc.h b/src/Witness_complex/doc/Witness_complex_doc.h index 4f3671e5..2831f107 100644 --- a/src/Witness_complex/doc/Witness_complex_doc.h +++ b/src/Witness_complex/doc/Witness_complex_doc.h @@ -17,7 +17,7 @@ Even though often the set of landmarks \f$L\f$ is a subset of the set of witnesses \f$ W\f$, it is not a requirement for the current implementation. - The simplices are based on landmarks + Landmarks are the vertices of the simplicial complex and witnesses help to decide on which simplices are inserted via a predicate "is witnessed". De Silva and Carlsson in their paper \cite de2004topological differentiate **weak witnessing** and **strong witnessing**: @@ -47,7 +47,13 @@ The constructors take on the step 1, while the function 'create_complex' executes the steps 2 and 3. - \section witnessexamples Examples + \section witnessexample1 Example 1: Constructing weak relaxed witness complex from an off file + + Let's start with a simple example, which reads an off point file and computes a weak witness complex. + + \include Witness_complex/example_witness_complex_off.cpp + + \section witnessexample2 Example2: Computing persistence using strong relaxed witness complex Here is an example of constructing a strong witness complex filtration and computing persistence on it: diff --git a/src/Witness_complex/example/example_strong_witness_persistence.cpp b/src/Witness_complex/example/example_strong_witness_persistence.cpp index f43cba52..a0563ee2 100644 --- a/src/Witness_complex/example/example_strong_witness_persistence.cpp +++ b/src/Witness_complex/example/example_strong_witness_persistence.cpp @@ -1,25 +1,3 @@ -/* 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) 2016 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 . - */ - #include #include #include @@ -81,10 +59,8 @@ int main(int argc, char * argv[]) { Gudhi::subsampling::pick_n_random_points(witnesses, nbL, std::back_inserter(landmarks)); // Compute witness complex - Strong_witness_complex strong_witness_complex(landmarks.begin(), - landmarks.end(), - witnesses.begin(), - witnesses.end()); + Strong_witness_complex strong_witness_complex(landmarks, + witnesses); strong_witness_complex.create_complex(simplex_tree, max_squared_alpha); diff --git a/src/Witness_complex/example/example_witness_complex_off.cpp b/src/Witness_complex/example/example_witness_complex_off.cpp index 94088370..2677499a 100644 --- a/src/Witness_complex/example/example_witness_complex_off.cpp +++ b/src/Witness_complex/example/example_witness_complex_off.cpp @@ -1,25 +1,3 @@ -/* 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 . - */ - #include #include @@ -72,10 +50,8 @@ int main(int argc, char * const argv[]) { // Compute witness complex start = clock(); - Witness_complex witness_complex(landmarks.begin(), - landmarks.end(), - point_vector.begin(), - point_vector.end()); + Witness_complex witness_complex(landmarks, + point_vector); witness_complex.create_complex(simplex_tree, alpha2, lim_dim); end = clock(); diff --git a/src/Witness_complex/example/example_witness_complex_persistence.cpp b/src/Witness_complex/example/example_witness_complex_persistence.cpp index b1b415fa..00f00aae 100644 --- a/src/Witness_complex/example/example_witness_complex_persistence.cpp +++ b/src/Witness_complex/example/example_witness_complex_persistence.cpp @@ -1,25 +1,3 @@ -/* 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) 2016 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 . - */ - #include #include #include @@ -81,10 +59,8 @@ int main(int argc, char * argv[]) { Gudhi::subsampling::pick_n_random_points(witnesses, nbL, std::back_inserter(landmarks)); // Compute witness complex - Witness_complex witness_complex(landmarks.begin(), - landmarks.end(), - witnesses.begin(), - witnesses.end()); + Witness_complex witness_complex(landmarks, + witnesses); witness_complex.create_complex(simplex_tree, max_squared_alpha); diff --git a/src/Witness_complex/example/example_witness_complex_sphere.cpp b/src/Witness_complex/example/example_witness_complex_sphere.cpp index d21195fa..42fb9f8d 100644 --- a/src/Witness_complex/example/example_witness_complex_sphere.cpp +++ b/src/Witness_complex/example/example_witness_complex_sphere.cpp @@ -1,24 +1,3 @@ -/* 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 . - */ #define BOOST_PARAMETER_MAX_ARITY 12 @@ -80,10 +59,8 @@ int main(int argc, char * const argv[]) { Gudhi::subsampling::pick_n_random_points(point_vector, number_of_landmarks, std::back_inserter(landmarks)); // Compute witness complex - Witness_complex witness_complex(landmarks.begin(), - landmarks.end(), - point_vector.begin(), - point_vector.end()); + Witness_complex witness_complex(landmarks, + point_vector); witness_complex.create_complex(simplex_tree, 0); end = clock(); double time = static_cast(end - start) / CLOCKS_PER_SEC; diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index 7ef8d3e5..c7b8c27b 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -94,22 +94,18 @@ private: /** * \brief Initializes member variables before constructing simplicial complex. - * \details Records landmarks from the range [landmarks_first, landmarks_last) into a - * table internally, as well as witnesses from the range [witnesses_first, witnesses_last). - * All iterator parameters should satisfy InputIterator - * C++ concept. + * \details Records landmarks from the range 'landmarks' into a + * table internally, as well as witnesses from the range 'witnesses'. */ - template< typename InputIteratorLandmarks, - typename InputIteratorWitnesses > - Strong_witness_complex(InputIteratorLandmarks landmarks_first, - InputIteratorLandmarks landmarks_last, - InputIteratorWitnesses witnesses_first, - InputIteratorWitnesses witnesses_last) - : witnesses_(witnesses_first, witnesses_last), landmarks_(landmarks_first, landmarks_last), landmark_tree_(landmarks_) + template< typename LandmarkRange, + typename WitnessRange > + Strong_witness_complex(const LandmarkRange & landmarks, + const WitnessRange & witnesses) + : witnesses_(witnesses), landmarks_(landmarks), landmark_tree_(landmarks_) { } + /** \brief Returns the point corresponding to the given vertex. */ template @@ -118,9 +114,10 @@ private: return landmarks_[vertex]; } - /** \brief Outputs the strong witness complex in a simplicial complex data structure. - * @param[out] complex Simplicial complex data structure compatible with 'find' and 'insert' operations. - * (Cf SimplicialComplexForWitness) + /** \brief Outputs the strong witness complex of relaxation 'max_alpha_square' + * in a simplicial complex data structure. + * @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). diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index ac0e8f66..c1d402c6 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -46,12 +46,6 @@ namespace witness_complex { * \tparam Kernel_ requires a CGAL::Epick_d class, which * can be static if you know the ambiant dimension at compile-time, or dynamic if you don't. - * \tparam DimensionTag can be either Dimension_tag - * if you know the intrinsic dimension at compile-time, - * or CGAL::Dynamic_dimension_tag - * if you don't. */ template< class Kernel_ > class Witness_complex { @@ -94,19 +88,14 @@ private: /** * \brief Initializes member variables before constructing simplicial complex. - * \details Records landmarks from the range [landmarks_first, landmarks_last) into a - * table internally, as well as witnesses from the range [witnesses_first, witnesses_last). - * All iterator parameters should satisfy InputIterator - * C++ concept. + * \details Records landmarks from the range 'landmarks' into a + * table internally, as well as witnesses from the range 'witnesses'. */ - template< typename InputIteratorLandmarks, - typename InputIteratorWitnesses > - Witness_complex(InputIteratorLandmarks landmarks_first, - InputIteratorLandmarks landmarks_last, - InputIteratorWitnesses witnesses_first, - InputIteratorWitnesses witnesses_last) - : witnesses_(witnesses_first, witnesses_last), landmarks_(landmarks_first, landmarks_last), landmark_tree_(landmarks_) + template< typename LandmarkRange, + typename WitnessRange > + Witness_complex(const LandmarkRange & landmarks, + const WitnessRange & witnesses) + : witnesses_(witnesses), landmarks_(landmarks), landmark_tree_(landmarks_) { } @@ -118,9 +107,10 @@ private: return landmarks_[vertex]; } - /** \brief Outputs the (weak) witness complex in a simplicial complex data structure. - * @param[out] complex Simplicial complex data structure compatible with 'find' and 'insert' operations. - * (Cf SimplicialComplexForWitness) + /** \brief Outputs the (weak) witness complex of relaxation 'max_alpha_square' + * in a simplicial complex data structure. + * @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). diff --git a/src/Witness_complex/test/test_simple_witness_complex.cpp b/src/Witness_complex/test/test_simple_witness_complex.cpp index 90b6cfa2..a0a1b36c 100644 --- a/src/Witness_complex/test/test_simple_witness_complex.cpp +++ b/src/Witness_complex/test/test_simple_witness_complex.cpp @@ -1,25 +1,3 @@ -/* 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) 2016 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 . - */ - #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE "simple_witness_complex" #include @@ -79,10 +57,8 @@ BOOST_AUTO_TEST_CASE(simple_witness_complex) { witnesses.push_back(Point_d(std::vector{ 2,-1})); witnesses.push_back(Point_d(std::vector{ 2, 1})); - WitnessComplex witness_complex(landmarks.begin(), - landmarks.end(), - witnesses.begin(), - witnesses.end()); + WitnessComplex witness_complex(landmarks, + witnesses); witness_complex.create_complex(complex, 0); std::cout << "complex.num_simplices() = " << complex.num_simplices() << std::endl; @@ -93,10 +69,8 @@ BOOST_AUTO_TEST_CASE(simple_witness_complex) { std::cout << "relaxed_complex.num_simplices() = " << relaxed_complex.num_simplices() << std::endl; BOOST_CHECK(relaxed_complex.num_simplices() == 239); - StrongWitnessComplex strong_witness_complex(landmarks.begin(), - landmarks.end(), - witnesses.begin(), - witnesses.end()); + StrongWitnessComplex strong_witness_complex(landmarks, + witnesses); strong_witness_complex.create_complex(strong_relaxed_complex, 9.1); -- cgit v1.2.3 From 6a1455578219460b9a15c58f47520d203682f9d8 Mon Sep 17 00:00:00 2001 From: skachano Date: Tue, 6 Dec 2016 09:22:03 +0000 Subject: Fixes in doc git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1823 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 2a0b01b5662daeeb1a15366d8e5d3d9747032175 --- src/Witness_complex/include/gudhi/Strong_witness_complex.h | 2 ++ src/Witness_complex/include/gudhi/Witness_complex.h | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index c7b8c27b..03cdbcca 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -96,6 +96,7 @@ private: * \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 > @@ -116,6 +117,7 @@ private: /** \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. diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index c1d402c6..36aad7c3 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -90,6 +90,7 @@ private: * \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 > @@ -109,6 +110,7 @@ private: /** \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. @@ -172,10 +174,10 @@ private: //@} 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 + /* \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, -- cgit v1.2.3 From 0c26001efc086657ab46aeb2a1b7746f3e8bbfcf Mon Sep 17 00:00:00 2001 From: skachano Date: Fri, 16 Dec 2016 08:24:02 +0000 Subject: Attempted to fix the bug in Strong witness complex with limited dimension git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1891 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 8dbe379ae908813ccfaeced316f5d82b6cd91360 --- .../include/gudhi/Strong_witness_complex.h | 47 ++++++++++++++++++++++ .../include/gudhi/Witness_complex.h | 4 +- 2 files changed, 49 insertions(+), 2 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index 03cdbcca..3803980b 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -159,6 +159,13 @@ private: 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) { + add_all_faces_of_dimension(limD, vertices, vertices.begin(), aw_it, typeVectorVertex({}), complex); + vertices.push_back(aw_it->first); + aw_it++; + } if ((Landmark_id)simplex.size() - 1 > complex_dim) complex_dim = simplex.size() - 1; } @@ -166,6 +173,46 @@ private: 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(int dim, + std::vector& vertices, + typename typeVectorVertex::iterator curr_it, + typename ActiveWitness::iterator aw_it, + std::vector& simplex, + SimplicialComplexForWitness& sc) + { + if (dim > 0) + while (curr_it != vertices.end()) { + simplex.push_back(curr_it->first); + typename ActiveWitness::iterator next_it = curr_it++; + add_all_faces_of_dimension(dim-1, + vertices, + next_it, + aw_it, + simplex, + sc); + simplex.pop_back(); + add_all_faces_of_dimension(dim, + vertices, + next_it, + aw_it, + simplex, + sc); + } + else if (dim == 0) { + simplex.push_back(aw_it->first); + sc.insert_simplex(simplex, aw_it->second); + simplex.pop_back(); + } + } + //@} }; diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index 36aad7c3..56ea8613 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -56,8 +56,8 @@ private: typedef std::vector Point_range; typedef gss::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 typename std::vector Nearest_landmark_table; + //typedef typename Nearest_landmark_range::iterator Nearest_landmark_row_iterator; typedef std::vector< double > Point_t; typedef std::vector< Point_t > Point_Vector; -- cgit v1.2.3 From e36bb3953817d9aa3b1baaa61e51cee4099787b9 Mon Sep 17 00:00:00 2001 From: skachano Date: Fri, 16 Dec 2016 08:42:13 +0000 Subject: memory access violation: here we go again git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1892 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: fff0a693f83f8f0a0f93d2fe57640408e7b17c69 --- src/Witness_complex/include/gudhi/Strong_witness_complex.h | 13 +++++++------ src/Witness_complex/test/test_simple_witness_complex.cpp | 8 +++++--- 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index 3803980b..5f9db5a4 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -162,7 +162,8 @@ private: // 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) { - add_all_faces_of_dimension(limD, vertices, vertices.begin(), aw_it, typeVectorVertex({}), complex); + typeVectorVertex facet = {}; + add_all_faces_of_dimension(limit_dimension, vertices, vertices.begin(), aw_it, facet, complex); vertices.push_back(aw_it->first); aw_it++; } @@ -181,17 +182,17 @@ private: * The landmark pointed by aw_it is added to all formed simplices. */ template < typename SimplicialComplexForWitness > - void add_all_faces_of_dimension(int dim, - std::vector& vertices, + void add_all_faces_of_dimension(Landmark_id dim, + typeVectorVertex& vertices, typename typeVectorVertex::iterator curr_it, typename ActiveWitness::iterator aw_it, - std::vector& simplex, + typeVectorVertex& simplex, SimplicialComplexForWitness& sc) { if (dim > 0) while (curr_it != vertices.end()) { - simplex.push_back(curr_it->first); - typename ActiveWitness::iterator next_it = curr_it++; + simplex.push_back(*curr_it); + typename typeVectorVertex::iterator next_it = curr_it++; add_all_faces_of_dimension(dim-1, vertices, next_it, diff --git a/src/Witness_complex/test/test_simple_witness_complex.cpp b/src/Witness_complex/test/test_simple_witness_complex.cpp index a0a1b36c..dc7f3175 100644 --- a/src/Witness_complex/test/test_simple_witness_complex.cpp +++ b/src/Witness_complex/test/test_simple_witness_complex.cpp @@ -32,7 +32,7 @@ typedef Gudhi::witness_complex::Strong_witness_complex StrongWitnessComp */ BOOST_AUTO_TEST_CASE(simple_witness_complex) { - Simplex_tree complex, relaxed_complex, strong_relaxed_complex; + Simplex_tree complex, relaxed_complex, strong_relaxed_complex, strong_relaxed_complex2; std::vector witnesses, landmarks; @@ -73,8 +73,10 @@ BOOST_AUTO_TEST_CASE(simple_witness_complex) { witnesses); strong_witness_complex.create_complex(strong_relaxed_complex, 9.1); - + strong_witness_complex.create_complex(strong_relaxed_complex2, 9.1, 2); + std::cout << "strong_relaxed_complex.num_simplices() = " << strong_relaxed_complex.num_simplices() << std::endl; BOOST_CHECK(strong_relaxed_complex.num_simplices() == 239); - + + std::cout << "strong_relaxed_complex2.num_simplices() = " << strong_relaxed_complex2.num_simplices() << std::endl; } -- cgit v1.2.3 From 7f5d6edb13f0c15bf85552984f3f6930fb810711 Mon Sep 17 00:00:00 2001 From: skachano Date: Fri, 16 Dec 2016 16:58:38 +0000 Subject: I'm almost there... git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1908 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: a3f2a7ccf38672e51462d2ce42056d82b675d45a --- src/Witness_complex/include/gudhi/Strong_witness_complex.h | 4 ++-- src/Witness_complex/test/CMakeLists.txt | 1 + src/Witness_complex/test/test_simple_witness_complex.cpp | 8 +++++++- 3 files changed, 10 insertions(+), 3 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index 5f9db5a4..4b39704e 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -192,7 +192,7 @@ private: if (dim > 0) while (curr_it != vertices.end()) { simplex.push_back(*curr_it); - typename typeVectorVertex::iterator next_it = curr_it++; + typename typeVectorVertex::iterator next_it = ++curr_it; add_all_faces_of_dimension(dim-1, vertices, next_it, @@ -209,7 +209,7 @@ private: } else if (dim == 0) { simplex.push_back(aw_it->first); - sc.insert_simplex(simplex, aw_it->second); + sc.insert_simplex_and_subfaces(simplex, aw_it->second); simplex.pop_back(); } } diff --git a/src/Witness_complex/test/CMakeLists.txt b/src/Witness_complex/test/CMakeLists.txt index 8d68ea1f..084761e2 100644 --- a/src/Witness_complex/test/CMakeLists.txt +++ b/src/Witness_complex/test/CMakeLists.txt @@ -12,6 +12,7 @@ endif() add_executable ( Witness_complex_test_simple_witness_complex test_simple_witness_complex.cpp ) target_link_libraries(Witness_complex_test_simple_witness_complex ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) +target_link_libraries(Witness_complex_test_simple_witness_complex ${TBB_LIBRARIES}) # Unitary tests definition and xml result file generation add_test(NAME simple_witness_complex diff --git a/src/Witness_complex/test/test_simple_witness_complex.cpp b/src/Witness_complex/test/test_simple_witness_complex.cpp index dc7f3175..299c7fd6 100644 --- a/src/Witness_complex/test/test_simple_witness_complex.cpp +++ b/src/Witness_complex/test/test_simple_witness_complex.cpp @@ -68,6 +68,10 @@ BOOST_AUTO_TEST_CASE(simple_witness_complex) { std::cout << "relaxed_complex.num_simplices() = " << relaxed_complex.num_simplices() << std::endl; BOOST_CHECK(relaxed_complex.num_simplices() == 239); + // All edges but big diagonals are present. + // + // Simplex count (number:dimension): + StrongWitnessComplex strong_witness_complex(landmarks, witnesses); @@ -78,5 +82,7 @@ BOOST_AUTO_TEST_CASE(simple_witness_complex) { std::cout << "strong_relaxed_complex.num_simplices() = " << strong_relaxed_complex.num_simplices() << std::endl; BOOST_CHECK(strong_relaxed_complex.num_simplices() == 239); - std::cout << "strong_relaxed_complex2.num_simplices() = " << strong_relaxed_complex2.num_simplices() << std::endl; + std::cout << "strong_relaxed_complex2.num_simplices() = " << strong_relaxed_complex2.num_simplices() << std::endl; + BOOST_CHECK(strong_relaxed_complex2.num_simplices() == 101); + std::cout << strong_relaxed_complex2 << std::endl; } -- cgit v1.2.3 From 413f0c97bd70642a107d1479e9e8762fd24f300d Mon Sep 17 00:00:00 2001 From: skachano Date: Fri, 16 Dec 2016 17:09:07 +0000 Subject: Got filtration value right git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1911 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: fcca8ce0da982092e8ea09e40f329afa9b21989b --- src/Witness_complex/include/gudhi/Strong_witness_complex.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index 4b39704e..a3f88aae 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -163,7 +163,7 @@ private: 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, facet, complex); + 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++; } @@ -186,6 +186,7 @@ private: typeVectorVertex& vertices, typename typeVectorVertex::iterator curr_it, typename ActiveWitness::iterator aw_it, + FT filtration_value, typeVectorVertex& simplex, SimplicialComplexForWitness& sc) { @@ -197,6 +198,7 @@ private: vertices, next_it, aw_it, + filtration_value, simplex, sc); simplex.pop_back(); @@ -204,12 +206,13 @@ private: 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, aw_it->second); + sc.insert_simplex_and_subfaces(simplex, filtration_value); simplex.pop_back(); } } -- cgit v1.2.3 From be4e9ebd24f48def07f6dfec1a46791321fbaee4 Mon Sep 17 00:00:00 2001 From: skachano Date: Fri, 16 Dec 2016 17:51:58 +0000 Subject: The bug with limit dimension in Strong witness is fixed git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1912 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 2229381ca73da7ebe6a8b22d9a9a8eab70f65eb5 --- src/Witness_complex/include/gudhi/Strong_witness_complex.h | 2 +- src/Witness_complex/test/test_simple_witness_complex.cpp | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index a3f88aae..3bb39c61 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -154,7 +154,7 @@ private: 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) { + 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++; diff --git a/src/Witness_complex/test/test_simple_witness_complex.cpp b/src/Witness_complex/test/test_simple_witness_complex.cpp index 299c7fd6..aff6949e 100644 --- a/src/Witness_complex/test/test_simple_witness_complex.cpp +++ b/src/Witness_complex/test/test_simple_witness_complex.cpp @@ -68,9 +68,7 @@ BOOST_AUTO_TEST_CASE(simple_witness_complex) { std::cout << "relaxed_complex.num_simplices() = " << relaxed_complex.num_simplices() << std::endl; BOOST_CHECK(relaxed_complex.num_simplices() == 239); - // All edges but big diagonals are present. - // - // Simplex count (number:dimension): + // The corner simplex {0,2,5,7} and its cofaces are missing. StrongWitnessComplex strong_witness_complex(landmarks, @@ -83,6 +81,6 @@ BOOST_AUTO_TEST_CASE(simple_witness_complex) { BOOST_CHECK(strong_relaxed_complex.num_simplices() == 239); std::cout << "strong_relaxed_complex2.num_simplices() = " << strong_relaxed_complex2.num_simplices() << std::endl; - BOOST_CHECK(strong_relaxed_complex2.num_simplices() == 101); - std::cout << strong_relaxed_complex2 << std::endl; + BOOST_CHECK(strong_relaxed_complex2.num_simplices() == 92); + // 8 vertices, 28 edges, 56 triangles } -- cgit v1.2.3 From eed110f1e5ec3842553051a421a76dd9d47877fe Mon Sep 17 00:00:00 2001 From: skachano Date: Wed, 18 Jan 2017 10:04:19 +0000 Subject: Added a file + fixed the bug git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1945 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: a5acd7e920dfba1857ed1b71bfc1b33e5522cfc3 --- .../include/gudhi/Strong_witness_complex.h | 65 +++++----------------- .../include/gudhi/Witness_complex.h | 1 - .../test/test_simple_witness_complex.cpp | 26 +++++++-- 3 files changed, 36 insertions(+), 56 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index 3bb39c61..164d8ffe 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -53,37 +53,21 @@ namespace witness_complex { * href="http://doc.cgal.org/latest/Kernel_23/classCGAL_1_1Dynamic__dimension__tag.html">CGAL::Dynamic_dimension_tag * if you don't. */ -template< class Kernel_ > +template< class Nearest_landmark_table_ > class Strong_witness_complex { private: - typedef Kernel_ K; - typedef typename K::Point_d Point_d; - typedef typename K::FT FT; - typedef std::vector Point_range; - typedef gss::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 typename Nearest_landmark_table_::value_type Nearest_landmark_range; + typedef std::size_t Witness_id; + typedef std::size_t Landmark_id; + typedef std::pair Id_distance_pair; + typedef Active_witness ActiveWitness; + typedef std::list< ActiveWitness > ActiveWitnessList; + typedef std::vector< Landmark_id > typeVectorVertex; - typedef std::vector< double > Point_t; - typedef std::vector< Point_t > Point_Vector; - - 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_; - Kd_tree landmark_tree_; + Nearest_landmark_table_& nearest_landmark_table_; public: ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -98,22 +82,10 @@ private: * table internally, as well as witnesses from the range 'witnesses'. * Both ranges should have value_type Kernel_::Point_d. */ - template< typename LandmarkRange, - typename WitnessRange > - Strong_witness_complex(const LandmarkRange & landmarks, - const WitnessRange & witnesses) - : witnesses_(witnesses), landmarks_(landmarks), landmark_tree_(landmarks_) + Strong_witness_complex(Nearest_landmark_table_ & nearest_landmark_table) + : nearest_landmark_table_(nearest_landmark_table) { } - - - /** \brief Returns the point corresponding to the given vertex. - */ - template - Point_d get_point( Vertex_handle vertex ) const - { - return landmarks_[vertex]; - } /** \brief Outputs the strong witness complex of relaxation 'max_alpha_square' * in a simplicial complex data structure. @@ -126,10 +98,9 @@ private: */ template < typename SimplicialComplexForWitness > bool create_complex(SimplicialComplexForWitness& complex, - FT max_alpha_square, + double max_alpha_square, Landmark_id limit_dimension = std::numeric_limits::max()-1) { - std::size_t nbL = landmarks_.size(); Landmark_id complex_dim = 0; if (complex.num_vertices() > 0) { std::cerr << "Strong witness complex cannot create complex - complex is not empty.\n"; @@ -143,14 +114,8 @@ private: std::cerr << "Strong witness complex cannot create complex - limit dimension must be non-negative.\n"; return false; } - typeVectorVertex vv; - for (unsigned i = 0; i != nbL; ++i) { - // initial fill of 0-dimensional simplices - vv = {i}; - complex.insert_simplex(vv, Filtration_value(0.0)); - } - for (auto w: witnesses_) { - ActiveWitness aw(landmark_tree_.query_incremental_nearest_neighbors(w)); + for (auto w: nearest_landmark_table_) { + ActiveWitness aw(w); typeVectorVertex simplex; typename ActiveWitness::iterator aw_it = aw.begin(); float lim_dist2 = aw.begin()->second + max_alpha_square; @@ -186,7 +151,7 @@ private: typeVectorVertex& vertices, typename typeVectorVertex::iterator curr_it, typename ActiveWitness::iterator aw_it, - FT filtration_value, + double filtration_value, typeVectorVertex& simplex, SimplicialComplexForWitness& sc) { diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index 73993900..2cd7a178 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -58,7 +58,6 @@ private: 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; diff --git a/src/Witness_complex/test/test_simple_witness_complex.cpp b/src/Witness_complex/test/test_simple_witness_complex.cpp index c50e829a..2d4134f4 100644 --- a/src/Witness_complex/test/test_simple_witness_complex.cpp +++ b/src/Witness_complex/test/test_simple_witness_complex.cpp @@ -102,17 +102,33 @@ BOOST_AUTO_TEST_CASE(simple_witness_complex) { BOOST_CHECK(relaxed_complex_ne.num_simplices() == 239); - - EuclideanStrongWitnessComplex strong_witness_complex(landmarks, - witnesses); + // Strong complex : Euclidean version + EuclideanStrongWitnessComplex eucl_strong_witness_complex(landmarks, + witnesses); - strong_witness_complex.create_complex(strong_relaxed_complex, 9.1); - strong_witness_complex.create_complex(strong_relaxed_complex2, 9.1, 2); + eucl_strong_witness_complex.create_complex(strong_relaxed_complex, 9.1); + eucl_strong_witness_complex.create_complex(strong_relaxed_complex2, 9.1, 2); std::cout << "strong_relaxed_complex.num_simplices() = " << strong_relaxed_complex.num_simplices() << std::endl; BOOST_CHECK(strong_relaxed_complex.num_simplices() == 239); std::cout << "strong_relaxed_complex2.num_simplices() = " << strong_relaxed_complex2.num_simplices() << std::endl; BOOST_CHECK(strong_relaxed_complex2.num_simplices() == 92); + + + // Strong complex : non-Euclidean version + EuclideanStrongWitnessComplex strong_witness_complex(landmarks, + witnesses); + + strong_witness_complex.create_complex(strong_relaxed_complex_ne, 9.1); + strong_witness_complex.create_complex(strong_relaxed_complex2_ne, 9.1, 2); + + std::cout << "strong_relaxed_complex.num_simplices() = " << strong_relaxed_complex_ne.num_simplices() << std::endl; + BOOST_CHECK(strong_relaxed_complex_ne.num_simplices() == 239); + + std::cout << "strong_relaxed_complex2.num_simplices() = " << strong_relaxed_complex2_ne.num_simplices() << std::endl; + BOOST_CHECK(strong_relaxed_complex2_ne.num_simplices() == 92); + + // 8 vertices, 28 edges, 56 triangles } -- cgit v1.2.3 From 6b7a6c4ab5e643393ac9ef9ccec25d9d9afac822 Mon Sep 17 00:00:00 2001 From: skachano Date: Wed, 18 Jan 2017 10:21:00 +0000 Subject: Fixed doc for non-Euclidean complexes. Concept is left git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1946 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 949925ad85a74418a53bff1c934ce2f7669c483e --- .../include/gudhi/Strong_witness_complex.h | 17 ++++------------- src/Witness_complex/include/gudhi/Witness_complex.h | 12 ++++-------- .../include/gudhi/Witness_complex/all_faces_in.h | 2 +- 3 files changed, 9 insertions(+), 22 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index 164d8ffe..20f9da8d 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -40,18 +40,10 @@ namespace witness_complex { /** * \private * \class Strong_witness_complex - * \brief Constructs strong witness complex for the given sets of witnesses and landmarks. + * \brief Constructs strong witness complex for a given table of nearest landmarks with respect to witnesses. * \ingroup witness_complex * - * \tparam Kernel_ requires a CGAL::Epick_d class, which - * can be static if you know the ambiant dimension at compile-time, or dynamic if you don't. - * \tparam DimensionTag can be either Dimension_tag - * if you know the intrinsic dimension at compile-time, - * or CGAL::Dynamic_dimension_tag - * if you don't. + * \tparam Nearest_landmark_table_ needs to be a range of a model of NearestLandmarkRange concept. */ template< class Nearest_landmark_table_ > class Strong_witness_complex { @@ -78,9 +70,8 @@ private: /** * \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. + * \details Records nearest landmark table. + * @param[in] nearest_landmark_table should be a range of a model of NearestLandmarkRange concept. */ Strong_witness_complex(Nearest_landmark_table_ & nearest_landmark_table) : nearest_landmark_table_(nearest_landmark_table) diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index 2cd7a178..70d51677 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -41,12 +41,10 @@ namespace witness_complex { /** * \private * \class Witness_complex - * \brief Constructs (weak) witness complex for the given sets of witnesses and landmarks. + * \brief Constructs (weak) witness complex for a given table of nearest landmarks with respect to witnesses. * \ingroup witness_complex * - * \tparam Kernel_ requires a CGAL::Epick_d class, which - * can be static if you know the ambiant dimension at compile-time, or dynamic if you don't. + * \tparam Nearest_landmark_table_ needs to be a range of a model of NearestLandmarkRange concept. */ template< class Nearest_landmark_table_ > class Witness_complex { @@ -73,9 +71,8 @@ private: /** * \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. + * \details Records nearest landmark table. + @param[in] nearest_landmark_table should be a range of a model of NearestLandmarkRange concept. */ Witness_complex(Nearest_landmark_table_ & nearest_landmark_table) @@ -98,7 +95,6 @@ private: double max_alpha_square, Landmark_id limit_dimension = std::numeric_limits::max()) { - // std::size_t nbL = landmarks_.size(); if (complex.num_vertices() > 0) { std::cerr << "Witness complex cannot create complex - complex is not empty.\n"; return false; diff --git a/src/Witness_complex/include/gudhi/Witness_complex/all_faces_in.h b/src/Witness_complex/include/gudhi/Witness_complex/all_faces_in.h index 899022f8..b69719a3 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex/all_faces_in.h +++ b/src/Witness_complex/include/gudhi/Witness_complex/all_faces_in.h @@ -23,7 +23,7 @@ template < typename SimplicialComplexForWitness, for (typename Simplex::iterator it = simplex.begin(); it != simplex.end(); ++it) if (it != not_it) facet.push_back(*it); - typename SimplicialComplexForWitness::Simplex_handle facet_sh = sc.find(facet); + Simplex_handle facet_sh = sc.find(facet); if (facet_sh == sc.null_simplex()) return false; else if (sc.filtration(facet_sh) > *filtration_value) -- cgit v1.2.3 From 9335a9dae7bfb76a7d6cb5e15f0975dcbb20f17e Mon Sep 17 00:00:00 2001 From: skachano Date: Wed, 18 Jan 2017 10:52:01 +0000 Subject: Fixed thedocumentation. Even without an additional concept. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1947 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 3efb3fc30ca069b720fe1134ab3d64d284feb7ad --- src/Witness_complex/concept/Simplicial_complex_for_witness.h | 2 +- src/Witness_complex/doc/Witness_complex_doc.h | 2 ++ src/Witness_complex/include/gudhi/Strong_witness_complex.h | 9 ++++++--- src/Witness_complex/include/gudhi/Witness_complex.h | 8 ++++++-- 4 files changed, 15 insertions(+), 6 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/concept/Simplicial_complex_for_witness.h b/src/Witness_complex/concept/Simplicial_complex_for_witness.h index b47de809..df294f19 100644 --- a/src/Witness_complex/concept/Simplicial_complex_for_witness.h +++ b/src/Witness_complex/concept/Simplicial_complex_for_witness.h @@ -27,7 +27,7 @@ namespace Gudhi { namespace witness_complex { -/** \brief The concept Simplicial_Complex describes the requirements +/** \brief The concept SimplicialComplexForWitness describes the requirements * for a type to implement a simplicial complex, * used for example to build a Witness_complex. */ diff --git a/src/Witness_complex/doc/Witness_complex_doc.h b/src/Witness_complex/doc/Witness_complex_doc.h index fa45e359..1ed3fd4e 100644 --- a/src/Witness_complex/doc/Witness_complex_doc.h +++ b/src/Witness_complex/doc/Witness_complex_doc.h @@ -44,7 +44,9 @@ The two complexes described above are implemented in the corresponding classes - Gudhi::witness_complex::Witness_complex + - Gudhi::witness_complex::Euclidean_witness_complex - Gudhi::witness_complex::Strong_witness_complex + - Gudhi::witness_complex::Euclidean_strong_witness_complex The construction of both of them follow the same scheme: 1. Construct a search tree on landmarks (for that Gudhi::spatial_searching::Kd_tree_search is used internally). diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index 20f9da8d..abfc879c 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -43,7 +43,9 @@ namespace witness_complex { * \brief Constructs strong witness complex for a given table of nearest landmarks with respect to witnesses. * \ingroup witness_complex * - * \tparam Nearest_landmark_table_ needs to be a range of a model of NearestLandmarkRange concept. + * \tparam Nearest_landmark_table_ needs to be a range of a range of nearest landmarks. + * 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'. */ template< class Nearest_landmark_table_ > class Strong_witness_complex { @@ -71,8 +73,9 @@ private: /** * \brief Initializes member variables before constructing simplicial complex. * \details Records nearest landmark table. - * @param[in] nearest_landmark_table should be a range of a model of NearestLandmarkRange concept. - */ + * @param[in] nearest_landmark_table needs to be a range of a range of nearest landmarks. + * 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_ & nearest_landmark_table) : nearest_landmark_table_(nearest_landmark_table) { diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index 70d51677..3305a8e2 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -44,7 +44,9 @@ namespace witness_complex { * \brief Constructs (weak) witness complex for a given table of nearest landmarks with respect to witnesses. * \ingroup witness_complex * - * \tparam Nearest_landmark_table_ needs to be a range of a model of NearestLandmarkRange concept. + * \tparam Nearest_landmark_table_ needs to be a range of a range of nearest landmarks. + * 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'. */ template< class Nearest_landmark_table_ > class Witness_complex { @@ -72,7 +74,9 @@ private: /** * \brief Initializes member variables before constructing simplicial complex. * \details Records nearest landmark table. - @param[in] nearest_landmark_table should be a range of a model of NearestLandmarkRange concept. + * @param[in] nearest_landmark_table needs to be a range of a range of nearest landmarks. + * 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'. */ Witness_complex(Nearest_landmark_table_ & nearest_landmark_table) -- cgit v1.2.3 From 53f243365ddc1653b776fe97ea8ba8493199dc14 Mon Sep 17 00:00:00 2001 From: skachano Date: Sat, 21 Jan 2017 11:00:43 +0000 Subject: Added all the consts git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1980 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 4651513288c5bf45fbdecd6b396779201b874f84 --- src/Witness_complex/include/gudhi/Active_witness/Active_witness.h | 2 +- .../include/gudhi/Active_witness/Active_witness_iterator.h | 2 +- src/Witness_complex/include/gudhi/Strong_witness_complex.h | 4 ++-- src/Witness_complex/include/gudhi/Witness_complex.h | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Active_witness/Active_witness.h b/src/Witness_complex/include/gudhi/Active_witness/Active_witness.h index f64701fa..08762fb3 100644 --- a/src/Witness_complex/include/gudhi/Active_witness/Active_witness.h +++ b/src/Witness_complex/include/gudhi/Active_witness/Active_witness.h @@ -49,7 +49,7 @@ public: INS_iterator iterator_next_; INS_iterator iterator_end_; - Active_witness(INS_range search_range) + Active_witness(const INS_range& search_range) : search_range_(search_range), iterator_next_(search_range_.begin()), iterator_end_(search_range_.end()) { //nearest_landmark_table_.push_back(*iterator_last_); 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 c1d2091a..d6ea6403 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 @@ -62,7 +62,7 @@ public: { } - Active_witness_iterator(Active_witness* aw, Pair_iterator lh) + Active_witness_iterator(Active_witness* aw, const Pair_iterator& lh) : aw_(aw), lh_(lh) { is_end_ = false; diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index abfc879c..87965b6e 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -93,7 +93,7 @@ private: template < typename SimplicialComplexForWitness > bool create_complex(SimplicialComplexForWitness& complex, double max_alpha_square, - Landmark_id limit_dimension = std::numeric_limits::max()-1) + Landmark_id limit_dimension = std::numeric_limits::max()-1) const { Landmark_id complex_dim = 0; if (complex.num_vertices() > 0) { @@ -147,7 +147,7 @@ private: typename ActiveWitness::iterator aw_it, double filtration_value, typeVectorVertex& simplex, - SimplicialComplexForWitness& sc) + SimplicialComplexForWitness& sc) const { if (dim > 0) while (curr_it != vertices.end()) { diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index 576b8b0d..7a6ef9ed 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -97,7 +97,7 @@ private: template < typename SimplicialComplexForWitness > bool create_complex(SimplicialComplexForWitness& complex, double max_alpha_square, - Landmark_id limit_dimension = std::numeric_limits::max()) + Landmark_id limit_dimension = std::numeric_limits::max()) const { if (complex.num_vertices() > 0) { std::cerr << "Witness complex cannot create complex - complex is not empty.\n"; @@ -156,7 +156,7 @@ private: typename ActiveWitness::iterator curr_l, std::vector& simplex, SimplicialComplexForWitness& sc, - typename ActiveWitness::iterator end) + typename ActiveWitness::iterator end) const { if (curr_l == end) return false; -- cgit v1.2.3 From 3928fcbc37c2226e42e66e8fe7a90233e536ed7f Mon Sep 17 00:00:00 2001 From: skachano Date: Mon, 30 Jan 2017 04:45:58 +0000 Subject: Two of Marc's remarks git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@2020 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: d8fa5a1307da3172198d1cafd7f3f5bd42c99acc --- src/Witness_complex/doc/Witness_complex_doc.h | 4 ++-- src/Witness_complex/include/gudhi/Strong_witness_complex.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/doc/Witness_complex_doc.h b/src/Witness_complex/doc/Witness_complex_doc.h index 8d99b381..247d862a 100644 --- a/src/Witness_complex/doc/Witness_complex_doc.h +++ b/src/Witness_complex/doc/Witness_complex_doc.h @@ -64,7 +64,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp} #include -#include +#include #include #include @@ -75,7 +75,7 @@ typedef CGAL::Epick_d K; typedef typename K::Point_d Point_d; -typedef typename Gudhi::witness_complex::Witness_complex Witness_complex; +typedef typename Gudhi::witness_complex::Euclidean_witness_complex Witness_complex; typedef std::vector< Vertex_handle > typeVectorVertex; typedef std::vector< Point_d > Point_vector; diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index 87965b6e..5bcd1b6e 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -61,7 +61,7 @@ private: typedef Landmark_id Vertex_handle; private: - Nearest_landmark_table_& nearest_landmark_table_; + Nearest_landmark_table_ nearest_landmark_table_; public: ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From 0629c55fc91ab128cca77c977106d8dbb0148e10 Mon Sep 17 00:00:00 2001 From: skachano Date: Mon, 30 Jan 2017 04:51:21 +0000 Subject: Another Marc's comment git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@2021 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: a9cdd269f4efe27de960dbfe372572c38864b14f --- src/Witness_complex/include/gudhi/Strong_witness_complex.h | 2 -- src/Witness_complex/include/gudhi/Witness_complex.h | 2 -- 2 files changed, 4 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index 5bcd1b6e..b2bf1b7d 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -31,8 +31,6 @@ #include #include -namespace gss = Gudhi::spatial_searching; - namespace Gudhi { namespace witness_complex { diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index 7a6ef9ed..52c638c5 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -32,8 +32,6 @@ #include #include -namespace gss = Gudhi::spatial_searching; - namespace Gudhi { namespace witness_complex { -- 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/Strong_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 5a4adcab18b7a577706cae7abfddc52a5cf8f1c5 Mon Sep 17 00:00:00 2001 From: skachano Date: Mon, 30 Jan 2017 12:44:11 +0000 Subject: Added the consts to Nearest_landmark_table_ parameters following the comment by Marc git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@2027 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 44f5e50e3d21baa0ec70aef022a1394bcc35b7d2 --- src/Witness_complex/include/gudhi/Strong_witness_complex.h | 2 +- src/Witness_complex/include/gudhi/Witness_complex.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index f9d1d681..aae1bb43 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -79,7 +79,7 @@ private: * @param[in] nearest_landmark_table needs to be a range of a range of nearest landmarks. * 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_ & nearest_landmark_table) + Strong_witness_complex(Nearest_landmark_table_ const & nearest_landmark_table) : nearest_landmark_table_(nearest_landmark_table) { } diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index 33c6c5d2..6741acde 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -81,7 +81,7 @@ private: * of the nearest landmark range iterator needs to be 'std::pair'. */ - Witness_complex(Nearest_landmark_table_ & nearest_landmark_table) + Witness_complex(Nearest_landmark_table_ const & nearest_landmark_table) : nearest_landmark_table_(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/Strong_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 2479359771875ee216de4962234aa5ea373978cc Mon Sep 17 00:00:00 2001 From: skachano Date: Wed, 1 Feb 2017 10:10:45 +0000 Subject: Removed next_it from strong git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@2041 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 7f553a8df6f0f799c5094af9aba2ae361f77af92 --- src/Witness_complex/include/gudhi/Strong_witness_complex.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index ca1c4db8..5858d917 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -155,10 +155,10 @@ private: if (dim > 0) while (curr_it != vertices.end()) { simplex.push_back(*curr_it); - typename typeVectorVertex::iterator next_it = ++curr_it; + ++curr_it; add_all_faces_of_dimension(dim-1, vertices, - next_it, + curr_it, aw_it, filtration_value, simplex, @@ -166,7 +166,7 @@ private: simplex.pop_back(); add_all_faces_of_dimension(dim, vertices, - next_it, + curr_it, aw_it, filtration_value, simplex, -- cgit v1.2.3 From e4a627b0675453fc88d3a43eef3bff663d3f8121 Mon Sep 17 00:00:00 2001 From: skachano Date: Wed, 1 Feb 2017 10:54:18 +0000 Subject: The rest of the comments git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@2043 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 37e81613f87a77768bde47d3539a2dbc6bf3552b --- src/Witness_complex/include/gudhi/Strong_witness_complex.h | 13 +++++++------ src/Witness_complex/include/gudhi/Witness_complex.h | 14 +++++++------- 2 files changed, 14 insertions(+), 13 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index 5858d917..058b5bbc 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -41,9 +41,9 @@ namespace witness_complex { * \brief Constructs strong witness complex for a given table of nearest landmarks with respect to witnesses. * \ingroup witness_complex * - * \tparam Nearest_landmark_table_ needs to be a range of a range of nearest landmarks. - * 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'. + * \tparam Nearest_landmark_table_ needs to be a CopyConstructible range of a range of pairs of nearest landmarks and distances. + * The range of pairs must admit a member type 'iterator'. The dereference type + * of the pair range iterator needs to be 'std::pair'. */ template< class Nearest_landmark_table_ > class Strong_witness_complex { @@ -76,9 +76,10 @@ private: /** * \brief Initializes member variables before constructing simplicial complex. * \details Records nearest landmark table. - * @param[in] nearest_landmark_table needs to be a range of a range of nearest landmarks. - * 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'. */ + * @param[in] nearest_landmark_table needs to be a CopyConstructible range of a range of pairs of nearest landmarks and distances. + * 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)) { diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index 05a26f7f..a3436eba 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -42,9 +42,9 @@ namespace witness_complex { * \brief Constructs (weak) witness complex for a given table of nearest landmarks with respect to witnesses. * \ingroup witness_complex * - * \tparam Nearest_landmark_table_ needs to be a range of a range of nearest landmarks. - * 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'. + * \tparam Nearest_landmark_table_ needs to be a CopyConstructible range of a range of pairs of nearest landmarks and distances. + * The range of pairs must admit a member type 'iterator'. The dereference type + * of the pair range iterator needs to be 'std::pair'. */ template< class Nearest_landmark_table_ > class Witness_complex { @@ -76,9 +76,9 @@ private: /** * \brief Initializes member variables before constructing simplicial complex. * \details Records nearest landmark table. - * @param[in] nearest_landmark_table needs to be a range of a range of nearest landmarks. - * 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'. + * @param[in] nearest_landmark_table needs to be a CopyConstructible range of a range of pairs of nearest landmarks and distances. + * The range of pairs must admit a member type 'iterator'. The dereference type + * of the pair range iterator needs to be 'std::pair'. */ Witness_complex(Nearest_landmark_table_ const & nearest_landmark_table) @@ -99,7 +99,7 @@ private: template < typename SimplicialComplexForWitness > bool create_complex(SimplicialComplexForWitness& complex, double max_alpha_square, - Landmark_id limit_dimension = std::numeric_limits::max()) const + std::size_t limit_dimension = std::numeric_limits::max()) const { if (complex.num_vertices() > 0) { std::cerr << "Witness complex cannot create complex - complex is not empty.\n"; -- cgit v1.2.3 From e4a4c6acf4d79fd0fe3817a36dd7bd4ce7845fb5 Mon Sep 17 00:00:00 2001 From: skachano Date: Thu, 2 Feb 2017 11:17:52 +0000 Subject: Changed the internal representation of Nearest landmark table git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@2048 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 885b5d305cc9c66bd5719ad989a69027d78e1945 --- src/Witness_complex/include/gudhi/Strong_witness_complex.h | 3 ++- src/Witness_complex/include/gudhi/Witness_complex.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index 058b5bbc..25b2f6e3 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -55,11 +55,12 @@ private: typedef Active_witness ActiveWitness; typedef std::list< ActiveWitness > ActiveWitnessList; typedef std::vector< Landmark_id > typeVectorVertex; + typedef std::vector Nearest_landmark_table_internal; typedef Landmark_id Vertex_handle; protected: - Nearest_landmark_table_ nearest_landmark_table_; + Nearest_landmark_table_internal nearest_landmark_table_; public: ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index a3436eba..8489083e 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -56,11 +56,12 @@ private: typedef Active_witness ActiveWitness; typedef std::list< ActiveWitness > ActiveWitnessList; typedef std::vector< Landmark_id > typeVectorVertex; + typedef std::vector Nearest_landmark_table_internal; typedef Landmark_id Vertex_handle; protected: - Nearest_landmark_table_ nearest_landmark_table_; + Nearest_landmark_table_internal nearest_landmark_table_; public: ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From bc2a24597b59d0e66856c97465310759ada80bd0 Mon Sep 17 00:00:00 2001 From: skachano Date: Thu, 2 Feb 2017 11:29:09 +0000 Subject: Fixed the doc git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@2049 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: e3ef8165c38d7b3e3dd78bd5ca25e7e92a4139e3 --- src/Witness_complex/include/gudhi/Strong_witness_complex.h | 4 ++-- src/Witness_complex/include/gudhi/Witness_complex.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index 25b2f6e3..f58dff40 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -41,7 +41,7 @@ namespace witness_complex { * \brief Constructs strong witness complex for a given table of nearest landmarks with respect to witnesses. * \ingroup witness_complex * - * \tparam Nearest_landmark_table_ needs to be a CopyConstructible range of a range of pairs of nearest landmarks and distances. + * \tparam Nearest_landmark_table_ needs to be a range of a range of pairs of nearest landmarks and distances. * The range of pairs must admit a member type 'iterator'. The dereference type * of the pair range iterator needs to be 'std::pair'. */ @@ -77,7 +77,7 @@ private: /** * \brief Initializes member variables before constructing simplicial complex. * \details Records nearest landmark table. - * @param[in] nearest_landmark_table needs to be a CopyConstructible range of a range of pairs of nearest landmarks and distances. + * @param[in] nearest_landmark_table needs to be a range of a range of pairs of nearest landmarks and distances. * The range of pairs must admit a member type 'iterator'. The dereference type * of the pair range iterator needs to be 'std::pair'. */ diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index 8489083e..103b131c 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -42,7 +42,7 @@ namespace witness_complex { * \brief Constructs (weak) witness complex for a given table of nearest landmarks with respect to witnesses. * \ingroup witness_complex * - * \tparam Nearest_landmark_table_ needs to be a CopyConstructible range of a range of pairs of nearest landmarks and distances. + * \tparam Nearest_landmark_table_ needs to be a range of a range of pairs of nearest landmarks and distances. * The range of pairs must admit a member type 'iterator'. The dereference type * of the pair range iterator needs to be 'std::pair'. */ @@ -77,7 +77,7 @@ private: /** * \brief Initializes member variables before constructing simplicial complex. * \details Records nearest landmark table. - * @param[in] nearest_landmark_table needs to be a CopyConstructible range of a range of pairs of nearest landmarks and distances. + * @param[in] nearest_landmark_table needs to be a range of a range of pairs of nearest landmarks and distances. * The range of pairs must admit a member type 'iterator'. The dereference type * of the pair range iterator needs to be 'std::pair'. */ -- cgit v1.2.3 From 004bfb8ea845b5109252e7fa86103586eda8e146 Mon Sep 17 00:00:00 2001 From: skachano Date: Wed, 22 Feb 2017 16:53:01 +0000 Subject: Marc's review:1 git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@2095 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 8a4f9c28d3d279f799b8706366559e2a39d11560 --- src/Witness_complex/include/gudhi/Strong_witness_complex.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index f58dff40..d7d0b2f0 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -118,7 +118,7 @@ private: 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) { + while ((Landmark_id)simplex.size() <= limit_dimension && 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++; -- cgit v1.2.3 From 618417f9844da70fc4408a05e8136d65c7979cdd Mon Sep 17 00:00:00 2001 From: skachano Date: Thu, 23 Feb 2017 10:55:57 +0000 Subject: Changed default limit_dim in Strong git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@2098 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: aa467ec1ae98bc6a7131cc7daf9348e695086a7c --- src/Witness_complex/include/gudhi/Strong_witness_complex.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index d7d0b2f0..50ba8d0b 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -98,7 +98,7 @@ private: template < typename SimplicialComplexForWitness > bool create_complex(SimplicialComplexForWitness& complex, double max_alpha_square, - Landmark_id limit_dimension = std::numeric_limits::max()-1) const + Landmark_id limit_dimension = std::numeric_limits::max()) const { Landmark_id complex_dim = 0; if (complex.num_vertices() > 0) { -- cgit v1.2.3 From ea51646efd72e9edab55abae846100c7494916ca Mon Sep 17 00:00:00 2001 From: skachano Date: Thu, 23 Feb 2017 11:04:40 +0000 Subject: Added the copiable precision to the doc. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@2100 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 1892ed7c04219bee7e3dbf408d49d153d85fe10b --- src/Witness_complex/include/gudhi/Strong_witness_complex.h | 2 ++ src/Witness_complex/include/gudhi/Witness_complex.h | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index 50ba8d0b..2f833ccd 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -42,6 +42,7 @@ namespace witness_complex { * \ingroup witness_complex * * \tparam Nearest_landmark_table_ needs to be a range of a range of pairs of nearest landmarks and distances. + * The class Nearest_landmark_table_::value_type must be a copiable range. * The range of pairs must admit a member type 'iterator'. The dereference type * of the pair range iterator needs to be 'std::pair'. */ @@ -78,6 +79,7 @@ private: * \brief Initializes member variables before constructing simplicial complex. * \details Records nearest landmark table. * @param[in] nearest_landmark_table needs to be a range of a range of pairs of nearest landmarks and distances. + * The class Nearest_landmark_table_::value_type must be a copiable range. * The range of pairs must admit a member type 'iterator'. The dereference type * of the pair range iterator needs to be 'std::pair'. */ diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index d808de57..c09e6af9 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -43,6 +43,7 @@ namespace witness_complex { * \ingroup witness_complex * * \tparam Nearest_landmark_table_ needs to be a range of a range of pairs of nearest landmarks and distances. + * The class Nearest_landmark_table_::value_type must be a copiable range. * The range of pairs must admit a member type 'iterator'. The dereference type * of the pair range iterator needs to be 'std::pair'. */ @@ -78,8 +79,9 @@ private: * \brief Initializes member variables before constructing simplicial complex. * \details Records nearest landmark table. * @param[in] nearest_landmark_table needs to be a range of a range of pairs of nearest landmarks and distances. - * The range of pairs must admit a member type 'iterator'. The dereference type - * of the pair range iterator needs to be 'std::pair'. + * The class Nearest_landmark_table_::value_type must be a copiable range. + * The range of pairs must admit a member type 'iterator'. The dereference type + * of the pair range iterator needs to be 'std::pair'. */ Witness_complex(Nearest_landmark_table_ const & nearest_landmark_table) -- cgit v1.2.3 From ba56545de435b62e0528d01fbde342bc4653da13 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 28 Feb 2017 13:59:47 +0000 Subject: Fix cppcheck git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@2118 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 5783a6de4bdb1fac8362f5badee204b37015da1d --- src/Witness_complex/include/gudhi/Strong_witness_complex.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index 2f833ccd..ad741794 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -190,4 +190,4 @@ private: } // namespace Gudhi -#endif +#endif // STRONG_WITNESS_COMPLEX_H_ -- cgit v1.2.3 From f2b63bcaa647d1ec839dbe2e5edbe5c4fde1b304 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 28 Feb 2017 16:16:08 +0000 Subject: Fix cppcheck git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@2120 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 49a5c2c6e94d9fbf235eecc92fa30e62980c7c70 --- .../example/example_nearest_landmark_table.cpp | 34 ++++++++++---- .../example/example_strong_witness_complex_off.cpp | 28 +++++++++-- .../example/example_strong_witness_persistence.cpp | 54 ++++++++++++++-------- .../example/example_witness_complex_off.cpp | 11 ++--- .../example_witness_complex_persistence.cpp | 22 +++++++++ .../example/example_witness_complex_sphere.cpp | 33 +++++++++---- src/Witness_complex/example/generators.h | 14 +++--- .../include/gudhi/Active_witness/Active_witness.h | 22 ++++----- .../gudhi/Active_witness/Active_witness_iterator.h | 41 ++++++++-------- .../gudhi/Euclidean_strong_witness_complex.h | 29 ++++++------ .../include/gudhi/Strong_witness_complex.h | 54 ++++++++++------------ .../include/gudhi/Witness_complex.h | 42 ++++++++--------- .../include/gudhi/Witness_complex/all_faces_in.h | 30 ++++++++++-- 13 files changed, 250 insertions(+), 164 deletions(-) (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/example/example_nearest_landmark_table.cpp b/src/Witness_complex/example/example_nearest_landmark_table.cpp index b3883248..65b675f9 100644 --- a/src/Witness_complex/example/example_nearest_landmark_table.cpp +++ b/src/Witness_complex/example/example_nearest_landmark_table.cpp @@ -1,16 +1,31 @@ -#define BOOST_PARAMETER_MAX_ARITY 12 - +/* 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) 2016 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 . + */ -#include -#include +#define BOOST_PARAMETER_MAX_ARITY 12 #include #include -#include #include -#include - #include #include #include @@ -24,6 +39,8 @@ int main(int argc, char * const argv[]) { using Nearest_landmark_table = std::vector; using Witness_complex = Gudhi::witness_complex::Witness_complex; using Simplex_tree = Gudhi::Simplex_tree<>; + using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; + using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; Simplex_tree simplex_tree; Nearest_landmark_table nlt; @@ -45,8 +62,7 @@ int main(int argc, char * const argv[]) { std::cout << "Number of simplices: " << simplex_tree.num_simplices() << std::endl; - using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; - Gudhi::persistent_cohomology::Persistent_cohomology pcoh(simplex_tree); + Persistent_cohomology pcoh(simplex_tree); // initializes the coefficient field for homology pcoh.init_coefficients(11); diff --git a/src/Witness_complex/example/example_strong_witness_complex_off.cpp b/src/Witness_complex/example/example_strong_witness_complex_off.cpp index 6a4925b8..0ee9ee90 100644 --- a/src/Witness_complex/example/example_strong_witness_complex_off.cpp +++ b/src/Witness_complex/example/example_strong_witness_complex_off.cpp @@ -1,5 +1,24 @@ -#include -#include +/* 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) 2016 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 . + */ #include #include @@ -16,9 +35,8 @@ using K = CGAL::Epick_d; using Point_d = typename K::Point_d; -typedef typename Gudhi::witness_complex::Euclidean_strong_witness_complex Witness_complex; -using typeVectorVertex = std::vector< typename Gudhi::Simplex_tree<>::Vertex_handle >; -using Point_vector = std::vector< Point_d >; +using Witness_complex = Gudhi::witness_complex::Euclidean_strong_witness_complex; +using Point_vector = std::vector; int main(int argc, char * const argv[]) { if (argc != 5) { diff --git a/src/Witness_complex/example/example_strong_witness_persistence.cpp b/src/Witness_complex/example/example_strong_witness_persistence.cpp index d42603aa..5efe69fd 100644 --- a/src/Witness_complex/example/example_strong_witness_persistence.cpp +++ b/src/Witness_complex/example/example_strong_witness_persistence.cpp @@ -1,3 +1,25 @@ +/* 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) 2016 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 . + */ + #include #include #include @@ -12,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 Strong_witness_complex = Gudhi::witness_complex::Euclidean_strong_witness_complex; +using SimplexTree = Gudhi::Simplex_tree<>; -typedef typename std::vector Point_vector; -typedef typename Gudhi::witness_complex::Euclidean_strong_witness_complex Strong_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 @@ -61,9 +82,9 @@ int main(int argc, char * argv[]) { // Compute witness complex Strong_witness_complex strong_witness_complex(landmarks, witnesses); - + strong_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"; @@ -71,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); @@ -89,7 +110,6 @@ int main(int argc, char * argv[]) { return 0; } - void program_options(int argc, char * argv[] , int & nbL , std::string & file_name @@ -98,14 +118,12 @@ 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."); - po::options_description visible("Allowed options", 100); visible.add_options() @@ -122,7 +140,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 strong witness complex we want to compute."); - + po::positional_options_description pos; pos.add("input-file", 1); @@ -133,7 +151,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"; diff --git a/src/Witness_complex/example/example_witness_complex_off.cpp b/src/Witness_complex/example/example_witness_complex_off.cpp index 38c6bedc..b36dac0d 100644 --- a/src/Witness_complex/example/example_witness_complex_off.cpp +++ b/src/Witness_complex/example/example_witness_complex_off.cpp @@ -14,11 +14,10 @@ #include #include -typedef CGAL::Epick_d K; -typedef typename K::Point_d Point_d; -typedef typename Gudhi::witness_complex::Euclidean_witness_complex Witness_complex; -typedef std::vector< typename Gudhi::Simplex_tree<>::Vertex_handle > typeVectorVertex; -typedef std::vector< Point_d > Point_vector; +using K = CGAL::Epick_d; +using Point_d = K::Point_d; +using Witness_complex = Gudhi::witness_complex::Euclidean_witness_complex; +using Point_vector = std::vector< Point_d >; int main(int argc, char * const argv[]) { if (argc != 5) { @@ -41,7 +40,7 @@ int main(int argc, char * const argv[]) { exit(-1); // ----- >> } point_vector = Point_vector(off_reader.get_point_cloud()); - + std::cout << "Successfully read " << point_vector.size() << " points.\n"; std::cout << "Ambient dimension is " << point_vector[0].dimension() << ".\n"; diff --git a/src/Witness_complex/example/example_witness_complex_persistence.cpp b/src/Witness_complex/example/example_witness_complex_persistence.cpp index fbb18cb4..364a114a 100644 --- a/src/Witness_complex/example/example_witness_complex_persistence.cpp +++ b/src/Witness_complex/example/example_witness_complex_persistence.cpp @@ -1,3 +1,25 @@ +/* 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) 2016 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 . + */ + #include #include #include diff --git a/src/Witness_complex/example/example_witness_complex_sphere.cpp b/src/Witness_complex/example/example_witness_complex_sphere.cpp index 1ea9408c..06fe3889 100644 --- a/src/Witness_complex/example/example_witness_complex_sphere.cpp +++ b/src/Witness_complex/example/example_witness_complex_sphere.cpp @@ -1,8 +1,26 @@ -#define BOOST_PARAMETER_MAX_ARITY 12 - +/* 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) 2016 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 . + */ -#include -#include +#define BOOST_PARAMETER_MAX_ARITY 12 #include #include @@ -32,8 +50,9 @@ void write_data(Data_range & data, std::string filename) { } int main(int argc, char * const argv[]) { - typedef Gudhi::witness_complex::Euclidean_witness_complex> Witness_complex; - + using Kernel = CGAL::Epick_d; + using Witness_complex = Gudhi::witness_complex::Euclidean_witness_complex; + if (argc != 2) { std::cerr << "Usage: " << argv[0] << " number_of_landmarks \n"; @@ -66,8 +85,6 @@ int main(int argc, char * const argv[]) { double time = static_cast(end - start) / CLOCKS_PER_SEC; std::cout << "Witness complex for " << number_of_landmarks << " landmarks took " << time << " s. \n"; - //assert(1 == 0); - //std::cout << simplex_tree << "\n"; std::cout << "Number of simplices is: " << simplex_tree.num_simplices() << "\n"; l_time.push_back(std::make_pair(nbP, time)); } diff --git a/src/Witness_complex/example/generators.h b/src/Witness_complex/example/generators.h index 731a52b0..7df43db5 100644 --- a/src/Witness_complex/example/generators.h +++ b/src/Witness_complex/example/generators.h @@ -32,12 +32,12 @@ #include #include -typedef CGAL::Epick_d K; -typedef K::FT FT; -typedef K::Point_d Point_d; -typedef std::vector Point_Vector; -typedef CGAL::Random_points_in_cube_d Random_cube_iterator; -typedef CGAL::Random_points_in_ball_d Random_point_iterator; +using K = CGAL::Epick_d; +using FT = K::FT; +using Point_d = K::Point_d; +using Point_Vector = std::vector; +using Random_cube_iterator = CGAL::Random_points_in_cube_d; +using Random_point_iterator = CGAL::Random_points_in_ball_d; /** * \brief Rock age method of reading off file @@ -155,7 +155,7 @@ void generate_points_torus(Point_Vector& W, int nbP, int dim) { for (int i = 0; i < nbP; i++) { std::vector point; for (int j = 0; j < dim; j++) { - double alpha = rand.uniform_real((double)0, 2*pi); + double alpha = rand.uniform_real(static_cast(0), 2*pi); point.push_back(sin(alpha)); point.push_back(cos(alpha)); } diff --git a/src/Witness_complex/include/gudhi/Active_witness/Active_witness.h b/src/Witness_complex/include/gudhi/Active_witness/Active_witness.h index ffc1750f..d41a6811 100644 --- a/src/Witness_complex/include/gudhi/Active_witness/Active_witness.h +++ b/src/Witness_complex/include/gudhi/Active_witness/Active_witness.h @@ -24,8 +24,7 @@ #define ACTIVE_WITNESS_ACTIVE_WITNESS_H_ #include -#include -#include +#include namespace Gudhi { @@ -38,7 +37,7 @@ namespace witness_complex { template< typename Id_distance_pair, typename INS_range > class Active_witness { -public: + public: typedef Active_witness ActiveWitness; typedef typename INS_range::iterator INS_iterator; typedef Active_witness_iterator< ActiveWitness, Id_distance_pair, INS_iterator > iterator; @@ -50,22 +49,19 @@ public: INS_iterator iterator_end_; Active_witness(const INS_range& search_range) - : search_range_(search_range), iterator_next_(search_range_.begin()), iterator_end_(search_range_.end()) - { + : search_range_(search_range), iterator_next_(search_range_.begin()), iterator_end_(search_range_.end()) { } - - iterator begin() - { + + iterator begin() { return iterator(this, nearest_landmark_table_.begin()); } - iterator end() - { + iterator end() { return iterator(this); } }; -} -} - +} // namespace witness_complex +} // namespace Gudhi + #endif // ACTIVE_WITNESS_ACTIVE_WITNESS_H_ 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 69a335fa..4e29a40d 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 @@ -24,7 +24,7 @@ #define ACTIVE_WITNESS_ACTIVE_WITNESS_ITERATOR_H_ #include -#include +#include namespace Gudhi { @@ -41,30 +41,29 @@ template< typename Active_witness, typename Id_distance_pair, typename INS_iterator > class Active_witness_iterator - : public boost::iterator_facade< Active_witness_iterator -, Id_distance_pair const -, boost::forward_traversal_tag -, Id_distance_pair const> { + : public boost::iterator_facade< Active_witness_iterator , + Id_distance_pair const, + boost::forward_traversal_tag, + 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; - - + 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 -public: + public: Active_witness_iterator(Active_witness* aw) - : aw_(aw), lh_(aw_->nearest_landmark_table_.end()), is_end_(true) - { + : aw_(aw), lh_(aw_->nearest_landmark_table_.end()), is_end_(true) { } Active_witness_iterator(Active_witness* aw, const Pair_iterator& lh) - : aw_(aw), lh_(lh) - { + : aw_(aw), lh_(lh) { is_end_ = false; if (lh_ == aw_->nearest_landmark_table_.end()) { if (aw_->iterator_next_ == aw_->iterator_end_) { @@ -76,21 +75,17 @@ public: } } } - -private : - Id_distance_pair& dereference() const - { + private : + Id_distance_pair& dereference() const { return *lh_; } - bool equal(const Iterator& other) const - { + bool equal(const Iterator& other) const { return (is_end_ == other.is_end_) || (lh_ == other.lh_); } - - void increment() - { + + 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.")); // if the id of the current landmark is the same as the last one 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 aad05547..6870c183 100644 --- a/src/Witness_complex/include/gudhi/Euclidean_strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Euclidean_strong_witness_complex.h @@ -23,17 +23,15 @@ #ifndef EUCLIDEAN_STRONG_WITNESS_COMPLEX_H_ #define EUCLIDEAN_STRONG_WITNESS_COMPLEX_H_ -#include -#include -#include -#include - #include #include #include +#include +#include + namespace Gudhi { - + namespace witness_complex { /** @@ -46,8 +44,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_strong_witness_complex : public Strong_witness_complex>::INS_range>> { -private: +class Euclidean_strong_witness_complex + : public Strong_witness_complex>::INS_range>> { + private: typedef Kernel_ K; typedef typename K::Point_d Point_d; typedef std::vector Point_range; @@ -58,12 +58,12 @@ private: typedef typename Nearest_landmark_range::Point_with_transformed_distance Id_distance_pair; typedef typename Id_distance_pair::first_type Landmark_id; typedef Landmark_id Vertex_handle; - + private: Point_range landmarks_; Kd_tree landmark_tree_; using Strong_witness_complex::nearest_landmark_table_; - + public: ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /* @name Constructor @@ -81,22 +81,19 @@ private: typename WitnessRange > Euclidean_strong_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) nearest_landmark_table_.push_back(landmark_tree_.query_incremental_nearest_neighbors(w)); } - /** \brief Returns the point corresponding to the given vertex. */ template - Point_d get_point( Vertex_handle vertex ) const - { + Point_d get_point(Vertex_handle vertex) const { return landmarks_[vertex]; } - + //@} }; diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index ad741794..3fbbb366 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -23,20 +23,19 @@ #ifndef STRONG_WITNESS_COMPLEX_H_ #define STRONG_WITNESS_COMPLEX_H_ +#include +#include + #include #include #include #include -#include -#include - namespace Gudhi { - + namespace witness_complex { -/** - * \private +/* \private * \class Strong_witness_complex * \brief Constructs strong witness complex for a given table of nearest landmarks with respect to witnesses. * \ingroup witness_complex @@ -48,7 +47,7 @@ namespace witness_complex { */ template< class Nearest_landmark_table_ > class Strong_witness_complex { -private: + private: typedef typename Nearest_landmark_table_::value_type Nearest_landmark_range; typedef std::size_t Witness_id; typedef std::size_t Landmark_id; @@ -57,12 +56,11 @@ private: typedef std::list< ActiveWitness > ActiveWitnessList; typedef std::vector< Landmark_id > typeVectorVertex; typedef std::vector Nearest_landmark_table_internal; - typedef Landmark_id Vertex_handle; - + protected: Nearest_landmark_table_internal nearest_landmark_table_; - + public: ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /* @name Constructor @@ -70,11 +68,9 @@ private: //@{ - Strong_witness_complex() - { + Strong_witness_complex() { } - /** * \brief Initializes member variables before constructing simplicial complex. * \details Records nearest landmark table. @@ -84,10 +80,9 @@ private: * 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)) - { + : nearest_landmark_table_(std::begin(nearest_landmark_table), std::end(nearest_landmark_table)) { } - + /** \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. @@ -100,15 +95,15 @@ private: template < typename SimplicialComplexForWitness > bool create_complex(SimplicialComplexForWitness& complex, double max_alpha_square, - Landmark_id limit_dimension = std::numeric_limits::max()) const - { + Landmark_id limit_dimension = std::numeric_limits::max()) const { Landmark_id complex_dim = 0; if (complex.num_vertices() > 0) { std::cerr << "Strong witness complex cannot create complex - complex is not empty.\n"; return false; } if (max_alpha_square < 0) { - std::cerr << "Strong witness complex cannot create complex - squared relaxation parameter must be non-negative.\n"; + std::cerr << "Strong witness complex cannot create complex - squared relaxation parameter must be " + << "non-negative.\n"; return false; } if (limit_dimension < 0) { @@ -129,7 +124,8 @@ private: 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); + 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++; } @@ -140,13 +136,12 @@ private: return true; } -private: - + 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. - */ + * 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, @@ -154,9 +149,8 @@ private: typename ActiveWitness::iterator aw_it, double filtration_value, typeVectorVertex& simplex, - SimplicialComplexForWitness& sc) const - { - if (dim > 0) + SimplicialComplexForWitness& sc) const { + if (dim > 0) { while (curr_it != vertices.end()) { simplex.push_back(*curr_it); ++curr_it; @@ -176,7 +170,7 @@ private: simplex, sc); } - else if (dim == 0) { + } 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 c09e6af9..c0506367 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -33,7 +33,7 @@ #include namespace Gudhi { - + namespace witness_complex { /** @@ -49,7 +49,7 @@ namespace witness_complex { */ template< class Nearest_landmark_table_ > class Witness_complex { -private: + private: typedef typename Nearest_landmark_table_::value_type Nearest_landmark_range; typedef std::size_t Witness_id; typedef std::size_t Landmark_id; @@ -58,12 +58,11 @@ private: typedef std::list< ActiveWitness > ActiveWitnessList; typedef std::vector< Landmark_id > typeVectorVertex; typedef std::vector Nearest_landmark_table_internal; - typedef Landmark_id Vertex_handle; protected: Nearest_landmark_table_internal nearest_landmark_table_; - + public: ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /* @name Constructor @@ -71,10 +70,9 @@ private: //@{ - Witness_complex() - { + Witness_complex() { } - + /** * \brief Initializes member variables before constructing simplicial complex. * \details Records nearest landmark table. @@ -85,11 +83,9 @@ private: */ Witness_complex(Nearest_landmark_table_ const & nearest_landmark_table) - : nearest_landmark_table_(std::begin(nearest_landmark_table), std::end(nearest_landmark_table)) - { + : nearest_landmark_table_(std::begin(nearest_landmark_table), std::end(nearest_landmark_table)) { } - /** \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. @@ -102,8 +98,7 @@ private: template < typename SimplicialComplexForWitness > bool create_complex(SimplicialComplexForWitness& complex, double max_alpha_square, - std::size_t limit_dimension = std::numeric_limits::max()) const - { + std::size_t limit_dimension = std::numeric_limits::max()) const { if (complex.num_vertices() > 0) { std::cerr << "Witness complex cannot create complex - complex is not empty.\n"; return false; @@ -118,9 +113,9 @@ private: } ActiveWitnessList active_witnesses; Landmark_id k = 0; /* current dimension in iterative construction */ - for (auto w: nearest_landmark_table_) + for (auto w : nearest_landmark_table_) active_witnesses.push_back(ActiveWitness(w)); - while (!active_witnesses.empty() && k <= limit_dimension ) { + while (!active_witnesses.empty() && k <= limit_dimension) { typename ActiveWitnessList::iterator aw_it = active_witnesses.begin(); std::vector simplex; simplex.reserve(k+1); @@ -134,10 +129,10 @@ private: aw_it->end()); assert(simplex.empty()); if (!ok) - active_witnesses.erase(aw_it++); //First increase the iterator and then erase the previous element + active_witnesses.erase(aw_it++); // First increase the iterator and then erase the previous element else aw_it++; - } + } k++; } complex.set_dimension(k-1); @@ -159,13 +154,12 @@ private: typename ActiveWitness::iterator curr_l, std::vector& simplex, SimplicialComplexForWitness& sc, - typename ActiveWitness::iterator end) const - { + 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) + 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()) { @@ -183,8 +177,8 @@ private: // If norelax_dist is infinity, change to first omitted distance if (l_it->second <= norelax_dist2) norelax_dist2 = l_it->second; - } - else if (dim == 0) + } + } 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; @@ -200,12 +194,12 @@ private: // 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 diff --git a/src/Witness_complex/include/gudhi/Witness_complex/all_faces_in.h b/src/Witness_complex/include/gudhi/Witness_complex/all_faces_in.h index d009caca..b68d75a1 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex/all_faces_in.h +++ b/src/Witness_complex/include/gudhi/Witness_complex/all_faces_in.h @@ -1,3 +1,25 @@ +/* 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 WITNESS_COMPLEX_ALL_FACES_IN_H_ #define WITNESS_COMPLEX_ALL_FACES_IN_H_ @@ -9,16 +31,14 @@ template < typename SimplicialComplexForWitness, typename Simplex > bool all_faces_in(Simplex& simplex, double* filtration_value, - SimplicialComplexForWitness& sc) - { + SimplicialComplexForWitness& sc) { typedef typename SimplicialComplexForWitness::Simplex_handle Simplex_handle; if (simplex.size() == 1) return true; /* Add vertices unconditionally */ - + Simplex facet; - for (typename Simplex::iterator not_it = simplex.begin(); not_it != simplex.end(); ++not_it) - { + for (typename Simplex::iterator not_it = simplex.begin(); not_it != simplex.end(); ++not_it) { facet.clear(); for (typename Simplex::iterator it = simplex.begin(); it != simplex.end(); ++it) if (it != not_it) -- 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/Strong_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 From 1566e2702deb978d6b04ee2add39a0245df3b477 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 7 Mar 2017 14:04:36 +0000 Subject: Remove Kdtree include in Witness_complex.h and Strong_witness_complex.h Seperate tests using euclidean witness (requires CGAL >= 4.6) and simple tests git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@2165 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: f5482e2331d59e60757e7b120e98cfcf97699f30 --- .../include/gudhi/Strong_witness_complex.h | 1 - .../include/gudhi/Witness_complex.h | 1 - src/Witness_complex/test/CMakeLists.txt | 23 ++- .../test/test_euclidean_simple_witness_complex.cpp | 135 ++++++++++++++++++ .../test/test_simple_witness_complex.cpp | 156 +++++---------------- 5 files changed, 194 insertions(+), 122 deletions(-) create mode 100644 src/Witness_complex/test/test_euclidean_simple_witness_complex.cpp (limited to 'src/Witness_complex/include/gudhi/Strong_witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h index 6708ac29..a973ddb7 100644 --- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h +++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h @@ -24,7 +24,6 @@ #define STRONG_WITNESS_COMPLEX_H_ #include -#include #include #include diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index e7adf80f..e2791f76 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -24,7 +24,6 @@ #define WITNESS_COMPLEX_H_ #include -#include #include #include diff --git a/src/Witness_complex/test/CMakeLists.txt b/src/Witness_complex/test/CMakeLists.txt index 084761e2..12b3be56 100644 --- a/src/Witness_complex/test/CMakeLists.txt +++ b/src/Witness_complex/test/CMakeLists.txt @@ -12,10 +12,31 @@ endif() add_executable ( Witness_complex_test_simple_witness_complex test_simple_witness_complex.cpp ) target_link_libraries(Witness_complex_test_simple_witness_complex ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) -target_link_libraries(Witness_complex_test_simple_witness_complex ${TBB_LIBRARIES}) +if (TBB_FOUND) + target_link_libraries(Witness_complex_test_simple_witness_complex ${TBB_LIBRARIES}) +endif(TBB_FOUND) # Unitary tests definition and xml result file generation add_test(NAME simple_witness_complex COMMAND ${CMAKE_CURRENT_BINARY_DIR}/Witness_complex_test_simple_witness_complex # XML format for Jenkins xUnit plugin --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/Witness_complex_test_simple_witness_complexUT.xml --log_level=test_suite --report_level=no) + +# CGAL and Eigen3 are required for Euclidean version of Witness +if(CGAL_FOUND) + if (NOT CGAL_VERSION VERSION_LESS 4.6.0) + if (EIGEN3_FOUND) + add_executable ( Witness_complex_test_euclidean_simple_witness_complex test_euclidean_simple_witness_complex.cpp ) + target_link_libraries(Witness_complex_test_euclidean_simple_witness_complex ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + if (TBB_FOUND) + target_link_libraries(Witness_complex_test_euclidean_simple_witness_complex ${TBB_LIBRARIES}) + endif(TBB_FOUND) + + # Unitary tests definition and xml result file generation + add_test(NAME euclidean_simple_witness_complex + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/Witness_complex_test_euclidean_simple_witness_complex + # XML format for Jenkins xUnit plugin + --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/Witness_complex_test_euclidean_simple_witness_complexUT.xml --log_level=test_suite --report_level=no) + endif(EIGEN3_FOUND) + endif (NOT CGAL_VERSION VERSION_LESS 4.6.0) +endif() diff --git a/src/Witness_complex/test/test_euclidean_simple_witness_complex.cpp b/src/Witness_complex/test/test_euclidean_simple_witness_complex.cpp new file mode 100644 index 00000000..62fd1157 --- /dev/null +++ b/src/Witness_complex/test/test_euclidean_simple_witness_complex.cpp @@ -0,0 +1,135 @@ +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE "euclidean_simple_witness_complex" +#include +#include + +#include + +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include + +typedef Gudhi::Simplex_tree<> Simplex_tree; +typedef typename Simplex_tree::Vertex_handle Vertex_handle; +typedef std::vector< Vertex_handle > typeVectorVertex; +typedef CGAL::Epick_d Kernel; +typedef typename Kernel::FT FT; +typedef typename Kernel::Point_d Point_d; +typedef Gudhi::witness_complex::Euclidean_witness_complex EuclideanWitnessComplex; +typedef Gudhi::witness_complex::Euclidean_strong_witness_complex EuclideanStrongWitnessComplex; + +typedef std::vector Point_range; +typedef Gudhi::spatial_searching::Kd_tree_search Kd_tree; +typedef Kd_tree::INS_range Nearest_landmark_range; +typedef std::vector Nearest_landmark_table; +typedef Gudhi::witness_complex::Witness_complex WitnessComplex; +typedef Gudhi::witness_complex::Strong_witness_complex StrongWitnessComplex; + + +/* All landmarks and witnesses are taken on the grid in the following manner. + LWLWL + WW.WW + L...L + WW.WW + LWLWL + + Witness complex consists of 8 vertices, 12 edges and 4 triangles + */ + +BOOST_AUTO_TEST_CASE(simple_witness_complex) { + Simplex_tree complex, relaxed_complex, strong_relaxed_complex, strong_relaxed_complex2; + Simplex_tree complex_ne, relaxed_complex_ne, strong_relaxed_complex_ne, strong_relaxed_complex2_ne; + + Point_range witnesses, landmarks; + + landmarks.push_back(Point_d(std::vector{-2,-2})); + landmarks.push_back(Point_d(std::vector{-2, 0})); + landmarks.push_back(Point_d(std::vector{-2, 2})); + landmarks.push_back(Point_d(std::vector{ 0,-2})); + landmarks.push_back(Point_d(std::vector{ 0, 2})); + landmarks.push_back(Point_d(std::vector{ 2,-2})); + landmarks.push_back(Point_d(std::vector{ 2, 0})); + landmarks.push_back(Point_d(std::vector{ 2, 2})); + witnesses.push_back(Point_d(std::vector{-2,-1})); + witnesses.push_back(Point_d(std::vector{-2, 1})); + witnesses.push_back(Point_d(std::vector{-1,-2})); + witnesses.push_back(Point_d(std::vector{-1,-1})); + witnesses.push_back(Point_d(std::vector{-1, 1})); + witnesses.push_back(Point_d(std::vector{-1, 2})); + witnesses.push_back(Point_d(std::vector{ 1,-2})); + witnesses.push_back(Point_d(std::vector{ 1,-1})); + witnesses.push_back(Point_d(std::vector{ 1, 1})); + witnesses.push_back(Point_d(std::vector{ 1, 2})); + witnesses.push_back(Point_d(std::vector{ 2,-1})); + witnesses.push_back(Point_d(std::vector{ 2, 1})); + + Kd_tree landmark_tree(landmarks); + Nearest_landmark_table nearest_landmark_table; + for (auto w: witnesses) + nearest_landmark_table.push_back(landmark_tree.query_incremental_nearest_neighbors(w)); + + // Weak witness complex: Euclidean version + EuclideanWitnessComplex eucl_witness_complex(landmarks, + witnesses); + eucl_witness_complex.create_complex(complex, 0); + + std::cout << "complex.num_simplices() = " << complex.num_simplices() << std::endl; + BOOST_CHECK(complex.num_simplices() == 24); + + eucl_witness_complex.create_complex(relaxed_complex, 8.01); + + std::cout << "relaxed_complex.num_simplices() = " << relaxed_complex.num_simplices() << std::endl; + BOOST_CHECK(relaxed_complex.num_simplices() == 239); + // The corner simplex {0,2,5,7} and its cofaces are missing. + + // Weak witness complex: non-Euclidean version + WitnessComplex witness_complex(nearest_landmark_table); + witness_complex.create_complex(complex_ne, 0); + + std::cout << "complex.num_simplices() = " << complex_ne.num_simplices() << std::endl; + BOOST_CHECK(complex_ne.num_simplices() == 24); + + witness_complex.create_complex(relaxed_complex_ne, 8.01); + + std::cout << "relaxed_complex.num_simplices() = " << relaxed_complex_ne.num_simplices() << std::endl; + BOOST_CHECK(relaxed_complex_ne.num_simplices() == 239); + + + // Strong complex : Euclidean version + EuclideanStrongWitnessComplex eucl_strong_witness_complex(landmarks, + witnesses); + + eucl_strong_witness_complex.create_complex(strong_relaxed_complex, 9.1); + eucl_strong_witness_complex.create_complex(strong_relaxed_complex2, 9.1, 2); + + std::cout << "strong_relaxed_complex.num_simplices() = " << strong_relaxed_complex.num_simplices() << std::endl; + BOOST_CHECK(strong_relaxed_complex.num_simplices() == 239); + + std::cout << "strong_relaxed_complex2.num_simplices() = " << strong_relaxed_complex2.num_simplices() << std::endl; + BOOST_CHECK(strong_relaxed_complex2.num_simplices() == 92); + + + // Strong complex : non-Euclidean version + StrongWitnessComplex strong_witness_complex(nearest_landmark_table); + + strong_witness_complex.create_complex(strong_relaxed_complex_ne, 9.1); + strong_witness_complex.create_complex(strong_relaxed_complex2_ne, 9.1, 2); + + std::cout << "strong_relaxed_complex.num_simplices() = " << strong_relaxed_complex_ne.num_simplices() << std::endl; + BOOST_CHECK(strong_relaxed_complex_ne.num_simplices() == 239); + + std::cout << "strong_relaxed_complex2.num_simplices() = " << strong_relaxed_complex2_ne.num_simplices() << std::endl; + BOOST_CHECK(strong_relaxed_complex2_ne.num_simplices() == 92); + + + // 8 vertices, 28 edges, 56 triangles +} diff --git a/src/Witness_complex/test/test_simple_witness_complex.cpp b/src/Witness_complex/test/test_simple_witness_complex.cpp index bb1df72d..9e3509d3 100644 --- a/src/Witness_complex/test/test_simple_witness_complex.cpp +++ b/src/Witness_complex/test/test_simple_witness_complex.cpp @@ -3,133 +3,51 @@ #include #include -#include - #include #include -#include -#include -#include - -#include #include -#include #include +#include -typedef Gudhi::Simplex_tree<> Simplex_tree; -typedef typename Simplex_tree::Vertex_handle Vertex_handle; -typedef std::vector< Vertex_handle > typeVectorVertex; -typedef CGAL::Epick_d Kernel; -typedef typename Kernel::FT FT; -typedef typename Kernel::Point_d Point_d; -typedef Gudhi::witness_complex::Euclidean_witness_complex EuclideanWitnessComplex; -typedef Gudhi::witness_complex::Euclidean_strong_witness_complex EuclideanStrongWitnessComplex; - -typedef std::vector Point_range; -typedef Gudhi::spatial_searching::Kd_tree_search Kd_tree; -typedef Kd_tree::INS_range Nearest_landmark_range; -typedef std::vector Nearest_landmark_table; -typedef Gudhi::witness_complex::Witness_complex WitnessComplex; -typedef Gudhi::witness_complex::Strong_witness_complex StrongWitnessComplex; - - -/* All landmarks and witnesses are taken on the grid in the following manner. - LWLWL - WW.WW - L...L - WW.WW - LWLWL - - Witness complex consists of 8 vertices, 12 edges and 4 triangles - */ BOOST_AUTO_TEST_CASE(simple_witness_complex) { - Simplex_tree complex, relaxed_complex, strong_relaxed_complex, strong_relaxed_complex2; - Simplex_tree complex_ne, relaxed_complex_ne, strong_relaxed_complex_ne, strong_relaxed_complex2_ne; - - Point_range witnesses, landmarks; - - landmarks.push_back(Point_d(std::vector{-2,-2})); - landmarks.push_back(Point_d(std::vector{-2, 0})); - landmarks.push_back(Point_d(std::vector{-2, 2})); - landmarks.push_back(Point_d(std::vector{ 0,-2})); - landmarks.push_back(Point_d(std::vector{ 0, 2})); - landmarks.push_back(Point_d(std::vector{ 2,-2})); - landmarks.push_back(Point_d(std::vector{ 2, 0})); - landmarks.push_back(Point_d(std::vector{ 2, 2})); - witnesses.push_back(Point_d(std::vector{-2,-1})); - witnesses.push_back(Point_d(std::vector{-2, 1})); - witnesses.push_back(Point_d(std::vector{-1,-2})); - witnesses.push_back(Point_d(std::vector{-1,-1})); - witnesses.push_back(Point_d(std::vector{-1, 1})); - witnesses.push_back(Point_d(std::vector{-1, 2})); - witnesses.push_back(Point_d(std::vector{ 1,-2})); - witnesses.push_back(Point_d(std::vector{ 1,-1})); - witnesses.push_back(Point_d(std::vector{ 1, 1})); - witnesses.push_back(Point_d(std::vector{ 1, 2})); - witnesses.push_back(Point_d(std::vector{ 2,-1})); - witnesses.push_back(Point_d(std::vector{ 2, 1})); - - Kd_tree landmark_tree(landmarks); - Nearest_landmark_table nearest_landmark_table; - for (auto w: witnesses) - nearest_landmark_table.push_back(landmark_tree.query_incremental_nearest_neighbors(w)); - - // Weak witness complex: Euclidean version - EuclideanWitnessComplex eucl_witness_complex(landmarks, - witnesses); - eucl_witness_complex.create_complex(complex, 0); - - std::cout << "complex.num_simplices() = " << complex.num_simplices() << std::endl; - BOOST_CHECK(complex.num_simplices() == 24); - - eucl_witness_complex.create_complex(relaxed_complex, 8.01); - - std::cout << "relaxed_complex.num_simplices() = " << relaxed_complex.num_simplices() << std::endl; - BOOST_CHECK(relaxed_complex.num_simplices() == 239); - // The corner simplex {0,2,5,7} and its cofaces are missing. - - // Weak witness complex: non-Euclidean version - WitnessComplex witness_complex(nearest_landmark_table); - witness_complex.create_complex(complex_ne, 0); - - std::cout << "complex.num_simplices() = " << complex_ne.num_simplices() << std::endl; - BOOST_CHECK(complex_ne.num_simplices() == 24); - - witness_complex.create_complex(relaxed_complex_ne, 8.01); - - std::cout << "relaxed_complex.num_simplices() = " << relaxed_complex_ne.num_simplices() << std::endl; - BOOST_CHECK(relaxed_complex_ne.num_simplices() == 239); - - - // Strong complex : Euclidean version - EuclideanStrongWitnessComplex eucl_strong_witness_complex(landmarks, - witnesses); - - eucl_strong_witness_complex.create_complex(strong_relaxed_complex, 9.1); - eucl_strong_witness_complex.create_complex(strong_relaxed_complex2, 9.1, 2); - - std::cout << "strong_relaxed_complex.num_simplices() = " << strong_relaxed_complex.num_simplices() << std::endl; - BOOST_CHECK(strong_relaxed_complex.num_simplices() == 239); - - std::cout << "strong_relaxed_complex2.num_simplices() = " << strong_relaxed_complex2.num_simplices() << std::endl; - BOOST_CHECK(strong_relaxed_complex2.num_simplices() == 92); - - - // Strong complex : non-Euclidean version - StrongWitnessComplex strong_witness_complex(nearest_landmark_table); - - strong_witness_complex.create_complex(strong_relaxed_complex_ne, 9.1); - strong_witness_complex.create_complex(strong_relaxed_complex2_ne, 9.1, 2); - - std::cout << "strong_relaxed_complex.num_simplices() = " << strong_relaxed_complex_ne.num_simplices() << std::endl; - BOOST_CHECK(strong_relaxed_complex_ne.num_simplices() == 239); - - std::cout << "strong_relaxed_complex2.num_simplices() = " << strong_relaxed_complex2_ne.num_simplices() << std::endl; - BOOST_CHECK(strong_relaxed_complex2_ne.num_simplices() == 92); - + using Nearest_landmark_range = std::vector>; + using Nearest_landmark_table = std::vector; + using Witness_complex = Gudhi::witness_complex::Witness_complex; + using Simplex_tree = Gudhi::Simplex_tree<>; + + Simplex_tree stree; + Nearest_landmark_table nlt; + + // Example contains 5 witnesses and 5 landmarks + Nearest_landmark_range w0 = {std::make_pair(0, 0), std::make_pair(1, 1), std::make_pair(2, 2), + std::make_pair(3, 3), std::make_pair(4, 4)}; nlt.push_back(w0); + Nearest_landmark_range w1 = {std::make_pair(1, 0), std::make_pair(2, 1), std::make_pair(3, 2), + std::make_pair(4, 3), std::make_pair(0, 4)}; nlt.push_back(w1); + Nearest_landmark_range w2 = {std::make_pair(2, 0), std::make_pair(3, 1), std::make_pair(4, 2), + std::make_pair(0, 3), std::make_pair(1, 4)}; nlt.push_back(w2); + Nearest_landmark_range w3 = {std::make_pair(3, 0), std::make_pair(4, 1), std::make_pair(0, 2), + std::make_pair(1, 3), std::make_pair(2, 4)}; nlt.push_back(w3); + Nearest_landmark_range w4 = {std::make_pair(4, 0), std::make_pair(0, 1), std::make_pair(1, 2), + std::make_pair(2, 3), std::make_pair(3, 4)}; nlt.push_back(w4); + + Witness_complex witness_complex(nlt); + BOOST_CHECK(witness_complex.create_complex(stree, 4.1)); + + std::cout << "Number of simplices: " << stree.num_simplices() << std::endl; + BOOST_CHECK(stree.num_simplices() == 31); + + // Check when complex not empty + BOOST_CHECK(!witness_complex.create_complex(stree, 4.1)); + + // Check when max_alpha_square negative + Simplex_tree stree2; + BOOST_CHECK(!witness_complex.create_complex(stree2, -0.02)); + + witness_complex.create_complex(stree2, 4.1, 2); + std::cout << "Number of simplices: " << stree2.num_simplices() << std::endl; + BOOST_CHECK(stree2.num_simplices() == 25); - // 8 vertices, 28 edges, 56 triangles } -- cgit v1.2.3