author Dmitriy Morozov <>
Thu, 18 Dec 2008 16:43:42 -0800
changeset 97 0a9bd3f34419
parent 83 cf653a5a2d4f
child 99 6c0da7931e4d
child 101 9efac05d629b
permissions -rw-r--r--
Intermediate commit while converting to the new architecture * Converted Filtration into StaticPersistence and DynamicPersistenceTrails (both right now work with the underlying std::vector rather than std::list order) * Filtration is now just an auxilliary glue (a map between Complex and Persistence) * Whether chains are vectors or lists can be interchanged * Added PersistenceDiagram with a simple bottleneck_distance() function * Converted triangle, alphashapes3d, and cech-complex examples * Lots of organizational changes (factoring utilities out into containers.h, indirect.h, property-maps.h) * Trying to document along the way with NaturalDocs-type comments

#ifndef __FILTRATION_H__
#define __FILTRATION_H__

#include <vector>
#include <iostream>
#include "complex-traits.h"
#include "utilities/indirect.h"
#include "utilities/property-maps.h"

// Class: Filtration
// TODO: this is really specialized for an std::vector<> Complex; eventually generalize
// TODO: should we derive from Order?
template<class Complex_, 
         class Index_ =             size_t, 
         class ComplexTraits_ =     ComplexTraits<Complex_> >
class Filtration
        // Typedefs: Template parameters
        typedef                 Index_                                          IntermediateIndex;
        typedef                 Complex_                                        Complex;
        typedef                 ComplexTraits_                                  ComplexTraits;

        // Typedefs: Complex
        typedef                 typename ComplexTraits::Index                   ComplexIndex;
        typedef                 typename ComplexTraits::Simplex                 Simplex;
        typedef                 typename ComplexTraits::SimplexIndexMap         SimplexIndexMap;
        typedef                 typename Simplex::Boundary                      SimplexBoundary;
        typedef                 std::vector<IntermediateIndex>                  IndexBoundary;

        // Typedefs: Order
        typedef                 std::vector<ComplexIndex>                       Order;
        typedef                 typename Order::const_iterator                  Index;
        typedef                 std::vector<IntermediateIndex>                  ReverseOrder;
        typedef                 typename ReverseOrder::const_iterator           ReverseOrderIndex;

        // Constructor: Filtration(bg, end, cmp)
                                template<class Comparison>
                                Filtration(ComplexIndex bg, ComplexIndex end, const Comparison& cmp = Comparison());

        const Simplex&          simplex(Index i) const                          { return **i; }

        // Function: boundary(i, bdry, map)
        // Computes boundary of a given index `i` in terms of other indices
        template<class Cycle, class Map>
        void                    boundary(const Index& i, Cycle& bdry, const Map& map) const;

        Index                   begin() const                                   { return order_.begin(); }
        Index                   end() const                                     { return order_.end(); }
        size_t                  size() const                                    { return order_.size(); }

        std::ostream&           operator<<(std::ostream& out) const;

        Order                   order_;
        ReverseOrder            reverse_order_;
        SimplexIndexMap         simplex_index_map_;

template<class C, class I, class CT>
operator<<(std::ostream& out, const Filtration<C,I,CT>& f)                      { return f.operator<<(out); }

template<class Functor_, class Filtration_>
class ThroughFiltration
        typedef                 Filtration_                                     Filtration;
        typedef                 Functor_                                        Functor;

        typedef                 typename Functor::result_type                   result_type;
        typedef                 typename Filtration::Index                      first_argument_type;

                                ThroughFiltration(const Filtration& filtration,
                                                  const Functor&    functor):
                                    functor_(functor)                           {}

        result_type             operator()(first_argument_type a) const         { return functor_(filtration_.simplex(a)); }

        const Filtration&       filtration_;
        const Functor&          functor_;

template<class Filtration, class Functor>
ThroughFiltration<Functor, Filtration>
evaluate_through_filtration(const Filtration& filtration, const Functor& functor)
{ return ThroughFiltration<Functor, Filtration>(filtration, functor); }

#include "filtration.hpp"

#endif // __FILTRATION_H__