File: TextureThreshold.tcl

package info (click to toggle)
vtk7 7.1.1%2Bdfsg2-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 127,396 kB
  • sloc: cpp: 1,539,584; ansic: 124,382; python: 78,038; tcl: 47,013; xml: 8,142; yacc: 5,040; java: 4,439; perl: 3,132; lex: 1,926; sh: 1,500; makefile: 126; objc: 83
file content (154 lines) | stat: -rw-r--r-- 4,915 bytes parent folder | download | duplicates (8)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# Load libraries for VTK
package require vtk
package require vtkinteraction
package require vtktesting

# This example shows how to use a transparent texture map to perform
# thresholding. The key is the vtkThresholdTextureCoords filter which
# creates texture coordinates based on a threshold value. These texture
# coordinates are used in conjuntion with a texture map with varying
# opacity and intensity to create an inside, transition, and outside
# region.
#

# Begin by reading some structure grid data.
vtkMultiBlockPLOT3DReader pl3d
    pl3d SetXYZFileName "$VTK_DATA_ROOT/Data/bluntfinxyz.bin"
    pl3d SetQFileName "$VTK_DATA_ROOT/Data/bluntfinq.bin"
    pl3d SetScalarFunctionNumber 100
    pl3d SetVectorFunctionNumber 202
    pl3d Update

set pl3dOutput [[pl3d GetOutput] GetBlock 0]

# Now extract surfaces from the grid corresponding to boundary geometry.
# First the wall.
vtkStructuredGridGeometryFilter wall
    wall SetInputData $pl3dOutput
    wall SetExtent 0 100 0 0 0 100
vtkPolyDataMapper wallMap
    wallMap SetInputConnection [wall GetOutputPort]
    wallMap ScalarVisibilityOff
vtkActor wallActor
    wallActor SetMapper wallMap
    eval [wallActor GetProperty] SetColor 0.8 0.8 0.8

# Now the fin.
#
vtkStructuredGridGeometryFilter fin
    fin SetInputData $pl3dOutput
    fin SetExtent 0 100 0 100 0 0
vtkPolyDataMapper finMap
    finMap SetInputConnection [fin GetOutputPort]
    finMap ScalarVisibilityOff
vtkActor finActor
    finActor SetMapper finMap
    eval [finActor GetProperty] SetColor 0.8 0.8 0.8

# Extract planes to threshold. Start by reading the specially
# designed texture map that has three regions: an inside, boundary,
# and outside region. The opacity and intensity of this texture map
# are varied.
vtkStructuredPointsReader tmap
  tmap SetFileName "$VTK_DATA_ROOT/Data/texThres2.vtk"
vtkTexture texture
  texture SetInputConnection [tmap GetOutputPort]
  texture InterpolateOff
  texture RepeatOff

# Here are the three planes which will be texture thresholded.
#
vtkStructuredGridGeometryFilter plane1
    plane1 SetInputData $pl3dOutput
    plane1 SetExtent 10 10 0 100 0 100
vtkThresholdTextureCoords thresh1
    thresh1 SetInputConnection [plane1 GetOutputPort]
    thresh1 ThresholdByUpper 1.5
vtkDataSetMapper plane1Map
    plane1Map SetInputConnection [thresh1 GetOutputPort]
    eval plane1Map SetScalarRange [$pl3dOutput GetScalarRange]
vtkActor plane1Actor
    plane1Actor SetMapper plane1Map
    plane1Actor SetTexture texture
[plane1Actor GetProperty] SetOpacity 0.999

vtkStructuredGridGeometryFilter plane2
    plane2 SetInputData $pl3dOutput
    plane2 SetExtent 30 30 0 100 0 100
vtkThresholdTextureCoords thresh2
    thresh2 SetInputConnection [plane2 GetOutputPort]
    thresh2 ThresholdByUpper 1.5
vtkDataSetMapper plane2Map
    plane2Map SetInputConnection [thresh2 GetOutputPort]
    eval plane2Map SetScalarRange [$pl3dOutput GetScalarRange]
vtkActor plane2Actor
    plane2Actor SetMapper plane2Map
    plane2Actor SetTexture texture
    [plane2Actor GetProperty] SetOpacity 0.999

vtkStructuredGridGeometryFilter plane3
    plane3 SetInputData $pl3dOutput
    plane3 SetExtent 35 35 0 100 0 100
vtkThresholdTextureCoords thresh3
    thresh3 SetInputConnection [plane3 GetOutputPort]
    thresh3 ThresholdByUpper 1.5
vtkDataSetMapper plane3Map
    plane3Map SetInputConnection [thresh3 GetOutputPort]
    eval plane3Map SetScalarRange [$pl3dOutput GetScalarRange]
vtkActor plane3Actor
    plane3Actor SetMapper plane3Map
    plane3Actor SetTexture texture
    [plane3Actor GetProperty] SetOpacity 0.999

# For context create an outline around the data.
#
vtkStructuredGridOutlineFilter outline
    outline SetInputData $pl3dOutput
vtkPolyDataMapper outlineMapper
    outlineMapper SetInputConnection [outline GetOutputPort]
vtkActor outlineActor
    outlineActor SetMapper outlineMapper
    set outlineProp [outlineActor GetProperty]
    eval $outlineProp SetColor 0 0 0

# Create the RenderWindow, Renderer and both Actors
#
vtkRenderer ren1
vtkRenderWindow renWin
    renWin AddRenderer ren1
vtkRenderWindowInteractor iren
    iren SetRenderWindow renWin

# Add the actors to the renderer, set the background and size
#
ren1 AddActor outlineActor
ren1 AddActor wallActor
ren1 AddActor finActor
ren1 AddActor plane1Actor
ren1 AddActor plane2Actor
ren1 AddActor plane3Actor
ren1 SetBackground 1 1 1
renWin SetSize 500 500

# Set up a nice view.
#
vtkCamera cam1
  cam1 SetClippingRange 1.51176 75.5879
  cam1 SetFocalPoint 2.33749 2.96739 3.61023
  cam1 SetPosition 10.8787 5.27346 15.8687
  cam1 SetViewAngle 30
  cam1 SetViewUp -0.0610856 0.987798 -0.143262
ren1 SetActiveCamera cam1

iren Initialize

# Set up an observer to invoke a proc when the UserEvent (keypress-u)
# is invoked.
#
iren AddObserver UserEvent {wm deiconify .vtkInteract}

# prevent the tk window from showing up then start the event loop
wm withdraw .

iren Start