This example simplifies a handle defect on an acquired surface geometry (pegasus statue) via the topological optimization of a SignedDistanceField to the input surface.
The processing pipeline first loads the surface and clips it to extract the handle defect.
It then 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 the persistence pair corresponding to the handle defect is removed.
Finally, using the topological optimization backend of TopologicalSimplification, the pipeline optimizes the scalar field to remove the handle defect from the level set corresponding to the considered surface. This removal is exemplified with the cutting (bottom left) and filling (bottom right) strategies.
Note that the handle defect can be detected by identifying the PersistentGenerators of smallest size. In this example, the PersistentGenerators are computed out of a low resolution signed distance field (to make the example easily computable). To detect the handle defect, a higher resolution is required (typically 1024^3 -- expect hours of computation -- but then TTK needs to be built with 64 bit identifiers, TTK_ENABLE_64BIT_IDS=ON).
The python script computes the topological optimization and saves the optimized scalar fields with the cutting and the filling strategies.
#!/usr/bin/env pythonfromparaview.simpleimport*# create a new 'XML Unstructured Grid Reader'pegasusvtu=XMLUnstructuredGridReader(FileName=["pegasus.vtu"])# create a new 'Clip'clip1=Clip(Input=pegasusvtu)clip1.ClipType="Plane"# init the 'Plane' selected for 'ClipType'clip1.ClipType.Origin=[29.7661,0.0,0.0]clip1.ClipType.Normal=[-1.0,0.0,0.0]# create a new 'Clip'clip2=Clip(Input=clip1)clip2.ClipType="Plane"# init the 'Plane' selected for 'ClipType'clip2.ClipType.Origin=[0.0,-40.2344,0.0]clip2.ClipType.Normal=[0.0,-1.0,0.0]# create a new 'Clip'clip3=Clip(Input=clip2)clip3.ClipType="Plane"# init the 'Plane' selected for 'ClipType'clip3.ClipType.Origin=[0.0,0.0,-1141.19]clip3.ClipType.Normal=[0.0,0.0,-1.0]# create a new 'Clip'clip4=Clip(Input=clip3)clip4.ClipType="Plane"# init the 'Plane' selected for 'ClipType'clip4.ClipType.Origin=[35.8833,0.0,0.0]# create a new 'Clip'clip5=Clip(Input=clip4)clip5.ClipType="Plane"# init the 'Plane' selected for 'ClipType'clip5.ClipType.Origin=[0.0,-28.6559,0.0]clip5.ClipType.Normal=[0.0,1.0,0.0]# create a new 'Clip'clip6=Clip(Input=clip5)clip6.ClipType="Plane"# init the 'Plane' selected for 'ClipType'clip6.ClipType.Origin=[0.0,0.0,-1133.85]clip6.ClipType.Normal=[0.0,0.0,1.0]# create a new 'Tetrahedralize'tetrahedralize1=Tetrahedralize(Input=clip6)# create a new 'TTK SignedDistanceField'tTKSignedDistanceField1=TTKSignedDistanceField(Input=tetrahedralize1)tTKSignedDistanceField1.SamplingDimensions=[68,128,81]tTKSignedDistanceField1.ExpandBox=0# create a new 'Calculator'calculator2=Calculator(Input=tTKSignedDistanceField1)calculator2.Function="-signedDistanceField"# create a new 'TTK PersistenceDiagram'tTKPersistenceDiagram3=TTKPersistenceDiagram(Input=calculator2)tTKPersistenceDiagram3.ScalarField=["POINTS","Result"]# create a new 'Threshold'threshold4=Threshold(Input=tTKPersistenceDiagram3)threshold4.Scalars=["CELLS","Persistence"]threshold4.LowerThreshold=0.277threshold4.UpperThreshold=0.278threshold4.Invert=1# create a new 'TTK TopologicalSimplification'tTKTopologicalSimplification2=TTKTopologicalSimplification(Domain=calculator2,Constraints=threshold4)tTKTopologicalSimplification2.ScalarField=["POINTS","Result"]tTKTopologicalSimplification2.Backend="Topological Optimization (IEEE VIS 2024)"tTKTopologicalSimplification2.StoppingConditionCoefficient=1e-05tTKTopologicalSimplification2.MaximumIterationNumber=125tTKTopologicalSimplification2.CancellationPrimitive="Fill-only"tTKTopologicalSimplification2.GradientStepSize=1.252# create a new 'TTK TopologicalSimplification'tTKTopologicalSimplification1=TTKTopologicalSimplification(Domain=calculator2,Constraints=threshold4)tTKTopologicalSimplification1.ScalarField=["POINTS","Result"]tTKTopologicalSimplification1.Backend="Topological Optimization (IEEE VIS 2024)"tTKTopologicalSimplification1.StoppingConditionCoefficient=1e-05tTKTopologicalSimplification1.MaximumIterationNumber=125tTKTopologicalSimplification1.CancellationPrimitive="Cut-only"tTKTopologicalSimplification1.GradientStepSize=1.1# save the outputSaveData("topoOpt_pegasus_fill.vti",tTKTopologicalSimplification2)SaveData("topoOpt_pegasus_cut.vti",tTKTopologicalSimplification1)
To run the above Python script, go to your ttk-data directory and enter the following command: