23 #ifndef BITMAP_CUBICAL_COMPLEX_H_ 24 #define BITMAP_CUBICAL_COMPLEX_H_ 26 #include <gudhi/Bitmap_cubical_complex_base.h> 27 #include <gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h> 30 #include <tbb/parallel_sort.h> 41 namespace cubical_complex {
44 const bool globalDbg =
false;
46 template <
typename T>
class is_before_in_filtration;
63 typedef size_t Simplex_key;
64 typedef typename T::filtration_type Filtration_value;
65 typedef Simplex_key Simplex_handle;
81 T(perseus_style_file), key_associated_to_simplex(this->total_number_of_cells + 1) {
83 std::cerr <<
"Bitmap_cubical_complex( const char* perseus_style_file )\n";
85 for (
size_t i = 0; i != this->total_number_of_cells; ++i) {
86 this->key_associated_to_simplex[i] = i;
100 const std::vector<Filtration_value>& top_dimensional_cells) :
101 T(dimensions, top_dimensional_cells),
102 key_associated_to_simplex(this->total_number_of_cells + 1) {
103 for (
size_t i = 0; i != this->total_number_of_cells; ++i) {
104 this->key_associated_to_simplex[i] = i;
120 const std::vector<Filtration_value>& top_dimensional_cells,
121 std::vector< bool > directions_in_which_periodic_b_cond_are_to_be_imposed) :
122 T(dimensions, top_dimensional_cells, directions_in_which_periodic_b_cond_are_to_be_imposed),
123 key_associated_to_simplex(this->total_number_of_cells + 1) {
124 for (
size_t i = 0; i != this->total_number_of_cells; ++i) {
125 this->key_associated_to_simplex[i] = i;
146 return this->total_number_of_cells;
154 std::cerr <<
"Simplex_handle null_simplex()\n";
156 return std::numeric_limits<Simplex_handle>::max();
163 return this->sizes.size();
171 std::cerr <<
"unsigned dimension(const Simplex_handle& sh)\n";
173 if (sh !=
null_simplex())
return this->get_dimension_of_a_cell(sh);
182 std::cerr <<
"Filtration_value filtration(const Simplex_handle& sh)\n";
186 return std::numeric_limits<Filtration_value>::infinity();
194 std::cerr <<
"Simplex_key null_key()\n";
196 return std::numeric_limits<Simplex_handle>::max();
202 Simplex_key
key(Simplex_handle sh)
const {
204 std::cerr <<
"Simplex_key key(const Simplex_handle& sh)\n";
207 return this->key_associated_to_simplex[sh];
217 std::cerr <<
"Simplex_handle simplex(Simplex_key key)\n";
220 return this->simplex_associated_to_key[
key ];
230 std::cerr <<
"void assign_key(Simplex_handle& sh, Simplex_key key)\n";
233 this->key_associated_to_simplex[sh] =
key;
234 this->simplex_associated_to_key[
key] = sh;
250 typedef typename std::vector< Simplex_handle > Boundary_simplex_range;
258 class Filtration_simplex_range;
260 class Filtration_simplex_iterator : std::iterator< std::input_iterator_tag, Simplex_handle > {
266 Filtration_simplex_iterator() : b(NULL), position(0) { }
268 Filtration_simplex_iterator operator++() {
270 std::cerr <<
"Filtration_simplex_iterator operator++\n";
276 Filtration_simplex_iterator operator++(
int) {
277 Filtration_simplex_iterator result = *
this;
282 Filtration_simplex_iterator& operator=(
const Filtration_simplex_iterator& rhs) {
284 std::cerr <<
"Filtration_simplex_iterator operator =\n";
287 this->position = rhs.position;
291 bool operator==(
const Filtration_simplex_iterator& rhs)
const {
293 std::cerr <<
"bool operator == ( const Filtration_simplex_iterator& rhs )\n";
295 return ( this->position == rhs.position);
298 bool operator!=(
const Filtration_simplex_iterator& rhs)
const {
300 std::cerr <<
"bool operator != ( const Filtration_simplex_iterator& rhs )\n";
302 return !(*
this == rhs);
305 Simplex_handle operator*() {
307 std::cerr <<
"Simplex_handle operator*()\n";
309 return this->b->simplex_associated_to_key[ this->position ];
312 friend class Filtration_simplex_range;
326 typedef Filtration_simplex_iterator const_iterator;
327 typedef Filtration_simplex_iterator iterator;
331 Filtration_simplex_iterator begin() {
333 std::cerr <<
"Filtration_simplex_iterator begin() \n";
335 return Filtration_simplex_iterator(this->b);
338 Filtration_simplex_iterator end() {
340 std::cerr <<
"Filtration_simplex_iterator end()\n";
342 Filtration_simplex_iterator it(this->b);
343 it.position = this->b->simplex_associated_to_key.size();
361 return this->get_boundary_of_a_cell(sh);
370 std::cerr <<
"Filtration_simplex_range filtration_simplex_range()\n";
373 return Filtration_simplex_range(
this);
392 std::pair<Simplex_handle, Simplex_handle>
endpoints(Simplex_handle sh) {
393 std::vector< size_t > bdry = this->get_boundary_of_a_cell(sh);
395 std::cerr <<
"std::pair<Simplex_handle, Simplex_handle> endpoints( Simplex_handle sh )\n";
396 std::cerr <<
"bdry.size() : " << bdry.size() << std::endl;
400 throw(
"Error in endpoints in Bitmap_cubical_complex class. The cell have less than two elements in the " 402 return std::make_pair(bdry[0], bdry[1]);
409 class Skeleton_simplex_range;
411 class Skeleton_simplex_iterator : std::iterator< std::input_iterator_tag, Simplex_handle > {
417 std::cerr <<
"Skeleton_simplex_iterator ( Bitmap_cubical_complex* b , size_t d )\n";
422 (this->position != b->data.size()) &&
423 (this->b->get_dimension_of_a_cell(this->position) != this->
dimension)
429 Skeleton_simplex_iterator() : b(NULL), position(0),
dimension(0) { }
431 Skeleton_simplex_iterator operator++() {
433 std::cerr <<
"Skeleton_simplex_iterator operator++()\n";
438 (this->position != this->b->data.size()) &&
439 (this->b->get_dimension_of_a_cell(this->position) != this->
dimension)
446 Skeleton_simplex_iterator operator++(
int) {
447 Skeleton_simplex_iterator result = *
this;
452 Skeleton_simplex_iterator& operator=(
const Skeleton_simplex_iterator& rhs) {
454 std::cerr <<
"Skeleton_simplex_iterator operator =\n";
457 this->position = rhs.position;
462 bool operator==(
const Skeleton_simplex_iterator& rhs)
const {
464 std::cerr <<
"bool operator ==\n";
466 return ( this->position == rhs.position);
469 bool operator!=(
const Skeleton_simplex_iterator& rhs)
const {
471 std::cerr <<
"bool operator != ( const Skeleton_simplex_iterator& rhs )\n";
473 return !(*
this == rhs);
476 Simplex_handle operator*() {
478 std::cerr <<
"Simplex_handle operator*() \n";
480 return this->position;
483 friend class Skeleton_simplex_range;
497 typedef Skeleton_simplex_iterator const_iterator;
498 typedef Skeleton_simplex_iterator iterator;
502 Skeleton_simplex_iterator begin() {
504 std::cerr <<
"Skeleton_simplex_iterator begin()\n";
506 return Skeleton_simplex_iterator(this->b, this->dimension);
509 Skeleton_simplex_iterator end() {
511 std::cerr <<
"Skeleton_simplex_iterator end()\n";
513 Skeleton_simplex_iterator it(this->b, this->dimension);
514 it.position = this->b->data.size();
528 std::cerr <<
"Skeleton_simplex_range skeleton_simplex_range( unsigned dimension )\n";
530 return Skeleton_simplex_range(
this, dimension);
533 friend class is_before_in_filtration<T>;
536 std::vector< size_t > key_associated_to_simplex;
537 std::vector< size_t > simplex_associated_to_key;
540 template <
typename T>
543 std::cerr <<
"void Bitmap_cubical_complex<T>::initialize_elements_ordered_according_to_filtration() \n";
545 this->simplex_associated_to_key = std::vector<size_t>(this->data.size());
546 std::iota(std::begin(simplex_associated_to_key), std::end(simplex_associated_to_key), 0);
548 tbb::parallel_sort(simplex_associated_to_key.begin(), simplex_associated_to_key.end(),
549 is_before_in_filtration<T>(
this));
551 std::sort(simplex_associated_to_key.begin(), simplex_associated_to_key.end(), is_before_in_filtration<T>(
this));
555 for (
size_t i = 0 ; i != simplex_associated_to_key.size() ; ++i ) {
556 this->key_associated_to_simplex[ simplex_associated_to_key[i] ] = i;
560 template <
typename T>
561 class is_before_in_filtration {
566 bool operator()(
const typename Bitmap_cubical_complex<T>::Simplex_handle& sh1,
567 const typename Bitmap_cubical_complex<T>::Simplex_handle& sh2)
const {
569 typedef typename T::filtration_type Filtration_value;
570 Filtration_value fil1 = CC_->data[sh1];
571 Filtration_value fil2 = CC_->data[sh2];
576 size_t dim1 = CC_->get_dimension_of_a_cell(sh1);
577 size_t dim2 = CC_->get_dimension_of_a_cell(sh2);
592 namespace Cubical_complex = cubical_complex;
596 #endif // BITMAP_CUBICAL_COMPLEX_H_ virtual ~Bitmap_cubical_complex()
Definition: Bitmap_cubical_complex.h:136
Boundary_simplex_range boundary_simplex_range(Simplex_handle sh)
Definition: Bitmap_cubical_complex.h:360
void initialize_simplex_associated_to_key()
Definition: Bitmap_cubical_complex.h:541
std::pair< Simplex_handle, Simplex_handle > endpoints(Simplex_handle sh)
Definition: Bitmap_cubical_complex.h:392
Definition: SimplicialComplexForAlpha.h:26
std::vector< Simplex_handle >::iterator Boundary_simplex_iterator
Definition: Bitmap_cubical_complex.h:249
Filtration_simplex_range filtration_simplex_range()
Definition: Bitmap_cubical_complex.h:368
Simplex_handle simplex(Simplex_key key)
Definition: Bitmap_cubical_complex.h:215
size_t num_simplices() const
Definition: Bitmap_cubical_complex.h:145
Simplex_key key(Simplex_handle sh) const
Definition: Bitmap_cubical_complex.h:202
Filtration_simplex_range provides the ranges for Filtration_simplex_iterator.
Definition: Bitmap_cubical_complex.h:322
void assign_key(Simplex_handle sh, Simplex_key key)
Definition: Bitmap_cubical_complex.h:228
Cubical complex represented as a bitmap.
Definition: Bitmap_cubical_complex.h:58
Bitmap_cubical_complex(const std::vector< unsigned > &dimensions, const std::vector< Filtration_value > &top_dimensional_cells)
Definition: Bitmap_cubical_complex.h:99
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:119
unsigned dimension(Simplex_handle sh) const
Definition: Bitmap_cubical_complex.h:169
Class needed for compatibility with Gudhi. Not useful for other purposes.
Definition: Bitmap_cubical_complex.h:493
static Simplex_key null_key()
Definition: Bitmap_cubical_complex.h:192
Bitmap_cubical_complex(const char *perseus_style_file)
Definition: Bitmap_cubical_complex.h:80
static Simplex_handle null_simplex()
Definition: Bitmap_cubical_complex.h:152
Skeleton_simplex_range skeleton_simplex_range(unsigned dimension)
Definition: Bitmap_cubical_complex.h:526
size_t dimension() const
Definition: Bitmap_cubical_complex.h:162
Filtration_value filtration(Simplex_handle sh)
Definition: Bitmap_cubical_complex.h:180