summaryrefslogtreecommitdiff
path: root/src/Tangential_complex
diff options
context:
space:
mode:
Diffstat (limited to 'src/Tangential_complex')
-rw-r--r--src/Tangential_complex/benchmark/CMakeLists.txt9
-rw-r--r--src/Tangential_complex/benchmark/benchmark_tc.cpp4
-rw-r--r--src/Tangential_complex/include/gudhi/Tangential_complex.h33
-rw-r--r--src/Tangential_complex/test/test_tangential_complex.cpp58
4 files changed, 75 insertions, 29 deletions
diff --git a/src/Tangential_complex/benchmark/CMakeLists.txt b/src/Tangential_complex/benchmark/CMakeLists.txt
index 56dd8128..788c2b4d 100644
--- a/src/Tangential_complex/benchmark/CMakeLists.txt
+++ b/src/Tangential_complex/benchmark/CMakeLists.txt
@@ -1,15 +1,6 @@
cmake_minimum_required(VERSION 2.6)
project(Tangential_complex_benchmark)
-if (GCOVR_PATH)
- # for gcovr to make coverage reports - Corbera Jenkins plugin
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
-endif()
-if (GPROF_PATH)
- # for gprof to make coverage reports - Jenkins
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
-endif()
-
# need CGAL 4.8
if(CGAL_FOUND)
if (NOT CGAL_VERSION VERSION_LESS 4.8.0)
diff --git a/src/Tangential_complex/benchmark/benchmark_tc.cpp b/src/Tangential_complex/benchmark/benchmark_tc.cpp
index 943fcb54..6d6dd548 100644
--- a/src/Tangential_complex/benchmark/benchmark_tc.cpp
+++ b/src/Tangential_complex/benchmark/benchmark_tc.cpp
@@ -161,7 +161,7 @@ typename Kernel, typename OutputIteratorPoints>
bool load_points_from_file(
const std::string &filename,
OutputIteratorPoints points,
- std::size_t only_first_n_points = std::numeric_limits<std::size_t>::max()) {
+ std::size_t only_first_n_points = (std::numeric_limits<std::size_t>::max)()) {
typedef typename Kernel::Point_d Point;
std::ifstream in(filename);
@@ -196,7 +196,7 @@ bool load_points_and_tangent_space_basis_from_file(
OutputIteratorPoints points,
OutputIteratorTS tangent_spaces,
int intrinsic_dim,
- std::size_t only_first_n_points = std::numeric_limits<std::size_t>::max()) {
+ std::size_t only_first_n_points = (std::numeric_limits<std::size_t>::max)()) {
typedef typename Kernel::Point_d Point;
typedef typename Kernel::Vector_d Vector;
diff --git a/src/Tangential_complex/include/gudhi/Tangential_complex.h b/src/Tangential_complex/include/gudhi/Tangential_complex.h
index e748d3b7..cfc82eb1 100644
--- a/src/Tangential_complex/include/gudhi/Tangential_complex.h
+++ b/src/Tangential_complex/include/gudhi/Tangential_complex.h
@@ -63,6 +63,7 @@
#include <iterator>
#include <cmath> // for std::sqrt
#include <string>
+#include <cstddef> // for std::size_t
#ifdef GUDHI_USE_TBB
#include <tbb/parallel_for.h>
@@ -82,7 +83,7 @@ using namespace internal;
class Vertex_data {
public:
- Vertex_data(std::size_t data = std::numeric_limits<std::size_t>::max())
+ Vertex_data(std::size_t data = (std::numeric_limits<std::size_t>::max)())
: m_data(data) { }
operator std::size_t() {
@@ -1048,7 +1049,7 @@ class Tangential_complex {
#endif // GUDHI_USE_TBB
bool is_infinite(Simplex const& s) const {
- return *s.rbegin() == std::numeric_limits<std::size_t>::max();
+ return *s.rbegin() == (std::numeric_limits<std::size_t>::max)();
}
// Output: "triangulation" is a Regular Triangulation containing at least the
@@ -1130,7 +1131,7 @@ class Tangential_complex {
Tr_vertex_handle vh = triangulation.insert_if_in_star(proj_pt, center_vertex);
// Tr_vertex_handle vh = triangulation.insert(proj_pt);
- if (vh != Tr_vertex_handle()) {
+ if (vh != Tr_vertex_handle() && vh->data() == (std::numeric_limits<std::size_t>::max)()) {
#ifdef GUDHI_TC_VERY_VERBOSE
++num_inserted_points;
#endif
@@ -1292,6 +1293,8 @@ class Tangential_complex {
if (index != i)
incident_simplex.insert(index);
}
+ GUDHI_CHECK(incident_simplex.size() == cur_dim_plus_1 - 1,
+ std::logic_error("update_star: wrong size of incident simplex"));
star.push_back(incident_simplex);
}
}
@@ -1303,21 +1306,14 @@ class Tangential_complex {
, bool normalize_basis = true
, Orthogonal_space_basis *p_orth_space_basis = NULL
) {
- unsigned int num_pts_for_pca = static_cast<unsigned int> (std::pow(GUDHI_TC_BASE_VALUE_FOR_PCA, m_intrinsic_dim));
+ unsigned int num_pts_for_pca = (std::min)(static_cast<unsigned int> (std::pow(GUDHI_TC_BASE_VALUE_FOR_PCA, m_intrinsic_dim)),
+ static_cast<unsigned int> (m_points.size()));
// Kernel functors
typename K::Construct_vector_d constr_vec =
m_k.construct_vector_d_object();
typename K::Compute_coordinate_d coord =
m_k.compute_coordinate_d_object();
- typename K::Squared_length_d sqlen =
- m_k.squared_length_d_object();
- typename K::Scaled_vector_d scaled_vec =
- m_k.scaled_vector_d_object();
- typename K::Scalar_product_d scalar_pdct =
- m_k.scalar_product_d_object();
- typename K::Difference_of_vectors_d diff_vec =
- m_k.difference_of_vectors_d_object();
#ifdef GUDHI_TC_USE_ANOTHER_POINT_SET_FOR_TANGENT_SPACE_ESTIM
KNS_range kns_range = m_points_ds_for_tse.query_k_nearest_neighbors(
@@ -1392,7 +1388,8 @@ 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<unsigned int> (std::pow(GUDHI_TC_BASE_VALUE_FOR_PCA, m_intrinsic_dim));
+ unsigned int num_pts_for_pca = (std::min)(static_cast<unsigned int> (std::pow(GUDHI_TC_BASE_VALUE_FOR_PCA, m_intrinsic_dim)),
+ static_cast<unsigned int> (m_points.size()));
// Kernel functors
typename K::Construct_vector_d constr_vec =
@@ -1650,7 +1647,7 @@ class Tangential_complex {
for (; it_point_idx != simplex.end(); ++it_point_idx) {
std::size_t point_idx = *it_point_idx;
// Don't check infinite simplices
- if (point_idx == std::numeric_limits<std::size_t>::max())
+ if (point_idx == (std::numeric_limits<std::size_t>::max)())
continue;
Star const& star = m_stars[point_idx];
@@ -1689,7 +1686,7 @@ class Tangential_complex {
for (; it_point_idx != s.end(); ++it_point_idx) {
std::size_t point_idx = *it_point_idx;
// Don't check infinite simplices
- if (point_idx == std::numeric_limits<std::size_t>::max())
+ if (point_idx == (std::numeric_limits<std::size_t>::max)())
continue;
Star const& star = m_stars[point_idx];
@@ -1900,7 +1897,7 @@ class Tangential_complex {
#ifdef GUDHI_TC_EXPORT_ALL_COORDS_IN_OFF
int num_coords = m_ambient_dim;
#else
- int num_coords = std::min(m_ambient_dim, 3);
+ int num_coords = (std::min)(m_ambient_dim, 3);
#endif
#ifdef GUDHI_TC_EXPORT_NORMALS
@@ -1955,7 +1952,7 @@ class Tangential_complex {
Triangulation const& tr = it_tr->tr();
Tr_vertex_handle center_vh = it_tr->center_vertex();
- if (&tr == NULL || tr.current_dimension() < m_intrinsic_dim)
+ if (tr.current_dimension() < m_intrinsic_dim)
continue;
// Color for this star
@@ -2154,7 +2151,7 @@ class Tangential_complex {
typedef std::vector<Simplex> Triangles;
Triangles triangles;
- std::size_t num_vertices = c.size();
+ int num_vertices = static_cast<int>(c.size());
// Do not export smaller dimension simplices
if (num_vertices < m_intrinsic_dim + 1)
continue;
diff --git a/src/Tangential_complex/test/test_tangential_complex.cpp b/src/Tangential_complex/test/test_tangential_complex.cpp
index f8b0d2fb..48156440 100644
--- a/src/Tangential_complex/test/test_tangential_complex.cpp
+++ b/src/Tangential_complex/test/test_tangential_complex.cpp
@@ -68,3 +68,61 @@ 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<CGAL::Dynamic_dimension_tag> Kernel;
+ typedef Kernel::Point_d Point;
+ typedef tc::Tangential_complex<Kernel, CGAL::Dynamic_dimension_tag, CGAL::Parallel_tag> TC;
+
+
+ const int INTRINSIC_DIM = 1;
+
+ // Generate points on a 2-sphere
+ std::vector<Point> points;
+ // [[0, 0], [1, 0], [0, 1], [1, 1]]
+ std::vector<double> 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 <<
+ " - inc simplices = " << num_inc.num_inconsistent_simplices <<
+ " - inc stars = " << num_inc.num_inconsistent_stars << std::endl;
+
+ BOOST_CHECK(tc.number_of_vertices() == 4);
+ BOOST_CHECK(num_inc.num_simplices == 4);
+ BOOST_CHECK(num_inc.num_inconsistent_simplices == 0);
+ BOOST_CHECK(num_inc.num_inconsistent_stars == 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;
+
+ BOOST_CHECK(stree.num_vertices() == 4);
+ BOOST_CHECK(stree.num_simplices() == 6);
+
+ 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 == 0);
+ BOOST_CHECK(num_inc.num_inconsistent_stars == 0);
+
+ // 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() == 6);
+}