From 644076d6f2de7d91a7694c94261c59da14264cd5 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 17 Jan 2019 17:14:20 +0000 Subject: Fix issue #5 : [Bitmap_cubical_complex] Perseus file reader rejects infinity git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/cubical_complex_small_fix@4064 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 77ec6d5d1f69ba3e1b0a1027d902084bb25d08f3 --- .../include/gudhi/Bitmap_cubical_complex_base.h | 37 +++++++++++++++------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'src/Bitmap_cubical_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 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::read_perseus_style_file(const char* perseus Bitmap_cubical_complex_base::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(); -- cgit v1.2.3