summaryrefslogtreecommitdiff
path: root/src/Persistent_cohomology
diff options
context:
space:
mode:
Diffstat (limited to 'src/Persistent_cohomology')
-rw-r--r--src/Persistent_cohomology/example/CMakeLists.txt63
-rw-r--r--src/Persistent_cohomology/example/alpha_complex_persistence.cpp4
-rw-r--r--src/Persistent_cohomology/example/custom_persistence_sort.cpp2
-rw-r--r--src/Persistent_cohomology/example/periodic_alpha_complex_3d_persistence.cpp24
-rw-r--r--src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h16
-rw-r--r--src/Persistent_cohomology/test/CMakeLists.txt22
-rw-r--r--src/Persistent_cohomology/test/persistent_cohomology_unit_test.cpp2
7 files changed, 77 insertions, 56 deletions
diff --git a/src/Persistent_cohomology/example/CMakeLists.txt b/src/Persistent_cohomology/example/CMakeLists.txt
index 186a6c33..5fb4ba12 100644
--- a/src/Persistent_cohomology/example/CMakeLists.txt
+++ b/src/Persistent_cohomology/example/CMakeLists.txt
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 2.6)
-project(GUDHIExPersCohom)
+project(Persistent_cohomology_examples)
# problem with Visual Studio link on Boost program_options
add_definitions( -DBOOST_ALL_NO_LIB )
@@ -21,11 +21,11 @@ add_executable(persistence_from_file persistence_from_file.cpp)
target_link_libraries(persistence_from_file ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY})
if (TBB_FOUND)
- target_link_libraries(plain_homology ${TBB_RELEASE_LIBRARY})
- target_link_libraries(persistence_from_simple_simplex_tree ${TBB_RELEASE_LIBRARY})
- target_link_libraries(rips_persistence ${TBB_RELEASE_LIBRARY})
- target_link_libraries(rips_persistence_via_boundary_matrix ${TBB_RELEASE_LIBRARY})
- target_link_libraries(persistence_from_file ${TBB_RELEASE_LIBRARY})
+ target_link_libraries(plain_homology ${TBB_LIBRARIES})
+ target_link_libraries(persistence_from_simple_simplex_tree ${TBB_LIBRARIES})
+ target_link_libraries(rips_persistence ${TBB_LIBRARIES})
+ target_link_libraries(rips_persistence_via_boundary_matrix ${TBB_LIBRARIES})
+ target_link_libraries(persistence_from_file ${TBB_LIBRARIES})
endif()
add_test(plain_homology ${CMAKE_CURRENT_BINARY_DIR}/plain_homology)
@@ -35,28 +35,34 @@ add_test(rips_persistence_via_boundary_matrix_3 ${CMAKE_CURRENT_BINARY_DIR}/rips
add_test(persistence_from_file_3_2_0 ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_file ${CMAKE_SOURCE_DIR}/data/points/bunny_5000.st -p 2 -m 0)
add_test(persistence_from_file_3_3_100 ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_file ${CMAKE_SOURCE_DIR}/data/points/bunny_5000.st -p 3 -m 100)
-if(GMPXX_FOUND AND GMP_FOUND)
- message("GMPXX_LIBRARIES = ${GMPXX_LIBRARIES}")
+if(GMP_FOUND)
message("GMP_LIBRARIES = ${GMP_LIBRARIES}")
- add_executable(rips_multifield_persistence rips_multifield_persistence.cpp )
- target_link_libraries(rips_multifield_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES})
- add_executable ( performance_rips_persistence performance_rips_persistence.cpp )
- target_link_libraries(performance_rips_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES})
- if (TBB_FOUND)
- target_link_libraries(rips_multifield_persistence ${TBB_RELEASE_LIBRARY})
- target_link_libraries(performance_rips_persistence ${TBB_RELEASE_LIBRARY})
- endif()
+ if(GMPXX_FOUND)
+ message("GMPXX_LIBRARIES = ${GMPXX_LIBRARIES}")
+
+ add_executable(rips_multifield_persistence rips_multifield_persistence.cpp )
+ target_link_libraries(rips_multifield_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES})
+ add_executable ( performance_rips_persistence performance_rips_persistence.cpp )
+ target_link_libraries(performance_rips_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES})
+ if (TBB_FOUND)
+ target_link_libraries(rips_multifield_persistence ${TBB_LIBRARIES})
+ target_link_libraries(performance_rips_persistence ${TBB_LIBRARIES})
+ endif(TBB_FOUND)
add_test(rips_multifield_persistence_2_71 ${CMAKE_CURRENT_BINARY_DIR}/rips_multifield_persistence ${CMAKE_SOURCE_DIR}/data/points/Kl.txt -r 0.2 -d 3 -p 2 -q 71 -m 100)
+ endif(GMPXX_FOUND)
+else()
+ # message(WARNING "GMP not found.")
+endif(GMP_FOUND)
if(CGAL_FOUND)
add_executable(alpha_complex_3d_persistence alpha_complex_3d_persistence.cpp)
- target_link_libraries(alpha_complex_3d_persistence ${Boost_SYSTEM_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES} ${CGAL_LIBRARY})
+ target_link_libraries(alpha_complex_3d_persistence ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY})
if (TBB_FOUND)
- target_link_libraries(alpha_complex_3d_persistence ${TBB_RELEASE_LIBRARY})
- endif()
+ target_link_libraries(alpha_complex_3d_persistence ${TBB_LIBRARIES})
+ endif(TBB_FOUND)
add_test(alpha_complex_3d_persistence_2_0_5 ${CMAKE_CURRENT_BINARY_DIR}/alpha_complex_3d_persistence ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off 2 0.45)
@@ -72,28 +78,27 @@ if(GMPXX_FOUND AND GMP_FOUND)
target_link_libraries(alpha_complex_persistence ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY})
add_executable(periodic_alpha_complex_3d_persistence periodic_alpha_complex_3d_persistence.cpp)
- target_link_libraries(periodic_alpha_complex_3d_persistence ${Boost_SYSTEM_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES} ${CGAL_LIBRARY})
+ target_link_libraries(periodic_alpha_complex_3d_persistence ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY})
add_executable(custom_persistence_sort custom_persistence_sort.cpp)
- target_link_libraries(custom_persistence_sort ${Boost_SYSTEM_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES} ${CGAL_LIBRARY})
+ target_link_libraries(custom_persistence_sort ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY})
if (TBB_FOUND)
- target_link_libraries(alpha_complex_persistence ${TBB_RELEASE_LIBRARY})
- target_link_libraries(periodic_alpha_complex_3d_persistence ${TBB_RELEASE_LIBRARY})
- target_link_libraries(custom_persistence_sort ${TBB_RELEASE_LIBRARY})
- endif()
+ target_link_libraries(alpha_complex_persistence ${TBB_LIBRARIES})
+ target_link_libraries(periodic_alpha_complex_3d_persistence ${TBB_LIBRARIES})
+ target_link_libraries(custom_persistence_sort ${TBB_LIBRARIES})
+ endif(TBB_FOUND)
add_test(alpha_complex_persistence_2_0_45 ${CMAKE_CURRENT_BINARY_DIR}/alpha_complex_persistence ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -m 0.45 -p 2)
- add_test(periodic_alpha_complex_3d_persistence_2_0 ${CMAKE_CURRENT_BINARY_DIR}/periodic_alpha_complex_3d_persistence ${CMAKE_SOURCE_DIR}/data/points/grid_10_10_10_in_0_1.off 2 0)
+ add_test(periodic_alpha_complex_3d_persistence_2_0 ${CMAKE_CURRENT_BINARY_DIR}/periodic_alpha_complex_3d_persistence ${CMAKE_SOURCE_DIR}/data/points/grid_10_10_10_in_0_1.off ${CMAKE_SOURCE_DIR}/data/points/iso_cuboid_3_in_0_1.txt 2 0)
add_test(custom_persistence_sort ${CMAKE_CURRENT_BINARY_DIR}/custom_persistence_sort)
else()
message(WARNING "Eigen3 not found. Version 3.1.0 is required for Alpha shapes feature.")
- endif()
+ endif(EIGEN3_FOUND)
else()
message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Alpha shapes feature. Version 4.6.0 is required.")
endif ()
else()
# message(WARNING "CGAL not found.")
- endif()
+ endif(CGAL_FOUND)
-endif()
diff --git a/src/Persistent_cohomology/example/alpha_complex_persistence.cpp b/src/Persistent_cohomology/example/alpha_complex_persistence.cpp
index 17fb84d2..cb181936 100644
--- a/src/Persistent_cohomology/example/alpha_complex_persistence.cpp
+++ b/src/Persistent_cohomology/example/alpha_complex_persistence.cpp
@@ -30,7 +30,7 @@ int main(int argc, char **argv) {
// Init of an alpha complex from an OFF file
// ----------------------------------------------------------------------------
using Kernel = CGAL::Epick_d< CGAL::Dynamic_dimension_tag >;
- Gudhi::alphacomplex::Alpha_complex<Kernel> alpha_complex_from_file(off_file_points, alpha_square_max_value);
+ Gudhi::alpha_complex::Alpha_complex<Kernel> alpha_complex_from_file(off_file_points, alpha_square_max_value);
// ----------------------------------------------------------------------------
// Display information about the alpha complex
@@ -44,7 +44,7 @@ int main(int argc, char **argv) {
std::cout << "Simplex_tree dim: " << alpha_complex_from_file.dimension() << std::endl;
// Compute the persistence diagram of the complex
- Gudhi::persistent_cohomology::Persistent_cohomology< Gudhi::alphacomplex::Alpha_complex<Kernel>,
+ Gudhi::persistent_cohomology::Persistent_cohomology< Gudhi::alpha_complex::Alpha_complex<Kernel>,
Gudhi::persistent_cohomology::Field_Zp > pcoh(alpha_complex_from_file);
// initializes the coefficient field for homology
pcoh.init_coefficients(coeff_field_characteristic);
diff --git a/src/Persistent_cohomology/example/custom_persistence_sort.cpp b/src/Persistent_cohomology/example/custom_persistence_sort.cpp
index d591a0d0..9af38611 100644
--- a/src/Persistent_cohomology/example/custom_persistence_sort.cpp
+++ b/src/Persistent_cohomology/example/custom_persistence_sort.cpp
@@ -37,7 +37,7 @@
using Kernel = CGAL::Epick_d< CGAL::Dimension_tag<3> >;
using Point = Kernel::Point_d;
-using Alpha_complex = Gudhi::alphacomplex::Alpha_complex<Kernel>;
+using Alpha_complex = Gudhi::alpha_complex::Alpha_complex<Kernel>;
std::vector<Point> random_points() {
// Instanciate a random point generator
diff --git a/src/Persistent_cohomology/example/periodic_alpha_complex_3d_persistence.cpp b/src/Persistent_cohomology/example/periodic_alpha_complex_3d_persistence.cpp
index b8e1097d..a199fea1 100644
--- a/src/Persistent_cohomology/example/periodic_alpha_complex_3d_persistence.cpp
+++ b/src/Persistent_cohomology/example/periodic_alpha_complex_3d_persistence.cpp
@@ -125,28 +125,28 @@ Vertex_list from(const Alpha_shape_3::Vertex_handle& vh) {
void usage(char * const progName) {
std::cerr << "Usage: " << progName <<
- " path_to_file_graph coeff_field_characteristic[integer > 0] min_persistence[float >= -1.0]\n";
+ " path_to_file_graph path_to_iso_cuboid_3_file coeff_field_characteristic[integer > 0] min_persistence[float >= -1.0]\n";
exit(-1);
}
int main(int argc, char * const argv[]) {
// program args management
- if (argc != 4) {
+ if (argc != 5) {
std::cerr << "Error: Number of arguments (" << argc << ") is not correct\n";
usage(argv[0]);
}
int coeff_field_characteristic = 0;
- int returnedScanValue = sscanf(argv[2], "%d", &coeff_field_characteristic);
+ int returnedScanValue = sscanf(argv[3], "%d", &coeff_field_characteristic);
if ((returnedScanValue == EOF) || (coeff_field_characteristic <= 0)) {
- std::cerr << "Error: " << argv[2] << " is not correct\n";
+ std::cerr << "Error: " << argv[3] << " is not correct\n";
usage(argv[0]);
}
Filtration_value min_persistence = 0.0;
- returnedScanValue = sscanf(argv[3], "%lf", &min_persistence);
+ returnedScanValue = sscanf(argv[4], "%lf", &min_persistence);
if ((returnedScanValue == EOF) || (min_persistence < -1.0)) {
- std::cerr << "Error: " << argv[3] << " is not correct\n";
+ std::cerr << "Error: " << argv[4] << " is not correct\n";
usage(argv[0]);
}
@@ -160,11 +160,21 @@ int main(int argc, char * const argv[]) {
usage(argv[0]);
}
+ // Read iso_cuboid_3 information from file
+ std::ifstream iso_cuboid_str(argv[2]);
+ double x_min, y_min, z_min, x_max, y_max, z_max;
+ if (iso_cuboid_str.good()) {
+ iso_cuboid_str >> x_min >> y_min >> z_min >> x_max >> y_max >> z_max;
+ } else {
+ std::cerr << "Unable to read file " << argv[2] << std::endl;
+ usage(argv[0]);
+ }
+
// Retrieve the triangulation
std::vector<Point_3> lp = off_reader.get_point_cloud();
// Define the periodic cube
- P3DT3 pdt(PK::Iso_cuboid_3(0, 0, 0, 1, 1, 1));
+ P3DT3 pdt(PK::Iso_cuboid_3(x_min, y_min, z_min, x_max, y_max, z_max));
// Heuristic for inserting large point sets (if pts is reasonably large)
pdt.insert(lp.begin(), lp.end(), true);
// As pdt won't be modified anymore switch to 1-sheeted cover if possible
diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
index efa9a367..a7d1e463 100644
--- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
+++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
@@ -594,7 +594,7 @@ class Persistent_cohomology {
}
/** @brief Returns Betti numbers.
- * @return A vector of persistent Betti numbers.
+ * @return A vector of Betti numbers.
*/
std::vector<int> betti_numbers() const {
// Init Betti numbers vector with zeros until Simplicial complex dimension
@@ -632,7 +632,7 @@ class Persistent_cohomology {
/** @brief Returns the persistent Betti numbers.
* @param[in] from The persistence birth limit to be added in the number \f$(persistent birth \leq from)\f$.
- * @param[in] to The persistence death limit to be added in the number \f$(persistent death > from)\f$.
+ * @param[in] to The persistence death limit to be added in the number \f$(persistent death > to)\f$.
* @return A vector of persistent Betti numbers.
*/
std::vector<int> persistent_betti_numbers(Filtration_value from, Filtration_value to) const {
@@ -641,7 +641,10 @@ class Persistent_cohomology {
for (auto pair : persistent_pairs_) {
// Count persistence intervals that covers the given interval
- if (cpx_->filtration(get<0>(pair)) <= from && cpx_->filtration(get<1>(pair)) > to) {
+ // null_simplex test : if the function is called with to=+infinity, we still get something useful. And it will
+ // still work if we change the complex filtration function to reject null simplices.
+ if (cpx_->filtration(get<0>(pair)) <= from &&
+ (get<1>(pair) == cpx_->null_simplex() || cpx_->filtration(get<1>(pair)) > to)) {
// Increment corresponding betti number
betti_numbers[cpx_->dimension(get<0>(pair))] += 1;
}
@@ -652,7 +655,7 @@ class Persistent_cohomology {
/** @brief Returns the persistent Betti number of the dimension passed by parameter.
* @param[in] dimension The Betti number dimension to get.
* @param[in] from The persistence birth limit to be added in the number \f$(persistent birth \leq from)\f$.
- * @param[in] to The persistence death limit to be added in the number \f$(persistent death > from)\f$.
+ * @param[in] to The persistence death limit to be added in the number \f$(persistent death > to)\f$.
* @return Persistent Betti number of the given dimension
*/
int persistent_betti_number(int dimension, Filtration_value from, Filtration_value to) const {
@@ -660,7 +663,10 @@ class Persistent_cohomology {
for (auto pair : persistent_pairs_) {
// Count persistence intervals that covers the given interval
- if (cpx_->filtration(get<0>(pair)) <= from && cpx_->filtration(get<1>(pair)) > to) {
+ // null_simplex test : if the function is called with to=+infinity, we still get something useful. And it will
+ // still work if we change the complex filtration function to reject null simplices.
+ if (cpx_->filtration(get<0>(pair)) <= from &&
+ (get<1>(pair) == cpx_->null_simplex() || cpx_->filtration(get<1>(pair)) > to)) {
if (cpx_->dimension(get<0>(pair)) == dimension) {
// Increment betti number found
++betti_number;
diff --git a/src/Persistent_cohomology/test/CMakeLists.txt b/src/Persistent_cohomology/test/CMakeLists.txt
index a034031a..a21f39c4 100644
--- a/src/Persistent_cohomology/test/CMakeLists.txt
+++ b/src/Persistent_cohomology/test/CMakeLists.txt
@@ -1,23 +1,23 @@
cmake_minimum_required(VERSION 2.6)
-project(GUDHIPersistentCohomologyUT)
+project(Persistent_cohomology_tests)
if (GCOVR_PATH)
# for gcovr to make coverage reports - Corbera Jenkins plugin
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
-endif()
+endif(GCOVR_PATH)
if (GPROF_PATH)
# for gprof to make coverage reports - Jenkins
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
-endif()
+endif(GPROF_PATH)
add_executable ( PersistentCohomologyUT persistent_cohomology_unit_test.cpp )
target_link_libraries(PersistentCohomologyUT ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
add_executable ( BettiNumbersUT betti_numbers_unit_test.cpp )
target_link_libraries(BettiNumbersUT ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
if (TBB_FOUND)
- target_link_libraries(PersistentCohomologyUT ${TBB_RELEASE_LIBRARY})
- target_link_libraries(BettiNumbersUT ${TBB_RELEASE_LIBRARY})
-endif()
+ target_link_libraries(PersistentCohomologyUT ${TBB_LIBRARIES})
+ target_link_libraries(BettiNumbersUT ${TBB_LIBRARIES})
+endif(TBB_FOUND)
# Unitary tests
add_test(NAME PersistentCohomologyUT
@@ -33,10 +33,10 @@ add_test(NAME BettiNumbersUT
if(GMPXX_FOUND AND GMP_FOUND)
add_executable ( PersistentCohomologyMultiFieldUT persistent_cohomology_unit_test_multi_field.cpp )
-target_link_libraries(PersistentCohomologyMultiFieldUT ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES})
-if (TBB_FOUND)
- target_link_libraries(PersistentCohomologyMultiFieldUT ${TBB_RELEASE_LIBRARY})
-endif()
+ target_link_libraries(PersistentCohomologyMultiFieldUT ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES})
+ if (TBB_FOUND)
+ target_link_libraries(PersistentCohomologyMultiFieldUT ${TBB_LIBRARIES})
+ endif(TBB_FOUND)
# Unitary tests
add_test(NAME PersistentCohomologyMultiFieldUT
@@ -45,5 +45,5 @@ endif()
# XML format for Jenkins xUnit plugin
--log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/PersistentCohomologyMultiFieldUT.xml --log_level=test_suite --report_level=no)
-endif()
+endif(GMPXX_FOUND AND GMP_FOUND)
diff --git a/src/Persistent_cohomology/test/persistent_cohomology_unit_test.cpp b/src/Persistent_cohomology/test/persistent_cohomology_unit_test.cpp
index 194b3e74..5c54ed5f 100644
--- a/src/Persistent_cohomology/test/persistent_cohomology_unit_test.cpp
+++ b/src/Persistent_cohomology/test/persistent_cohomology_unit_test.cpp
@@ -43,7 +43,7 @@ std::string test_rips_persistence(int coefficient, int min_persistence) {
st.initialize_filtration();
// Compute the persistence diagram of the complex
- persistent_cohomology::Persistent_cohomology<Simplex_tree<>, Field_Zp> pcoh(st);
+ Persistent_cohomology<Simplex_tree<>, Field_Zp> pcoh(st);
pcoh.init_coefficients( coefficient ); // initializes the coefficient field for homology
// Check infinite rips