summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2017-03-14 22:08:43 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2017-03-14 22:08:43 +0000
commitaf46c40bec8ae03cdf5a1e5a37ede198f910e3ea (patch)
treebba1a850972fbff632efd35d2e650f02846689bc /src
parent6d66260b62aa5c780e3ac2f0f191992aca016e24 (diff)
Add Windows and CGAL_HEADER_ONLY cythonization support
Add OFF reader interfaces (required by Euclidean witness complex) Add Euclidean_witness_complex git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST_cythonize@2186 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 4d780f05c3409bea47a81e4377dbaf509b9e718c
Diffstat (limited to 'src')
-rw-r--r--src/cython/CMakeLists.txt52
-rw-r--r--src/cython/cython/euclidean_witness_complex.pyx84
-rw-r--r--src/cython/cython/off_reader.pyx49
-rwxr-xr-xsrc/cython/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py78
-rwxr-xr-xsrc/cython/example/witness_complex_from_file_example.py56
-rw-r--r--src/cython/gudhi.pyx.in2
-rw-r--r--src/cython/include/Euclidean_witness_complex_interface.h113
-rw-r--r--src/cython/include/Off_reader_interface.h42
-rw-r--r--src/cython/include/Strong_witness_complex_interface.h2
-rw-r--r--src/cython/include/Witness_complex_interface.h2
-rwxr-xr-xsrc/cython/test/test_euclidean_witness_complex.py39
-rwxr-xr-xsrc/cython/test/test_witness_complex.py51
12 files changed, 485 insertions, 85 deletions
diff --git a/src/cython/CMakeLists.txt b/src/cython/CMakeLists.txt
index bcc1e929..efe2005c 100644
--- a/src/cython/CMakeLists.txt
+++ b/src/cython/CMakeLists.txt
@@ -1,6 +1,19 @@
cmake_minimum_required(VERSION 2.8)
project(Cython)
+macro( find_the_lib placeholder THE_LIBS )
+ set (THE_LIB_WE_FOUND "NO")
+ foreach(THE_LIB ${THE_LIBS})
+ if(EXISTS ${THE_LIB})
+ get_filename_component(THE_LIB_WE ${THE_LIB} NAME_WE)
+ if (NOT THE_LIB_WE_FOUND)
+ set (THE_LIB_WE_FOUND "YES")
+ set(returnValue "${THE_LIB_WE}")
+ endif(NOT THE_LIB_WE_FOUND)
+ endif(EXISTS ${THE_LIB})
+ endforeach(THE_LIB ${THE_LIBS})
+endmacro( find_the_lib )
+
FIND_PROGRAM( PYTHON_PATH python )
FIND_PROGRAM( CYTHON_PATH cython )
@@ -13,8 +26,15 @@ if(PYTHON_PATH AND CYTHON_PATH)
set(GUDHI_CYTHON_EXTRA_COMPILE_ARGS "${GUDHI_CYTHON_EXTRA_COMPILE_ARGS}'-DBOOST_RESULT_OF_USE_DECLTYPE', ")
set(GUDHI_CYTHON_EXTRA_COMPILE_ARGS "${GUDHI_CYTHON_EXTRA_COMPILE_ARGS}'-DBOOST_ALL_NO_LIB', ")
- set(GUDHI_CYTHON_LIBRARIES "${GUDHI_CYTHON_LIBRARIES}'boost_system', ")
set(GUDHI_CYTHON_LIBRARY_DIRS "${GUDHI_CYTHON_LIBRARY_DIRS}'${Boost_LIBRARY_DIRS}', ")
+ if(WIN32)
+ set( returnValue "" )
+ find_the_lib (${returnValue} ${Boost_SYSTEM_LIBRARY})
+ set(BOOST_SYSTEM_LIB_NAME ${returnValue})
+ else()
+ set(BOOST_SYSTEM_LIB_NAME "boost_system")
+ endif()
+ set(GUDHI_CYTHON_LIBRARIES "${GUDHI_CYTHON_LIBRARIES}'${BOOST_SYSTEM_LIB_NAME}', ")
# Gudhi and CGAL compilation option
if(MSVC)
@@ -105,16 +125,38 @@ if(PYTHON_PATH AND CYTHON_PATH)
file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/doc/alpha_complex_sum.rst")
file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/doc/alpha_complex_user.rst")
endif (NOT CGAL_VERSION VERSION_LESS 4.7.0)
+ if (NOT CGAL_VERSION VERSION_LESS 4.6.0)
+ # If CGAL_VERSION >= 4.6.0, include euclidean versions of witness complex
+ set(GUDHI_CYTHON_EUCLIDEAN_WITNESS_COMPLEX
+ "include 'cython/euclidean_witness_complex.pyx'\n")
+ else (NOT CGAL_VERSION VERSION_LESS 4.6.0)
+ # Remove alpha complex unitary tests
+ file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/test/test_euclidean_witness_complex.py)
+ file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/doc/euclidean_witness_complex_ref.rst")
+ file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/doc/euclidean_strong_witness_complex_ref.rst")
+ endif (NOT CGAL_VERSION VERSION_LESS 4.6.0)
if(CGAL_FOUND)
# Add CGAL compilation args
- set(GUDHI_CYTHON_LIBRARIES "${GUDHI_CYTHON_LIBRARIES}'CGAL', ")
- set(GUDHI_CYTHON_LIBRARY_DIRS "${GUDHI_CYTHON_LIBRARY_DIRS}'${CGAL_LIBRARIES_DIR}', ")
+ if(CGAL_HEADER_ONLY)
+ set(GUDHI_CYTHON_EXTRA_COMPILE_ARGS "${GUDHI_CYTHON_EXTRA_COMPILE_ARGS}'-DCGAL_HEADER_ONLY', ")
+ else(CGAL_HEADER_ONLY)
+ if(WIN32)
+ set(GUDHI_CYTHON_LIBRARIES "${GUDHI_CYTHON_LIBRARIES}'CGAL-vc140-mt-4.7', ")
+ else(WIN32)
+ set(GUDHI_CYTHON_LIBRARIES "${GUDHI_CYTHON_LIBRARIES}'CGAL', ")
+ endif(WIN32)
+ set(GUDHI_CYTHON_LIBRARY_DIRS "${GUDHI_CYTHON_LIBRARY_DIRS}'${CGAL_LIBRARIES_DIR}', ")
+ endif(CGAL_HEADER_ONLY)
# GMP and GMPXX are not required, but if present, CGAL will link with them.
if(GMP_FOUND)
set(GUDHI_CYTHON_EXTRA_COMPILE_ARGS "${GUDHI_CYTHON_EXTRA_COMPILE_ARGS}'-DCGAL_USE_GMP', ")
- set(GUDHI_CYTHON_LIBRARIES "${GUDHI_CYTHON_LIBRARIES}'gmp', ")
- set(GUDHI_CYTHON_LIBRARY_DIRS "${GUDHI_CYTHON_LIBRARY_DIRS}'${GMP_LIBRARIES_DIR}', ")
+ if(WIN32)
+ set(GUDHI_CYTHON_LIBRARIES "${GUDHI_CYTHON_LIBRARIES}'libgmp-10', ")
+ else(WIN32)
+ set(GUDHI_CYTHON_LIBRARIES "${GUDHI_CYTHON_LIBRARIES}'gmp', ")
+ endif(WIN32)
+ set(GUDHI_CYTHON_LIBRARY_DIRS "${GUDHI_CYTHON_LIBRARY_DIRS}'${GMP_LIBRARIES_DIR}', ")
if(GMPXX_FOUND)
set(GUDHI_CYTHON_EXTRA_COMPILE_ARGS "${GUDHI_CYTHON_EXTRA_COMPILE_ARGS}'-DCGAL_USE_GMPXX', ")
set(GUDHI_CYTHON_LIBRARIES "${GUDHI_CYTHON_LIBRARIES}'gmpxx', ")
diff --git a/src/cython/cython/euclidean_witness_complex.pyx b/src/cython/cython/euclidean_witness_complex.pyx
new file mode 100644
index 00000000..efbbf06d
--- /dev/null
+++ b/src/cython/cython/euclidean_witness_complex.pyx
@@ -0,0 +1,84 @@
+from cython cimport numeric
+from libcpp.vector cimport vector
+from libcpp.utility cimport pair
+
+"""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 "Euclidean_witness_complex_interface.h" namespace "Gudhi":
+ cdef cppclass Euclidean_witness_complex_interface "Gudhi::witness_complex::Euclidean_witness_complex_interface":
+ Euclidean_witness_complex_interface(vector[vector[double]] landmarks, vector[vector[double]] witnesses)
+ void create_simplex_tree(Simplex_tree_interface_full_featured* simplex_tree, double max_alpha_square)
+ void create_simplex_tree(Simplex_tree_interface_full_featured* simplex_tree, double max_alpha_square,
+ unsigned limit_dimension)
+
+# EuclideanWitnessComplex python interface
+cdef class EuclideanWitnessComplex:
+ """EuclideanWitnessComplex is a simplicial complex constructed from ...
+
+ """
+
+ cdef Euclidean_witness_complex_interface * thisptr
+
+ # Fake constructor that does nothing but documenting the constructor
+ def __init__(self, landmarks=None, witnesses=None):
+ """WitnessComplex constructor.
+
+ :param landmarks: A list of landmarks (in the point cloud).
+ :type landmarks: list of list of double
+
+ :param witnesses: The point cloud.
+ :type witnesses: list of list of double
+ """
+
+ # The real cython constructor
+ def __cinit__(self, landmarks=None, witnesses=None):
+ if landmarks is not None and witnesses is not None:
+ self.thisptr = new Euclidean_witness_complex_interface(landmarks, witnesses)
+
+ def __dealloc__(self):
+ if self.thisptr != NULL:
+ del self.thisptr
+
+ def __is_defined(self):
+ """Returns true if WitnessComplex pointer is not NULL.
+ """
+ return self.thisptr != NULL
+
+ def create_simplex_tree(self, max_alpha_square, limit_dimension = -1):
+ """
+ :param max_alpha_square: The maximum alpha square threshold the
+ simplices shall not exceed. Default is set to infinity.
+ :type max_alpha_square: float
+ :returns: A simplex tree created from the Delaunay Triangulation.
+ :rtype: SimplexTree
+ """
+ simplex_tree = SimplexTree()
+ if limit_dimension is not -1:
+ self.thisptr.create_simplex_tree(simplex_tree.thisptr, max_alpha_square, limit_dimension)
+ else:
+ self.thisptr.create_simplex_tree(simplex_tree.thisptr, max_alpha_square)
+ return simplex_tree
diff --git a/src/cython/cython/off_reader.pyx b/src/cython/cython/off_reader.pyx
new file mode 100644
index 00000000..78c37969
--- /dev/null
+++ b/src/cython/cython/off_reader.pyx
@@ -0,0 +1,49 @@
+from cython cimport numeric
+from libcpp.vector cimport vector
+from libcpp.string cimport string
+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 "Off_reader_interface.h" namespace "Gudhi":
+ vector[vector[double]] read_points_from_OFF_file(string off_file)
+
+def read_off(off_file=''):
+ """Read points from OFF file.
+
+ :param off_file: An OFF file style name.
+ :type off_file: string
+
+ :returns: The point set.
+ :rtype: vector[vector[double]]
+ """
+ if off_file is not '':
+ if os.path.isfile(off_file):
+ return read_points_from_OFF_file(off_file)
+ else:
+ print("file " + off_file + " not found.")
+
diff --git a/src/cython/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py b/src/cython/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py
new file mode 100755
index 00000000..7f04a98e
--- /dev/null
+++ b/src/cython/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py
@@ -0,0 +1,78 @@
+#!/usr/bin/env python
+
+import gudhi
+import argparse
+
+"""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"
+
+parser = argparse.ArgumentParser(description='EuclideanWitnessComplex creation from '
+ 'points read in a OFF file.',
+ epilog='Example: '
+ 'example/witness_complex_diagram_persistence_from_off_file_example.py '
+ '-f ../data/points/tore3D_300.off -a 1.0 -n 20 -d 2'
+ '- Constructs a alpha complex with the '
+ 'points from the given OFF file.')
+parser.add_argument("-f", "--file", type=str, required=True)
+parser.add_argument("-a", "--max_alpha_square", type=float, required=True)
+parser.add_argument("-n", "--number_of_landmarks", type=int, required=True)
+parser.add_argument("-d", "--limit_dimension", type=int, required=True)
+parser.add_argument('--no-diagram', default=False, action='store_true' , help='Flag for not to display the diagrams')
+
+args = parser.parse_args()
+
+with open(args.file, 'r') as f:
+ first_line = f.readline()
+ if (first_line == 'OFF\n') or (first_line == 'nOFF\n'):
+ print("#####################################################################")
+ print("EuclideanWitnessComplex creation from points read in a OFF file")
+
+ witnesses = gudhi.read_off(off_file=args.file)
+ landmarks = gudhi.pick_n_random_points(points=witnesses, nb_points=args.number_of_landmarks)
+
+ message = "EuclideanWitnessComplex with max_edge_length=" + repr(args.max_alpha_square) + \
+ " - Number of landmarks=" + repr(args.number_of_landmarks)
+ print(message)
+
+ witness_complex = gudhi.EuclideanWitnessComplex(witnesses=witnesses, landmarks=landmarks)
+ simplex_tree = witness_complex.create_simplex_tree(max_alpha_square=args.max_alpha_square,
+ limit_dimension=args.limit_dimension)
+
+ message = "Number of simplices=" + repr(simplex_tree.num_simplices())
+ print(message)
+
+ diag = simplex_tree.persistence()
+
+ print("betti_numbers()=")
+ print(simplex_tree.betti_numbers())
+
+ if args.no_diagram == False:
+ gudhi.diagram_persistence(diag)
+
+ else:
+ print(args.file, "is not a valid OFF file")
+
+ f.close()
diff --git a/src/cython/example/witness_complex_from_file_example.py b/src/cython/example/witness_complex_from_file_example.py
deleted file mode 100755
index 82a5b49a..00000000
--- a/src/cython/example/witness_complex_from_file_example.py
+++ /dev/null
@@ -1,56 +0,0 @@
-#!/usr/bin/env python
-
-import gudhi
-import pandas
-import argparse
-
-"""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"
-
-print("#####################################################################")
-print("WitnessComplex creation from points read in a file")
-
-parser = argparse.ArgumentParser(description='WitnessComplex creation from '
- 'points read in a file.',
- epilog='Example: '
- 'example/witness_complex_from_file_example.py'
- ' data/2000_random_points_on_3D_Torus.csv '
- '- Constructs a witness complex with the '
- 'points from the given file. File format '
- 'is X1, X2, ..., Xn')
-parser.add_argument('file', type=argparse.FileType('r'))
-args = parser.parse_args()
-
-points = pandas.read_csv(args.file, header=None)
-
-print("WitnessComplex with number_of_landmarks=100")
-
-witness_complex = gudhi.WitnessComplex(points=points.values,
- number_of_landmarks=100)
-
-witness_complex.initialize_filtration()
-
-print("filtered_tree=", witness_complex.get_filtered_tree())
diff --git a/src/cython/gudhi.pyx.in b/src/cython/gudhi.pyx.in
index 60bf0cd7..34d7c3b5 100644
--- a/src/cython/gudhi.pyx.in
+++ b/src/cython/gudhi.pyx.in
@@ -24,6 +24,7 @@ __author__ = "Vincent Rouvreau"
__copyright__ = "Copyright (C) 2016 INRIA"
__license__ = "GPL v3"
+include "cython/off_reader.pyx"
include "cython/simplex_tree.pyx"
include "cython/rips_complex.pyx"
include "cython/cubical_complex.pyx"
@@ -32,6 +33,7 @@ include "cython/persistence_graphical_tools.py"
include "cython/witness_complex.pyx"
include "cython/strong_witness_complex.pyx"
@GUDHI_CYTHON_ALPHA_COMPLEX@
+@GUDHI_CYTHON_EUCLIDEAN_WITNESS_COMPLEX@
@GUDHI_CYTHON_SUBSAMPLING@
@GUDHI_CYTHON_TANGENTIAL_COMPLEX@
@GUDHI_CYTHON_BOTTLENECK_DISTANCE@
diff --git a/src/cython/include/Euclidean_witness_complex_interface.h b/src/cython/include/Euclidean_witness_complex_interface.h
new file mode 100644
index 00000000..f79d93ab
--- /dev/null
+++ b/src/cython/include/Euclidean_witness_complex_interface.h
@@ -0,0 +1,113 @@
+/* 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 EUCLIDEAN_WITNESS_COMPLEX_INTERFACE_H
+#define EUCLIDEAN_WITNESS_COMPLEX_INTERFACE_H
+
+#include <gudhi/Simplex_tree.h>
+#include <gudhi/Euclidean_witness_complex.h>
+
+#include "Simplex_tree_interface.h"
+
+#include <CGAL/Epick_d.h>
+
+#include <vector>
+#include <utility> // std::pair
+#include <iostream>
+#include <cstddef>
+
+namespace Gudhi {
+
+namespace witness_complex {
+
+
+class Euclidean_witness_complex_interface {
+ using Dynamic_kernel = CGAL::Epick_d< CGAL::Dynamic_dimension_tag >;
+ using Point_d = Dynamic_kernel::Point_d;
+
+ typedef typename Simplex_tree<>::Simplex_key Simplex_key;
+
+ public:
+ Euclidean_witness_complex_interface(std::vector<std::vector<double>>&landmarks, std::vector<std::vector<double>>&witnesses)
+ : landmarks_(landmarks.begin(), landmarks.end()),
+ witnesses_(witnesses.begin(), witnesses.end()),
+ witness_complex_(landmarks_, witnesses_) {
+ }
+ Euclidean_witness_complex_interface(std::vector<Point_d>&landmarks, std::vector<Point_d>&witnesses)
+ : landmarks_(landmarks.begin(), landmarks.end()),
+ witnesses_(witnesses.begin(), witnesses.end()),
+ witness_complex_(landmarks_, witnesses_) {
+ }
+
+ void create_simplex_tree(Gudhi::Simplex_tree<>* simplex_tree, double max_alpha_square, std::size_t limit_dimension) {
+ witness_complex_.create_complex(*simplex_tree, max_alpha_square, limit_dimension);
+ simplex_tree->initialize_filtration();
+ }
+
+ void create_simplex_tree(Gudhi::Simplex_tree<>* simplex_tree, double max_alpha_square) {
+ witness_complex_.create_complex(*simplex_tree, max_alpha_square);
+ simplex_tree->initialize_filtration();
+ }
+
+ private:
+ std::vector<Point_d> landmarks_;
+ std::vector<Point_d> witnesses_;
+ Euclidean_witness_complex<Dynamic_kernel> witness_complex_;
+};
+
+/*template<typename Kernel = CGAL::Epick_d<CGAL::Dynamic_dimension_tag>>
+class Euclidean_witness_complex_interface : public Euclidean_witness_complex<Kernel> {
+//class Euclidean_witness_complex_interface {
+ using Point_d = Kernel::Point_d;
+
+ public:
+ Euclidean_witness_complex_interface(const std::vector<std::vector<double>>& landmarks, const std::vector<std::vector<double>>& witnesses) {
+ : landmarks_(std::begin(landmarks), std::end(landmarks)),
+ witnesses_(std::begin(witnesses), std::end(witnesses)),
+ Gudhi::witness_complex::Euclidean_witness_complex<Kernel>(landmarks_, witnesses_) {
+ }
+
+ void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square,
+ std::size_t limit_dimension) {
+ create_complex(*simplex_tree, max_alpha_square, limit_dimension);
+ simplex_tree->initialize_filtration();
+ }
+
+ void create_simplex_tree(Simplex_tree_interface<>* simplex_tree,
+ double max_alpha_square) {
+ create_complex(*simplex_tree, max_alpha_square);
+ simplex_tree->initialize_filtration();
+ }
+
+ private:
+// Euclidean_witness_complex<Kernel>* witness_complex_;
+ std::vector<Point_d> landmarks_;
+ std::vector<Point_d> witnesses_;
+
+};*/
+
+} // namespace witness_complex
+
+} // namespace Gudhi
+
+#endif // EUCLIDEAN_WITNESS_COMPLEX_INTERFACE_H
+
diff --git a/src/cython/include/Off_reader_interface.h b/src/cython/include/Off_reader_interface.h
new file mode 100644
index 00000000..257331f8
--- /dev/null
+++ b/src/cython/include/Off_reader_interface.h
@@ -0,0 +1,42 @@
+/* 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 OFF_READER_INTERFACE_H
+#define OFF_READER_INTERFACE_H
+
+#include <gudhi/Points_off_io.h>
+
+#include <iostream>
+#include <vector>
+#include <string>
+
+namespace Gudhi {
+
+std::vector<std::vector<double>> read_points_from_OFF_file(std::string& off_file) {
+ Gudhi::Points_off_reader<std::vector<double>> off_reader(off_file);
+ return off_reader.get_point_cloud();
+}
+
+} // namespace Gudhi
+
+#endif // OFF_READER_INTERFACE_H
+
diff --git a/src/cython/include/Strong_witness_complex_interface.h b/src/cython/include/Strong_witness_complex_interface.h
index e59e58ea..5081ec2d 100644
--- a/src/cython/include/Strong_witness_complex_interface.h
+++ b/src/cython/include/Strong_witness_complex_interface.h
@@ -54,7 +54,7 @@ class Strong_witness_complex_interface {
void create_simplex_tree(Simplex_tree_interface<>* simplex_tree,
double max_alpha_square) {
- witness_complex_->create_complex(*simplex_tree, max_alpha_square, std::numeric_limits<std::size_t>::max());
+ witness_complex_->create_complex(*simplex_tree, max_alpha_square);
simplex_tree->initialize_filtration();
}
diff --git a/src/cython/include/Witness_complex_interface.h b/src/cython/include/Witness_complex_interface.h
index 38661cb6..3761b43d 100644
--- a/src/cython/include/Witness_complex_interface.h
+++ b/src/cython/include/Witness_complex_interface.h
@@ -54,7 +54,7 @@ class Witness_complex_interface {
void create_simplex_tree(Simplex_tree_interface<>* simplex_tree,
double max_alpha_square) {
- witness_complex_->create_complex(*simplex_tree, max_alpha_square, std::numeric_limits<std::size_t>::max());
+ witness_complex_->create_complex(*simplex_tree, max_alpha_square);
simplex_tree->initialize_filtration();
}
diff --git a/src/cython/test/test_euclidean_witness_complex.py b/src/cython/test/test_euclidean_witness_complex.py
new file mode 100755
index 00000000..cb150b7e
--- /dev/null
+++ b/src/cython/test/test_euclidean_witness_complex.py
@@ -0,0 +1,39 @@
+import gudhi
+
+"""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"
+
+
+def test_empty_euclidean_witness_complex():
+ euclidean_witness = gudhi.EuclideanWitnessComplex()
+ assert euclidean_witness.__is_defined() == False
+
+def test_witness_complex():
+ point_cloud = [[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]]
+ landmarks = gudhi.pick_n_random_points(points=point_cloud,nb_points=3)
+ euclidean_witness_complex = gudhi.EuclideanWitnessComplex(landmarks=landmarks, witnesses = point_cloud)
+ simplex_tree = euclidean_witness_complex.create_simplex_tree(max_alpha_square=4.1)
diff --git a/src/cython/test/test_witness_complex.py b/src/cython/test/test_witness_complex.py
index a55e80d7..7d1fb6be 100755
--- a/src/cython/test/test_witness_complex.py
+++ b/src/cython/test/test_witness_complex.py
@@ -1,4 +1,4 @@
-from gudhi import WitnessComplex
+from gudhi import WitnessComplex, StrongWitnessComplex, SimplexTree
"""This file is part of the Gudhi Library. The Gudhi library
(Geometric Understanding in Higher Dimensions) is a generic C++
@@ -32,24 +32,31 @@ def test_empty_witness_complex():
assert witness.__is_defined() == False
def test_witness_complex():
- point_list = [[0, 0], [1, 0], [0, 1], [1, 1]]
- witness = WitnessComplex(points=point_list, number_of_landmarks=10)
- assert witness.__is_defined() == True
-
- # FIXME: Remove this line
- witness.set_dimension(2)
-
- assert witness.num_simplices() == 13
- assert witness.num_vertices() == 10
- witness.initialize_filtration()
-"""
- assert witness.get_filtered_tree() == \
- [([0], 0.0), ([1], 0.0), ([0, 1], 0.0), ([2], 0.0), ([1, 2], 0.0),
- ([3], 0.0), ([2, 3], 0.0), ([4], 0.0), ([5], 0.0), ([6], 0.0),
- ([7], 0.0), ([8], 0.0), ([9], 0.0)]
-
-
- assert witness.get_coface_tree([2], 1) == [([1, 2], 0.0), ([2, 3], 0.0)]
- assert witness.get_star_tree([2]) == \
- [([1, 2], 0.0), ([2], 0.0), ([2, 3], 0.0)]
-"""
+ nearest_landmark_table = [[[0, 0], [1, 1], [2, 2], [3, 3], [4, 4]],
+ [[1, 0], [2, 1], [3, 2], [4, 3], [0, 4]],
+ [[2, 0], [3, 1], [4, 2], [0, 3], [1, 4]],
+ [[3, 0], [4, 1], [0, 2], [1, 3], [2, 4]],
+ [[4, 0], [0, 1], [1, 2], [2, 3], [3, 4]]]
+
+ witness_complex = WitnessComplex(nearest_landmark_table=nearest_landmark_table)
+ simplex_tree = witness_complex.create_simplex_tree(max_alpha_square=4.1)
+ assert simplex_tree.num_vertices() == 5
+ assert simplex_tree.num_simplices() == 31
+ simplex_tree = witness_complex.create_simplex_tree(max_alpha_square=4.1, limit_dimension=2)
+ assert simplex_tree.num_vertices() == 5
+ assert simplex_tree.num_simplices() == 25
+
+def test_strong_witness_complex():
+ nearest_landmark_table = [[[0, 0], [1, 1], [2, 2], [3, 3], [4, 4]],
+ [[1, 0], [2, 1], [3, 2], [4, 3], [0, 4]],
+ [[2, 0], [3, 1], [4, 2], [0, 3], [1, 4]],
+ [[3, 0], [4, 1], [0, 2], [1, 3], [2, 4]],
+ [[4, 0], [0, 1], [1, 2], [2, 3], [3, 4]]]
+
+ strong_witness_complex = StrongWitnessComplex(nearest_landmark_table=nearest_landmark_table)
+ simplex_tree = strong_witness_complex.create_simplex_tree(max_alpha_square=4.1)
+ assert simplex_tree.num_vertices() == 5
+ assert simplex_tree.num_simplices() == 31
+ simplex_tree = strong_witness_complex.create_simplex_tree(max_alpha_square=4.1, limit_dimension=2)
+ assert simplex_tree.num_vertices() == 5
+ assert simplex_tree.num_simplices() == 25