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