summaryrefslogtreecommitdiff
path: root/src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex_base.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex_base.h')
-rw-r--r--src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex_base.h37
1 files changed, 26 insertions, 11 deletions
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();