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> 30 namespace cubical_complex {
33 const bool globalDbg =
false;
36 class 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::cerr <<
"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::cerr <<
"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::cerr <<
"unsigned dimension(const Simplex_handle& sh)\n";
157 if (sh !=
null_simplex())
return this->get_dimension_of_a_cell(sh);
166 std::cerr <<
"Filtration_value filtration(const Simplex_handle& sh)\n";
170 return std::numeric_limits<Filtration_value>::infinity();
178 std::cerr <<
"Simplex_key null_key()\n";
180 return std::numeric_limits<Simplex_handle>::max();
186 Simplex_key
key(Simplex_handle sh)
const {
188 std::cerr <<
"Simplex_key key(const Simplex_handle& sh)\n";
191 return this->key_associated_to_simplex[sh];
201 std::cerr <<
"Simplex_handle simplex(Simplex_key key)\n";
204 return this->simplex_associated_to_key[
key];
214 std::cerr <<
"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 : std::iterator<std::input_iterator_tag, Simplex_handle> {
250 Filtration_simplex_iterator() : b(NULL), position(0) {}
252 Filtration_simplex_iterator operator++() {
254 std::cerr <<
"Filtration_simplex_iterator operator++\n";
260 Filtration_simplex_iterator operator++(
int) {
261 Filtration_simplex_iterator result = *
this;
266 Filtration_simplex_iterator& operator=(
const Filtration_simplex_iterator& rhs) {
268 std::cerr <<
"Filtration_simplex_iterator operator =\n";
271 this->position = rhs.position;
275 bool operator==(
const Filtration_simplex_iterator& rhs)
const {
277 std::cerr <<
"bool operator == ( const Filtration_simplex_iterator& rhs )\n";
279 return (this->position == rhs.position);
282 bool operator!=(
const Filtration_simplex_iterator& rhs)
const {
284 std::cerr <<
"bool operator != ( const Filtration_simplex_iterator& rhs )\n";
286 return !(*
this == rhs);
289 Simplex_handle operator*() {
291 std::cerr <<
"Simplex_handle operator*()\n";
293 return this->b->simplex_associated_to_key[this->position];
300 std::size_t position;
310 typedef Filtration_simplex_iterator const_iterator;
311 typedef Filtration_simplex_iterator iterator;
315 Filtration_simplex_iterator begin() {
317 std::cerr <<
"Filtration_simplex_iterator begin() \n";
319 return Filtration_simplex_iterator(this->b);
322 Filtration_simplex_iterator end() {
324 std::cerr <<
"Filtration_simplex_iterator end()\n";
326 Filtration_simplex_iterator it(this->b);
327 it.position = this->b->simplex_associated_to_key.size();
350 std::cerr <<
"Filtration_simplex_range filtration_simplex_range()\n";
370 std::pair<Simplex_handle, Simplex_handle>
endpoints(Simplex_handle sh) {
371 std::vector<std::size_t> bdry = this->get_boundary_of_a_cell(sh);
373 std::cerr <<
"std::pair<Simplex_handle, Simplex_handle> endpoints( Simplex_handle sh )\n";
374 std::cerr <<
"bdry.size() : " << bdry.size() <<
"\n";
379 "Error in endpoints in Bitmap_cubical_complex class. The cell have less than two elements in the " 381 return std::make_pair(bdry[0], bdry[1]);
389 class Skeleton_simplex_iterator : std::iterator<std::input_iterator_tag, Simplex_handle> {
395 std::cerr <<
"Skeleton_simplex_iterator ( Bitmap_cubical_complex* b , std::size_t d )\n";
399 while ((this->position != b->data.size()) &&
400 (this->b->get_dimension_of_a_cell(this->position) != this->
dimension)) {
405 Skeleton_simplex_iterator() : b(NULL), position(0),
dimension(0) {}
407 Skeleton_simplex_iterator operator++() {
409 std::cerr <<
"Skeleton_simplex_iterator operator++()\n";
413 while ((this->position != this->b->data.size()) &&
414 (this->b->get_dimension_of_a_cell(this->position) != this->
dimension)) {
420 Skeleton_simplex_iterator operator++(
int) {
421 Skeleton_simplex_iterator result = *
this;
426 Skeleton_simplex_iterator& operator=(
const Skeleton_simplex_iterator& rhs) {
428 std::cerr <<
"Skeleton_simplex_iterator operator =\n";
431 this->position = rhs.position;
436 bool operator==(
const Skeleton_simplex_iterator& rhs)
const {
438 std::cerr <<
"bool operator ==\n";
440 return (this->position == rhs.position);
443 bool operator!=(
const Skeleton_simplex_iterator& rhs)
const {
445 std::cerr <<
"bool operator != ( const Skeleton_simplex_iterator& rhs )\n";
447 return !(*
this == rhs);
450 Simplex_handle operator*() {
452 std::cerr <<
"Simplex_handle operator*() \n";
454 return this->position;
461 std::size_t position;
472 typedef Skeleton_simplex_iterator const_iterator;
473 typedef Skeleton_simplex_iterator iterator;
477 Skeleton_simplex_iterator begin() {
479 std::cerr <<
"Skeleton_simplex_iterator begin()\n";
481 return Skeleton_simplex_iterator(this->b, this->dimension);
484 Skeleton_simplex_iterator end() {
486 std::cerr <<
"Skeleton_simplex_iterator end()\n";
488 Skeleton_simplex_iterator it(this->b, this->dimension);
489 it.position = this->b->data.size();
503 std::cerr <<
"Skeleton_simplex_range skeleton_simplex_range( unsigned dimension )\n";
508 friend class is_before_in_filtration<T>;
511 std::vector<std::size_t> key_associated_to_simplex;
512 std::vector<std::size_t> simplex_associated_to_key;
515 template <
typename T>
518 std::cerr <<
"void Bitmap_cubical_complex<T>::initialize_elements_ordered_according_to_filtration() \n";
520 this->simplex_associated_to_key = std::vector<std::size_t>(this->data.size());
521 std::iota(std::begin(simplex_associated_to_key), std::end(simplex_associated_to_key), 0);
523 tbb::parallel_sort(simplex_associated_to_key.begin(), simplex_associated_to_key.end(),
524 is_before_in_filtration<T>(
this));
526 std::sort(simplex_associated_to_key.begin(), simplex_associated_to_key.end(), is_before_in_filtration<T>(
this));
530 for (std::size_t i = 0; i != simplex_associated_to_key.size(); ++i) {
531 this->key_associated_to_simplex[simplex_associated_to_key[i]] = i;
535 template <
typename T>
536 class is_before_in_filtration {
540 bool operator()(
const typename Bitmap_cubical_complex<T>::Simplex_handle& sh1,
541 const typename Bitmap_cubical_complex<T>::Simplex_handle& sh2)
const {
543 typedef typename T::filtration_type Filtration_value;
544 Filtration_value fil1 = CC_->data[sh1];
545 Filtration_value fil2 = CC_->data[sh2];
550 std::size_t dim1 = CC_->get_dimension_of_a_cell(sh1);
551 std::size_t dim2 = CC_->get_dimension_of_a_cell(sh2);
566 namespace Cubical_complex = cubical_complex;
570 #endif // BITMAP_CUBICAL_COMPLEX_H_ virtual ~Bitmap_cubical_complex()
Definition: Bitmap_cubical_complex.h:124
Boundary_simplex_range boundary_simplex_range(Simplex_handle sh)
Definition: Bitmap_cubical_complex.h:342
std::vector< Simplex_handle >::iterator Boundary_simplex_iterator
Definition: Bitmap_cubical_complex.h:233
Simplex_key key(Simplex_handle sh) const
Definition: Bitmap_cubical_complex.h:186
void initialize_simplex_associated_to_key()
Definition: Bitmap_cubical_complex.h:516
std::size_t dimension() const
Definition: Bitmap_cubical_complex.h:148
std::pair< Simplex_handle, Simplex_handle > endpoints(Simplex_handle sh)
Definition: Bitmap_cubical_complex.h:370
Definition: SimplicialComplexForAlpha.h:14
std::size_t num_simplices() const
Definition: Bitmap_cubical_complex.h:133
unsigned dimension(Simplex_handle sh) const
Definition: Bitmap_cubical_complex.h:153
Filtration_simplex_range filtration_simplex_range()
Definition: Bitmap_cubical_complex.h:348
Simplex_handle simplex(Simplex_key key)
Definition: Bitmap_cubical_complex.h:199
Filtration_simplex_range provides the ranges for Filtration_simplex_iterator.
Definition: Bitmap_cubical_complex.h:306
void assign_key(Simplex_handle sh, Simplex_key key)
Definition: Bitmap_cubical_complex.h:212
Cubical complex represented as a bitmap.
Definition: Bitmap_cubical_complex.h:48
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
Class needed for compatibility with Gudhi. Not useful for other purposes.
Definition: Bitmap_cubical_complex.h:468
static Simplex_key null_key()
Definition: Bitmap_cubical_complex.h:176
Bitmap_cubical_complex(const char *perseus_style_file)
Definition: Bitmap_cubical_complex.h:69
static Simplex_handle null_simplex()
Definition: Bitmap_cubical_complex.h:138
Skeleton_simplex_range skeleton_simplex_range(unsigned dimension)
Definition: Bitmap_cubical_complex.h:501
Filtration_value filtration(Simplex_handle sh)
Definition: Bitmap_cubical_complex.h:164