File: PolyDataMapperAllPolygons.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 (133 lines) | stat: -rw-r--r-- 4,306 bytes parent folder | download | duplicates (12)
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
package require vtk
package require vtkinteraction

vtkRenderer ren1
vtkRenderWindow renWin
  renWin AddRenderer ren1
vtkRenderWindowInteractor iren
  iren SetRenderWindow renWin

vtkBMPReader bmpReader
  bmpReader SetFileName "$VTK_DATA_ROOT/Data/masonry.bmp"
vtkTexture texture
  texture SetInputConnection [bmpReader GetOutputPort]

vtkPoints triangleStripPoints
  triangleStripPoints SetNumberOfPoints 5
  triangleStripPoints InsertPoint 0 0 1 0
  triangleStripPoints InsertPoint 1 0 0 .5
  triangleStripPoints InsertPoint 2 1 1 .3
  triangleStripPoints InsertPoint 3 1 0 .6
  triangleStripPoints InsertPoint 4 2 1 .1

vtkFloatArray triangleStripTCoords
  triangleStripTCoords SetNumberOfComponents 2
  triangleStripTCoords SetNumberOfTuples 5
  triangleStripTCoords InsertTuple2 0 0 1
  triangleStripTCoords InsertTuple2 1 0 0
  triangleStripTCoords InsertTuple2 2 .5 1
  triangleStripTCoords InsertTuple2 3 .5 0
  triangleStripTCoords InsertTuple2 4 1 1

vtkFloatArray triangleStripPointScalars
  triangleStripPointScalars SetNumberOfTuples 5
  triangleStripPointScalars InsertValue 0 1
  triangleStripPointScalars InsertValue 1 0
  triangleStripPointScalars InsertValue 2 0
  triangleStripPointScalars InsertValue 3 0
  triangleStripPointScalars InsertValue 4 0

vtkFloatArray triangleStripCellScalars
  triangleStripCellScalars SetNumberOfTuples 1
  triangleStripCellScalars InsertValue 0 1

vtkFloatArray triangleStripPointNormals
  triangleStripPointNormals SetNumberOfComponents 3
  triangleStripPointNormals SetNumberOfTuples 5
  triangleStripPointNormals InsertTuple3 0 0 0 1
  triangleStripPointNormals InsertTuple3 1 0 1 0
  triangleStripPointNormals InsertTuple3 2 0 1 1
  triangleStripPointNormals InsertTuple3 3 1 0 0
  triangleStripPointNormals InsertTuple3 4 1 0 1

vtkFloatArray triangleStripCellNormals
  triangleStripCellNormals SetNumberOfComponents 3
  triangleStripCellNormals SetNumberOfTuples 1
  triangleStripCellNormals InsertTuple3 0 0 0 1

vtkTriangleStrip aTriangleStrip
  [aTriangleStrip GetPointIds] SetNumberOfIds 5
  [aTriangleStrip GetPointIds] SetId 0 0
  [aTriangleStrip GetPointIds] SetId 1 1
  [aTriangleStrip GetPointIds] SetId 2 2
  [aTriangleStrip GetPointIds] SetId 3 3
  [aTriangleStrip GetPointIds] SetId 4 4

vtkLookupTable lut
  lut SetNumberOfColors 5
  lut SetTableValue 0 0 0 1 1
  lut SetTableValue 1 0 1 0 1
  lut SetTableValue 2 0 1 1 1
  lut SetTableValue 3 1 0 0 1
  lut SetTableValue 4 1 0 1 1

set masks "0 1 2 3 4 5 6 7 10 11 14 15 16 18 20 22 26 30"
set i 0; set j 0 ; set k 0
set types "strip triangle"
foreach type $types {
  foreach mask $masks {
    vtkUnstructuredGrid grid$i
      grid$i Allocate 1 1
      grid$i InsertNextCell [aTriangleStrip GetCellType] [aTriangleStrip GetPointIds]
      grid$i SetPoints triangleStripPoints
    vtkGeometryFilter geometry$i
      geometry$i SetInputData grid$i
    vtkTriangleFilter triangles$i
      triangles$i SetInputConnection [geometry$i GetOutputPort]
    vtkPolyDataMapper mapper$i
    if {$type == "strip"} {mapper$i SetInputConnection [geometry$i GetOutputPort]}
    if {$type == "triangle"} {mapper$i SetInputConnection [triangles$i GetOutputPort]}
      mapper$i SetLookupTable lut
      mapper$i SetScalarRange 0 4
    vtkActor actor$i
      actor$i SetMapper mapper$i

      if {[expr $mask & 1] != 0} {
        [grid$i GetPointData] SetNormals triangleStripPointNormals
      }
      if {[expr $mask & 2] != 0} {
        [grid$i GetPointData] SetScalars triangleStripPointScalars
        mapper$i SetScalarModeToUsePointData
      }
      if {[expr $mask & 4] != 0} {
        [grid$i GetPointData] SetTCoords triangleStripTCoords
        actor$i SetTexture texture
      }
      if {[expr $mask & 8] != 0} {
        [grid$i GetCellData] SetScalars triangleStripCellScalars
        mapper$i SetScalarModeToUseCellData
      }
      if {[expr $mask & 16] != 0} {
        [grid$i GetCellData] SetNormals triangleStripCellNormals
      }
    actor$i AddPosition [expr $j * 2] [expr $k * 2] 0
    ren1 AddActor actor$i
    incr j
    if {$j >= 6} {set j 0; incr k};
    incr i
  }
}
renWin SetSize 480 480
ren1 SetBackground .7 .3 .1
ren1 ResetCameraClippingRange

renWin Render

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