TTK
Loading...
Searching...
No Matches
ContourForests.h
Go to the documentation of this file.
1
19
20#pragma once
21
22#include "ContourForestsTree.h"
23
24namespace ttk {
25 namespace cf {
26 // Classes Interface
27 // ContourForests
28
29 class Interface {
30 private:
31 // same size : number of conn. components.
32 SimplexId seed_;
33
34 // Overlap
35 std::vector<SimplexId> lowerOverlap_;
36 std::vector<SimplexId> upperOverlap_;
37
38 public:
39 Interface(const SimplexId &seed);
40
41 // Getter & Setter
42 // {
43
44 inline const SimplexId &getSeed() const {
45 return seed_;
46 }
47
48 inline std::vector<SimplexId> &getUpper() {
49 return upperOverlap_;
50 }
51
52 inline std::vector<SimplexId> &getLower() {
53 return lowerOverlap_;
54 }
55 inline SimplexId getNbUpper() const {
56 return upperOverlap_.size();
57 }
58
59 inline SimplexId getNbLower() const {
60 return lowerOverlap_.size();
61 }
62
63 inline void setSeed(const SimplexId &local_seed) {
64 seed_ = local_seed;
65 }
66
67 inline void addUpper(const SimplexId &lb) {
68 upperOverlap_.emplace_back(lb);
69 }
70
71 inline void addLower(const SimplexId &lb) {
72 lowerOverlap_.emplace_back(lb);
73 }
74
75 inline void upReserve(const SimplexId &u) {
76 upperOverlap_.reserve(u);
77 }
78
79 inline void loReserve(const SimplexId &l) {
80 lowerOverlap_.reserve(l);
81 }
82
83 inline void appendUpper(const std::vector<SimplexId> &vertices) {
84 upperOverlap_.insert(
85 upperOverlap_.end(), vertices.cbegin(), vertices.cend());
86 }
87
88 inline void appendLower(const std::vector<SimplexId> &vertices) {
89 lowerOverlap_.insert(
90 lowerOverlap_.end(), vertices.cbegin(), vertices.cend());
91 }
92
93 inline void swapUpper(std::vector<SimplexId> &verts) {
94 upperOverlap_.swap(verts);
95 }
96
97 inline void swapLower(std::vector<SimplexId> &verts) {
98 lowerOverlap_.swap(verts);
99 }
100
101 // }
102 };
103
111
113 std::vector<Interface> interfaces;
114 std::vector<ContourForestsTree> trees;
115 };
116
118 private:
119 // global (one instance -> no pointer)
120 ParallelParams parallelParams_;
121
122 // local
123 ParallelData parallelData_;
124
125 // storage
126 std::list<std::vector<std::pair<SimplexId, bool>>> storage_;
127
128 public:
130
131 ~ContourForests() override;
132
133 // Getters & Setters
134 // {
135
136 inline int setThreadNumber(const int nbThread) override {
137 if(nbThread) {
138 parallelParams_.nbThreads = nbThread;
139 } else {
140 parallelParams_.nbThreads = OsCall::getNumberOfCores();
141 }
142 return 0;
143 }
144
145 inline void setPartitionNum(int p) {
146 parallelParams_.partitionNum = p;
147 }
148
149 inline void setLessPartition(bool l) {
150 parallelParams_.lessPartition = l;
151 }
152
153 // range of partitions, position of seeds , ...
154
155 inline std::tuple<SimplexId, SimplexId>
156 getJTRange(const idPartition &i) const {
157 const SimplexId &start
158 = (i == 0)
159 ? 0
160 : scalars_->sosOffsets[parallelData_.interfaces[i - 1].getSeed()];
161
162 const SimplexId &end
163 = (i == parallelParams_.nbInterfaces)
164 ? scalars_->size
165 : scalars_->sosOffsets[parallelData_.interfaces[i].getSeed()];
166
167 return std::make_tuple(start, end);
168 }
169
170 inline std::tuple<SimplexId, SimplexId>
171 getSTRange(const idPartition &i) const {
172 const SimplexId &start
173 = (i == parallelParams_.nbInterfaces)
174 ? scalars_->size - 1
175 : scalars_->sosOffsets[parallelData_.interfaces[i].getSeed()] - 1;
176
177 const SimplexId &end
178 = (i == 0)
179 ? -1
180 : scalars_->sosOffsets[parallelData_.interfaces[i - 1].getSeed()]
181 - 1;
182
183 return std::make_tuple(start, end);
184 }
185
186 inline std::tuple<SimplexId, SimplexId>
187 getSeedsPos(const idPartition &i) const {
188 const SimplexId &seed0
189 = (i == 0)
190 ? -1
191 : scalars_->sosOffsets[parallelData_.interfaces[i - 1].getSeed()];
192
193 const SimplexId &seed1
194 = (i == parallelParams_.nbInterfaces)
195 ? nullVertex
196 : scalars_->sosOffsets[parallelData_.interfaces[i].getSeed()];
197
198 return std::make_tuple(seed0, seed1);
199 }
200
201 inline std::tuple<std::vector<SimplexId>, std::vector<SimplexId>>
203 const std::vector<SimplexId> &lower
204 = (i == 0) ? std::vector<SimplexId>()
205 : parallelData_.interfaces[i - 1].getLower();
206
207 const std::vector<SimplexId> &upper
208 = (i == parallelParams_.nbInterfaces)
209 ? std::vector<SimplexId>()
210 : parallelData_.interfaces[i].getUpper();
211
212 return std::make_tuple(lower, upper);
213 }
214
216
217 // }
218
219 // Init
220 // {
221 void initInterfaces();
222
223 template <typename triangulationType>
224 void initOverlap(const triangulationType &mesh);
225
226 void initNbPartitions();
227
228 //}
229 // Process
230 // {
231
232 template <typename scalarType, typename triangulationType>
233 int build(const triangulationType &mesh);
234
235 template <typename scalarType, typename triangulationType>
236 int
237 parallelBuild(std::vector<std::vector<ExtendedUnionFind *>> &baseUF_JT,
238 std::vector<std::vector<ExtendedUnionFind *>> &baseUF_ST,
239 const triangulationType &mesh);
240
241 void stitch();
242 void stitchTree(const char tree);
243
244 // replace distributed tree by a global one, will be removed
245 void unify();
246 void unifyTree(const char treetype);
247 // }
248
249 // Print
250 // {
251 void printDebug(DebugTimer &timer, const std::string &str);
252
253 void printVectCT();
254 // }
255 };
256
257 } // namespace cf
258} // namespace ttk
259
Legacy backward compatibility.
Definition Debug.h:472
static int getNumberOfCores()
Definition Os.cpp:87
std::tuple< SimplexId, SimplexId > getSTRange(const idPartition &i) const
int parallelBuild(std::vector< std::vector< ExtendedUnionFind * > > &baseUF_JT, std::vector< std::vector< ExtendedUnionFind * > > &baseUF_ST, const triangulationType &mesh)
int build(const triangulationType &mesh)
int setThreadNumber(const int nbThread) override
void stitchTree(const char tree)
idPartition vertex2partition(const SimplexId &v)
void initOverlap(const triangulationType &mesh)
std::tuple< SimplexId, SimplexId > getJTRange(const idPartition &i) const
void printDebug(DebugTimer &timer, const std::string &str)
void unifyTree(const char treetype)
std::tuple< SimplexId, SimplexId > getSeedsPos(const idPartition &i) const
std::tuple< std::vector< SimplexId >, std::vector< SimplexId > > getOverlaps(const idPartition &i)
void upReserve(const SimplexId &u)
void swapLower(std::vector< SimplexId > &verts)
void addLower(const SimplexId &lb)
void setSeed(const SimplexId &local_seed)
void addUpper(const SimplexId &lb)
const SimplexId & getSeed() const
SimplexId getNbLower() const
void swapUpper(std::vector< SimplexId > &verts)
void loReserve(const SimplexId &l)
std::vector< SimplexId > & getUpper()
SimplexId getNbUpper() const
std::vector< SimplexId > & getLower()
void appendLower(const std::vector< SimplexId > &vertices)
void appendUpper(const std::vector< SimplexId > &vertices)
std::shared_ptr< Scalars > scalars_
Definition MergeTree.h:44
numThread idInterface
index of the interface/partition in vect_interfaces_
numThread idPartition
ThreadId numThread
type use to store threads related numbers
The Topology ToolKit.
int SimplexId
Identifier type for simplices of any dimension.
Definition DataTypes.h:22
T end(std::pair< T, T > &p)
Definition ripserpy.cpp:472
std::vector< Interface > interfaces
std::vector< ContourForestsTree > trees