include/topology/complex-traits.h
author Dmitriy Morozov <dmitriy@mrzv.org>
Mon, 12 Jan 2009 15:33:04 -0800
branchdev
changeset 109 75eb7a4628f2
parent 97 0a9bd3f34419
child 179 d15c6d144645
permissions -rw-r--r--
Debugged ZigzagPersistence (having added heavier consistency checking) * Added DEBUG_CONTAINERS option (uses std::__debug::* containers for chains and in ZigzagPersistence) * Added SizeStorage specialization for std::deque<T> * ZigzagPersistence got a lot more consistency checking (in debug mode only, which now crawls); as a result it's been debugged (running on non-trivial examples) * examples/rips/rips-zigzag takes command-line options * added ChainWrapper::clear() * added Simplex::VertexDimensionComparison * added PairwiseDistances class (for computing distances between points in a container according to a distance functor)

#ifndef __COMPLEX_TRAITS_H__
#define __COMPLEX_TRAITS_H__

#include <vector>
#include <map>
#include "utilities/property-maps.h"

// Class: ComplexTraits
// Class that extracts various properties of a complex.
//
// Parameter:
//   Complex -      the type whose traits we are extracting
template<class Complex_>
struct ComplexTraits
{
    /* 
     * Typedefs: Associated types
     * Types extractable by the traits class.
     *
     * Complex -            the type of the complex
     * Simplex -            the type of the simplex stored in the complex
     * Index -              the type used to refer to the elements of the complex
     * IndexComparison -    the type used to compare indices
     */
    typedef         Complex_                                                Complex;
    typedef         typename Complex::Simplex                               Simplex;
    typedef         typename Complex::Index                                 Index;
    typedef         std::less<Index>                                        IndexComparison;

    /* Typedefs: Maps
     * Maps to go from Indicies to Simplices and back.
     *
     * SimplexIndexMap -    the map from Simplex to the Index (could be implemented via a binary search, or a map)
     */
    typedef         AssociativeMap<std::map<Simplex, Index, 
                                   typename Simplex::VertexComparison> >    SimplexIndexMap;

    // Function: simplex_index_map() 
    // Initializes an SimplexIndexMap given a Complex.
    static SimplexIndexMap
                    simplex_index_map(const Complex& complex)               { return SimplexIndexMap(complex.begin(),
                                                                                                     complex.end()); } 

    static Index    begin(const Complex& complex)                           { return complex.begin(); }
    static Index    end(const Complex& complex)                             { return complex.end(); }
};


// Specializations
template<class Simplex_>
struct ComplexTraits<std::vector<Simplex_> >
{
    typedef         std::vector<Simplex_>                                   Complex;
    typedef         Simplex_                                                Simplex;
    typedef         typename Complex::const_iterator                        Index;
    typedef         std::less<Index>                                        IndexComparison;

    typedef         BinarySearchMap<Simplex, Index,
                                    typename Simplex::VertexComparison>     SimplexIndexMap;

    static SimplexIndexMap
                    simplex_index_map(const Complex& complex)               { return SimplexIndexMap(complex.begin(),
                                                                                                     complex.end()); }
    static SimplexIndexMap
                    simplex_index_map(Index bg, Index end)                  { return SimplexIndexMap(bg, end); }

    static Index    begin(const Complex& complex)                           { return complex.begin(); }
    static Index    end(const Complex& complex)                             { return complex.end(); }
};

#endif // __COMPLEX_TRAITS_H__