summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2019-02-12 14:59:28 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2019-02-12 14:59:28 +0000
commit36e654407b7f4bbedc2790e9c0d6e8ec60415258 (patch)
tree0da92a78fad0b15c119c18480b6d98d94924c78e
parent2905296b253588bd43de924d44585f9bfbd45540 (diff)
parentf29a6e9a03dca95dc0a070b604fb11e18897a6f6 (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
-rw-r--r--data/bitmap/sinusoid.txt77
-rw-r--r--src/Bitmap_cubical_complex/doc/Gudhi_Cubical_Complex_doc.h11
-rw-r--r--src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex_base.h37
-rw-r--r--src/Bitmap_cubical_complex/test/Bitmap_test.cpp15
-rw-r--r--src/Bitmap_cubical_complex/test/CMakeLists.txt3
-rw-r--r--src/common/doc/file_formats.h6
-rw-r--r--src/cython/doc/cubical_complex_user.rst10
-rw-r--r--src/cython/doc/fileformats.rst10
-rw-r--r--src/cython/doc/nerve_gic_complex_ref.rst4
-rw-r--r--src/cython/doc/nerve_gic_complex_user.rst4
10 files changed, 159 insertions, 18 deletions
diff --git a/data/bitmap/sinusoid.txt b/data/bitmap/sinusoid.txt
new file mode 100644
index 00000000..4318a790
--- /dev/null
+++ b/data/bitmap/sinusoid.txt
@@ -0,0 +1,77 @@
+1
+75
+10.0
+inf
+6.581647338757176
+4.961839035093842
+3.4462687716225506
+2.0647730896031224
+0.843170409296631
+-0.19751272994853286
+-1.041671820306659
+-1.679592041609764
+-2.1077394076819154
+-2.3288666774217717
+-2.351930856552615
+-2.1918247624544565
+-1.8689306968915753
+-1.4085096027502502
+-0.8399440113300294
+-0.19585746852629526
+0.4888631699173285
+1.178113272962392
+1.835652464698967
+2.4261907229474
+2.916445996426541
+3.2761416444450404
+3.47891380654902
+3.503101508895332
+3.332395828417585
+2.956328659790991
+2.3705864371935323
+1.5771394088427577
+0.5841825900410704
+-0.5941098356746579
+-1.9380093068542301
+-3.4228241352585
+-5.019639498406313
+-6.696183996487342
+-8.417796803538899
+-10.148466428045634
+-11.851909952036825
+-13.492660404643832
+-15.037129682296172
+-16.454615160584872
+-17.71821983034286
+-18.80565838211054
+-19.699925081201553
+-20.389803417622236
+-20.870202256994908
+-21.142308418277846
+-21.213551105635062
+-21.0973792604076
+-20.812858505791425
+-20.38409976350673
+-19.839536666415423
+-19.211073422523185
+-18.53312866828296
+-17.841603966244676
+-17.172807860451854
+-16.562367734888753
+-16.044162085815913
+-15.649305207041936
+-15.405214716400426
+-15.334789869008524
+-15.455725282681154
+-15.779980642668242
+-16.3134222782912
+-17.055647353175157
+-17.999995937972063
+-19.13375060376363
+-20.438517554470188
+-21.890777875994743
+-23.46259238155293
+-25.122438929469578
+-26.836157119615592
+-28.567972056597156
+-30.281566498233445
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