Skip to content

Merge Tree Principal Geodesic Analysis

Merge Tree Principal Geodesic Analysis example Image

Pipeline description

This example first loads an ensemble of scalar fields inside a cinema database from disk. Then, the MergeTree is computed on each scalar field to compute the Split Tree.

All these trees are passed to MergeTreePrincipalGeodesics to compute principal geodesic analysis in the metric space of merge trees.

Then the filter MergeTreePrincipalGeodesicsDecoding is used to reconstruct the input trees, to sample evenly trees along the principal geodesics and to sample a discrete grid of merge trees of the PGA basis.

A distance matrix is then computed with MergeTreeDistanceMatrix with the trees of the grid. This distance matrix is used as input of DimensionReduction to compute a MultiDimensional Scaling (MDS), performing a dimensionality reduction in 3D (and 2D with a second DimensionReduction filter) respecting the most the input distance matrix.

Finally the PointSetToSurface and ProjectionFromTable are used to create the 3D surface (and the 2D surface). The ProjectionFromTable allows to project the points (reconstructed trees, geodesic trees etc.) to the 3D (or 2D) surface.

In terms of visualisation, a scalar field of each cluster is displayed with a zoom on their right of the important persistence pairs. The original trees are displayed alongside their reconstruction at their right. The persistence pairs of the trees are colored by ID to see what features they correspond to in the scalar field.

The 3D and 2D surface are displayed with the persistence correlation view at the top right. The 12 scalar fields are colored by Cluster ID. Finally, a path drawn with PolyLineSource on the surface is drawn at the bottom right to show how we can interactivily explore the MT-PGA basis in user-defined locations.

The python script computes the MT-PGA basis. It saves the resulting coefficients of the input trees and the geodesics of the basis. Finally it saves the reconstructed trees given the basis and the coordinates of the trees in the basis.

ParaView

To reproduce the above screenshot, go to your ttk-data directory and enter the following command:

paraview states/mergeTreePGA.pvsm

Python code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python

from paraview.simple import *

# create a new 'TTK CinemaReader'
tTKCinemaReader1 = TTKCinemaReader(DatabasePath="./Earthquake.cdb")

# create a new 'TTK CinemaProductReader'
tTKCinemaProductReader1 = TTKCinemaProductReader(Input=tTKCinemaReader1)
tTKCinemaProductReader1.AddFieldDataRecursively = 1

# create a new 'TTK Merge and Contour Tree'
tTKMergeandContourTreeFTM1 = TTKMergeTree(Input=tTKCinemaProductReader1)
tTKMergeandContourTreeFTM1.ScalarField = ["POINTS", "VectorMag"]
tTKMergeandContourTreeFTM1.TreeType = "Split Tree"

# create a new 'TTK BlockAggregator'
tTKBlockAggregator1 = TTKBlockAggregator(
    Input=[
        tTKMergeandContourTreeFTM1,
        OutputPort(tTKMergeandContourTreeFTM1, 1),
        OutputPort(tTKMergeandContourTreeFTM1, 2),
    ]
)
tTKBlockAggregator1.FlattenInput = 0

# create a new 'TTK MergeTreePrincipalGeodesics'
tTKMergeTreePrincipalGeodesics1 = TTKMergeTreePrincipalGeodesics(
    Input=tTKBlockAggregator1, OptionalInput=None
)
tTKMergeTreePrincipalGeodesics1.BarycenterSizeLimitPercent = 17.0
tTKMergeTreePrincipalGeodesics1.Deterministic = 1
tTKMergeTreePrincipalGeodesics1.Epsilon1 = 1.5
tTKMergeTreePrincipalGeodesics1.Epsilon2 = 35.0
tTKMergeTreePrincipalGeodesics1.Epsilon3 = 34.0
tTKMergeTreePrincipalGeodesics1.PersistenceThreshold = 1.0
tTKMergeTreePrincipalGeodesics1.DeleteMultiPersistencePairs = 1

# create a new 'TTK MergeTreePrincipalGeodesicsDecoding'
tTKMergeTreePrincipalGeodesicsDecoding1 = TTKMergeTreePrincipalGeodesicsDecoding(
    Barycenter=tTKMergeTreePrincipalGeodesics1,
    Coefficients=OutputPort(tTKMergeTreePrincipalGeodesics1, 1),
    GeodesicsVectors=OutputPort(tTKMergeTreePrincipalGeodesics1, 2),
    CorrelationMatrixoptional=None,
    InputTreesoptional=None,
)

# save the output
SaveData("MT-PGA_coef.csv", OutputPort(tTKMergeTreePrincipalGeodesics1, 1))
SaveData("MT-PGA_geodesics.csv", OutputPort(tTKMergeTreePrincipalGeodesics1, 2))
SaveData("MT-PGA_reconstructed_trees.vtm", tTKMergeTreePrincipalGeodesicsDecoding1)

To run the above Python script, go to your ttk-data directory and enter the following command:

pvpython python/mergeTreePGA.py

Inputs

Outputs

  • MT-PGA_coef.csv: the coefficients of the input trees corresponding to their coordinates in the PGA basis.
  • MT-PGA_geodesics.csv: the geodesics of the PGA basis.
  • MT-PGA_reconstructed_trees.vtm: the reconstructed input trees.

C++/Python API

BlockAggregator

CinemaProductReader

CinemaReader

DataSetToTable

DimensionReduction

FlattenMultiBlock

MergeTree

GeometrySmoother

MergeBockTables

MergeTreeClustering

MergeTreeDistanceMatrix

MergeTreePrincipalGeodesics

MergeTreePrincipalGeodesicsDecoding

PointSetToCurve

PointSetToSurface

ProjectionFromTable