This toy example simplifies the handle of a torus via the topological optimization of a SignedDistanceField to the input surface.
This processing pipeline first loads the surface.
Then, it computes a signed distance field to create a scalar field defined on a regular grid using the SignedDistanceField module.
The persistence diagram is computed using the PersistenceDiagram module and then it is thresholded to create a target diagram where only the persistence pair with infinite persistence is kept.
Finally, using the topological optimization backend of TopologicalSimplification, the pipeline optimizes the scalar field to remove the handle. This removal is exemplified with the cutting (bottom left) and filling (bottom right) strategies.
The python script computes the topological optimization and saves the output surfaces (for the cutting and filling strategies).
#!/usr/bin/env pythonfromparaview.simpleimport*# create a new 'XML Unstructured Grid Reader'torusvtu=XMLUnstructuredGridReader(FileName=["torus.vtu"])# create a new 'TTK SignedDistanceField'tTKSignedDistanceField1=TTKSignedDistanceField(Input=torusvtu)tTKSignedDistanceField1.SamplingDimensions=[64,64,64]# create a new 'TTK PersistenceDiagram'tTKPersistenceDiagram1=TTKPersistenceDiagram(Input=tTKSignedDistanceField1)tTKPersistenceDiagram1.ScalarField=["POINTS","signedDistanceField"]# create a new 'Threshold'threshold2=Threshold(Input=tTKPersistenceDiagram1)threshold2.Scalars=["CELLS","IsFinite"]# create a new 'TTK TopologicalSimplification'tTKTopologicalSimplification1=TTKTopologicalSimplification(Domain=tTKSignedDistanceField1,Constraints=threshold2)tTKTopologicalSimplification1.ScalarField=["POINTS","signedDistanceField"]tTKTopologicalSimplification1.Backend="Topological Optimization (IEEE VIS 2024)"tTKTopologicalSimplification1.StoppingConditionCoefficient=0.001tTKTopologicalSimplification1.MaximumIterationNumber=2000tTKTopologicalSimplification1.CancellationPrimitive="Cut-only"tTKTopologicalSimplification1.GradientStepSize=0.9# create a new 'TTK ScalarFieldSmoother'tTKScalarFieldSmoother1=TTKScalarFieldSmoother(Input=tTKTopologicalSimplification1)tTKScalarFieldSmoother1.ScalarField=["POINTS","signedDistanceField"]# create a new 'Contour'contour1=Contour(Input=tTKScalarFieldSmoother1)contour1.ContourBy=["POINTS","signedDistanceField"]contour1.Isosurfaces=[0.0]# create a new 'TTK TopologicalSimplification'tTKTopologicalSimplification2=TTKTopologicalSimplification(Domain=tTKSignedDistanceField1,Constraints=threshold2)tTKTopologicalSimplification2.ScalarField=["POINTS","signedDistanceField"]tTKTopologicalSimplification2.Backend="Topological Optimization (IEEE VIS 2024)"tTKTopologicalSimplification2.StoppingConditionCoefficient=0.001tTKTopologicalSimplification2.MaximumIterationNumber=2000tTKTopologicalSimplification2.CancellationPrimitive="Fill-only"tTKTopologicalSimplification2.GradientStepSize=0.9tTKTopologicalSimplification2.ConstraintAveraging=0# create a new 'Contour'contour2=Contour(Input=tTKTopologicalSimplification2)contour2.ContourBy=["POINTS","signedDistanceField"]contour2.Isosurfaces=[0.0]SaveData("topoOpt_torus_cut.vtp",contour1)SaveData("topoOpt_torus_fill.vtp",contour2)
To run the above Python script, go to your ttk-data directory and enter the following command: