summaryrefslogtreecommitdiff
path: root/src/Alpha_complex
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-11-12 16:26:05 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-11-12 16:26:05 +0000
commit8881190bccba9da4af0a07c701369099fd7f2277 (patch)
treea215efb479896620d3973af26c65595e85064e1a /src/Alpha_complex
parent493372a01e24220d16ef0405eb7cdc4bbe96fe1c (diff)
code review fix
prune_above_filtration and remove_maximal_simplex in Simplex_tree.h make_filtration_non_decreasing and rec_make_filtration_non_decreasing in Simplex_tree.h git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/alphashapes@910 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: a20c9da65a5a3294e42ad2dd45a399d77fb5ad30
Diffstat (limited to 'src/Alpha_complex')
-rw-r--r--src/Alpha_complex/doc/Intro_alpha_complex.h5
-rw-r--r--src/Alpha_complex/example/Alpha_complex_from_off.cpp6
-rw-r--r--src/Alpha_complex/example/CMakeLists.txt2
-rw-r--r--src/Alpha_complex/include/gudhi/Alpha_complex.h24
-rw-r--r--src/Alpha_complex/test/Alpha_complex_unit_test.cpp54
5 files changed, 66 insertions, 25 deletions
diff --git a/src/Alpha_complex/doc/Intro_alpha_complex.h b/src/Alpha_complex/doc/Intro_alpha_complex.h
index 2cb37578..1fb8fdee 100644
--- a/src/Alpha_complex/doc/Intro_alpha_complex.h
+++ b/src/Alpha_complex/doc/Intro_alpha_complex.h
@@ -20,6 +20,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#ifndef INTRO_ALPHA_COMPLEX_H_
+#define INTRO_ALPHA_COMPLEX_H_
+
// needs namespace for Doxygen to link on classes
namespace Gudhi {
// needs namespace for Doxygen to link on classes
@@ -117,3 +120,5 @@ namespace alphacomplex {
} // namespace alphacomplex
} // namespace Gudhi
+
+#endif // INTRO_ALPHA_COMPLEX_H_
diff --git a/src/Alpha_complex/example/Alpha_complex_from_off.cpp b/src/Alpha_complex/example/Alpha_complex_from_off.cpp
index e140fe3d..cd6f5a4b 100644
--- a/src/Alpha_complex/example/Alpha_complex_from_off.cpp
+++ b/src/Alpha_complex/example/Alpha_complex_from_off.cpp
@@ -25,7 +25,7 @@ int main(int argc, char **argv) {
// ----------------------------------------------------------------------------
typedef CGAL::Epick_d< CGAL::Dynamic_dimension_tag > Kernel;
Gudhi::alphacomplex::Alpha_complex<Kernel> alpha_complex_from_file(off_file_name, alpha_square_max_value);
-
+
// ----------------------------------------------------------------------------
// Display information about the alpha complex
// ----------------------------------------------------------------------------
@@ -35,14 +35,14 @@ int main(int argc, char **argv) {
std::cout << "Iterator on alpha complex simplices in the filtration order, with [filtration value]:" << std::endl;
for (auto f_simplex : alpha_complex_from_file.filtration_simplex_range()) {
- if (alpha_complex_from_file.filtration(f_simplex) <= alpha_complex_from_file.filtration()) {
+ //if (alpha_complex_from_file.filtration(f_simplex) <= alpha_complex_from_file.filtration()) {
std::cout << " ( ";
for (auto vertex : alpha_complex_from_file.simplex_vertex_range(f_simplex)) {
std::cout << vertex << " ";
}
std::cout << ") -> " << "[" << alpha_complex_from_file.filtration(f_simplex) << "] ";
std::cout << std::endl;
- }
+ //}
}
return 0;
}
diff --git a/src/Alpha_complex/example/CMakeLists.txt b/src/Alpha_complex/example/CMakeLists.txt
index 10b87f04..24f3a9dc 100644
--- a/src/Alpha_complex/example/CMakeLists.txt
+++ b/src/Alpha_complex/example/CMakeLists.txt
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 2.6)
project(GUDHIAlphaShapesExample)
+add_executable ( flat flat.cpp )
+
# need CGAL 4.7
# cmake -DCGAL_DIR=~/workspace/CGAL-4.7-Ic-41 ../../..
if(CGAL_FOUND)
diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex.h b/src/Alpha_complex/include/gudhi/Alpha_complex.h
index 562b80c3..10b290b5 100644
--- a/src/Alpha_complex/include/gudhi/Alpha_complex.h
+++ b/src/Alpha_complex/include/gudhi/Alpha_complex.h
@@ -105,6 +105,7 @@ class Alpha_complex : public Simplex_tree<> {
* the Alpha_complex.
*
* @param[in] off_file_name OFF file [path and] name.
+ * @param[in] max_alpha_square maximum for alpha square value. Default value is +\f$\infty\f$.
*/
Alpha_complex(const std::string& off_file_name,
Filtration_value max_alpha_square = std::numeric_limits<Filtration_value>::infinity())
@@ -115,25 +116,24 @@ class Alpha_complex : public Simplex_tree<> {
exit(-1); // ----- >>
}
triangulation_ = off_reader.get_complex();
- set_filtration(max_alpha_square);
- init();
+ init(max_alpha_square);
}
/** \brief Alpha_complex constructor from a Delaunay triangulation.
*
* @param[in] triangulation_ptr Pointer on a Delaunay triangulation.
+ * @param[in] max_alpha_square maximum for alpha square value. Default value is +\f$\infty\f$.
*/
Alpha_complex(Delaunay_triangulation* triangulation_ptr,
Filtration_value max_alpha_square = std::numeric_limits<Filtration_value>::infinity())
: triangulation_(triangulation_ptr) {
- set_filtration(max_alpha_square);
- init();
+ init(max_alpha_square);
}
/** \brief Alpha_complex constructor from a list of points.
*
- * @param[in] dimension Dimension of points to be inserted.
* @param[in] points Range of points to triangulate. Points must be in Kernel::Point_d
+ * @param[in] max_alpha_square maximum for alpha square value. Default value is +\f$\infty\f$.
*
* The type InputPointRange must be a range for which std::begin and
* std::end return input iterators on a Kernel::Point_d.
@@ -155,8 +155,7 @@ class Alpha_complex : public Simplex_tree<> {
std::cerr << "Alpha_complex - insertion failed " << inserted << " != " << (last -first) << std::endl;
exit(-1); // ----- >>
}
- set_filtration(max_alpha_square);
- init();
+ init(max_alpha_square);
}
/** \brief Alpha_complex destructor from a Delaunay triangulation.
@@ -180,12 +179,14 @@ class Alpha_complex : public Simplex_tree<> {
private:
/** \brief Initialize the Alpha_complex from the Delaunay triangulation.
*
+ * @param[in] max_alpha_square maximum for alpha square value.
+ *
* @warning Delaunay triangulation must be already constructed with at least one vertex and dimension must be more
* than 0.
*
* Initialization can be launched once.
*/
- void init() {
+ void init(Filtration_value max_alpha_square) {
if (triangulation_ == nullptr) {
std::cerr << "Alpha_complex init - Cannot init from a NULL triangulation" << std::endl;
return; // ----- >>
@@ -287,6 +288,13 @@ class Alpha_complex : public Simplex_tree<> {
}
}
// --------------------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------------------
+ // As Alpha value is an approximation, we have to make filtration non decreasing while increasing the dimension
+ make_filtration_non_decreasing();
+ // Remove all simplices that have a filtration value greater than max_alpha_square
+ prune_above_filtration(max_alpha_square);
+ // --------------------------------------------------------------------------------------------
}
template<typename Simplex_handle>
diff --git a/src/Alpha_complex/test/Alpha_complex_unit_test.cpp b/src/Alpha_complex/test/Alpha_complex_unit_test.cpp
index f64a8ea9..2912019d 100644
--- a/src/Alpha_complex/test/Alpha_complex_unit_test.cpp
+++ b/src/Alpha_complex/test/Alpha_complex_unit_test.cpp
@@ -88,20 +88,9 @@ BOOST_AUTO_TEST_CASE(ALPHA_DOC_OFF_file_filtered) {
std::cout << "alpha_complex_from_file.num_vertices()=" << alpha_complex_from_file.num_vertices() << std::endl;
BOOST_CHECK(alpha_complex_from_file.num_vertices() == NUMBER_OF_VERTICES);
- const int NUMBER_OF_SIMPLICES = 25;
+ const int NUMBER_OF_SIMPLICES = 23;
std::cout << "alpha_complex_from_file.num_simplices()=" << alpha_complex_from_file.num_simplices() << std::endl;
BOOST_CHECK(alpha_complex_from_file.num_simplices() == NUMBER_OF_SIMPLICES);
-
- int num_filtered_simplices = 0;
- for (auto f_simplex : alpha_complex_from_file.filtration_simplex_range()) {
- if (alpha_complex_from_file.filtration(f_simplex) <= alpha_complex_from_file.filtration()) {
- num_filtered_simplices++;
- }
- }
- const int NUMBER_OF_FILTERED_SIMPLICES = 23;
- std::cout << "num_filtered_simplices=" << num_filtered_simplices << std::endl;
- BOOST_CHECK(num_filtered_simplices == NUMBER_OF_FILTERED_SIMPLICES);
-
}
bool are_almost_the_same(float a, float b) {
@@ -140,8 +129,7 @@ BOOST_AUTO_TEST_CASE(Alpha_complex_from_points) {
// ----------------------------------------------------------------------------
// Init of an alpha complex from the list of points
// ----------------------------------------------------------------------------
- double max_alpha_square_value = 1e10;
- Gudhi::alphacomplex::Alpha_complex<Kernel_s> alpha_complex_from_points(points, max_alpha_square_value);
+ Gudhi::alphacomplex::Alpha_complex<Kernel_s> alpha_complex_from_points(points);
std::cout << "========== Alpha_complex_from_points ==========" << std::endl;
@@ -210,4 +198,42 @@ BOOST_AUTO_TEST_CASE(Alpha_complex_from_points) {
BOOST_CHECK_THROW (alpha_complex_from_points.get_point(4), std::out_of_range);
BOOST_CHECK_THROW (alpha_complex_from_points.get_point(-1), std::out_of_range);
BOOST_CHECK_THROW (alpha_complex_from_points.get_point(1234), std::out_of_range);
+
+ // Test after prune_above_filtration
+ alpha_complex_from_points.prune_above_filtration(0.6);
+ // Another way to check num_simplices
+ std::cout << "Iterator on alpha complex simplices in the filtration order, with [filtration value]:" << std::endl;
+ num_simplices = 0;
+ for (auto f_simplex : alpha_complex_from_points.filtration_simplex_range()) {
+ num_simplices++;
+ std::cout << " ( ";
+ for (auto vertex : alpha_complex_from_points.simplex_vertex_range(f_simplex)) {
+ std::cout << vertex << " ";
+ }
+ std::cout << ") -> " << "[" << alpha_complex_from_points.filtration(f_simplex) << "] ";
+ std::cout << std::endl;
+ }
+ BOOST_CHECK(num_simplices == 10);
+ std::cout << "alpha_complex_from_points.num_simplices()=" << alpha_complex_from_points.num_simplices() << std::endl;
+ BOOST_CHECK(alpha_complex_from_points.num_simplices() == 10);
+
+ std::cout << "alpha_complex_from_points.dimension()=" << alpha_complex_from_points.dimension() << std::endl;
+ BOOST_CHECK(alpha_complex_from_points.dimension() == 4);
+ std::cout << "alpha_complex_from_points.num_vertices()=" << alpha_complex_from_points.num_vertices() << std::endl;
+ BOOST_CHECK(alpha_complex_from_points.num_vertices() == 4);
+
+ for (auto f_simplex : alpha_complex_from_points.filtration_simplex_range()) {
+ switch (alpha_complex_from_points.dimension(f_simplex)) {
+ case 0:
+ BOOST_CHECK(are_almost_the_same(alpha_complex_from_points.filtration(f_simplex), 0.0));
+ break;
+ case 1:
+ BOOST_CHECK(are_almost_the_same(alpha_complex_from_points.filtration(f_simplex), 1.0/2.0));
+ break;
+ default:
+ BOOST_CHECK(false); // Shall not happen
+ break;
+ }
+ }
+
}