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> 42 namespace cubical_complex {
45 const bool globalDbg =
false;
48 class is_before_in_filtration;
65 typedef std::size_t Simplex_key;
66 typedef typename T::filtration_type Filtration_value;
67 typedef Simplex_key Simplex_handle;
82 : T(perseus_style_file), key_associated_to_simplex(this->total_number_of_cells + 1) {
84 std::cerr <<
"Bitmap_cubical_complex( const char* perseus_style_file )\n";
86 for (std::size_t i = 0; i != this->total_number_of_cells; ++i) {
87 this->key_associated_to_simplex[i] = i;
101 const std::vector<Filtration_value>& top_dimensional_cells)
102 : T(dimensions, top_dimensional_cells), key_associated_to_simplex(this->total_number_of_cells + 1) {
103 for (std::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 (std::size_t i = 0; i != this->total_number_of_cells; ++i) {
125 this->key_associated_to_simplex[i] = i;
152 std::cerr <<
"Simplex_handle null_simplex()\n";
154 return std::numeric_limits<Simplex_handle>::max();
160 inline std::size_t
dimension()
const {
return this->sizes.size(); }
167 std::cerr <<
"unsigned dimension(const Simplex_handle& sh)\n";
169 if (sh !=
null_simplex())
return this->get_dimension_of_a_cell(sh);
178 std::cerr <<
"Filtration_value filtration(const Simplex_handle& sh)\n";
182 return std::numeric_limits<Filtration_value>::infinity();
190 std::cerr <<
"Simplex_key null_key()\n";
192 return std::numeric_limits<Simplex_handle>::max();
198 Simplex_key
key(Simplex_handle sh)
const {
200 std::cerr <<
"Simplex_key key(const Simplex_handle& sh)\n";
203 return this->key_associated_to_simplex[sh];
213 std::cerr <<
"Simplex_handle simplex(Simplex_key key)\n";
216 return this->simplex_associated_to_key[
key];
226 std::cerr <<
"void assign_key(Simplex_handle& sh, Simplex_key key)\n";
229 this->key_associated_to_simplex[sh] =
key;
230 this->simplex_associated_to_key[
key] = sh;
246 typedef typename std::vector<Simplex_handle> Boundary_simplex_range;
254 class Filtration_simplex_range;
256 class Filtration_simplex_iterator : std::iterator<std::input_iterator_tag, Simplex_handle> {
262 Filtration_simplex_iterator() : b(NULL), position(0) {}
264 Filtration_simplex_iterator operator++() {
266 std::cerr <<
"Filtration_simplex_iterator operator++\n";
272 Filtration_simplex_iterator operator++(
int) {
273 Filtration_simplex_iterator result = *
this;
278 Filtration_simplex_iterator& operator=(
const Filtration_simplex_iterator& rhs) {
280 std::cerr <<
"Filtration_simplex_iterator operator =\n";
283 this->position = rhs.position;
287 bool operator==(
const Filtration_simplex_iterator& rhs)
const {
289 std::cerr <<
"bool operator == ( const Filtration_simplex_iterator& rhs )\n";
291 return (this->position == rhs.position);
294 bool operator!=(
const Filtration_simplex_iterator& rhs)
const {
296 std::cerr <<
"bool operator != ( const Filtration_simplex_iterator& rhs )\n";
298 return !(*
this == rhs);
301 Simplex_handle operator*() {
303 std::cerr <<
"Simplex_handle operator*()\n";
305 return this->b->simplex_associated_to_key[this->position];
308 friend class Filtration_simplex_range;
312 std::size_t position;
322 typedef Filtration_simplex_iterator const_iterator;
323 typedef Filtration_simplex_iterator iterator;
327 Filtration_simplex_iterator begin() {
329 std::cerr <<
"Filtration_simplex_iterator begin() \n";
331 return Filtration_simplex_iterator(this->b);
334 Filtration_simplex_iterator end() {
336 std::cerr <<
"Filtration_simplex_iterator end()\n";
338 Filtration_simplex_iterator it(this->b);
339 it.position = this->b->simplex_associated_to_key.size();
362 std::cerr <<
"Filtration_simplex_range filtration_simplex_range()\n";
365 return Filtration_simplex_range(
this);
382 std::pair<Simplex_handle, Simplex_handle>
endpoints(Simplex_handle sh) {
383 std::vector<std::size_t> bdry = this->get_boundary_of_a_cell(sh);
385 std::cerr <<
"std::pair<Simplex_handle, Simplex_handle> endpoints( Simplex_handle sh )\n";
386 std::cerr <<
"bdry.size() : " << bdry.size() <<
"\n";
391 "Error in endpoints in Bitmap_cubical_complex class. The cell have less than two elements in the " 393 return std::make_pair(bdry[0], bdry[1]);
399 class Skeleton_simplex_range;
401 class Skeleton_simplex_iterator : std::iterator<std::input_iterator_tag, Simplex_handle> {
407 std::cerr <<
"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::cerr <<
"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::cerr <<
"Skeleton_simplex_iterator operator =\n";
443 this->position = rhs.position;
448 bool operator==(
const Skeleton_simplex_iterator& rhs)
const {
450 std::cerr <<
"bool operator ==\n";
452 return (this->position == rhs.position);
455 bool operator!=(
const Skeleton_simplex_iterator& rhs)
const {
457 std::cerr <<
"bool operator != ( const Skeleton_simplex_iterator& rhs )\n";
459 return !(*
this == rhs);
462 Simplex_handle operator*() {
464 std::cerr <<
"Simplex_handle operator*() \n";
466 return this->position;
469 friend class Skeleton_simplex_range;
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::cerr <<
"Skeleton_simplex_iterator begin()\n";
493 return Skeleton_simplex_iterator(this->b, this->dimension);
496 Skeleton_simplex_iterator end() {
498 std::cerr <<
"Skeleton_simplex_iterator end()\n";
500 Skeleton_simplex_iterator it(this->b, this->dimension);
501 it.position = this->b->data.size();
515 std::cerr <<
"Skeleton_simplex_range skeleton_simplex_range( unsigned dimension )\n";
517 return Skeleton_simplex_range(
this, dimension);
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;
527 template <
typename T>
530 std::cerr <<
"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;
547 template <
typename T>
548 class 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 {
555 typedef typename T::filtration_type Filtration_value;
556 Filtration_value fil1 = CC_->data[sh1];
557 Filtration_value fil2 = CC_->data[sh2];
562 std::size_t dim1 = CC_->get_dimension_of_a_cell(sh1);
563 std::size_t dim2 = CC_->get_dimension_of_a_cell(sh2);
578 namespace Cubical_complex = cubical_complex;
582 #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:354
std::vector< Simplex_handle >::iterator Boundary_simplex_iterator
Definition: Bitmap_cubical_complex.h:245
Simplex_key key(Simplex_handle sh) const
Definition: Bitmap_cubical_complex.h:198
void initialize_simplex_associated_to_key()
Definition: Bitmap_cubical_complex.h:528
std::size_t dimension() const
Definition: Bitmap_cubical_complex.h:160
std::pair< Simplex_handle, Simplex_handle > endpoints(Simplex_handle sh)
Definition: Bitmap_cubical_complex.h:382
Definition: SimplicialComplexForAlpha.h:26
std::size_t num_simplices() const
Definition: Bitmap_cubical_complex.h:145
unsigned dimension(Simplex_handle sh) const
Definition: Bitmap_cubical_complex.h:165
Filtration_simplex_range filtration_simplex_range()
Definition: Bitmap_cubical_complex.h:360
Simplex_handle simplex(Simplex_key key)
Definition: Bitmap_cubical_complex.h:211
Filtration_simplex_range provides the ranges for Filtration_simplex_iterator.
Definition: Bitmap_cubical_complex.h:318
void assign_key(Simplex_handle sh, Simplex_key key)
Definition: Bitmap_cubical_complex.h:224
Cubical complex represented as a bitmap.
Definition: Bitmap_cubical_complex.h:60
Bitmap_cubical_complex(const std::vector< unsigned > &dimensions, const std::vector< Filtration_value > &top_dimensional_cells)
Definition: Bitmap_cubical_complex.h:100
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
Class needed for compatibility with Gudhi. Not useful for other purposes.
Definition: Bitmap_cubical_complex.h:480
static Simplex_key null_key()
Definition: Bitmap_cubical_complex.h:188
Bitmap_cubical_complex(const char *perseus_style_file)
Definition: Bitmap_cubical_complex.h:81
static Simplex_handle null_simplex()
Definition: Bitmap_cubical_complex.h:150
Skeleton_simplex_range skeleton_simplex_range(unsigned dimension)
Definition: Bitmap_cubical_complex.h:513
Filtration_value filtration(Simplex_handle sh)
Definition: Bitmap_cubical_complex.h:176