diff options
-rw-r--r-- | src/Bitmap_cubical_complex/doc/Gudhi_Cubical_Complex_doc.h | 8 | ||||
-rw-r--r-- | src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex_base.h | 37 | ||||
-rw-r--r-- | src/common/doc/file_formats.h | 4 |
3 files changed, 36 insertions, 13 deletions
diff --git a/src/Bitmap_cubical_complex/doc/Gudhi_Cubical_Complex_doc.h b/src/Bitmap_cubical_complex/doc/Gudhi_Cubical_Complex_doc.h index d1836ef0..9e14455e 100644 --- a/src/Bitmap_cubical_complex/doc/Gudhi_Cubical_Complex_doc.h +++ b/src/Bitmap_cubical_complex/doc/Gudhi_Cubical_Complex_doc.h @@ -90,8 +90,12 @@ namespace cubical_complex { * In the current implantation, filtration is given at the maximal cubes, and it is then extended by the lower star * filtration to all cubes. There are a number of constructors that can be used to construct cubical complex by users * who want to use the code directly. They can be found in the \a Bitmap_cubical_complex class. - * Currently one input from a text file is used. It uses a format used already in Perseus software - * (http://www.sas.upenn.edu/~vnanda/perseus/) by Vidit Nanda. The file format is described here: \ref FileFormatsPerseus. + * Currently one input from a text file is used. It uses a format nspired from the Perseus software + * (http://www.sas.upenn.edu/~vnanda/perseus/) by Vidit Nanda. Note however an important difference: while Perseus + * assume the filtration of all maximal cubes to be non-negative, over here we do not enforce this and we allow any + * filtration values. + * As a consequence one cannot use -1's to indicate missing cubes. If you have missing cubes in your complex, please + * set their filtration to +Inf. The file format is described in details in here: \ref FileFormatsPerseus. * * \section PeriodicBoundaryConditions Periodic boundary conditions * Often one would like to impose periodic boundary conditions to the cubical complex. Let \f$ I_1\times ... \times 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 9b74e267..f5e005b2 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 @@ -650,18 +650,33 @@ void Bitmap_cubical_complex_base<T>::read_perseus_style_file(const char* perseus Bitmap_cubical_complex_base<T>::Top_dimensional_cells_iterator it(*this); it = this->top_dimensional_cells_iterator_begin(); - T filtrationLevel; - for (std::size_t i = 0; i < dimensions; ++i) { - if (!(inFiltration >> filtrationLevel) || (inFiltration.eof())) { - throw std::ios_base::failure("Bad Perseus file format."); - } - if (dbg) { - std::cerr << "Cell of an index : " << it.compute_index_in_bitmap() - << " and dimension: " << this->get_dimension_of_a_cell(it.compute_index_in_bitmap()) - << " get the value : " << filtrationLevel << std::endl; + T filtrationLevel = 0.; + std::size_t filtration_counter = 0; + while (!inFiltration.eof()) { + std::string line; + getline(inFiltration, line); + if (line.length() != 0) { + int n = sscanf(line.c_str(), "%lf", &filtrationLevel); + if (n != 1) { + std::string perseus_error("Bad Perseus file format. This line is incorrect : " + line); + throw std::ios_base::failure(perseus_error.c_str()); + } + + if (dbg) { + std::cerr << "Cell of an index : " << it.compute_index_in_bitmap() + << " and dimension: " << this->get_dimension_of_a_cell(it.compute_index_in_bitmap()) + << " get the value : " << filtrationLevel << std::endl; + } + this->get_cell_data(*it) = filtrationLevel; + ++it; + ++filtration_counter; } - this->get_cell_data(*it) = filtrationLevel; - ++it; + } + + if (filtration_counter != dimensions) { + std::string perseus_error("Bad Perseus file format. Read " + std::to_string(filtration_counter) + " expected " + \ + std::to_string(dimensions) + " values"); + throw std::ios_base::failure(perseus_error.c_str()); } inFiltration.close(); diff --git a/src/common/doc/file_formats.h b/src/common/doc/file_formats.h index 523153b8..d38d90e0 100644 --- a/src/common/doc/file_formats.h +++ b/src/common/doc/file_formats.h @@ -118,6 +118,10 @@ namespace Gudhi { Indicate that we have imposed periodic boundary conditions in the direction x, but not in the direction y. Other sample files can be found in the `data/bitmap` folder. + + Please note that unlike in Perseus format the filtration on the maximal cubes can be any double precision number. + Consequently one cannot mark the cubes that are not present with -1's. To do that please set their filtration value to + +Inf. */ } // namespace Gudhi |