TTK
Loading...
Searching...
No Matches
FTMNode.h
Go to the documentation of this file.
1
7//
10
11#pragma once
12
13#include <vector>
14
15#include <Debug.h>
16#include <functional>
17
18#include "FTMDataTypes.h"
19
20namespace ttk {
21 namespace ftm {
22 class Node {
23 friend class FTMTree_MT;
24
25 private:
26 // mesh vertex where this node is
27 SimplexId vertexId_;
28 // For leaves, linkedNode is the saddle ending the persistence pair
29 // For saddle, linked is the leaf starting the persistence pair in which
30 // they are
31 SimplexId linkedNode_;
32 // link with superArc above and below
33 std::vector<idSuperArc> vect_downSuperArcList_, vect_upSuperArcList_;
34
35 public:
36 // -----------------
37 // CONSTRUCTOR
38 // -----------------
39
40 // This node will need to receive a vertex id before being printed
41 Node() : vertexId_(nullVertex), linkedNode_(nullNodes) {
42 }
43
45 : vertexId_(id), linkedNode_(linked) {
46 }
47
48 // -----------------
49 // ACCESSOR
50 // ------------------
51
52 // Vertex id
53
54 inline SimplexId getVertexId() const {
55 return vertexId_;
56 }
57
58 inline void setVertexId(SimplexId vertexId) {
59 vertexId_ = vertexId;
60 }
61
62 // Linked node
63
64 inline SimplexId getOrigin() const {
65 return linkedNode_;
66 }
67
68 inline SimplexId getTermination() const {
69 return linkedNode_;
70 }
71
72 inline void setOrigin(SimplexId linked) {
73 linkedNode_ = linked;
74 }
75
76 inline void setTermination(SimplexId linked) {
77 linkedNode_ = linked;
78 }
79
80 // vector arcs
81
83 return vect_downSuperArcList_.size();
84 }
85
87 return vect_upSuperArcList_.size();
88 }
89
91 return vect_upSuperArcList_.size() + vect_downSuperArcList_.size();
92 }
93
94 inline idSuperArc getDownSuperArcId(idSuperArc neighborId) const {
95#ifndef TTK_ENABLE_KAMIKAZE
96 if(neighborId >= vect_downSuperArcList_.size()) {
97 std::cerr << "[Merge Tree:Node] get down on bad neighbor !";
98 std::cerr << std::endl;
99 return 0;
100 }
101#endif
102 return vect_downSuperArcList_[neighborId];
103 }
104
105 inline idSuperArc getUpSuperArcId(idSuperArc neighborId) const {
106#ifndef TTK_ENABLE_KAMIKAZE
107 if(neighborId >= vect_upSuperArcList_.size()) {
108 std::cerr << "[FTMTree_MT:Node] No SuperArc to access "
109 << static_cast<unsigned>(neighborId);
110 std::cerr << std::endl;
111 }
112#endif
113 if(vect_upSuperArcList_.size() == 0) {
114 return nullSuperArc;
115 }
116 return vect_upSuperArcList_[neighborId];
117 }
118
119 inline void addDownSuperArcId(idSuperArc downSuperArcId) {
120 vect_downSuperArcList_.emplace_back(downSuperArcId);
121 }
122
123 inline void addUpSuperArcId(idSuperArc upSuperArcId) {
124 vect_upSuperArcList_.emplace_back(upSuperArcId);
125 }
126
128 idSuperArc const s = vect_downSuperArcList_.size();
129 vect_downSuperArcList_.clear();
130 return s;
131 }
132
134 idSuperArc const s = vect_upSuperArcList_.size();
135 vect_upSuperArcList_.clear();
136 return s;
137 }
138
139 // remove the i^th arc
141 vect_downSuperArcList_[i] = vect_downSuperArcList_.back();
142 vect_downSuperArcList_.pop_back();
143 }
144
145 // Find and remove the arc
146 inline void removeDownSuperArc(idSuperArc idSa) {
147 for(idSuperArc i = 0; i < vect_downSuperArcList_.size(); ++i) {
148 if(vect_downSuperArcList_[i] == idSa) {
149 vect_downSuperArcList_[i] = vect_downSuperArcList_.back();
150 vect_downSuperArcList_.pop_back();
151
152 return;
153 }
154 }
155 }
156
157 // Find and remove the arc
158 inline void removeUpSuperArc(idSuperArc idSa) {
159 for(idSuperArc i = 0; i < vect_upSuperArcList_.size(); ++i) {
160 if(vect_upSuperArcList_[i] == idSa) {
161 vect_upSuperArcList_[i] = vect_upSuperArcList_.back();
162 vect_upSuperArcList_.pop_back();
163
164 return;
165 }
166 }
167 }
168
170 const std::function<bool(const idSuperArc, const idSuperArc)> &comp) {
171 sort(vect_upSuperArcList_.begin(), vect_upSuperArcList_.end(), comp);
172 }
173
175 const std::function<bool(const idSuperArc, const idSuperArc)> &comp) {
176 sort(
177 vect_downSuperArcList_.begin(), vect_downSuperArcList_.end(), comp);
178 }
179 };
180
181 } // namespace ftm
182} // namespace ttk
void removeDownSuperArcPos(idSuperArc i)
Definition FTMNode.h:140
void sortDownArcs(const std::function< bool(const idSuperArc, const idSuperArc)> &comp)
Definition FTMNode.h:174
idSuperArc getUpSuperArcId(idSuperArc neighborId) const
Definition FTMNode.h:105
idSuperArc clearUpSuperArcs()
Definition FTMNode.h:133
idSuperArc getNumberOfSuperArcs() const
Definition FTMNode.h:90
void addDownSuperArcId(idSuperArc downSuperArcId)
Definition FTMNode.h:119
SimplexId getTermination() const
Definition FTMNode.h:68
Node(SimplexId id, SimplexId linked)
Definition FTMNode.h:44
idSuperArc getNumberOfDownSuperArcs() const
Definition FTMNode.h:82
idSuperArc getDownSuperArcId(idSuperArc neighborId) const
Definition FTMNode.h:94
void removeUpSuperArc(idSuperArc idSa)
Definition FTMNode.h:158
idSuperArc clearDownSuperArcs()
Definition FTMNode.h:127
void setOrigin(SimplexId linked)
Definition FTMNode.h:72
void removeDownSuperArc(idSuperArc idSa)
Definition FTMNode.h:146
void addUpSuperArcId(idSuperArc upSuperArcId)
Definition FTMNode.h:123
SimplexId getVertexId() const
Definition FTMNode.h:54
void setVertexId(SimplexId vertexId)
Definition FTMNode.h:58
void setTermination(SimplexId linked)
Definition FTMNode.h:76
void sortUpArcs(const std::function< bool(const idSuperArc, const idSuperArc)> &comp)
Definition FTMNode.h:169
SimplexId getOrigin() const
Definition FTMNode.h:64
idSuperArc getNumberOfUpSuperArcs() const
Definition FTMNode.h:86
long unsigned int idSuperArc
SuperArc index in vect_superArcs_.
The Topology ToolKit.
int SimplexId
Identifier type for simplices of any dimension.
Definition DataTypes.h:22