author Aravindakshan Babu <>
Thu, 08 Jul 2010 23:50:39 -0700
changeset 217 64a272a34cb2
parent 179 d15c6d144645
permissions -rw-r--r--
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. Added an iterator for Point objects. This iterates over the coords and then the data( if present ).

 * Author: Dmitriy Morozov
 * Department of Computer Science, Duke University, 2005 -- 2008


#include <boost/serialization/access.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/nvp.hpp>

 * Struct: MaxVertexComparison
 * Functor that determines which simplex has a higher vertex with respect to VertexComparison_, breaking ties by dimension
template<class Simplex_, class VertexComparison_>
struct MaxVertexComparison
    typedef                     VertexComparison_                                   VertexComparison;
    typedef                     Simplex_                                            Simplex;
    typedef                     typename Simplex::Vertex                            Vertex;

                                MaxVertexComparison(const VertexComparison& vcmp):
                                    vcmp_(vcmp)                                     {}

    bool                        operator()(const Simplex& s1, const Simplex& s2) const
        const Vertex& max1 = *std::max_element(s1.vertices().begin(), s1.vertices().end(), vcmp_);
        const Vertex& max2 = *std::max_element(s2.vertices().begin(), s2.vertices().end(), vcmp_);
        bool less = vcmp_(max1, max2), 
             more = vcmp_(max2, max1);
        if (!less && !more)     // equal
            return s1.dimension() < s2.dimension();

        return less;

    VertexComparison            vcmp_;

 * Map from i-th vertex to its index in the filtration.
template<class Index_, class Filtration_>
class VertexSimplexMap
        typedef                 Index_                                              Index;
        typedef                 Filtration_                                         Filtration;
        typedef                 std::vector<Index>                                  VertexVector;
                                VertexSimplexMap(Index begin, Index end, const Filtration& f)
            for (Index cur = begin; cur != end; ++cur)
                if (f.simplex(cur).dimension() == 0)

        VertexVector            vertices_;