summaryrefslogtreecommitdiff
path: root/src/Alpha_complex/utilities/periodic_alpha_complex_3d_persistence.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Alpha_complex/utilities/periodic_alpha_complex_3d_persistence.cpp')
-rw-r--r--src/Alpha_complex/utilities/periodic_alpha_complex_3d_persistence.cpp54
1 files changed, 23 insertions, 31 deletions
diff --git a/src/Alpha_complex/utilities/periodic_alpha_complex_3d_persistence.cpp b/src/Alpha_complex/utilities/periodic_alpha_complex_3d_persistence.cpp
index 186a58f8..188cf604 100644
--- a/src/Alpha_complex/utilities/periodic_alpha_complex_3d_persistence.cpp
+++ b/src/Alpha_complex/utilities/periodic_alpha_complex_3d_persistence.cpp
@@ -3,6 +3,7 @@
* library for computational topology.
*
* Author(s): Vincent Rouvreau
+ * Pawel Dlotko - 2017 - Swansea University, UK
*
* Copyright (C) 2014 INRIA
*
@@ -39,7 +40,6 @@
#include <tuple>
#include <map>
#include <utility>
-#include <list>
#include <vector>
#include <cstdlib>
@@ -72,14 +72,13 @@ using Cell_handle = Alpha_shape_3::Cell_handle;
using Facet = Alpha_shape_3::Facet;
using Edge_3 = Alpha_shape_3::Edge;
using Vertex_handle = Alpha_shape_3::Vertex_handle;
-using Vertex_list = std::list<Alpha_shape_3::Vertex_handle>;
+using Vertex_list = std::vector<Alpha_shape_3::Vertex_handle>;
// gudhi type definition
using ST = Gudhi::Simplex_tree<Gudhi::Simplex_tree_options_fast_persistence>;
using Filtration_value = ST::Filtration_value;
using Simplex_tree_vertex = ST::Vertex_handle;
using Alpha_shape_simplex_tree_map = std::map<Alpha_shape_3::Vertex_handle, Simplex_tree_vertex>;
-using Alpha_shape_simplex_tree_pair = std::pair<Alpha_shape_3::Vertex_handle, Simplex_tree_vertex>;
using Simplex_tree_vector_vertex = std::vector<Simplex_tree_vertex>;
using Persistent_cohomology =
Gudhi::persistent_cohomology::Persistent_cohomology<ST, Gudhi::persistent_cohomology::Field_Zp>;
@@ -114,8 +113,13 @@ int main(int argc, char **argv) {
std::cerr << "Unable to read file " << cuboid_file << std::endl;
exit(-1);
}
+ // Checking if the cuboid is the same in x,y and z direction. If not, CGAL will not process it.
+ if ((x_max - x_min != y_max - y_min) || (x_max - x_min != z_max - z_min) || (z_max - z_min != y_max - y_min)) {
+ std::cerr << "The size of the cuboid in every directions is not the same." << std::endl;
+ exit(-1);
+ }
- // Retrieve the triangulation
+ // Retrieve the points
std::vector<Point_3> lp = off_reader.get_point_cloud();
// Define the periodic cube
@@ -123,7 +127,12 @@ int main(int argc, char **argv) {
// Heuristic for inserting large point sets (if pts is reasonably large)
pdt.insert(lp.begin(), lp.end(), true);
// As pdt won't be modified anymore switch to 1-sheeted cover if possible
- if (pdt.is_triangulation_in_1_sheet()) pdt.convert_to_1_sheeted_covering();
+ if (pdt.is_triangulation_in_1_sheet()) {
+ pdt.convert_to_1_sheeted_covering();
+ } else {
+ std::cerr << "ERROR: we were not able to construct a triangulation within a single periodic domain." << std::endl;
+ exit(-1);
+ }
std::cout << "Periodic Delaunay computed." << std::endl;
// alpha shape construction from points. CGAL has a strange behavior in REGULARIZED mode. This is the default mode
@@ -152,37 +161,23 @@ int main(int argc, char **argv) {
ST simplex_tree;
Alpha_shape_simplex_tree_map map_cgal_simplex_tree;
std::vector<Alpha_value_type>::iterator the_alpha_value_iterator = the_alpha_values.begin();
- int dim_max = 0;
- Filtration_value filtration_max = 0.0;
for (auto object_iterator : the_objects) {
// Retrieve Alpha shape vertex list from object
- if (const Cell_handle* cell = CGAL::object_cast<Cell_handle>(&object_iterator)) {
+ if (const Cell_handle *cell = CGAL::object_cast<Cell_handle>(&object_iterator)) {
vertex_list = from_cell<Vertex_list, Cell_handle>(*cell);
count_cells++;
- if (dim_max < 3) {
- // Cell is of dim 3
- dim_max = 3;
- }
- } else if (const Facet* facet = CGAL::object_cast<Facet>(&object_iterator)) {
+ } else if (const Facet *facet = CGAL::object_cast<Facet>(&object_iterator)) {
vertex_list = from_facet<Vertex_list, Facet>(*facet);
count_facets++;
- if (dim_max < 2) {
- // Facet is of dim 2
- dim_max = 2;
- }
- } else if (const Edge_3* edge = CGAL::object_cast<Edge_3>(&object_iterator)) {
+ } else if (const Edge_3 *edge = CGAL::object_cast<Edge_3>(&object_iterator)) {
vertex_list = from_edge<Vertex_list, Edge_3>(*edge);
count_edges++;
- if (dim_max < 1) {
- // Edge_3 is of dim 1
- dim_max = 1;
- }
- } else if (const Vertex_handle* vertex = CGAL::object_cast<Vertex_handle>(&object_iterator)) {
+ } else if (const Vertex_handle *vertex = CGAL::object_cast<Vertex_handle>(&object_iterator)) {
count_vertices++;
vertex_list = from_vertex<Vertex_list, Vertex_handle>(*vertex);
}
// Construction of the vector of simplex_tree vertex from list of alpha_shapes vertex
- Simplex_tree_vector_vertex the_simplex_tree;
+ Simplex_tree_vector_vertex the_simplex;
for (auto the_alpha_shape_vertex : vertex_list) {
Alpha_shape_simplex_tree_map::iterator the_map_iterator = map_cgal_simplex_tree.find(the_alpha_shape_vertex);
if (the_map_iterator == map_cgal_simplex_tree.end()) {
@@ -191,15 +186,15 @@ int main(int argc, char **argv) {
#ifdef DEBUG_TRACES
std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] not found - insert " << vertex << std::endl;
#endif // DEBUG_TRACES
- the_simplex_tree.push_back(vertex);
- map_cgal_simplex_tree.insert(Alpha_shape_simplex_tree_pair(the_alpha_shape_vertex, vertex));
+ the_simplex.push_back(vertex);
+ map_cgal_simplex_tree.emplace(the_alpha_shape_vertex, vertex);
} else {
// alpha shape found
Simplex_tree_vertex vertex = the_map_iterator->second;
#ifdef DEBUG_TRACES
std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] found in " << vertex << std::endl;
#endif // DEBUG_TRACES
- the_simplex_tree.push_back(vertex);
+ the_simplex.push_back(vertex);
}
}
// Construction of the simplex_tree
@@ -207,10 +202,7 @@ int main(int argc, char **argv) {
#ifdef DEBUG_TRACES
std::cout << "filtration = " << filtr << std::endl;
#endif // DEBUG_TRACES
- if (filtr > filtration_max) {
- filtration_max = filtr;
- }
- simplex_tree.insert_simplex(the_simplex_tree, filtr);
+ simplex_tree.insert_simplex(the_simplex, filtr);
if (the_alpha_value_iterator != the_alpha_values.end())
++the_alpha_value_iterator;
else