From c6ab4a62da2572b51032995266c109df7fe76dfd Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Fri, 18 Nov 2016 17:21:46 +0000 Subject: Add distance matrix read from csv files Distance template instead of Point_d for distance matrices git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/distance_matrix_in_rips_module@1762 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 695bead714228c57e1be1650048125aa0b841683 --- src/Rips_complex/include/gudhi/Rips_complex.h | 89 ++++++++++++++++----------- 1 file changed, 53 insertions(+), 36 deletions(-) (limited to 'src/Rips_complex/include/gudhi/Rips_complex.h') diff --git a/src/Rips_complex/include/gudhi/Rips_complex.h b/src/Rips_complex/include/gudhi/Rips_complex.h index da755b7c..6f947f41 100644 --- a/src/Rips_complex/include/gudhi/Rips_complex.h +++ b/src/Rips_complex/include/gudhi/Rips_complex.h @@ -2,7 +2,7 @@ * (Geometric Understanding in Higher Dimensions) is a generic C++ * library for computational topology. * - * Author(s): Clément Maria, Vincent Rouvreau + * Author(s): Clément Maria, Pawel Dlotko, Vincent Rouvreau * * Copyright (C) 2016 INRIA * @@ -58,12 +58,13 @@ template class Rips_complex { private: typedef typename boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS - , boost::property < vertex_filtration_t, Filtration_value > - , boost::property < edge_filtration_t, Filtration_value >> Graph_t; - + , boost::property < vertex_filtration_t, Filtration_value > + , boost::property < edge_filtration_t, Filtration_value >> Graph_t; + typedef int Vertex_handle; - + public: + /** \brief Rips_complex constructor from a list of points. * * @param[in] points Range of points. @@ -72,9 +73,51 @@ class Rips_complex { * * The type InputPointRange must be a range for which std::begin and std::end return input iterators on a point. */ - template - Rips_complex(const InputPointRange& points, Filtration_value threshold, - Filtration_value distance(const Point_d& p1,const Point_d& p2)) { + template + Rips_complex(const InputPointRange& points, Filtration_value threshold, Distance distance) { + compute_proximity_graph(points, threshold, distance); + } + + /** \brief Initializes the simplicial complex from the 1-skeleton graph and expands it until a given maximal + * dimension. + * + * \tparam SimplicialComplexForRips must meet `SimplicialComplexForRips` concept. + * + * @param[in] complex SimplicialComplexForRips to be created. + * @param[in] dim_max graph expansion for rips until this given maximal dimension. + * + * @return true if creation succeeds, false otherwise. + * + */ + template + bool create_complex(SimplicialComplexForRips& complex, int dim_max) { + if (complex.num_vertices() > 0) { + std::cerr << "Rips_complex create_complex - complex is not empty\n"; + return false; // ----- >> + } + + // insert the proximity graph in the simplicial complex + complex.insert_graph(rips_skeleton_graph_); + // expand the graph until dimension dim_max + complex.expansion(dim_max); + + // -------------------------------------------------------------------------------------------- + return true; + } + + public: + /** \brief Output the proximity graph of the points. + * + * If points contains n elements, the proximity graph is the graph + * with n vertices, and an edge [u,v] iff the distance function between + * points u and v is smaller than threshold. + * + * The type PointCloud furnishes .begin() and .end() methods, that return + * iterators with value_type Point. + */ + template< typename InputPointRange, typename Distance > + void compute_proximity_graph(const InputPointRange& points, Filtration_value threshold, + Distance distance) { std::vector< std::pair< Vertex_handle, Vertex_handle > > edges; std::vector< Filtration_value > edges_fil; std::map< Vertex_handle, Filtration_value > vertices; @@ -102,7 +145,7 @@ class Rips_complex { // -------------------------------------------------------------------------------------------- // Creates the proximity graph from edges and sets the property with the filtration value. // Number of points is labeled from 0 to idx_u-1 - rips_skeleton_graph_ = Graph_t(edges.begin() , edges.end() , edges_fil.begin() , idx_u); + rips_skeleton_graph_ = Graph_t(edges.begin(), edges.end(), edges_fil.begin(), idx_u); auto vertex_prop = boost::get(vertex_filtration_t(), rips_skeleton_graph_); @@ -112,37 +155,11 @@ class Rips_complex { vi != vi_end; ++vi) { boost::put(vertex_prop, *vi, 0.); } - } - /** \brief Initializes the simplicial complex from the 1-skeleton graph and expands it until a given maximal - * dimension. - * - * \tparam SimplicialComplexForRips must meet `SimplicialComplexForRips` concept. - * - * @param[in] complex SimplicialComplexForRips to be created. - * @param[in] dim_max graph expansion for rips until this given maximal dimension. - * - * @return true if creation succeeds, false otherwise. - * - */ - template - bool create_complex(SimplicialComplexForRips& complex, int dim_max) { - if (complex.num_vertices() > 0) { - std::cerr << "Rips_complex create_complex - complex is not empty\n"; - return false; // ----- >> - } - - // insert the proximity graph in the simplicial complex - complex.insert_graph(rips_skeleton_graph_); - // expand the graph until dimension dim_max - complex.expansion(dim_max); - - // -------------------------------------------------------------------------------------------- - return true; - } private: Graph_t rips_skeleton_graph_; + }; } // namespace rips_complex -- cgit v1.2.3