From d133f17dede836cee1dfff47d2e00532573b9ead Mon Sep 17 00:00:00 2001 From: pdlotko Date: Thu, 17 Mar 2016 08:43:58 +0000 Subject: cleanning up the stuff with iterators in Bitmap_cubical_complex_base.h class. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/bitmap@1049 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 9630d6df6a2ecdb51ab25150454a563cd928b09a --- .../example/Random_bitmap_cubical_complex.cpp | 7 +- .../include/gudhi/Bitmap_cubical_complex_base.h | 515 +++++++++++++-------- ...cal_complex_periodic_boundary_conditions_base.h | 4 +- src/Bitmap_cubical_complex/test/Bitmap_test.cpp | 183 +++++++- 4 files changed, 500 insertions(+), 209 deletions(-) (limited to 'src/Bitmap_cubical_complex') diff --git a/src/Bitmap_cubical_complex/example/Random_bitmap_cubical_complex.cpp b/src/Bitmap_cubical_complex/example/Random_bitmap_cubical_complex.cpp index 97347162..8b7f6a04 100644 --- a/src/Bitmap_cubical_complex/example/Random_bitmap_cubical_complex.cpp +++ b/src/Bitmap_cubical_complex/example/Random_bitmap_cubical_complex.cpp @@ -70,11 +70,12 @@ The program will create random cubical complex of that sizes and compute persist for ( size_t i = 0 ; i != multipliers ; ++i ) { data.push_back( rand()/(double)RAND_MAX ); - } - + } + Bitmap_cubical_complex< Bitmap_cubical_complex_base > b( sizes , data ); + + - Bitmap_cubical_complex< Bitmap_cubical_complex_base > b( sizes , data ); // Compute the persistence diagram of the complex diff --git a/src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex_base.h b/src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex_base.h index 807be335..6d2b705c 100644 --- a/src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex_base.h +++ b/src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex_base.h @@ -22,7 +22,7 @@ #pragma once -#include +#include #include #include #include @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include "Bitmap_cubical_complex/counter.h" @@ -69,13 +69,13 @@ namespace Cubical_complex template class Bitmap_cubical_complex_base { -public: - typedef T filtration_type; - /** - *Default constructor - **/ - Bitmap_cubical_complex_base() - { +public: + typedef T filtration_type; + /** + *Default constructor + **/ + Bitmap_cubical_complex_base() + { } /** * There are a few constructors of a Bitmap_cubical_complex_base class. @@ -96,11 +96,11 @@ public: * together with vector of filtration values of top dimensional cells. **/ Bitmap_cubical_complex_base( const std::vector& dimensions , const std::vector& top_dimensional_cells ); - + /** * Destructor of the Bitmap_cubical_complex_base class. - **/ - virtual ~Bitmap_cubical_complex_base(){} + **/ + virtual ~Bitmap_cubical_complex_base(){} /** * The functions get_boundary_of_a_cell, get_coboundary_of_a_cell, get_dimension_of_a_cell @@ -130,7 +130,9 @@ public: **/ inline unsigned get_dimension_of_a_cell( size_t cell )const; /** - * In the case of get_cell_data, the output parameter is a reference to the value of a cube in a given position. + * In the case of get_cell_data, the output parameter is a reference to the value of a cube in a given position. This allows reading and changing the value of filtration. + * Note that if the value of a filtration is changed, the code do not check if we have a filtration or not. i.e. it do not check if the value of a filtration of a cell is + * not smaller than the value of a filtration of its boundary and not greater than the value of its coboundary. **/ inline T& get_cell_data( size_t cell ); @@ -162,27 +164,27 @@ public: * Writing to stream operator. **/ template - friend ostream& operator << ( ostream & os , const Bitmap_cubical_complex_base& b ); - - + friend ostream& operator << ( ostream & os , const Bitmap_cubical_complex_base& b ); + + /** - * Function that put the input data to bins. Sometimes if most of the cells have different birth-death times, the performance of the algorithms to compute persistence gets - * worst. When dealing with this type of data, one may want to put different values on cells to some number of bins. The function put_data_toBins( size_t number_of_bins ) + * Function that put the input data to bins. Sometimes if most of the cells have different birth-death times, the performance of the algorithms to compute persistence gets + * worst. When dealing with this type of data, one may want to put different values on cells to some number of bins. The function put_data_toBins( size_t number_of_bins ) * ais designed for that purpose. The parameter of the function is the number of bins (distinct values) we want to have in the cubical complex. **/ - void put_data_toBins( size_t number_of_bins ); - + void put_data_toBins( size_t number_of_bins ); + /** - * Function that put the input data to bins. Sometimes if most of the cells have different birth-death times, the performance of the algorithms to compute persistence gets - * worst. When dealing with this type of data, one may want to put different values on cells to some number of bins. The function put_data_toBins( T diameter_of_bin ) is - * designed for that purpose. The parameter of it is the diameter of each bin. Note that the bottleneck distance between the persistence diagram of the cubical complex + * Function that put the input data to bins. Sometimes if most of the cells have different birth-death times, the performance of the algorithms to compute persistence gets + * worst. When dealing with this type of data, one may want to put different values on cells to some number of bins. The function put_data_toBins( T diameter_of_bin ) is + * designed for that purpose. The parameter of it is the diameter of each bin. Note that the bottleneck distance between the persistence diagram of the cubical complex * before and after using such a function will be bounded by the parameter diameter_of_bin. **/ - void put_data_toBins( T diameter_of_bin ); - + void put_data_toBins( T diameter_of_bin ); + /** * Functions to find min and max values of filtration. - **/ + **/ std::pair< T ,T > min_max_filtration(); //ITERATORS @@ -191,76 +193,179 @@ public: * Iterator through all cells in the complex (in order they appear in the structure -- i.e. * in lexicographical order). **/ - typedef typename std::vector< T >::iterator all_cells_iterator; + //typedef typename std::vector< T >::iterator all_cells_iterator; /** * Constant iterator through all cells in the complex (in order they appear in the structure -- i.e. * in lexicographical order). **/ - typedef typename std::vector< T >::const_iterator all_cells_const_iterator; - + //typedef typename std::vector< T >::const_iterator all_cells_const_iterator; + /** * Function returning a constant iterator to the first cell of the bitmap. **/ - all_cells_const_iterator all_cells_const_begin()const - { - return this->data.begin(); - } - - + //all_cells_const_iterator all_cells_const_begin()const + //{ + // return this->data.begin(); + //} + + /** * Function returning a constant iterator to the last cell of the bitmap. **/ - all_cells_const_iterator all_cells_const_end()const + //all_cells_const_iterator all_cells_const_end()const + //{ + // return this->data.end(); + //} + + /** + * Function returning an iterator to the first cell of the bitmap. + **/ + //all_cells_iterator all_cells_begin() + //{ + // return this->data.begin(); + //} + + /** + * Function returning a constant iterator to the first cell of the bitmap. + **/ + //all_cells_const_iterator all_cells_begin() const + //{ + // return this->data.begin(); + //} + + /** + * Function returning an iterator to the last cell of the bitmap. + **/ + //all_cells_iterator all_cells_end() + //{ + // return this->data.end(); + //} + + /** + * Function returning a constant iterator to the last cell of the bitmap. + **/ + //all_cells_const_iterator all_cells_end() const + //{ + // return this->data.end(); + //} + + /** + * Iterator through all cells in the complex (in order they appear in the structure -- i.e. + * in lexicographical order). + **/ + class All_cells_iterator : std::iterator< std::input_iterator_tag, T > { - return this->data.end(); - } + public: + All_cells_iterator() + { + this->counter = 0; + } + All_cells_iterator operator++() + { + //first find first element of the counter that can be increased: + ++this->counter; + return *this; + } + All_cells_iterator operator++(int) + { + All_cells_iterator result = *this; + ++(*this); + return result; + } + All_cells_iterator operator =( const All_cells_iterator& rhs ) + { + this->counter = rhs.counter; + return *this; + } + bool operator == ( const All_cells_iterator& rhs )const + { + if ( this->counter != rhs.counter )return false; + return true; + } + bool operator != ( const All_cells_iterator& rhs )const + { + return !(*this == rhs); + } + size_t operator*() + { + return this->counter; + } + friend class Bitmap_cubical_complex_base; + protected: + size_t counter; + }; + /** - * Function returning an iterator to the first cell of the bitmap. + * Function returning a All_cells_iterator to the first cell of the bitmap. **/ - all_cells_iterator all_cells_begin() + All_cells_iterator all_cells_iterator_begin() { - return this->data.begin(); - } - + All_cells_iterator a; + return a; + } + /** - * Function returning a constant iterator to the first cell of the bitmap. + * Function returning a All_cells_iterator to the last cell of the bitmap. **/ - all_cells_const_iterator all_cells_begin() const + All_cells_iterator all_cells_iterator_end() { - return this->data.begin(); - } - + All_cells_iterator a; + a.counter = this->data.size(); + return a; + } + /** - * Function returning an iterator to the last cell of the bitmap. + * Boundary_range class provides ranges for boundary iterators. + **/ + typedef typename std::vector< size_t >::iterator Boundary_iterator; + typedef typename std::vector< size_t > Boundary_range; + + /** + * boundary_simplex_range creates an object of a Boundary_simplex_range class + * that provides ranges for the Boundary_simplex_iterator. **/ - all_cells_iterator all_cells_end() + Boundary_range boundary_range(size_t sh) { - return this->data.end(); - } - + return this->get_boundary_of_a_cell(sh); + } + /** - * Function returning a constant iterator to the last cell of the bitmap. + * Coboundary_range class provides ranges for boundary iterators. + **/ + typedef typename std::vector< size_t >::iterator Coboundary_iterator; + typedef typename std::vector< size_t > Coboundary_range; + + /** + * boundary_simplex_range creates an object of a Boundary_simplex_range class + * that provides ranges for the Boundary_simplex_iterator. **/ - all_cells_const_iterator all_cells_end() const + Coboundary_range coboundary_range(size_t sh) { - return this->data.end(); - } + return this->get_coboundary_of_a_cell(sh); + } + + + + + + + /** * Iterator through top dimensional cells of the complex. The cells appear in order they are stored * in the structure (i.e. in lexicographical order) **/ - class Top_dimensional_cells_iterator : std::iterator< std::input_iterator_tag, double > + class Top_dimensional_cells_iterator : std::iterator< std::input_iterator_tag, T > { public: Top_dimensional_cells_iterator( Bitmap_cubical_complex_base& b ):b(b) { - this->counter = std::vector(b.dimension()); - //std::fill( this->counter.begin() , this->counter.end() , 0 ); - } + this->counter = std::vector(b.dimension()); + //std::fill( this->counter.begin() , this->counter.end() , 0 ); + } Top_dimensional_cells_iterator operator++() { //first find first element of the counter that can be increased: @@ -308,15 +413,20 @@ public: return !(*this == rhs); } - T& operator*() - { - //given the counter, compute the index in the array and return this element. - unsigned index = 0; - for ( size_t i = 0 ; i != this->counter.size() ; ++i ) - { - index += (2*this->counter[i]+1)*this->b.multipliers[i]; - } - return this->b.data[index]; + //T& operator*() + //{ + // //given the counter, compute the index in the array and return this element. + // unsigned index = 0; + // for ( size_t i = 0 ; i != this->counter.size() ; ++i ) + // { + // index += (2*this->counter[i]+1)*this->b.multipliers[i]; + // } + // return this->b.data[index]; + //} + + size_t operator*() + { + return this->compute_index_in_bitmap(); } size_t compute_index_in_bitmap()const @@ -327,7 +437,8 @@ public: index += (2*this->counter[i]+1)*this->b.multipliers[i]; } return index; - } + } + void print_counter()const { @@ -340,19 +451,19 @@ public: protected: std::vector< size_t > counter; Bitmap_cubical_complex_base& b; - }; - + }; + /** - * Function returning a Top_dimensional_cells_iterator to the first top dimensional cell cell of the bitmap. + * Function returning a Top_dimensional_cells_iterator to the first top dimensional cell of the bitmap. **/ Top_dimensional_cells_iterator top_dimensional_cells_begin() { Top_dimensional_cells_iterator a(*this); return a; - } - + } + /** - * Function returning a Top_dimensional_cells_iterator to the last top dimensional cell cell of the bitmap. + * Function returning a Top_dimensional_cells_iterator to the last top dimensional cell of the bitmap. **/ Top_dimensional_cells_iterator top_dimensional_cells_end() { @@ -370,11 +481,11 @@ public: //****************************************************************************************************************// //****************************************************************************************************************// //****************************************************************************************************************// - - -inline size_t number_cells()const -{ - return this->total_number_of_cells; + + +inline size_t number_cells()const +{ + return this->total_number_of_cells; } //****************************************************************************************************************// @@ -412,7 +523,7 @@ protected: std::vector compute_counter_for_given_cell( size_t cell )const { - std::vector counter; + std::vector counter; counter.reserve( this->sizes.size() ); for ( size_t dim = this->sizes.size() ; dim != 0 ; --dim ) { @@ -421,59 +532,59 @@ protected: } std::reverse( counter.begin() , counter.end() ); return counter; - } - void read_perseus_style_file( const char* perseus_style_file ); - void setup_bitmap_based_on_top_dimensional_cells_list(const std::vector& sizes_in_following_directions , const std::vector& top_dimensional_cells); - Bitmap_cubical_complex_base( const char* perseus_style_file , std::vector directions ); - Bitmap_cubical_complex_base( const std::vector& sizes , std::vector directions ); + } + void read_perseus_style_file( const char* perseus_style_file ); + void setup_bitmap_based_on_top_dimensional_cells_list(const std::vector& sizes_in_following_directions , const std::vector& top_dimensional_cells); + Bitmap_cubical_complex_base( const char* perseus_style_file , std::vector directions ); + Bitmap_cubical_complex_base( const std::vector& sizes , std::vector directions ); Bitmap_cubical_complex_base( const std::vector& dimensions , const std::vector& top_dimensional_cells , std::vector directions ); }; +template +void Bitmap_cubical_complex_base::put_data_toBins( size_t number_of_bins ) +{ + bool bdg = false; + + std::pair< T ,T > min_max = this->min_max_filtration(); + T dx = (min_max.second-min_max.first)/(T)number_of_bins; + + //now put the data into the appropriate bins: + for ( size_t i = 0 ; i != this->data.size() ; ++i ) + { + if ( bdg ){cerr << "Before binning : " << this->data[i] << endl;} + this->data[i] = min_max.first + dx*(this->data[i]-min_max.first)/number_of_bins; + if ( bdg ){cerr << "After binning : " << this->data[i] << endl;getchar();} + } +} + template -void Bitmap_cubical_complex_base::put_data_toBins( size_t number_of_bins ) -{ - bool bdg = false; - - std::pair< T ,T > min_max = this->min_max_filtration(); - T dx = (min_max.second-min_max.first)/(T)number_of_bins; - - //now put the data into the appropriate bins: - for ( size_t i = 0 ; i != this->data.size() ; ++i ) - { - if ( bdg ){cerr << "Before binning : " << this->data[i] << endl;} - this->data[i] = min_max.first + dx*(this->data[i]-min_max.first)/number_of_bins; - if ( bdg ){cerr << "After binning : " << this->data[i] << endl;getchar();} - } -} - -template -void Bitmap_cubical_complex_base::put_data_toBins( T diameter_of_bin ) -{ - bool bdg = false; - std::pair< T ,T > min_max = this->min_max_filtration(); - - size_t number_of_bins = (min_max.second - min_max.first)/diameter_of_bin; - //now put the data into the appropriate bins: - for ( size_t i = 0 ; i != this->data.size() ; ++i ) - { - if ( bdg ){cerr << "Before binning : " << this->data[i] << endl;} - this->data[i] = min_max.first + diameter_of_bin*(this->data[i]-min_max.first)/number_of_bins; - if ( bdg ){cerr << "After binning : " << this->data[i] << endl;getchar();} - } -} - -template -std::pair< T ,T > Bitmap_cubical_complex_base::min_max_filtration() -{ - std::pair< T ,T > min_max( std::numeric_limits::max() , std::numeric_limits::min() ); - for ( size_t i = 0 ; i != this->data.size() ; ++i ) - { - if ( this->data[i] < min_max.first )min_max.first = this->data[i]; - if ( this->data[i] > min_max.second )min_max.second = this->data[i]; - } - return min_max; -} +void Bitmap_cubical_complex_base::put_data_toBins( T diameter_of_bin ) +{ + bool bdg = false; + std::pair< T ,T > min_max = this->min_max_filtration(); + + size_t number_of_bins = (min_max.second - min_max.first)/diameter_of_bin; + //now put the data into the appropriate bins: + for ( size_t i = 0 ; i != this->data.size() ; ++i ) + { + if ( bdg ){cerr << "Before binning : " << this->data[i] << endl;} + this->data[i] = min_max.first + diameter_of_bin*(this->data[i]-min_max.first)/number_of_bins; + if ( bdg ){cerr << "After binning : " << this->data[i] << endl;getchar();} + } +} + +template +std::pair< T ,T > Bitmap_cubical_complex_base::min_max_filtration() +{ + std::pair< T ,T > min_max( std::numeric_limits::max() , std::numeric_limits::min() ); + for ( size_t i = 0 ; i != this->data.size() ; ++i ) + { + if ( this->data[i] < min_max.first )min_max.first = this->data[i]; + if ( this->data[i] > min_max.second )min_max.second = this->data[i]; + } + return min_max; +} template @@ -494,10 +605,10 @@ Bitmap_cubical_complex_base::Bitmap_cubical_complex_base { this->set_up_containers( sizes ); } - -template -void Bitmap_cubical_complex_base::setup_bitmap_based_on_top_dimensional_cells_list(const std::vector& sizes_in_following_directions , const std::vector& top_dimensional_cells) -{ + +template +void Bitmap_cubical_complex_base::setup_bitmap_based_on_top_dimensional_cells_list(const std::vector& sizes_in_following_directions , const std::vector& top_dimensional_cells) +{ this->set_up_containers( sizes_in_following_directions ); size_t number_of_top_dimensional_elements = 1; @@ -523,22 +634,22 @@ void Bitmap_cubical_complex_base::setup_bitmap_based_on_top_dimensional_cells size_t index = 0; for ( it = this->top_dimensional_cells_begin() ; it != this->top_dimensional_cells_end() ; ++it ) { - (*it) = top_dimensional_cells[index]; + this->get_cell_data(*it) = top_dimensional_cells[index]; ++index; } - this->impose_lower_star_filtration(); -} + this->impose_lower_star_filtration(); +} template Bitmap_cubical_complex_base::Bitmap_cubical_complex_base ( const std::vector& sizes_in_following_directions , const std::vector& top_dimensional_cells ) { this->setup_bitmap_based_on_top_dimensional_cells_list( sizes_in_following_directions , top_dimensional_cells ); -} - -template -void Bitmap_cubical_complex_base::read_perseus_style_file( const char* perseus_style_file ) -{ +} + +template +void Bitmap_cubical_complex_base::read_perseus_style_file( const char* perseus_style_file ) +{ bool dbg = false; ifstream inFiltration, inIds; inFiltration.open( perseus_style_file ); @@ -547,7 +658,7 @@ void Bitmap_cubical_complex_base::read_perseus_style_file( const char* perseu if (dbg){cerr << "dimensionOfData : " << dimensionOfData << endl;getchar();} - std::vector sizes; + std::vector sizes; sizes.reserve( dimensionOfData ); for ( size_t i = 0 ; i != dimensionOfData ; ++i ) { @@ -564,7 +675,7 @@ void Bitmap_cubical_complex_base::read_perseus_style_file( const char* perseu while ( !inFiltration.eof() ) { - double filtrationLevel; + T filtrationLevel; inFiltration >> filtrationLevel; if ( dbg ) { @@ -574,35 +685,35 @@ void Bitmap_cubical_complex_base::read_perseus_style_file( const char* perseu << this->get_dimension_of_a_cell(it.compute_index_in_bitmap()) << " get the value : " << filtrationLevel << endl; } - *it = filtrationLevel; + this->get_cell_data(*it) = filtrationLevel; ++it; } inFiltration.close(); - this->impose_lower_star_filtration(); -} - -template -Bitmap_cubical_complex_base::Bitmap_cubical_complex_base( const char* perseus_style_file , std::vector directions ) -{ - //this constructor is here just for compatibility with a class that creates cubical complexes with periodic bundary conditions. - //It ignores the last parameter of the function. - this->read_perseus_style_file( perseus_style_file ); -} - -template -Bitmap_cubical_complex_base::Bitmap_cubical_complex_base( const std::vector& sizes , std::vector directions ) -{ - //this constructor is here just for compatibility with a class that creates cubical complexes with periodic bundary conditions. - //It ignores the last parameter of the function. - this->set_up_containers( sizes ); -} - -template + this->impose_lower_star_filtration(); +} + +template +Bitmap_cubical_complex_base::Bitmap_cubical_complex_base( const char* perseus_style_file , std::vector directions ) +{ + //this constructor is here just for compatibility with a class that creates cubical complexes with periodic bundary conditions. + //It ignores the last parameter of the function. + this->read_perseus_style_file( perseus_style_file ); +} + +template +Bitmap_cubical_complex_base::Bitmap_cubical_complex_base( const std::vector& sizes , std::vector directions ) +{ + //this constructor is here just for compatibility with a class that creates cubical complexes with periodic bundary conditions. + //It ignores the last parameter of the function. + this->set_up_containers( sizes ); +} + +template Bitmap_cubical_complex_base::Bitmap_cubical_complex_base( const std::vector& dimensions , const std::vector& top_dimensional_cells , std::vector directions ) -{ - //this constructor is here just for compatibility with a class that creates cubical complexes with periodic bundary conditions. - //It ignores the last parameter of the function. - this->setup_bitmap_based_on_top_dimensional_cells_list( dimensions , top_dimensional_cells ); +{ + //this constructor is here just for compatibility with a class that creates cubical complexes with periodic bundary conditions. + //It ignores the last parameter of the function. + this->setup_bitmap_based_on_top_dimensional_cells_list( dimensions , top_dimensional_cells ); } template @@ -615,29 +726,29 @@ Bitmap_cubical_complex_base::Bitmap_cubical_complex_base( const char* perseus template std::vector< size_t > Bitmap_cubical_complex_base::get_boundary_of_a_cell( size_t cell )const { - std::vector< size_t > boundary_elements; - - //Speed traded of for memory. Check if it is better in practice. - boundary_elements.reserve( this->dimension()*2 ); + std::vector< size_t > boundary_elements; + + //Speed traded of for memory. Check if it is better in practice. + boundary_elements.reserve( this->dimension()*2 ); size_t cell1 = cell; for ( size_t i = this->multipliers.size() ; i != 0 ; --i ) { unsigned position = cell1/this->multipliers[i-1]; if ( position%2 == 1 ) - { - boundary_elements.push_back( cell - this->multipliers[ i-1 ] ); + { + boundary_elements.push_back( cell - this->multipliers[ i-1 ] ); boundary_elements.push_back( cell + this->multipliers[ i-1 ] ); } cell1 = cell1%this->multipliers[i-1]; } return boundary_elements; -} - - - +} + + + template std::vector< size_t > Bitmap_cubical_complex_base::get_coboundary_of_a_cell( size_t cell )const { @@ -662,8 +773,8 @@ std::vector< size_t > Bitmap_cubical_complex_base::get_coboundary_of_a_cell( cell1 = cell1%this->multipliers[i-1]; } return coboundary_elements; -} - +} + @@ -712,14 +823,14 @@ void Bitmap_cubical_complex_base::impose_lower_star_filtration() //this vector will be used to check which elements have already been taken care of //in imposing lower star filtration: std::vector is_this_cell_considered( this->data.size() , false ); - - size_t size_to_reserve = 1; - for ( size_t i = 0 ; i != this->multipliers.size() ; ++i ) - { - size_to_reserve *= (size_t)((this->multipliers[i]-1)/2); - } - - std::vector indices_to_consider; + + size_t size_to_reserve = 1; + for ( size_t i = 0 ; i != this->multipliers.size() ; ++i ) + { + size_to_reserve *= (size_t)((this->multipliers[i]-1)/2); + } + + std::vector indices_to_consider; indices_to_consider.reserve( size_to_reserve ); //we assume here that we already have a filtration on the top dimensional cells and //we have to extend it to lower ones. @@ -745,20 +856,20 @@ void Bitmap_cubical_complex_base::impose_lower_star_filtration() { std::vector bd = this->get_boundary_of_a_cell( indices_to_consider[i] ); for ( size_t boundaryIt = 0 ; boundaryIt != bd.size() ; ++boundaryIt ) - { - if ( dbg ) - { - cerr << "filtration of a cell : " << bd[boundaryIt] << " is : " << this->data[ bd[boundaryIt] ] << " while of a cell: " << indices_to_consider[i] << " is: " << this->data[ indices_to_consider[i] ] << endl; - getchar(); - + { + if ( dbg ) + { + cerr << "filtration of a cell : " << bd[boundaryIt] << " is : " << this->data[ bd[boundaryIt] ] << " while of a cell: " << indices_to_consider[i] << " is: " << this->data[ indices_to_consider[i] ] << endl; + getchar(); + } if ( this->data[ bd[boundaryIt] ] > this->data[ indices_to_consider[i] ] ) { - this->data[ bd[boundaryIt] ] = this->data[ indices_to_consider[i] ]; - if ( dbg ) - { - cerr << "Setting the value of a cell : " << bd[boundaryIt] << " to : " << this->data[ indices_to_consider[i] ] << endl; - getchar(); + this->data[ bd[boundaryIt] ] = this->data[ indices_to_consider[i] ]; + if ( dbg ) + { + cerr << "Setting the value of a cell : " << bd[boundaryIt] << " to : " << this->data[ indices_to_consider[i] ] << endl; + getchar(); } } if ( is_this_cell_considered[ bd[boundaryIt] ] == false ) @@ -797,4 +908,4 @@ bool compareFirstElementsOfTuples( const std::pair< std::pair< T , size_t > , ch } -} +} diff --git a/src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h b/src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h index 8c1254db..9a5ef0eb 100644 --- a/src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h +++ b/src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h @@ -121,7 +121,7 @@ void Bitmap_cubical_complex_periodic_boundary_conditions_base::construct_comp size_t i = 0; for ( typename Bitmap_cubical_complex_periodic_boundary_conditions_base::Top_dimensional_cells_iterator it = this->top_dimensional_cells_begin() ; it != this->top_dimensional_cells_end() ; ++it ) { - *it = topDimensionalCells[i]; + this->get_cell_data(*it) = topDimensionalCells[i]; ++i; } this->impose_lower_star_filtration(); @@ -178,7 +178,7 @@ Bitmap_cubical_complex_periodic_boundary_conditions_base::Bitmap_cubical_comp << this->get_dimension_of_a_cell(it.compute_index_in_bitmap()) << " get the value : " << filtrationLevel << endl; } - *it = filtrationLevel; + this->get_cell_data(*it) = filtrationLevel; ++it; } inFiltration.close(); diff --git a/src/Bitmap_cubical_complex/test/Bitmap_test.cpp b/src/Bitmap_cubical_complex/test/Bitmap_test.cpp index 968483a3..c1c846c9 100644 --- a/src/Bitmap_cubical_complex/test/Bitmap_test.cpp +++ b/src/Bitmap_cubical_complex/test/Bitmap_test.cpp @@ -95,13 +95,13 @@ BOOST_AUTO_TEST_CASE(topDimensionalCellsIterator_test) { int i = 0; for (Bitmap_cubical_complex< Bitmap_cubical_complex_base >::Top_dimensional_cells_iterator it = increasing.top_dimensional_cells_begin(); it != increasing.top_dimensional_cells_end(); ++it) { - BOOST_CHECK(*it == expectedFiltrationValues2[i]); + BOOST_CHECK(increasing.get_cell_data(*it) == expectedFiltrationValues2[i]); ++i; } i = 0; for (Bitmap_cubical_complex< Bitmap_cubical_complex_base >::Top_dimensional_cells_iterator it = hole.top_dimensional_cells_begin(); it != hole.top_dimensional_cells_end(); ++it) { - BOOST_CHECK(*it == expectedFiltrationValues1[i]); + BOOST_CHECK(hole.get_cell_data(*it) == expectedFiltrationValues1[i]); ++i; } } @@ -884,3 +884,182 @@ BOOST_AUTO_TEST_CASE(bitmap_2d_with_periodic_bcond_filtration) { BOOST_CHECK( filtration[i] == cmplx.get_cell_data(i) ); } } + +BOOST_AUTO_TEST_CASE(all_cells_iterator_and_boundary_iterators_in_Bitmap_cubical_complex_base_check) +{ + std::vector< double > expected_filtration; + expected_filtration.push_back(0); + expected_filtration.push_back(0); + expected_filtration.push_back(0); + expected_filtration.push_back(1); + expected_filtration.push_back(1); + expected_filtration.push_back(0); + expected_filtration.push_back(0); + expected_filtration.push_back(0); + expected_filtration.push_back(1); + expected_filtration.push_back(1); + expected_filtration.push_back(0); + expected_filtration.push_back(0); + expected_filtration.push_back(0); + expected_filtration.push_back(1); + expected_filtration.push_back(1); + expected_filtration.push_back(2); + expected_filtration.push_back(2); + expected_filtration.push_back(2); + expected_filtration.push_back(3); + expected_filtration.push_back(3); + expected_filtration.push_back(2); + expected_filtration.push_back(2); + expected_filtration.push_back(2); + expected_filtration.push_back(3); + expected_filtration.push_back(3); + + std::vector expected_dimension; + expected_dimension.push_back(0); + expected_dimension.push_back(1); + expected_dimension.push_back(0); + expected_dimension.push_back(1); + expected_dimension.push_back(0); + expected_dimension.push_back(1); + expected_dimension.push_back(2); + expected_dimension.push_back(1); + expected_dimension.push_back(2); + expected_dimension.push_back(1); + expected_dimension.push_back(0); + expected_dimension.push_back(1); + expected_dimension.push_back(0); + expected_dimension.push_back(1); + expected_dimension.push_back(0); + expected_dimension.push_back(1); + expected_dimension.push_back(2); + expected_dimension.push_back(1); + expected_dimension.push_back(2); + expected_dimension.push_back(1); + expected_dimension.push_back(0); + expected_dimension.push_back(1); + expected_dimension.push_back(0); + expected_dimension.push_back(1); + expected_dimension.push_back(0); + + std::vector expected_boundary; + expected_boundary.push_back(0); + expected_boundary.push_back(2); + expected_boundary.push_back(2); + expected_boundary.push_back(4); + expected_boundary.push_back(0); + expected_boundary.push_back(10); + expected_boundary.push_back(1); + expected_boundary.push_back(11); + expected_boundary.push_back(5); + expected_boundary.push_back(7); + expected_boundary.push_back(2); + expected_boundary.push_back(12); + expected_boundary.push_back(3); + expected_boundary.push_back(13); + expected_boundary.push_back(7); + expected_boundary.push_back(9); + expected_boundary.push_back(4); + expected_boundary.push_back(14); + expected_boundary.push_back(10); + expected_boundary.push_back(12); + expected_boundary.push_back(12); + expected_boundary.push_back(14); + expected_boundary.push_back(10); + expected_boundary.push_back(20); + expected_boundary.push_back(11); + expected_boundary.push_back(21); + expected_boundary.push_back(15); + expected_boundary.push_back(17); + expected_boundary.push_back(12); + expected_boundary.push_back(22); + expected_boundary.push_back(13); + expected_boundary.push_back(23); + expected_boundary.push_back(17); + expected_boundary.push_back(19); + expected_boundary.push_back(14); + expected_boundary.push_back(24); + expected_boundary.push_back(20); + expected_boundary.push_back(22); + expected_boundary.push_back(22); + expected_boundary.push_back(24); + + + std::vector expected_coboundary; + expected_coboundary.push_back(5); + expected_coboundary.push_back(1); + expected_coboundary.push_back(6); + expected_coboundary.push_back(7); + expected_coboundary.push_back(1); + expected_coboundary.push_back(3); + expected_coboundary.push_back(8); + expected_coboundary.push_back(9); + expected_coboundary.push_back(3); + expected_coboundary.push_back(6); + expected_coboundary.push_back(6); + expected_coboundary.push_back(8); + expected_coboundary.push_back(8); + expected_coboundary.push_back(5); + expected_coboundary.push_back(15); + expected_coboundary.push_back(11); + expected_coboundary.push_back(6); + expected_coboundary.push_back(16); + expected_coboundary.push_back(7); + expected_coboundary.push_back(17); + expected_coboundary.push_back(11); + expected_coboundary.push_back(13); + expected_coboundary.push_back(8); + expected_coboundary.push_back(18); + expected_coboundary.push_back(9); + expected_coboundary.push_back(19); + expected_coboundary.push_back(13); + expected_coboundary.push_back(16); + expected_coboundary.push_back(16); + expected_coboundary.push_back(18); + expected_coboundary.push_back(18); + expected_coboundary.push_back(15); + expected_coboundary.push_back(21); + expected_coboundary.push_back(16); + expected_coboundary.push_back(17); + expected_coboundary.push_back(21); + expected_coboundary.push_back(23); + expected_coboundary.push_back(18); + expected_coboundary.push_back(19); + expected_coboundary.push_back(23); + + + + std::vector< unsigned > sizes(2); + sizes[0] = 2; + sizes[1] = 2; + + std::vector< double > data(4); + data[0] = 0; + data[1] = 1; + data[2] = 2; + data[3] = 3; + + Bitmap_cubical_complex_base ba( sizes , data ); + int i = 0; + int bd_it = 0; + int cbd_it = 0; + for ( Bitmap_cubical_complex_base::All_cells_iterator it = ba.all_cells_iterator_begin() ; it != ba.all_cells_iterator_end() ; ++it ) + { + BOOST_CHECK( expected_filtration[i] == ba.get_cell_data( *it ) ); + BOOST_CHECK( expected_dimension[i] == ba.get_dimension_of_a_cell( *it ) ); + + Bitmap_cubical_complex_base::Boundary_range bdrange = ba.boundary_range(*it); + for ( Bitmap_cubical_complex_base::Boundary_iterator bd = bdrange.begin() ; bd != bdrange.end() ; ++bd ) + { + BOOST_CHECK( expected_boundary[bd_it] == *bd ); + ++bd_it; + } + + Bitmap_cubical_complex_base::Coboundary_range cbdrange = ba.coboundary_range(*it); + for ( Bitmap_cubical_complex_base::Coboundary_iterator cbd = cbdrange.begin() ; cbd != cbdrange.end() ; ++cbd ) + { + BOOST_CHECK( expected_coboundary[cbd_it] == *cbd ); + ++cbd_it; + } + ++i; + } +} -- cgit v1.2.3