import os import sys # Add the topology directory to Python path sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../..')) from topologyScoring import pointCloudGeometryScore, partitionAssignmentDiceScore def evaluate2DAsymmetricTFTopology(gtDPFilename : str, gtEigenvectorFilename : str, gtEigenvalueFilename : str, reconDPFilename : str, reconEigenvectorFilename : str, reconEigenvalueFilename : str, verbose : bool = False) -> int: """ Given the topological descriptors computed from two 2D asymmetric tensor fields, return a score from 0-10 comparing their topology. A score of 0 is considered bad and 10 is considered good. 5 points come from the eigenvector partition, while 5 points come from the eigenvalue partition. The scoring for the eigenvector partition is divided evenly between the placement of the degenerate points as well as the partition itself. Because classifications in the eigenvector and eigenvalue partitions do not interpolate linearly inside of cells, it can be advantageous to store them in a mesh with a higher resolution than original dataset. This function supports eigenvector and eigenvalue partition meshes at arbitrary resolutions, provided that the mesh represents an integer scaling in terms of the number of grid cells. For example, suppose that the dataset is defined on a mesh with a width of m square grid cells, then this function supports eigenvector and eigenvalue partition meshes with a width of nm for any positive integer n. Note that this is the number of grid cells, and not points (which represent the vertices of the grid cells). In the case above, the original mesh would contain m+1 points and this function supports meshes with nm+1 points for positive integers n. The resolution of the ground truth and reconstructed data do not need to match but they do need to be validly supported resolutions. Args: gtDPFilename: The name of a file in legacy VTK format (.vtk) that stores the locations of each degenerate point in the ground truth data. It should also have a point array called "DegeneracyType". It should assign a value of 0 to each trisector and 1 for each wedge. gtEigenvectorFilename: The name of a file containing VTK image data (.vti) that classifies each point according to its classification in the eigenvector partition. The classifications should be stored in a point array called "Partition". It should assign values as follows: 0: W_{c,s}. 1: W_{r,s} 2: W_{r,n}. 3: W_{c,n}. gtEigenvalueFilename: The name of a file containing VTK image data (.vti) that classifies each point according to its classification in the eigenvalue partition. The classifications should be stored in a point array called "Partition". It should assign values as follows: 0: positive scaling. 1: counterclockwise rotation. 2: negative scaling. 3: clockwise rotation. 4: anisotropic stretching. reconDPFilename: The name of a file in legacy VTK format (.vtk) that stores the locations and degeneracy types of the degenerate points of the reconstructed data. reconEigenvectorFilename: The name of a file containing VTK image data (.vti) that classifies each point according to the eigenvector partition. reconEigenvalueFilename: The name of a file containing VTK image data (.vti) that classifies each point according to the eigenvalue partition. verbose: Should error messages be printed if there are issues with the input files. """ pointScore = pointCloudGeometryScore(gtDPFilename, "DegeneracyType", reconDPFilename, "DegeneracyType", verbose) eigenvectorDiceScore = partitionAssignmentDiceScore(gtEigenvectorFilename, "Partition", reconEigenvectorFilename, "Partition", verbose, allowResampling=True) eigenvalueDiceScore = partitionAssignmentDiceScore(gtEigenvalueFilename, "Partition", reconEigenvalueFilename, "Partition", verbose, allowResampling=True) eigenvectorScore = (pointScore + eigenvectorDiceScore) / 2 totalScore = (eigenvalueDiceScore + eigenvectorScore) / 2 return totalScore if __name__ == "__main__": if len(sys.argv) != 7: print(f"{os.path.basename(__file__)}: usage is 'python3 {os.path.basename(__file__)} gt_degenerate_points.vtk gt_eigenvector_partition.vti gt_eigenvalue_partition.vti'" \ " recon_degenerate_points.vtk recon_eigenvector_partition.vti recon_eigenvalue_partition.vti") exit(1) score = evaluate2DAsymmetricTFTopology(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5], sys.argv[6], verbose=True) print(f"This eigenvector and eigenvalue partition scored: {score}")