summaryrefslogtreecommitdiff
path: root/src/Toplex_map/example/simple_toplex_map.cpp
blob: 912d79a00a21579c946a277287fd5e0c389ce0e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*    This file is part of the Gudhi Library. The Gudhi library
 *    (Geometric Understanding in Higher Dimensions) is a generic C++
 *    library for computational topology.
 *
 *    Author(s):       Vincent Rouvreau
 *
 *    Copyright (C) 2018
 *
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#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::cout << "num max simplices = " << tm.num_maximal_simplices() << " - num vertices = " << tm.num_vertices() << std::endl;

  // Browse maximal cofaces
  Simplex sigma3 = {2, 3};
  std::cout << "Maximal cofaces of {2, 3} are :" << std::endl;
  for (auto simplex_ptr : tm.maximal_cofaces(sigma3, 2)) {
    for (auto v : *simplex_ptr) {
      std::cout << v << ", ";
    }
    std::cout << std::endl;
  }

  // Browse maximal simplices
  std::cout << "Maximal simplices are :" << std::endl;
  for (auto simplex_ptr : tm.maximal_simplices()) {
    for (auto v : *simplex_ptr) {
      std::cout << v << ", ";
    }
    std::cout << std::endl;
  }

  Simplex sigma4 = {1, 3};
  assert(tm.membership(sigma4));

  Gudhi::Toplex_map::Vertex v = tm.contraction(1, 3);
  std::cout << "After contraction(1, 3) - " << v << std::endl;
  /* Simplex is:   */
  /*    2   4      */
  /*    o---o      */
  /*     \5/       */
  /*      o        */
  /*      3        */
  std::cout << "num max simplices = " << tm.num_maximal_simplices() << " - num vertices = " << tm.num_vertices() << std::endl;

  // Browse maximal simplices
  std::cout << "Maximal simplices are :" << std::endl;
  for (auto simplex_ptr : tm.maximal_simplices()) {
    for (auto v : *simplex_ptr) {
      std::cout << v << ", ";
    }
    std::cout << std::endl;
  }

  Simplex sigma5 = {3, 4};
  assert(tm.membership(sigma5));

  v = tm.contraction(3, 4);
  std::cout << "After contraction(3, 4) - " << v << std::endl;
  /* Simplex is:   */
  /*    2   4      */
  /*    o---o      */
  /*     \X/       */
  /*      o        */
  /*      5        */
  std::cout << "num max simplices = " << tm.num_maximal_simplices() << " - num vertices = " << tm.num_vertices() << std::endl;

  // Browse maximal simplices
  std::cout << "Maximal simplices are :" << std::endl;
  for (auto simplex_ptr : tm.maximal_simplices()) {
    for (auto v : *simplex_ptr) {
      std::cout << v << ", ";
    }
    std::cout << 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::cout << "After remove_simplex(1, 2, 3)" << std::endl;
  /* Simplex is:   */
  /*    2   4      */
  /*    o---o      */
  /*   / \5/       */
  /*  o---o        */
  /*  1   3        */
  std::cout << "num max simplices = " << tm.num_maximal_simplices() << " - num vertices = " << tm.num_vertices() << std::endl;

  // Browse maximal simplices
  std::cout << "Maximal simplices are :" << std::endl;
  for (auto simplex_ptr : tm.maximal_simplices()) {
    for (auto v : *simplex_ptr) {
      std::cout << v << ", ";
    }
    std::cout << std::endl;
  }

  tm.remove_vertex(1);

  std::cout << "After remove_vertex(1)" << std::endl;
  /* Simplex is:   */
  /*    2   4      */
  /*    o---o      */
  /*     \5/       */
  /*      o        */
  /*      3        */
  std::cout << "num max simplices = " << tm.num_maximal_simplices() << " - num vertices = " << tm.num_vertices() << std::endl;

  // Browse maximal simplices
  std::cout << "Maximal simplices are :" << std::endl;
  for (auto simplex_ptr : tm.maximal_simplices()) {
    for (auto v : *simplex_ptr) {
      std::cout << v << ", ";
    }
    std::cout << std::endl;
  }

  return 0;
}