File: CSpline.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 (127 lines) | stat: -rw-r--r-- 3,350 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
# This example demonstrates the use of vtkCardinalSpline.
# It creates random points and connects them with a spline

#
# First we include the VTK Tcl packages which will make available
# all of the vtk commands to Tcl
#
package require vtk
package require vtkinteraction
package require vtktesting

# This will be used later to get random numbers.
vtkMath math

# Total number of points.
set numberOfInputPoints 10

# One spline for each direction.
vtkCardinalSpline aSplineX
vtkCardinalSpline aSplineY
vtkCardinalSpline aSplineZ

# Generate random (pivot) points and add the corresponding
# coordinates to the splines.
# aSplineX will interpolate the x values of the points
# aSplineY will interpolate the y values of the points
# aSplineZ will interpolate the z values of the points
vtkPoints inputPoints
for {set i 0} {$i < $numberOfInputPoints} {incr i 1} {
    set x  [math Random 0 1]
    set y  [math Random 0 1]
    set z  [math Random 0 1]
    aSplineX AddPoint $i $x
    aSplineY AddPoint $i $y
    aSplineZ AddPoint $i $z
    inputPoints InsertPoint $i $x $y $z
}

# The following section will create glyphs for the pivot points
# in order to make the effect of the spline more clear.

# Create a polydata to be glyphed.
vtkPolyData inputData
inputData SetPoints inputPoints

# Use sphere as glyph source.
vtkSphereSource balls
balls SetRadius .01
balls SetPhiResolution 10
balls SetThetaResolution 10

vtkGlyph3D glyphPoints
glyphPoints SetInputData inputData
glyphPoints SetSourceConnection [balls GetOutputPort]

vtkPolyDataMapper glyphMapper
glyphMapper SetInputConnection [glyphPoints GetOutputPort]

vtkActor glyph
glyph SetMapper glyphMapper
eval   [glyph GetProperty] SetDiffuseColor $tomato
[glyph GetProperty] SetSpecular .3
[glyph GetProperty] SetSpecularPower 30

# Generate the polyline for the spline.
vtkPoints points
vtkPolyData profileData

# Number of points on the spline
set numberOfOutputPoints 400

# Interpolate x, y and z by using the three spline filters and
# create new points
for {set i 0} {$i< $numberOfOutputPoints} {incr i 1} {
    set t [expr ( $numberOfInputPoints - 1.0 ) / ( $numberOfOutputPoints - 1.0 ) * $i]
    points InsertPoint $i [aSplineX Evaluate $t] [aSplineY Evaluate $t] [aSplineZ Evaluate $t]
}

# Create the polyline.
vtkCellArray lines
lines InsertNextCell $numberOfOutputPoints
for {set i 0} {$i < $numberOfOutputPoints} {incr i 1} {
  lines InsertCellPoint $i
}
profileData SetPoints points
profileData SetLines lines

# Add thickness to the resulting line.
vtkTubeFilter profileTubes
profileTubes SetNumberOfSides 8
profileTubes SetInputData profileData
profileTubes SetRadius .005

vtkPolyDataMapper profileMapper
profileMapper SetInputConnection [profileTubes GetOutputPort]

vtkActor profile
profile SetMapper profileMapper
eval  [profile GetProperty] SetDiffuseColor $banana
[profile GetProperty] SetSpecular .3
[profile GetProperty] SetSpecularPower 30


# Now create the RenderWindow, Renderer and Interactor
#
vtkRenderer ren1
vtkRenderWindow renWin
renWin AddRenderer ren1

vtkRenderWindowInteractor iren
iren SetRenderWindow renWin

# Add the actors
ren1 AddActor glyph
ren1 AddActor profile

renWin SetSize 500 500

# render the image
#
iren Initialize
iren AddObserver UserEvent {wm deiconify .vtkInteract}

# prevent the tk window from showing up
wm withdraw .
iren Start