From 2445eaa9d34272832a8edd680e30c2b8b3298242 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 9 Jun 2015 11:20:14 +0000 Subject: Checkin for rollback purpose. Compiles but do not work. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/alphashapes@607 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: e163ca16ebc76a13cec21bf881fe3b03e0617711 --- .../example/Delaunay_triangulation_off_rw.cpp | 4 +- .../Simplex_tree_from_delaunay_triangulation.cpp | 2 +- src/Alpha_shapes/example/alphashapedoc.off | 10 ++++ src/Alpha_shapes/include/gudhi/Alpha_shapes.h | 45 ++++++++++-------- .../Alpha_shapes/Delaunay_triangulation_off_io.h | 54 +++++++++++++++++----- 5 files changed, 80 insertions(+), 35 deletions(-) create mode 100755 src/Alpha_shapes/example/alphashapedoc.off diff --git a/src/Alpha_shapes/example/Delaunay_triangulation_off_rw.cpp b/src/Alpha_shapes/example/Delaunay_triangulation_off_rw.cpp index a31c44ab..6c9fcdab 100644 --- a/src/Alpha_shapes/example/Delaunay_triangulation_off_rw.cpp +++ b/src/Alpha_shapes/example/Delaunay_triangulation_off_rw.cpp @@ -82,7 +82,7 @@ int main(int argc, char **argv) { } std::cout << std::endl;*/ - int i = 0, j = 0; + /*int i = 0, j = 0; typedef T::Full_cell_iterator Full_cell_iterator; typedef T::Facet Facet; @@ -96,7 +96,7 @@ int main(int argc, char **argv) { } std::cout << "There are " << i << " facets on the convex hull." << std::endl; std::cout << "There are " << j << " facets not on the convex hull." << std::endl; - +*/ std::string offOutputFile("out.off"); Gudhi::alphashapes::Delaunay_triangulation_off_writer off_writer(offOutputFile, dt); diff --git a/src/Alpha_shapes/example/Simplex_tree_from_delaunay_triangulation.cpp b/src/Alpha_shapes/example/Simplex_tree_from_delaunay_triangulation.cpp index 11079a03..0a24fb56 100644 --- a/src/Alpha_shapes/example/Simplex_tree_from_delaunay_triangulation.cpp +++ b/src/Alpha_shapes/example/Simplex_tree_from_delaunay_triangulation.cpp @@ -66,12 +66,12 @@ int main(int argc, char **argv) { // // ---------------------------------------------------------------------------- Gudhi::alphashapes::Alpha_shapes alpha_shapes_from_file(off_file_name); - //std::cout << alpha_shapes_from_file << std::endl; std::cout << "alpha_shapes_from_file.dimension()=" << alpha_shapes_from_file.dimension() << std::endl; std::cout << "alpha_shapes_from_file.filtration()=" << alpha_shapes_from_file.filtration() << std::endl; std::cout << "alpha_shapes_from_file.num_simplices()=" << alpha_shapes_from_file.num_simplices() << std::endl; std::cout << "alpha_shapes_from_file.num_vertices()=" << alpha_shapes_from_file.num_vertices() << std::endl; + //std::cout << alpha_shapes_from_file << std::endl; return 0; } \ No newline at end of file diff --git a/src/Alpha_shapes/example/alphashapedoc.off b/src/Alpha_shapes/example/alphashapedoc.off new file mode 100755 index 00000000..bb790193 --- /dev/null +++ b/src/Alpha_shapes/example/alphashapedoc.off @@ -0,0 +1,10 @@ +nOFF +2 7 0 0 +1.0 1.0 +7.0 0.0 +4.0 6.0 +9.0 6.0 +0.0 14.0 +2.0 19.0 +9.0 17.0 + diff --git a/src/Alpha_shapes/include/gudhi/Alpha_shapes.h b/src/Alpha_shapes/include/gudhi/Alpha_shapes.h index 6f290938..6de675f6 100644 --- a/src/Alpha_shapes/include/gudhi/Alpha_shapes.h +++ b/src/Alpha_shapes/include/gudhi/Alpha_shapes.h @@ -96,13 +96,13 @@ class Alpha_shapes { private: /** \brief Upper bound on the simplex tree of the simplicial complex.*/ - Gudhi::Simplex_tree<> _st; + Gudhi::Simplex_tree<> st_; public: - Alpha_shapes(std::string off_file_name) { + Alpha_shapes(std::string& off_file_name) { // Construct a default Delaunay_triangulation (dim=0) - dim will be set in visitor reader init function - Delaunay_triangulation dt(3); + Delaunay_triangulation dt(2); Gudhi::alphashapes::Delaunay_triangulation_off_reader off_reader(off_file_name, dt); if (!off_reader.is_valid()) { std::cerr << "Unable to read file " << off_file_name << std::endl; @@ -117,7 +117,7 @@ class Alpha_shapes { } template - Alpha_shapes(T triangulation) { + Alpha_shapes(T& triangulation) { init(triangulation); } @@ -126,8 +126,8 @@ class Alpha_shapes { private: template - void init(T triangulation) { - _st.set_dimension(triangulation.maximal_dimension()); + void init(T& triangulation) { + st_.set_dimension(triangulation.maximal_dimension()); Filtration_value filtration_max = 0.0; Kernel k; @@ -148,11 +148,11 @@ class Alpha_shapes { // Vector of points for alpha_shapes filtration value computation pointVector.push_back((*vit)->point()); #ifdef DEBUG_TRACES - std::cout << "Point "; + /*std::cout << "Point "; for (auto Coord = (*vit)->point().cartesian_begin(); Coord != (*vit)->point().cartesian_end(); ++Coord) { std::cout << *Coord << " | "; } - std::cout << std::endl; + std::cout << std::endl;*/ #endif // DEBUG_TRACES } } @@ -161,66 +161,71 @@ class Alpha_shapes { if (!triangulation.is_infinite(cit)) { alpha_shapes_filtration = squared_radius(pointVector.begin(), pointVector.end()); #ifdef DEBUG_TRACES - std::cout << "Alpha_shape filtration value = " << alpha_shapes_filtration << std::endl; + //std::cout << "Alpha_shape filtration value = " << alpha_shapes_filtration << std::endl; #endif // DEBUG_TRACES } else { Filtration_value tmp_filtration = 0.0; bool is_gab = true; - for (auto vit = triangulation.finite_vertices_begin(); vit != triangulation.finite_vertices_end(); ++vit) { + /*for (auto vit = triangulation.finite_vertices_begin(); vit != triangulation.finite_vertices_end(); ++vit) { if (CGAL::ON_UNBOUNDED_SIDE != is_gabriel(pointVector.begin(), pointVector.end(), vit->point())) { is_gab = false; // TODO(VR) : Compute minimum } - } + }*/ if (true == is_gab) { alpha_shapes_filtration = squared_radius(pointVector.begin(), pointVector.end()); #ifdef DEBUG_TRACES - std::cout << "Alpha_shape filtration value = " << alpha_shapes_filtration << std::endl; + //std::cout << "Alpha_shape filtration value = " << alpha_shapes_filtration << std::endl; #endif // DEBUG_TRACES } } // Insert each point in the simplex tree - _st.insert_simplex_and_subfaces(vertexVector, alpha_shapes_filtration); + st_.insert_simplex_and_subfaces(vertexVector, alpha_shapes_filtration); #ifdef DEBUG_TRACES std::cout << "C" << std::distance(triangulation.full_cells_begin(), cit) << ":"; for (auto value : vertexVector) { std::cout << value << ' '; } - std::cout << std::endl; + std::cout << " | alpha=" << alpha_shapes_filtration << std::endl; #endif // DEBUG_TRACES } - _st.set_filtration(filtration_max); + st_.set_filtration(filtration_max); + } + + template + void recursive_init(T& triangulation, typeVectorVertex vertexVector) { + } public: /** \brief Returns the number of vertices in the complex. */ size_t num_vertices() { - return _st.num_vertices(); + return st_.num_vertices(); } /** \brief Returns the number of simplices in the complex. * * Does not count the empty simplex. */ const unsigned int& num_simplices() const { - return _st.num_simplices(); + return st_.num_simplices(); } /** \brief Returns an upper bound on the dimension of the simplicial complex. */ int dimension() { - return _st.dimension(); + return st_.dimension(); } /** \brief Returns an upper bound of the filtration values of the simplices. */ Filtration_value filtration() { - return _st.filtration(); + return st_.filtration(); } friend std::ostream& operator<<(std::ostream& os, const Alpha_shapes& alpha_shape) { // TODO: Program terminated with signal SIGABRT, Aborted - Maybe because of copy constructor - Gudhi::Simplex_tree<> st = alpha_shape._st; + Gudhi::Simplex_tree<> st = alpha_shape.st_; os << st << std::endl; return os; } diff --git a/src/Alpha_shapes/include/gudhi/Alpha_shapes/Delaunay_triangulation_off_io.h b/src/Alpha_shapes/include/gudhi/Alpha_shapes/Delaunay_triangulation_off_io.h index 3215c8f6..1413ad89 100644 --- a/src/Alpha_shapes/include/gudhi/Alpha_shapes/Delaunay_triangulation_off_io.h +++ b/src/Alpha_shapes/include/gudhi/Alpha_shapes/Delaunay_triangulation_off_io.h @@ -25,6 +25,7 @@ #include #include #include +#include // std::distance #include "gudhi/Off_reader.h" @@ -47,7 +48,7 @@ class Delaunay_triangulation_off_visitor_reader { void init(int dim, int num_vertices, int num_faces, int num_edges) { #ifdef DEBUG_TRACES - std::cout << "Delaunay_triangulation_off_visitor_reader::init - dim=" << dim << " - num_vertices=" << + std::cout << "Delaunay_triangulation_off_visitor_reader::init - dim=" << dim << " - num_vertices=" << num_vertices << " - num_faces=" << num_faces << " - num_edges=" << num_edges << std::endl; #endif // DEBUG_TRACES if (num_faces > 0) { @@ -121,7 +122,7 @@ class Delaunay_triangulation_off_reader { bool is_valid() const { return valid_; } - + private: bool valid_; }; @@ -138,10 +139,19 @@ class Delaunay_triangulation_off_writer { Delaunay_triangulation_off_writer(const std::string & name_file, const Complex& save_complex) { std::ofstream stream(name_file); if (stream.is_open()) { - // OFF header - stream << "OFF" << std::endl; - // no endl on next line - don't know why... - stream << save_complex.number_of_vertices() << " " << save_complex.number_of_finite_full_cells() << " 0"; + if (save_complex.current_dimension() == 3) { + // OFF header + stream << "OFF" << std::endl; + // no endl on next line - don't know why... + stream << save_complex.number_of_vertices() << " " << save_complex.number_of_finite_full_cells() << " 0"; + } else { + // nOFF header + stream << "nOFF" << std::endl; + // no endl on next line - don't know why... + stream << save_complex.current_dimension() << " " << save_complex.number_of_vertices() << " " << + save_complex.number_of_finite_full_cells() << " 0"; + + } // Points list for (auto vit = save_complex.vertices_begin(); vit != save_complex.vertices_end(); ++vit) { @@ -151,16 +161,36 @@ class Delaunay_triangulation_off_writer { stream << std::endl; } - // Finite cells list - for (auto cit = save_complex.finite_full_cells_begin(); cit != save_complex.finite_full_cells_end(); ++cit) { - stream << std::distance(cit->vertices_begin(), cit->vertices_end()) << " "; // Dimension + + for (auto cit = save_complex.full_cells_begin(); cit != save_complex.full_cells_end(); ++cit) { + std::vector vertexVector; + stream << std::distance(cit->vertices_begin(), cit->vertices_end()) << " "; for (auto vit = cit->vertices_begin(); vit != cit->vertices_end(); ++vit) { - auto vertexHdl = *vit; - // auto vertexHdl = std::distance(save_complex.vertices_begin(), *vit) - 1; - // stream << std::distance(save_complex.vertices_begin(), *(vit)) - 1 << " "; + // Vector of vertex construction for simplex_tree structure + // Vertex handle is distance - 1 + //int vertexHdl = std::distance(save_complex.vertices_begin(), *vit); + // infinite cell is -1 for infinite + //vertexVector.push_back(vertexHdl); + // Vector of points for alpha_shapes filtration value computation } stream << std::endl; } + + + + + + /* + // Finite cells list + for (auto cit = save_complex.full_cells_begin(); cit != save_complex.full_cells_end(); ++cit) { + stream << std::distance(cit->vertices_begin(), cit->vertices_end()) << " "; // Dimension + for (auto vit = cit->vertices_begin(); vit != cit->vertices_end(); ++vit) { + //auto vertexHdl = *vit; + auto vertexHdl = std::distance(save_complex.vertices_begin(), vit) - 1; + // stream << std::distance(save_complex.vertices_begin(), *(vit)) - 1 << " "; + } + stream << std::endl; + }*/ stream.close(); } else { std::cerr << "Delaunay_triangulation_off_writer::Delaunay_triangulation_off_writer could not open file " << -- cgit v1.2.3