TTK
Loading...
Searching...
No Matches
ProgressiveTopology.h
Go to the documentation of this file.
1
21
22#pragma once
23
24// base code includes
25#include <DynamicTree.h>
26#include <MultiresTopology.h>
27
28#include <limits>
29#include <tuple>
30
31namespace ttk {
32
37 using triplet = std::tuple<ttk::SimplexId, ttk::SimplexId, ttk::SimplexId>;
38 using polarity = unsigned char;
39
45
46 public:
47 // struct PersistencePair {
48 // /** first (lower) vertex id */
49 // ttk::SimplexId birth{};
50 // /** second (higher) vertex id */
51 // ttk::SimplexId death{};
52 // /** pair type (min-saddle: 0, saddle-saddle: 1, saddle-max: 2) */
53 // ttk::SimplexId pairType{};
54
55 // PersistencePair() = default;
56 // PersistencePair(const SimplexId b,
57 // const SimplexId d,
58 // const SimplexId pType)
59 // : birth{b}, death{d}, pairType{pType} {
60 // }
61 // };
62
64 this->setDebugMsgPrefix("ProgressiveTopology");
65 }
66
67 /* PROGRESSIVE MODE DECLARATIONS */
68 int executeCPProgressive(int computePersistenceDiagram,
69 const SimplexId *inputOffsets);
70
71 int resumeProgressive(int computePersistenceDiagram,
72 const SimplexId *offsets);
73
74 inline void setAlgorithm(int data) {
76 }
77 void setStartingDecimationLevel(int data) override {
78 if(data != startingDecimationLevel_) {
79 resumeProgressive_ = false;
80 }
81 startingDecimationLevel_ = std::max(data, 0);
82 }
83 void setStoppingDecimationLevel(int data) override {
84 if(data >= stoppingDecimationLevel_) {
85 resumeProgressive_ = false;
86 }
87 stoppingDecimationLevel_ = std::max(data, 0);
88 }
89 inline void setIsResumable(const bool b) {
90 this->isResumable_ = b;
91 if(!b) {
92 resumeProgressive_ = false;
93 }
94 }
95 void setPreallocateMemory(const bool b) override {
96 if(b != preallocateMemory_) {
97 resumeProgressive_ = false;
98 }
99 this->preallocateMemory_ = b;
100 }
101 inline void setTimeLimit(const double d) {
102 if(d <= 0.0) {
103 this->timeLimit_ = std::numeric_limits<double>::infinity();
104 } else {
105 this->timeLimit_ = d;
106 }
107 }
108
109 int computeProgressivePD(std::vector<PersistencePair> &CTDiagram,
110 const SimplexId *offsets);
111
113 std::vector<std::pair<SimplexId, char>> *criticalPoints,
114 const SimplexId *offsets);
115
116 protected:
117 void sortPersistenceDiagram2(std::vector<PersistencePair> &diagram,
118 const SimplexId *const offsets) const;
119
121 = std::array<std::vector<std::pair<SimplexId, SimplexId>>, nLink_>;
122
123 void
124 initCriticalPoints(std::vector<polarity> &isNew,
125 std::vector<std::vector<std::pair<polarity, polarity>>>
126 &vertexLinkPolarity,
127 std::vector<polarity> &toProcess,
128 std::vector<polarity> &toReprocess,
129 std::vector<DynamicTree> &link,
130 std::vector<uint8_t> &vertexLink,
131 VLBoundaryType &vertexLinkByBoundaryType,
132 std::vector<char> &vertexTypes,
133 const SimplexId *const offsets) const;
134
135 void initSaddleSeeds(std::vector<polarity> &isNew,
136 std::vector<std::vector<std::pair<polarity, polarity>>>
137 &vertexLinkPolarity,
138 std::vector<polarity> &toPropagateMin,
139 std::vector<polarity> &toPropagateMax,
140 std::vector<polarity> &toProcess,
141 std::vector<DynamicTree> &link,
142 std::vector<uint8_t> &vertexLink,
143 VLBoundaryType &vertexLinkByBoundaryType,
144 std::vector<std::vector<SimplexId>> &saddleCCMin,
145 std::vector<std::vector<SimplexId>> &saddleCCMax,
146 const SimplexId *const offsets) const;
147
148 void initPropagation(
149 std::vector<polarity> &toPropagateMin,
150 std::vector<polarity> &toPropagateMax,
151 std::vector<std::vector<SimplexId>> &vertexRepresentativesMin,
152 std::vector<std::vector<SimplexId>> &vertexRepresentativesMax,
153 std::vector<std::vector<SimplexId>> &saddleCCMin,
154 std::vector<std::vector<SimplexId>> &saddleCCMax,
155 std::vector<Lock> &vertLockMin,
156 std::vector<Lock> &vertLockMax,
157 std::vector<polarity> &isUpdatedMin,
158 std::vector<polarity> &isUpdatedMax,
159 const SimplexId *const offsets) const;
160
162 std::vector<polarity> &toPropagateMin,
163 std::vector<polarity> &toPropagateMax,
164 std::vector<std::vector<SimplexId>> &vertexRepresentativesMin,
165 std::vector<std::vector<SimplexId>> &vertexRepresentativesMax,
166 std::vector<std::vector<SimplexId>> &saddleCCMin,
167 std::vector<std::vector<SimplexId>> &saddleCCMax,
168 std::vector<Lock> &vertLockMin,
169 std::vector<Lock> &vertLockMax,
170 std::vector<polarity> &isUpdatedMin,
171 std::vector<polarity> &isUpdatedMax,
172 const SimplexId *const offsets) const;
173
174 void
175 buildVertexLinkPolarity(const SimplexId vertexId,
176 std::vector<std::pair<polarity, polarity>> &vlp,
177 const SimplexId *const offsets) const;
178
179 void sortTriplets(std::vector<triplet> &triplets,
180 const SimplexId *const offsets,
181 const bool splitTree) const;
182
184 std::vector<PersistencePair> &pairs,
185 std::vector<std::vector<SimplexId>> &vertexRepresentatives,
186 std::vector<triplet> &triplets,
187 const SimplexId *const offsets,
188 const bool splitTree) const;
189
190 void initDynamicLink(const SimplexId &vertexId,
191 std::vector<std::pair<polarity, polarity>> &vlp,
192 uint8_t &vertexLink,
193 DynamicTree &link,
194 VLBoundaryType &vlbt,
195 const SimplexId *const offsets) const;
196
198 const SimplexId globalId,
199 const std::vector<std::pair<polarity, polarity>> &vlp,
200 DynamicTree &link,
201 polarity &reprocess) const;
202
203 void
205 std::vector<std::pair<polarity, polarity>> &vlp,
206 std::vector<std::pair<SimplexId, SimplexId>> &vl) const;
207
209 std::vector<polarity> &isNew,
210 std::vector<std::vector<std::pair<polarity, polarity>>>
211 &vertexLinkPolarity,
212 std::vector<polarity> &toProcess,
213 std::vector<polarity> &toReprocess,
214 std::vector<DynamicTree> &link,
215 std::vector<uint8_t> &vertexLink,
216 VLBoundaryType &vertexLinkByBoundaryType,
217 std::vector<char> &vertexTypes,
218 const SimplexId *const offsets) const;
219
220 void
221 updateSaddleSeeds(std::vector<polarity> &isNew,
222 std::vector<std::vector<std::pair<polarity, polarity>>>
223 &vertexLinkPolarity,
224 std::vector<polarity> &toPropagateMin,
225 std::vector<polarity> &toPropagateMax,
226 std::vector<polarity> &toProcess,
227 std::vector<polarity> &toReprocess,
228 std::vector<DynamicTree> &link,
229 std::vector<uint8_t> &vertexLink,
230 VLBoundaryType &vertexLinkByBoundaryType,
231 std::vector<std::vector<SimplexId>> &saddleCCMin,
232 std::vector<std::vector<SimplexId>> &saddleCCMax,
233 std::vector<polarity> &isUpdatedMin,
234 std::vector<polarity> &isUpdatedMax,
235 const SimplexId *const offsets) const;
236
238 const SimplexId vertexId,
239 const std::vector<polarity> &isNew,
240 std::vector<polarity> &toProcess,
241 std::vector<polarity> &toReprocess,
242 std::vector<std::pair<polarity, polarity>> &vlp,
243 const SimplexId *const offsets) const;
244
245 void updateLinkPolarity(const SimplexId vertexId,
246 std::vector<std::pair<polarity, polarity>> &vlp,
247 const SimplexId *const offsets) const;
248
250 const SimplexId vertexId,
251 std::vector<Lock> &vertLock,
252 std::vector<polarity> &toPropagate,
253 std::vector<std::vector<SimplexId>> &vertexRepresentatives,
254 std::vector<std::vector<SimplexId>> &saddleCC,
255 std::vector<polarity> &isUpdated,
256 std::vector<SimplexId> &globalExtremum,
257 const SimplexId *const offsets,
258 const bool splitTree) const;
259
261 std::vector<PersistencePair> &CTDiagram,
262 const SimplexId *const offsets,
263 std::vector<std::vector<SimplexId>> &vertexRepresentativesMin,
264 std::vector<std::vector<SimplexId>> &vertexRepresentativesMax,
265 const std::vector<polarity> &toPropagateMin,
266 const std::vector<polarity> &toPropagateMax) const;
267
268 double predictNextIterationDuration(const double currItDuration,
269 const size_t nCurrPairs) const;
270
271 void stopComputationIf(const bool b);
272 void clearResumableState();
273
274 // progressive approach
276
277 // do some extra computations to allow to resume computation
278 bool isResumable_{false};
280 // time limit
281 double timeLimit_{0.0};
283
284 // keep state in case of resuming computation
285 std::vector<std::vector<SimplexId>> vertexRepresentativesMax_{},
287 std::vector<std::vector<std::pair<polarity, polarity>>>
289 std::vector<polarity> isNew_{};
290
291 std::vector<uint8_t> vertexLink_{};
293 std::vector<DynamicTree> link_{};
294 std::vector<polarity> toProcess_{};
295 std::vector<polarity> toReprocess_{};
296 std::vector<std::vector<SimplexId>> saddleCCMin_{};
297 std::vector<std::vector<SimplexId>> saddleCCMax_{};
298 std::vector<char> vertexTypes_{};
299 };
300} // namespace ttk
void setDebugMsgPrefix(const std::string &prefix)
Definition Debug.h:364
Implements the Dynamic Tree data-structure (or ST-Tree)
Definition DynamicTree.h:66
TTK processing package for progressive Topological Data Analysis.
static const size_t nLink_
TTK processing package for progressive Topological Data Analysis.
std::vector< std::vector< SimplexId > > saddleCCMin_
void sortTriplets(std::vector< triplet > &triplets, const SimplexId *const offsets, const bool splitTree) const
void setTimeLimit(const double d)
std::vector< polarity > toReprocess_
std::vector< std::vector< std::pair< polarity, polarity > > > vertexLinkPolarity_
void updateDynamicLink(DynamicTree &link, std::vector< std::pair< polarity, polarity > > &vlp, std::vector< std::pair< SimplexId, SimplexId > > &vl) const
std::vector< std::vector< SimplexId > > vertexRepresentativesMin_
std::vector< char > vertexTypes_
std::vector< polarity > isNew_
int executeCPProgressive(int computePersistenceDiagram, const SimplexId *inputOffsets)
ttk::SimplexId propagateFromSaddles(const SimplexId vertexId, std::vector< Lock > &vertLock, std::vector< polarity > &toPropagate, std::vector< std::vector< SimplexId > > &vertexRepresentatives, std::vector< std::vector< SimplexId > > &saddleCC, std::vector< polarity > &isUpdated, std::vector< SimplexId > &globalExtremum, const SimplexId *const offsets, const bool splitTree) const
std::vector< uint8_t > vertexLink_
void setStartingDecimationLevel(int data) override
void initSaddleSeeds(std::vector< polarity > &isNew, std::vector< std::vector< std::pair< polarity, polarity > > > &vertexLinkPolarity, std::vector< polarity > &toPropagateMin, std::vector< polarity > &toPropagateMax, std::vector< polarity > &toProcess, std::vector< DynamicTree > &link, std::vector< uint8_t > &vertexLink, VLBoundaryType &vertexLinkByBoundaryType, std::vector< std::vector< SimplexId > > &saddleCCMin, std::vector< std::vector< SimplexId > > &saddleCCMax, const SimplexId *const offsets) const
void initCriticalPoints(std::vector< polarity > &isNew, std::vector< std::vector< std::pair< polarity, polarity > > > &vertexLinkPolarity, std::vector< polarity > &toProcess, std::vector< polarity > &toReprocess, std::vector< DynamicTree > &link, std::vector< uint8_t > &vertexLink, VLBoundaryType &vertexLinkByBoundaryType, std::vector< char > &vertexTypes, const SimplexId *const offsets) const
void buildVertexLinkPolarity(const SimplexId vertexId, std::vector< std::pair< polarity, polarity > > &vlp, const SimplexId *const offsets) const
std::vector< polarity > toProcess_
void initDynamicLink(const SimplexId &vertexId, std::vector< std::pair< polarity, polarity > > &vlp, uint8_t &vertexLink, DynamicTree &link, VLBoundaryType &vlbt, const SimplexId *const offsets) const
void computePersistencePairsFromSaddles(std::vector< PersistencePair > &CTDiagram, const SimplexId *const offsets, std::vector< std::vector< SimplexId > > &vertexRepresentativesMin, std::vector< std::vector< SimplexId > > &vertexRepresentativesMax, const std::vector< polarity > &toPropagateMin, const std::vector< polarity > &toPropagateMax) const
std::array< std::vector< std::pair< SimplexId, SimplexId > >, nLink_ > VLBoundaryType
char getCriticalTypeFromLink(const SimplexId globalId, const std::vector< std::pair< polarity, polarity > > &vlp, DynamicTree &link, polarity &reprocess) const
void initPropagation(std::vector< polarity > &toPropagateMin, std::vector< polarity > &toPropagateMax, std::vector< std::vector< SimplexId > > &vertexRepresentativesMin, std::vector< std::vector< SimplexId > > &vertexRepresentativesMax, std::vector< std::vector< SimplexId > > &saddleCCMin, std::vector< std::vector< SimplexId > > &saddleCCMax, std::vector< Lock > &vertLockMin, std::vector< Lock > &vertLockMax, std::vector< polarity > &isUpdatedMin, std::vector< polarity > &isUpdatedMax, const SimplexId *const offsets) const
bool getMonotonyChangeByOldPointCP(const SimplexId vertexId, const std::vector< polarity > &isNew, std::vector< polarity > &toProcess, std::vector< polarity > &toReprocess, std::vector< std::pair< polarity, polarity > > &vlp, const SimplexId *const offsets) const
void updatePropagation(std::vector< polarity > &toPropagateMin, std::vector< polarity > &toPropagateMax, std::vector< std::vector< SimplexId > > &vertexRepresentativesMin, std::vector< std::vector< SimplexId > > &vertexRepresentativesMax, std::vector< std::vector< SimplexId > > &saddleCCMin, std::vector< std::vector< SimplexId > > &saddleCCMax, std::vector< Lock > &vertLockMin, std::vector< Lock > &vertLockMax, std::vector< polarity > &isUpdatedMin, std::vector< polarity > &isUpdatedMax, const SimplexId *const offsets) const
int computeProgressivePD(std::vector< PersistencePair > &CTDiagram, const SimplexId *offsets)
std::vector< std::vector< SimplexId > > saddleCCMax_
std::vector< std::vector< SimplexId > > vertexRepresentativesMax_
void setStoppingDecimationLevel(int data) override
void sortPersistenceDiagram2(std::vector< PersistencePair > &diagram, const SimplexId *const offsets) const
int resumeProgressive(int computePersistenceDiagram, const SimplexId *offsets)
void updateSaddleSeeds(std::vector< polarity > &isNew, std::vector< std::vector< std::pair< polarity, polarity > > > &vertexLinkPolarity, std::vector< polarity > &toPropagateMin, std::vector< polarity > &toPropagateMax, std::vector< polarity > &toProcess, std::vector< polarity > &toReprocess, std::vector< DynamicTree > &link, std::vector< uint8_t > &vertexLink, VLBoundaryType &vertexLinkByBoundaryType, std::vector< std::vector< SimplexId > > &saddleCCMin, std::vector< std::vector< SimplexId > > &saddleCCMax, std::vector< polarity > &isUpdatedMin, std::vector< polarity > &isUpdatedMax, const SimplexId *const offsets) const
void setIsResumable(const bool b)
double predictNextIterationDuration(const double currItDuration, const size_t nCurrPairs) const
std::vector< DynamicTree > link_
VLBoundaryType vertexLinkByBoundaryType_
void setPreallocateMemory(const bool b) override
void updateLinkPolarity(const SimplexId vertexId, std::vector< std::pair< polarity, polarity > > &vlp, const SimplexId *const offsets) const
void updateCriticalPoints(std::vector< polarity > &isNew, std::vector< std::vector< std::pair< polarity, polarity > > > &vertexLinkPolarity, std::vector< polarity > &toProcess, std::vector< polarity > &toReprocess, std::vector< DynamicTree > &link, std::vector< uint8_t > &vertexLink, VLBoundaryType &vertexLinkByBoundaryType, std::vector< char > &vertexTypes, const SimplexId *const offsets) const
void tripletsToPersistencePairs(std::vector< PersistencePair > &pairs, std::vector< std::vector< SimplexId > > &vertexRepresentatives, std::vector< triplet > &triplets, const SimplexId *const offsets, const bool splitTree) const
int computeProgressiveCP(std::vector< std::pair< SimplexId, char > > *criticalPoints, const SimplexId *offsets)
The Topology ToolKit.
std::tuple< ttk::SimplexId, ttk::SimplexId, ttk::SimplexId > triplet
Persistence pair type (with persistence in double)
unsigned char polarity
int SimplexId
Identifier type for simplices of any dimension.
Definition DataTypes.h:22