summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-11-23 11:49:15 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-11-23 11:49:15 +0000
commitf843ef3f8e4ab4ce94a28ded6d8cafd37f2b2311 (patch)
tree7d053afbeb51a16916da07f932deecc364c7eb42 /src
parent8d656e33138ef8b3a7d86a7375c92646efc29511 (diff)
Add tangential complex
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST_cythonize@1773 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b47285aafaa430c883c8fe5432ac667d6cedaf37
Diffstat (limited to 'src')
-rw-r--r--src/cython/CMakeLists.txt10
-rw-r--r--src/cython/cython/alpha_complex.pyx2
-rw-r--r--src/cython/cython/tangential_complex.pyx363
-rw-r--r--src/cython/cythonize_gudhi.py.in4
-rw-r--r--src/cython/doc/alpha_complex_sum.rst2
-rw-r--r--src/cython/doc/persistence_graphical_tools_ref.rst8
-rw-r--r--src/cython/doc/persistence_graphical_tools_sum.rst4
-rw-r--r--src/cython/gudhi.pyx.in5
-rw-r--r--src/cython/include/Tangential_complex_interface.h220
9 files changed, 602 insertions, 16 deletions
diff --git a/src/cython/CMakeLists.txt b/src/cython/CMakeLists.txt
index 81fbe8fe..09ebb678 100644
--- a/src/cython/CMakeLists.txt
+++ b/src/cython/CMakeLists.txt
@@ -45,8 +45,8 @@ if(PYTHON_PATH AND CYTHON_PATH)
file(COPY test DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
if (CGAL_FOUND)
- if (NOT CGAL_VERSION VERSION_LESS 4.7.0)
- # If CGAL_VERSION >= 4.7.0, include alpha complex
+ if (NOT CGAL_VERSION VERSION_LESS 4.8.0)
+ # If CGAL_VERSION >= 4.8.0, include alpha complex
set(GUDHI_CYTHON_LIBRARIES "${GUDHI_CYTHON_LIBRARIES}'CGAL', ")
set(GUDHI_CYTHON_LIBRARY_DIRS "${GUDHI_CYTHON_LIBRARY_DIRS}'${CGAL_LIBRARIES_DIR}', ")
# GMP and GMPXX are not required, but if present, CGAL will link with them.
@@ -62,10 +62,12 @@ if(PYTHON_PATH AND CYTHON_PATH)
endif(GMP_FOUND)
set(GUDHI_CYTHON_ALPHA_COMPLEX "include 'cython/alpha_complex.pyx'")
- else (NOT CGAL_VERSION VERSION_LESS 4.7.0)
+ set(GUDHI_CYTHON_TANGENTIAL_COMPLEX "include 'cython/tangential_complex.pyx'")
+ else (NOT CGAL_VERSION VERSION_LESS 4.8.0)
# Remove alpha complex unitary tests
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/test/test_alpha_complex.py)
- endif (NOT CGAL_VERSION VERSION_LESS 4.7.0)
+ file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/test/test_tangential_complex.py)
+ endif (NOT CGAL_VERSION VERSION_LESS 4.8.0)
endif (CGAL_FOUND)
# Loop on INCLUDE_DIRECTORIES PROPERTY
diff --git a/src/cython/cython/alpha_complex.pyx b/src/cython/cython/alpha_complex.pyx
index af609863..85771300 100644
--- a/src/cython/cython/alpha_complex.pyx
+++ b/src/cython/cython/alpha_complex.pyx
@@ -32,7 +32,7 @@ __copyright__ = "Copyright (C) 2016 INRIA"
__license__ = "GPL v3"
cdef extern from "Alpha_complex_interface.h" namespace "Gudhi":
- cdef cppclass Alpha_complex_interface "Gudhi::alphacomplex::Alpha_complex_interface":
+ cdef cppclass Alpha_complex_interface "Gudhi::alpha_complex::Alpha_complex_interface":
Alpha_complex_interface(vector[vector[double]] points, double max_alpha_square)
# bool from_file is a workaround for cython to find the correct signature
Alpha_complex_interface(string off_file, double max_alpha_square, bool from_file)
diff --git a/src/cython/cython/tangential_complex.pyx b/src/cython/cython/tangential_complex.pyx
new file mode 100644
index 00000000..01782004
--- /dev/null
+++ b/src/cython/cython/tangential_complex.pyx
@@ -0,0 +1,363 @@
+from cython cimport numeric
+from libcpp.vector cimport vector
+from libcpp.utility cimport pair
+from libcpp.string cimport string
+from libcpp cimport bool
+import os
+
+"""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): Vincent Rouvreau
+
+ Copyright (C) 2016 INRIA
+
+ 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/>.
+"""
+
+__author__ = "Vincent Rouvreau"
+__copyright__ = "Copyright (C) 2016 INRIA"
+__license__ = "GPL v3"
+
+cdef extern from "Tangential_complex_interface.h" namespace "Gudhi":
+ cdef cppclass Tangential_complex_interface "Gudhi::tangential_complex::Tangential_complex_interface":
+ Tangential_complex_interface(vector[vector[double]] points, double max_alpha_square)
+ # bool from_file is a workaround for cython to find the correct signature
+ Tangential_complex_interface(string off_file, double max_alpha_square, bool from_file)
+ double filtration()
+ double simplex_filtration(vector[int] simplex)
+ void set_filtration(double filtration)
+ void initialize_filtration()
+ int num_vertices()
+ int num_simplices()
+ void set_dimension(int dimension)
+ int dimension()
+ bint find_simplex(vector[int] simplex)
+ bint insert_simplex_and_subfaces(vector[int] simplex,
+ double filtration)
+ vector[pair[vector[int], double]] get_filtered_tree()
+ vector[pair[vector[int], double]] get_skeleton_tree(int dimension)
+ vector[pair[vector[int], double]] get_star_tree(vector[int] simplex)
+ vector[pair[vector[int], double]] get_coface_tree(vector[int] simplex,
+ int dimension)
+ void remove_maximal_simplex(vector[int] simplex)
+ vector[double] get_point(int vertex)
+ vector[pair[int, pair[double, double]]] get_persistence(int homology_coeff_field, double min_persistence)
+ vector[int] get_betti_numbers()
+ vector[int] get_persistent_betti_numbers(double from_value, double to_value)
+
+# TangentialComplex python interface
+cdef class TangentialComplex:
+ """TangentialComplex is a simplicial complex constructed from the finite cells
+ of a Delaunay Triangulation.
+
+ The filtration value of each simplex is computed as the square of the
+ circumradius of the simplex if the circumsphere is empty (the simplex is
+ then said to be Gabriel), and as the minimum of the filtration values of
+ the codimension 1 cofaces that make it not Gabriel otherwise.
+
+ All simplices that have a filtration value strictly greater than a given
+ alpha squared value are not inserted into the complex.
+
+ .. note::
+
+ When Tangential_complex is constructed with an infinite value of alpha, the
+ complex is a Delaunay complex.
+
+ """
+
+ cdef Tangential_complex_interface * thisptr
+
+ # Fake constructor that does nothing but documenting the constructor
+ def __init__(self, points=None, off_file='', max_alpha_square=float('inf')):
+ """TangentialComplex constructor.
+
+ :param points: A list of points in d-Dimension.
+ :type points: list of list of double
+
+ Or
+
+ :param off_file: An OFF file style name.
+ :type off_file: string
+
+ :param max_alpha_square: Maximum Tangential square value. Default is :math:`\infty`
+ :type max_alpha_square: double
+ """
+
+ # The real cython constructor
+ def __cinit__(self, points=[], off_file='', max_alpha_square=float('inf')):
+ if off_file is not '':
+ if os.path.isfile(off_file):
+ self.thisptr = new Tangential_complex_interface(off_file,
+ max_alpha_square, True)
+ else:
+ print("file " + off_file + " not found.")
+ else:
+ self.thisptr = new Tangential_complex_interface(points,
+ max_alpha_square)
+
+
+ def __dealloc__(self):
+ if self.thisptr != NULL:
+ del self.thisptr
+
+ def __is_defined(self):
+ """Returns true if TangentialComplex pointer is not NULL.
+ """
+ return self.thisptr != NULL
+
+ def get_filtration(self):
+ """This function returns the main simplicial complex filtration value.
+
+ :returns: float -- the simplicial complex filtration value.
+ """
+ return self.thisptr.filtration()
+
+ def filtration(self, simplex):
+ """This function returns the simplicial complex filtration value for a
+ given N-simplex.
+
+ :param simplex: The N-simplex, represented by a list of vertex.
+ :type simplex: list of int
+ :returns: float -- the simplicial complex filtration value.
+ """
+ return self.thisptr.simplex_filtration(simplex)
+
+ def set_filtration(self, filtration):
+ """This function sets the main simplicial complex filtration value.
+
+ :param filtration: The filtration value.
+ :type filtration: float.
+ """
+ self.thisptr.set_filtration(<double> filtration)
+
+ def initialize_filtration(self):
+ """This function initializes and sorts the simplicial complex
+ filtration vector.
+
+ .. note::
+
+ This function must be launched before persistence, betti_numbers,
+ persistent_betti_numbers or get_filtered_tree after inserting or
+ removing simplices.
+ """
+ self.thisptr.initialize_filtration()
+
+ def num_vertices(self):
+ """This function returns the number of vertices of the simplicial
+ complex.
+
+ :returns: int -- the simplicial complex number of vertices.
+ """
+ return self.thisptr.num_vertices()
+
+ def num_simplices(self):
+ """This function returns the number of simplices of the simplicial
+ complex.
+
+ :returns: int -- the simplicial complex number of simplices.
+ """
+ return self.thisptr.num_simplices()
+
+ def dimension(self):
+ """This function returns the dimension of the simplicial complex.
+
+ :returns: int -- the simplicial complex dimension.
+ """
+ return self.thisptr.dimension()
+
+ def set_dimension(self, dimension):
+ """This function sets the dimension of the simplicial complex.
+
+ :param dimension: The new dimension value.
+ :type dimension: int.
+ """
+ self.thisptr.set_dimension(<int>dimension)
+
+ def find(self, simplex):
+ """This function returns if the N-simplex was found in the simplicial
+ complex or not.
+
+ :param simplex: The N-simplex to find, represented by a list of vertex.
+ :type simplex: list of int.
+ :returns: bool -- true if the simplex was found, false otherwise.
+ """
+ cdef vector[int] complex
+ for i in simplex:
+ complex.push_back(i)
+ return self.thisptr.find_simplex(complex)
+
+ def insert(self, simplex, filtration=0.0):
+ """This function inserts the given N-simplex with the given filtration
+ value (default value is '0.0').
+
+ :param simplex: The N-simplex to insert, represented by a list of
+ vertex.
+ :type simplex: list of int.
+ :param filtration: The filtration value of the simplex.
+ :type filtration: float.
+ :returns: bool -- true if the simplex was found, false otherwise.
+ """
+ cdef vector[int] complex
+ for i in simplex:
+ complex.push_back(i)
+ return self.thisptr.insert_simplex_and_subfaces(complex,
+ <double>filtration)
+
+ def get_filtered_tree(self):
+ """This function returns the tree sorted by increasing filtration
+ values.
+
+ :returns: list of tuples(simplex, filtration) -- the tree sorted by
+ increasing filtration values.
+ """
+ cdef vector[pair[vector[int], double]] coface_tree \
+ = self.thisptr.get_filtered_tree()
+ ct = []
+ for filtered_complex in coface_tree:
+ v = []
+ for vertex in filtered_complex.first:
+ v.append(vertex)
+ ct.append((v, filtered_complex.second))
+ return ct
+
+ def get_skeleton_tree(self, dimension):
+ """This function returns the tree skeleton of a maximum given
+ dimension.
+
+ :param dimension: The skeleton dimension value.
+ :type dimension: int.
+ :returns: list of tuples(simplex, filtration) -- the skeleton tree
+ of a maximum dimension.
+ """
+ cdef vector[pair[vector[int], double]] coface_tree \
+ = self.thisptr.get_skeleton_tree(<int>dimension)
+ ct = []
+ for filtered_complex in coface_tree:
+ v = []
+ for vertex in filtered_complex.first:
+ v.append(vertex)
+ ct.append((v, filtered_complex.second))
+ return ct
+
+ def get_star_tree(self, simplex):
+ """This function returns the star tree of a given N-simplex.
+
+ :param simplex: The N-simplex, represented by a list of vertex.
+ :type simplex: list of int.
+ :returns: list of tuples(simplex, filtration) -- the star tree of a
+ simplex.
+ """
+ cdef vector[int] complex
+ for i in simplex:
+ complex.push_back(i)
+ cdef vector[pair[vector[int], double]] coface_tree \
+ = self.thisptr.get_star_tree(complex)
+ ct = []
+ for filtered_complex in coface_tree:
+ v = []
+ for vertex in filtered_complex.first:
+ v.append(vertex)
+ ct.append((v, filtered_complex.second))
+ return ct
+
+ def get_coface_tree(self, simplex, codimension):
+ """This function returns the coface tree of a given N-simplex with a
+ given codimension.
+
+ :param simplex: The N-simplex, represented by a list of vertex.
+ :type simplex: list of int.
+ :param codimension: The codimension. If codimension = 0, all cofaces
+ are returned (equivalent of get_star_tree function)
+ :type codimension: int.
+ :returns: list of tuples(simplex, filtration) -- the coface tree of a
+ simplex.
+ """
+ cdef vector[int] complex
+ for i in simplex:
+ complex.push_back(i)
+ cdef vector[pair[vector[int], double]] coface_tree \
+ = self.thisptr.get_coface_tree(complex, <int>codimension)
+ ct = []
+ for filtered_complex in coface_tree:
+ v = []
+ for vertex in filtered_complex.first:
+ v.append(vertex)
+ ct.append((v, filtered_complex.second))
+ return ct
+
+ def remove_maximal_simplex(self, simplex):
+ """This function removes a given maximal N-simplex from the simplicial
+ complex.
+
+ :param simplex: The N-simplex, represented by a list of vertex.
+ :type simplex: list of int.
+ """
+ self.thisptr.remove_maximal_simplex(simplex)
+
+ def get_point(self, vertex):
+ """This function returns the point corresponding to a given vertex.
+
+ :param vertex: The vertex.
+ :type vertex: int.
+ :returns: list of float -- the point.
+ """
+ cdef vector[double] point = self.thisptr.get_point(vertex)
+ return point
+
+ def persistence(self, homology_coeff_field=11, min_persistence=0.0):
+ """This function returns the persistence of the simplicial complex.
+
+ :param homology_coeff_field: The homology coefficient field. Must be a
+ prime number
+ :type homology_coeff_field: int.
+ :param min_persistence: The minimum persistence value to take into
+ account (strictly greater than min_persistence). Default value is
+ 0.0.
+ Sets min_persistence to -1.0 to see all values.
+ :type min_persistence: float.
+ :note: list of pairs(dimension, pair(birth, death)) -- the
+ persistence of the simplicial complex.
+ """
+ return self.thisptr.get_persistence(homology_coeff_field, min_persistence)
+
+ def betti_numbers(self):
+ """This function returns the Betti numbers of the simplicial complex.
+
+ :returns: list of int -- The Betti numbers ([B0, B1, ..., Bn]).
+
+ :note: betti_numbers function requires persistence function to be
+ launched first.
+ """
+ return self.thisptr.get_betti_numbers()
+
+ def persistent_betti_numbers(self, from_value, to_value):
+ """This function returns the persistent Betti numbers of the
+ simplicial complex.
+
+ :param from_value: The persistence birth limit to be added in the
+ numbers (persistent birth <= from_value).
+ :type from_value: float.
+ :param to_value: The persistence death limit to be added in the
+ numbers (persistent death > to_value).
+ :type to_value: float.
+
+ :returns: list of int -- The persistent Betti numbers ([B0, B1, ...,
+ Bn]).
+
+ :note: persistent_betti_numbers function requires persistence
+ function to be launched first.
+ """
+ return self.thisptr.get_persistent_betti_numbers(from_value, to_value)
diff --git a/src/cython/cythonize_gudhi.py.in b/src/cython/cythonize_gudhi.py.in
index fb9a381e..46d19c2d 100644
--- a/src/cython/cythonize_gudhi.py.in
+++ b/src/cython/cythonize_gudhi.py.in
@@ -7,7 +7,7 @@ from Cython.Build import cythonize
Author(s): Vincent Rouvreau
- Copyright (C) 2016 INRIA Saclay (France)
+ Copyright (C) 2016 INRIA
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
@@ -24,7 +24,7 @@ from Cython.Build import cythonize
"""
__author__ = "Vincent Rouvreau"
-__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)"
+__copyright__ = "Copyright (C) 2016 INRIA"
__license__ = "GPL v3"
gudhi = Extension(
diff --git a/src/cython/doc/alpha_complex_sum.rst b/src/cython/doc/alpha_complex_sum.rst
index b3689556..af6c087f 100644
--- a/src/cython/doc/alpha_complex_sum.rst
+++ b/src/cython/doc/alpha_complex_sum.rst
@@ -1,7 +1,7 @@
===================================== ===================================== =====================================
:Author: Vincent Rouvreau :Introduced in: GUDHI 1.3.0 :Copyright: GPL v3
===================================== ===================================== =====================================
-:Requires: CGAL &ge 4.7.0 Eigen3
+:Requires: CGAL &ge; 4.7.0 Eigen3
===================================== ===================================== =====================================
+-------------------------------------------+----------------------------------------------------------------------+
diff --git a/src/cython/doc/persistence_graphical_tools_ref.rst b/src/cython/doc/persistence_graphical_tools_ref.rst
index aa214edf..a12021c4 100644
--- a/src/cython/doc/persistence_graphical_tools_ref.rst
+++ b/src/cython/doc/persistence_graphical_tools_ref.rst
@@ -2,7 +2,7 @@
Persistence graphical tools reference manual
============================================
-.. automethod:: gudhi.__min_birth_max_death
-.. automethod:: gudhi.show_palette_values
-.. automethod:: gudhi.barcode_persistence
-.. automethod:: gudhi.diagram_persistence \ No newline at end of file
+.. autofunction:: gudhi.__min_birth_max_death
+.. autofunction:: gudhi.show_palette_values
+.. autofunction:: gudhi.barcode_persistence
+.. autofunction:: gudhi.diagram_persistence
diff --git a/src/cython/doc/persistence_graphical_tools_sum.rst b/src/cython/doc/persistence_graphical_tools_sum.rst
index a6260032..a4ee4398 100644
--- a/src/cython/doc/persistence_graphical_tools_sum.rst
+++ b/src/cython/doc/persistence_graphical_tools_sum.rst
@@ -1,7 +1,7 @@
===================================== ===================================== =====================================
:Author: Vincent Rouvreau :Introduced in: GUDHI 1.4.0 :Copyright: GPL v3
===================================== ===================================== =====================================
-:Requires: Matplotlib Numpy
+:Requires: Matplotlib Numpy
===================================== ===================================== =====================================
+---------------------------------------------+----------------------------------------------------------------------+
@@ -9,5 +9,5 @@
| img/graphical_tools_representation.png | the user to build easily barcode and persistence diagram. |
| | |
+---------------------------------------------+----------------------------------------------------------------------+
-| :doc:`persistence_graphical_tools_user` | * :doc:`persistence_graphical_tools_ref` |
+| :doc:`persistence_graphical_tools_user` | :doc:`persistence_graphical_tools_ref` |
+---------------------------------------------+----------------------------------------------------------------------+
diff --git a/src/cython/gudhi.pyx.in b/src/cython/gudhi.pyx.in
index 1b8a669b..09d765b6 100644
--- a/src/cython/gudhi.pyx.in
+++ b/src/cython/gudhi.pyx.in
@@ -4,7 +4,7 @@
Author(s): Vincent Rouvreau
- Copyright (C) 2016 INRIA Saclay (France)
+ Copyright (C) 2016 INRIA
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
@@ -21,7 +21,7 @@
"""
__author__ = "Vincent Rouvreau"
-__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)"
+__copyright__ = "Copyright (C) 2016 INRIA"
__license__ = "GPL v3"
include "cython/simplex_tree.pyx"
@@ -32,3 +32,4 @@ include "cython/periodic_cubical_complex.pyx"
include "cython/persistence_graphical_tools.py"
include "cython/witness_complex.pyx"
@GUDHI_CYTHON_ALPHA_COMPLEX@
+@GUDHI_CYTHON_TANGENTIAL_COMPLEX@
diff --git a/src/cython/include/Tangential_complex_interface.h b/src/cython/include/Tangential_complex_interface.h
new file mode 100644
index 00000000..645aad72
--- /dev/null
+++ b/src/cython/include/Tangential_complex_interface.h
@@ -0,0 +1,220 @@
+/* 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): Vincent Rouvreau
+ *
+ * Copyright (C) 2016 INRIA
+ *
+ * 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/>.
+ */
+
+#ifndef TANGENTIAL_COMPLEX_INTERFACE_H
+#define TANGENTIAL_COMPLEX_INTERFACE_H
+
+#include <gudhi/Simplex_tree.h>
+#include <gudhi/Tangential_complex.h>
+#include <gudhi/Points_off_io.h>
+#include <CGAL/Epick_d.h>
+
+#include "Persistent_cohomology_interface.h"
+
+#include <vector>
+#include <utility> // std::pair
+#include <iostream>
+
+namespace Gudhi {
+
+namespace tangential_complex {
+
+class Tangential_complex_interface {
+ using Dynamic_kernel = CGAL::Epick_d< CGAL::Dynamic_dimension_tag >;
+ using Point_d = Dynamic_kernel::Point_d;
+ typedef typename Simplex_tree<>::Simplex_handle Simplex_handle;
+ typedef typename std::pair<Simplex_handle, bool> Insertion_result;
+ using Simplex = std::vector<Vertex_handle>;
+ using Filtered_complex = std::pair<Simplex, Filtration_value>;
+ using Complex_tree = std::vector<Filtered_complex>;
+ using TC = Tangential_complex<Dynamic_kernel, CGAL::Dynamic_dimension_tag, CGAL::Parallel_tag>;
+
+ public:
+ Tangential_complex_interface(std::vector<std::vector<double>>&points, double max_alpha_square)
+ : pcoh_(nullptr) {
+ Dynamic_kernel k;
+ unsigned intrisic_dim = 0;
+ if (points.size() > 0)
+ intrisic_dim = points[0].size();
+
+ tangential_complex_ = new TC(points, intrisic_dim, k);
+ tangential_complex_->create_complex(simplex_tree_, max_alpha_square);
+ simplex_tree_.initialize_filtration();
+ }
+
+ Tangential_complex_interface(std::string off_file_name, double max_alpha_square, bool from_file = true)
+ : pcoh_(nullptr) {
+ Gudhi::Points_off_reader<Point_d> off_reader(off_file_name);
+ Dynamic_kernel k;
+ unsigned intrisic_dim = 0;
+ std::vector<Point_d> points = off_reader.get_point_cloud();
+ if (points.size() > 0)
+ intrisic_dim = points[0].size();
+
+ tangential_complex_ = new TC(points, intrisic_dim, k);
+ tangential_complex_->create_complex(simplex_tree_, max_alpha_square);
+ simplex_tree_.initialize_filtration();
+ }
+
+ bool find_simplex(const Simplex& vh) {
+ return (simplex_tree_.find(vh) != simplex_tree_.null_simplex());
+ }
+
+ bool insert_simplex_and_subfaces(const Simplex& complex, Filtration_value filtration = 0) {
+ Insertion_result result = simplex_tree_.insert_simplex_and_subfaces(complex, filtration);
+ return (result.second);
+ }
+
+ Filtration_value simplex_filtration(const Simplex& complex) {
+ return simplex_tree_.filtration(simplex_tree_.find(complex));
+ }
+
+ void remove_maximal_simplex(const Simplex& complex) {
+ return simplex_tree_.remove_maximal_simplex(simplex_tree_.find(complex));
+ }
+
+ Complex_tree get_filtered_tree() {
+ Complex_tree filtered_tree;
+ for (auto f_simplex : simplex_tree_.filtration_simplex_range()) {
+ Simplex simplex;
+ for (auto vertex : simplex_tree_.simplex_vertex_range(f_simplex)) {
+ simplex.insert(simplex.begin(), vertex);
+ }
+ filtered_tree.push_back(std::make_pair(simplex, simplex_tree_.filtration(f_simplex)));
+ }
+ return filtered_tree;
+
+ }
+
+ Complex_tree get_skeleton_tree(int dimension) {
+ Complex_tree skeleton_tree;
+ for (auto f_simplex : simplex_tree_.skeleton_simplex_range(dimension)) {
+ Simplex simplex;
+ for (auto vertex : simplex_tree_.simplex_vertex_range(f_simplex)) {
+ simplex.insert(simplex.begin(), vertex);
+ }
+ skeleton_tree.push_back(std::make_pair(simplex, simplex_tree_.filtration(f_simplex)));
+ }
+ return skeleton_tree;
+ }
+
+ Complex_tree get_star_tree(const Simplex& complex) {
+ Complex_tree star_tree;
+ for (auto f_simplex : simplex_tree_.star_simplex_range(simplex_tree_.find(complex))) {
+ Simplex simplex;
+ for (auto vertex : simplex_tree_.simplex_vertex_range(f_simplex)) {
+ simplex.insert(simplex.begin(), vertex);
+ }
+ star_tree.push_back(std::make_pair(simplex, simplex_tree_.filtration(f_simplex)));
+ }
+ return star_tree;
+ }
+
+ Complex_tree get_coface_tree(const Simplex& complex, int dimension) {
+ Complex_tree coface_tree;
+ for (auto f_simplex : simplex_tree_.cofaces_simplex_range(simplex_tree_.find(complex), dimension)) {
+ Simplex simplex;
+ for (auto vertex : simplex_tree_.simplex_vertex_range(f_simplex)) {
+ simplex.insert(simplex.begin(), vertex);
+ }
+ coface_tree.push_back(std::make_pair(simplex, simplex_tree_.filtration(f_simplex)));
+ }
+ return coface_tree;
+ }
+
+ // Specific to Witness complex because no inheritance
+ Filtration_value filtration() const {
+ return simplex_tree_.filtration();
+ }
+
+ void set_filtration(Filtration_value fil) {
+ simplex_tree_.set_filtration(fil);
+ }
+
+ void initialize_filtration() {
+ simplex_tree_.initialize_filtration();
+ }
+
+ size_t num_vertices() const {
+ return simplex_tree_.num_vertices();
+ }
+
+ size_t num_simplices() {
+ return simplex_tree_.num_simplices();
+ }
+
+ int dimension() const {
+ return simplex_tree_.dimension();
+ }
+
+ void set_dimension(int dimension) {
+ simplex_tree_.set_dimension(dimension);
+ }
+
+ std::vector<double> get_point(int vh) {
+ std::vector<double> vd;
+ try {
+ Point_d ph = tangential_complex_->get_point(vh);
+ for (auto coord = ph.cartesian_begin(); coord < ph.cartesian_end(); coord++)
+ vd.push_back(*coord);
+ } catch (std::out_of_range outofrange) {
+ // std::out_of_range is thrown in case not found. Other exceptions must be re-thrown
+ }
+ return vd;
+ }
+
+ std::vector<std::pair<int, std::pair<double, double>>> get_persistence(int homology_coeff_field, double min_persistence) {
+ if (pcoh_ != nullptr) {
+ delete pcoh_;
+ }
+ pcoh_ = new Persistent_cohomology_interface<Simplex_tree<>>(&simplex_tree_);
+ return pcoh_->get_persistence(homology_coeff_field, min_persistence);
+ }
+
+ std::vector<int> get_betti_numbers() const {
+ if (pcoh_ != nullptr) {
+ return pcoh_->betti_numbers();
+ }
+ std::vector<int> betti_numbers;
+ return betti_numbers;
+ }
+
+ std::vector<int> get_persistent_betti_numbers(Filtration_value from, Filtration_value to) const {
+ if (pcoh_ != nullptr) {
+ return pcoh_->persistent_betti_numbers(from, to);
+ }
+ std::vector<int> persistent_betti_numbers;
+ return persistent_betti_numbers;
+ }
+
+ private:
+ Simplex_tree<> simplex_tree_;
+ Persistent_cohomology_interface<Simplex_tree<>>* pcoh_;
+ TC* tangential_complex_;
+};
+
+} // namespace tangential_complex
+
+} // namespace Gudhi
+
+#endif // TANGENTIAL_COMPLEX_INTERFACE_H
+