examples/triangle/triangle-zigzag.cpp
author Dmitriy Morozov <dmitriy@mrzv.org>
Fri May 11 17:06:55 2012 -0700 (2 weeks ago)
branchdev
changeset 251 870865d25958
permissions -rw-r--r--
Merge
     1 #include <vector>
     2 #include <cassert>
     3 #include <iostream>
     4 
     5 #include <topology/simplex.h>
     6 #include <topology/zigzag-persistence.h>
     7 #include <boost/tuple/tuple.hpp>
     8 
     9 typedef     ZigzagPersistence<unsigned>     Zigzag;
    10 typedef     Zigzag::SimplexIndex            Index;
    11 typedef     Zigzag::Death                   Death;
    12 typedef     Zigzag::ZColumn                 Boundary;
    13 typedef     std::vector<Index>              Complex;
    14 
    15 int main(int argc, char** argv)
    16 {
    17 #ifdef LOGGING
    18     rlog::RLogInit(argc, argv);
    19 
    20     //stdoutLog.subscribeTo(RLOG_CHANNEL("topology/persistence"));
    21 #endif
    22 
    23 
    24     Zigzag zz;
    25     Complex c;
    26     Index i; Death d;
    27     unsigned birth = 0;
    28 
    29     // Adding the triangle
    30     std::cout << birth << ": adding 0" << std::endl;
    31     boost::tie(i, d)        = zz.add(Boundary(), birth++);  // A
    32     c.push_back(i);
    33     assert(!d);                                             // birth
    34 
    35     std::cout << birth << ": adding 1" << std::endl;
    36     boost::tie(i, d)        = zz.add(Boundary(), birth++);  // B
    37     c.push_back(i);
    38     assert(!d);                                             // birth
    39 
    40     std::cout << birth << ": adding 2" << std::endl;
    41     boost::tie(i, d)        = zz.add(Boundary(), birth++); // C
    42     c.push_back(i);
    43     assert(!d);                                             // birth
    44     
    45     std::cout << birth << ": adding 3" << std::endl;
    46     boost::tie(i, d)        = zz.add(Boundary(c.begin(), 
    47                                               boost::next(c.begin(),2)), 
    48                                      birth++);              // AB
    49     c.push_back(i);
    50     assert(d);                                              // death
    51     if (d)                  std::cout << "Death of: " << *d << std::endl;
    52 
    53     std::cout << birth << ": adding 4" << std::endl;
    54     boost::tie(i, d)        = zz.add(Boundary(boost::next(c.begin()), 
    55                                               boost::next(c.begin(),3)), 
    56                                      birth++);              // BC
    57     c.push_back(i);
    58     assert(d);                                              // death
    59     if (d)                  std::cout << "Death of: " << *d << std::endl;
    60     
    61     std::cout << birth << ": adding 5" << std::endl;
    62     {
    63         Boundary bdry; bdry.append(*c.begin(), zz.cmp); bdry.append(*boost::next(c.begin(), 2), zz.cmp);
    64         boost::tie(i, d)    = zz.add(bdry, birth++);        // AC
    65     }
    66     c.push_back(i);
    67     assert(!d);                                             // birth
    68     
    69     std::cout << birth << ": adding 6" << std::endl;
    70     boost::tie(i, d)        = zz.add(Boundary(boost::next(c.begin(), 3), 
    71                                               boost::next(c.begin(), 6)), 
    72                                      birth++);              // ABC
    73     c.push_back(i);
    74     assert(d);                                              // death
    75     if (d)                  std::cout << "Death of: " << *d << std::endl;
    76 
    77     //zz.show_all();
    78 
    79     // Removing the triangle in reverse order
    80     for (Complex::reverse_iterator cur = c.rbegin(); cur != c.rend(); ++cur)
    81     {
    82         std::cout << birth << ": removing " << (*cur)->order << std::endl;
    83         d = zz.remove(*cur, birth++);
    84         if (d)              std::cout << "Death of: " << *d << std::endl;
    85         //zz.show_all();
    86     }
    87 }