Added extra functionality to Point class( an iterator ) and PersistenceDiagram( dimension property and __len__ func ).
persistence-diagram.h:
Added a new read-only dimension member and member function to access it.
With a new constructor that that takes in an int type to initialize dimension.
persistence-diagram.cpp:
Added new bp::init constructor. Takes in an integer type to initialize the dimension. Exposed the dimension property. Exposed the size property via a __len__ method.
__init__.py:
Added an iterator for Point objects. This iterates over the coords and then the data( if present ).
--- a/bindings/python/dionysus/__init__.py Fri Jul 02 17:08:02 2010 -0700
+++ b/bindings/python/dionysus/__init__.py Thu Jul 08 23:50:39 2010 -0700
@@ -26,3 +26,13 @@
def vertex_dim_cmp(s1, s2):
return cmp(s1.dimension(), s2.dimension()) or vertex_cmp(s1, s2)
+
+# TBD: Port this into C++
+def point_iterator( point ):
+
+ yield point.x
+ yield point.y
+ if not point.data is None:
+ yield point.data
+
+Point.__iter__ = point_iterator
--- a/bindings/python/persistence-diagram.cpp Fri Jul 02 17:08:02 2010 -0700
+++ b/bindings/python/persistence-diagram.cpp Thu Jul 08 23:50:39 2010 -0700
@@ -52,30 +52,44 @@
-template<class PersistenceDiagramD, class PointD>
-boost::shared_ptr<PersistenceDiagramD> init_from_points_sequence( bp::object point_sequence ){
+template<class PersistenceDiagram, class Point>
+boost::shared_ptr<PersistenceDiagram> init_from_points_sequence( bp::object point_sequence ){
- typedef bp::stl_input_iterator<PointD> PointDIterator;
+ typedef bp::stl_input_iterator<Point> PointIterator;
- PointDIterator beg = PointDIterator( point_sequence ), end = PointDIterator( );
+ 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<PersistenceDiagramD> p( new PersistenceDiagramD( beg, end );
- boost::shared_ptr<PersistenceDiagramD> p( new PersistenceDiagramD( ) );
+ //boost::shared_ptr<PersistenceDiagram> p( new PersistenceDiagram( beg, end );
+ boost::shared_ptr<PersistenceDiagram> p( new PersistenceDiagram( ) );
- for( PointDIterator cur=beg; cur!=end; 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( );
+}
+
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( "points", bp::range( &dp::PersistenceDiagramD::begin, &dp::PersistenceDiagramD::end ) )
+ .add_property( "dimension", &get_dimension<dp::PersistenceDiagramD> )
.def( repr(bp::self) )
.def( "__sub__", &bottleneck_distance<dp::PersistenceDiagramD,dp::PersistenceDiagramD> )
+ .def( "__len__", &get_length<dp::PersistenceDiagramD> )
;
bp::def( "BottleneckDistance", bottleneck_distance<dp::PersistenceDiagramD,dp::PersistenceDiagramD> );
--- a/include/topology/persistence-diagram.h Fri Jul 02 17:08:02 2010 -0700
+++ b/include/topology/persistence-diagram.h Thu Jul 08 23:50:39 2010 -0700
@@ -85,6 +85,9 @@
PersistenceDiagram() {}
+ PersistenceDiagram( Dimension dimension ):
+ dimension_( dimension ) {}
+
template<class OtherData>
PersistenceDiagram(const PersistenceDiagram<OtherData>& other);
@@ -110,8 +113,11 @@
std::ostream& operator<<(std::ostream& out) const;
+ const Dimension& dimension( ) const { return dimension_; }
+
private:
PointVector points_;
+ Dimension dimension_;
private:
/* Serialization */