File: TestImprintFilter4.py

package info (click to toggle)
vtk9 9.5.2%2Bdfsg3-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 205,916 kB
  • sloc: cpp: 2,336,565; ansic: 327,116; python: 111,200; yacc: 4,104; java: 3,977; sh: 3,032; xml: 2,771; perl: 2,189; lex: 1,787; makefile: 178; javascript: 165; objc: 153; tcl: 59
file content (125 lines) | stat: -rwxr-xr-x 3,224 bytes parent folder | download | duplicates (5)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python
from vtkmodules.vtkFiltersCore import vtkFeatureEdges
from vtkmodules.vtkFiltersModeling import vtkImprintFilter
from vtkmodules.vtkFiltersSources import vtkSphereSource
from vtkmodules.vtkIOLegacy import vtkPolyDataWriter
from vtkmodules.vtkRenderingCore import (
    vtkActor,
    vtkPolyDataMapper,
    vtkRenderWindow,
    vtkRenderWindowInteractor,
    vtkRenderer,
)
import vtkmodules.vtkInteractionStyle
import vtkmodules.vtkRenderingFreeType
import vtkmodules.vtkRenderingOpenGL2

# Control the resolution of the test
radius = 10.0
res = 4
debug = 0
write = 0

# Create pipeline. Use two sphere sources:
# a portion of one sphere imprints on the other.
#
target = vtkSphereSource()
target.SetRadius(radius)
target.SetCenter(0,0,0)
target.LatLongTessellationOn()
target.SetThetaResolution(4*res)
target.SetPhiResolution(4*res)
target.SetStartTheta(0)
target.SetEndTheta(90)

imprint = vtkSphereSource()
imprint.SetRadius(radius)
imprint.SetCenter(0,0,0)
imprint.LatLongTessellationOn()
imprint.SetThetaResolution(8*res)
imprint.SetPhiResolution(4*res)
imprint.SetStartTheta(12)
imprint.SetEndTheta(57)
imprint.SetStartPhi(60.0)
imprint.SetEndPhi(120.0)

# Produce an imprint
imp = vtkImprintFilter()
imp.SetTargetConnection(target.GetOutputPort())
imp.SetImprintConnection(imprint.GetOutputPort())
imp.SetTolerance(0.1)
imp.SetMergeTolerance(0.055)
if debug:
    imp.SetDebugOutputTypeToTriangulationInput()
    imp.SetDebugCellId(10)
#imp.TriangulateOutputOn()
imp.Update()

if write:
  w = vtkPolyDataWriter()
  w.SetInputConnection(imp.GetOutputPort(1))
  w.SetFileName("imp.vtk")
  w.Write()

impMapper = vtkPolyDataMapper()
impMapper.SetInputConnection(imp.GetOutputPort())
impMapper.SetScalarRange(0,2)
impMapper.SetScalarModeToUseCellFieldData()
impMapper.SelectColorArray("ImprintedCells")

impActor = vtkActor()
impActor.SetMapper(impMapper)
impActor.GetProperty().SetColor(1,0,0)

imprintMapper = vtkPolyDataMapper()
imprintMapper.SetInputConnection(imprint.GetOutputPort())

imprintActor = vtkActor()
imprintActor.SetMapper(imprintMapper)
imprintActor.GetProperty().SetColor(1,1,1)

fedges = vtkFeatureEdges()
fedges.SetInputConnection(imp.GetOutputPort())
fedges.ExtractAllEdgeTypesOff()
fedges.NonManifoldEdgesOn()
fedges.BoundaryEdgesOn()

fedgesMapper = vtkPolyDataMapper()
fedgesMapper.SetInputConnection(fedges.GetOutputPort())

fedgesActor = vtkActor()
fedgesActor.SetMapper(fedgesMapper)
fedgesActor.GetProperty().SetRepresentationToWireframe()
fedgesActor.GetProperty().SetColor(0,1,0)

# Second output if needed
if debug:
    out2Mapper = vtkPolyDataMapper()
    out2Mapper.SetInputConnection(imp.GetOutputPort(1))
    out2Actor = vtkActor()
    out2Actor.SetMapper(out2Mapper)
    out2Actor.GetProperty().SetColor(1,1,0)

# Create the RenderWindow, Renderer
#
ren1 = vtkRenderer()
renWin = vtkRenderWindow()
renWin.AddRenderer( ren1 )
renWin.SetSize(300,200)

iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

ren1.AddActor(impActor)
#ren1.AddActor(imprintActor)
ren1.AddActor(fedgesActor)
if debug:
    ren1.AddActor(out2Actor)

cam = ren1.GetActiveCamera()
cam.SetPosition(1,0.5,0)
cam.SetFocalPoint(0,0,0)
ren1.ResetCamera()

renWin.Render()
iren.Start()