File: multiLineText.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 (318 lines) | stat: -rw-r--r-- 11,754 bytes parent folder | download | duplicates (3)
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# This example demonstrates the use of multiline 2D text using
# vtkTextMappers.  It shows several justifications as well as single-line
# and multiple-line text inputs.

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

set font_size 14

# Create the text mappers and the associated Actor2Ds.

# The font and text properties (except justification) are the same for each
# single line mapper. Let's create a common text property object

vtkTextProperty singleLineTextProp
    singleLineTextProp SetFontSize $font_size
    singleLineTextProp SetFontFamilyToArial
    singleLineTextProp BoldOff
    singleLineTextProp ItalicOff
    singleLineTextProp ShadowOff

# The font and text properties (except justification) are the same for each
# multi line mapper. Let's create a common text property object

vtkTextProperty multiLineTextProp
    multiLineTextProp ShallowCopy singleLineTextProp
    multiLineTextProp BoldOn
    multiLineTextProp ItalicOn
    multiLineTextProp ShadowOn

# The text is on a single line and bottom-justified.
vtkTextMapper singleLineTextB
    singleLineTextB SetInput "Single line (bottom)"
    set tprop [singleLineTextB GetTextProperty]
    $tprop ShallowCopy singleLineTextProp
    $tprop SetVerticalJustificationToBottom
    $tprop SetColor 1 0 0
vtkActor2D singleLineTextActorB
    singleLineTextActorB SetMapper singleLineTextB
    [singleLineTextActorB GetPositionCoordinate] \
          SetCoordinateSystemToNormalizedDisplay
    [singleLineTextActorB GetPositionCoordinate] SetValue 0.05 0.85

# The text is on a single line and center-justified (vertical justification).
vtkTextMapper singleLineTextC
    singleLineTextC SetInput "Single line (centered)"
    set tprop [singleLineTextC GetTextProperty]
    $tprop ShallowCopy singleLineTextProp
    $tprop SetVerticalJustificationToCentered
    $tprop SetColor 0 1 0
vtkActor2D singleLineTextActorC
    singleLineTextActorC SetMapper singleLineTextC
    [singleLineTextActorC GetPositionCoordinate] \
          SetCoordinateSystemToNormalizedDisplay
    [singleLineTextActorC GetPositionCoordinate] SetValue 0.05 0.75

# The text is on a single line and top-justified - above 0.5
vtkTextMapper singleLineTextT
    singleLineTextT SetInput "Single line (top)"
    set tprop [singleLineTextT GetTextProperty]
    $tprop ShallowCopy singleLineTextProp
    $tprop SetVerticalJustificationToTop
    $tprop SetColor 0 0 1
vtkActor2D singleLineTextActorT
    singleLineTextActorT SetMapper singleLineTextT
    [singleLineTextActorT GetPositionCoordinate] \
          SetCoordinateSystemToNormalizedDisplay
    [singleLineTextActorT GetPositionCoordinate] SetValue 0.05 0.65

# The text is on a single line and top-justified -below 0.5
vtkTextMapper singleLineTextTB
    singleLineTextTB SetInput "Single line below (top)"
    set tprop [singleLineTextTB GetTextProperty]
    $tprop ShallowCopy singleLineTextProp
    $tprop SetVerticalJustificationToTop
    $tprop SetColor 0 0 1
vtkActor2D singleLineTextActorTB
    singleLineTextActorTB SetMapper singleLineTextTB
    [singleLineTextActorTB GetPositionCoordinate] \
        SetCoordinateSystemToNormalizedDisplay
    [singleLineTextActorTB GetPositionCoordinate] SetValue 0.5 0.25

# The text is on a single line and centered -below 0.5
vtkTextMapper singleLineTextCC
    singleLineTextCC SetInput "HHHHH"
    set tprop [singleLineTextCC GetTextProperty]
    $tprop ShallowCopy singleLineTextProp
    $tprop SetJustificationToCentered
    $tprop SetVerticalJustificationToCentered
    $tprop UseTightBoundingBoxOn
    $tprop SetColor 0 0 0
vtkActor2D singleLineTextActorCC
    singleLineTextActorCC SetMapper singleLineTextCC
    [singleLineTextActorCC GetPositionCoordinate] SetCoordinateSystemToNormalizedDisplay
    [singleLineTextActorCC GetPositionCoordinate] SetValue 0.5 0.15

# The text is on a single line and bottom-right justified with a tight bounding-box
vtkTextMapper singleLineTextBR
    singleLineTextBR SetInput "Line bottom"
    set tprop [singleLineTextBR GetTextProperty]
    $tprop ShallowCopy singleLineTextProp
    $tprop SetJustificationToRight
    $tprop SetVerticalJustificationToBottom
    $tprop UseTightBoundingBoxOn
    $tprop SetColor 0 0 1
vtkActor2D singleLineTextActorBR
    singleLineTextActorBR SetMapper singleLineTextBR
    [singleLineTextActorBR GetPositionCoordinate] SetCoordinateSystemToNormalizedDisplay
    [singleLineTextActorBR GetPositionCoordinate] SetValue 0.95 0.15

# The text is on a single line and bottom-right justified with a tight bounding-box
vtkTextMapper singleLineTextBL
    singleLineTextBL SetInput "Tight line (bottom)"
    set tprop [singleLineTextBL GetTextProperty]
    $tprop ShallowCopy singleLineTextProp
    $tprop SetJustificationToLeft
    $tprop SetVerticalJustificationToBottom
    $tprop UseTightBoundingBoxOn
    $tprop SetColor 0 0 1
vtkActor2D singleLineTextActorBL
    singleLineTextActorBL SetMapper singleLineTextBL
    [singleLineTextActorBL GetPositionCoordinate] SetCoordinateSystemToNormalizedDisplay
    [singleLineTextActorBL GetPositionCoordinate] SetValue 0.05 0.15

# The text is on a single line and top-justified - above 0.5
vtkTextMapper singleLineTextLTT
    singleLineTextLTT SetInput "Single line (top)"
    set tprop [singleLineTextLTT GetTextProperty]
    $tprop ShallowCopy singleLineTextProp
    $tprop SetVerticalJustificationToTop
    $tprop UseTightBoundingBoxOn
    $tprop SetColor 0 0 1
vtkActor2D singleLineTextActorLTT
    singleLineTextActorLTT SetMapper singleLineTextLTT
    [singleLineTextActorLTT GetPositionCoordinate] SetCoordinateSystemToNormalizedDisplay
    [singleLineTextActorLTT GetPositionCoordinate] SetValue 0.05 0.15

# The text is on a single line and top-justified - above 0.5
vtkTextMapper singleLineTextRTT
    singleLineTextRTT SetInput "nge ne op"
    set tprop [singleLineTextRTT GetTextProperty]
    $tprop ShallowCopy singleLineTextProp
    $tprop SetJustificationToRight
    $tprop SetVerticalJustificationToTop
    $tprop UseTightBoundingBoxOn
    $tprop SetColor 0 0 1
vtkActor2D singleLineTextActorRTT
    singleLineTextActorRTT SetMapper singleLineTextRTT
    [singleLineTextActorRTT GetPositionCoordinate] SetCoordinateSystemToNormalizedDisplay
    [singleLineTextActorRTT GetPositionCoordinate] SetValue 0.95 0.15

# The text is on multiple lines and left- and top-justified - below 0.5
vtkTextMapper textMapperL
    textMapperL SetInput "This is\nmulti-line\ntext output\n(left-top)"
    set tprop [textMapperL GetTextProperty]
    $tprop ShallowCopy multiLineTextProp
    $tprop SetJustificationToLeft
    $tprop SetVerticalJustificationToTop
    $tprop SetColor 1 0 0
vtkActor2D textActorL
    textActorL SetMapper textMapperL
    [textActorL GetPositionCoordinate] SetCoordinateSystemToNormalizedDisplay
    [textActorL GetPositionCoordinate] SetValue 0.05 0.5

# The text is on multiple lines and left- and top-justified - above 0.5
vtkTextMapper textMapperLA
    textMapperLA SetInput "This is\nmulti-line\ntext output\nabove (left-top)"
    set tprop [textMapperLA GetTextProperty]
    $tprop ShallowCopy multiLineTextProp
    $tprop SetJustificationToLeft
    $tprop SetVerticalJustificationToTop
    $tprop SetColor 1 0 0
vtkActor2D textActorLA
    textActorLA SetMapper textMapperLA
    [textActorLA GetPositionCoordinate] SetCoordinateSystemToNormalizedDisplay
    [textActorLA GetPositionCoordinate] SetValue 0.5 0.85

# The text is on multiple lines and center-justified (both horizontal and
# vertical).
vtkTextMapper textMapperC
    textMapperC SetInput "This is\nmulti-line\ntext output\n(centered)"
    set tprop [textMapperC GetTextProperty]
    $tprop ShallowCopy multiLineTextProp
    $tprop SetJustificationToCentered
    $tprop SetVerticalJustificationToCentered
    $tprop SetColor 0 1 0
vtkActor2D textActorC
    textActorC SetMapper textMapperC
    [textActorC GetPositionCoordinate] SetCoordinateSystemToNormalizedDisplay
    [textActorC GetPositionCoordinate] SetValue 0.5 0.5

# The text is on multiple lines and right- and bottom-justified.
vtkTextMapper textMapperR
    textMapperR SetInput "This is\nmulti-line\ntext output\n(right-bottom)"
    set tprop [textMapperR GetTextProperty]
    $tprop ShallowCopy multiLineTextProp
    $tprop SetJustificationToRight
    $tprop SetVerticalJustificationToBottom
    $tprop SetColor 0 0 1
vtkActor2D textActorR
    textActorR SetMapper textMapperR
    [textActorR GetPositionCoordinate] SetCoordinateSystemToNormalizedDisplay
    [textActorR GetPositionCoordinate] SetValue 0.95 0.5

# Draw the grid to demonstrate the placement of the text.

# Set up the necessary points.
vtkPoints Pts
    Pts InsertNextPoint 0.05 0.0 0.0
    Pts InsertNextPoint 0.05 1.0 0.0
    Pts InsertNextPoint 0.5 0.0 0.0
    Pts InsertNextPoint 0.5 1.0 0.0
    Pts InsertNextPoint 0.95 0.0 0.0
    Pts InsertNextPoint 0.95 1.0 0.0
    Pts InsertNextPoint 0.0 0.5 0.0
    Pts InsertNextPoint 1.0 0.5 0.0
    Pts InsertNextPoint 0.0 0.85 0.0
    Pts InsertNextPoint 1.0 0.85 0.0
    Pts InsertNextPoint 0.00 0.75 0.0
    Pts InsertNextPoint 0.50 0.75 0.0
    Pts InsertNextPoint 0.00 0.65 0.0
    Pts InsertNextPoint 0.50 0.65 0.0
    Pts InsertNextPoint 0.00 0.25 0.0
    Pts InsertNextPoint 1.00 0.25 0.0
    Pts InsertNextPoint 0.00 0.15 0.0
    Pts InsertNextPoint 1.00 0.15 0.0

# Set up the lines that use these points.
vtkCellArray Lines
    Lines InsertNextCell 2
    Lines InsertCellPoint 0
    Lines InsertCellPoint 1
    Lines InsertNextCell 2
    Lines InsertCellPoint 2
    Lines InsertCellPoint 3
    Lines InsertNextCell 2
    Lines InsertCellPoint 4
    Lines InsertCellPoint 5
    Lines InsertNextCell 2
    Lines InsertCellPoint 6
    Lines InsertCellPoint 7
    Lines InsertNextCell 2
    Lines InsertCellPoint 8
    Lines InsertCellPoint 9
    Lines InsertNextCell 2
    Lines InsertCellPoint 10
    Lines InsertCellPoint 11
    Lines InsertNextCell 2
    Lines InsertCellPoint 12
    Lines InsertCellPoint 13
    Lines InsertNextCell 2
    Lines InsertCellPoint 14
    Lines InsertCellPoint 15
    Lines InsertNextCell 2
    Lines InsertCellPoint 16
    Lines InsertCellPoint 17

# Create a grid that uses these points and lines.
vtkPolyData Grid
    Grid SetPoints Pts
    Grid SetLines Lines
# Set up the coordinate system.
vtkCoordinate normCoords
    normCoords SetCoordinateSystemToNormalizedDisplay

# Set up the mapper and actor (2D) for the grid.
vtkPolyDataMapper2D mapper
    mapper SetInputData Grid
    mapper SetTransformCoordinate normCoords
vtkActor2D gridActor
    gridActor SetMapper mapper
    [gridActor GetProperty] SetColor 0.1 0.1 0.1

# Create the Renderer, RenderWindow, and RenderWindowInteractor
#
vtkRenderer ren1
vtkRenderWindow renWin
    renWin SetMultiSamples 0
    renWin AddRenderer ren1
vtkRenderWindowInteractor iren
    iren SetRenderWindow renWin

# Add the actors to the renderer; set the background and size; zoom in
# closer to the image; render
#
ren1 AddActor2D gridActor
ren1 AddActor2D textActorL
ren1 AddActor2D singleLineTextActorT
ren1 AddActor2D textActorLA
ren1 AddActor2D textActorC
ren1 AddActor2D textActorR
ren1 AddActor2D singleLineTextActorB
ren1 AddActor2D singleLineTextActorC
ren1 AddActor2D singleLineTextActorLTT
ren1 AddActor2D singleLineTextActorRTT
ren1 AddActor2D singleLineTextActorTB
ren1 AddActor2D singleLineTextActorBR
ren1 AddActor2D singleLineTextActorBL
ren1 AddActor2D singleLineTextActorCC

ren1 SetBackground 1 1 1
renWin SetSize 500 300
[ren1 GetActiveCamera] Zoom 1.5
renWin Render

# Set the user method (bound to key 'u')
#
iren AddObserver UserEvent {wm deiconify .vtkInteract}

# Withdraw the default tk window.
wm withdraw .