writing_persistence_to_file.h
1 /* This file is part of the Gudhi Library. The Gudhi library
2  * (Geometric Understanding in Higher Dimensions) is a generic C++
3  * library for computational topology.
4  *
5  * Author(s): Pawel Dlotko
6  *
7  * Copyright (C) 2017 Swansea University, UK
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef WRITING_PERSISTENCE_TO_FILE_H_
24 #define WRITING_PERSISTENCE_TO_FILE_H_
25 
26 #include <iostream>
27 #include <string>
28 #include <limits>
29 
30 namespace Gudhi {
31 
37 template <typename Filtration_type, typename Coefficient_field>
39  public:
43  Persistence_interval_common(Filtration_type birth, Filtration_type death)
44  : birth_(birth),
45  death_(death),
46  dimension_(std::numeric_limits<unsigned>::max()),
47  arith_element_(std::numeric_limits<Coefficient_field>::max()) {}
48 
52  Persistence_interval_common(Filtration_type birth, Filtration_type death, unsigned dim)
53  : birth_(birth), death_(death), dimension_(dim), arith_element_(std::numeric_limits<Coefficient_field>::max()) {}
54 
59  Persistence_interval_common(Filtration_type birth, Filtration_type death, unsigned dim, Coefficient_field field)
60  : birth_(birth), death_(death), dimension_(dim), arith_element_(field) {}
61 
67  bool operator==(const Persistence_interval_common& i2) const {
68  return ((this->birth_ == i2.birth_) && (this->death_ == i2.death_) && (this->dimension_ == i2.dimension_) &&
69  (this->arith_element_ == i2.arith_element_));
70  }
71 
75  bool operator!=(const Persistence_interval_common& i2) const { return (!((*this) == i2)); }
76 
82  bool operator<(const Persistence_interval_common& i2) const {
83  return fabs(this->death_ - this->birth_) < fabs(i2.death_ - i2.birth_);
84  }
85 
86  friend std::ostream& operator<<(std::ostream& out, const Persistence_interval_common& it) {
87  if (it.arith_element_ != std::numeric_limits<Coefficient_field>::max()) {
88  out << it.arith_element_ << " ";
89  }
90  if (it.dimension_ != std::numeric_limits<unsigned>::max()) {
91  out << it.dimension_ << " ";
92  }
93  out << it.birth_ << " " << it.death_ << " ";
94  return out;
95  }
96 
97  private:
98  Filtration_type birth_;
99  Filtration_type death_;
100  unsigned dimension_;
101  Coefficient_field arith_element_;
102 };
103 
107 template <typename Persistence_interval_range>
108 void write_persistence_intervals_to_stream(const Persistence_interval_range& intervals,
109  std::ostream& out = std::cout) {
110  for (auto interval : intervals) {
111  out << interval << "\n";
112  }
113 }
114 
115 } // namespace Gudhi
116 
117 #endif // WRITING_PERSISTENCE_TO_FILE_H_
Persistence_interval_common(Filtration_type birth, Filtration_type death)
Definition: writing_persistence_to_file.h:43
Definition: SimplicialComplexForAlpha.h:26
bool operator<(const Persistence_interval_common &i2) const
Definition: writing_persistence_to_file.h:82
Persistence_interval_common(Filtration_type birth, Filtration_type death, unsigned dim, Coefficient_field field)
Definition: writing_persistence_to_file.h:59
Definition: writing_persistence_to_file.h:38
void write_persistence_intervals_to_stream(const Persistence_interval_range &intervals, std::ostream &out=std::cout)
Definition: writing_persistence_to_file.h:108
bool operator==(const Persistence_interval_common &i2) const
Definition: writing_persistence_to_file.h:67
Persistence_interval_common(Filtration_type birth, Filtration_type death, unsigned dim)
Definition: writing_persistence_to_file.h:52
bool operator!=(const Persistence_interval_common &i2) const
Definition: writing_persistence_to_file.h:75
GUDHI  Version 2.2.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : GPL v3 Generated on Thu Jun 14 2018 15:00:55 for GUDHI by Doxygen 1.8.13