--- a/bindings/python/persistence-diagram.cpp Mon Oct 04 18:03:35 2010 -0700
+++ b/bindings/python/persistence-diagram.cpp Sat Oct 09 13:56:26 2010 -0700
@@ -5,7 +5,7 @@
#include<boost/python/init.hpp>
#include<boost/shared_ptr.hpp>
#include<boost/python/stl_iterator.hpp>
-#include <boost/python/def.hpp>
+#include<boost/python/def.hpp>
namespace bp = boost::python;
@@ -22,74 +22,52 @@
namespace dp = dionysus::python;
-
-template<class PDPoint>
-RealType get_x_coord( const PDPoint& p ){
- return p.x( );
-}
-
-template<class PDPoint>
-RealType get_y_coord( const PDPoint& p ){
- return p.y( );
-}
+// Easy way out of overloads
+RealType get_x (const dp::PointD& p) { return p.x(); }
+RealType get_y (const dp::PointD& p) { return p.y(); }
+bp::object get_data(const dp::PointD& p) { return p.data(); }
-template<class PDPoint>
-bp::object get_data( const PDPoint& p ){
- return p.data( );
-}
-
-void export_point( ){
-
+void export_point( )
+{
bp::class_<dp::PointD>("Point")
- .def( bp::init< RealType, RealType, bp::optional<dp::Data> >( ) )
- .add_property( "x", &get_x_coord<dp::PointD> )
- .add_property( "y", &get_y_coord<dp::PointD> )
- .add_property( "data", &get_data<dp::PointD> )
- .def( repr(bp::self) )
+ .def( bp::init<RealType, RealType, bp::optional<dp::Data> >())
+ .add_property("x", &get_x)
+ .add_property("y", &get_y)
+ .add_property("data", &get_data)
+ .def( repr(bp::self))
;
-
}
-
-template<class PersistenceDiagram, class Point>
-boost::shared_ptr<PersistenceDiagram> init_from_points_sequence( Dimension dimension, bp::object point_sequence ){
-
- typedef bp::stl_input_iterator<Point> PointIterator;
+boost::shared_ptr<dp::PersistenceDiagramD> init_from_points_sequence(Dimension dimension, bp::object point_sequence)
+{
+ typedef bp::stl_input_iterator<dp::PointD> PointIterator;
- PointIterator beg = PointIterator( point_sequence ), end = PointIterator( );
- // The following line is commented out until we can figure out the Evaluator class in make_point
- //boost::shared_ptr<PersistenceDiagram> p( new PersistenceDiagram( beg, end );
- boost::shared_ptr<PersistenceDiagram> p( new PersistenceDiagram( dimension ) );
+ PointIterator beg = PointIterator(point_sequence), end = PointIterator();
+ boost::shared_ptr<dp::PersistenceDiagramD> p(new dp::PersistenceDiagramD(dimension));
- for( PointIterator cur=beg; cur!=end; cur++ )
- (*p).push_back( *cur );
+ for(PointIterator cur = beg; cur != end; cur++)
+ (*p).push_back(*cur);
return p;
}
-
-template<class PersistenceDiagram>
-Dimension get_dimension( PersistenceDiagram dgm ){
- return dgm.dimension( );
-}
-
-template<class PersistenceDiagram>
-SizeType get_length( PersistenceDiagram dgm ){
- return dgm.size( );
-}
+RealType bottleneck_distnace_adapter(const dp::PersistenceDiagramD& dgm1, const dp::PersistenceDiagramD& dgm2)
+{
+ return bottleneck_distance(dgm1, dgm2);
+}
-void export_persistence_diagram( ){
-
+void export_persistence_diagram()
+{
bp::class_<dp::PersistenceDiagramD>("PersistenceDiagram")
- .def( "__init__", bp::make_constructor( &init_from_points_sequence< dp::PersistenceDiagramD, dp::PointD > ) )
- .def( bp::init< Dimension >( ) )
- .def( "append", &dp::PersistenceDiagramD::push_back )
- .add_property( "dimension", &get_dimension<dp::PersistenceDiagramD> )
- .def( repr(bp::self) )
- .def( "__iter__", bp::range( &dp::PersistenceDiagramD::begin, &dp::PersistenceDiagramD::end ) )
- .def( "__len__", &get_length<dp::PersistenceDiagramD> )
+ .def("__init__", bp::make_constructor(&init_from_points_sequence))
+ .def( bp::init<Dimension>())
+ .def("append", &dp::PersistenceDiagramD::push_back)
+ .add_property("dimension", &dp::PersistenceDiagramD::dimension)
+ .def( repr(bp::self))
+ .def("__iter__", bp::range(&dp::PersistenceDiagramD::begin, &dp::PersistenceDiagramD::end))
+ .def("__len__", &dp::PersistenceDiagramD::size)
;
- bp::def( "bottleneck_distance", bottleneck_distance<dp::PersistenceDiagramD,dp::PersistenceDiagramD> );
+ bp::def("bottleneck_distance", &bottleneck_distnace_adapter);
}
--- a/include/topology/persistence-diagram.h Mon Oct 04 18:03:35 2010 -0700
+++ b/include/topology/persistence-diagram.h Sat Oct 09 13:56:26 2010 -0700
@@ -113,7 +113,7 @@
std::ostream& operator<<(std::ostream& out) const;
- const Dimension& dimension( ) const { return dimension_; }
+ Dimension dimension() const { return dimension_; }
private:
PointVector points_;