Skip to content

Topological Optimization for Pegasus Genus Repair

Topological Optimization Pegasus example Image

Pipeline description

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.

ParaView

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

paraview states/topologicalOptimization_pegasus.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
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
#!/usr/bin/env python

from paraview.simple import *

# 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.277
threshold4.UpperThreshold = 0.278
threshold4.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-05
tTKTopologicalSimplification2.MaximumIterationNumber = 125
tTKTopologicalSimplification2.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-05
tTKTopologicalSimplification1.MaximumIterationNumber = 125
tTKTopologicalSimplification1.CancellationPrimitive = "Cut-only"
tTKTopologicalSimplification1.GradientStepSize = 1.1

# save the output
SaveData("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:

pvpython python/topologicalOptimization_pegasus.py

Inputs

  • pegasus.vtu: An acquired surface geometry representing a pegasus statue.

Outputs

  • topoOpt_pegasus_fill.vti: the optimized dataset with the fill strategy.
  • topoOpt_pegasus_cut.vti: the optimized dataset with the cut strategy.

C++/Python API

GeometrySmoother

PersistenceDiagram

PersistentGenerators

ScalarFieldSmoother

SignedDistanceField

TopologicalSimplification