TTK
Loading...
Searching...
No Matches
FTRPropagation.h
Go to the documentation of this file.
1
12
13#pragma once
14
15// local include
16#include "FTRAtomicUF.h"
17#include "FTRCommon.h"
18
19// base code includes
20#include <Triangulation.h>
21
22// library include
23#include <boost/heap/fibonacci_heap.hpp>
24
25// C++ includes
26#include <deque>
27#include <unordered_map>
28
29namespace ttk {
30 namespace ftr {
32 private:
33 // cache current simplex
34 idVertex curVert_;
35 idSuperArc nbArcs_;
36
37 // comparison function
38 VertCompFN comp_;
39 // come from min/max leaf
40 bool goUp_;
41
42 // priority deque
43 boost::heap::fibonacci_heap<idVertex, boost::heap::compare<VertCompFN>>
44 propagation_;
45
46 // representant (pos in array)
47 AtomicUF id_;
48
49 public:
50 Propagation(idVertex startVert, const VertCompFN &vertComp, bool up)
51 : curVert_{nullVertex}, nbArcs_{1}, comp_{vertComp}, goUp_{up},
52 propagation_{vertComp}, id_{this} {
53 propagation_.emplace(startVert);
54 }
55
56 Propagation(const Propagation &other) = delete;
57
59 return curVert_;
60 }
61
62 // used to avoid the fibonacci heaps the local propagation is only
63 // used to store comp and current vert during a sequential pass using
64 // the reference alforithm and so it's a mock propagation used for
65 // compliance with the rest of the code
66 void setCurvert(const idVertex v) {
67 curVert_ = v;
68 }
69
71 return nbArcs_;
72 }
73
74 void moreArc(const idSuperArc a = 1) {
75 nbArcs_ += a;
76 // std::cout << " - new nb arc " << nbArcs_ << " added " << a <<
77 // std::endl;
78 }
79
80 void lessArc(const idSuperArc a = 1) {
81 nbArcs_ -= a;
82 // std::cout << " - new nb arc " << nbArcs_ << " removed " << a <<
83 // std::endl;
84 }
85
87 return id_.find();
88 }
89
91 curVert_ = propagation_.top();
92 removeDuplicates(curVert_);
93 return curVert_;
94 }
95
97#ifndef TTK_ENABLE_KAMIKAZE
98 if(propagation_.empty()) {
99 std::cerr << "[FTR]: Propagation get next on empty structure"
100 << std::endl;
101 return nullVertex;
102 }
103#endif
104 return propagation_.top();
105 }
106
108 while(!propagation_.empty() && propagation_.top() == d) {
109 propagation_.pop();
110 }
111 }
112
113 void removeBelow(const idVertex d, const VertCompFN &comp) {
114 while(!propagation_.empty() && comp(propagation_.top(), d)) {
115 propagation_.pop();
116 }
117 }
118
119 void addNewVertex(const idVertex v) {
120 propagation_.emplace(v);
121 }
122
123 void merge(Propagation &other) {
124 if(&other == this)
125 return;
126 propagation_.merge(other.propagation_);
127 AtomicUF::makeUnion(&id_, &other.id_);
128 nbArcs_ += other.nbArcs_;
129 // std::cout << " ~ new nb arc " << nbArcs_ << " added " <<
130 // other.nbArcs_ << std::endl;
131 // TODO once after all the merge ?
132 id_.find()->setPropagation(this);
133 }
134
135 bool empty() const {
136 return propagation_.empty();
137 }
138
139 void clear() {
140 propagation_.clear();
141 }
142
147 bool compare(const idVertex a, const idVertex b) const {
148 return comp_(b, a);
149 }
150
151 // true if propagation initiated form a min leaf
152 bool goUp() const {
153 return goUp_;
154 }
155
156 bool goDown() const {
157 return !goUp_;
158 }
159
160 // DEBUG ONLY
161
162 bool find(idVertex v) const {
163 return std::find(propagation_.begin(), propagation_.end(), v)
164 != propagation_.end();
165 }
166
167 std::size_t size() const {
168 return propagation_.size();
169 }
170
171 std::string print() const {
172 std::stringstream res;
173 res << " localProp " << curVert_ << " : ";
174#ifndef NDEBUG
175 // only if perf are not important: copy
176 boost::heap::fibonacci_heap<idVertex, boost::heap::compare<VertCompFN>>
177 tmp(propagation_);
178 while(!tmp.empty()) {
179 res << tmp.top() << " ";
180 tmp.pop();
181 }
182#else
183 res << "...";
184#endif
185 return res.str();
186 }
187 };
188 } // namespace ftr
189} // namespace ttk
Union find compliant with parallel find and maintaining the current local propagation inspired by ttk...
Definition FTRAtomicUF.h:23
AtomicUF * find()
Definition FTRAtomicUF.h:35
void setPropagation(Propagation *const p)
Definition FTRAtomicUF.h:55
static AtomicUF * makeUnion(AtomicUF *uf0, AtomicUF *uf1)
Definition FTRAtomicUF.h:82
TTK fTRGraph propagation management with Fibonacci heaps.
std::size_t size() const
idVertex getNextVertex() const
void setCurvert(const idVertex v)
Propagation(const Propagation &other)=delete
idSuperArc getNbArcs() const
void moreArc(const idSuperArc a=1)
void removeBelow(const idVertex d, const VertCompFN &comp)
idVertex getCurVertex() const
void addNewVertex(const idVertex v)
bool compare(const idVertex a, const idVertex b) const
void removeDuplicates(const idVertex d)
std::string print() const
Propagation(idVertex startVert, const VertCompFN &vertComp, bool up)
bool find(idVertex v) const
void lessArc(const idSuperArc a=1)
void merge(Propagation &other)
std::function< bool(const idVertex, const idVertex)> VertCompFN
long unsigned int idSuperArc
SuperArc index in vect_superArcs_.
SimplexId idVertex
Vertex index in scalars_.
The Topology ToolKit.