Loading...
Searching...
No Matches
writing_persistence_to_file.h
/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
* See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
* Author(s): Pawel Dlotko
*
* Copyright (C) 2017 Swansea University, UK
*
* Modification(s):
* - YYYY/MM Author: Description of the modification
*/
#ifndef WRITING_PERSISTENCE_TO_FILE_H_
#define WRITING_PERSISTENCE_TO_FILE_H_
#include <iostream>
#include <string>
#include <limits>
namespace Gudhi {
template <typename Filtration_type, typename Coefficient_field>
class Persistence_interval_common {
public:
Persistence_interval_common(Filtration_type birth, Filtration_type death)
: birth_(birth),
death_(death),
dimension_(std::numeric_limits<unsigned>::max()),
arith_element_(std::numeric_limits<Coefficient_field>::max()) {}
Persistence_interval_common(Filtration_type birth, Filtration_type death, unsigned dim)
: birth_(birth), death_(death), dimension_(dim), arith_element_(std::numeric_limits<Coefficient_field>::max()) {}
Persistence_interval_common(Filtration_type birth, Filtration_type death, unsigned dim, Coefficient_field field)
: birth_(birth), death_(death), dimension_(dim), arith_element_(field) {}
bool operator==(const Persistence_interval_common& i2) const {
return ((this->birth_ == i2.birth_) && (this->death_ == i2.death_) && (this->dimension_ == i2.dimension_) &&
(this->arith_element_ == i2.arith_element_));
}
bool operator!=(const Persistence_interval_common& i2) const { return (!((*this) == i2)); }
bool operator<(const Persistence_interval_common& i2) const {
return fabs(this->death_ - this->birth_) < fabs(i2.death_ - i2.birth_);
}
friend std::ostream& operator<<(std::ostream& out, const Persistence_interval_common& it) {
if (it.arith_element_ != std::numeric_limits<Coefficient_field>::max()) {
out << it.arith_element_ << " ";
}
if (it.dimension_ != std::numeric_limits<unsigned>::max()) {
out << it.dimension_ << " ";
}
out << it.birth_ << " " << it.death_ << " ";
return out;
}
private:
Filtration_type birth_;
Filtration_type death_;
unsigned dimension_;
Coefficient_field arith_element_;
};
template <typename Persistence_interval_range>
void write_persistence_intervals_to_stream(const Persistence_interval_range& intervals,
std::ostream& out = std::cout) {
for (auto interval : intervals) {
out << interval << "\n";
}
}
} // namespace Gudhi
#endif // WRITING_PERSISTENCE_TO_FILE_H_
Gudhi::Persistence_interval_common
Definition writing_persistence_to_file.h:26
Gudhi::Persistence_interval_common::operator==
bool operator==(const Persistence_interval_common &i2) const
Definition writing_persistence_to_file.h:55
Gudhi::Persistence_interval_common::operator!=
bool operator!=(const Persistence_interval_common &i2) const
Definition writing_persistence_to_file.h:63
Gudhi::Persistence_interval_common::operator<
bool operator<(const Persistence_interval_common &i2) const
Definition writing_persistence_to_file.h:70
Gudhi::Persistence_interval_common::Persistence_interval_common
Persistence_interval_common(Filtration_type birth, Filtration_type death)
Definition writing_persistence_to_file.h:31
Gudhi::Persistence_interval_common::Persistence_interval_common
Persistence_interval_common(Filtration_type birth, Filtration_type death, unsigned dim)
Definition writing_persistence_to_file.h:40
Gudhi::Persistence_interval_common::Persistence_interval_common
Persistence_interval_common(Filtration_type birth, Filtration_type death, unsigned dim, Coefficient_field field)
Definition writing_persistence_to_file.h:47
Gudhi
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14
Gudhi::write_persistence_intervals_to_stream
void write_persistence_intervals_to_stream(const Persistence_interval_range &intervals, std::ostream &out=std::cout)
Definition writing_persistence_to_file.h:96
std
STL namespace.