Debian Codegraph @

src/Zigzag_persistence/example/example_zigzag_filtration_as_input_loop.cpp

raw
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) 2023 Inria
6 *
7 * Modification(s):
8 * - YYYY/MM Author: Description of the modification
9 */
10
11 #include <iostream>
12 #include <vector>
13
14 #include <gudhi/filtered_zigzag_persistence.h>
15
16 using ZP = Gudhi::zigzag_persistence::Filtered_zigzag_persistence_with_storage<>;
17 using Cell_handle = ZP::Cell_key;
18 using Filtration_value = ZP::Filtration_value;
19 using Interval_filtration = ZP::Filtration_value_interval;
20
21 void print_barcode(ZP& zp) {
22 std::cout << std::endl << "Current barcode:" << std::endl;
23 for (Interval_filtration& bar : zp.get_persistence_diagram(0, true)) {
24 //stream out content of bar
25 std::cout << bar << std::endl;
26 //to access the content of the bar, it can either be used as a struct:
27 // bar.birth
28 // bar.death
29 // bar.dim
30 //or as a tuple
31 // std::get<0>(bar) <- birth
32 // std::get<1>(bar) <- death
33 // std::get<2>(bar) <- dim
34 }
35 }
36
37 void print_indices(ZP& zp) {
38 std::cout << std::endl << "Current pairs:" << std::endl;
39 for (auto& bar : zp.get_index_persistence_diagram()) {
40 //stream out content of bar
41 std::cout << bar << std::endl;
42 //to access the content of the bar, it can either be used as a struct:
43 // bar.birth
44 // bar.death
45 // bar.dim
46 //or as a tuple:
47 // std::get<0>(bar) <- birth
48 // std::get<1>(bar) <- death
49 // std::get<2>(bar) <- dim
50 }
51 }
52
53 std::vector<std::vector<Cell_handle> > get_boundaries() {
54 return {{},
55 {},
56 {},
57 {0, 1},
58 {0, 2},
59 {},
60 {1, 2},
61 {},
62 {5, 7},
63 {},
64 {3, 4, 6},
65 {7, 9},
66 {5, 9},
67 {8, 11, 12},
68 {10}, // remove
69 {13}, // remove
70 {1, 7},
71 {3, 4, 6},
72 {2, 7},
73 {8, 11, 12},
74 {0, 7},
75 {4, 18, 20},
76 {6, 16, 18},
77 {3, 16, 20},
78 {19}, // remove
79 {8}, // remove
80 {12}, // remove
81 {17, 21, 22, 23},
82 {27}}; // remove
83 }
84
85 std::vector<Filtration_value> get_filtration_values() {
86 return {0, 0, 0,
87 1, 1, 1,
88 2, 2, 2,
89 3, 3, 3, 3,
90 4,
91 5,
92 6, 6, 6,
93 7, 7, 7, 7, 7, 7,
94 8,
95 9, 9, 9,
96 10};
97 }
98
99 std::vector<bool> get_directions() {
100 return {true, true, true, true, true, true, true, true, true, true, true, true, true, true,
101 false, false,
102 true, true, true, true, true, true, true, true,
103 false, false, false,
104 true,
105 false};
106 }
107
108 std::vector<unsigned int> get_batch_sizes() {
109 return {14, 2, 8, 3, 1, 1};
110 }
111
112 int main(int argc, char* const argv[]) {
113 std::clog << "********** Example **********" << std::endl;
114
115 ZP zp;
116
117 std::vector<std::vector<Cell_handle> > simplices = get_boundaries();
118 std::vector<Filtration_value> fils = get_filtration_values();
119 std::vector<bool> dirs = get_directions();
120
121 for (unsigned int i = 0; i < simplices.size(); ++i) {
122 if (i > 0 && dirs[i] != dirs[i - 1]) {
123 print_barcode(zp);
124 print_indices(zp);
125 }
126 if (dirs[i]) {
127 int dim = simplices[i].size() == 0 ? 0 : simplices[i].size() - 1;
128 zp.insert_cell(i, simplices[i], dim, fils[i]);
129 } else {
130 auto id = simplices[i][0];
131 zp.remove_cell(id, fils[i]);
132 }
133 }
134
135 print_barcode(zp);
136 print_indices(zp);
137
138 return 0;
139 }