-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimplex_coboundary_enumerator.cpp
142 lines (125 loc) · 4.07 KB
/
simplex_coboundary_enumerator.cpp
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
/* simplex_coboundary_enumerator.cpp
Copyright 2017-2018 Takeki Sudo and Kazushi Ahara.
This file is part of CubicalRipser_2dim.
CubicalRipser: C++ system for computation of Cubical persistence pairs
Copyright 2017-2018 Takeki Sudo and Kazushi Ahara.
CubicalRipser is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your option)
any later version.
CubicalRipser is deeply depending on 'Ripser', software for Vietoris-Rips
persitence pairs by Ulrich Bauer, 2015-2016. We appreciate Ulrich very much.
We rearrange his codes of Ripser and add some new ideas for optimization on it
and modify it for calculation of a Cubical filtration.
This part of CubicalRiper is a calculator of cubical persistence pairs for
2 dimensional pixel data. The input data format conforms to that of DIPHA.
See more descriptions in README.
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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <algorithm>
#include <string>
#include "dense_cubical_grids.h"
#include "birthday_index.h"
#include "columns_to_reduce.h"
#include "simplex_coboundary_enumerator.h"
SimplexCoboundaryEnumerator::SimplexCoboundaryEnumerator(){
nextCoface = BirthdayIndex(0, -1, 1);
}
void SimplexCoboundaryEnumerator::setSimplexCoboundaryEnumerator(BirthdayIndex _s, DenseCubicalGrids* _dcg) {
simplex = _s;
dcg = _dcg;
dim = simplex.dim;
birthtime = simplex.birthday;
ax = _dcg->ax;
ay = _dcg->ay;
cx = (simplex.index) & 0x07ff;
cy = (simplex.index >> 11) & 0x03ff;
cm = (simplex.index >> 21) & 0xff;
threshold = _dcg->threshold;
count = 0;
}
bool SimplexCoboundaryEnumerator::hasNextCoface() {
int index = 0;
double birthday = 0;
switch (dim) {
case 0:
for (int i = count; i < 4; i++) {
switch(i){
case 0: // y+
index = (1 << 21) | ((cy) << 11) | (cx);
birthday = max(birthtime, dcg->dense2[cx ][cy+1]);
break;
case 1: // y-
index = (1 << 21) | ((cy-1) << 11) | (cx);
birthday = max(birthtime, dcg->dense2[cx ][cy-1]);
break;
case 2: // x+
index = (0 << 21) | ((cy) << 11) | (cx);
birthday = max(birthtime, dcg->dense2[cx+1][cy ]);
break;
case 3: // x-
index = (0 << 21) | ((cy) << 11) | (cx-1);
birthday = max(birthtime, dcg->dense2[cx-1][cy ]);
break;
}
if (birthday != threshold) {
count = i + 1;
nextCoface = BirthdayIndex(birthday, index, 1);
return true;
}
}
return false;
case 1:
switch (cm) {
case 0:
if(count == 0){ // upper
count++;
index = ((cy) << 11) | cx;
birthday = max({birthtime, dcg->dense2[cx][cy + 1], dcg->dense2[cx + 1][cy + 1]});
if (birthday != threshold) {
nextCoface = BirthdayIndex(birthday, index, 2);
return true;
}
}
if(count == 1){ // lower
count++;
index = ((cy - 1) << 11) | cx;
birthday = max({birthtime, dcg->dense2[cx][cy - 1], dcg->dense2[cx + 1][cy - 1]});
if (birthday != threshold) {
nextCoface = BirthdayIndex(birthday, index, 2);
return true;
}
}
return false;
case 1:
if(count == 0){ // right
count ++;
index = ((cy) << 11) | cx;
birthday = max({birthtime, dcg->dense2[cx + 1][cy], dcg->dense2[cx + 1][cy + 1]});
if (birthday != threshold) {
nextCoface = BirthdayIndex(birthday, index, 2);
return true;
}
}
if(count == 1){ //left
count++;
index = ((cy) << 11) | (cx - 1);
birthday = max({birthtime, dcg->dense2[cx - 1][cy], dcg->dense2[cx - 1][cy + 1]});
if (birthday != threshold) {
nextCoface = BirthdayIndex(birthday, index, 2);
return true;
}
}
return false;
}
}
return false;
}
BirthdayIndex SimplexCoboundaryEnumerator::getNextCoface() {
return nextCoface;
}