11#ifndef BITMAP_CUBICAL_COMPLEX_H_
12#define BITMAP_CUBICAL_COMPLEX_H_
14#include <gudhi/Bitmap_cubical_complex_base.h>
15#include <gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h>
18#include <tbb/parallel_sort.h>
30namespace cubical_complex {
33const bool globalDbg =
false;
36class is_before_in_filtration;
53 typedef std::size_t Simplex_key;
54 typedef typename T::filtration_type Filtration_value;
55 typedef Simplex_key Simplex_handle;
70 : T(perseus_style_file), key_associated_to_simplex(this->total_number_of_cells + 1) {
72 std::clog <<
"Bitmap_cubical_complex( const char* perseus_style_file )\n";
74 for (std::size_t i = 0; i != this->total_number_of_cells; ++i) {
75 this->key_associated_to_simplex[i] = i;
89 const std::vector<Filtration_value>& top_dimensional_cells)
90 : T(dimensions, top_dimensional_cells), key_associated_to_simplex(this->total_number_of_cells + 1) {
91 for (std::size_t i = 0; i != this->total_number_of_cells; ++i) {
92 this->key_associated_to_simplex[i] = i;
108 const std::vector<Filtration_value>& top_dimensional_cells,
109 std::vector<bool> directions_in_which_periodic_b_cond_are_to_be_imposed)
110 : T(dimensions, top_dimensional_cells, directions_in_which_periodic_b_cond_are_to_be_imposed),
111 key_associated_to_simplex(this->total_number_of_cells + 1) {
112 for (std::size_t i = 0; i != this->total_number_of_cells; ++i) {
113 this->key_associated_to_simplex[i] = i;
140 std::clog <<
"Simplex_handle null_simplex()\n";
142 return std::numeric_limits<Simplex_handle>::max();
148 inline std::size_t
dimension()
const {
return this->sizes.size(); }
155 std::clog <<
"unsigned dimension(const Simplex_handle& sh)\n";
157 if (sh !=
null_simplex())
return this->get_dimension_of_a_cell(sh);
166 std::clog <<
"Filtration_value filtration(const Simplex_handle& sh)\n";
170 return std::numeric_limits<Filtration_value>::infinity();
178 std::clog <<
"Simplex_key null_key()\n";
180 return std::numeric_limits<Simplex_handle>::max();
186 Simplex_key
key(Simplex_handle sh)
const {
188 std::clog <<
"Simplex_key key(const Simplex_handle& sh)\n";
191 return this->key_associated_to_simplex[sh];
201 std::clog <<
"Simplex_handle simplex(Simplex_key key)\n";
204 return this->simplex_associated_to_key[
key];
214 std::clog <<
"void assign_key(Simplex_handle& sh, Simplex_key key)\n";
217 this->key_associated_to_simplex[sh] =
key;
218 this->simplex_associated_to_key[
key] = sh;
234 typedef typename std::vector<Simplex_handle> Boundary_simplex_range;
244 class Filtration_simplex_iterator {
248 typedef std::input_iterator_tag iterator_category;
249 typedef Simplex_handle value_type;
250 typedef std::ptrdiff_t difference_type;
251 typedef value_type* pointer;
252 typedef value_type reference;
256 Filtration_simplex_iterator() : b(NULL), position(0) {}
258 Filtration_simplex_iterator operator++() {
260 std::clog <<
"Filtration_simplex_iterator operator++\n";
266 Filtration_simplex_iterator operator++(
int) {
267 Filtration_simplex_iterator result = *
this;
272 Filtration_simplex_iterator& operator=(
const Filtration_simplex_iterator& rhs) {
274 std::clog <<
"Filtration_simplex_iterator operator =\n";
277 this->position = rhs.position;
281 bool operator==(
const Filtration_simplex_iterator& rhs)
const {
283 std::clog <<
"bool operator == ( const Filtration_simplex_iterator& rhs )\n";
285 return (this->position == rhs.position);
288 bool operator!=(
const Filtration_simplex_iterator& rhs)
const {
290 std::clog <<
"bool operator != ( const Filtration_simplex_iterator& rhs )\n";
292 return !(*
this == rhs);
295 Simplex_handle operator*() {
297 std::clog <<
"Simplex_handle operator*()\n";
299 return this->b->simplex_associated_to_key[this->position];
302 friend class Filtration_simplex_range;
305 Bitmap_cubical_complex<T>* b;
306 std::size_t position;
316 typedef Filtration_simplex_iterator const_iterator;
317 typedef Filtration_simplex_iterator iterator;
321 Filtration_simplex_iterator begin() {
323 std::clog <<
"Filtration_simplex_iterator begin() \n";
325 return Filtration_simplex_iterator(this->b);
328 Filtration_simplex_iterator end() {
330 std::clog <<
"Filtration_simplex_iterator end()\n";
332 Filtration_simplex_iterator it(this->b);
333 it.position = this->b->simplex_associated_to_key.size();
356 std::clog <<
"Filtration_simplex_range filtration_simplex_range()\n";
376 std::pair<Simplex_handle, Simplex_handle>
endpoints(Simplex_handle sh) {
377 std::vector<std::size_t> bdry = this->get_boundary_of_a_cell(sh);
379 std::clog <<
"std::pair<Simplex_handle, Simplex_handle> endpoints( Simplex_handle sh )\n";
380 std::clog <<
"bdry.size() : " << bdry.size() <<
"\n";
385 "Error in endpoints in Bitmap_cubical_complex class. The cell have less than two elements in the "
387 return std::make_pair(bdry[0], bdry[1]);
393 class Skeleton_simplex_range;
395 class Skeleton_simplex_iterator {
399 typedef std::input_iterator_tag iterator_category;
400 typedef Simplex_handle value_type;
401 typedef std::ptrdiff_t difference_type;
402 typedef value_type* pointer;
403 typedef value_type reference;
407 std::clog <<
"Skeleton_simplex_iterator ( Bitmap_cubical_complex* b , std::size_t d )\n";
411 while ((this->position != b->data.size()) &&
412 (this->b->get_dimension_of_a_cell(this->position) != this->dimension)) {
417 Skeleton_simplex_iterator() : b(NULL), position(0), dimension(0) {}
419 Skeleton_simplex_iterator operator++() {
421 std::clog <<
"Skeleton_simplex_iterator operator++()\n";
425 while ((this->position != this->b->data.size()) &&
426 (this->b->get_dimension_of_a_cell(this->position) != this->dimension)) {
432 Skeleton_simplex_iterator operator++(
int) {
433 Skeleton_simplex_iterator result = *
this;
438 Skeleton_simplex_iterator& operator=(
const Skeleton_simplex_iterator& rhs) {
440 std::clog <<
"Skeleton_simplex_iterator operator =\n";
443 this->position = rhs.position;
448 bool operator==(
const Skeleton_simplex_iterator& rhs)
const {
450 std::clog <<
"bool operator ==\n";
452 return (this->position == rhs.position);
455 bool operator!=(
const Skeleton_simplex_iterator& rhs)
const {
457 std::clog <<
"bool operator != ( const Skeleton_simplex_iterator& rhs )\n";
459 return !(*
this == rhs);
462 Simplex_handle operator*() {
464 std::clog <<
"Simplex_handle operator*() \n";
466 return this->position;
469 friend class Skeleton_simplex_range;
472 Bitmap_cubical_complex<T>* b;
473 std::size_t position;
484 typedef Skeleton_simplex_iterator const_iterator;
485 typedef Skeleton_simplex_iterator iterator;
489 Skeleton_simplex_iterator begin() {
491 std::clog <<
"Skeleton_simplex_iterator begin()\n";
493 return Skeleton_simplex_iterator(this->b, this->dimension);
496 Skeleton_simplex_iterator end() {
498 std::clog <<
"Skeleton_simplex_iterator end()\n";
500 Skeleton_simplex_iterator it(this->b, this->dimension);
501 it.position = this->b->data.size();
515 std::clog <<
"Skeleton_simplex_range skeleton_simplex_range( unsigned dimension )\n";
520 friend class is_before_in_filtration<T>;
523 std::vector<std::size_t> key_associated_to_simplex;
524 std::vector<std::size_t> simplex_associated_to_key;
530 std::clog <<
"void Bitmap_cubical_complex<T>::initialize_elements_ordered_according_to_filtration() \n";
532 this->simplex_associated_to_key = std::vector<std::size_t>(this->data.size());
533 std::iota(std::begin(simplex_associated_to_key), std::end(simplex_associated_to_key), 0);
535 tbb::parallel_sort(simplex_associated_to_key.begin(), simplex_associated_to_key.end(),
536 is_before_in_filtration<T>(
this));
538 std::sort(simplex_associated_to_key.begin(), simplex_associated_to_key.end(), is_before_in_filtration<T>(
this));
542 for (std::size_t i = 0; i != simplex_associated_to_key.size(); ++i) {
543 this->key_associated_to_simplex[simplex_associated_to_key[i]] = i;
548class is_before_in_filtration {
552 bool operator()(
const typename Bitmap_cubical_complex<T>::Simplex_handle& sh1,
553 const typename Bitmap_cubical_complex<T>::Simplex_handle& sh2)
const {
562 std::size_t dim1 = CC_->get_dimension_of_a_cell(sh1);
563 std::size_t dim2 = CC_->get_dimension_of_a_cell(sh2);
573 Bitmap_cubical_complex<T>* CC_;
578namespace Cubical_complex = cubical_complex;
Filtration_simplex_range provides the ranges for Filtration_simplex_iterator.
Definition: Bitmap_cubical_complex.h:312
Class needed for compatibility with Gudhi. Not useful for other purposes.
Definition: Bitmap_cubical_complex.h:480
Cubical complex represented as a bitmap.
Definition: Bitmap_cubical_complex.h:48
std::pair< Simplex_handle, Simplex_handle > endpoints(Simplex_handle sh)
Definition: Bitmap_cubical_complex.h:376
Bitmap_cubical_complex(const std::vector< unsigned > &dimensions, const std::vector< Filtration_value > &top_dimensional_cells)
Definition: Bitmap_cubical_complex.h:88
Bitmap_cubical_complex(const std::vector< unsigned > &dimensions, const std::vector< Filtration_value > &top_dimensional_cells, std::vector< bool > directions_in_which_periodic_b_cond_are_to_be_imposed)
Definition: Bitmap_cubical_complex.h:107
Filtration_simplex_range filtration_simplex_range()
Definition: Bitmap_cubical_complex.h:354
Bitmap_cubical_complex(const char *perseus_style_file)
Definition: Bitmap_cubical_complex.h:69
Simplex_key key(Simplex_handle sh) const
Definition: Bitmap_cubical_complex.h:186
std::size_t dimension() const
Definition: Bitmap_cubical_complex.h:148
std::vector< Simplex_handle >::iterator Boundary_simplex_iterator
Definition: Bitmap_cubical_complex.h:233
Filtration_value filtration(Simplex_handle sh)
Definition: Bitmap_cubical_complex.h:164
Boundary_simplex_range boundary_simplex_range(Simplex_handle sh)
Definition: Bitmap_cubical_complex.h:348
void assign_key(Simplex_handle sh, Simplex_key key)
Definition: Bitmap_cubical_complex.h:212
static Simplex_key null_key()
Definition: Bitmap_cubical_complex.h:176
Simplex_handle simplex(Simplex_key key)
Definition: Bitmap_cubical_complex.h:199
unsigned dimension(Simplex_handle sh) const
Definition: Bitmap_cubical_complex.h:153
void initialize_simplex_associated_to_key()
Definition: Bitmap_cubical_complex.h:528
std::size_t num_simplices() const
Definition: Bitmap_cubical_complex.h:133
Skeleton_simplex_range skeleton_simplex_range(unsigned dimension)
Definition: Bitmap_cubical_complex.h:513
static Simplex_handle null_simplex()
Definition: Bitmap_cubical_complex.h:138
virtual ~Bitmap_cubical_complex()
Definition: Bitmap_cubical_complex.h:124
Value type for a filtration function on a cell complex.
Definition: FiltrationValue.h:20