diff options
author | skachano <skachano@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2015-12-07 14:45:43 +0000 |
---|---|---|
committer | skachano <skachano@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2015-12-07 14:45:43 +0000 |
commit | c4078affdbf6fac7150c10ade96fcb72270ac013 (patch) | |
tree | 1ad197bb90078a56036a49c6ee3766a032f85e63 /src/common/include/gudhi/reader_utils.h | |
parent | f70e386fc98f1dbd8287d1cb7cc715710a8f751b (diff) | |
parent | 061e43a2a48525bc5a69482a1ea80f20ff505e55 (diff) |
Merged with trunk and removed unnecessary files
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/witness@934 636b058d-ea47-450e-bf9e-a15bfbe3eedb
Former-commit-id: d0ec52d222d22c102e9fe57590882cd0024c82d5
Diffstat (limited to 'src/common/include/gudhi/reader_utils.h')
-rw-r--r-- | src/common/include/gudhi/reader_utils.h | 193 |
1 files changed, 104 insertions, 89 deletions
diff --git a/src/common/include/gudhi/reader_utils.h b/src/common/include/gudhi/reader_utils.h index ab12c268..e05714c7 100644 --- a/src/common/include/gudhi/reader_utils.h +++ b/src/common/include/gudhi/reader_utils.h @@ -1,32 +1,38 @@ - /* 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): Clément Maria - * - * Copyright (C) 2014 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 <http://www.gnu.org/licenses/>. - */ - -#ifndef GUDHI_READER_UTILS_H -#define GUDHI_READER_UTILS_H +/* 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): Clément Maria + * + * Copyright (C) 2014 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef READER_UTILS_H_ +#define READER_UTILS_H_ + +#include <gudhi/graph_simplicial_complex.h> + +#include <boost/graph/adjacency_list.hpp> #include <iostream> #include <fstream> -#include <boost/graph/adjacency_list.hpp> -#include "gudhi/graph_simplicial_complex.h" +#include <map> +#include <limits> // for numeric_limits<> +#include <string> +#include <vector> /** * \brief Read a set of points to turn it @@ -37,22 +43,21 @@ * X21 X22 ... X2d * etc */ -inline void -read_points ( std::string file_name - , std::vector< std::vector< double > > & points) -{ - std::ifstream in_file (file_name.c_str(),std::ios::in); - if(!in_file.is_open()) { +inline void read_points(std::string file_name, std::vector< std::vector< double > > & points) { + std::ifstream in_file(file_name.c_str(), std::ios::in); + if (!in_file.is_open()) { std::cerr << "Unable to open file " << file_name << std::endl; - return;} + return; + } std::string line; double x; - while( getline ( in_file , line ) ) - { + while (getline(in_file, line)) { std::vector< double > point; - std::istringstream iss( line ); - while(iss >> x) { point.push_back(x); } + std::istringstream iss(line); + while (iss >> x) { + point.push_back(x); + } points.push_back(point); } in_file.close(); @@ -70,53 +75,64 @@ read_points ( std::string file_name * Every simplex must appear exactly once. * Simplices of dimension more than 1 are ignored. */ -inline Graph_t -read_graph ( std::string file_name ) -{ - std::ifstream in_ (file_name.c_str(),std::ios::in); - if(!in_.is_open()) { std::cerr << "Unable to open file " << file_name << std::endl; } - - std::vector< Edge_t > edges; - std::vector< Filtration_value > edges_fil; +inline Graph_t read_graph(std::string file_name) { + std::ifstream in_(file_name.c_str(), std::ios::in); + if (!in_.is_open()) { + std::cerr << "Unable to open file " << file_name << std::endl; + } + + std::vector< Edge_t > edges; + std::vector< Filtration_value > edges_fil; std::map< Vertex_handle, Filtration_value > vertices; - - std::string line; - int dim; - Vertex_handle u,v,max_h = -1; + + std::string line; + int dim; + Vertex_handle u, v, max_h = -1; Filtration_value fil; - while( getline ( in_ , line ) ) - { - std::istringstream iss( line ); - while(iss >> dim) { - switch ( dim ) { - case 0 : { - iss >> u; iss >> fil; + while (getline(in_, line)) { + std::istringstream iss(line); + while (iss >> dim) { + switch (dim) { + case 0: + { + iss >> u; + iss >> fil; vertices[u] = fil; - if(max_h < u) { max_h = u; } + if (max_h < u) { + max_h = u; + } break; } - case 1 : { - iss >> u; iss >> v; iss >> fil; - edges.push_back(Edge_t(u,v)); + case 1: + { + iss >> u; + iss >> v; + iss >> fil; + edges.push_back(Edge_t(u, v)); edges_fil.push_back(fil); break; } - default: {break;} - } + default: + { + break; + } + } } } in_.close(); - if((size_t)(max_h+1) != vertices.size()) - { std::cerr << "Error: vertices must be labeled from 0 to n-1 \n"; } + if ((size_t) (max_h + 1) != vertices.size()) { + std::cerr << "Error: vertices must be labeled from 0 to n-1 \n"; + } - Graph_t skel_graph(edges.begin(),edges.end(),edges_fil.begin(),vertices.size()); - auto vertex_prop = boost::get(vertex_filtration_t(),skel_graph); + Graph_t skel_graph(edges.begin(), edges.end(), edges_fil.begin(), vertices.size()); + auto vertex_prop = boost::get(vertex_filtration_t(), skel_graph); boost::graph_traits<Graph_t>::vertex_iterator vi, vi_end; auto v_it = vertices.begin(); - for (std::tie(vi, vi_end) = boost::vertices(skel_graph); vi != vi_end; ++vi,++v_it) - { boost::put(vertex_prop, *vi, v_it->second); } + for (std::tie(vi, vi_end) = boost::vertices(skel_graph); vi != vi_end; ++vi, ++v_it) { + boost::put(vertex_prop, *vi, v_it->second); + } return skel_graph; } @@ -133,17 +149,15 @@ read_graph ( std::string file_name ) * Every simplex must appear exactly once. * Simplices of dimension more than 1 are ignored. */ -template< typename Vertex_handle - , typename Filtration_value > -bool read_simplex ( std::istream & in_ - , std::vector< Vertex_handle > & simplex - , Filtration_value & fil ) -{ - int dim=0; - if(!(in_ >> dim)) return false; +template< typename Vertex_handle, typename Filtration_value > +bool read_simplex(std::istream & in_, std::vector< Vertex_handle > & simplex, Filtration_value & fil) { + int dim = 0; + if (!(in_ >> dim)) return false; Vertex_handle v; - for(int i=0; i<dim+1; ++i) - { in_ >> v; simplex.push_back(v); } + for (int i = 0; i < dim + 1; ++i) { + in_ >> v; + simplex.push_back(v); + } in_ >> fil; in_.ignore((std::numeric_limits<std::streamsize>::max)(), '\n'); // ignore until the carriage return return true; @@ -162,20 +176,21 @@ bool read_simplex ( std::istream & in_ * Dimi ki1 ki2 ... kiDimi Fili means that the ith simplex in the * filtration has dimension Dimi, filtration value fil1 and simplices with * key ki1 ... kiDimi in its boundary.*/ -template< typename Simplex_key - , typename Filtration_value > -bool read_hasse_simplex ( std::istream & in_ - , std::vector< Simplex_key > & boundary - , Filtration_value & fil ) -{ +template< typename Simplex_key, typename Filtration_value > +bool read_hasse_simplex(std::istream & in_, std::vector< Simplex_key > & boundary, Filtration_value & fil) { int dim; - if(!(in_ >> dim)) return false; - if(dim == 0) {in_ >> fil; return true;} + if (!(in_ >> dim)) return false; + if (dim == 0) { + in_ >> fil; + return true; + } Simplex_key key; - for(int i=0; i<dim+1; ++i) - { in_ >> key; boundary.push_back(key); } + for (int i = 0; i < dim + 1; ++i) { + in_ >> key; + boundary.push_back(key); + } in_ >> fil; return true; } -#endif // GUDHI_READER_UTILS_H +#endif // READER_UTILS_H_ |