File: fieldToPolyData.tcl

package info (click to toggle)
vtk 5.8.0-13
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 130,524 kB
  • sloc: cpp: 1,129,256; ansic: 708,203; tcl: 48,526; python: 20,875; xml: 6,779; yacc: 4,208; perl: 3,121; java: 2,788; lex: 931; sh: 660; asm: 471; makefile: 299
file content (73 lines) | stat: -rw-r--r-- 2,075 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
package require vtk
package require vtkinteraction

# This example demonstrates the reading of a field and conversion to PolyData
# The output should be the same as polyEx.tcl.

# get the interactor ui

# Create a reader and write out the field
vtkPolyDataReader reader
    reader SetFileName "$VTK_DATA_ROOT/Data/polyEx.vtk"
vtkDataSetToDataObjectFilter ds2do
    ds2do SetInputConnection [reader GetOutputPort]
if {[catch {set channel [open "PolyField.vtk" "w"]}] == 0 } {
   close $channel
   vtkDataObjectWriter writer
    writer SetInputConnection [ds2do GetOutputPort]
    writer SetFileName "PolyField.vtk"
    writer Write

# create pipeline
#
vtkDataObjectReader dor
    dor SetFileName "PolyField.vtk"
vtkDataObjectToDataSetFilter do2ds
    do2ds SetInputConnection [dor GetOutputPort]
    do2ds SetDataSetTypeToPolyData
    do2ds SetPointComponent 0 "Points" 0 
    do2ds SetPointComponent 1 "Points" 1 
    do2ds SetPointComponent 2 "Points" 2 
    do2ds SetPolysComponent "Polys" 0
vtkFieldDataToAttributeDataFilter fd2ad
    fd2ad SetInput [do2ds GetPolyDataOutput]
    fd2ad SetInputFieldToDataObjectField
    fd2ad SetOutputAttributeDataToPointData
    fd2ad SetScalarComponent 0 "my_scalars" 0 

vtkPolyDataMapper mapper
    mapper SetInput [fd2ad GetPolyDataOutput]
    eval mapper SetScalarRange [[fd2ad GetOutput] GetScalarRange]
vtkActor actor
    actor SetMapper mapper

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

ren1 AddActor actor
ren1 SetBackground 1 1 1
renWin SetSize 300 300

ren1 ResetCamera
set cam1 [ren1 GetActiveCamera]
$cam1 SetClippingRange .348 17.43
$cam1 SetPosition 2.92 2.62 -0.836
$cam1 SetViewUp -0.436 -0.067 -0.897
$cam1 Azimuth 90
# render the image
#
iren AddObserver UserEvent {wm deiconify .vtkInteract}
renWin Render

if {[info commands "rtExMath"] != ""} { 
    file delete -force "PolyField.vtk"
}
}
# prevent the tk window from showing up then start the event loop
wm withdraw .