From 12fa1bbb902bebb2ffc21482a25913ac7c49dc85 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Mon, 12 Dec 2016 10:04:42 +0000 Subject: Fix the bug, remove tan_test from examples and add a unitary test git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/tangential_test@1850 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 852570382d6f5713e534b49e7abf1e96a4a84076 --- CMakeLists.txt | 14 +++--- src/Tangential_complex/example/CMakeLists.txt | 5 -- src/Tangential_complex/example/tan_test.cpp | 54 -------------------- .../include/gudhi/Tangential_complex.h | 8 ++- .../test/test_tangential_complex.cpp | 57 ++++++++++++++++++++++ 5 files changed, 70 insertions(+), 68 deletions(-) delete mode 100644 src/Tangential_complex/example/tan_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 005df6d7..78de6c09 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,13 +73,13 @@ else() set(Boost_USE_STATIC_RUNTIME OFF) # Find TBB package for parallel sort - not mandatory, just optional. - set(TBB_FIND_QUIETLY ON) - find_package(TBB) - if (TBB_FOUND) - include(${TBB_USE_FILE}) - message("TBB found in ${TBB_LIBRARY_DIRS}") - add_definitions(-DGUDHI_USE_TBB) - endif() + #set(TBB_FIND_QUIETLY ON) + #find_package(TBB) + #if (TBB_FOUND) + # include(${TBB_USE_FILE}) + # message("TBB found in ${TBB_LIBRARY_DIRS}") + # add_definitions(-DGUDHI_USE_TBB) + #endif() find_package(Eigen3 3.1.0) if (EIGEN3_FOUND) diff --git a/src/Tangential_complex/example/CMakeLists.txt b/src/Tangential_complex/example/CMakeLists.txt index 76ba0a32..32f6eebb 100644 --- a/src/Tangential_complex/example/CMakeLists.txt +++ b/src/Tangential_complex/example/CMakeLists.txt @@ -8,12 +8,9 @@ if(CGAL_FOUND) target_link_libraries(Tangential_complex_example_basic ${CGAL_LIBRARY} ${Boost_DATE_TIME_LIBRARY}) add_executable( Tangential_complex_example_with_perturb example_with_perturb.cpp ) target_link_libraries(Tangential_complex_example_with_perturb ${CGAL_LIBRARY} ${Boost_DATE_TIME_LIBRARY}) - add_executable( tan_test tan_test.cpp ) - target_link_libraries(tan_test ${CGAL_LIBRARY} ${Boost_DATE_TIME_LIBRARY}) if (TBB_FOUND) target_link_libraries(Tangential_complex_example_basic ${TBB_LIBRARIES}) target_link_libraries(Tangential_complex_example_with_perturb ${TBB_LIBRARIES}) - target_link_libraries(tan_test ${TBB_LIBRARIES}) endif(TBB_FOUND) add_test(Tangential_complex_example_basic @@ -22,8 +19,6 @@ if(CGAL_FOUND) add_test(Tangential_complex_example_with_perturb ${CMAKE_CURRENT_BINARY_DIR}/Tangential_complex_example_with_perturb) - add_test(tan_test - ${CMAKE_CURRENT_BINARY_DIR}/tan_test) endif(EIGEN3_FOUND) endif(NOT CGAL_VERSION VERSION_LESS 4.8.0) endif(CGAL_FOUND) diff --git a/src/Tangential_complex/example/tan_test.cpp b/src/Tangential_complex/example/tan_test.cpp deleted file mode 100644 index afb9f13c..00000000 --- a/src/Tangential_complex/example/tan_test.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include - -#include -#include - -#include -#include - -namespace tc = Gudhi::tangential_complex; - -typedef CGAL::Epick_d Kernel; -typedef Kernel::FT FT; -typedef Kernel::Point_d Point; -typedef Kernel::Vector_d Vector; -typedef tc::Tangential_complex< -Kernel, CGAL::Dynamic_dimension_tag, -CGAL::Parallel_tag> TC; - -int main(void) { - const int INTRINSIC_DIM = 1; - - // Generate points on a 2-sphere - std::vector points; - // [[0, 0], [1, 0], [0, 1], [1, 1]] - std::vector point = {0.0, 0.0}; - points.push_back(Point(point.size(), point.begin(), point.end())); - point = {1.0, 0.0}; - points.push_back(Point(point.size(), point.begin(), point.end())); - point = {0.0, 1.0}; - points.push_back(Point(point.size(), point.begin(), point.end())); - point = {1.0, 1.0}; - points.push_back(Point(point.size(), point.begin(), point.end())); - - Kernel k; - for (int i = 0; i < 100; i++) { - - // Compute the TC - TC tc(points, INTRINSIC_DIM, k); - tc.compute_tangential_complex(); - TC::Num_inconsistencies num_inc = tc.number_of_inconsistent_simplices(); - std::cout << "TC vertices = " << tc.number_of_vertices() << " - simplices = " << num_inc.num_simplices << - " - inconsistencies = " << num_inc.num_inconsistent_simplices << std::endl; - - tc.fix_inconsistencies_using_perturbation(10.0, 60.0); - // Export the TC into a Simplex_tree - Gudhi::Simplex_tree<> stree; - tc.create_complex(stree); - std::cout << "ST vertices = " << stree.num_vertices() << " - simplices = " << stree.num_simplices() << std::endl; - - } - - return 0; -} diff --git a/src/Tangential_complex/include/gudhi/Tangential_complex.h b/src/Tangential_complex/include/gudhi/Tangential_complex.h index e748d3b7..90c164e2 100644 --- a/src/Tangential_complex/include/gudhi/Tangential_complex.h +++ b/src/Tangential_complex/include/gudhi/Tangential_complex.h @@ -1303,7 +1303,9 @@ class Tangential_complex { , bool normalize_basis = true , Orthogonal_space_basis *p_orth_space_basis = NULL ) { - unsigned int num_pts_for_pca = static_cast (std::pow(GUDHI_TC_BASE_VALUE_FOR_PCA, m_intrinsic_dim)); +// unsigned int num_pts_for_pca = static_cast (std::pow(GUDHI_TC_BASE_VALUE_FOR_PCA, m_intrinsic_dim)); + unsigned int num_pts_for_pca = (std::min)(static_cast (std::pow(GUDHI_TC_BASE_VALUE_FOR_PCA, m_intrinsic_dim)), + static_cast (m_points.size())); // Kernel functors typename K::Construct_vector_d constr_vec = @@ -1392,7 +1394,9 @@ class Tangential_complex { // on it. Note that most points are duplicated. Tangent_space_basis compute_tangent_space(const Simplex &s, bool normalize_basis = true) { - unsigned int num_pts_for_pca = static_cast (std::pow(GUDHI_TC_BASE_VALUE_FOR_PCA, m_intrinsic_dim)); +// unsigned int num_pts_for_pca = static_cast (std::pow(GUDHI_TC_BASE_VALUE_FOR_PCA, m_intrinsic_dim)); + unsigned int num_pts_for_pca = (std::min)(static_cast (std::pow(GUDHI_TC_BASE_VALUE_FOR_PCA, m_intrinsic_dim)), + static_cast (m_points.size())); // Kernel functors typename K::Construct_vector_d constr_vec = diff --git a/src/Tangential_complex/test/test_tangential_complex.cpp b/src/Tangential_complex/test/test_tangential_complex.cpp index f8b0d2fb..4c3dec3b 100644 --- a/src/Tangential_complex/test/test_tangential_complex.cpp +++ b/src/Tangential_complex/test/test_tangential_complex.cpp @@ -68,3 +68,60 @@ BOOST_AUTO_TEST_CASE(test_Spatial_tree_data_structure) { Gudhi::Simplex_tree<> stree; tc.create_complex(stree); } + +BOOST_AUTO_TEST_CASE(test_mini_tangential) { + typedef CGAL::Epick_d Kernel; + typedef Kernel::FT FT; + typedef Kernel::Point_d Point; + typedef Kernel::Vector_d Vector; + typedef tc::Tangential_complex TC; + + + const int INTRINSIC_DIM = 1; + + // Generate points on a 2-sphere + std::vector points; + // [[0, 0], [1, 0], [0, 1], [1, 1]] + std::vector point = {0.0, 0.0}; + points.push_back(Point(point.size(), point.begin(), point.end())); + point = {1.0, 0.0}; + points.push_back(Point(point.size(), point.begin(), point.end())); + point = {0.0, 1.0}; + points.push_back(Point(point.size(), point.begin(), point.end())); + point = {1.0, 1.0}; + points.push_back(Point(point.size(), point.begin(), point.end())); + std::cout << "points = " << points.size() << std::endl; + Kernel k; + + // Compute the TC + TC tc(points, INTRINSIC_DIM, k); + tc.compute_tangential_complex(); + TC::Num_inconsistencies num_inc = tc.number_of_inconsistent_simplices(); + std::cout << "TC vertices = " << tc.number_of_vertices() << " - simplices = " << num_inc.num_simplices << + " - inconsistencies = " << num_inc.num_inconsistent_simplices << std::endl; + + BOOST_CHECK(tc.number_of_vertices() == 4); + BOOST_CHECK(num_inc.num_simplices == 4); + BOOST_CHECK(num_inc.num_inconsistent_simplices == 2); + + // Export the TC into a Simplex_tree + Gudhi::Simplex_tree<> stree; + tc.create_complex(stree); + std::cout << "ST vertices = " << stree.num_vertices() << " - simplices = " << stree.num_simplices() << std::endl; + + BOOST_CHECK(stree.num_vertices() == 4); + BOOST_CHECK(stree.num_simplices() == 12); + + tc.fix_inconsistencies_using_perturbation(0.01, 30.0); + + BOOST_CHECK(tc.number_of_vertices() == 4); + BOOST_CHECK(num_inc.num_simplices == 4); + BOOST_CHECK(num_inc.num_inconsistent_simplices == 2); + + // Export the TC into a Simplex_tree + tc.create_complex(stree); + std::cout << "ST vertices = " << stree.num_vertices() << " - simplices = " << stree.num_simplices() << std::endl; + + BOOST_CHECK(stree.num_vertices() == 4); + BOOST_CHECK(stree.num_simplices() == 12); +} -- cgit v1.2.3