File: expCos.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 (103 lines) | stat: -rw-r--r-- 2,694 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
# This example demonstrates how to use a programmable filter and how to use
# the special vtkDataSetToDataSet::GetOutputPort() methods

# first we load in the standard vtk packages into tcl
package require vtk
package require vtkinteraction
package require vtktesting

#
# We create a 100 by 100 point plane to sample
#
vtkPlaneSource plane
    plane SetXResolution 100
    plane SetYResolution 100

#
# We transform the plane by a factor of 10 on X and Y
#
vtkTransform transform
   transform Scale 10 10 1
vtkTransformPolyDataFilter transF
   transF SetInputConnection [plane GetOutputPort]
   transF SetTransform transform

#
# Compute Bessel function and derivatives. We'll use a programmable filter
# for this. Note the unusual GetPolyDataInput() & GetOutputPort() methods.
#
vtkProgrammableFilter besselF
   besselF SetInputConnection [transF GetOutputPort]
   besselF SetExecuteMethod bessel

#
# The SetExecuteMethod takes a Tcl proc as an argument
# In here is where all the processing is done.
#
proc bessel {} {
   set input [besselF GetPolyDataInput]
   set numPts [$input GetNumberOfPoints]
   vtkPoints newPts
   vtkFloatArray derivs

    for {set i 0} {$i < $numPts} {incr i} {
	set x [$input GetPoint $i]
	set x0 [lindex $x 0]
	set x1 [lindex $x 1]

	set r [expr sqrt($x0*$x0 + $x1*$x1)]
	set x2 [expr exp(-$r) * cos(10.0*$r)]
	set deriv [expr -exp(-$r) * (cos(10.0*$r) + 10.0*sin(10.0*$r))]

	newPts InsertPoint $i $x0 $x1 $x2
	eval derivs InsertValue $i $deriv
    }

    [besselF GetPolyDataOutput] CopyStructure $input
    [besselF GetPolyDataOutput] SetPoints newPts
    [[besselF GetPolyDataOutput] GetPointData] SetScalars derivs

    newPts Delete; #reference counting - it's ok
    derivs Delete
}

#
# We warp the plane based on the scalar values calculated above
#
vtkWarpScalar warp
    warp SetInputConnection [besselF GetOutputPort]
    warp XYPlaneOn
    warp SetScaleFactor 0.5

#
# We create a mapper and actor as usual. In the case we adjust the
# scalar range of the mapper to match that of the computed scalars
#
vtkPolyDataMapper mapper
    mapper SetInputConnection [warp GetOutputPort]
    eval mapper SetScalarRange [[besselF GetPolyDataOutput] GetScalarRange]
vtkActor carpet
    carpet SetMapper mapper

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

ren1 AddActor carpet
renWin SetSize 500 500

# render the image
#
iren AddObserver UserEvent {wm deiconify .vtkInteract}
ren1 ResetCamera
[ren1 GetActiveCamera] Zoom 1.5
renWin Render

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