writing_persistence_to_file.h
1 /* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
2  * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
3  * Author(s): Pawel Dlotko
4  *
5  * Copyright (C) 2017 Swansea University, UK
6  *
7  * Modification(s):
8  * - YYYY/MM Author: Description of the modification
9  */
10 
11 #ifndef WRITING_PERSISTENCE_TO_FILE_H_
12 #define WRITING_PERSISTENCE_TO_FILE_H_
13 
14 #include <iostream>
15 #include <string>
16 #include <limits>
17 
18 namespace Gudhi {
19 
25 template <typename Filtration_type, typename Coefficient_field>
27  public:
31  Persistence_interval_common(Filtration_type birth, Filtration_type death)
32  : birth_(birth),
33  death_(death),
34  dimension_(std::numeric_limits<unsigned>::max()),
35  arith_element_(std::numeric_limits<Coefficient_field>::max()) {}
36 
40  Persistence_interval_common(Filtration_type birth, Filtration_type death, unsigned dim)
41  : birth_(birth), death_(death), dimension_(dim), arith_element_(std::numeric_limits<Coefficient_field>::max()) {}
42 
47  Persistence_interval_common(Filtration_type birth, Filtration_type death, unsigned dim, Coefficient_field field)
48  : birth_(birth), death_(death), dimension_(dim), arith_element_(field) {}
49 
55  bool operator==(const Persistence_interval_common& i2) const {
56  return ((this->birth_ == i2.birth_) && (this->death_ == i2.death_) && (this->dimension_ == i2.dimension_) &&
57  (this->arith_element_ == i2.arith_element_));
58  }
59 
63  bool operator!=(const Persistence_interval_common& i2) const { return (!((*this) == i2)); }
64 
70  bool operator<(const Persistence_interval_common& i2) const {
71  return fabs(this->death_ - this->birth_) < fabs(i2.death_ - i2.birth_);
72  }
73 
74  friend std::ostream& operator<<(std::ostream& out, const Persistence_interval_common& it) {
75  if (it.arith_element_ != std::numeric_limits<Coefficient_field>::max()) {
76  out << it.arith_element_ << " ";
77  }
78  if (it.dimension_ != std::numeric_limits<unsigned>::max()) {
79  out << it.dimension_ << " ";
80  }
81  out << it.birth_ << " " << it.death_ << " ";
82  return out;
83  }
84 
85  private:
86  Filtration_type birth_;
87  Filtration_type death_;
88  unsigned dimension_;
89  Coefficient_field arith_element_;
90 };
91 
95 template <typename Persistence_interval_range>
96 void write_persistence_intervals_to_stream(const Persistence_interval_range& intervals,
97  std::ostream& out = std::cout) {
98  for (auto interval : intervals) {
99  out << interval << "\n";
100  }
101 }
102 
103 } // namespace Gudhi
104 
105 #endif // WRITING_PERSISTENCE_TO_FILE_H_
Definition: writing_persistence_to_file.h:26
bool operator==(const Persistence_interval_common &i2) const
Definition: writing_persistence_to_file.h:55
bool operator!=(const Persistence_interval_common &i2) const
Definition: writing_persistence_to_file.h:63
bool operator<(const Persistence_interval_common &i2) const
Definition: writing_persistence_to_file.h:70
Persistence_interval_common(Filtration_type birth, Filtration_type death)
Definition: writing_persistence_to_file.h:31
Persistence_interval_common(Filtration_type birth, Filtration_type death, unsigned dim)
Definition: writing_persistence_to_file.h:40
Persistence_interval_common(Filtration_type birth, Filtration_type death, unsigned dim, Coefficient_field field)
Definition: writing_persistence_to_file.h:47
Gudhi namespace.
Definition: SimplicialComplexForAlpha.h:14
void write_persistence_intervals_to_stream(const Persistence_interval_range &intervals, std::ostream &out=std::cout)
Definition: writing_persistence_to_file.h:96