TTK
Loading...
Searching...
No Matches
FTRPropagations.h
Go to the documentation of this file.
1
10
11#pragma once
12
13// local includes
14#include "FTRAtomicVector.h"
15#include "FTRDataTypes.h"
16#include "FTRPropagation.h"
17
18// c++ includes
19#include <memory>
20#include <vector>
21
22namespace ttk {
23 namespace ftr {
24 struct Visit {
26 bool done;
27 };
28
29 struct Visits {
30 std::vector<Visit> up, down;
31 };
32
33 // Split in one up one down ?
34 class Propagations : public Allocable {
36 Visits visits_;
37
38 public:
39 ~Propagations() override = default;
40
41 void alloc() override {
42 propagations_.reserve(nbElmt_);
43 visits_.down.resize(nbElmt_);
44 visits_.up.resize(nbElmt_);
45 }
46
47 void init() override {
48 fillVector<Visit>(visits_.down, {nullptr, false});
49 fillVector<Visit>(visits_.up, {nullptr, false});
50 }
51
52 // newPropagation
53 // history / toVisit related function
54 // localGrowth maybe :P
55
56 // Create a new propagation starting at leaf
58 const VertCompFN &comp,
59 const bool fromMin) {
60 const auto propId = propagations_.getNext();
61 propagations_[propId]
62 = std::make_unique<Propagation>(leaf, comp, fromMin);
63 return propagations_[propId].get();
64 }
65
66 void toVisit(const idVertex v, Propagation *const prop) {
67 if(prop->goUp()) {
68 visits_.up[v].prop = prop;
69 } else {
70 visits_.down[v].prop = prop;
71 }
72 }
73
74 void visit(const idVertex v, Propagation *const prop) {
75 if(prop->goUp()) {
76 visits_.up[v].prop = prop;
77 visits_.up[v].done = true;
78 } else {
79 visits_.down[v].prop = prop;
80 visits_.down[v].done = true;
81 }
82 }
83
84 bool willVisit(const idVertex v, const Propagation *const prop) const {
85 if(prop->goUp()) {
86 return visits_.up[v].prop == prop;
87 } else {
88 return visits_.down[v].prop == prop;
89 }
90 }
91
92 bool hasVisited(const idVertex v, Propagation *const prop) const {
93 // return visits_[v].prop && visits_[v].prop->getId() == prop->getId()
94 // && visits_[v].done; more revisit but no UF traversal. No perf impact
95 // noticed
96 if(prop->goUp()) {
97 return visits_.up[v].prop == prop && visits_.up[v].done;
98 } else {
99 return visits_.down[v].prop == prop && visits_.down[v].done;
100 }
101 }
102
103 // check if the opposite propagation already processed this vertex (done)
104 // TODO: improve by accepting vertices planned to be visited (not the
105 // .done)
106 bool hasVisitedOpposite(const idVertex v, Propagation *const prop) const {
107 // reversed
108 bool res;
109 if(prop->goUp()) {
110#ifdef TTK_ENABLE_OPENMP4
111#pragma omp atomic read seq_cst
112#endif
113 res = visits_.down[v].done;
114 } else {
115#ifdef TTK_ENABLE_OPENMP4
116#pragma omp atomic read seq_cst
117#endif
118 res = visits_.up[v].done;
119 }
120 return res;
121 }
122
123 Visit visit(const idVertex v, const Propagation *const prop) const {
124 if(prop->goUp()) {
125 return visits_.up[v];
126 } else {
127 return visits_.down[v];
128 }
129 }
130
132 const Propagation *const prop) const {
133 if(prop->goUp()) {
134 return visits_.down[v];
135 } else {
136 return visits_.up[v];
137 }
138 }
139 };
140 } // namespace ftr
141} // namespace ttk
TTK processing package that manage a parallel version of vector Same as in FTM: Common ?
void reserve(const std::size_t &newSize, const bool fromOther=false)
idVertex nbElmt_
Allocation may depends on the number of vertices.
Definition FTRCommon.h:50
TTK fTRGraph propagation management with Fibonacci heaps.
manage propagations for FTR Graph
void toVisit(const idVertex v, Propagation *const prop)
Visit visitOpposite(const idVertex v, const Propagation *const prop) const
bool hasVisitedOpposite(const idVertex v, Propagation *const prop) const
bool willVisit(const idVertex v, const Propagation *const prop) const
Visit visit(const idVertex v, const Propagation *const prop) const
Propagation * newPropagation(const idVertex leaf, const VertCompFN &comp, const bool fromMin)
~Propagations() override=default
void visit(const idVertex v, Propagation *const prop)
bool hasVisited(const idVertex v, Propagation *const prop) const
std::function< bool(const idVertex, const idVertex)> VertCompFN
SimplexId idVertex
Vertex index in scalars_.
The Topology ToolKit.
Propagation * prop
std::vector< Visit > up
std::vector< Visit > down