#include <CGAL/Epick_d.h>
#include <CGAL/point_generators_d.h>
#include <CGAL/algorithm.h>
#include <CGAL/assertions.h>
#include <gudhi/Alpha_complex.h>
#include <gudhi/Persistent_cohomology.h>
#include <gudhi/Simplex_tree.h>
#include <iostream>
#include <iterator>
#include <vector>
#include <fstream>
#include <algorithm>
using Kernel = CGAL::Epick_d< CGAL::Dimension_tag<3> >;
using Point = Kernel::Point_d;
std::vector<Point> random_points() {
CGAL::Random rng(0);
std::vector<Point> points;
CGAL::Random_points_on_sphere_d<Point> rand_outside(3, 4.0, rng);
CGAL::cpp11::copy_n(rand_outside, 1000, std::back_inserter(points));
CGAL::Random_points_in_ball_d<Point> rand_inside(3, 3.0, rng);
CGAL::cpp11::copy_n(rand_inside, 2000, std::back_inserter(points));
return points;
}
struct cmp_intervals_by_dim_then_length {
explicit cmp_intervals_by_dim_then_length(Simplex_tree * sc)
: sc_(sc) { }
template<typename Persistent_interval>
bool operator()(const Persistent_interval & p1, const Persistent_interval & p2) {
if (sc_->dimension(get < 0 > (p1)) == sc_->dimension(get < 0 > (p2)))
return (sc_->filtration(get < 1 > (p1)) - sc_->filtration(get < 0 > (p1))
> sc_->filtration(get < 1 > (p2)) - sc_->filtration(get < 0 > (p2)));
else
return (sc_->dimension(get < 0 > (p1)) > sc_->dimension(get < 0 > (p2)));
}
Simplex_tree* sc_;
};
int main(int argc, char **argv) {
std::vector<Point> points = random_points();
std::clog << "Points size=" << points.size() << std::endl;
Alpha_complex alpha_complex_from_points(points);
std::clog << "alpha_complex_from_points" << std::endl;
Simplex_tree simplex;
std::clog << "simplex" << std::endl;
if (alpha_complex_from_points.create_complex(simplex, 0.6)) {
std::clog << "simplex" << std::endl;
std::clog <<
"Simplicial complex is of dimension " << simplex.
dimension() <<
std::clog <<
"Simplex_tree dim: " << simplex.
dimension() << std::endl;
cmp_intervals_by_dim_then_length cmp(&simplex);
std::sort(std::begin(persistent_pairs), std::end(persistent_pairs), cmp);
for (auto pair : persistent_pairs) {
std::clog << simplex.
dimension(get<0>(pair)) <<
" " }
std::clog << "The persistent Betti numbers in interval [0.40, 0.41] are : ";
for (
int dim = 0; dim < simplex.
dimension(); dim++)
std::clog << std::endl;
std::clog << "The Betti numbers are : ";
for (std::size_t i = 0; i < betti_numbers.size(); i++)
std::clog << "b" << i << " = " << betti_numbers[i] << " ; ";
std::clog << std::endl;
}
return 0;
}