| import os |
| import sys |
|
|
| |
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../..')) |
|
|
| from topologyScoring import mergeTreePartialFusedGWDistanceScore, mergeTreePersistenceWassersteinScore |
|
|
| def evaluateMergetree(gtPointsFilename : str, gtEdgesFilename : str, reconPointsFilename : str, |
| reconEdgesFilename : str, verbose : bool = False) -> int: |
| """ |
| Given two merge trees, return a similarity score from 0-10. |
| |
| This implementation only works with join trees, and not split trees or contour trees. Each merge tree |
| should be stored as two legacy VTK files (.vtk) where there is one file for the points and another for the edges. |
| The edges file should store the edges as cells of type vtkLine. |
| The points file should have an array called "CriticalType" which labels each vertex according to what type of |
| critical point it is. It should follow: 0: minimum. 1: 1-saddle. 2: 2-saddle. 3: maximum. 4: degenerate critical point. |
| The points file should also have an array called "Scalar" which stores the scalar field value at that point. |
| |
| A score of 0 is considered bad and 10 is considered good. The score is computed based on the partial fused GW distance between |
| the two trees, as well as the Wasserstein distance between their persistence diagrams. These two distances are weighted equally. |
| For more information on the partial fused GW distance, see: |
| Mingzhe Li et al. "Flexible and Probabilistic Topology Tracking With Partial Optimal Transport". |
| doi: 10.1109/TVCG.2025.3561300 |
| |
| Args: |
| gtPointsFilename: The name of a file in legacy VTK format (.vtk) that stores the points of the ground truth merge tree |
| along with the critical types and scalar field values. |
| gtEdgesFilename: The name of a file in legacy VTK format (.vtk) that stores the points of the ground truth merge tree. |
| reconPointsFilename: The name of a file in legacy VTK format (.vtk) that stores the points of the reconstructed merge tree |
| along with the critical types and scalar field values. |
| reconEdgesFilename: The name of a file in legacy VTK format (.vtk) that stores the edges of the reconstructed merge tree. |
| Returns: |
| A score from 0-10 comparing the similarity of the two merge trees. |
| |
| """ |
|
|
| pFGWScore = mergeTreePartialFusedGWDistanceScore(gtPointsFilename, gtEdgesFilename, "CriticalType", "Scalar", |
| reconPointsFilename, reconEdgesFilename, "CriticalType", "Scalar", verbose ) |
|
|
| persistenceScore = mergeTreePersistenceWassersteinScore(gtPointsFilename, gtEdgesFilename, "Scalar", |
| reconPointsFilename, reconEdgesFilename, "Scalar", verbose) |
|
|
| return (pFGWScore + persistenceScore) / 2 |
|
|
| if __name__ == "__main__": |
|
|
| if len(sys.argv) != 5: |
| print(f"{os.path.basename(__file__)}: usage is 'python3 {os.path.basename(__file__)} gt_points_file.vtk gt_edge_file.vtk reconstructed_points_file.vtk reconstructed_edges_file.vtk'") |
| exit(1) |
|
|
| score = evaluateMergetree(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], verbose=True) |
|
|
| print(f"This merge tree scored: {score}") |