summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorglisse <glisse@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-08-22 08:51:16 +0000
committerglisse <glisse@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-08-22 08:51:16 +0000
commit2fb35dc2204d97b512951cf4b4432cf20df28ee3 (patch)
tree6f3863438db351f15e475e9c3d72abf0d85652b3
parent05a215d2d8fed0961daf0b48e9e63973a12b9315 (diff)
Add an example showing how to use different options for Simplex_tree.
It has a few FIXMEs for things that are already in progress elsewhere and should be fixed before the release. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST-options@750 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: dda65a6af3112dc14843d764881c22a04ff4b90e
-rw-r--r--src/Simplex_tree/example/CMakeLists.txt9
-rw-r--r--src/Simplex_tree/example/mini_simplex_tree.cpp71
2 files changed, 77 insertions, 3 deletions
diff --git a/src/Simplex_tree/example/CMakeLists.txt b/src/Simplex_tree/example/CMakeLists.txt
index 1a3cdfbf..2f924490 100644
--- a/src/Simplex_tree/example/CMakeLists.txt
+++ b/src/Simplex_tree/example/CMakeLists.txt
@@ -7,15 +7,18 @@ add_test(simplex_tree_from_file_3 ${CMAKE_CURRENT_BINARY_DIR}/simplex_tree_from_
add_executable ( simple_simplex_tree simple_simplex_tree.cpp )
add_test(simple_simplex_tree ${CMAKE_CURRENT_BINARY_DIR}/simple_simplex_tree)
-
+
+add_executable ( mini_simplex_tree mini_simplex_tree.cpp )
+add_test(mini_simplex_tree ${CMAKE_CURRENT_BINARY_DIR}/mini_simplex_tree)
+
# An example with Simplex-tree using CGAL alpha_shapes_3
if(GMP_FOUND AND CGAL_FOUND)
message("CGAL_lib = ${CGAL_LIBRARIES_DIR}")
- message("GMP_LIBRARIES = ${GMP_LIBRARIES}")
+ message("GMP_LIBRARIES = ${GMP_LIBRARIES}")
INCLUDE_DIRECTORIES(${GMP_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${CGAL_INCLUDE_DIRS})
add_executable ( simplex_tree_from_alpha_shapes_3 simplex_tree_from_alpha_shapes_3.cpp )
target_link_libraries(simplex_tree_from_alpha_shapes_3 ${GMP_LIBRARIES} ${CGAL_LIBRARY})
add_test(simplex_tree_from_alpha_shapes_3 ${CMAKE_CURRENT_BINARY_DIR}/simplex_tree_from_alpha_shapes_3 ${CMAKE_SOURCE_DIR}/data/points/bunny_5000)
-endif()
+endif()
diff --git a/src/Simplex_tree/example/mini_simplex_tree.cpp b/src/Simplex_tree/example/mini_simplex_tree.cpp
new file mode 100644
index 00000000..a7e4c27d
--- /dev/null
+++ b/src/Simplex_tree/example/mini_simplex_tree.cpp
@@ -0,0 +1,71 @@
+/* This file is part of the Gudhi Library. The Gudhi library
+ * (Geometric Understanding in Higher Dimensions) is a generic C++
+ * library for computational topology.
+ *
+ * Author(s): Marc Glisse
+ *
+ * Copyright (C) 2015 INRIA Saclay - Ile-de-France (France)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// FIXME: remove the first include
+#include <gudhi/graph_simplicial_complex.h>
+#include <gudhi/Simplex_tree.h>
+#include <iostream>
+#include <initializer_list>
+
+using namespace Gudhi;
+
+struct MyOptions : Simplex_tree_options_full_featured {
+ // Not doing persistence, so we don't need those
+ static constexpr bool store_key = false;
+ static constexpr bool store_filtration = false;
+ // I have few vertices
+ typedef short Vertex_handle;
+};
+typedef Simplex_tree<MyOptions> ST;
+
+// Dictionary should be private, but for now this is the easiest way.
+static_assert(sizeof(ST::Dictionary::value_type) < sizeof(Simplex_tree<>::Dictionary::value_type),
+ "Not storing the filtration and key should save some space");
+
+int main() {
+ ST st;
+
+ /* Complex to build. */
+ /* 1 */
+ /* o */
+ /* /X\ */
+ /* o---o---o */
+ /* 2 0 3 */
+
+ // FIXME: Replace std::vector<short> with auto
+ std::vector<short> triangle012 = {0, 1, 2};
+ std::vector<short> edge03 = {0, 3};
+ st.insert_simplex_and_subfaces(triangle012);
+ st.insert_simplex_and_subfaces(edge03);
+ // FIXME: Remove this line
+ st.set_dimension(2);
+
+ std::vector<short> edge02 = {0, 2};
+ ST::Simplex_handle e = st.find(edge02);
+ assert(st.filtration(e) == 0); // We are not using filtrations so everything has value 0
+ for(ST::Simplex_handle t : st.cofaces_simplex_range(e, 1)) // Only coface is 012
+ {
+ for(ST::Vertex_handle v : st.simplex_vertex_range(t)) // v in { 0, 1, 2 }
+ std::cout << v;
+ std::cout << '\n';
+ }
+}