| 1 |
/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT. |
| 2 |
* See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details. |
| 3 |
* Author(s): Hannah Schreiber |
| 4 |
* |
| 5 |
* Copyright (C) 2024 Inria |
| 6 |
* |
| 7 |
* Modification(s): |
| 8 |
* - YYYY/MM Author: Description of the modification |
| 9 |
*/ |
| 10 |
|
| 11 |
#include <iostream> |
| 12 |
|
| 13 |
#include <gudhi/zigzag_persistence.h> |
| 14 |
|
| 15 |
using Zigzag_persistence = Gudhi::zigzag_persistence::Zigzag_persistence<>; |
| 16 |
using Dimension = Zigzag_persistence::Dimension; |
| 17 |
using Index = Zigzag_persistence::Index; |
| 18 |
|
| 19 |
int main() { |
| 20 |
std::clog << "************* Minimalistic example of usage of the Zigzag_persistence class *************" << std::endl; |
| 21 |
|
| 22 |
// Zigzag_persistence(callback) with for example callback method as a anonymous lambda |
| 23 |
Zigzag_persistence zp([](Dimension dim, Index birth, Index death) { |
| 24 |
std::cout << "[" << dim << "] " << birth << " - " << death << std::endl; |
| 25 |
}); |
| 26 |
|
| 27 |
// It is important that the operations of insertions and removals are made **in the same order** as in the zigzag |
| 28 |
// filtration ones wants to compute the barcode from. |
| 29 |
// A cell has to be identified in the boundaries by the operation number the cell was inserted with in the sequence. |
| 30 |
|
| 31 |
// inserts vertex 0 -> birth at 0 of 0-cycle |
| 32 |
zp.insert_cell({}, 0); |
| 33 |
// inserts vertex 1 -> birth at 1 of 0-cycle |
| 34 |
zp.insert_cell({}, 0); |
| 35 |
// inserts edge 2 = (0,1) -> death at 2 -> outputs (0, 1, 2) |
| 36 |
zp.insert_cell({0, 1}, 1); |
| 37 |
// inserts vertex 3 -> birth at 3 of 0-cycle |
| 38 |
zp.insert_cell({}, 0); |
| 39 |
// inserts edge 4 = (0,3) -> death at 4 -> outputs (0, 3, 4) |
| 40 |
zp.insert_cell({0, 3}, 1); |
| 41 |
// inserts edge 5 = (1,3) -> birth at 5 of 1-cycle |
| 42 |
zp.insert_cell({1, 3}, 1); |
| 43 |
// removes edge 4 -> death at 6 -> outputs (1, 5, 6) |
| 44 |
zp.remove_cell(4); |
| 45 |
// removes edge 2 -> birth at 7 of 0-cycle |
| 46 |
zp.remove_cell(2); |
| 47 |
|
| 48 |
// Only the closed bars were output so far, so the open/infinite bars still need to be retrieved. |
| 49 |
|
| 50 |
// in this example, computes (0, 0) and (0, 7) |
| 51 |
zp.get_current_infinite_intervals( |
| 52 |
[](Dimension dim, Index birth) { std::cout << "[" << dim << "] " << birth << " - inf" << std::endl; }); |
| 53 |
|
| 54 |
return 0; |
| 55 |
} |