diff options
author | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2019-02-12 14:59:28 +0000 |
---|---|---|
committer | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2019-02-12 14:59:28 +0000 |
commit | 36e654407b7f4bbedc2790e9c0d6e8ec60415258 (patch) | |
tree | 0da92a78fad0b15c119c18480b6d98d94924c78e /src | |
parent | 2905296b253588bd43de924d44585f9bfbd45540 (diff) | |
parent | f29a6e9a03dca95dc0a070b604fb11e18897a6f6 (diff) |
merge cubical_small_fix to fix
https://gitlab.inria.fr/GUDHI/gudhi-devel/issues/5 [Bitmap_cubical_complex] Perseus file reader rejects infinity
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@4103 636b058d-ea47-450e-bf9e-a15bfbe3eedb
Former-commit-id: b036b89564e31e4c385cb0b782db22a3ca445a9f
Diffstat (limited to 'src')
-rw-r--r-- | src/Bitmap_cubical_complex/doc/Gudhi_Cubical_Complex_doc.h | 11 | ||||
-rw-r--r-- | src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex_base.h | 37 | ||||
-rw-r--r-- | src/Bitmap_cubical_complex/test/Bitmap_test.cpp | 15 | ||||
-rw-r--r-- | src/Bitmap_cubical_complex/test/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/common/doc/file_formats.h | 6 | ||||
-rw-r--r-- | src/cython/doc/cubical_complex_user.rst | 10 | ||||
-rw-r--r-- | src/cython/doc/fileformats.rst | 10 | ||||
-rw-r--r-- | src/cython/doc/nerve_gic_complex_ref.rst | 4 | ||||
-rw-r--r-- | src/cython/doc/nerve_gic_complex_user.rst | 4 |
9 files changed, 82 insertions, 18 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..5fa02a5e 100644 --- a/src/Bitmap_cubical_complex/doc/Gudhi_Cubical_Complex_doc.h +++ b/src/Bitmap_cubical_complex/doc/Gudhi_Cubical_Complex_doc.h @@ -87,11 +87,16 @@ namespace cubical_complex { * * \section inputformat Input Format * - * In the current implantation, filtration is given at the maximal cubes, and it is then extended by the lower star + * In the current implementation, 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 inspired from the Perseus software + * (http://www.sas.upenn.edu/~vnanda/perseus/) by Vidit Nanda. + * \note 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 \f$+\infty\f$ (aka. `inf` in the file). + * + * The file format is described in details in \ref FileFormatsPerseus file format section. * * \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/Bitmap_cubical_complex/test/Bitmap_test.cpp b/src/Bitmap_cubical_complex/test/Bitmap_test.cpp index ca7bd986..6a917c25 100644 --- a/src/Bitmap_cubical_complex/test/Bitmap_test.cpp +++ b/src/Bitmap_cubical_complex/test/Bitmap_test.cpp @@ -32,6 +32,7 @@ #include <iostream> #include <sstream> #include <vector> +#include <limits> typedef Gudhi::cubical_complex::Bitmap_cubical_complex_base<double> Bitmap_cubical_complex_base; typedef Gudhi::cubical_complex::Bitmap_cubical_complex<Bitmap_cubical_complex_base> Bitmap_cubical_complex; @@ -1576,3 +1577,17 @@ BOOST_AUTO_TEST_CASE(compute_incidence_between_cells_test_periodic_boundary_cond } } } + +BOOST_AUTO_TEST_CASE(perseus_file_read) { + Bitmap_cubical_complex increasing("sinusoid.txt"); + + auto it = increasing.top_dimensional_cells_iterator_begin(); + double value = increasing.get_cell_data(*it); + std::cout << "First value of sinusoid.txt is " << value << std::endl; + BOOST_CHECK(value == 10.); + // Next value + ++it; + value = increasing.get_cell_data(*it); + std::cout << "Second value of sinusoid.txt is " << value << std::endl; + BOOST_CHECK(value == std::numeric_limits<double>::infinity()); +} diff --git a/src/Bitmap_cubical_complex/test/CMakeLists.txt b/src/Bitmap_cubical_complex/test/CMakeLists.txt index 8b43632a..d2f002a6 100644 --- a/src/Bitmap_cubical_complex/test/CMakeLists.txt +++ b/src/Bitmap_cubical_complex/test/CMakeLists.txt @@ -2,6 +2,9 @@ project(Bitmap_cubical_complex_tests) include(GUDHI_test_coverage) +# Do not forget to copy test files in current binary dir +file(COPY "${CMAKE_SOURCE_DIR}/data/bitmap/sinusoid.txt" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) + add_executable ( Bitmap_cubical_complex_test_unit Bitmap_test.cpp ) target_link_libraries(Bitmap_cubical_complex_test_unit ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) if (TBB_FOUND) diff --git a/src/common/doc/file_formats.h b/src/common/doc/file_formats.h index 523153b8..23214e25 100644 --- a/src/common/doc/file_formats.h +++ b/src/common/doc/file_formats.h @@ -72,7 +72,7 @@ namespace Gudhi { \section FileFormatsPerseus Perseus - This file format is the format used by the Perseus software + This file format is a format inspired from the Perseus software (http://www.sas.upenn.edu/~vnanda/perseus/) by Vidit Nanda. The first line contains a number d begin the dimension of the bitmap (2 in the example below). Next d lines are the numbers of top dimensional cubes in each dimensions (3 and 3 @@ -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. + + \note 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 \f$+\infty\f$ (aka. `inf` in the file). */ } // namespace Gudhi diff --git a/src/cython/doc/cubical_complex_user.rst b/src/cython/doc/cubical_complex_user.rst index 320bd79b..19120360 100644 --- a/src/cython/doc/cubical_complex_user.rst +++ b/src/cython/doc/cubical_complex_user.rst @@ -83,9 +83,15 @@ Input Format. 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 :doc:`cubical_complex_ref`. -Currently one input from a text file is used. It uses a format used already in +Currently one input from a text file is used. It uses a format inspired from the Perseus software `Perseus software <http://www.sas.upenn.edu/~vnanda/perseus/>`_ by Vidit Nanda. -The file format is described here: :doc:`Perseus <fileformats>`. + +.. note:: + 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 :math:`+\infty` (aka. ``inf`` in the file). + +The file format is described in details in :ref:`Perseus file format` file format section. .. testcode:: diff --git a/src/cython/doc/fileformats.rst b/src/cython/doc/fileformats.rst index ff20f26e..e205cc8b 100644 --- a/src/cython/doc/fileformats.rst +++ b/src/cython/doc/fileformats.rst @@ -51,10 +51,12 @@ Here is a simple sample file in the 3D case:: 1. 1. 1. +.. _Perseus file format: + Perseus ******* -This file format is the format used by the +This file format is a format inspired from the `Perseus software <http://www.sas.upenn.edu/~vnanda/perseus/>`_ by Vidit Nanda. The first line contains a number d begin the dimension of the bitmap (2 in the example below). Next d lines are the numbers of top dimensional cubes in each @@ -88,3 +90,9 @@ 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. + +.. note:: + 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 + :math:`+\infty` (aka. ``inf`` in the file).
\ No newline at end of file diff --git a/src/cython/doc/nerve_gic_complex_ref.rst b/src/cython/doc/nerve_gic_complex_ref.rst index e24e01fc..abde2e8c 100644 --- a/src/cython/doc/nerve_gic_complex_ref.rst +++ b/src/cython/doc/nerve_gic_complex_ref.rst @@ -1,3 +1,7 @@ +:orphan: + +.. To get rid of WARNING: document isn't included in any toctree + ================================ Cover complexes reference manual ================================ diff --git a/src/cython/doc/nerve_gic_complex_user.rst b/src/cython/doc/nerve_gic_complex_user.rst index d774827e..44f30e1a 100644 --- a/src/cython/doc/nerve_gic_complex_user.rst +++ b/src/cython/doc/nerve_gic_complex_user.rst @@ -1,3 +1,7 @@ +:orphan: + +.. To get rid of WARNING: document isn't included in any toctree + Cover complexes user manual =========================== Definition |