diff options
-rwxr-xr-x | src/cython/example/cubical_complex_from_perseus_file_example.py | 53 | ||||
-rw-r--r-- | src/cython/src/cpp/Cubical_complex_interface.h | 4 | ||||
-rw-r--r-- | src/cython/src/cython/cubical_complex.pyx | 10 |
3 files changed, 65 insertions, 2 deletions
diff --git a/src/cython/example/cubical_complex_from_perseus_file_example.py b/src/cython/example/cubical_complex_from_perseus_file_example.py new file mode 100755 index 00000000..9fc083ff --- /dev/null +++ b/src/cython/example/cubical_complex_from_perseus_file_example.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python + +import gudhi +import numpy +import argparse +import operator + + +"""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='Cubical complex from a perseus' + 'file style name.', + epilog='Example: ' + './cubical_complex_from_perseus_file_example.py' + '../data/bitmap/CubicalTwoSphere.txt') +parser.add_argument('perseus_file', type=str, required=True, + help='Perseus file style name') + +args = parser.parse_args() + +print("#####################################################################") +print("CubicalComplex creation") +cubical_complex = gudhi.CubicalComplex(perseus_file=args.perseus_file) + +print("persistence(homology_coeff_field=2, min_persistence=0)=") +print(cubical_complex.persistence(homology_coeff_field=2, min_persistence=0)) + +print("betti_numbers()=") +print(cubical_complex.betti_numbers())
\ No newline at end of file diff --git a/src/cython/src/cpp/Cubical_complex_interface.h b/src/cython/src/cpp/Cubical_complex_interface.h index 1bed6fd1..f054fbbd 100644 --- a/src/cython/src/cpp/Cubical_complex_interface.h +++ b/src/cython/src/cpp/Cubical_complex_interface.h @@ -44,6 +44,10 @@ class Cubical_complex_interface : public Bitmap_cubical_complex<CubicalComplexOp : Bitmap_cubical_complex<CubicalComplexOptions>(dimensions, top_dimensional_cells) { } + Cubical_complex_interface(const std::string& perseus_file) + : Bitmap_cubical_complex<CubicalComplexOptions>(perseus_file.c_str()) { + } + }; } // namespace Cubical_complex diff --git a/src/cython/src/cython/cubical_complex.pyx b/src/cython/src/cython/cubical_complex.pyx index 74aeaa56..98f0526a 100644 --- a/src/cython/src/cython/cubical_complex.pyx +++ b/src/cython/src/cython/cubical_complex.pyx @@ -1,6 +1,7 @@ from cython cimport numeric from libcpp.vector cimport vector from libcpp.utility cimport pair +from libcpp.string cimport string """This file is part of the Gudhi Library. The Gudhi library (Geometric Understanding in Higher Dimensions) is a generic C++ @@ -31,6 +32,7 @@ __license__ = "GPL v3" cdef extern from "Cubical_complex_interface.h" namespace "Gudhi": cdef cppclass Bitmap_cubical_complex_base_interface "Gudhi::Cubical_complex::Cubical_complex_interface<>": Bitmap_cubical_complex_base_interface(vector[unsigned] dimensions, vector[double] top_dimensional_cells) + Bitmap_cubical_complex_base_interface(string perseus_file) cdef extern from "Persistent_cohomology_interface.h" namespace "Gudhi": cdef cppclass Cubical_complex_persistence_interface "Gudhi::Persistent_cohomology_interface<Gudhi::Cubical_complex::Cubical_complex_interface<>>": @@ -50,16 +52,20 @@ cdef class CubicalComplex: cdef Cubical_complex_persistence_interface * pcohptr - def __cinit__(self, dimensions=None, top_dimensional_cells=None): - """CubicalComplex constructor. + def __cinit__(self, dimensions=None, top_dimensional_cells=None, perseus_file=''): + """CubicalComplex constructor from dimensions and + top_dimensional_cells or from a perseus file style name. Args: dimensions (list): A list of number of top dimensional cells. top_dimensional_cells (list): A list of top dimensional cells. + perseus_file (string): A perseus file style name. """ if dimensions is not None: if top_dimensional_cells is not None: self.thisptr = new Bitmap_cubical_complex_base_interface(dimensions, top_dimensional_cells) + else: + self.thisptr = new Bitmap_cubical_complex_base_interface(perseus_file) def __dealloc__(self): if self.thisptr != NULL: |