File: SurfacePickerWithTexture.tcl

package info (click to toggle)
vtk6 6.3.0%2Bdfsg2-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 118,880 kB
  • sloc: cpp: 1,442,792; ansic: 113,395; python: 72,383; tcl: 46,998; xml: 8,119; yacc: 4,525; java: 4,239; perl: 3,108; lex: 1,694; sh: 1,093; asm: 154; makefile: 103; objc: 17
file content (140 lines) | stat: -rw-r--r-- 3,537 bytes parent folder | download | duplicates (16)
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
package require vtk
package require vtkinteraction

#
# Do picking with an actor with a texture.
# This example draws a cone at the pick point, with the color
# of the cone set from the color of the texture at the pick position.
#

# renderer and interactor
vtkRenderer ren

vtkRenderWindow renWin
renWin AddRenderer ren

vtkRenderWindowInteractor iren
iren SetRenderWindow renWin

# read the volume
vtkJPEGReader reader
reader SetFileName "$VTK_DATA_ROOT/Data/beach.jpg"

#---------------------------------------------------------
# Do the surface rendering
vtkSphereSource sphereSource
sphereSource SetRadius 100

vtkTextureMapToSphere textureSphere
textureSphere SetInputConnection [sphereSource GetOutputPort]

vtkStripper sphereStripper
sphereStripper SetInputConnection [textureSphere GetOutputPort]
sphereStripper SetMaximumLength 5

vtkPolyDataMapper sphereMapper
sphereMapper SetInputConnection [sphereStripper GetOutputPort]
sphereMapper ScalarVisibilityOff

vtkTexture sphereTexture
sphereTexture SetInputConnection [reader GetOutputPort]

vtkProperty sphereProperty
sphereProperty BackfaceCullingOn

vtkActor sphere
sphere SetMapper sphereMapper
sphere SetTexture sphereTexture
sphere SetProperty sphereProperty

#---------------------------------------------------------
ren AddViewProp sphere

set camera [ren GetActiveCamera]
$camera SetFocalPoint 0 0 0
$camera SetPosition 100 400 -100
$camera SetViewUp 0 0 -1

ren ResetCameraClippingRange

renWin Render

#---------------------------------------------------------
# the cone should point along the Z axis
vtkConeSource coneSource
coneSource CappingOn
coneSource SetHeight 12
coneSource SetRadius 5
coneSource SetResolution 31
coneSource SetCenter 6 0 0
coneSource SetDirection -1 0 0

#---------------------------------------------------------
vtkCellPicker picker
picker SetTolerance 1e-6
picker PickTextureDataOn

# A function to point an actor along a vector
proc PointCone {actor nx ny nz} {
  if [expr $nx < 0.0] {
    $actor RotateWXYZ 180 0 1 0
    $actor RotateWXYZ 180 [expr ($nx - 1.0)*0.5] [expr $ny*0.5] [expr $nz*0.5]
  } else {
    $actor RotateWXYZ 180 [expr ($nx + 1.0)*0.5] [expr $ny*0.5] [expr $nz*0.5]
  }
}

# Pick the actor
picker Pick 104 154 0 ren
#puts [picker Print]
set p [picker GetPickPosition]
set n [picker GetPickNormal]
set ijk [picker GetPointIJK]
set data [picker GetDataSet]

set i [lindex $ijk 0]
set j [lindex $ijk 1]
set k [lindex $ijk 2]

if { [$data IsA "vtkImageData"] } {
  set r [$data GetScalarComponentAsDouble $i $j $k 0]
  set g [$data GetScalarComponentAsDouble $i $j $k 1]
  set b [$data GetScalarComponentAsDouble $i $j $k 2]
} else {
  set r 255.0
  set g 0.0
  set b 0.0
}

set r [expr $r / 255.0]
set g [expr $g / 255.0]
set b [expr $b / 255.0]

vtkActor coneActor1
coneActor1 PickableOff
vtkDataSetMapper coneMapper1
coneMapper1 SetInputConnection [coneSource GetOutputPort]
coneActor1 SetMapper coneMapper1
[coneActor1 GetProperty] SetColor $r $g $b
[coneActor1 GetProperty] BackfaceCullingOn
coneActor1 SetPosition [lindex $p 0] [lindex $p 1] [lindex $p 2]
PointCone coneActor1 [lindex $n 0] [lindex $n 1] [lindex $n 2]
ren AddViewProp coneActor1

ren ResetCameraClippingRange

renWin Render

#---------------------------------------------------------
# test-related code
proc TkCheckAbort {} {
  set foo [renWin GetEventPending]
  if {$foo != 0} {renWin SetAbortRender 1}
}
renWin AddObserver AbortCheckEvent {TkCheckAbort}

iren AddObserver UserEvent {wm deiconify .vtkInteract}
iren Initialize

wm withdraw .