TTK
Loading...
Searching...
No Matches
ttkMergeTreeClustering.h
Go to the documentation of this file.
1
45
46#pragma once
47
48// VTK Module
49#include <ttkMergeTreeClusteringModule.h>
50
51// VTK Includes
52#include <ttkAlgorithm.h>
53#include <vtkMultiBlockDataSet.h>
54#include <vtkSmartPointer.h>
55#include <vtkUnstructuredGrid.h>
56
57// TTK Base Includes
58#include <MergeTreeBarycenter.h>
59#include <MergeTreeClustering.h>
60#include <MergeTreeDistance.h>
61
62class TTKMERGETREECLUSTERING_EXPORT ttkMergeTreeClustering
63 : public ttkAlgorithm // we inherit from the generic ttkAlgorithm class
64//, protected ttk::MergeTreeDistance // and we inherit from the base class
65{
66private:
71 // Input Options
72 bool Epsilon1UseFarthestSaddle = false;
73 double EpsilonTree1 = 5.;
74 double EpsilonTree2 = 5.;
75 double Epsilon2Tree1 = 95.;
76 double Epsilon2Tree2 = 95.;
77 double Epsilon3Tree1 = 90.;
78 double Epsilon3Tree2 = 90.;
79 double PersistenceThreshold = 0.;
80 bool DeleteMultiPersPairs = false;
81 bool UseMinMaxPair = true;
82 bool IsPersistenceDiagram = false;
83
84 // Execution Options
85 int Backend = 0;
86 double Alpha = 0.5;
87 int AssignmentSolver = 0;
88 bool BranchDecomposition = true;
89 bool NormalizedWasserstein = true;
90 bool KeepSubtree = false;
91 bool oldBD = BranchDecomposition;
92 bool oldNW = NormalizedWasserstein;
93 bool oldKS = KeepSubtree;
94 double JoinSplitMixtureCoefficient = 0.5;
95 int DiagramPairTypes = 0;
96 bool ComputeBarycenter = false;
97 unsigned int NumberOfBarycenters = 1;
98 double BarycenterSizeLimitPercent = 0.0;
99 bool Deterministic = false;
100 int pathMetric = 0;
101 int branchMetric = 0;
102 int baseModule = 0;
103 double NonMatchingWeight = 1.0;
104
105 // Output Options
106 bool OutputTrees = true;
107 bool OutputSegmentation = false;
108 bool PlanarLayout = false;
109 bool BranchDecompositionPlanarLayout = false;
110 double BranchSpacing = 1.;
111 bool RescaleTreesIndividually = false;
112 double DimensionSpacing = 1.;
113 int DimensionToShift = 0;
114 double ImportantPairs = 50.;
115 int MaximumImportantPairs = 0;
116 int MinimumImportantPairs = 0;
117 double ImportantPairsSpacing = 1.;
118 double NonImportantPairsSpacing = 1.;
119 double NonImportantPairsProximity = 0.05;
120 bool BarycenterPositionAlpha = false;
121 std::string ExcludeImportantPairsLower = "";
122 std::string ExcludeImportantPairsHigher = "";
123
124 // ----------------------
125 // Data for visualization
126 // ----------------------
127 // Trees
128 std::vector<ttk::ftm::MergeTree<double>> intermediateSTrees,
129 intermediateSTrees2;
130 std::vector<vtkUnstructuredGrid *> treesNodes, treesNodes2;
131 std::vector<vtkUnstructuredGrid *> treesArcs, treesArcs2;
132 std::vector<vtkDataSet *> treesSegmentation, treesSegmentation2;
133
134 // Matching
135 std::vector<std::tuple<ttk::ftm::idNode, ttk::ftm::idNode, double>>
136 outputMatching;
137 std::vector<std::vector<
138 std::vector<std::tuple<ttk::ftm::idNode, ttk::ftm::idNode, double>>>>
139 outputMatchingBarycenter, outputMatchingBarycenter2;
140
141 // Barycenter
142 std::vector<ttk::ftm::MergeTree<double>> barycentersS, barycentersS2;
143 std::vector<int> clusteringAssignment;
144
145 // Node correspondence
146 std::vector<std::vector<int>> trees1NodeCorrMesh, trees2NodeCorrMesh;
147
148 // Distances
149 std::vector<double> finalDistances;
150
151 void setDataVisualization(int numInputs, int numInputs2) {
152 // Trees
153 intermediateSTrees = std::vector<ttk::ftm::MergeTree<double>>(numInputs);
154 intermediateSTrees2 = std::vector<ttk::ftm::MergeTree<double>>(numInputs2);
155 treesNodes = std::vector<vtkUnstructuredGrid *>(numInputs);
156 treesNodes2 = std::vector<vtkUnstructuredGrid *>(numInputs2);
157 treesArcs = std::vector<vtkUnstructuredGrid *>(numInputs);
158 treesArcs2 = std::vector<vtkUnstructuredGrid *>(numInputs2);
159 treesSegmentation = std::vector<vtkDataSet *>(numInputs);
160 treesSegmentation2 = std::vector<vtkDataSet *>(numInputs2);
161
162 // Matching
163 outputMatchingBarycenter = std::vector<std::vector<
164 std::vector<std::tuple<ttk::ftm::idNode, ttk::ftm::idNode, double>>>>(
165 NumberOfBarycenters,
166 std::vector<
167 std::vector<std::tuple<ttk::ftm::idNode, ttk::ftm::idNode, double>>>(
168 numInputs));
169
170 outputMatchingBarycenter2 = std::vector<std::vector<
171 std::vector<std::tuple<ttk::ftm::idNode, ttk::ftm::idNode, double>>>>(
172 NumberOfBarycenters,
173 std::vector<
174 std::vector<std::tuple<ttk::ftm::idNode, ttk::ftm::idNode, double>>>(
175 numInputs2));
176
177 // Barycenter
178 barycentersS
179 = std::vector<ttk::ftm::MergeTree<double>>(NumberOfBarycenters);
180 clusteringAssignment = std::vector<int>(numInputs, 0);
181 }
182
183 void resetDataVisualization() {
184 setDataVisualization(0, 0);
185 trees1NodeCorrMesh = std::vector<std::vector<int>>();
186 trees2NodeCorrMesh = std::vector<std::vector<int>>();
187 finalDistances = std::vector<double>();
188 }
189
190 bool isDataVisualizationFilled() {
191 return trees1NodeCorrMesh.size() != 0 and finalDistances.size() != 0;
192 }
193
194public:
199 // Input Options
200 void SetEpsilon1UseFarthestSaddle(bool epsilon1UseFarthestSaddle) {
201 Epsilon1UseFarthestSaddle = epsilon1UseFarthestSaddle;
202 Modified();
203 resetDataVisualization();
204 }
205 vtkGetMacro(Epsilon1UseFarthestSaddle, bool);
206
207 void SetEpsilonTree1(double epsilonTree1) {
208 EpsilonTree1 = epsilonTree1;
209 Modified();
210 resetDataVisualization();
211 }
212 vtkGetMacro(EpsilonTree1, double);
213
214 void SetEpsilon2Tree1(double epsilon2Tree1) {
215 Epsilon2Tree1 = epsilon2Tree1;
216 Modified();
217 resetDataVisualization();
218 }
219 vtkGetMacro(Epsilon2Tree1, double);
220
221 void SetEpsilon3Tree1(double epsilon3Tree1) {
222 Epsilon3Tree1 = epsilon3Tree1;
223 Modified();
224 resetDataVisualization();
225 }
226 vtkGetMacro(Epsilon3Tree1, double);
227
228 void SetPersistenceThreshold(double persistenceThreshold) {
229 PersistenceThreshold = persistenceThreshold;
230 Modified();
231 resetDataVisualization();
232 }
233 vtkGetMacro(PersistenceThreshold, double);
234
235 void SetUseMinMaxPair(bool useMinMaxPair) {
236 UseMinMaxPair = useMinMaxPair;
237 Modified();
238 resetDataVisualization();
239 }
240 vtkGetMacro(UseMinMaxPair, bool);
241
242 void SetDeleteMultiPersPairs(bool deleteMultiPersPairs) {
243 DeleteMultiPersPairs = deleteMultiPersPairs;
244 Modified();
245 resetDataVisualization();
246 }
247 vtkGetMacro(DeleteMultiPersPairs, bool);
248
249 // Execution Options
250 void SetBackend(int newBackend) {
251 if(Backend == 2) { // Custom
252 oldBD = BranchDecomposition;
253 oldNW = NormalizedWasserstein;
254 oldKS = KeepSubtree;
255 }
256 if(newBackend == 2) { // Custom
257 BranchDecomposition = oldBD;
258 NormalizedWasserstein = oldNW;
259 KeepSubtree = oldKS;
260 }
261 Backend = newBackend;
262 Modified();
263 resetDataVisualization();
264 }
265 vtkGetMacro(Backend, int);
266
267 void SetAlpha(double alpha) {
268 Alpha = 1 - alpha;
269 Alpha = std::min(1 - 1e-6, Alpha);
270 Alpha = std::max(1e-6, Alpha);
271 Modified();
272 resetDataVisualization();
273 }
274 vtkGetMacro(Alpha, double);
275
276 void SetAssignmentSolver(int assignmentSolver) {
277 AssignmentSolver = assignmentSolver;
278 Modified();
279 resetDataVisualization();
280 }
281 vtkGetMacro(AssignmentSolver, int);
282
283 void SetBranchDecomposition(bool branchDecomposition) {
284 BranchDecomposition = branchDecomposition;
285 Modified();
286 resetDataVisualization();
287 }
288 vtkGetMacro(BranchDecomposition, bool);
289
290 void SetDeterministic(bool deterministic) {
291 Deterministic = deterministic;
292 Modified();
293 resetDataVisualization();
294 }
295 vtkGetMacro(Deterministic, bool);
296
297 void SetNormalizedWasserstein(bool normalizedWasserstein) {
298 NormalizedWasserstein = normalizedWasserstein;
299 Modified();
300 resetDataVisualization();
301 }
302 vtkGetMacro(NormalizedWasserstein, bool);
303
304 void SetKeepSubtree(bool keepSubtree) {
305 KeepSubtree = keepSubtree;
306 Modified();
307 resetDataVisualization();
308 }
309 vtkGetMacro(KeepSubtree, bool);
310
311 void SetJoinSplitMixtureCoefficient(double joinSplitMixtureCoefficient) {
312 JoinSplitMixtureCoefficient = joinSplitMixtureCoefficient;
313 Modified();
314 resetDataVisualization();
315 }
316 vtkGetMacro(JoinSplitMixtureCoefficient, double);
317
318 void SetDiagramPairTypes(int diagramPairTypes) {
319 DiagramPairTypes = diagramPairTypes;
320 Modified();
321 resetDataVisualization();
322 }
323 vtkGetMacro(DiagramPairTypes, int);
324
325 void SetComputeBarycenter(bool computeBarycenter) {
326 ComputeBarycenter = computeBarycenter;
327 Modified();
328 resetDataVisualization();
329 }
330 vtkGetMacro(ComputeBarycenter, bool);
331
332 void SetNumberOfBarycenters(unsigned int numberOfBarycenters) {
333 NumberOfBarycenters = numberOfBarycenters;
334 Modified();
335 resetDataVisualization();
336 }
337 vtkGetMacro(NumberOfBarycenters, unsigned int);
338
339 void SetBarycenterSizeLimitPercent(double percent) {
340 BarycenterSizeLimitPercent = percent;
341 Modified();
342 resetDataVisualization();
343 }
344 vtkGetMacro(BarycenterSizeLimitPercent, double);
345
346 void SetBranchMetric(int m) {
347 branchMetric = m;
348 Modified();
349 }
350
351 void SetPathMetric(int m) {
352 pathMetric = m;
353 Modified();
354 }
355
356 void SetNonMatchingWeight(double weight) {
357 NonMatchingWeight = weight;
358 Modified();
359 resetDataVisualization();
360 }
361 vtkGetMacro(NonMatchingWeight, double);
362
363 // Output Options
364 vtkSetMacro(BarycenterPositionAlpha, bool);
365 vtkGetMacro(BarycenterPositionAlpha, bool);
366
367 vtkSetMacro(OutputTrees, bool);
368 vtkGetMacro(OutputTrees, bool);
369
370 vtkSetMacro(OutputSegmentation, bool);
371 vtkGetMacro(OutputSegmentation, bool);
372
373 vtkSetMacro(PlanarLayout, bool);
374 vtkGetMacro(PlanarLayout, bool);
375
376 vtkSetMacro(BranchDecompositionPlanarLayout, bool);
377 vtkGetMacro(BranchDecompositionPlanarLayout, bool);
378
379 vtkSetMacro(BranchSpacing, double);
380 vtkGetMacro(BranchSpacing, double);
381
382 vtkSetMacro(RescaleTreesIndividually, bool);
383 vtkGetMacro(RescaleTreesIndividually, bool);
384
385 vtkSetMacro(DimensionSpacing, double);
386 vtkGetMacro(DimensionSpacing, double);
387
388 vtkSetMacro(DimensionToShift, int);
389 vtkGetMacro(DimensionToShift, int);
390
391 vtkSetMacro(ImportantPairs, double);
392 vtkGetMacro(ImportantPairs, double);
393
394 vtkSetMacro(MaximumImportantPairs, int);
395 vtkGetMacro(MaximumImportantPairs, int);
396
397 vtkSetMacro(MinimumImportantPairs, int);
398 vtkGetMacro(MinimumImportantPairs, int);
399
400 vtkSetMacro(ImportantPairsSpacing, double);
401 vtkGetMacro(ImportantPairsSpacing, double);
402
403 vtkSetMacro(NonImportantPairsSpacing, double);
404 vtkGetMacro(NonImportantPairsSpacing, double);
405
406 vtkSetMacro(NonImportantPairsProximity, double);
407 vtkGetMacro(NonImportantPairsProximity, double);
408
409 vtkSetMacro(ExcludeImportantPairsLower, const std::string &);
410 vtkGetMacro(ExcludeImportantPairsLower, std::string);
411
412 vtkSetMacro(ExcludeImportantPairsHigher, const std::string &);
413 vtkGetMacro(ExcludeImportantPairsHigher, std::string);
414
421
422protected:
429
434 int FillInputPortInformation(int port, vtkInformation *info) override;
435
440 int FillOutputPortInformation(int port, vtkInformation *info) override;
441
446 int RequestData(vtkInformation *request,
447 vtkInformationVector **inputVector,
448 vtkInformationVector *outputVector) override;
449
450 template <class dataType>
451 int run(vtkInformationVector *outputVector,
452 std::vector<vtkSmartPointer<vtkMultiBlockDataSet>> &inputTrees,
453 std::vector<vtkSmartPointer<vtkMultiBlockDataSet>> &inputTrees2);
454
455 template <class dataType>
457 vtkInformationVector *outputVector,
458 std::vector<vtkSmartPointer<vtkMultiBlockDataSet>> &inputTrees,
459 std::vector<vtkSmartPointer<vtkMultiBlockDataSet>> &inputTrees2);
460
461 template <class dataType>
463 vtkInformationVector *outputVector,
464 std::vector<vtkSmartPointer<vtkMultiBlockDataSet>> &inputTrees,
465 std::vector<vtkSmartPointer<vtkMultiBlockDataSet>> &inputTrees2);
466};
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
void SetBarycenterSizeLimitPercent(double percent)
void SetKeepSubtree(bool keepSubtree)
void SetDeterministic(bool deterministic)
void SetComputeBarycenter(bool computeBarycenter)
void SetAssignmentSolver(int assignmentSolver)
void SetEpsilon1UseFarthestSaddle(bool epsilon1UseFarthestSaddle)
void SetJoinSplitMixtureCoefficient(double joinSplitMixtureCoefficient)
void SetEpsilonTree1(double epsilonTree1)
void SetDiagramPairTypes(int diagramPairTypes)
void SetNumberOfBarycenters(unsigned int numberOfBarycenters)
void SetBackend(int newBackend)
int runCompute(vtkInformationVector *outputVector, std::vector< vtkSmartPointer< vtkMultiBlockDataSet > > &inputTrees, std::vector< vtkSmartPointer< vtkMultiBlockDataSet > > &inputTrees2)
void SetUseMinMaxPair(bool useMinMaxPair)
static ttkMergeTreeClustering * New()
void SetEpsilon2Tree1(double epsilon2Tree1)
int run(vtkInformationVector *outputVector, std::vector< vtkSmartPointer< vtkMultiBlockDataSet > > &inputTrees, std::vector< vtkSmartPointer< vtkMultiBlockDataSet > > &inputTrees2)
void SetDeleteMultiPersPairs(bool deleteMultiPersPairs)
void SetEpsilon3Tree1(double epsilon3Tree1)
int runOutput(vtkInformationVector *outputVector, std::vector< vtkSmartPointer< vtkMultiBlockDataSet > > &inputTrees, std::vector< vtkSmartPointer< vtkMultiBlockDataSet > > &inputTrees2)
void SetBranchDecomposition(bool branchDecomposition)
void SetPersistenceThreshold(double persistenceThreshold)
void SetNonMatchingWeight(double weight)
~ttkMergeTreeClustering() override
void SetNormalizedWasserstein(bool normalizedWasserstein)