summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-12-14 13:27:02 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-12-14 13:27:02 +0000
commitde2573cf2b2eb92cff628d9690a067b50b4ca145 (patch)
tree1b9ec11f5fcb1e4a2bd08ea48f7ea26fb3733f1e
parentd9895d13cecf61de78a1c812bfb80bbc2778e7a6 (diff)
Rollback pointer modification, and use of of a hack for no deep copy of boost graph
"voidification" of create_complex method git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/distance_matrix_in_rips_module@1868 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 3667c8f57388dec0300d1fed8bf1b063843727dd
-rw-r--r--src/Rips_complex/example/example_one_skeleton_rips_from_distance_matrix.cpp32
-rw-r--r--src/Rips_complex/example/example_one_skeleton_rips_from_points.cpp33
-rw-r--r--src/Rips_complex/example/example_rips_complex_from_csv_distance_matrix_file.cpp34
-rw-r--r--src/Rips_complex/example/example_rips_complex_from_off_file.cpp34
-rw-r--r--src/Rips_complex/include/gudhi/Rips_complex.h39
-rw-r--r--src/Rips_complex/test/test_rips_complex.cpp38
6 files changed, 112 insertions, 98 deletions
diff --git a/src/Rips_complex/example/example_one_skeleton_rips_from_distance_matrix.cpp b/src/Rips_complex/example/example_one_skeleton_rips_from_distance_matrix.cpp
index 02bffe0d..326ad52f 100644
--- a/src/Rips_complex/example/example_one_skeleton_rips_from_distance_matrix.cpp
+++ b/src/Rips_complex/example/example_one_skeleton_rips_from_distance_matrix.cpp
@@ -45,24 +45,24 @@ int main(int argc, char **argv) {
Rips_complex rips_complex_from_points(distances, threshold);
Simplex_tree stree;
- if (rips_complex_from_points.create_complex(stree, 1)) {
- // ----------------------------------------------------------------------------
- // Display information about the one skeleton rips complex
- // ----------------------------------------------------------------------------
- std::cout << "Rips complex is of dimension " << stree.dimension() <<
- " - " << stree.num_simplices() << " simplices - " <<
- stree.num_vertices() << " vertices." << std::endl;
+ rips_complex_from_points.create_complex(stree, 1);
+ // ----------------------------------------------------------------------------
+ // Display information about the one skeleton rips complex
+ // ----------------------------------------------------------------------------
+ std::cout << "Rips complex is of dimension " << stree.dimension() <<
+ " - " << stree.num_simplices() << " simplices - " <<
+ stree.num_vertices() << " vertices." << std::endl;
- std::cout << "Iterator on rips complex simplices in the filtration order, with [filtration value]:" <<
- std::endl;
- for (auto f_simplex : stree.filtration_simplex_range()) {
- std::cout << " ( ";
- for (auto vertex : stree.simplex_vertex_range(f_simplex)) {
- std::cout << vertex << " ";
- }
- std::cout << ") -> " << "[" << stree.filtration(f_simplex) << "] ";
- std::cout << std::endl;
+ std::cout << "Iterator on rips complex simplices in the filtration order, with [filtration value]:" <<
+ std::endl;
+ for (auto f_simplex : stree.filtration_simplex_range()) {
+ std::cout << " ( ";
+ for (auto vertex : stree.simplex_vertex_range(f_simplex)) {
+ std::cout << vertex << " ";
}
+ std::cout << ") -> " << "[" << stree.filtration(f_simplex) << "] ";
+ std::cout << std::endl;
}
+
return 0;
}
diff --git a/src/Rips_complex/example/example_one_skeleton_rips_from_points.cpp b/src/Rips_complex/example/example_one_skeleton_rips_from_points.cpp
index efbcd88e..6e8dee27 100644
--- a/src/Rips_complex/example/example_one_skeleton_rips_from_points.cpp
+++ b/src/Rips_complex/example/example_one_skeleton_rips_from_points.cpp
@@ -40,24 +40,23 @@ int main(int argc, char **argv) {
Rips_complex rips_complex_from_points(points, threshold, Euclidean_distance());
Simplex_tree stree;
- if (rips_complex_from_points.create_complex(stree, 1)) {
- // ----------------------------------------------------------------------------
- // Display information about the one skeleton rips complex
- // ----------------------------------------------------------------------------
- std::cout << "Rips complex is of dimension " << stree.dimension() <<
- " - " << stree.num_simplices() << " simplices - " <<
- stree.num_vertices() << " vertices." << std::endl;
-
- std::cout << "Iterator on rips complex simplices in the filtration order, with [filtration value]:" <<
- std::endl;
- for (auto f_simplex : stree.filtration_simplex_range()) {
- std::cout << " ( ";
- for (auto vertex : stree.simplex_vertex_range(f_simplex)) {
- std::cout << vertex << " ";
- }
- std::cout << ") -> " << "[" << stree.filtration(f_simplex) << "] ";
- std::cout << std::endl;
+ rips_complex_from_points.create_complex(stree, 1);
+ // ----------------------------------------------------------------------------
+ // Display information about the one skeleton rips complex
+ // ----------------------------------------------------------------------------
+ std::cout << "Rips complex is of dimension " << stree.dimension() <<
+ " - " << stree.num_simplices() << " simplices - " <<
+ stree.num_vertices() << " vertices." << std::endl;
+
+ std::cout << "Iterator on rips complex simplices in the filtration order, with [filtration value]:" <<
+ std::endl;
+ for (auto f_simplex : stree.filtration_simplex_range()) {
+ std::cout << " ( ";
+ for (auto vertex : stree.simplex_vertex_range(f_simplex)) {
+ std::cout << vertex << " ";
}
+ std::cout << ") -> " << "[" << stree.filtration(f_simplex) << "] ";
+ std::cout << std::endl;
}
return 0;
}
diff --git a/src/Rips_complex/example/example_rips_complex_from_csv_distance_matrix_file.cpp b/src/Rips_complex/example/example_rips_complex_from_csv_distance_matrix_file.cpp
index 7cdaffdf..cc6c3a33 100644
--- a/src/Rips_complex/example/example_rips_complex_from_csv_distance_matrix_file.cpp
+++ b/src/Rips_complex/example/example_rips_complex_from_csv_distance_matrix_file.cpp
@@ -46,27 +46,27 @@ int main(int argc, char **argv) {
}
Simplex_tree stree;
- if (rips_complex_from_file.create_complex(stree, dim_max)) {
- std::ostream output_stream(streambufffer);
+ rips_complex_from_file.create_complex(stree, dim_max);
+ std::ostream output_stream(streambufffer);
- // ----------------------------------------------------------------------------
- // Display information about the rips complex
- // ----------------------------------------------------------------------------
- output_stream << "Rips complex is of dimension " << stree.dimension() <<
- " - " << stree.num_simplices() << " simplices - " <<
- stree.num_vertices() << " vertices." << std::endl;
+ // ----------------------------------------------------------------------------
+ // Display information about the rips complex
+ // ----------------------------------------------------------------------------
+ output_stream << "Rips complex is of dimension " << stree.dimension() <<
+ " - " << stree.num_simplices() << " simplices - " <<
+ stree.num_vertices() << " vertices." << std::endl;
- output_stream << "Iterator on rips complex simplices in the filtration order, with [filtration value]:" <<
- std::endl;
- for (auto f_simplex : stree.filtration_simplex_range()) {
- output_stream << " ( ";
- for (auto vertex : stree.simplex_vertex_range(f_simplex)) {
- output_stream << vertex << " ";
- }
- output_stream << ") -> " << "[" << stree.filtration(f_simplex) << "] ";
- output_stream << std::endl;
+ output_stream << "Iterator on rips complex simplices in the filtration order, with [filtration value]:" <<
+ std::endl;
+ for (auto f_simplex : stree.filtration_simplex_range()) {
+ output_stream << " ( ";
+ for (auto vertex : stree.simplex_vertex_range(f_simplex)) {
+ output_stream << vertex << " ";
}
+ output_stream << ") -> " << "[" << stree.filtration(f_simplex) << "] ";
+ output_stream << std::endl;
}
+
ouput_file_stream.close();
return 0;
}
diff --git a/src/Rips_complex/example/example_rips_complex_from_off_file.cpp b/src/Rips_complex/example/example_rips_complex_from_off_file.cpp
index 8849d784..b6c961d0 100644
--- a/src/Rips_complex/example/example_rips_complex_from_off_file.cpp
+++ b/src/Rips_complex/example/example_rips_complex_from_off_file.cpp
@@ -45,27 +45,27 @@ int main(int argc, char **argv) {
}
Simplex_tree stree;
- if (rips_complex_from_file.create_complex(stree, dim_max)) {
- std::ostream output_stream(streambufffer);
+ rips_complex_from_file.create_complex(stree, dim_max);
+ std::ostream output_stream(streambufffer);
- // ----------------------------------------------------------------------------
- // Display information about the rips complex
- // ----------------------------------------------------------------------------
- output_stream << "Rips complex is of dimension " << stree.dimension() <<
- " - " << stree.num_simplices() << " simplices - " <<
- stree.num_vertices() << " vertices." << std::endl;
+ // ----------------------------------------------------------------------------
+ // Display information about the rips complex
+ // ----------------------------------------------------------------------------
+ output_stream << "Rips complex is of dimension " << stree.dimension() <<
+ " - " << stree.num_simplices() << " simplices - " <<
+ stree.num_vertices() << " vertices." << std::endl;
- output_stream << "Iterator on rips complex simplices in the filtration order, with [filtration value]:" <<
- std::endl;
- for (auto f_simplex : stree.filtration_simplex_range()) {
- output_stream << " ( ";
- for (auto vertex : stree.simplex_vertex_range(f_simplex)) {
- output_stream << vertex << " ";
- }
- output_stream << ") -> " << "[" << stree.filtration(f_simplex) << "] ";
- output_stream << std::endl;
+ output_stream << "Iterator on rips complex simplices in the filtration order, with [filtration value]:" <<
+ std::endl;
+ for (auto f_simplex : stree.filtration_simplex_range()) {
+ output_stream << " ( ";
+ for (auto vertex : stree.simplex_vertex_range(f_simplex)) {
+ output_stream << vertex << " ";
}
+ output_stream << ") -> " << "[" << stree.filtration(f_simplex) << "] ";
+ output_stream << std::endl;
}
+
ouput_file_stream.close();
return 0;
}
diff --git a/src/Rips_complex/include/gudhi/Rips_complex.h b/src/Rips_complex/include/gudhi/Rips_complex.h
index 5ac46071..1061de73 100644
--- a/src/Rips_complex/include/gudhi/Rips_complex.h
+++ b/src/Rips_complex/include/gudhi/Rips_complex.h
@@ -73,8 +73,7 @@ class Rips_complex {
* The type InputPointRange must be a range for which std::begin and std::end return input iterators on a point.
*/
template<typename InputPointRange, typename Distance >
- Rips_complex(const InputPointRange& points, Filtration_value threshold, Distance distance)
- : rips_skeleton_graph_(nullptr) {
+ Rips_complex(const InputPointRange& points, Filtration_value threshold, Distance distance) {
compute_proximity_graph<InputPointRange, Distance >(points, threshold, distance);
}
@@ -88,8 +87,7 @@ class Rips_complex {
* distance_matrix.size().\f$
*/
template<typename InputDistanceRange>
- Rips_complex(const InputDistanceRange& distance_matrix, Filtration_value threshold)
- : rips_skeleton_graph_(nullptr) {
+ Rips_complex(const InputDistanceRange& distance_matrix, Filtration_value threshold) {
compute_proximity_graph(boost::irange((size_t)0, distance_matrix.size()), threshold,
[&](size_t i, size_t j){return distance_matrix[j][i];});
}
@@ -101,28 +99,18 @@ class Rips_complex {
*
* @param[in] complex SimplicialComplexForRips to be created.
* @param[in] dim_max graph expansion for rips until this given maximal dimension.
- *
- * @return true if creation succeeds, false otherwise.
- *
+ * @exception std::invalid_argument In debug mode, if \code complex.num_vertices() \endcode does not return 0.
+ *
*/
template <typename SimplicialComplexForRips>
- bool create_complex(SimplicialComplexForRips& complex, int dim_max) {
- if (complex.num_vertices() > 0) {
- std::cerr << "Rips_complex create_complex - complex is not empty\n";
- return false; // ----- >>
- }
- if (rips_skeleton_graph_ == nullptr) {
- std::cerr << "Rips Skeleton Graph is not defined\n";
- return false; // ----- >>
- }
+ void create_complex(SimplicialComplexForRips& complex, int dim_max) {
+ GUDHI_CHECK(complex.num_vertices() == 0,
+ std::invalid_argument("Rips_complex::create_complex - simplicial complex is not empty"));
// insert the proximity graph in the simplicial complex
- complex.insert_graph(*rips_skeleton_graph_);
+ complex.insert_graph(rips_skeleton_graph_);
// expand the graph until dimension dim_max
complex.expansion(dim_max);
-
- // --------------------------------------------------------------------------------------------
- return true;
}
private:
@@ -161,20 +149,23 @@ class Rips_complex {
// --------------------------------------------------------------------------------------------
// Creates the proximity graph from edges and sets the property with the filtration value.
// Number of points is labeled from 0 to idx_u-1
- rips_skeleton_graph_ = new Graph_t(edges.begin(), edges.end(), edges_fil.begin(), idx_u);
+ // --------------------------------------------------------------------------------------------
+ // Do not use : rips_skeleton_graph_ = Graph_t(...) -> deep copy of the graph (boost graph is not move-enabled)
+ rips_skeleton_graph_.~Graph_t();
+ new(&rips_skeleton_graph_)Graph_t(edges.begin(), edges.end(), edges_fil.begin(), idx_u);
- auto vertex_prop = boost::get(vertex_filtration_t(), *rips_skeleton_graph_);
+ auto vertex_prop = boost::get(vertex_filtration_t(), rips_skeleton_graph_);
using vertex_iterator = typename boost::graph_traits<Graph_t>::vertex_iterator;
vertex_iterator vi, vi_end;
- for (std::tie(vi, vi_end) = boost::vertices(*rips_skeleton_graph_);
+ for (std::tie(vi, vi_end) = boost::vertices(rips_skeleton_graph_);
vi != vi_end; ++vi) {
boost::put(vertex_prop, *vi, 0.);
}
}
private:
- Graph_t* rips_skeleton_graph_;
+ Graph_t rips_skeleton_graph_;
};
} // namespace rips_complex
diff --git a/src/Rips_complex/test/test_rips_complex.cpp b/src/Rips_complex/test/test_rips_complex.cpp
index 7e0473d9..1bdd0512 100644
--- a/src/Rips_complex/test/test_rips_complex.cpp
+++ b/src/Rips_complex/test/test_rips_complex.cpp
@@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE(RIPS_DOC_OFF_file) {
const int DIMENSION_1 = 1;
Simplex_tree st;
- BOOST_CHECK(rips_complex_from_file.create_complex(st, DIMENSION_1));
+ rips_complex_from_file.create_complex(st, DIMENSION_1);
std::cout << "st.dimension()=" << st.dimension() << std::endl;
BOOST_CHECK(st.dimension() == DIMENSION_1);
@@ -98,7 +98,7 @@ BOOST_AUTO_TEST_CASE(RIPS_DOC_OFF_file) {
const int DIMENSION_2 = 2;
Simplex_tree st2;
- BOOST_CHECK(rips_complex_from_file.create_complex(st2, DIMENSION_2));
+ rips_complex_from_file.create_complex(st2, DIMENSION_2);
std::cout << "st2.dimension()=" << st2.dimension() << std::endl;
BOOST_CHECK(st2.dimension() == DIMENSION_2);
@@ -124,7 +124,7 @@ BOOST_AUTO_TEST_CASE(RIPS_DOC_OFF_file) {
const int DIMENSION_3 = 3;
Simplex_tree st3;
- BOOST_CHECK(rips_complex_from_file.create_complex(st3, DIMENSION_3));
+ rips_complex_from_file.create_complex(st3, DIMENSION_3);
std::cout << "st3.dimension()=" << st3.dimension() << std::endl;
BOOST_CHECK(st3.dimension() == DIMENSION_3);
@@ -192,7 +192,7 @@ BOOST_AUTO_TEST_CASE(Rips_complex_from_points) {
std::cout << "========== Rips_complex_from_points ==========" << std::endl;
Simplex_tree st;
const int DIMENSION = 3;
- BOOST_CHECK(rips_complex_from_points.create_complex(st, DIMENSION));
+ rips_complex_from_points.create_complex(st, DIMENSION);
// Another way to check num_simplices
std::cout << "Iterator on rips complex simplices in the filtration order, with [filtration value]:" << std::endl;
@@ -249,7 +249,7 @@ BOOST_AUTO_TEST_CASE(Rips_doc_csv_file) {
const int DIMENSION_1 = 1;
Simplex_tree st;
- BOOST_CHECK(rips_complex_from_file.create_complex(st, DIMENSION_1));
+ rips_complex_from_file.create_complex(st, DIMENSION_1);
std::cout << "st.dimension()=" << st.dimension() << std::endl;
BOOST_CHECK(st.dimension() == DIMENSION_1);
@@ -282,7 +282,7 @@ BOOST_AUTO_TEST_CASE(Rips_doc_csv_file) {
const int DIMENSION_2 = 2;
Simplex_tree st2;
- BOOST_CHECK(rips_complex_from_file.create_complex(st2, DIMENSION_2));
+ rips_complex_from_file.create_complex(st2, DIMENSION_2);
std::cout << "st2.dimension()=" << st2.dimension() << std::endl;
BOOST_CHECK(st2.dimension() == DIMENSION_2);
@@ -308,7 +308,7 @@ BOOST_AUTO_TEST_CASE(Rips_doc_csv_file) {
const int DIMENSION_3 = 3;
Simplex_tree st3;
- BOOST_CHECK(rips_complex_from_file.create_complex(st3, DIMENSION_3));
+ rips_complex_from_file.create_complex(st3, DIMENSION_3);
std::cout << "st3.dimension()=" << st3.dimension() << std::endl;
BOOST_CHECK(st3.dimension() == DIMENSION_3);
@@ -327,3 +327,27 @@ BOOST_AUTO_TEST_CASE(Rips_doc_csv_file) {
BOOST_CHECK(are_almost_the_same(f0123, std::max(f012, std::max(f123, std::max(f013, f023)))));
}
+
+#ifdef GUDHI_DEBUG
+BOOST_AUTO_TEST_CASE(Rips_create_complex_throw) {
+ // ----------------------------------------------------------------------------
+ //
+ // Init of a rips complex from a OFF file
+ //
+ // ----------------------------------------------------------------------------
+ std::string off_file_name("alphacomplexdoc.off");
+ double rips_threshold = 12.0;
+ std::cout << "========== OFF FILE NAME = " << off_file_name << " - rips threshold=" <<
+ rips_threshold << "==========" << std::endl;
+
+ Gudhi::Points_off_reader<Point> off_reader(off_file_name);
+ Rips_complex rips_complex_from_file(off_reader.get_point_cloud(), rips_threshold, Euclidean_distance());
+
+ Simplex_tree stree;
+ std::vector<int> simplex = {0, 1, 2};
+ stree.insert_simplex_and_subfaces(simplex);
+ std::cout << "Check exception throw in debug mode" << std::endl;
+ // throw excpt because stree is not empty
+ BOOST_CHECK_THROW (rips_complex_from_file.create_complex(stree, 1), std::invalid_argument);
+}
+#endif