| 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): Vincent Rouvreau |
| 4 |
* |
| 5 |
* Copyright (C) 2014 Inria |
| 6 |
* |
| 7 |
* Modification(s): |
| 8 |
* - YYYY/MM Author: Description of the modification |
| 9 |
*/ |
| 10 |
|
| 11 |
#include <gudhi/graph_simplicial_complex.h> |
| 12 |
#include <gudhi/Simplex_tree.h> |
| 13 |
#include <gudhi/Persistent_cohomology.h> |
| 14 |
|
| 15 |
#include <iostream> |
| 16 |
#include <ctime> |
| 17 |
#include <utility> |
| 18 |
#include <vector> |
| 19 |
|
| 20 |
// Types definition |
| 21 |
using Simplex_tree = Gudhi::Simplex_tree<>; |
| 22 |
using Filtration_value = Simplex_tree::Filtration_value; |
| 23 |
using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; |
| 24 |
using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology<Simplex_tree, Field_Zp >; |
| 25 |
using typeVectorVertex = std::vector< Simplex_tree::Vertex_handle >; |
| 26 |
|
| 27 |
void usage(char * const progName) { |
| 28 |
std::cerr << "Usage: " << progName << " coeff_field_characteristic[integer > 0] min_persistence[float >= -1.0]\n"; |
| 29 |
exit(-1); |
| 30 |
} |
| 31 |
|
| 32 |
int main(int argc, char * const argv[]) { |
| 33 |
// program args management |
| 34 |
if (argc != 3) { |
| 35 |
std::cerr << "Error: Number of arguments (" << argc << ") is not correct\n"; |
| 36 |
usage(argv[0]); |
| 37 |
} |
| 38 |
|
| 39 |
int coeff_field_characteristic = 0; |
| 40 |
int returnedScanValue = sscanf(argv[1], "%d", &coeff_field_characteristic); |
| 41 |
if ((returnedScanValue == EOF) || (coeff_field_characteristic <= 0)) { |
| 42 |
std::cerr << "Error: " << argv[1] << " is not correct\n"; |
| 43 |
usage(argv[0]); |
| 44 |
} |
| 45 |
|
| 46 |
Filtration_value min_persistence = 0.0; |
| 47 |
returnedScanValue = sscanf(argv[2], "%lf", &min_persistence); |
| 48 |
if ((returnedScanValue == EOF) || (min_persistence < -1.0)) { |
| 49 |
std::cerr << "Error: " << argv[2] << " is not correct\n"; |
| 50 |
usage(argv[0]); |
| 51 |
} |
| 52 |
|
| 53 |
// TEST OF INSERTION |
| 54 |
std::clog << "********************************************************************" << std::endl; |
| 55 |
std::clog << "TEST OF INSERTION" << std::endl; |
| 56 |
Simplex_tree st; |
| 57 |
|
| 58 |
// ++ FIRST |
| 59 |
std::clog << " - INSERT (0,1,2)" << std::endl; |
| 60 |
typeVectorVertex SimplexVector = {0, 1, 2}; |
| 61 |
st.insert_simplex_and_subfaces(SimplexVector, 0.3); |
| 62 |
|
| 63 |
// ++ SECOND |
| 64 |
std::clog << " - INSERT 3" << std::endl; |
| 65 |
SimplexVector = {3}; |
| 66 |
st.insert_simplex_and_subfaces(SimplexVector, 0.1); |
| 67 |
|
| 68 |
// ++ THIRD |
| 69 |
std::clog << " - INSERT (0,3)" << std::endl; |
| 70 |
SimplexVector = {0, 3}; |
| 71 |
st.insert_simplex_and_subfaces(SimplexVector, 0.2); |
| 72 |
|
| 73 |
// ++ FOURTH |
| 74 |
std::clog << " - INSERT (0,1) (already inserted)" << std::endl; |
| 75 |
SimplexVector = {0, 1}; |
| 76 |
st.insert_simplex_and_subfaces(SimplexVector, 0.2); |
| 77 |
|
| 78 |
// ++ FIFTH |
| 79 |
std::clog << " - INSERT (3,4,5)" << std::endl; |
| 80 |
SimplexVector = {3, 4, 5}; |
| 81 |
st.insert_simplex_and_subfaces(SimplexVector, 0.3); |
| 82 |
|
| 83 |
// ++ SIXTH |
| 84 |
std::clog << " - INSERT (0,1,6,7)" << std::endl; |
| 85 |
SimplexVector = {0, 1, 6, 7}; |
| 86 |
st.insert_simplex_and_subfaces(SimplexVector, 0.4); |
| 87 |
|
| 88 |
// ++ SEVENTH |
| 89 |
std::clog << " - INSERT (4,5,8,9)" << std::endl; |
| 90 |
SimplexVector = {4, 5, 8, 9}; |
| 91 |
st.insert_simplex_and_subfaces(SimplexVector, 0.4); |
| 92 |
|
| 93 |
// ++ EIGHTH |
| 94 |
std::clog << " - INSERT (9,10,11)" << std::endl; |
| 95 |
SimplexVector = {9, 10, 11}; |
| 96 |
st.insert_simplex_and_subfaces(SimplexVector, 0.3); |
| 97 |
|
| 98 |
// ++ NINTH |
| 99 |
std::clog << " - INSERT (2,10,12)" << std::endl; |
| 100 |
SimplexVector = {2, 10, 12}; |
| 101 |
st.insert_simplex_and_subfaces(SimplexVector, 0.3); |
| 102 |
|
| 103 |
// ++ TENTH |
| 104 |
std::clog << " - INSERT (11,6)" << std::endl; |
| 105 |
SimplexVector = {6, 11}; |
| 106 |
st.insert_simplex_and_subfaces(SimplexVector, 0.2); |
| 107 |
|
| 108 |
// ++ ELEVENTH |
| 109 |
std::clog << " - INSERT (13,14,15)" << std::endl; |
| 110 |
SimplexVector = {13, 14, 15}; |
| 111 |
st.insert_simplex_and_subfaces(SimplexVector, 0.25); |
| 112 |
|
| 113 |
/* Inserted simplex: */ |
| 114 |
/* 1 6 */ |
| 115 |
/* o---o */ |
| 116 |
/* /X\7/ 4 2 */ |
| 117 |
/* o---o---o---o o */ |
| 118 |
/* 2 0 3\X/8\ 10 /X\ */ |
| 119 |
/* o---o---o---o */ |
| 120 |
/* 5 9\X/ 12 */ |
| 121 |
/* o---o */ |
| 122 |
/* 11 6 */ |
| 123 |
/* In other words: */ |
| 124 |
/* A facet [2,1,0] */ |
| 125 |
/* An edge [0,3] */ |
| 126 |
/* A facet [3,4,5] */ |
| 127 |
/* A cell [0,1,6,7] */ |
| 128 |
/* A cell [4,5,8,9] */ |
| 129 |
/* A facet [9,10,11] */ |
| 130 |
/* An edge [11,6] */ |
| 131 |
/* An edge [10,12,2] */ |
| 132 |
|
| 133 |
|
| 134 |
std::clog << "The complex contains " << st.num_simplices() << " simplices - " << st.num_vertices() << " vertices " |
| 135 |
<< std::endl; |
| 136 |
std::clog << " - dimension " << st.dimension() << std::endl; |
| 137 |
std::clog << std::endl << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:" |
| 138 |
<< std::endl; |
| 139 |
std::clog << "**************************************************************" << std::endl; |
| 140 |
std::clog << "strict graph G { " << std::endl; |
| 141 |
|
| 142 |
for (auto f_simplex : st.filtration_simplex_range()) { |
| 143 |
std::clog << " " << "[" << st.filtration(f_simplex) << "] "; |
| 144 |
for (auto vertex : st.simplex_vertex_range(f_simplex)) { |
| 145 |
std::clog << static_cast<int>(vertex) << " -- "; |
| 146 |
} |
| 147 |
std::clog << ";" << std::endl; |
| 148 |
} |
| 149 |
|
| 150 |
std::clog << "}" << std::endl; |
| 151 |
std::clog << "**************************************************************" << std::endl; |
| 152 |
|
| 153 |
// Compute the persistence diagram of the complex |
| 154 |
Persistent_cohomology pcoh(st); |
| 155 |
// initializes the coefficient field for homology |
| 156 |
pcoh.init_coefficients(coeff_field_characteristic); |
| 157 |
|
| 158 |
pcoh.compute_persistent_cohomology(min_persistence); |
| 159 |
|
| 160 |
// Output the diagram in filediag |
| 161 |
pcoh.output_diagram(); |
| 162 |
return 0; |
| 163 |
} |