Loading...
Searching...
No Matches
simple_toplex_map.cpp

# Collapse

/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
* See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
* Author(s): Vincent Rouvreau
*
* Copyright (C) 2018
*
* Modification(s):
* - YYYY/MM Author: Description of the modification
*/
#include <gudhi/Toplex_map.h>
#include <iostream>
#include <utility> // for pair
#include <vector>
#include <cassert>
int main(int argc, char* const argv[]) {
using Simplex = Gudhi::Toplex_map::Simplex;
Simplex sigma1 = {1, 2, 3};
Simplex sigma2 = {2, 3, 4, 5};
Gudhi::Toplex_map tm;
tm.insert_simplex(sigma1);
tm.insert_simplex(sigma2);
/* Simplex is: */
/* 2 4 */
/* o---o */
/* /X\5/ */
/* o---o */
/* 1 3 */
std::clog << "num max simplices = " << tm.num_maximal_simplices() << " - num vertices = " << tm.num_vertices()
<< std::endl;
// Browse maximal cofaces
Simplex sigma3 = {2, 3};
std::clog << "Maximal cofaces of {2, 3} are :" << std::endl;
for (auto simplex_ptr : tm.maximal_cofaces(sigma3, 2)) {
for (auto v : *simplex_ptr) {
std::clog << v << ", ";
}
std::clog << std::endl;
}
// Browse maximal simplices
std::clog << "Maximal simplices are :" << std::endl;
for (auto simplex_ptr : tm.maximal_simplices()) {
for (auto v : *simplex_ptr) {
std::clog << v << ", ";
}
std::clog << std::endl;
}
Simplex sigma4 = {1, 3};
assert(tm.membership(sigma4));
Gudhi::Toplex_map::Vertex v = tm.contraction(1, 3);
std::clog << "After contraction(1, 3) - " << v << std::endl;
/* Simplex is: */
/* 2 4 */
/* o---o */
/* \5/ */
/* o */
/* 3 */
std::clog << "num max simplices = " << tm.num_maximal_simplices() << " - num vertices = " << tm.num_vertices()
<< std::endl;
// Browse maximal simplices
std::clog << "Maximal simplices are :" << std::endl;
for (auto simplex_ptr : tm.maximal_simplices()) {
for (auto v : *simplex_ptr) {
std::clog << v << ", ";
}
std::clog << std::endl;
}
Simplex sigma5 = {3, 4};
assert(tm.membership(sigma5));
v = tm.contraction(3, 4);
std::clog << "After contraction(3, 4) - " << v << std::endl;
/* Simplex is: */
/* 2 4 */
/* o---o */
/* \X/ */
/* o */
/* 5 */
std::clog << "num max simplices = " << tm.num_maximal_simplices() << " - num vertices = " << tm.num_vertices()
<< std::endl;
// Browse maximal simplices
std::clog << "Maximal simplices are :" << std::endl;
for (auto simplex_ptr : tm.maximal_simplices()) {
for (auto v : *simplex_ptr) {
std::clog << v << ", ";
}
std::clog << std::endl;
}
tm.insert_simplex(sigma1);
tm.insert_simplex(sigma2);
/* Simplex is: */
/* 2 4 */
/* o---o */
/* /X\5/ */
/* o---o */
/* 1 3 */
tm.remove_simplex(sigma1);
std::clog << "After remove_simplex(1, 2, 3)" << std::endl;
/* Simplex is: */
/* 2 4 */
/* o---o */
/* / \5/ */
/* o---o */
/* 1 3 */
std::clog << "num max simplices = " << tm.num_maximal_simplices() << " - num vertices = " << tm.num_vertices()
<< std::endl;
// Browse maximal simplices
std::clog << "Maximal simplices are :" << std::endl;
for (auto simplex_ptr : tm.maximal_simplices()) {
for (auto v : *simplex_ptr) {
std::clog << v << ", ";
}
std::clog << std::endl;
}
tm.remove_vertex(1);
std::clog << "After remove_vertex(1)" << std::endl;
/* Simplex is: */
/* 2 4 */
/* o---o */
/* \5/ */
/* o */
/* 3 */
std::clog << "num max simplices = " << tm.num_maximal_simplices() << " - num vertices = " << tm.num_vertices()
<< std::endl;
// Browse maximal simplices
std::clog << "Maximal simplices are :" << std::endl;
for (auto simplex_ptr : tm.maximal_simplices()) {
for (auto v : *simplex_ptr) {
std::clog << v << ", ";
}
std::clog << std::endl;
}
return 0;
}
Gudhi::Toplex_map
Toplex map data structure for representing unfiltered simplicial complexes.
Definition Toplex_map.h:29
Gudhi::Toplex_map::maximal_cofaces
Toplex_map::Simplex_ptr_set maximal_cofaces(const Input_vertex_range &vertex_range, const std::size_t max_number=0) const
Definition Toplex_map.h:187
Gudhi::Toplex_map::remove_vertex
void remove_vertex(const Vertex x)
Definition Toplex_map.h:253
Gudhi::Toplex_map::maximal_simplices
Toplex_map::Simplex_ptr_set maximal_simplices(const std::size_t max_number=0) const
Definition Toplex_map.h:78
Gudhi::Toplex_map::num_vertices
std::size_t num_vertices() const
Number of vertices.
Definition Toplex_map.h:94
Gudhi::Toplex_map::num_maximal_simplices
std::size_t num_maximal_simplices() const
Number of maximal simplices.
Definition Toplex_map.h:91
Gudhi::Toplex_map::membership
bool membership(const Input_vertex_range &vertex_range) const
Definition Toplex_map.h:169
Gudhi::Toplex_map::contraction
Vertex contraction(const Vertex x, const Vertex y)
Definition Toplex_map.h:211
Gudhi::Toplex_map::remove_simplex
void remove_simplex(const Input_vertex_range &vertex_range)
Removes the given simplex and its cofaces from the complex. Its faces are kept inside.
Definition Toplex_map.h:151
Gudhi::Toplex_map::Simplex
std::set< Vertex > Simplex
Definition Toplex_map.h:35
Gudhi::Toplex_map::Vertex
std::size_t Vertex
Definition Toplex_map.h:32
Gudhi::Toplex_map::insert_simplex
void insert_simplex(const Input_vertex_range &vertex_range)
Adds the given simplex to the complex. Nothing happens if the simplex is already in the complex (i....
Definition Toplex_map.h:130