TTK
Loading...
Searching...
No Matches
DeprecatedSuperArc.h
Go to the documentation of this file.
1
2//
17
18#pragma once
19
20#include <list>
21#include <vector>
22
23#include <Debug.h>
24
25#include "DeprecatedDataTypes.h"
26#include "ExtendedUF.h"
27
28namespace ttk {
29 namespace cf {
30
31 class SuperArc {
32 private:
33 // Extrema
34 idNode downNodeId_, upNodeId_;
35 // SuperArc are in charge of interCT communication
36 idPartition downCT_, upCT_, replacantCT_;
37 // Before stitching, an arc can cross the interface below the partition.
38 // It can also cross the interface above.
39 // We keep these information
40 bool overlapBelow_, overlapAbove_;
41 // Keep th last vertex seen by this arc
42 // After the build a a merge tree, a close step is
43 // done, using this field to close each root arc
44 SimplexId lastVisited_;
45 // Stat of this arc, if replaced...
46 ComponentState state_;
47 // ... use this field to know by which other arc.
48 // Caution, we do not want chained replacant !
49 idSuperArc replacantId_;
50
51 // Regular nodes in this arc
52 // Vector for initialisation only (mergetree::build & simplify)
53 // Use vertList and sizeVertList_ to access Arc's vertices after combine
54 std::vector<std::pair<SimplexId, bool>> vertices_;
55 // initialized with vertices_.data() and vertices_.size()
56 // these two variable allow to split the segmentation when
57 // inserting node in the arc without moving memory
58 // |------------| Arc
59 // [............] Size N
60 //
61 // |---*--------| Arc with new node
62 // [..][........] Size N1 + N2 = N
63 // So we split static array with a2 = a1 + N1
64 //
65 // It works because vertices are sorted by construction in these arrays
66
67 // Array version, also Retain masqued regular nodes :
68 // when a node is removed from an arc of a tree,
69 // we mark as masqed vertices that are in the arc we added in CT
70 // and also in the staying arc to avoid duplicate.
71 // _/!\_ used at combine time => create this array using sizeVertList_
72 std::pair<SimplexId, bool> *vertList_;
73 // The size of *vertList_
74 SimplexId sizeVertList_;
75#ifndef TTK_ENABLE_KAMIKAZE
76 // add a size verification for global simplify step
77 SimplexId allocSgm_ = -1;
78#endif
79
80 public:
81 // CONSTRUCT
82 // -----------------
83 // {
84 SuperArc(const idNode &d,
85 const idNode &u,
86 const bool overB,
87 const bool overA,
88 const unsigned char &ctd = 0,
89 const unsigned char &ctu = 0,
90 const size_t &resv = 0ul,
92 : downNodeId_(d), upNodeId_(u), downCT_(ctd), upCT_(ctu),
93 overlapBelow_(overB), overlapAbove_(overA), lastVisited_(nullVertex),
94 state_(state), replacantId_(nullSuperArc), vertList_(nullptr),
95 sizeVertList_(-1) {
96 vertices_.reserve(resv);
97 }
98
99 // }
100 // ------------------
101 // ACCESSOR
102 // --------------------
103 // {
104 //
105 // node
106 // .................................{
107
108 inline const idNode &getUpNodeId() const {
109 return upNodeId_;
110 }
111
112 inline const idNode &getDownNodeId() const {
113 return downNodeId_;
114 }
115
116 inline void setUpNodeId(const idNode &upId) {
117 upNodeId_ = upId;
118 }
119
120 inline void setDownNodeId(const idNode &downId) {
121 downNodeId_ = downId;
122 }
123
124 // }
125 // tree
126 // .................................{
127 //
128 // idPartition u_char so lighter than a ref
129 inline idPartition getDownCT() const {
130 return downCT_;
131 }
132
133 inline idPartition getUpCT() const {
134 return upCT_;
135 }
136
137 inline void setUpCT(decltype(upCT_) &ct) {
138 upCT_ = ct;
139 }
140
141 // }
142 // overlap
143 // .................................{
144
145 inline bool getOverlapAbove() const {
146 return overlapAbove_;
147 }
148
149 inline bool getOverlapBelow() const {
150 return overlapBelow_;
151 }
152
153 inline bool isCrossing() const {
154 return overlapBelow_ || overlapAbove_;
155 }
156
157 inline void setOverlapAbove(const bool local_overlapAbove) {
158 overlapAbove_ = local_overlapAbove;
159 }
160
161 inline void setOverlapBelow(const bool local_overlapBelow) {
162 overlapBelow_ = local_overlapBelow;
163 }
164
165 // }
166 // last vertex seen
167 // .................................{
168
169 inline const SimplexId &getLastVisited() const {
170 return lastVisited_;
171 }
172
173 inline void setLastVisited(const SimplexId &vertId) {
174 lastVisited_ = vertId;
175 vertices_.emplace_back(vertId, false);
176 }
177
178 // }
179 // state
180 // .................................{
181
182 inline bool isHidden() const {
183 return state_ == ComponentState::Hidden;
184 }
185
186 inline bool isPruned() const {
187 return state_ == ComponentState::Merged;
188 }
189
190 inline bool isMerged() const {
191 return state_ == ComponentState::Merged;
192 }
193
194 inline bool isExternal() const {
195 return downCT_ != upCT_;
196 }
197
198 inline bool isVisible() const {
199 return state_ == ComponentState::Visible;
200 }
201
202 inline void hide() {
203 state_ = ComponentState::Hidden;
204 }
205
206 inline void merge(const idSuperArc &arc, const idPartition ct = 255) {
207 replacantCT_ = (ct == 255) ? upCT_ : ct;
208 replacantId_ = arc;
209 state_ = ComponentState::Merged;
210 }
211
212 // }
213 // replacant arc/tree (merge)
214 // .................................{
215
216 inline const idSuperArc &getReplacantArcId() const {
217 return replacantId_;
218 }
219
221 return replacantCT_;
222 }
223
224 // }
225 // regular nodes (segmentation)
226 // .................................{
227
229 return getVertSize();
230 }
231
232 inline const SimplexId &getRegularNodeId(const SimplexId &idx) {
233 return getVertList()[idx].first;
234 }
235
236 inline bool isMasqued(const SimplexId &v) const {
237 return vertList_[v].second;
238 }
239
240 // The std::vector
241
243 return vertices_.size();
244 }
245
246 // not const for sort in simplify
247 inline std::vector<std::pair<SimplexId, bool>> &getSegmentation() {
248 return vertices_;
249 }
250
251 // The array
252
253 inline std::pair<SimplexId, bool> *getVertList() {
254 if(sizeVertList_ == -1) {
255 vertList_ = vertices_.data();
256 sizeVertList_ = vertices_.size();
257 }
258 return vertList_;
259 }
260
261 inline const SimplexId &getVertSize() {
262 if(sizeVertList_ == -1) {
263 vertList_ = vertices_.data();
264 sizeVertList_ = vertices_.size();
265 }
266 return sizeVertList_;
267 }
268
269 inline void setMasqued(const SimplexId &v) {
270 vertList_[v].second = true;
271 }
272
273 inline void setVertList(std::pair<SimplexId, bool> *vl) {
274 vertList_ = vl;
275 }
276
277 inline void setVertSize(const SimplexId &s) {
278 sizeVertList_ = s;
279 }
280
281 // append regular nodes :
282
283 // From array : alloc should be already done
284 inline void appendVertLists(
285 const std::list<std::pair<SimplexId, bool> *> &vertLists,
286 std::list<SimplexId> vertSizes,
287 std::list<std::vector<std::pair<SimplexId, bool>>> &storage,
288 const SimplexId &totalSize) {
289 // size local
290 SimplexId newSize = sizeVertList_;
291 if(newSize == -1)
292 newSize = 0;
293
294 // size added
295 newSize += totalSize;
296
297 // alloc
298 std::pair<SimplexId, bool> *tmpVert{};
299#ifdef TTK_ENABLE_OPENMP
300#pragma omp critical
301#endif // TTK_ENABLE_OPENMP
302 {
303 storage.emplace_back(newSize);
304 tmpVert = storage.back().data();
305 }
306 SimplexId pos = 0;
307
308 // values local
309 for(SimplexId i = 0; i < sizeVertList_; ++i) {
310 tmpVert[pos++] = vertList_[i];
311 }
312
313 // values added
314 for(std::pair<SimplexId, bool> *vertices : vertLists) {
315 const SimplexId size = vertSizes.front();
316 vertSizes.pop_front();
317 for(SimplexId i = 0; i < size; ++i) {
318 tmpVert[pos++] = vertices[i];
319 }
320 }
321
322 // set values
323 vertList_ = tmpVert;
324 sizeVertList_ = newSize;
325 }
326
327 // From array : alloc should be already done (check boundary no kamikaze
328 // only)
329 inline int addSegmentationGlobal(const std::pair<SimplexId, bool> *arr,
330 const SimplexId &size) {
331
332#ifndef TTK_ENABLE_KAMIKAZE
333 // cout << "size " << sizeVertList_ << " add " << size << " on " <<
334 // allocSgm_ << std::endl;
335 if(sizeVertList_ + size >= allocSgm_) {
336 std::cerr << "SEGMENTATION SIZE PROBLEM :" << std::endl;
337 std::cerr << "alloc : " << allocSgm_ << std::endl;
338 std::cerr << "size : " << sizeVertList_ << std::endl;
339 std::cerr << "add : " << size << std::endl;
340 // gdb
341 return 1;
342 }
343#endif
344
345 for(SimplexId v = 0; v < size; v++) {
346 if(!arr[v].second) {
347 vertList_[sizeVertList_++] = arr[v];
348 }
349 }
350
351 return 0;
352 }
353
354 // from std::vector
356 const std::vector<std::pair<SimplexId, bool>> &other) {
357 vertices_.insert(vertices_.end(), other.begin(), other.end());
358 }
359
360 // from std::vector with a move
361 inline void
362 setVertices(std::vector<std::pair<SimplexId, bool>>::iterator &a,
363 std::vector<std::pair<SimplexId, bool>>::iterator b) {
364 vertices_.insert(
365 vertices_.end(), make_move_iterator(a), make_move_iterator(b));
366 }
367
368 // add one vertex, alloc should be already done
369 inline void addSegmentationGlobal(const SimplexId &v) {
370 vertList_[sizeVertList_++] = std::make_pair(v, false);
371 }
372
373 // }
374
375 // }
376 // -----------
377 // RESERVE
378 // ----------
379 // {
380 // Trick
381 // During simplification we use sizeVertList to keep the number of
382 // vertices that will merge in
383 // materArc
384 // Doing so we ensure we have only one reserve on the std::vector
385 // At the end, we set sizeVertList_ back to minus one for normal
386 // utilisation.
387
388 inline void addFuturReserve(const SimplexId &nb) {
389 sizeVertList_ += nb;
390 // We have an offset of -1 due to the initial value of sizeVertList_
391 }
392
393 inline void makeAllocGlobal(
394 const SimplexId &size,
395 std::list<std::vector<std::pair<SimplexId, bool>>> &storage) {
396#ifdef TTK_ENABLE_OPENMP
397#pragma omp critical
398#endif // TTK_ENABLE_OPENMP
399 {
400 storage.emplace_back(size);
401 vertList_ = storage.back().data();
402 }
403 sizeVertList_ = 0;
404#ifndef TTK_ENABLE_KAMIKAZE
405 allocSgm_ = size;
406#endif
407 }
408
409 // Real reserve
410 inline void makeReserve() {
411 if(sizeVertList_ != -1) {
412 // We have an offset of -1 due to the initial value of sizeVertList_
413 vertices_.reserve(sizeVertList_ + 1);
414 sizeVertList_ = -1;
415 }
416 }
417
418 //}
419 };
420 } // namespace cf
421} // namespace ttk
idPartition getDownCT() const
bool isMasqued(const SimplexId &v) const
const idNode & getUpNodeId() const
SimplexId getSegmentationSize() const
void setOverlapBelow(const bool local_overlapBelow)
void setUpCT(decltype(upCT_) &ct)
const SimplexId & getVertSize()
SimplexId getNumberOfRegularNodes()
const SimplexId & getRegularNodeId(const SimplexId &idx)
void setVertices(std::vector< std::pair< SimplexId, bool > >::iterator &a, std::vector< std::pair< SimplexId, bool > >::iterator b)
int addSegmentationGlobal(const std::pair< SimplexId, bool > *arr, const SimplexId &size)
void appendSegmentation(const std::vector< std::pair< SimplexId, bool > > &other)
void setOverlapAbove(const bool local_overlapAbove)
void setLastVisited(const SimplexId &vertId)
idPartition getReplacantCT() const
std::vector< std::pair< SimplexId, bool > > & getSegmentation()
void setMasqued(const SimplexId &v)
void setDownNodeId(const idNode &downId)
std::pair< SimplexId, bool > * getVertList()
const SimplexId & getLastVisited() const
void merge(const idSuperArc &arc, const idPartition ct=255)
bool getOverlapBelow() const
void addFuturReserve(const SimplexId &nb)
void makeAllocGlobal(const SimplexId &size, std::list< std::vector< std::pair< SimplexId, bool > > > &storage)
void setVertList(std::pair< SimplexId, bool > *vl)
void appendVertLists(const std::list< std::pair< SimplexId, bool > * > &vertLists, std::list< SimplexId > vertSizes, std::list< std::vector< std::pair< SimplexId, bool > > > &storage, const SimplexId &totalSize)
void addSegmentationGlobal(const SimplexId &v)
void setVertSize(const SimplexId &s)
const idSuperArc & getReplacantArcId() const
const idNode & getDownNodeId() const
void setUpNodeId(const idNode &upId)
idPartition getUpCT() const
bool getOverlapAbove() const
SuperArc(const idNode &d, const idNode &u, const bool overB, const bool overA, const unsigned char &ctd=0, const unsigned char &ctu=0, const size_t &resv=0ul, const ComponentState &state=ComponentState::Visible)
numThread idPartition
long unsigned int idSuperArc
SuperArc index in vect_superArcs_.
unsigned int idNode
Node index in vect_nodes_.
The Topology ToolKit.
int SimplexId
Identifier type for simplices of any dimension.
Definition DataTypes.h:22