summaryrefslogtreecommitdiff
path: root/src/cython/example/Simplex_tree_example.py
blob: 049b2ca46bc0c5486810aa01a20123e52a5e80f9 (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
#!/usr/bin/env python

import gudhi

st = gudhi.SimplexTree()

print("#######################################################################")
print("SimplexTree creation from insertion")
if st.insert([0,1]):
  print("Inserted !!")
else:
  print("Not inserted...")

if st.find([0,1]):
  print("Found !!")
else:
  print("Not found...")

if st.insert([0,1,2], filtration=4.0):
  print("Inserted !!")
else:
  print("Not inserted...")

# FIXME: Remove this line
st.set_dimension(3)
print("dimension=", st.dimension())

st.set_filtration(4.0)
st.initialize_filtration()
print("filtration=", st.get_filtration())
print("filtration[1,2]=", st.filtration([1,2]))
print("filtration[4,2]=", st.filtration([4,2]))

print("num_simplices=", st.num_simplices())
print("num_vertices=", st.num_vertices())

print("skeleton_tree[2]=", st.get_skeleton_tree(2))
print("skeleton_tree[1]=", st.get_skeleton_tree(1))
print("skeleton_tree[0]=", st.get_skeleton_tree(0))

print("#######################################################################")
print("SimplexTree creation from Rips")
st_from_rips = gudhi.SimplexTree(points=[[0,0],[1,0],[0,1],[1,1]],max_dimension=1,max_edge_length=42)

print("filtered_tree=", st_from_rips.get_filtered_tree())
print("star([0])=", st_from_rips.get_star_tree([0]))
print("coface([0],1)=", st_from_rips.get_coface_tree([0], 1))


print("#######################################################################")
print("MiniSimplexTree creation from insertion")
triangle012 = [0, 1, 2]
edge03 = [0, 3]
mini_st = gudhi.MiniSimplexTree()
mini_st.insert(triangle012)
mini_st.insert(edge03)
# FIXME: Remove this line
mini_st.set_dimension(2);

edge02 = [0, 2]
if mini_st.find(edge02):
  # Only coface is 012
  print("coface(edge02,1)=", mini_st.get_coface_tree(edge02, 1))

if mini_st.get_coface_tree(triangle012, 1) == []:
  # Precondition: Check the simplex has no coface before removing it.
  mini_st.remove_maximal_simplex(triangle012)

print("filtered_tree after triangle012 removal =", mini_st.get_filtered_tree())