TTK
Loading...
Searching...
No Matches
FTMTree_CT_Template.h
Go to the documentation of this file.
1#pragma once
2
3#include <FTMTree_CT.h>
4
5namespace ttk {
6 namespace ftm {
7
8 template <class triangulationType>
9 void FTMTree_CT::build(const triangulationType *mesh, TreeType tt) {
10 Timer mergeTreesTime;
11
12 const bool bothMT = tt == TreeType::Contour || tt == TreeType::Join_Split;
13
14 initComp();
15
16 if(bothMT) {
17 // single leaf search for both tree
18 // When executed from CT, both minima and maxima are extracted
19 Timer precomputeTime;
20#ifdef TTK_ENABLE_OPENMP4
21#pragma omp parallel num_threads(threadNumber_)
22#endif
23 {
24#ifdef TTK_ENABLE_OPENMP4
25#pragma omp single nowait
26#endif
27 { leafSearch(mesh); }
28 }
29 printTime(precomputeTime, "leafSearch", 3);
30 }
31
32#ifdef TTK_ENABLE_OMP_PRIORITY
33 {
34 // Set priority
36 st_.setPrior();
37 else
38 jt_.setPrior();
39 }
40#endif
41
42 // JT & ST
43 // clang-format off
44#ifdef TTK_ENABLE_OPENMP4
45#pragma omp parallel num_threads(threadNumber_)
46#endif
47 {
48#ifdef TTK_ENABLE_OPENMP4
49#pragma omp single nowait
50#endif
51 {
52 if(tt == TreeType::Join || bothMT) {
53#ifdef TTK_ENABLE_OPENMP4
54#pragma omp task UNTIED() if(threadNumber_ > 1)
55#endif
56 jt_.build(mesh, tt == TreeType::Contour);
57 }
58 if(tt == TreeType::Split || bothMT) {
59#ifdef TTK_ENABLE_OPENMP4
60#pragma omp task UNTIED() if(threadNumber_ > 1)
61#endif
62 st_.build(mesh, tt == TreeType::Contour);
63 }
64 }
65#ifdef TTK_ENABLE_OPENMP4
66#pragma omp taskwait
67#endif
68 }
69
70 printTime(mergeTreesTime, "merge trees ", 3);
71
72 // Combine
73 if(tt == TreeType::Contour) {
74
75 Timer combineFullTime;
77
78 Timer combineTime;
79 combine();
80 printTime(combineTime, "combine trees", 4);
81 printTime(combineFullTime, "combine full", 3);
82 }
83 // Debug
84 if(debugLevel_ > 3) {
85 std::string nbNodes;
86 switch(tt) {
87 case TreeType::Join:
88 nbNodes = std::to_string(jt_.getNumberOfNodes());
89 break;
90 case TreeType::Split:
91 nbNodes = std::to_string(st_.getNumberOfNodes());
92 break;
94 nbNodes
95 = std::to_string(jt_.getNumberOfNodes() + st_.getNumberOfNodes());
96 break;
97 default:
98 nbNodes = std::to_string(getNumberOfNodes());
99 }
100 this->printMsg({"- final number of nodes :", nbNodes});
101 }
102 }
103// clang-format on
104// clang format fail to use the right indentation level
105// here, but it break the code if not disabled...
106
107// ------------------------------------------------------------------------
108
109template <class triangulationType>
110int FTMTree_CT::leafSearch(const triangulationType *mesh) {
111 const auto nbScalars = scalars_->size;
112 const auto chunkSize = getChunkSize();
113 const auto chunkNb = getChunkCount();
114
115 // Extrema extract and launch tasks
116 for(SimplexId chunkId = 0; chunkId < chunkNb; ++chunkId) {
117#ifdef TTK_ENABLE_OPENMP4
118#pragma omp task firstprivate(chunkId)
119#endif
120 {
121 const SimplexId lowerBound = chunkId * chunkSize;
122 const SimplexId upperBound
123 = std::min(nbScalars, (chunkId + 1) * chunkSize);
124 for(SimplexId v = lowerBound; v < upperBound; ++v) {
125 const auto &neighNumb = mesh->getVertexNeighborNumber(v);
126 valence upval = 0;
127 valence downval = 0;
128
129 for(valence n = 0; n < neighNumb; ++n) {
130 SimplexId neigh{-1};
131 mesh->getVertexNeighbor(v, n, neigh);
132 if(scalars_->isLower(neigh, v)) {
133 ++downval;
134 } else {
135 ++upval;
136 }
137 }
138
139 jt_.setValence(v, downval);
140 st_.setValence(v, upval);
141
142 if(!downval) {
143 jt_.makeNode(v);
144 }
145
146 if(!upval) {
147 st_.makeNode(v);
148 }
149 }
150 }
151 }
152
153#ifdef TTK_ENABLE_OPENMP4
154#pragma omp taskwait
155#endif
156 return 0;
157}
158
159} // namespace ftm
160} // namespace ttk
int debugLevel_
Definition Debug.h:379
void build(const triangulationType *mesh, TreeType tt)
int leafSearch(const triangulationType *mesh)
idNode getNumberOfNodes() const
Definition FTMTree_MT.h:389
SimplexId getChunkSize(const SimplexId nbVerts=-1, const SimplexId nbtasks=100) const
Definition FTMTree_MT.h:821
idNode getNumberOfLeaves() const
Definition FTMTree_MT.h:403
void build(const triangulationType *mesh, const bool ct)
Compute the merge.
int printTime(Timer &t, const std::string &s, const int debugLevel=2) const
SimplexId getChunkCount(const SimplexId nbVerts=-1, const SimplexId nbTasks=100) const
Definition FTMTree_MT.h:834
idNode makeNode(SimplexId vertexId, SimplexId linked=nullVertex)
void setValence(const SimplexId v, const SimplexId val)
Definition FTMTree_MT.h:397
std::shared_ptr< Scalars > scalars_
Definition FTMTree_MT.h:87
SimplexId valence
for vertex up/down valence
The Topology ToolKit.
int SimplexId
Identifier type for simplices of any dimension.
Definition DataTypes.h:22
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)