TTK
Loading...
Searching...
No Matches
ttkTrackingFromPersistenceDiagrams.h
Go to the documentation of this file.
1#pragma once
2
4#include <numeric>
5#include <ttkAlgorithm.h>
6
7// VTK Module
8#include <ttkTrackingFromPersistenceDiagramsModule.h>
9#include <vtkCellData.h>
10#include <vtkDataArray.h>
11#include <vtkDoubleArray.h>
12#include <vtkFloatArray.h>
13#include <vtkInformation.h>
14#include <vtkInformationVector.h>
15#include <vtkIntArray.h>
16#include <vtkObjectFactory.h>
17#include <vtkPointData.h>
18#include <vtkUnstructuredGrid.h>
19
20class vtkUnstructuredGrid;
21
22class TTKTRACKINGFROMPERSISTENCEDIAGRAMS_EXPORT
24 : public ttkAlgorithm,
26
27public:
29
31
32 vtkSetMacro(Tolerance, double);
33 vtkGetMacro(Tolerance, double);
34
35 vtkSetMacro(PX, double);
36 vtkGetMacro(PX, double);
37
38 vtkSetMacro(PY, double);
39 vtkGetMacro(PY, double);
40
41 vtkSetMacro(PZ, double);
42 vtkGetMacro(PZ, double);
43
44 vtkSetMacro(PE, double);
45 vtkGetMacro(PE, double);
46
47 vtkSetMacro(PS, double);
48 vtkGetMacro(PS, double);
49
50 vtkSetMacro(WassersteinMetric, const std::string &);
51 vtkGetMacro(WassersteinMetric, std::string);
52
53 vtkSetMacro(DistanceAlgorithm, const std::string &);
54 vtkGetMacro(DistanceAlgorithm, std::string);
55
56 vtkSetMacro(PVAlgorithm, int);
57 vtkGetMacro(PVAlgorithm, int);
58
59 vtkSetMacro(UseGeometricSpacing, bool);
60 vtkGetMacro(UseGeometricSpacing, bool);
61
62 vtkSetMacro(Spacing, double);
63 vtkGetMacro(Spacing, double);
64
65 vtkSetMacro(DoPostProc, bool);
66 vtkGetMacro(DoPostProc, bool);
67
68 vtkSetMacro(PostProcThresh, double);
69 vtkGetMacro(PostProcThresh, double);
70
71 static int buildMesh(
72 const std::vector<ttk::trackingTuple> &trackings,
73 const std::vector<std::vector<ttk::MatchingType>> &outputMatchings,
74 const std::vector<ttk::DiagramType> &inputPersistenceDiagrams,
75 const bool useGeometricSpacing,
76 const double spacing,
77 const bool doPostProc,
78 const std::vector<std::set<int>> &trackingTupleToMerged,
79 vtkPoints *points,
80 vtkUnstructuredGrid *persistenceDiagram,
81 vtkDoubleArray *persistenceScalars,
82 vtkDoubleArray *valueScalars,
83 vtkIntArray *matchingIdScalars,
84 vtkIntArray *lengthScalars,
85 vtkIntArray *timeScalars,
86 vtkIntArray *componentIds,
87 vtkIntArray *pointTypeScalars,
88 const ttk::Debug &dbg);
89
90 template <class triangulationType>
91 static int buildMeshAlt(
92 const triangulationType *triangulation,
93 const std::vector<ttk::trackingTuple> &trackings,
94 const std::vector<std::vector<double>> &allTrackingsCosts,
95 const std::vector<std::vector<double>> &allTrackingsInstantPersistence,
96 const bool useGeometricSpacing,
97 const double spacing,
98 vtkPoints *points,
99 vtkUnstructuredGrid *outputMesh,
100 vtkIntArray *pointsCriticalType,
101 vtkIntArray *timeScalars,
102 vtkIntArray *lengthScalars,
103 vtkIntArray *globalVertexIds,
104 vtkIntArray *connectedComponentIds,
105 vtkDoubleArray *costs,
106 vtkDoubleArray *averagePersistence,
107 vtkDoubleArray *integratedPersistence,
108 vtkDoubleArray *maximalPersistence,
109 vtkDoubleArray *minimalPersistence,
110 vtkDoubleArray *instantPersistence,
111 unsigned int *sizes) {
112
113 int pointCpt = 0;
114 int edgeCpt = 0;
115 for(unsigned int i = 0; i < trackings.size(); i++) {
117 if(i < sizes[0])
119 else if(i < sizes[1] && i >= sizes[0])
120 currentType = ttk::CriticalType::Saddle1;
121 else if(i < sizes[2] && i >= sizes[1])
122 currentType = ttk::CriticalType::Saddle2;
123 int startTime = std::get<0>(trackings[i]);
124 std::vector<ttk::SimplexId> chain = std::get<2>(trackings[i]);
125
126 float x = 0;
127 float y = 0;
128 float z = 0;
129 triangulation->getVertexPoint(chain[0], x, y, z);
130 if(useGeometricSpacing)
131 z += startTime * spacing;
132 points->InsertNextPoint(x, y, z);
133 instantPersistence->InsertTuple1(
134 pointCpt, allTrackingsInstantPersistence[i][0]);
135 double currentMaxPersistence
136 = *(std::max_element(allTrackingsInstantPersistence[i].begin(),
137 allTrackingsInstantPersistence[i].end()));
138 double currentMinPersistence
139 = *(std::min_element(allTrackingsInstantPersistence[i].begin(),
140 allTrackingsInstantPersistence[i].end()));
141 double currentIntegratedPersistence
142 = std::accumulate(allTrackingsInstantPersistence[i].begin(),
143 allTrackingsInstantPersistence[i].end(), 0.0);
144 double currentAveragePersistence
145 = currentIntegratedPersistence / (double)chain.size();
146 globalVertexIds->InsertTuple1(pointCpt, (int)chain[0]);
147 pointsCriticalType->InsertTuple1(pointCpt, (int)currentType);
148 timeScalars->InsertTuple1(pointCpt, startTime);
149 vtkIdType edge[2];
150 for(unsigned int j = 1; j < chain.size(); j++) {
151 triangulation->getVertexPoint(chain[j], x, y, z);
152 if(useGeometricSpacing)
153 z += (j + startTime) * spacing;
154 edge[0] = pointCpt;
155 pointCpt++;
156 edge[1] = pointCpt;
157 points->InsertNextPoint(x, y, z);
158 globalVertexIds->InsertTuple1(pointCpt, (int)chain[j]);
159 outputMesh->InsertNextCell(VTK_LINE, 2, edge);
160 pointsCriticalType->InsertTuple1(pointCpt, (int)currentType);
161 timeScalars->InsertTuple1(pointCpt, startTime + j);
162 lengthScalars->InsertTuple1(edgeCpt, chain.size() - 1);
163 connectedComponentIds->InsertTuple1(edgeCpt, i);
164 costs->InsertTuple1(edgeCpt, allTrackingsCosts[i][j - 1]);
165 instantPersistence->InsertTuple1(
166 pointCpt, allTrackingsInstantPersistence[i][j]);
167 integratedPersistence->InsertTuple1(
168 edgeCpt, currentIntegratedPersistence);
169 maximalPersistence->InsertTuple1(edgeCpt, currentMaxPersistence);
170 minimalPersistence->InsertTuple1(edgeCpt, currentMinPersistence);
171 averagePersistence->InsertTuple1(edgeCpt, currentAveragePersistence);
172 edgeCpt++;
173 }
174 pointCpt++;
175 }
176
177 outputMesh->SetPoints(points);
178 outputMesh->GetCellData()->AddArray(lengthScalars);
179 outputMesh->GetCellData()->AddArray(connectedComponentIds);
180 outputMesh->GetCellData()->AddArray(averagePersistence);
181 outputMesh->GetCellData()->AddArray(integratedPersistence);
182 outputMesh->GetCellData()->AddArray(maximalPersistence);
183 outputMesh->GetCellData()->AddArray(minimalPersistence);
184 outputMesh->GetPointData()->AddArray(instantPersistence);
185 outputMesh->GetCellData()->AddArray(costs);
186 outputMesh->GetPointData()->AddArray(pointsCriticalType);
187 outputMesh->GetPointData()->AddArray(timeScalars);
188 outputMesh->GetPointData()->AddArray(globalVertexIds);
189
190 return 0;
191 }
192
193protected:
195
196 int FillInputPortInformation(int port, vtkInformation *info) override;
197 int FillOutputPortInformation(int port, vtkInformation *info) override;
198
199 int RequestData(vtkInformation *request,
200 vtkInformationVector **inputVector,
201 vtkInformationVector *outputVector) override;
202
203private:
204 // Input bottleneck config.
205 bool UseGeometricSpacing{false};
206 bool DoPostProc{false};
207 double PostProcThresh{0.0};
208 double Spacing{1.0};
209 double Tolerance{1.0};
210 double PX{1};
211 double PY{1};
212 double PZ{1};
213 double PE{1};
214 double PS{1};
215 std::string DistanceAlgorithm{"ttk"};
216 int PVAlgorithm{-1};
217 std::string WassersteinMetric{"1"};
218};
virtual int RequestData(vtkInformation *ttkNotUsed(request), vtkInformationVector **ttkNotUsed(inputVectors), vtkInformationVector *ttkNotUsed(outputVector))
int FillInputPortInformation(int ttkNotUsed(port), vtkInformation *ttkNotUsed(info)) override
int FillOutputPortInformation(int ttkNotUsed(port), vtkInformation *ttkNotUsed(info)) override
static int buildMeshAlt(const triangulationType *triangulation, const std::vector< ttk::trackingTuple > &trackings, const std::vector< std::vector< double > > &allTrackingsCosts, const std::vector< std::vector< double > > &allTrackingsInstantPersistence, const bool useGeometricSpacing, const double spacing, vtkPoints *points, vtkUnstructuredGrid *outputMesh, vtkIntArray *pointsCriticalType, vtkIntArray *timeScalars, vtkIntArray *lengthScalars, vtkIntArray *globalVertexIds, vtkIntArray *connectedComponentIds, vtkDoubleArray *costs, vtkDoubleArray *averagePersistence, vtkDoubleArray *integratedPersistence, vtkDoubleArray *maximalPersistence, vtkDoubleArray *minimalPersistence, vtkDoubleArray *instantPersistence, unsigned int *sizes)
static ttkTrackingFromPersistenceDiagrams * New()
static int buildMesh(const std::vector< ttk::trackingTuple > &trackings, const std::vector< std::vector< ttk::MatchingType > > &outputMatchings, const std::vector< ttk::DiagramType > &inputPersistenceDiagrams, const bool useGeometricSpacing, const double spacing, const bool doPostProc, const std::vector< std::set< int > > &trackingTupleToMerged, vtkPoints *points, vtkUnstructuredGrid *persistenceDiagram, vtkDoubleArray *persistenceScalars, vtkDoubleArray *valueScalars, vtkIntArray *matchingIdScalars, vtkIntArray *lengthScalars, vtkIntArray *timeScalars, vtkIntArray *componentIds, vtkIntArray *pointTypeScalars, const ttk::Debug &dbg)
Minimalist debugging class.
Definition Debug.h:88
CriticalType
default value for critical index
Definition DataTypes.h:88
T end(std::pair< T, T > &p)
Definition ripser.cpp:503
T begin(std::pair< T, T > &p)
Definition ripser.cpp:499