bindings/python/rips.cpp
author Dmitriy Morozov <dmitriy@mrzv.org>
Tue, 14 Apr 2009 14:38:08 -0700
branchdev
changeset 129 95454ea3f9c0
parent 128 a5fd0c2a1c88
child 130 580eaa850c4f
permissions -rw-r--r--
Cleaned up Python bindings to restore functionality: * StaticPersistence is iterable, its nodes are usable (sign, pair, cycle) * StaticPersistence knows how to map its nodes into Filtration indices * moved PythonCmp into utils.h * minor cosmetic changes

#include <topology/rips.h>
#include <boost/python.hpp>
#include "rips.h"                   // defines RipsWithDistances

#include <iostream>

namespace bp = boost::python;

/* Various wrappers for exposing Rips to Python */
// Constructor from distances
boost::shared_ptr<RipsWithDistances>        init_from_distances(bp::object distances)
{ 
    boost::shared_ptr<RipsWithDistances>    p(new RipsWithDistances(distances));
    return p;
}

void export_rips()
{
    bp::class_<RipsWithDistances>("Rips", bp::no_init)
        .def("__init__",            make_constructor(&init_from_distances))
        .def("generate",            &RipsWithDistances::generate)
        .def("generate",            &RipsWithDistances::generate_candidates)
        .def("vertex_cofaces",      &RipsWithDistances::vertex_cofaces)
        .def("vertex_cofaces",      &RipsWithDistances::vertex_cofaces_candidate)
        .def("edge_cofaces",        &RipsWithDistances::edge_cofaces)
        .def("edge_cofaces",        &RipsWithDistances::edge_cofaces_candidates)

        .def("cmp",                 &RipsWithDistances::cmp)
        .def("cmp",                 &RipsWithDistances::cmp_native)
        .def("eval",                &RipsWithDistances::eval)
        .def("eval",                &RipsWithDistances::eval_native)
    ;
}