Loading...
Searching...
No Matches
Bitmap_cubical_complex_base.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) 2015 Inria
6 *
7 * Modification(s):
8 * - YYYY/MM Author: Description of the modification
9 */
10
11#ifndef BITMAP_CUBICAL_COMPLEX_BASE_H_
12#define BITMAP_CUBICAL_COMPLEX_BASE_H_
13
14#include <gudhi/Bitmap_cubical_complex/counter.h>
15
16#include <boost/config.hpp>
17
18#include <iostream>
19#include <vector>
20#include <string>
21#include <fstream>
22#include <algorithm>
23#include <iterator>
24#include <limits>
25#include <utility>
26#include <stdexcept>
27#include <cstddef>
28
29namespace Gudhi {
30
31namespace cubical_complex {
32
52template <typename T>
54 public:
55 typedef T filtration_type;
56
60 Bitmap_cubical_complex_base() : total_number_of_cells(0) {}
67 Bitmap_cubical_complex_base(const std::vector<unsigned>& sizes);
74 Bitmap_cubical_complex_base(const char* perseus_style_file);
79 Bitmap_cubical_complex_base(const std::vector<unsigned>& dimensions, const std::vector<T>& top_dimensional_cells);
80
85
97 virtual inline std::vector<std::size_t> get_boundary_of_a_cell(std::size_t cell) const;
112 virtual inline std::vector<std::size_t> get_coboundary_of_a_cell(std::size_t cell) const;
113
122 inline size_t get_top_dimensional_coface_of_a_cell(size_t splx);
123
143 virtual int compute_incidence_between_cells(std::size_t coface, std::size_t face) const {
144 // first get the counters for coface and face:
145 std::vector<unsigned> coface_counter = this->compute_counter_for_given_cell(coface);
146 std::vector<unsigned> face_counter = this->compute_counter_for_given_cell(face);
147
148 // coface_counter and face_counter should agree at all positions except from one:
149 int number_of_position_in_which_counters_do_not_agree = -1;
150 std::size_t number_of_full_faces_that_comes_before = 0;
151 for (std::size_t i = 0; i != coface_counter.size(); ++i) {
152 if ((coface_counter[i] % 2 == 1) && (number_of_position_in_which_counters_do_not_agree == -1)) {
153 ++number_of_full_faces_that_comes_before;
154 }
155 if (coface_counter[i] != face_counter[i]) {
156 if (number_of_position_in_which_counters_do_not_agree != -1) {
157 std::cerr << "Cells given to compute_incidence_between_cells procedure do not form a pair of coface-face.\n";
158 throw std::logic_error(
159 "Cells given to compute_incidence_between_cells procedure do not form a pair of coface-face.");
160 }
161 number_of_position_in_which_counters_do_not_agree = i;
162 }
163 }
164
165 int incidence = 1;
166 if (number_of_full_faces_that_comes_before % 2) incidence = -1;
167 // if the face cell is on the right from coface cell:
168 if (coface_counter[number_of_position_in_which_counters_do_not_agree] + 1 ==
169 face_counter[number_of_position_in_which_counters_do_not_agree]) {
170 incidence *= -1;
171 }
172
173 return incidence;
174 }
175
184 inline unsigned get_dimension_of_a_cell(std::size_t cell) const;
185
192 inline T& get_cell_data(std::size_t cell);
193
202 void impose_lower_star_filtration(); // assume that top dimensional cells are already set.
203
207 inline unsigned dimension() const { return sizes.size(); }
208
212 inline std::size_t size() const { return this->data.size(); }
213
218 template <typename K>
219 friend std::ostream& operator<<(std::ostream& os, const Bitmap_cubical_complex_base<K>& b);
220
229 void put_data_to_bins(std::size_t number_of_bins);
230
241 void put_data_to_bins(T diameter_of_bin);
242
246 std::pair<T, T> min_max_filtration();
247
248 // ITERATORS
249
255 public:
256 typedef std::input_iterator_tag iterator_category;
257 typedef std::size_t value_type;
258 typedef std::ptrdiff_t difference_type;
259 typedef value_type* pointer;
260 typedef value_type reference;
261
262 All_cells_iterator() { this->counter = 0; }
263
264 All_cells_iterator operator++() {
265 // first find first element of the counter that can be increased:
266 ++this->counter;
267 return *this;
268 }
269
270 All_cells_iterator operator++(int) {
271 All_cells_iterator result = *this;
272 ++(*this);
273 return result;
274 }
275
276 All_cells_iterator& operator=(const All_cells_iterator& rhs) {
277 this->counter = rhs.counter;
278 return *this;
279 }
280
281 bool operator==(const All_cells_iterator& rhs) const {
282 if (this->counter != rhs.counter) return false;
283 return true;
284 }
285
286 bool operator!=(const All_cells_iterator& rhs) const { return !(*this == rhs); }
287
288 /*
289 * The operator * returns position of a cube in the structure of cubical complex. This position can be then used as
290 * an argument of the following functions:
291 * get_boundary_of_a_cell, get_coboundary_of_a_cell, get_dimension_of_a_cell to get information about the cell
292 * boundary and coboundary and dimension
293 * and in function get_cell_data to get a filtration of a cell.
294 */
295 std::size_t operator*() { return this->counter; }
296 friend class Bitmap_cubical_complex_base;
297
298 protected:
299 std::size_t counter;
300 };
301
307 return a;
308 }
309
315 a.counter = this->data.size();
316 return a;
317 }
318
323 public:
325
326 All_cells_iterator begin() { return b->all_cells_iterator_begin(); }
327
328 All_cells_iterator end() { return b->all_cells_iterator_end(); }
329
330 private:
332 };
333
334 All_cells_range all_cells_range() { return All_cells_range(this); }
335
339 typedef typename std::vector<std::size_t>::const_iterator Boundary_iterator;
340 typedef typename std::vector<std::size_t> Boundary_range;
341
346 Boundary_range boundary_range(std::size_t sh) { return this->get_boundary_of_a_cell(sh); }
347
351 typedef typename std::vector<std::size_t>::const_iterator Coboundary_iterator;
352 typedef typename std::vector<std::size_t> Coboundary_range;
353
358 Coboundary_range coboundary_range(std::size_t sh) { return this->get_coboundary_of_a_cell(sh); }
359
365 public:
366 typedef std::input_iterator_tag iterator_category;
367 typedef std::size_t value_type;
368 typedef std::ptrdiff_t difference_type;
369 typedef value_type* pointer;
370 typedef value_type reference;
371
373 this->counter = std::vector<std::size_t>(b.dimension());
374 // std::fill( this->counter.begin() , this->counter.end() , 0 );
375 }
376
377 Top_dimensional_cells_iterator operator++() {
378 // first find first element of the counter that can be increased:
379 std::size_t dim = 0;
380 while ((dim != this->b.dimension()) && (this->counter[dim] == this->b.sizes[dim] - 1)) ++dim;
381
382 if (dim != this->b.dimension()) {
383 ++this->counter[dim];
384 for (std::size_t i = 0; i != dim; ++i) {
385 this->counter[i] = 0;
386 }
387 } else {
388 ++this->counter[0];
389 }
390 return *this;
391 }
392
393 Top_dimensional_cells_iterator operator++(int) {
394 Top_dimensional_cells_iterator result = *this;
395 ++(*this);
396 return result;
397 }
398
400 this->counter = rhs.counter;
401 this->b = rhs.b;
402 return *this;
403 }
404
405 bool operator==(const Top_dimensional_cells_iterator& rhs) const {
406 if (&this->b != &rhs.b) return false;
407 if (this->counter.size() != rhs.counter.size()) return false;
408 for (std::size_t i = 0; i != this->counter.size(); ++i) {
409 if (this->counter[i] != rhs.counter[i]) return false;
410 }
411 return true;
412 }
413
414 bool operator!=(const Top_dimensional_cells_iterator& rhs) const { return !(*this == rhs); }
415
416 /*
417 * The operator * returns position of a cube in the structure of cubical complex. This position can be then used as
418 * an argument of the following functions:
419 * get_boundary_of_a_cell, get_coboundary_of_a_cell, get_dimension_of_a_cell to get information about the cell
420 * boundary and coboundary and dimension
421 * and in function get_cell_data to get a filtration of a cell.
422 */
423 std::size_t operator*() { return this->compute_index_in_bitmap(); }
424
425 std::size_t compute_index_in_bitmap() const {
426 std::size_t index = 0;
427 for (std::size_t i = 0; i != this->counter.size(); ++i) {
428 index += (2 * this->counter[i] + 1) * this->b.multipliers[i];
429 }
430 return index;
431 }
432
433 void print_counter() const {
434 for (std::size_t i = 0; i != this->counter.size(); ++i) {
435 std::clog << this->counter[i] << " ";
436 }
437 }
438 friend class Bitmap_cubical_complex_base;
439
440 protected:
441 std::vector<std::size_t> counter;
443 };
444
450 return a;
451 }
452
458 for (std::size_t i = 0; i != this->dimension(); ++i) {
459 a.counter[i] = this->sizes[i] - 1;
460 }
461 a.counter[0]++;
462 return a;
463 }
464
469 public:
471
473
475
476 private:
478 };
479
480 Top_dimensional_cells_range top_dimensional_cells_range() { return Top_dimensional_cells_range(this); }
481
482 //****************************************************************************************************************//
483 //****************************************************************************************************************//
484 //****************************************************************************************************************//
485 //****************************************************************************************************************//
486
487 inline std::size_t number_cells() const { return this->total_number_of_cells; }
488
489 //****************************************************************************************************************//
490 //****************************************************************************************************************//
491 //****************************************************************************************************************//
492 //****************************************************************************************************************//
493
494 protected:
495 std::vector<unsigned> sizes;
496 std::vector<unsigned> multipliers;
497 std::vector<T> data;
498 std::size_t total_number_of_cells;
499
500 void set_up_containers(const std::vector<unsigned>& sizes) {
501 unsigned multiplier = 1;
502 for (std::size_t i = 0; i != sizes.size(); ++i) {
503 this->sizes.push_back(sizes[i]);
504 this->multipliers.push_back(multiplier);
505 multiplier *= 2 * sizes[i] + 1;
506 }
507 this->data = std::vector<T>(multiplier, std::numeric_limits<T>::infinity());
508 this->total_number_of_cells = multiplier;
509 }
510
511 std::size_t compute_position_in_bitmap(const std::vector<unsigned>& counter) {
512 std::size_t position = 0;
513 for (std::size_t i = 0; i != this->multipliers.size(); ++i) {
514 position += this->multipliers[i] * counter[i];
515 }
516 return position;
517 }
518
519 std::vector<unsigned> compute_counter_for_given_cell(std::size_t cell) const {
520 std::vector<unsigned> counter;
521 counter.reserve(this->sizes.size());
522 for (std::size_t dim = this->sizes.size(); dim != 0; --dim) {
523 counter.push_back(cell / this->multipliers[dim - 1]);
524 cell = cell % this->multipliers[dim - 1];
525 }
526 std::reverse(counter.begin(), counter.end());
527 return counter;
528 }
529 void read_perseus_style_file(const char* perseus_style_file);
530 void setup_bitmap_based_on_top_dimensional_cells_list(const std::vector<unsigned>& sizes_in_following_directions,
531 const std::vector<T>& top_dimensional_cells);
532 Bitmap_cubical_complex_base(const char* perseus_style_file, std::vector<bool> directions);
533 Bitmap_cubical_complex_base(const std::vector<unsigned>& sizes, std::vector<bool> directions);
534 Bitmap_cubical_complex_base(const std::vector<unsigned>& dimensions, const std::vector<T>& top_dimensional_cells,
535 std::vector<bool> directions);
536};
537
538template <typename T>
539void Bitmap_cubical_complex_base<T>::put_data_to_bins(std::size_t number_of_bins) {
540 bool dbg = false;
541
542 std::pair<T, T> min_max = this->min_max_filtration();
543 T dx = (min_max.second - min_max.first) / (T)number_of_bins;
544
545 // now put the data into the appropriate bins:
546 for (std::size_t i = 0; i != this->data.size(); ++i) {
547 if (dbg) {
548 std::clog << "Before binning : " << this->data[i] << std::endl;
549 }
550 this->data[i] = min_max.first + dx * (this->data[i] - min_max.first) / number_of_bins;
551 if (dbg) {
552 std::clog << "After binning : " << this->data[i] << std::endl;
553 }
554 }
555}
556
557template <typename T>
559 bool dbg = false;
560 std::pair<T, T> min_max = this->min_max_filtration();
561
562 std::size_t number_of_bins = (min_max.second - min_max.first) / diameter_of_bin;
563 // now put the data into the appropriate bins:
564 for (std::size_t i = 0; i != this->data.size(); ++i) {
565 if (dbg) {
566 std::clog << "Before binning : " << this->data[i] << std::endl;
567 }
568 this->data[i] = min_max.first + diameter_of_bin * (this->data[i] - min_max.first) / number_of_bins;
569 if (dbg) {
570 std::clog << "After binning : " << this->data[i] << std::endl;
571 }
572 }
573}
574
575template <typename T>
577 std::pair<T, T> min_max(std::numeric_limits<T>::infinity(), -std::numeric_limits<T>::infinity());
578 for (std::size_t i = 0; i != this->data.size(); ++i) {
579 if (this->data[i] < min_max.first) min_max.first = this->data[i];
580 if (this->data[i] > min_max.second) min_max.second = this->data[i];
581 }
582 return min_max;
583}
584
585template <typename K>
586std::ostream& operator<<(std::ostream& out, const Bitmap_cubical_complex_base<K>& b) {
587 for (typename Bitmap_cubical_complex_base<K>::all_cells_const_iterator it = b.all_cells_const_begin();
588 it != b.all_cells_const_end(); ++it) {
589 out << *it << " ";
590 }
591 return out;
592}
593
594template <typename T>
596 this->set_up_containers(sizes);
597}
598
599template <typename T>
601 const std::vector<unsigned>& sizes_in_following_directions, const std::vector<T>& top_dimensional_cells) {
602 this->set_up_containers(sizes_in_following_directions);
603
604 std::size_t number_of_top_dimensional_elements = 1;
605 for (std::size_t i = 0; i != sizes_in_following_directions.size(); ++i) {
606 number_of_top_dimensional_elements *= sizes_in_following_directions[i];
607 }
608 if (number_of_top_dimensional_elements != top_dimensional_cells.size()) {
609 std::cerr << "Error in constructor Bitmap_cubical_complex_base ( std::vector<std::size_t> "
610 << "sizes_in_following_directions, std::vector<T> top_dimensional_cells ). Number of top dimensional "
611 << "elements that follow from sizes_in_following_directions vector is different than the size of "
612 << "top_dimensional_cells vector."
613 << std::endl;
614 throw(
615 "Error in constructor Bitmap_cubical_complex_base( std::vector<std::size_t> sizes_in_following_directions,"
616 "std::vector<T> top_dimensional_cells ). Number of top dimensional elements that follow from "
617 "sizes_in_following_directions vector is different than the size of top_dimensional_cells vector.");
618 }
619
620 Bitmap_cubical_complex_base<T>::Top_dimensional_cells_iterator it(*this);
621 std::size_t index = 0;
622 for (it = this->top_dimensional_cells_iterator_begin(); it != this->top_dimensional_cells_iterator_end(); ++it) {
623 this->get_cell_data(*it) = top_dimensional_cells[index];
624 ++index;
625 }
626 this->impose_lower_star_filtration();
627}
628
629template <typename T>
631 if (this->get_dimension_of_a_cell(splx) == this->dimension()){return splx;}
632 else{
633 for (auto v : this->get_coboundary_of_a_cell(splx)){
634 if(this->get_cell_data(v) == this->get_cell_data(splx)){
635 return this->get_top_dimensional_coface_of_a_cell(v);
636 }
637 }
638 }
639 BOOST_UNREACHABLE_RETURN(-2);
640}
641
642template <typename T>
643Bitmap_cubical_complex_base<T>::Bitmap_cubical_complex_base(const std::vector<unsigned>& sizes_in_following_directions,
644 const std::vector<T>& top_dimensional_cells) {
645 this->setup_bitmap_based_on_top_dimensional_cells_list(sizes_in_following_directions, top_dimensional_cells);
646}
647
648template <typename T>
649void Bitmap_cubical_complex_base<T>::read_perseus_style_file(const char* perseus_style_file) {
650 bool dbg = false;
651 std::ifstream inFiltration;
652 inFiltration.open(perseus_style_file);
653 unsigned dimensionOfData;
654 inFiltration >> dimensionOfData;
655
656 if (dbg) {
657 std::clog << "dimensionOfData : " << dimensionOfData << std::endl;
658 }
659
660 std::vector<unsigned> sizes;
661 sizes.reserve(dimensionOfData);
662 // all dimensions multiplied
663 std::size_t dimensions = 1;
664 for (std::size_t i = 0; i != dimensionOfData; ++i) {
665 unsigned size_in_this_dimension;
666 inFiltration >> size_in_this_dimension;
667 sizes.push_back(size_in_this_dimension);
668 dimensions *= size_in_this_dimension;
669 if (dbg) {
670 std::clog << "size_in_this_dimension : " << size_in_this_dimension << std::endl;
671 }
672 }
673 this->set_up_containers(sizes);
674
675 Bitmap_cubical_complex_base<T>::Top_dimensional_cells_iterator it(*this);
676 it = this->top_dimensional_cells_iterator_begin();
677
678 T filtrationLevel = 0.;
679 std::size_t filtration_counter = 0;
680 while (!inFiltration.eof()) {
681 std::string line;
682 getline(inFiltration, line);
683 if (line.length() != 0) {
684 int n = sscanf(line.c_str(), "%lf", &filtrationLevel);
685 if (n != 1) {
686 std::string perseus_error("Bad Perseus file format. This line is incorrect : " + line);
687 throw std::ios_base::failure(perseus_error.c_str());
688 }
689
690 if (dbg) {
691 std::clog << "Cell of an index : " << it.compute_index_in_bitmap()
692 << " and dimension: " << this->get_dimension_of_a_cell(it.compute_index_in_bitmap())
693 << " get the value : " << filtrationLevel << std::endl;
694 }
695 this->get_cell_data(*it) = filtrationLevel;
696 ++it;
697 ++filtration_counter;
698 }
699 }
700
701 if (filtration_counter != dimensions) {
702 std::string perseus_error("Bad Perseus file format. Read " + std::to_string(filtration_counter) + " expected " + \
703 std::to_string(dimensions) + " values");
704 throw std::ios_base::failure(perseus_error.c_str());
705 }
706
707 inFiltration.close();
708 this->impose_lower_star_filtration();
709}
710
711template <typename T>
713 std::vector<bool> directions) {
714 // this constructor is here just for compatibility with a class that creates cubical complexes with periodic boundary
715 // conditions.
716 // It ignores the last parameter of the function.
717 this->read_perseus_style_file(perseus_style_file);
718}
719
720template <typename T>
721Bitmap_cubical_complex_base<T>::Bitmap_cubical_complex_base(const std::vector<unsigned>& sizes,
722 std::vector<bool> directions) {
723 // this constructor is here just for compatibility with a class that creates cubical complexes with periodic boundary
724 // conditions.
725 // It ignores the last parameter of the function.
726 this->set_up_containers(sizes);
727}
728
729template <typename T>
730Bitmap_cubical_complex_base<T>::Bitmap_cubical_complex_base(const std::vector<unsigned>& dimensions,
731 const std::vector<T>& top_dimensional_cells,
732 std::vector<bool> directions) {
733 // this constructor is here just for compatibility with a class that creates cubical complexes with periodic boundary
734 // conditions.
735 // It ignores the last parameter of the function.
736 this->setup_bitmap_based_on_top_dimensional_cells_list(dimensions, top_dimensional_cells);
737}
738
739template <typename T>
741 this->read_perseus_style_file(perseus_style_file);
742}
743
744template <typename T>
745std::vector<std::size_t> Bitmap_cubical_complex_base<T>::get_boundary_of_a_cell(std::size_t cell) const {
746 std::vector<std::size_t> boundary_elements;
747
748 // Speed traded of for memory. Check if it is better in practice.
749 boundary_elements.reserve(this->dimension() * 2);
750
751 std::size_t sum_of_dimensions = 0;
752 std::size_t cell1 = cell;
753 for (std::size_t i = this->multipliers.size(); i != 0; --i) {
754 unsigned position = cell1 / this->multipliers[i - 1];
755 if (position % 2 == 1) {
756 if (sum_of_dimensions % 2) {
757 boundary_elements.push_back(cell + this->multipliers[i - 1]);
758 boundary_elements.push_back(cell - this->multipliers[i - 1]);
759 } else {
760 boundary_elements.push_back(cell - this->multipliers[i - 1]);
761 boundary_elements.push_back(cell + this->multipliers[i - 1]);
762 }
763 ++sum_of_dimensions;
764 }
765 cell1 = cell1 % this->multipliers[i - 1];
766 }
767
768 return boundary_elements;
769}
770
771template <typename T>
772std::vector<std::size_t> Bitmap_cubical_complex_base<T>::get_coboundary_of_a_cell(std::size_t cell) const {
773 std::vector<unsigned> counter = this->compute_counter_for_given_cell(cell);
774 std::vector<std::size_t> coboundary_elements;
775 std::size_t cell1 = cell;
776 for (std::size_t i = this->multipliers.size(); i != 0; --i) {
777 unsigned position = cell1 / this->multipliers[i - 1];
778 if (position % 2 == 0) {
779 if ((cell > this->multipliers[i - 1]) && (counter[i - 1] != 0)) {
780 coboundary_elements.push_back(cell - this->multipliers[i - 1]);
781 }
782 if ((cell + this->multipliers[i - 1] < this->data.size()) && (counter[i - 1] != 2 * this->sizes[i - 1])) {
783 coboundary_elements.push_back(cell + this->multipliers[i - 1]);
784 }
785 }
786 cell1 = cell1 % this->multipliers[i - 1];
787 }
788 return coboundary_elements;
789}
790
791template <typename T>
793 bool dbg = false;
794 if (dbg) std::clog << "\n\n\n Computing position o a cell of an index : " << cell << std::endl;
795 unsigned dimension = 0;
796 for (std::size_t i = this->multipliers.size(); i != 0; --i) {
797 unsigned position = cell / this->multipliers[i - 1];
798
799 if (dbg) {
800 std::clog << "i-1 :" << i - 1 << std::endl;
801 std::clog << "cell : " << cell << std::endl;
802 std::clog << "position : " << position << std::endl;
803 std::clog << "multipliers[" << i - 1 << "] = " << this->multipliers[i - 1] << std::endl;
804 }
805
806 if (position % 2 == 1) {
807 if (dbg) std::clog << "Nonzero length in this direction \n";
808 dimension++;
809 }
810 cell = cell % this->multipliers[i - 1];
811 }
812 return dimension;
813}
814
815template <typename T>
817 return this->data[cell];
818}
819
820template <typename T>
822 bool dbg = false;
823
824 // this vector will be used to check which elements have already been taken care of in imposing lower star filtration
825 std::vector<bool> is_this_cell_considered(this->data.size(), false);
826
827 std::size_t size_to_reserve = 1;
828 for (std::size_t i = 0; i != this->multipliers.size(); ++i) {
829 size_to_reserve *= (std::size_t)((this->multipliers[i] - 1) / 2);
830 }
831
832 std::vector<std::size_t> indices_to_consider;
833 indices_to_consider.reserve(size_to_reserve);
834 // we assume here that we already have a filtration on the top dimensional cells and
835 // we have to extend it to lower ones.
837 for (it = this->top_dimensional_cells_iterator_begin(); it != this->top_dimensional_cells_iterator_end(); ++it) {
838 indices_to_consider.push_back(it.compute_index_in_bitmap());
839 }
840
841 while (indices_to_consider.size()) {
842 if (dbg) {
843 std::clog << "indices_to_consider in this iteration \n";
844 for (std::size_t i = 0; i != indices_to_consider.size(); ++i) {
845 std::clog << indices_to_consider[i] << " ";
846 }
847 }
848 std::vector<std::size_t> new_indices_to_consider;
849 for (std::size_t i = 0; i != indices_to_consider.size(); ++i) {
850 std::vector<std::size_t> bd = this->get_boundary_of_a_cell(indices_to_consider[i]);
851 for (std::size_t boundaryIt = 0; boundaryIt != bd.size(); ++boundaryIt) {
852 if (dbg) {
853 std::clog << "filtration of a cell : " << bd[boundaryIt] << " is : " << this->data[bd[boundaryIt]]
854 << " while of a cell: " << indices_to_consider[i] << " is: " << this->data[indices_to_consider[i]]
855 << std::endl;
856 }
857 if (this->data[bd[boundaryIt]] > this->data[indices_to_consider[i]]) {
858 this->data[bd[boundaryIt]] = this->data[indices_to_consider[i]];
859 if (dbg) {
860 std::clog << "Setting the value of a cell : " << bd[boundaryIt]
861 << " to : " << this->data[indices_to_consider[i]] << std::endl;
862 }
863 }
864 if (is_this_cell_considered[bd[boundaryIt]] == false) {
865 new_indices_to_consider.push_back(bd[boundaryIt]);
866 is_this_cell_considered[bd[boundaryIt]] = true;
867 }
868 }
869 }
870 indices_to_consider.swap(new_indices_to_consider);
871 }
872}
873
874template <typename T>
875bool compareFirstElementsOfTuples(const std::pair<std::pair<T, std::size_t>, char>& first,
876 const std::pair<std::pair<T, std::size_t>, char>& second) {
877 if (first.first.first < second.first.first) {
878 return true;
879 } else {
880 if (first.first.first > second.first.first) {
881 return false;
882 }
883 // in this case first.first.first == second.first.first, so we need to compare dimensions
884 return first.second < second.second;
885 }
886}
887
888} // namespace cubical_complex
889
890namespace Cubical_complex = cubical_complex;
891
892} // namespace Gudhi
893
894#endif // BITMAP_CUBICAL_COMPLEX_BASE_H_
Iterator through all cells in the complex (in order they appear in the structure – i....
Definition: Bitmap_cubical_complex_base.h:254
All_cells_range class provides ranges for All_cells_iterator.
Definition: Bitmap_cubical_complex_base.h:322
Iterator through top dimensional cells of the complex. The cells appear in order they are stored in t...
Definition: Bitmap_cubical_complex_base.h:364
Top_dimensional_cells_iterator_range class provides ranges for Top_dimensional_cells_iterator_range.
Definition: Bitmap_cubical_complex_base.h:468
Cubical complex represented as a bitmap, class with basic implementation.
Definition: Bitmap_cubical_complex_base.h:53
All_cells_iterator all_cells_iterator_end()
Definition: Bitmap_cubical_complex_base.h:313
std::vector< std::size_t >::const_iterator Coboundary_iterator
Definition: Bitmap_cubical_complex_base.h:351
Bitmap_cubical_complex_base()
Definition: Bitmap_cubical_complex_base.h:60
void put_data_to_bins(std::size_t number_of_bins)
Definition: Bitmap_cubical_complex_base.h:539
void impose_lower_star_filtration()
Definition: Bitmap_cubical_complex_base.h:821
std::size_t size() const
Definition: Bitmap_cubical_complex_base.h:212
All_cells_iterator all_cells_iterator_begin()
Definition: Bitmap_cubical_complex_base.h:305
virtual std::vector< std::size_t > get_coboundary_of_a_cell(std::size_t cell) const
Definition: Bitmap_cubical_complex_base.h:772
unsigned get_dimension_of_a_cell(std::size_t cell) const
Definition: Bitmap_cubical_complex_base.h:792
unsigned dimension() const
Definition: Bitmap_cubical_complex_base.h:207
Top_dimensional_cells_iterator top_dimensional_cells_iterator_begin()
Definition: Bitmap_cubical_complex_base.h:448
friend std::ostream & operator<<(std::ostream &os, const Bitmap_cubical_complex_base< K > &b)
Definition: Bitmap_cubical_complex_base.h:586
virtual std::vector< std::size_t > get_boundary_of_a_cell(std::size_t cell) const
Definition: Bitmap_cubical_complex_base.h:745
Coboundary_range coboundary_range(std::size_t sh)
Definition: Bitmap_cubical_complex_base.h:358
std::pair< T, T > min_max_filtration()
Definition: Bitmap_cubical_complex_base.h:576
Top_dimensional_cells_iterator top_dimensional_cells_iterator_end()
Definition: Bitmap_cubical_complex_base.h:456
std::vector< std::size_t >::const_iterator Boundary_iterator
Definition: Bitmap_cubical_complex_base.h:339
size_t get_top_dimensional_coface_of_a_cell(size_t splx)
Definition: Bitmap_cubical_complex_base.h:630
T & get_cell_data(std::size_t cell)
Definition: Bitmap_cubical_complex_base.h:816
Boundary_range boundary_range(std::size_t sh)
Definition: Bitmap_cubical_complex_base.h:346
virtual int compute_incidence_between_cells(std::size_t coface, std::size_t face) const
Definition: Bitmap_cubical_complex_base.h:143
virtual ~Bitmap_cubical_complex_base()
Definition: Bitmap_cubical_complex_base.h:84
This is an implementation of a counter being a vector of integers.
Definition: counter.h:32