23 #ifndef ALPHA_COMPLEX_H_ 24 #define ALPHA_COMPLEX_H_ 26 #include <gudhi/Debug_utils.h> 28 #include <gudhi/Points_off_io.h> 33 #include <CGAL/Delaunay_triangulation.h> 34 #include <CGAL/Epick_d.h> 35 #include <CGAL/Spatial_sort_traits_adapter_d.h> 36 #include <CGAL/property_map.h> 49 namespace alpha_complex {
74 template<
class Kernel = CGAL::Epick_d<CGAL::Dynamic_dimension_tag>>
78 typedef CGAL::Triangulation_data_structure<
typename Kernel::Dimension,
79 CGAL::Triangulation_vertex<Kernel, std::ptrdiff_t>,
80 CGAL::Triangulation_full_cell<Kernel> > TDS;
91 typedef typename Kernel::Compute_squared_radius_d Squared_Radius;
92 typedef typename Kernel::Side_of_bounded_sphere_d Is_Gabriel;
93 typedef typename Kernel::Point_dimension_d Point_Dimension;
96 typedef typename std::vector<Point_d> Vector_of_CGAL_points;
99 typedef typename Delaunay_triangulation::Vertex_iterator CGAL_vertex_iterator;
102 typedef typename Delaunay_triangulation::size_type size_type;
105 typedef typename std::map< std::size_t, CGAL_vertex_iterator > Vector_vertex_iterator;
110 Vector_vertex_iterator vertex_handle_to_iterator_;
112 Delaunay_triangulation* triangulation_;
127 : triangulation_(nullptr) {
130 std::cerr <<
"Alpha_complex - Unable to read file " << off_file_name <<
"\n";
146 template<
typename InputPo
intRange >
148 : triangulation_(nullptr) {
149 init_from_range(points);
155 delete triangulation_;
171 return vertex_handle_to_iterator_.at(vertex)->point();
179 return vertex_handle_to_iterator_.size();
183 template<
typename InputPo
intRange >
184 void init_from_range(
const InputPointRange& points) {
185 auto first = std::begin(points);
186 auto last = std::end(points);
190 Point_Dimension point_dimension = kernel_.point_dimension_d_object();
195 std::vector<Point_d> point_cloud(first, last);
198 std::vector<std::ptrdiff_t> indices(boost::counting_iterator<std::ptrdiff_t>(0),
199 boost::counting_iterator<std::ptrdiff_t>(point_cloud.size()));
201 typedef boost::iterator_property_map<typename std::vector<Point_d>::iterator,
202 CGAL::Identity_property_map<std::ptrdiff_t>> Point_property_map;
203 typedef CGAL::Spatial_sort_traits_adapter_d<Kernel, Point_property_map> Search_traits_d;
205 CGAL::spatial_sort(indices.begin(), indices.end(), Search_traits_d(std::begin(point_cloud)));
207 typename Delaunay_triangulation::Full_cell_handle hint;
208 for (
auto index : indices) {
209 typename Delaunay_triangulation::Vertex_handle pos = triangulation_->insert(point_cloud[index], hint);
212 hint = pos->full_cell();
217 for (CGAL_vertex_iterator vit = triangulation_->vertices_begin(); vit != triangulation_->vertices_end(); ++vit) {
218 if (!triangulation_->is_infinite(*vit)) {
220 std::cout <<
"Vertex insertion - " << vit->data() <<
" -> " << vit->point() << std::endl;
221 #endif // DEBUG_TRACES 222 vertex_handle_to_iterator_.emplace(vit->data(), vit);
230 template <
typename SimplicialComplexForAlpha>
233 return create_complex(complex, std::numeric_limits<Filtration_value>::infinity());
251 template <
typename SimplicialComplexForAlpha,
typename Filtration_value>
256 typedef std::vector<Vertex_handle> Vector_vertex;
258 if (triangulation_ ==
nullptr) {
259 std::cerr <<
"Alpha_complex cannot create_complex from a NULL triangulation\n";
262 if (triangulation_->maximal_dimension() < 1) {
263 std::cerr <<
"Alpha_complex cannot create_complex from a zero-dimension triangulation\n";
267 std::cerr <<
"Alpha_complex create_complex - complex is not empty\n";
275 if (triangulation_->number_of_vertices() > 0) {
276 for (
auto cit = triangulation_->finite_full_cells_begin(); cit != triangulation_->finite_full_cells_end(); ++cit) {
277 Vector_vertex vertexVector;
279 std::cout <<
"Simplex_tree insertion ";
280 #endif // DEBUG_TRACES 281 for (
auto vit = cit->vertices_begin(); vit != cit->vertices_end(); ++vit) {
282 if (*vit !=
nullptr) {
284 std::cout <<
" " << (*vit)->data();
285 #endif // DEBUG_TRACES 287 vertexVector.push_back((*vit)->data());
291 std::cout << std::endl;
292 #endif // DEBUG_TRACES 301 Vector_of_CGAL_points pointVector;
303 for (
int decr_dim = triangulation_->maximal_dimension(); decr_dim >= 0; decr_dim--) {
305 for (Simplex_handle f_simplex : complex.skeleton_simplex_range(decr_dim)) {
306 int f_simplex_dim = complex.
dimension(f_simplex);
307 if (decr_dim == f_simplex_dim) {
310 std::cout <<
"Sigma of dim " << decr_dim <<
" is";
311 #endif // DEBUG_TRACES 313 pointVector.push_back(
get_point(vertex));
315 std::cout <<
" " << vertex;
316 #endif // DEBUG_TRACES 319 std::cout << std::endl;
320 #endif // DEBUG_TRACES 322 if (std::isnan(complex.filtration(f_simplex))) {
323 Filtration_value alpha_complex_filtration = 0.0;
325 if (f_simplex_dim > 0) {
327 Squared_Radius squared_radius = kernel_.compute_squared_radius_d_object();
329 alpha_complex_filtration = squared_radius(pointVector.begin(), pointVector.end());
333 std::cout <<
"filt(Sigma) is NaN : filt(Sigma) =" << complex.filtration(f_simplex) << std::endl;
334 #endif // DEBUG_TRACES 336 propagate_alpha_filtration(complex, f_simplex, decr_dim);
352 template <
typename SimplicialComplexForAlpha,
typename Simplex_handle>
358 #endif // DEBUG_TRACES 363 std::cout <<
" | --------------------------------------------------\n";
364 std::cout <<
" | Tau ";
366 std::cout << vertex <<
" ";
368 std::cout <<
"is a face of Sigma\n";
369 std::cout <<
" | isnan(complex.filtration(Tau)=" << std::isnan(complex.filtration(f_boundary)) << std::endl;
370 #endif // DEBUG_TRACES 372 if (!std::isnan(complex.filtration(f_boundary))) {
374 Filtration_value alpha_complex_filtration = fmin(complex.filtration(f_boundary),
375 complex.filtration(f_simplex));
378 std::cout <<
" | filt(Tau) = fmin(filt(Tau), filt(Sigma)) = " << complex.filtration(f_boundary) << std::endl;
379 #endif // DEBUG_TRACES 386 Vector_of_CGAL_points pointVector;
388 Vertex_handle vertexForGabriel = Vertex_handle();
389 #endif // DEBUG_TRACES 391 pointVector.push_back(
get_point(vertex));
394 Point_d point_for_gabriel;
397 if (std::find(pointVector.begin(), pointVector.end(), point_for_gabriel) == pointVector.end()) {
400 vertexForGabriel = vertex;
401 #endif // DEBUG_TRACES 407 Is_Gabriel is_gabriel = kernel_.side_of_bounded_sphere_d_object();
408 bool is_gab = is_gabriel(pointVector.begin(), pointVector.end(), point_for_gabriel)
409 != CGAL::ON_BOUNDED_SIDE;
411 std::cout <<
" | Tau is_gabriel(Sigma)=" << is_gab <<
" - vertexForGabriel=" << vertexForGabriel << std::endl;
412 #endif // DEBUG_TRACES 414 if (
false == is_gab) {
416 Filtration_value alpha_complex_filtration = complex.filtration(f_simplex);
419 std::cout <<
" | filt(Tau) = filt(Sigma) = " << complex.filtration(f_boundary) << std::endl;
420 #endif // DEBUG_TRACES 430 namespace alphacomplex = alpha_complex;
434 #endif // ALPHA_COMPLEX_H_ OFF file reader implementation in order to read points from an OFF file.
Definition: Points_off_io.h:134
void insert_simplex_and_subfaces(std::vector< Vertex_handle > const &vertex_range, Filtration_value filtration)
Inserts a simplex with vertices from a given simplex (represented by a vector of Vertex_handle) in th...
Simplex_vertex_range simplex_vertex_range(Simplex_handle const &simplex)
Returns a range over vertices of a given simplex.
Definition: SimplicialComplexForAlpha.h:26
const std::vector< Point_d > & get_point_cloud() const
Point cloud getter.
Definition: Points_off_io.h:170
~Alpha_complex()
Alpha_complex destructor deletes the Delaunay triangulation.
Definition: Alpha_complex.h:154
Kernel::Point_d Point_d
A point in Euclidean space.
Definition: Alpha_complex.h:85
Alpha_complex(const InputPointRange &points)
Alpha_complex constructor from a list of points.
Definition: Alpha_complex.h:147
Alpha_complex(const std::string &off_file_name)
Alpha_complex constructor from an OFF file name.
Definition: Alpha_complex.h:126
unspecified Vertex_handle
Definition: SimplicialComplexForAlpha.h:37
The concept SimplicialComplexForAlpha describes the requirements for a type to implement a simplicial...
Definition: SimplicialComplexForAlpha.h:33
void make_filtration_non_decreasing()
int dimension(Simplex_handle simplex)
void prune_above_filtration(Filtration_value filtration)
Kernel Geom_traits
Geometric traits class that provides the geometric types and predicates needed by Delaunay triangulat...
Definition: Alpha_complex.h:88
Alpha complex data structure.
Definition: Alpha_complex.h:75
const std::size_t number_of_vertices() const
number_of_vertices returns the number of vertices (same as the number of points). ...
Definition: Alpha_complex.h:178
CGAL::Delaunay_triangulation< Kernel, TDS > Delaunay_triangulation
A Delaunay triangulation of a set of points in .
Definition: Alpha_complex.h:82
void set_dimension(int dimension)
bool create_complex(SimplicialComplexForAlpha &complex, Filtration_value max_alpha_square)
Inserts all Delaunay triangulation into the simplicial complex. It also computes the filtration value...
Definition: Alpha_complex.h:252
int assign_filtration(Simplex_handle simplex, Filtration_value filtration)
bool is_valid() const
Returns if the OFF file read operation was successful or not.
Definition: Points_off_io.h:162
unspecified Simplex_handle
Definition: SimplicialComplexForAlpha.h:35
std::size_t num_vertices()
Boundary_simplex_range boundary_simplex_range(Simplex_handle const &simplex)
Returns a range over boundaries of a given simplex.
unspecified Filtration_value
Definition: SimplicialComplexForAlpha.h:39
const Point_d & get_point(std::size_t vertex) const
get_point returns the point corresponding to the vertex given as parameter.
Definition: Alpha_complex.h:170