TTK
Loading...
Searching...
No Matches
FTMTreePP.h
Go to the documentation of this file.
1
7// to the contour tree package.
13
14#pragma once
15
16#include "FTMTree.h"
17
18namespace ttk {
19 namespace ftm {
25 class FTMTreePP : public FTMTree {
26 private:
27 std::vector<AtomicUF> nodesUF_;
28
29 // Custom tree option
30 ftm::FTMTree_MT *customTree;
31 std::vector<idNode> customTreeLeaves;
32 bool useCustomTree = false;
33 bool isJt;
34
35 public:
36 FTMTreePP();
37 ~FTMTreePP() override;
38
39 template <typename scalarType>
41 std::vector<std::tuple<SimplexId, SimplexId, scalarType>> &pairs,
42 const bool jt);
43
45 customTree = cTree;
46 useCustomTree = true;
47 }
48
49 protected:
50 template <typename scalarType>
51 void computePairs(
52 ftm::FTMTree_MT *tree,
53 std::vector<std::tuple<SimplexId, SimplexId, scalarType>> &pairs);
54
55 template <typename scalarType>
57 ftm::FTMTree_MT *tree,
58 std::vector<std::tuple<SimplexId, SimplexId, scalarType>> &pairs);
59
60 void addPendingNode(const idNode parentNode, const idNode toAdd) {
61 // Trick, we use the arc list to maintaint nodes
62 // coming to this UF.
63 nodesUF_[parentNode].find()->addArcToClose(toAdd);
64 }
65
67 return nodesUF_[current].find()->getOpenedArcs().size();
68 }
69
70 template <typename scalarType>
72 ftm::FTMTree_MT *tree) {
73 SimplexId minVert = tree->getNode(current)->getVertexId();
74 scalarType minVal = tree->getValue<scalarType>(minVert);
75 AtomicUF *uf = nodesUF_[current].find();
76
77 for(const auto nodeid : uf->getOpenedArcs()) {
78 const SimplexId vtmp = nodesUF_[nodeid].find()->getExtrema();
79 const scalarType tmpVal = tree->getValue<scalarType>(vtmp);
80 if((useCustomTree
81 and ((!isJt and tmpVal > minVal) or (isJt and tmpVal < minVal)))
82 or (not useCustomTree and tree->compLower(vtmp, minVert))) {
83 minVal = tmpVal;
84 minVert = vtmp;
85 }
86 }
87
88 return minVert;
89 }
90
91 void clearPendingNodes(const idNode current) {
92 nodesUF_[current].find()->clearOpenedArcs();
93 }
94
95 template <typename scalarType>
97 const idNode current,
98 std::vector<std::tuple<SimplexId, SimplexId, scalarType>> &pairs,
99 ftm::FTMTree_MT *tree,
100 const SimplexId mp) {
101 AtomicUF *uf = nodesUF_[current].find();
102 const SimplexId curVert = tree->getNode(current)->getVertexId();
103 const scalarType curVal = (not useCustomTree)
104 ? getValue<scalarType>(curVert)
105 : tree->getValue<scalarType>(curVert);
106
107 for(const auto nodeid : uf->getOpenedArcs()) {
108 const SimplexId tmpVert = nodesUF_[nodeid].find()->getExtrema();
109 AtomicUF::makeUnion(uf, &nodesUF_[nodeid]);
110 if(tmpVert != mp) {
111 const scalarType tmpVal = (not useCustomTree)
112 ? getValue<scalarType>(tmpVert)
113 : tree->getValue<scalarType>(tmpVert);
114 if((useCustomTree and tmpVal < curVal)
115 or (not useCustomTree and scalars_->isLower(tmpVert, curVert))) {
116 pairs.emplace_back(tmpVert, curVert, curVal - tmpVal);
117 } else {
118 pairs.emplace_back(tmpVert, curVert, tmpVal - curVal);
119 }
120 }
121 }
122 }
123 };
124 } // namespace ftm
125} // namespace ttk
126
127template <typename scalarType>
129 std::vector<std::tuple<SimplexId, SimplexId, scalarType>> &pairs,
130 const bool jt) {
131 ftm::FTMTree_MT *tree;
132 idNode nbLeaves;
133
134 if(useCustomTree) {
135 tree = customTree;
136 tree->getLeavesFromTree(customTreeLeaves);
137 nbLeaves = customTreeLeaves.size();
138 isJt = jt;
139 } else {
140 tree = jt ? getJoinTree() : getSplitTree();
141 nbLeaves = tree->getNumberOfLeaves();
142 }
143
144 pairs.clear();
145 pairs.reserve(nbLeaves);
146
147 const auto nbNodes = tree->getNumberOfNodes();
148 nodesUF_.resize(nbNodes);
149
150 for(idNode nid = 0; nid < nbNodes; ++nid) {
151 nodesUF_[nid] = AtomicUF{tree->getNode(nid)->getVertexId()};
152 }
153
154 computePairs<scalarType>(tree, pairs);
155 sortPairs<scalarType>(tree, pairs);
156}
157
158template <typename scalarType>
160 ftm::FTMTree_MT *tree,
161 std::vector<std::tuple<SimplexId, SimplexId, scalarType>> &pairs) {
162 auto getParentNode = [&](const idNode current) {
163 const idSuperArc parentArc = tree->getNode(current)->getUpSuperArcId(0);
164 return tree->getSuperArc(parentArc)->getUpNodeId();
165 };
166
167 ::std::queue<idNode> toSee;
168
169 // start at the leaves
170 auto &vectLeaves = (not useCustomTree) ? tree->getLeaves() : customTreeLeaves;
171 for(auto nid : vectLeaves) {
172 toSee.emplace(nid);
173 }
174
175 while(!toSee.empty()) {
176 const idNode current = toSee.front();
177 toSee.pop();
178
179 if(!tree->getNode(current)->getNumberOfUpSuperArcs()) {
180 createPairs<scalarType>(current, pairs, tree, ftm::nullVertex);
181 clearPendingNodes(current);
182 continue;
183 } else {
184 clearPendingNodes(current);
185 }
186
187 const idNode parentNode = getParentNode(current);
188 addPendingNode(parentNode, current);
189
190 if(countPendingNode(parentNode)
191 == tree->getNode(parentNode)->getNumberOfDownSuperArcs()) {
192 const SimplexId mostPersist
193 = getMostPersistVert<scalarType>(parentNode, tree);
194 createPairs<scalarType>(parentNode, pairs, tree, mostPersist);
195 nodesUF_[parentNode].find()->setExtrema(mostPersist);
196 toSee.push(parentNode);
197 }
198 }
199}
200
201template <typename scalarType>
204 std::vector<std::tuple<SimplexId, SimplexId, scalarType>> &pairs) {
205 auto comp = [&](const std::tuple<SimplexId, SimplexId, scalarType> a,
206 const std::tuple<SimplexId, SimplexId, scalarType> b) {
207 return std::get<2>(a) < std::get<2>(b);
208 };
209
210 sort(pairs.begin(), pairs.end(), comp);
211}
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
Definition BaseClass.h:47
FTMAtomicVector< idSuperArc > & getOpenedArcs()
Definition FTMAtomicUF.h:86
SimplexId getExtrema() const
Definition FTMAtomicUF.h:54
static AtomicUF * makeUnion(AtomicUF *uf0, AtomicUF *uf1)
AtomicUF * find()
Definition FTMAtomicUF.h:38
void computePersistencePairs(std::vector< std::tuple< SimplexId, SimplexId, scalarType > > &pairs, const bool jt)
Definition FTMTreePP.h:128
void clearPendingNodes(const idNode current)
Definition FTMTreePP.h:91
void setCustomTree(ftm::FTMTree_MT *cTree)
Definition FTMTreePP.h:44
void computePairs(ftm::FTMTree_MT *tree, std::vector< std::tuple< SimplexId, SimplexId, scalarType > > &pairs)
Definition FTMTreePP.h:159
idNode countPendingNode(const idNode current)
Definition FTMTreePP.h:66
void sortPairs(ftm::FTMTree_MT *tree, std::vector< std::tuple< SimplexId, SimplexId, scalarType > > &pairs)
void createPairs(const idNode current, std::vector< std::tuple< SimplexId, SimplexId, scalarType > > &pairs, ftm::FTMTree_MT *tree, const SimplexId mp)
Definition FTMTreePP.h:96
~FTMTreePP() override
SimplexId getMostPersistVert(const idNode current, ftm::FTMTree_MT *tree)
Definition FTMTreePP.h:71
void addPendingNode(const idNode parentNode, const idNode toAdd)
Definition FTMTreePP.h:60
FTMTree_MT * getSplitTree()
Definition FTMTree_CT.h:51
FTMTree_MT * getJoinTree()
Definition FTMTree_CT.h:47
const scalarType & getValue(SimplexId nodeId) const
Definition FTMTree_MT.h:339
SuperArc * getSuperArc(idSuperArc i)
Definition FTMTree_MT.h:367
idNode getNumberOfNodes() const
Definition FTMTree_MT.h:389
idNode getNumberOfLeaves() const
Definition FTMTree_MT.h:403
const std::vector< idNode > & getLeaves() const
Definition FTMTree_MT.h:407
void getLeavesFromTree(std::vector< idNode > &res)
Node * getNode(idNode nodeId)
Definition FTMTree_MT.h:393
std::shared_ptr< Scalars > scalars_
Definition FTMTree_MT.h:87
bool compLower(const SimplexId a, const SimplexId b)
Definition FTMTree_MT.h:145
TTK processing package that efficiently computes the contour tree of scalar data and more (data segme...
Definition FTMTree.h:53
idSuperArc getUpSuperArcId(idSuperArc neighborId) const
Definition FTMNode.h:105
idSuperArc getNumberOfDownSuperArcs() const
Definition FTMNode.h:82
SimplexId getVertexId() const
Definition FTMNode.h:54
idSuperArc getNumberOfUpSuperArcs() const
Definition FTMNode.h:86
idNode getUpNodeId() const
Definition FTMSuperArc.h:68
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