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>
19 #include <tbb/parallel_sort.h>
32 namespace cubical_complex {
35 const bool globalDbg =
false;
38 class is_before_in_filtration;
55 typedef std::size_t Simplex_key;
56 typedef typename T::filtration_type Filtration_value;
57 typedef Simplex_key Simplex_handle;
72 : T(perseus_style_file), key_associated_to_simplex(this->total_number_of_cells + 1) {
74 std::clog <<
"Bitmap_cubical_complex( const char* perseus_style_file )\n";
76 for (std::size_t i = 0; i != this->total_number_of_cells; ++i) {
77 this->key_associated_to_simplex[i] = i;
91 const std::vector<Filtration_value>& top_dimensional_cells)
92 : T(dimensions, top_dimensional_cells), key_associated_to_simplex(this->total_number_of_cells + 1) {
93 for (std::size_t i = 0; i != this->total_number_of_cells; ++i) {
94 this->key_associated_to_simplex[i] = i;
110 const std::vector<Filtration_value>& top_dimensional_cells,
111 std::vector<bool> directions_in_which_periodic_b_cond_are_to_be_imposed)
112 : T(dimensions, top_dimensional_cells, directions_in_which_periodic_b_cond_are_to_be_imposed),
113 key_associated_to_simplex(this->total_number_of_cells + 1) {
114 for (std::size_t i = 0; i != this->total_number_of_cells; ++i) {
115 this->key_associated_to_simplex[i] = i;
142 std::clog <<
"Simplex_handle null_simplex()\n";
144 return std::numeric_limits<Simplex_handle>::max();
150 inline std::size_t
dimension()
const {
return this->sizes.size(); }
157 std::clog <<
"unsigned dimension(const Simplex_handle& sh)\n";
159 if (sh !=
null_simplex())
return this->get_dimension_of_a_cell(sh);
168 std::clog <<
"Filtration_value filtration(const Simplex_handle& sh)\n";
172 return std::numeric_limits<Filtration_value>::infinity();
180 std::clog <<
"Simplex_key null_key()\n";
182 return std::numeric_limits<Simplex_handle>::max();
188 Simplex_key
key(Simplex_handle sh)
const {
190 std::clog <<
"Simplex_key key(const Simplex_handle& sh)\n";
193 return this->key_associated_to_simplex[sh];
203 std::clog <<
"Simplex_handle simplex(Simplex_key key)\n";
206 return this->simplex_associated_to_key[
key];
216 std::clog <<
"void assign_key(Simplex_handle& sh, Simplex_key key)\n";
219 this->key_associated_to_simplex[sh] =
key;
220 this->simplex_associated_to_key[
key] = sh;
236 typedef typename std::vector<Simplex_handle> Boundary_simplex_range;
246 class Filtration_simplex_iterator : std::iterator<std::input_iterator_tag, Simplex_handle> {
252 Filtration_simplex_iterator() : b(NULL), position(0) {}
254 Filtration_simplex_iterator operator++() {
256 std::clog <<
"Filtration_simplex_iterator operator++\n";
262 Filtration_simplex_iterator operator++(
int) {
263 Filtration_simplex_iterator result = *
this;
268 Filtration_simplex_iterator& operator=(
const Filtration_simplex_iterator& rhs) {
270 std::clog <<
"Filtration_simplex_iterator operator =\n";
273 this->position = rhs.position;
277 bool operator==(
const Filtration_simplex_iterator& rhs)
const {
279 std::clog <<
"bool operator == ( const Filtration_simplex_iterator& rhs )\n";
281 return (this->position == rhs.position);
284 bool operator!=(
const Filtration_simplex_iterator& rhs)
const {
286 std::clog <<
"bool operator != ( const Filtration_simplex_iterator& rhs )\n";
288 return !(*
this == rhs);
291 Simplex_handle operator*() {
293 std::clog <<
"Simplex_handle operator*()\n";
295 return this->b->simplex_associated_to_key[this->position];
298 friend class Filtration_simplex_range;
301 Bitmap_cubical_complex<T>* b;
302 std::size_t position;
312 typedef Filtration_simplex_iterator const_iterator;
313 typedef Filtration_simplex_iterator iterator;
317 Filtration_simplex_iterator begin() {
319 std::clog <<
"Filtration_simplex_iterator begin() \n";
321 return Filtration_simplex_iterator(this->b);
324 Filtration_simplex_iterator end() {
326 std::clog <<
"Filtration_simplex_iterator end()\n";
328 Filtration_simplex_iterator it(this->b);
329 it.position = this->b->simplex_associated_to_key.size();
352 std::clog <<
"Filtration_simplex_range filtration_simplex_range()\n";
372 std::pair<Simplex_handle, Simplex_handle>
endpoints(Simplex_handle sh) {
373 std::vector<std::size_t> bdry = this->get_boundary_of_a_cell(sh);
375 std::clog <<
"std::pair<Simplex_handle, Simplex_handle> endpoints( Simplex_handle sh )\n";
376 std::clog <<
"bdry.size() : " << bdry.size() <<
"\n";
381 "Error in endpoints in Bitmap_cubical_complex class. The cell have less than two elements in the "
383 return std::make_pair(bdry[0], bdry[1]);
389 class Skeleton_simplex_range;
391 class Skeleton_simplex_iterator : std::iterator<std::input_iterator_tag, Simplex_handle> {
397 std::clog <<
"Skeleton_simplex_iterator ( Bitmap_cubical_complex* b , std::size_t d )\n";
401 while ((this->position != b->data.size()) &&
402 (this->b->get_dimension_of_a_cell(this->position) != this->dimension)) {
407 Skeleton_simplex_iterator() : b(NULL), position(0),
dimension(0) {}
409 Skeleton_simplex_iterator operator++() {
411 std::clog <<
"Skeleton_simplex_iterator operator++()\n";
415 while ((this->position != this->b->data.size()) &&
416 (this->b->get_dimension_of_a_cell(this->position) != this->dimension)) {
422 Skeleton_simplex_iterator operator++(
int) {
423 Skeleton_simplex_iterator result = *
this;
428 Skeleton_simplex_iterator& operator=(
const Skeleton_simplex_iterator& rhs) {
430 std::clog <<
"Skeleton_simplex_iterator operator =\n";
433 this->position = rhs.position;
438 bool operator==(
const Skeleton_simplex_iterator& rhs)
const {
440 std::clog <<
"bool operator ==\n";
442 return (this->position == rhs.position);
445 bool operator!=(
const Skeleton_simplex_iterator& rhs)
const {
447 std::clog <<
"bool operator != ( const Skeleton_simplex_iterator& rhs )\n";
449 return !(*
this == rhs);
452 Simplex_handle operator*() {
454 std::clog <<
"Simplex_handle operator*() \n";
456 return this->position;
459 friend class Skeleton_simplex_range;
462 Bitmap_cubical_complex<T>* b;
463 std::size_t position;
474 typedef Skeleton_simplex_iterator const_iterator;
475 typedef Skeleton_simplex_iterator iterator;
479 Skeleton_simplex_iterator begin() {
481 std::clog <<
"Skeleton_simplex_iterator begin()\n";
483 return Skeleton_simplex_iterator(this->b, this->dimension);
486 Skeleton_simplex_iterator end() {
488 std::clog <<
"Skeleton_simplex_iterator end()\n";
490 Skeleton_simplex_iterator it(this->b, this->dimension);
491 it.position = this->b->data.size();
505 std::clog <<
"Skeleton_simplex_range skeleton_simplex_range( unsigned dimension )\n";
510 friend class is_before_in_filtration<T>;
513 std::vector<std::size_t> key_associated_to_simplex;
514 std::vector<std::size_t> simplex_associated_to_key;
517 template <
typename T>
520 std::clog <<
"void Bitmap_cubical_complex<T>::initialize_elements_ordered_according_to_filtration() \n";
522 this->simplex_associated_to_key = std::vector<std::size_t>(this->data.size());
523 std::iota(std::begin(simplex_associated_to_key), std::end(simplex_associated_to_key), 0);
525 tbb::parallel_sort(simplex_associated_to_key.begin(), simplex_associated_to_key.end(),
526 is_before_in_filtration<T>(
this));
528 std::sort(simplex_associated_to_key.begin(), simplex_associated_to_key.end(), is_before_in_filtration<T>(
this));
532 for (std::size_t i = 0; i != simplex_associated_to_key.size(); ++i) {
533 this->key_associated_to_simplex[simplex_associated_to_key[i]] = i;
537 template <
typename T>
538 class is_before_in_filtration {
542 bool operator()(
const typename Bitmap_cubical_complex<T>::Simplex_handle& sh1,
543 const typename Bitmap_cubical_complex<T>::Simplex_handle& sh2)
const {
552 std::size_t dim1 = CC_->get_dimension_of_a_cell(sh1);
553 std::size_t dim2 = CC_->get_dimension_of_a_cell(sh2);
563 Bitmap_cubical_complex<T>* CC_;
568 namespace Cubical_complex = cubical_complex;
572 #endif // BITMAP_CUBICAL_COMPLEX_H_