23 #ifndef ALPHA_COMPLEX_H_
24 #define ALPHA_COMPLEX_H_
27 #include <gudhi/graph_simplicial_complex.h>
28 #include <gudhi/Simplex_tree.h>
29 #include <gudhi/Debug_utils.h>
31 #include <gudhi/Points_off_io.h>
36 #include <CGAL/Delaunay_triangulation.h>
37 #include <CGAL/Epick_d.h>
38 #include <CGAL/Spatial_sort_traits_adapter_d.h>
51 namespace alphacomplex {
76 template<
class Kernel = CGAL::Epick_d<CGAL::Dynamic_dimension_tag>>
80 typedef CGAL::Triangulation_data_structure<CGAL::Dynamic_dimension_tag,
81 CGAL::Triangulation_vertex<Kernel, std::ptrdiff_t>,
82 CGAL::Triangulation_full_cell<Kernel> > TDS;
95 typedef std::vector<Vertex_handle> Vector_vertex;
98 typedef typename std::pair<Simplex_handle, bool> Simplex_result;
100 typedef typename Kernel::Compute_squared_radius_d Squared_Radius;
101 typedef typename Kernel::Side_of_bounded_sphere_d Is_Gabriel;
102 typedef typename Kernel::Point_dimension_d Point_Dimension;
105 typedef typename std::vector<Point_d> Vector_of_CGAL_points;
108 typedef typename Delaunay_triangulation::Vertex_iterator CGAL_vertex_iterator;
111 typedef typename Delaunay_triangulation::size_type size_type;
114 typedef typename std::map< Vertex_handle, CGAL_vertex_iterator > Vector_vertex_iterator;
119 Vector_vertex_iterator vertex_handle_to_iterator_;
136 Filtration_value max_alpha_square = std::numeric_limits<Filtration_value>::infinity())
137 : triangulation_(nullptr) {
140 std::cerr <<
"Alpha_complex - Unable to read file " << off_file_name <<
"\n";
159 template<
typename InputPo
intRange >
161 Filtration_value max_alpha_square = std::numeric_limits<Filtration_value>::infinity())
162 : triangulation_(nullptr) {
163 init_from_range(points, max_alpha_square);
171 delete triangulation_;
187 return vertex_handle_to_iterator_.at(vertex)->point();
191 template<
typename InputPo
intRange >
192 void init_from_range(
const InputPointRange& points, Filtration_value max_alpha_square) {
193 auto first = std::begin(points);
194 auto last = std::end(points);
197 Point_Dimension point_dimension = kernel_.point_dimension_d_object();
202 std::vector<Point_d> points(first, last);
205 std::vector<std::ptrdiff_t> indices(boost::counting_iterator<std::ptrdiff_t>(0),
206 boost::counting_iterator<std::ptrdiff_t>(points.size()));
209 typedef CGAL::Spatial_sort_traits_adapter_d<Kernel, Point_d*> Search_traits_d;
210 spatial_sort(indices.begin(), indices.end(), Search_traits_d(&(points[0])));
212 typename Delaunay_triangulation::Full_cell_handle hint;
213 for (
auto index : indices) {
214 typename Delaunay_triangulation::Vertex_handle pos = triangulation_->insert(points[index], hint);
217 hint = pos->full_cell();
219 init(max_alpha_square);
232 void init(Filtration_value max_alpha_square) {
233 if (triangulation_ ==
nullptr) {
234 std::cerr <<
"Alpha_complex init - Cannot init from a NULL triangulation\n";
237 if (triangulation_->number_of_vertices() < 1) {
238 std::cerr <<
"Alpha_complex init - Cannot init from a triangulation without vertices\n";
241 if (triangulation_->maximal_dimension() < 1) {
242 std::cerr <<
"Alpha_complex init - Cannot init from a zero-dimension triangulation\n";
246 std::cerr <<
"Alpha_complex init - Cannot init twice\n";
255 for (CGAL_vertex_iterator vit = triangulation_->vertices_begin(); vit != triangulation_->vertices_end(); ++vit) {
256 if (!triangulation_->is_infinite(*vit)) {
258 std::cout <<
"Vertex insertion - " << vit->data() <<
" -> " << vit->point() << std::endl;
259 #endif // DEBUG_TRACES
260 vertex_handle_to_iterator_.emplace(vit->data(), vit);
267 for (
auto cit = triangulation_->finite_full_cells_begin(); cit != triangulation_->finite_full_cells_end(); ++cit) {
268 Vector_vertex vertexVector;
270 std::cout <<
"Simplex_tree insertion ";
271 #endif // DEBUG_TRACES
272 for (
auto vit = cit->vertices_begin(); vit != cit->vertices_end(); ++vit) {
273 if (*vit !=
nullptr) {
275 std::cout <<
" " << (*vit)->data();
276 #endif // DEBUG_TRACES
278 vertexVector.push_back((*vit)->data());
282 std::cout << std::endl;
283 #endif // DEBUG_TRACES
291 for (
int decr_dim =
dimension(); decr_dim >= 0; decr_dim--) {
294 int f_simplex_dim =
dimension(f_simplex);
295 if (decr_dim == f_simplex_dim) {
296 Vector_of_CGAL_points pointVector;
298 std::cout <<
"Sigma of dim " << decr_dim <<
" is";
299 #endif // DEBUG_TRACES
301 pointVector.push_back(
get_point(vertex));
303 std::cout <<
" " << vertex;
304 #endif // DEBUG_TRACES
307 std::cout << std::endl;
308 #endif // DEBUG_TRACES
311 Filtration_value alpha_complex_filtration = 0.0;
313 if (f_simplex_dim > 0) {
315 Squared_Radius squared_radius = kernel_.compute_squared_radius_d_object();
317 alpha_complex_filtration = squared_radius(pointVector.begin(), pointVector.end());
321 std::cout <<
"filt(Sigma) is NaN : filt(Sigma) =" <<
filtration(f_simplex) << std::endl;
322 #endif // DEBUG_TRACES
324 propagate_alpha_filtration(f_simplex, decr_dim);
342 template<
typename Simplex_handle>
343 void propagate_alpha_filtration(
Simplex_handle f_simplex,
int decr_dim) {
347 std::cout <<
" | --------------------------------------------------\n";
348 std::cout <<
" | Tau ";
350 std::cout << vertex <<
" ";
352 std::cout <<
"is a face of Sigma\n";
353 std::cout <<
" | isnan(filtration(Tau)=" << isnan(
filtration(f_boundary)) << std::endl;
354 #endif // DEBUG_TRACES
358 Filtration_value alpha_complex_filtration = fmin(
filtration(f_boundary),
filtration(f_simplex));
361 std::cout <<
" | filt(Tau) = fmin(filt(Tau), filt(Sigma)) = " <<
filtration(f_boundary) << std::endl;
362 #endif // DEBUG_TRACES
369 Vector_of_CGAL_points pointVector;
372 #endif // DEBUG_TRACES
374 pointVector.push_back(
get_point(vertex));
380 if (std::find(pointVector.begin(), pointVector.end(), point_for_gabriel) == pointVector.end()) {
383 vertexForGabriel = vertex;
384 #endif // DEBUG_TRACES
390 Is_Gabriel is_gabriel = kernel_.side_of_bounded_sphere_d_object();
391 bool is_gab = is_gabriel(pointVector.begin(), pointVector.end(), point_for_gabriel)
392 != CGAL::ON_BOUNDED_SIDE;
394 std::cout <<
" | Tau is_gabriel(Sigma)=" << is_gab <<
" - vertexForGabriel=" << vertexForGabriel << std::endl;
395 #endif // DEBUG_TRACES
397 if (
false == is_gab) {
399 Filtration_value alpha_complex_filtration =
filtration(f_simplex);
402 std::cout <<
" | filt(Tau) = filt(Sigma) = " <<
filtration(f_boundary) << std::endl;
403 #endif // DEBUG_TRACES
415 #endif // ALPHA_COMPLEX_H_
Dictionary::iterator Simplex_handle
Handle type to a simplex contained in the simplicial complex represented by the simplex tree...
Definition: Simplex_tree.h:164
bool prune_above_filtration(Filtration_value filtration)
Prune above filtration value given as parameter.
Definition: Simplex_tree.h:1192
Kernel Geom_traits
Geometric traits class that provides the geometric types and predicates needed by Delaunay triangulat...
Definition: Alpha_complex.h:90
Simplex Tree data structure for representing simplicial complexes.
Definition: Simplex_tree.h:102
std::pair< Simplex_handle, bool > insert_simplex_and_subfaces(const InputVertexRange &Nsimplex, Filtration_value filtration=0)
Insert a N-simplex and all his subfaces, from a N-simplex represented by a range of Vertex_handles...
Definition: Simplex_tree.h:693
OFF file reader implementation in order to read points from an OFF file.
Definition: Points_off_io.h:135
Point_d get_point(Vertex_handle vertex) const
get_point returns the point corresponding to the vertex given as parameter.
Definition: Alpha_complex.h:186
Alpha_complex(const InputPointRange &points, Filtration_value max_alpha_square=std::numeric_limits< Filtration_value >::infinity())
Alpha_complex constructor from a list of points.
Definition: Alpha_complex.h:160
const std::vector< Point_d > & get_point_cloud() const
Point cloud getter.
Definition: Points_off_io.h:171
Filtration_value filtration() const
Returns an upper bound of the filtration values of the simplices.
Definition: Simplex_tree.h:462
bool make_filtration_non_decreasing()
Browse the simplex tree to ensure the filtration is not decreasing. The simplex tree is browsed start...
Definition: Simplex_tree.h:1142
void initialize_filtration()
Initializes the filtrations, i.e. sort the simplices according to their order in the filtration and i...
Definition: Simplex_tree.h:811
void assign_filtration(Simplex_handle sh, Filtration_value fv)
Sets the filtration value of a simplex. In debug mode, if sh is a null_simplex.
Definition: Simplex_tree.h:455
Boundary_simplex_range boundary_simplex_range(SimplexHandle sh)
Returns a range over the simplices of the boundary of a simplex.
Definition: Simplex_tree.h:311
int dimension() const
Returns an upper bound on the dimension of the simplicial complex.
Definition: Simplex_tree.h:526
Simplex_vertex_range simplex_vertex_range(Simplex_handle sh)
Returns a range over the vertices of a simplex.
Definition: Simplex_tree.h:290
Kernel::Point_d Point_d
A point in Euclidean space.
Definition: Alpha_complex.h:87
Options::Vertex_handle Vertex_handle
Type for the vertex handle.
Definition: Simplex_tree.h:117
~Alpha_complex()
Alpha_complex destructor.
Definition: Alpha_complex.h:170
Alpha complex data structure.
Definition: Alpha_complex.h:77
Skeleton_simplex_range skeleton_simplex_range(int dim)
Returns a range over the simplices of the dim-skeleton of the simplicial complex. ...
Definition: Simplex_tree.h:257
Alpha_complex(const std::string &off_file_name, Filtration_value max_alpha_square=std::numeric_limits< Filtration_value >::infinity())
Alpha_complex constructor from an OFF file name. Uses the Delaunay_triangulation_off_reader to constr...
Definition: Alpha_complex.h:135
void set_dimension(int dimension)
Definition: Simplex_tree.h:797
CGAL::Delaunay_triangulation< Kernel, TDS > Delaunay_triangulation
A Delaunay triangulation of a set of points in .
Definition: Alpha_complex.h:84
bool is_valid() const
Returns if the OFF file read operation was successful or not.
Definition: Points_off_io.h:163
size_t num_vertices() const
Returns the number of vertices in the complex.
Definition: Simplex_tree.h:487
Options::Filtration_value Filtration_value
Type for the value of the filtration function.
Definition: Simplex_tree.h:109