Hasse_diagram_cell.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 HASSE_DIAGRAM_CELL_H
12 #define HASSE_DIAGRAM_CELL_H
13 
14 #include <vector>
15 #include <utility> // for std::pair
16 #include <ostream>
17 #include <string>
18 #include <type_traits> // for std::is_same
19 #include <cstdlib> // for std::size_t
20 
21 namespace Gudhi {
22 namespace Hasse_diagram {
23 
24 template <typename Cell_type>
25 class Hasse_diagram;
26 
48 template <typename Incidence_type_, typename Filtration_type_, typename Additional_information_ = void>
50  public:
51  typedef Incidence_type_ Incidence_type;
52  typedef Filtration_type_ Filtration_type;
53  typedef Additional_information_ Additional_information;
54  using Cell_range = std::vector<std::pair<Hasse_diagram_cell*, Incidence_type> >;
55 
59  Hasse_diagram_cell() : dimension(0), position(0), deleted_(false) {}
60 
64  Hasse_diagram_cell(int dim) : dimension(dim), position(0), deleted_(false) {}
65 
69  Hasse_diagram_cell(int dim, Filtration_type filt_)
70  : dimension(dim), position(0), deleted_(false), filtration(filt_) {}
71 
75  Hasse_diagram_cell(const Cell_range& boundary_, int dim)
76  : dimension(dim), boundary(boundary_), position(0), deleted_(false) {}
77 
81  Hasse_diagram_cell(const Cell_range& boundary_, const Cell_range& coboundary_, int dim)
82  : dimension(dim), boundary(boundary_), coBoundary(coboundary_), position(0), deleted_(false) {}
83 
88  Hasse_diagram_cell(const Cell_range& boundary_, const Cell_range& coboundary_, const Additional_information& ai,
89  int dim)
90  : dimension(dim),
91  boundary(boundary_),
92  coBoundary(coboundary_),
93  additional_info(ai),
94  position(0),
95  deleted_(false) {}
96 
100  Hasse_diagram_cell(Additional_information ai, int dim)
101  : dimension(dim), additional_info(ai), position(0), deleted_(false) {}
102 
108  inline Cell_range& get_boundary() { return this->boundary; }
109 
115  inline Cell_range& get_coBoundary() { return this->coBoundary; }
116 
120  inline int& get_dimension() { return this->dimension; }
121 
125  inline Additional_information& get_additional_information() { return this->additional_info; }
126 
133  inline unsigned& get_position() { return this->position; }
134 
138  inline Filtration_type& get_filtration() {
139  // std::cout << "Accessing the filtration of a cell : " << *this << std::endl;
140  return this->filtration;
141  }
142 
148  inline bool deleted() { return this->deleted_; }
149 
150  template <typename Cell_type>
151  friend class Hasse_diagram;
152 
153  template <typename Cell_type>
154  friend class is_before_in_filtration;
155 
156  template <typename Complex_type, typename Cell_type>
157  friend std::vector<Cell_type*> convert_to_vector_of_Cell_type(Complex_type& cmplx);
158 
164  Cell_range new_boundary;
165  new_boundary.reserve(this->boundary.size());
166  for (std::size_t bd = 0; bd != this->boundary.size(); ++bd) {
167  if (!this->boundary[bd].first->deleted()) {
168  new_boundary.push_back(this->boundary[bd]);
169  }
170  }
171  this->boundary.swap(new_boundary);
172 
173  Cell_range new_coBoundary;
174  new_coBoundary.reserve(this->coBoundary.size());
175  for (std::size_t cbd = 0; cbd != this->coBoundary.size(); ++cbd) {
176  if (!this->coBoundary[cbd].first->deleted()) {
177  new_coBoundary.push_back(this->coBoundary[cbd]);
178  }
179  }
180  this->coBoundary.swap(new_coBoundary);
181  }
182 
186  friend std::ostream& operator<<(
188  // cout << "position : " << c.position << ", dimension : " << c.dimension << ", filtration: " << c.filtration << ",
189  // size of boundary : " << c.boundary.size() << "\n";
190  out << c.position << " " << c.dimension << " " << c.filtration << std::endl;
191  for (std::size_t bd = 0; bd != c.boundary.size(); ++bd) {
192  // do not write out the cells that has been deleted
193  if (c.boundary[bd].first->deleted()) continue;
194  out << c.boundary[bd].first->position << " " << c.boundary[bd].second << " ";
195  }
196  out << std::endl;
197  return out;
198  }
199 
203  inline std::vector<Hasse_diagram_cell*> get_list_of_boundary_elements() {
204  std::vector<Hasse_diagram_cell*> result;
205  std::size_t size_of_boundary = this->boundary.size();
206  result.reserve(size_of_boundary);
207  for (std::size_t bd = 0; bd != size_of_boundary; ++bd) {
208  result.push_back(this->boundary[bd].first);
209  }
210  return result;
211  }
212 
216  inline std::vector<unsigned> get_list_of_positions_of_boundary_elements() {
217  std::vector<unsigned> result;
218  std::size_t size_of_boundary = this->boundary.size();
219  result.reserve(size_of_boundary);
220  for (std::size_t bd = 0; bd != size_of_boundary; ++bd) {
221  result.push_back(this->boundary[bd].first->position);
222  }
223  return result;
224  }
225 
231  std::string result;
232  result += "dimension: ";
233  result += std::to_string(this->dimension);
234  result += " filtration: ";
235  result += std::to_string(this->filtration);
236  result += " position: ";
237  result += std::to_string(this->position);
238  result += " deleted_: ";
239  result += std::to_string(this->deleted_);
240 
241  // if the Additional_information is not void, add them to
242  // the signature as well.
243  if (std::is_same<Additional_information, void>::value) {
244  result += " Additional_information: ";
245  result += std::to_string(this->additional_info);
246  }
247  result += " boundary ";
248  for (std::size_t bd = 0; bd != this->boundary.size(); ++bd) {
249  result += "( " + std::to_string(this->boundary[bd].first->position);
250  result += " " + std::to_string(this->boundary[bd].second);
251  result += ") ";
252  }
253 
254  result += " coBoundary ";
255  for (std::size_t cbd = 0; cbd != this->coBoundary.size(); ++cbd) {
256  result += "( " + std::to_string(this->coBoundary[cbd].first->position);
257  result += " " + std::to_string(this->coBoundary[cbd].second);
258  result += ") ";
259  }
260 
261  return result;
262  }
263 
264  protected:
265  Cell_range boundary;
266  Cell_range coBoundary;
267  int dimension;
268  Additional_information additional_info;
269  unsigned position;
270  bool deleted_;
271  Filtration_type filtration;
272 
279  void delete_cell() { this->deleted_ = true; }
280 }; // Hasse_diagram_cell
281 
282 } // namespace Hasse_diagram
283 } // namespace Gudhi
284 
285 #endif // CELL_H
Data structure to store a cell in a Hasse diagram.
Definition: Hasse_diagram_cell.h:49
Cell_range & get_coBoundary()
Definition: Hasse_diagram_cell.h:115
bool deleted()
Definition: Hasse_diagram_cell.h:148
Hasse_diagram_cell(int dim)
Definition: Hasse_diagram_cell.h:64
Hasse_diagram_cell(int dim, Filtration_type filt_)
Definition: Hasse_diagram_cell.h:69
int & get_dimension()
Definition: Hasse_diagram_cell.h:120
void remove_deleted_elements_from_boundary_and_coboundary()
Definition: Hasse_diagram_cell.h:163
std::vector< unsigned > get_list_of_positions_of_boundary_elements()
Definition: Hasse_diagram_cell.h:216
Hasse_diagram_cell(Additional_information ai, int dim)
Definition: Hasse_diagram_cell.h:100
Hasse_diagram_cell()
Definition: Hasse_diagram_cell.h:59
Cell_range & get_boundary()
Definition: Hasse_diagram_cell.h:108
std::vector< Hasse_diagram_cell * > get_list_of_boundary_elements()
Definition: Hasse_diagram_cell.h:203
Hasse_diagram_cell(const Cell_range &boundary_, const Cell_range &coboundary_, const Additional_information &ai, int dim)
Definition: Hasse_diagram_cell.h:88
Hasse_diagram_cell(const Cell_range &boundary_, int dim)
Definition: Hasse_diagram_cell.h:75
friend std::ostream & operator<<(std::ostream &out, const Hasse_diagram_cell< Incidence_type, Filtration_type, Additional_information > &c)
Definition: Hasse_diagram_cell.h:186
unsigned & get_position()
Definition: Hasse_diagram_cell.h:133
Filtration_type & get_filtration()
Definition: Hasse_diagram_cell.h:138
Additional_information & get_additional_information()
Definition: Hasse_diagram_cell.h:125
Hasse_diagram_cell(const Cell_range &boundary_, const Cell_range &coboundary_, int dim)
Definition: Hasse_diagram_cell.h:81
std::string full_signature_of_the_structure()
Definition: Hasse_diagram_cell.h:230
Gudhi namespace.
Definition: SimplicialComplexForAlpha.h:14