diff options
author | ROUVREAU Vincent <vincent.rouvreau@inria.fr> | 2020-04-06 23:40:29 +0200 |
---|---|---|
committer | ROUVREAU Vincent <vincent.rouvreau@inria.fr> | 2020-04-06 23:40:29 +0200 |
commit | 599e910811e1c4c743a61be65e089e798f578d4a (patch) | |
tree | 67114c4b856850b462c8cd0996119ee5da89f051 /src/Collapse | |
parent | 076cc203005373ddcb58055af3db604240157601 (diff) |
Remove rips edge list first part
Diffstat (limited to 'src/Collapse')
-rw-r--r-- | src/Collapse/include/gudhi/Flag_complex_sparse_matrix.h | 40 | ||||
-rw-r--r-- | src/Collapse/utilities/point_cloud_edge_collapse_rips_persistence.cpp | 39 |
2 files changed, 58 insertions, 21 deletions
diff --git a/src/Collapse/include/gudhi/Flag_complex_sparse_matrix.h b/src/Collapse/include/gudhi/Flag_complex_sparse_matrix.h index 786a970a..d7014f2f 100644 --- a/src/Collapse/include/gudhi/Flag_complex_sparse_matrix.h +++ b/src/Collapse/include/gudhi/Flag_complex_sparse_matrix.h @@ -12,8 +12,15 @@ #define FLAG_COMPLEX_SPARSE_MATRIX_H_ #include <gudhi/Rips_edge_list.h> +#include <gudhi/graph_simplicial_complex.h> + #include <boost/functional/hash.hpp> -// #include <boost/graph/adjacency_list.hpp> + +#include <Eigen/Sparse> + +#ifdef GUDHI_USE_TBB +#include <tbb/parallel_sort.h> +#endif #include <iostream> #include <utility> @@ -28,8 +35,6 @@ #include <ctime> #include <fstream> -#include <Eigen/Sparse> - typedef std::size_t Vertex; using Edge = std::pair<Vertex, Vertex>; // This is an ordered pair, An edge is stored with convention of the first // element being the smaller i.e {2,3} not {3,2}. However this is at the level @@ -319,6 +324,35 @@ class Flag_complex_sparse_matrix { } } + template<typename OneSkeletonGraph> + Flag_complex_sparse_matrix(const OneSkeletonGraph& one_skeleton_graph) + : rows(0), + edgeCollapsed(false) { + // Insert all vertices + for (auto v_it = boost::vertices(one_skeleton_graph); v_it.first != v_it.second; ++v_it.first) { + vertices.emplace(*(v_it.first)); + } + // Insert all edges + for (auto edge_it = boost::edges(one_skeleton_graph); + edge_it.first != edge_it.second; ++edge_it.first) { + auto edge = *(edge_it.first); + Vertex u = source(edge, one_skeleton_graph); + Vertex v = target(edge, one_skeleton_graph); + f_edge_vector.push_back({{u, v}, boost::get(Gudhi::edge_filtration_t(), one_skeleton_graph, edge)}); + } + // Sort edges + auto sort_by_filtration = [](const EdgeFilt& edge_a, const EdgeFilt& edge_b) -> bool + { + return (get<1>(edge_a) < get<1>(edge_b)); + }; + +#ifdef GUDHI_USE_TBB + tbb::parallel_sort(f_edge_vector.begin(), f_edge_vector.end(), sort_by_filtration); +#else + std::stable_sort(f_edge_vector.begin(), f_edge_vector.end(), sort_by_filtration); +#endif + } + // Performs edge collapse in a decreasing sequence of the filtration value. Filtered_sorted_edge_list filtered_edge_collapse() { std::size_t endIdx = 0; diff --git a/src/Collapse/utilities/point_cloud_edge_collapse_rips_persistence.cpp b/src/Collapse/utilities/point_cloud_edge_collapse_rips_persistence.cpp index e3290b7a..a2840674 100644 --- a/src/Collapse/utilities/point_cloud_edge_collapse_rips_persistence.cpp +++ b/src/Collapse/utilities/point_cloud_edge_collapse_rips_persistence.cpp @@ -6,23 +6,29 @@ #include <gudhi/distance_functions.h> #include <gudhi/reader_utils.h> #include <gudhi/Points_off_io.h> +#include <gudhi/graph_simplicial_complex.h> -#include <CGAL/Epick_d.h> - +#include <boost/graph/adjacency_list.hpp> #include <boost/program_options.hpp> // Types definition -using Point = CGAL::Epick_d<CGAL::Dynamic_dimension_tag>::Point_d; + +using Simplex_tree = Gudhi::Simplex_tree<>; +using Filtration_value = Simplex_tree::Filtration_value; +using Point = std::vector<Filtration_value>; using Vector_of_points = std::vector<Point>; -using Simplex_tree = Gudhi::Simplex_tree<Gudhi::Simplex_tree_options_fast_persistence>; -using Filtration_value = double; + using Rips_complex = Gudhi::rips_complex::Rips_complex<Filtration_value>; using Rips_edge_list = Gudhi::rips_edge_list::Rips_edge_list<Filtration_value>; using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology<Simplex_tree, Field_Zp>; using Distance_matrix = std::vector<std::vector<Filtration_value>>; +using Adjacency_list = boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, + boost::property<Gudhi::vertex_filtration_t, double>, + boost::property<Gudhi::edge_filtration_t, double>>; + class filt_edge_to_dist_matrix { public: @@ -92,30 +98,27 @@ int main(int argc, char* argv[]) { exit(-1); // ----- >> } - int dimension = point_vector[0].dimension(); + //int dimension = point_vector[0].dimension(); number_of_points = point_vector.size(); std::cout << "Successfully read " << number_of_points << " point_vector.\n"; - std::cout << "Ambient dimension is " << dimension << ".\n"; + //std::cout << "Ambient dimension is " << dimension << ".\n"; std::cout << "Point Set Generated." << std::endl; - Filtered_sorted_edge_list edge_t; - std::cout << "Computing the one-skeleton for threshold: " << threshold << std::endl; - - Rips_edge_list Rips_edge_list_from_file(point_vector, threshold, Gudhi::Euclidean_distance()); - Rips_edge_list_from_file.create_edges(edge_t); - - std::cout << "Sorted edge list computed" << std::endl; - std::cout << "Total number of edges before collapse are: " << edge_t.size() << std::endl; + Adjacency_list proximity_graph = Gudhi::compute_proximity_graph<Simplex_tree>(off_reader.get_point_cloud(), + threshold, + Gudhi::Euclidean_distance()); - if (edge_t.size() <= 0) { + if (num_edges(proximity_graph) <= 0) { std::cerr << "Total number of egdes are zero." << std::endl; exit(-1); } - // Now we will perform filtered edge collapse to sparsify the edge list edge_t. std::cout << "Filtered edge collapse begins" << std::endl; - Flag_complex_sparse_matrix mat_filt_edge_coll(edge_t); + Flag_complex_sparse_matrix mat_filt_edge_coll(proximity_graph); + + std::cout << "Computing the one-skeleton for threshold: " << threshold << std::endl; + std::cout << "Matrix instansiated" << std::endl; Filtered_sorted_edge_list collapse_edges; collapse_edges = mat_filt_edge_coll.filtered_edge_collapse(); |