bindings/python/static-persistence.cpp
author Dmitriy Morozov <dmitriy@mrzv.org>
Sun, 12 Sep 2010 09:55:44 -0700
branchdev
changeset 232 edbbf84fde9e
parent 193 7198c9bf279d
child 246 88f7806633e0
permissions -rw-r--r--
Added Python bindings for DynamicPersistenceChains

#include <topology/static-persistence.h>

#include <boost/python.hpp>
#include <boost/python/iterator.hpp>
#include <boost/python/return_internal_reference.hpp>
namespace bp = boost::python;

#include "filtration.h"
#include "static-persistence.h"
#include "chain.h"
namespace dp = dionysus::python;


void                                    pair_simplices(dp::SPersistence& sp)                { sp.pair_simplices(false); }


void export_static_persistence()
{
    bp::class_<dp::SPersistenceNode>("SPNode", bp::no_init)
        .def("pair",            &dp::pair<dp::SPersistenceNode>,        bp::return_internal_reference<1>())
        .add_property("cycle",  &dp::SPersistenceNode::cycle)
        .def("sign",            &dp::SPersistenceNode::sign)
        .def("unpaired",        &dp::SPersistenceNode::unpaired)
    ;

    bp::class_<dp::SPersistence>("StaticPersistence", bp::no_init)
        .def("__init__",        bp::make_constructor(&dp::init_from_filtration<dp::SPersistence>))
        
        .def("pair_simplices",  &pair_simplices)
        .def("__call__",        &dp::distance<dp::SPersistence, dp::SPersistenceIndex>)
        .def("make_simplex_map",&dp::SPersistence::make_simplex_map<dp::PythonFiltration>)

        .def("__iter__",        bp::range<bp::return_internal_reference<1> >(&dp::SPersistence::begin, &dp::SPersistence::end))
        .def("__len__",         &dp::SPersistence::size)
    ;

    bp::class_<dp::SPersistenceSimplexMap>("SPersistenceSimplexMap", bp::no_init)
        .def("__getitem__",     &dp::psmap_getitem<dp::SPersistenceSimplexMap, dp::SPersistenceIndex>,  bp::return_internal_reference<1>())
    ;
}