Loading...
Searching...
No Matches
Hasse_diagram_cell.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 HASSE_DIAGRAM_CELL_H
#define HASSE_DIAGRAM_CELL_H
#include <vector>
#include <utility> // for std::pair
#include <ostream>
#include <string>
#include <type_traits> // for std::is_same
#include <cstdlib> // for std::size_t
namespace Gudhi {
namespace Hasse_diagram {
template <typename Cell_type>
class Hasse_diagram;
template <typename Incidence_type_, typename Filtration_type_, typename Additional_information_ = void>
class Hasse_diagram_cell {
public:
typedef Incidence_type_ Incidence_type;
typedef Filtration_type_ Filtration_type;
typedef Additional_information_ Additional_information;
using Cell_range = std::vector<std::pair<Hasse_diagram_cell*, Incidence_type> >;
Hasse_diagram_cell() : dimension(0), position(0), deleted_(false) {}
Hasse_diagram_cell(int dim) : dimension(dim), position(0), deleted_(false) {}
Hasse_diagram_cell(int dim, Filtration_type filt_)
: dimension(dim), position(0), deleted_(false), filtration(filt_) {}
Hasse_diagram_cell(const Cell_range& boundary_, int dim)
: dimension(dim), boundary(boundary_), position(0), deleted_(false) {}
Hasse_diagram_cell(const Cell_range& boundary_, const Cell_range& coboundary_, int dim)
: dimension(dim), boundary(boundary_), coBoundary(coboundary_), position(0), deleted_(false) {}
Hasse_diagram_cell(const Cell_range& boundary_, const Cell_range& coboundary_, const Additional_information& ai,
int dim)
: dimension(dim),
boundary(boundary_),
coBoundary(coboundary_),
additional_info(ai),
position(0),
deleted_(false) {}
Hasse_diagram_cell(Additional_information ai, int dim)
: dimension(dim), additional_info(ai), position(0), deleted_(false) {}
inline Cell_range& get_boundary() { return this->boundary; }
inline Cell_range& get_coBoundary() { return this->coBoundary; }
inline int& get_dimension() { return this->dimension; }
inline Additional_information& get_additional_information() { return this->additional_info; }
inline unsigned& get_position() { return this->position; }
inline Filtration_type& get_filtration() {
// std::cout << "Accessing the filtration of a cell : " << *this << std::endl;
return this->filtration;
}
inline bool deleted() { return this->deleted_; }
template <typename Cell_type>
friend class Hasse_diagram;
template <typename Cell_type>
friend class is_before_in_filtration;
template <typename Complex_type, typename Cell_type>
friend std::vector<Cell_type*> convert_to_vector_of_Cell_type(Complex_type& cmplx);
void remove_deleted_elements_from_boundary_and_coboundary() {
Cell_range new_boundary;
new_boundary.reserve(this->boundary.size());
for (std::size_t bd = 0; bd != this->boundary.size(); ++bd) {
if (!this->boundary[bd].first->deleted()) {
new_boundary.push_back(this->boundary[bd]);
}
}
this->boundary.swap(new_boundary);
Cell_range new_coBoundary;
new_coBoundary.reserve(this->coBoundary.size());
for (std::size_t cbd = 0; cbd != this->coBoundary.size(); ++cbd) {
if (!this->coBoundary[cbd].first->deleted()) {
new_coBoundary.push_back(this->coBoundary[cbd]);
}
}
this->coBoundary.swap(new_coBoundary);
}
friend std::ostream& operator<<(
std::ostream& out, const Hasse_diagram_cell<Incidence_type, Filtration_type, Additional_information>& c) {
// cout << "position : " << c.position << ", dimension : " << c.dimension << ", filtration: " << c.filtration << ",
// size of boundary : " << c.boundary.size() << "\n";
out << c.position << " " << c.dimension << " " << c.filtration << std::endl;
for (std::size_t bd = 0; bd != c.boundary.size(); ++bd) {
// do not write out the cells that has been deleted
if (c.boundary[bd].first->deleted()) continue;
out << c.boundary[bd].first->position << " " << c.boundary[bd].second << " ";
}
out << std::endl;
return out;
}
inline std::vector<Hasse_diagram_cell*> get_list_of_boundary_elements() {
std::vector<Hasse_diagram_cell*> result;
std::size_t size_of_boundary = this->boundary.size();
result.reserve(size_of_boundary);
for (std::size_t bd = 0; bd != size_of_boundary; ++bd) {
result.push_back(this->boundary[bd].first);
}
return result;
}
inline std::vector<unsigned> get_list_of_positions_of_boundary_elements() {
std::vector<unsigned> result;
std::size_t size_of_boundary = this->boundary.size();
result.reserve(size_of_boundary);
for (std::size_t bd = 0; bd != size_of_boundary; ++bd) {
result.push_back(this->boundary[bd].first->position);
}
return result;
}
std::string full_signature_of_the_structure() {
std::string result;
result += "dimension: ";
result += std::to_string(this->dimension);
result += " filtration: ";
result += std::to_string(this->filtration);
result += " position: ";
result += std::to_string(this->position);
result += " deleted_: ";
result += std::to_string(this->deleted_);
// if the Additional_information is not void, add them to
// the signature as well.
if (std::is_same<Additional_information, void>::value) {
result += " Additional_information: ";
result += std::to_string(this->additional_info);
}
result += " boundary ";
for (std::size_t bd = 0; bd != this->boundary.size(); ++bd) {
result += "( " + std::to_string(this->boundary[bd].first->position);
result += " " + std::to_string(this->boundary[bd].second);
result += ") ";
}
result += " coBoundary ";
for (std::size_t cbd = 0; cbd != this->coBoundary.size(); ++cbd) {
result += "( " + std::to_string(this->coBoundary[cbd].first->position);
result += " " + std::to_string(this->coBoundary[cbd].second);
result += ") ";
}
return result;
}
protected:
Cell_range boundary;
Cell_range coBoundary;
int dimension;
Additional_information additional_info;
unsigned position;
bool deleted_;
Filtration_type filtration;
void delete_cell() { this->deleted_ = true; }
}; // Hasse_diagram_cell
} // namespace Hasse_diagram
} // namespace Gudhi
#endif // CELL_H
Gudhi::Hasse_diagram::Hasse_diagram_cell::get_filtration
Filtration_type & get_filtration()
Definition Hasse_diagram_cell.h:138
Gudhi::Hasse_diagram::Hasse_diagram_cell::get_additional_information
Additional_information & get_additional_information()
Definition Hasse_diagram_cell.h:125
Gudhi::Hasse_diagram::Hasse_diagram_cell::deleted
bool deleted()
Definition Hasse_diagram_cell.h:148
Gudhi::Hasse_diagram::Hasse_diagram_cell::get_coBoundary
Cell_range & get_coBoundary()
Definition Hasse_diagram_cell.h:115
Gudhi::Hasse_diagram::Hasse_diagram_cell::get_list_of_positions_of_boundary_elements
std::vector< unsigned > get_list_of_positions_of_boundary_elements()
Definition Hasse_diagram_cell.h:216
Gudhi::Hasse_diagram::Hasse_diagram_cell::Hasse_diagram_cell
Hasse_diagram_cell(int dim)
Definition Hasse_diagram_cell.h:64
Gudhi::Hasse_diagram::Hasse_diagram_cell::Hasse_diagram_cell
Hasse_diagram_cell(int dim, Filtration_type filt_)
Definition Hasse_diagram_cell.h:69
Gudhi::Hasse_diagram::Hasse_diagram_cell::remove_deleted_elements_from_boundary_and_coboundary
void remove_deleted_elements_from_boundary_and_coboundary()
Definition Hasse_diagram_cell.h:163
Gudhi::Hasse_diagram::Hasse_diagram_cell::Hasse_diagram_cell
Hasse_diagram_cell(Additional_information ai, int dim)
Definition Hasse_diagram_cell.h:100
Gudhi::Hasse_diagram::Hasse_diagram_cell::Hasse_diagram_cell
Hasse_diagram_cell()
Definition Hasse_diagram_cell.h:59
Gudhi::Hasse_diagram::Hasse_diagram_cell::get_boundary
Cell_range & get_boundary()
Definition Hasse_diagram_cell.h:108
Gudhi::Hasse_diagram::Hasse_diagram_cell::Hasse_diagram_cell
Hasse_diagram_cell(const Cell_range &boundary_, const Cell_range &coboundary_, const Additional_information &ai, int dim)
Definition Hasse_diagram_cell.h:88
Gudhi::Hasse_diagram::Hasse_diagram_cell::get_dimension
int & get_dimension()
Definition Hasse_diagram_cell.h:120
Gudhi::Hasse_diagram::Hasse_diagram_cell::operator<<
friend std::ostream & operator<<(std::ostream &out, const Hasse_diagram_cell< Incidence_type, Filtration_type, Additional_information > &c)
Definition Hasse_diagram_cell.h:186
Gudhi::Hasse_diagram::Hasse_diagram_cell::Hasse_diagram_cell
Hasse_diagram_cell(const Cell_range &boundary_, int dim)
Definition Hasse_diagram_cell.h:75
Gudhi::Hasse_diagram::Hasse_diagram_cell::get_list_of_boundary_elements
std::vector< Hasse_diagram_cell * > get_list_of_boundary_elements()
Definition Hasse_diagram_cell.h:203
Gudhi::Hasse_diagram::Hasse_diagram_cell::get_position
unsigned & get_position()
Definition Hasse_diagram_cell.h:133
Gudhi::Hasse_diagram::Hasse_diagram_cell::Hasse_diagram_cell
Hasse_diagram_cell(const Cell_range &boundary_, const Cell_range &coboundary_, int dim)
Definition Hasse_diagram_cell.h:81
Gudhi::Hasse_diagram::Hasse_diagram_cell::full_signature_of_the_structure
std::string full_signature_of_the_structure()
Definition Hasse_diagram_cell.h:230
Gudhi
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14