summaryrefslogtreecommitdiff
path: root/src/Cech_complex/test/test_cech_complex.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Cech_complex/test/test_cech_complex.cpp')
-rw-r--r--src/Cech_complex/test/test_cech_complex.cpp122
1 files changed, 66 insertions, 56 deletions
diff --git a/src/Cech_complex/test/test_cech_complex.cpp b/src/Cech_complex/test/test_cech_complex.cpp
index c6b15d7f..f5980e6d 100644
--- a/src/Cech_complex/test/test_cech_complex.cpp
+++ b/src/Cech_complex/test/test_cech_complex.cpp
@@ -22,21 +22,20 @@
// to construct Cech_complex from a OFF file of points
#include <gudhi/Points_off_io.h>
#include <gudhi/Simplex_tree.h>
-#include <gudhi/distance_functions.h>
#include <gudhi/Unitary_tests_utils.h>
-#include <gudhi/Miniball.hpp>
+
+#include <CGAL/Epeck_d.h> // For EXACT or SAFE version
// Type definitions
using Simplex_tree = Gudhi::Simplex_tree<>;
using Filtration_value = Simplex_tree::Filtration_value;
-using Point = std::vector<Filtration_value>;
+using Kernel = CGAL::Epeck_d<CGAL::Dynamic_dimension_tag>;
+using FT = typename Kernel::FT;
+using Point = typename Kernel::Point_d;
+
using Point_cloud = std::vector<Point>;
using Points_off_reader = Gudhi::Points_off_reader<Point>;
-using Cech_complex = Gudhi::cech_complex::Cech_complex<Simplex_tree, Point_cloud>;
-
-using Point_iterator = Point_cloud::const_iterator;
-using Coordinate_iterator = Point::const_iterator;
-using Min_sphere = Gudhi::Miniball::Miniball<Gudhi::Miniball::CoordAccessor<Point_iterator, Coordinate_iterator>>;
+using Cech_complex = Gudhi::cech_complex::Cech_complex<Kernel, Simplex_tree>;
BOOST_AUTO_TEST_CASE(Cech_complex_for_documentation) {
// ----------------------------------------------------------------------------
@@ -45,20 +44,32 @@ BOOST_AUTO_TEST_CASE(Cech_complex_for_documentation) {
//
// ----------------------------------------------------------------------------
Point_cloud points;
- points.push_back({1., 0.}); // 0
- points.push_back({0., 1.}); // 1
- points.push_back({2., 1.}); // 2
- points.push_back({3., 2.}); // 3
- points.push_back({0., 3.}); // 4
- points.push_back({3. + std::sqrt(3.), 3.}); // 5
- points.push_back({1., 4.}); // 6
- points.push_back({3., 4.}); // 7
- points.push_back({2., 4. + std::sqrt(3.)}); // 8
- points.push_back({0., 4.}); // 9
- points.push_back({-0.5, 2.}); // 10
+
+ std::vector<FT> point0({1., 0.});
+ points.emplace_back(point0.begin(), point0.end());
+ std::vector<FT> point1({0., 1.});
+ points.emplace_back(point1.begin(), point1.end());
+ std::vector<FT> point2({2., 1.});
+ points.emplace_back(point2.begin(), point2.end());
+ std::vector<FT> point3({3., 2.});
+ points.emplace_back(point3.begin(), point3.end());
+ std::vector<FT> point4({0., 3.});
+ points.emplace_back(point4.begin(), point4.end());
+ std::vector<FT> point5({3. + std::sqrt(3.), 3.});
+ points.emplace_back(point5.begin(), point5.end());
+ std::vector<FT> point6({1., 4.});
+ points.emplace_back(point6.begin(), point6.end());
+ std::vector<FT> point7({3., 4.});
+ points.emplace_back(point7.begin(), point7.end());
+ std::vector<FT> point8({2., 4. + std::sqrt(3.)});
+ points.emplace_back(point8.begin(), point8.end());
+ std::vector<FT> point9({0., 4.});
+ points.emplace_back(point9.begin(), point9.end());
+ std::vector<FT> point10({-0.5, 2.});
+ points.emplace_back(point10.begin(), point10.end());
Filtration_value max_radius = 1.0;
- std::cout << "========== NUMBER OF POINTS = " << points.size() << " - Cech max_radius = " << max_radius
+ std::clog << "========== NUMBER OF POINTS = " << points.size() << " - Cech max_radius = " << max_radius
<< "==========" << std::endl;
Cech_complex cech_complex_for_doc(points, max_radius);
@@ -72,14 +83,14 @@ BOOST_AUTO_TEST_CASE(Cech_complex_for_documentation) {
const int DIMENSION_1 = 1;
Simplex_tree st;
cech_complex_for_doc.create_complex(st, DIMENSION_1);
- std::cout << "st.dimension()=" << st.dimension() << std::endl;
+ std::clog << "st.dimension()=" << st.dimension() << std::endl;
BOOST_CHECK(st.dimension() == DIMENSION_1);
const int NUMBER_OF_VERTICES = 11;
- std::cout << "st.num_vertices()=" << st.num_vertices() << std::endl;
+ std::clog << "st.num_vertices()=" << st.num_vertices() << std::endl;
BOOST_CHECK(st.num_vertices() == NUMBER_OF_VERTICES);
- std::cout << "st.num_simplices()=" << st.num_simplices() << std::endl;
+ std::clog << "st.num_simplices()=" << st.num_simplices() << std::endl;
BOOST_CHECK(st.num_simplices() == 27);
// Check filtration values of vertices is 0.0
@@ -91,16 +102,16 @@ BOOST_AUTO_TEST_CASE(Cech_complex_for_documentation) {
for (auto f_simplex : st.skeleton_simplex_range(DIMENSION_1)) {
if (DIMENSION_1 == st.dimension(f_simplex)) {
std::vector<Point> vp;
- std::cout << "vertex = (";
+ std::clog << "vertex = (";
for (auto vertex : st.simplex_vertex_range(f_simplex)) {
- std::cout << vertex << ",";
+ std::clog << vertex << ",";
vp.push_back(points.at(vertex));
}
- std::cout << ") - distance =" << Gudhi::Minimal_enclosing_ball_radius()(vp.at(0), vp.at(1))
+ std::clog << ") - distance =" << Gudhi::cech_complex::Sphere_circumradius<Kernel, Filtration_value>()(vp.at(0), vp.at(1))
<< " - filtration =" << st.filtration(f_simplex) << std::endl;
BOOST_CHECK(vp.size() == 2);
GUDHI_TEST_FLOAT_EQUALITY_CHECK(st.filtration(f_simplex),
- Gudhi::Minimal_enclosing_ball_radius()(vp.at(0), vp.at(1)));
+ Gudhi::cech_complex::Sphere_circumradius<Kernel, Filtration_value>()(vp.at(0), vp.at(1)));
}
}
@@ -112,48 +123,47 @@ BOOST_AUTO_TEST_CASE(Cech_complex_for_documentation) {
Simplex_tree st2;
cech_complex_for_doc.create_complex(st2, DIMENSION_2);
- std::cout << "st2.dimension()=" << st2.dimension() << std::endl;
+ std::clog << "st2.dimension()=" << st2.dimension() << std::endl;
BOOST_CHECK(st2.dimension() == DIMENSION_2);
- std::cout << "st2.num_vertices()=" << st2.num_vertices() << std::endl;
+ std::clog << "st2.num_vertices()=" << st2.num_vertices() << std::endl;
BOOST_CHECK(st2.num_vertices() == NUMBER_OF_VERTICES);
- std::cout << "st2.num_simplices()=" << st2.num_simplices() << std::endl;
+ std::clog << "st2.num_simplices()=" << st2.num_simplices() << std::endl;
BOOST_CHECK(st2.num_simplices() == 30);
Point_cloud points012;
for (std::size_t vertex = 0; vertex <= 2; vertex++) {
points012.push_back(cech_complex_for_doc.get_point(vertex));
}
- std::size_t dimension = points[0].end() - points[0].begin();
- Min_sphere ms012(dimension, points012.begin(), points012.end());
- Simplex_tree::Filtration_value f012 = st2.filtration(st2.find({0, 1, 2}));
- std::cout << "f012= " << f012 << " | ms012_radius= " << std::sqrt(ms012.squared_radius()) << std::endl;
+ Kernel kern;
+ Filtration_value f012 = st2.filtration(st2.find({0, 1, 2}));
+ std::clog << "f012= " << f012 << std::endl;
- GUDHI_TEST_FLOAT_EQUALITY_CHECK(f012, std::sqrt(ms012.squared_radius()));
+ CGAL::NT_converter<FT, Filtration_value> cast_to_fv;
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(f012, std::sqrt(cast_to_fv(kern.compute_squared_radius_d_object()(points012.begin(), points012.end()))));
Point_cloud points1410;
points1410.push_back(cech_complex_for_doc.get_point(1));
points1410.push_back(cech_complex_for_doc.get_point(4));
points1410.push_back(cech_complex_for_doc.get_point(10));
- Min_sphere ms1410(dimension, points1410.begin(), points1410.end());
- Simplex_tree::Filtration_value f1410 = st2.filtration(st2.find({1, 4, 10}));
- std::cout << "f1410= " << f1410 << " | ms1410_radius= " << std::sqrt(ms1410.squared_radius()) << std::endl;
+ Filtration_value f1410 = st2.filtration(st2.find({1, 4, 10}));
+ std::clog << "f1410= " << f1410 << std::endl;
- GUDHI_TEST_FLOAT_EQUALITY_CHECK(f1410, std::sqrt(ms1410.squared_radius()));
+ // In this case, the computed circumsphere using CGAL kernel does not match the minimal enclosing ball; the filtration value check is therefore done against a hardcoded value
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(f1410, 1.);
Point_cloud points469;
points469.push_back(cech_complex_for_doc.get_point(4));
points469.push_back(cech_complex_for_doc.get_point(6));
points469.push_back(cech_complex_for_doc.get_point(9));
- Min_sphere ms469(dimension, points469.begin(), points469.end());
- Simplex_tree::Filtration_value f469 = st2.filtration(st2.find({4, 6, 9}));
- std::cout << "f469= " << f469 << " | ms469_radius= " << std::sqrt(ms469.squared_radius()) << std::endl;
+ Filtration_value f469 = st2.filtration(st2.find({4, 6, 9}));
+ std::clog << "f469= " << f469 << std::endl;
- GUDHI_TEST_FLOAT_EQUALITY_CHECK(f469, std::sqrt(ms469.squared_radius()));
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(f469, std::sqrt(cast_to_fv(kern.compute_squared_radius_d_object()(points469.begin(), points469.end()))));
BOOST_CHECK((st2.find({6, 7, 8}) == st2.null_simplex()));
BOOST_CHECK((st2.find({3, 5, 7}) == st2.null_simplex()));
@@ -178,35 +188,35 @@ BOOST_AUTO_TEST_CASE(Cech_complex_from_points) {
// ----------------------------------------------------------------------------
Cech_complex cech_complex_from_points(points, 2.0);
- std::cout << "========== cech_complex_from_points ==========" << std::endl;
+ std::clog << "========== cech_complex_from_points ==========" << std::endl;
Simplex_tree st;
const int DIMENSION = 3;
cech_complex_from_points.create_complex(st, DIMENSION);
// Another way to check num_simplices
- std::cout << "Iterator on Cech complex simplices in the filtration order, with [filtration value]:" << std::endl;
+ std::clog << "Iterator on Cech complex simplices in the filtration order, with [filtration value]:" << std::endl;
int num_simplices = 0;
for (auto f_simplex : st.filtration_simplex_range()) {
num_simplices++;
- std::cout << " ( ";
+ std::clog << " ( ";
for (auto vertex : st.simplex_vertex_range(f_simplex)) {
- std::cout << vertex << " ";
+ std::clog << vertex << " ";
}
- std::cout << ") -> "
+ std::clog << ") -> "
<< "[" << st.filtration(f_simplex) << "] ";
- std::cout << std::endl;
+ std::clog << std::endl;
}
BOOST_CHECK(num_simplices == 15);
- std::cout << "st.num_simplices()=" << st.num_simplices() << std::endl;
+ std::clog << "st.num_simplices()=" << st.num_simplices() << std::endl;
BOOST_CHECK(st.num_simplices() == 15);
- std::cout << "st.dimension()=" << st.dimension() << std::endl;
+ std::clog << "st.dimension()=" << st.dimension() << std::endl;
BOOST_CHECK(st.dimension() == DIMENSION);
- std::cout << "st.num_vertices()=" << st.num_vertices() << std::endl;
+ std::clog << "st.num_vertices()=" << st.num_vertices() << std::endl;
BOOST_CHECK(st.num_vertices() == 4);
for (auto f_simplex : st.filtration_simplex_range()) {
- std::cout << "dimension(" << st.dimension(f_simplex) << ") - f = " << st.filtration(f_simplex) << std::endl;
+ std::clog << "dimension(" << st.dimension(f_simplex) << ") - f = " << st.filtration(f_simplex) << std::endl;
switch (st.dimension(f_simplex)) {
case 0:
GUDHI_TEST_FLOAT_EQUALITY_CHECK(st.filtration(f_simplex), 0.0);
@@ -235,8 +245,8 @@ BOOST_AUTO_TEST_CASE(Cech_create_complex_throw) {
//
// ----------------------------------------------------------------------------
std::string off_file_name("alphacomplexdoc.off");
- double max_radius = 12.0;
- std::cout << "========== OFF FILE NAME = " << off_file_name << " - Cech max_radius=" << max_radius
+ Filtration_value max_radius = 12.0;
+ std::clog << "========== OFF FILE NAME = " << off_file_name << " - Cech max_radius=" << max_radius
<< "==========" << std::endl;
Gudhi::Points_off_reader<Point> off_reader(off_file_name);
@@ -245,7 +255,7 @@ BOOST_AUTO_TEST_CASE(Cech_create_complex_throw) {
Simplex_tree stree;
std::vector<int> simplex = {0, 1, 2};
stree.insert_simplex_and_subfaces(simplex);
- std::cout << "Check exception throw in debug mode" << std::endl;
+ std::clog << "Check exception throw in debug mode" << std::endl;
// throw excpt because stree is not empty
BOOST_CHECK_THROW(cech_complex_from_file.create_complex(stree, 1), std::invalid_argument);
}