TTK
Loading...
Searching...
No Matches
ttkMergeTreeTemporalReductionUtils.h
Go to the documentation of this file.
1
6
7#pragma once
8
9#include <FTMTreeUtils.h>
10
11#include <vtkCellData.h>
12#include <vtkPointData.h>
13#include <vtkUnstructuredGrid.h>
14
15// -------------------------------------------------------------------------------------
16// Temporal Subsampling
17// -------------------------------------------------------------------------------------
18template <class dataType>
20 const std::vector<ttk::ftm::MergeTree<dataType>> &intermediateMTrees,
21 const std::vector<std::vector<double>> &embedding,
22 const std::vector<ttk::ftm::MergeTree<dataType>> &ttkNotUsed(allMT),
23 const std::vector<int> &removed,
24 vtkUnstructuredGrid *const vtkOutputNode1,
25 vtkUnstructuredGrid *const vtkOutputArc1,
26 const bool displayRemoved = false) {
27
28 auto fullSize = intermediateMTrees.size() + removed.size();
29 std::vector<ttk::SimplexId> nodeSimplexId(fullSize);
30 vtkNew<vtkIntArray> treeId{};
31 treeId->SetName("TreeId");
32 vtkNew<vtkIntArray> nodePathId{};
33 nodePathId->SetName("NodePathId");
34 vtkNew<vtkIntArray> pathId{};
35 pathId->SetName("PathId");
36 vtkNew<vtkIntArray> nodeRemoved{};
37 nodeRemoved->SetName("isNodeRemoved");
38 vtkNew<vtkIntArray> nodeId{};
39 nodeId->SetName("NodeId");
40 vtkNew<vtkIntArray> arcId{};
41 arcId->SetName("ArcId");
42
43 vtkNew<vtkUnstructuredGrid> vtkArcs{};
44 vtkNew<vtkPoints> points{};
45 for(unsigned int i = 0; i < embedding[0].size(); ++i) {
46 if(not displayRemoved and i >= intermediateMTrees.size())
47 continue;
48
49 // Next point
50 double point[3] = {embedding[0][i], embedding[1][i], 0};
51 nodeSimplexId[i] = points->InsertNextPoint(point);
52
53 // Add TreeID field
54 int index = i;
55 if(i >= intermediateMTrees.size())
56 index = removed[i - intermediateMTrees.size()];
57 treeId->InsertNextTuple1(index);
58
59 // Add NodePathId field
60 int thisPathId = (i < intermediateMTrees.size() ? 0 : 1);
61 nodePathId->InsertNextTuple1(thisPathId);
62
63 // Add NodeId
64 nodeId->InsertNextTuple1(i);
65
66 // Add cell
67 if(i > 0 and i < intermediateMTrees.size()) {
68 vtkIdType pointIds[2];
69 pointIds[0] = nodeSimplexId[i - 1];
70 pointIds[1] = nodeSimplexId[i];
71 vtkArcs->InsertNextCell(VTK_LINE, 2, pointIds);
72
73 // Add PathId field
74 pathId->InsertNextTuple1(0);
75
76 // Add Arc Id
77 arcId->InsertNextTuple1(i);
78 }
79 }
80
81 if(displayRemoved) {
82 for(unsigned int i = 0; i < removed.size(); ++i) {
83 int const index = removed[i];
84 // First cell
85 if(i == 0) {
86 vtkIdType pointIds[2];
87 pointIds[0] = nodeSimplexId[index - 1];
88 pointIds[1] = nodeSimplexId[intermediateMTrees.size() + i];
89 vtkArcs->InsertNextCell(VTK_LINE, 2, pointIds);
90 pathId->InsertNextTuple1(1);
91
92 if(removed[i + 1] != index + 1) {
93 vtkIdType pointIds2[2];
94 pointIds2[0] = nodeSimplexId[intermediateMTrees.size() + i];
95 pointIds2[1] = nodeSimplexId[index + 1];
96 vtkArcs->InsertNextCell(VTK_LINE, 2, pointIds2);
97 pathId->InsertNextTuple1(1);
98 }
99 }
100 // Between cell
101 if(i > 0 and i < removed.size() - 1) {
102 vtkIdType pointIds[2];
103 int prevIndex
104 = (removed[i - 1] == index - 1 ? intermediateMTrees.size() + i - 1
105 : index - 1);
106 pointIds[0] = nodeSimplexId[prevIndex];
107 pointIds[1] = nodeSimplexId[intermediateMTrees.size() + i];
108 vtkArcs->InsertNextCell(VTK_LINE, 2, pointIds);
109 pathId->InsertNextTuple1(1);
110
111 vtkIdType pointIds2[2];
112 int nextvIndex
113 = (removed[i + 1] == index + 1 ? intermediateMTrees.size() + i + 1
114 : index + 1);
115 pointIds2[0] = nodeSimplexId[intermediateMTrees.size() + i];
116 pointIds2[1] = nodeSimplexId[nextvIndex];
117 vtkArcs->InsertNextCell(VTK_LINE, 2, pointIds2);
118 pathId->InsertNextTuple1(1);
119 }
120 // End cell
121 if(i == removed.size() - 1) {
122 vtkIdType pointIds[2];
123 pointIds[0] = nodeSimplexId[intermediateMTrees.size() + i];
124 pointIds[1] = nodeSimplexId[index + 1];
125 vtkArcs->InsertNextCell(VTK_LINE, 2, pointIds);
126 pathId->InsertNextTuple1(1);
127
128 if(removed[i - 1] != index - 1) {
129 vtkIdType pointIds2[2];
130 pointIds2[0] = nodeSimplexId[index - 1];
131 pointIds2[1] = nodeSimplexId[intermediateMTrees.size() + i];
132 vtkArcs->InsertNextCell(VTK_LINE, 2, pointIds2);
133 pathId->InsertNextTuple1(1);
134 }
135 }
136 }
137 } else {
138 for(unsigned int i = 0; i < removed.size(); ++i) {
139 int before = removed[i] - 1;
140 int index = i - 1;
141 if(i > 0)
142 while(before == removed[index]) {
143 before = removed[index] - 1;
144 --index;
145 }
146
147 int after = removed[i] + 1;
148 index = i + 1;
149 if(i < removed.size() - 1)
150 while(after == removed[index]) {
151 after = removed[index] + 1;
152 ++index;
153 }
154
155 vtkIdType pointIds[2];
156 pointIds[0] = nodeSimplexId[before];
157 pointIds[1] = nodeSimplexId[after];
158 vtkArcs->InsertNextCell(VTK_LINE, 2, pointIds);
159 pathId->InsertNextTuple1(1);
160 arcId->InsertNextTuple1(intermediateMTrees.size() + i);
161 }
162 }
163
164 for(unsigned int i = 0; i < fullSize; ++i)
165 nodeRemoved->InsertNextTuple1(0);
166 for(unsigned int i = 0; i < removed.size(); ++i) {
167 nodeRemoved->SetTuple1(removed[i], 1);
168 nodeRemoved->SetTuple1(intermediateMTrees.size() + i, 1);
169 }
170
171 vtkOutputNode1->SetPoints(points);
172 vtkOutputNode1->GetPointData()->AddArray(treeId);
173 vtkOutputNode1->GetPointData()->AddArray(nodePathId);
174 vtkOutputNode1->GetPointData()->AddArray(nodeRemoved);
175 vtkOutputNode1->GetPointData()->AddArray(nodeId);
176 vtkArcs->SetPoints(points);
177 vtkArcs->GetCellData()->AddArray(pathId);
178 vtkArcs->GetCellData()->AddArray(arcId);
179 vtkOutputArc1->ShallowCopy(vtkArcs);
180}
181
182template <class dataType>
184 const std::vector<ttk::ftm::MergeTree<dataType>> &intermediateMTrees,
185 const std::vector<double> &emptyTreeDistances,
186 const std::vector<ttk::ftm::MergeTree<dataType>> &allMT,
187 const std::vector<int> removed,
188 vtkUnstructuredGrid *const vtkOutputNode1,
189 vtkUnstructuredGrid *const vtkOutputArc1,
190 const double DistanceAxisStretch) {
191
192 std::array<std::vector<double>, 2> embedding{};
193 for(size_t i = 0; i < intermediateMTrees.size() + removed.size(); ++i) {
194 double const y = emptyTreeDistances[i] * DistanceAxisStretch;
195 double x = i;
196 if(i >= intermediateMTrees.size())
197 x = removed[i - intermediateMTrees.size()];
198
199 embedding[0].push_back(x);
200 embedding[1].push_back(y);
201 }
202
203 // Create output
204 makeTemporalSubsamplingOutput<dataType>(intermediateMTrees, embedding, allMT,
205 removed, vtkOutputNode1,
206 vtkOutputArc1);
207}
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
Definition BaseClass.h:47
void makeTemporalSubsamplingETDOutput(const std::vector< ttk::ftm::MergeTree< dataType > > &intermediateMTrees, const std::vector< double > &emptyTreeDistances, const std::vector< ttk::ftm::MergeTree< dataType > > &allMT, const std::vector< int > removed, vtkUnstructuredGrid *const vtkOutputNode1, vtkUnstructuredGrid *const vtkOutputArc1, const double DistanceAxisStretch)
void makeTemporalSubsamplingOutput(const std::vector< ttk::ftm::MergeTree< dataType > > &intermediateMTrees, const std::vector< std::vector< double > > &embedding, const std::vector< ttk::ftm::MergeTree< dataType > > &ttkNotUsed(allMT), const std::vector< int > &removed, vtkUnstructuredGrid *const vtkOutputNode1, vtkUnstructuredGrid *const vtkOutputArc1, const bool displayRemoved=false)