/usr/share/vtk/ImageProcessing/Tcl/MandelbrotViewer.tcl is in vtk-examples 5.8.0-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | #
# This script uses a vtkTkRenderWidget to create a
# Tk widget that is associated with a vtkRenderWindow.
#
# 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 RANGE 150
set MAX_ITERATIONS_1 $RANGE
set MAX_ITERATIONS_2 $RANGE
set XRAD 200
set YRAD 200
#
# Create firt Mandelbrot viewer
#
vtkImageMandelbrotSource mandelbrot1
mandelbrot1 SetMaximumNumberOfIterations [expr int($MAX_ITERATIONS_1)]
mandelbrot1 SetWholeExtent [expr -$XRAD] [expr $XRAD-1] \
[expr -$YRAD] [expr $YRAD-1] \
0 0
set sample [expr 1.3 / $XRAD]
mandelbrot1 SetSampleCX $sample $sample $sample $sample
mandelbrot1 SetOriginCX -0.72 0.22 0.0 0.0
mandelbrot1 SetProjectionAxes 0 1 2
vtkLookupTable table1
table1 SetTableRange 0 $RANGE
table1 SetNumberOfColors $RANGE
table1 Build
table1 SetTableValue [expr $RANGE - 1] 0.0 0.0 0.0 0.0
vtkImageMapToColors map1
map1 SetInputConnection [mandelbrot1 GetOutputPort]
map1 SetOutputFormatToRGB
map1 SetLookupTable table1
vtkImageViewer viewer
viewer SetInputConnection [map1 GetOutputPort]
viewer SetColorWindow 255.0
viewer SetColorLevel 127.5
[viewer GetActor2D] SetPosition $XRAD $YRAD
#
# Create second Mandelbrot viewer
#
vtkImageMandelbrotSource mandelbrot2
mandelbrot2 SetMaximumNumberOfIterations [expr int($MAX_ITERATIONS_2)]
mandelbrot2 SetWholeExtent [expr -$XRAD] [expr $XRAD-1] \
[expr -$YRAD] [expr $YRAD-1] \
0 0
set sample [expr 1.3 / $XRAD]
mandelbrot2 SetSampleCX $sample $sample $sample $sample
mandelbrot2 SetOriginCX -0.72 0.22 0.0 0.0
mandelbrot2 SetProjectionAxes 2 3 1
vtkLookupTable table2
table2 SetTableRange 0 $RANGE
table2 SetNumberOfColors $RANGE
table2 Build
table2 SetTableValue [expr $RANGE - 1] 0.0 0.0 0.0 0.0
vtkImageMapToColors map2
map2 SetInputConnection [mandelbrot2 GetOutputPort]
map2 SetOutputFormatToRGB
map2 SetLookupTable table2
vtkImageViewer viewer2
viewer2 SetInputConnection [map2 GetOutputPort]
viewer2 SetColorWindow 256.0
viewer2 SetColorLevel 127.5
[viewer2 GetActor2D] SetPosition $XRAD $YRAD
#
# Create the GUI: two vtkTkImageViewer widgets and a quit/reset buttons
#
wm withdraw .
set top [toplevel .top]
wm protocol .top WM_DELETE_WINDOW ::vtk::cb_exit
wm title .top "Mandelbrot Viewer"
set f1 [frame $top.f1]
pack $f1 \
-side bottom \
-fill both -expand f
#
# Create the image viewer widget for set 1
#
set manFrame [frame $f1.man]
set julFrame [frame $f1.jul]
pack $manFrame $julFrame \
-side left \
-padx 3 -pady 3 \
-fill both -expand f
set manView [vtkTkImageViewerWidget $manFrame.view \
-iv viewer \
-width [expr $XRAD*2] \
-height [expr $YRAD*2]]
set manRange [label $manFrame.range \
-text "Mandelbrot Range: 0 - $RANGE"]
set quit [button $manFrame.quit \
-text "Quit" \
-command ::vtk::cb_exit]
#
# Create the image viewer widget for set 2
#
pack $manView $manRange $quit \
-side top \
-padx 2 -pady 2 \
-fill both -expand f
set julView [vtkTkImageViewerWidget $julFrame.view \
-iv viewer2 \
-width [expr $XRAD*2] \
-height [expr $YRAD*2]]
set julRange [label $julFrame.range \
-text "Julia Range: 0 - $RANGE"]
set reset [button $julFrame.reset \
-text "Reset" \
-command Reset]
pack $julView $julRange $reset \
-side top \
-padx 2 -pady 2 \
-fill both -expand f
#
# The equation label
#
set equation [label $top.equation \
-text "X = X^2 + C"]
pack $equation \
-side bottom \
-fill x -expand f
#
# Create the default bindings
#
::vtk::bind_tk_imageviewer_widget $manView
::vtk::bind_tk_imageviewer_widget $julView
#
# Override some of the bindings
#
foreach {widget master slave} [list $manView 1 2 $julView 2 1] {
set iren [[[$widget GetImageViewer] GetRenderWindow] GetInteractor]
set istyle [$iren GetInteractorStyle]
# Zoom in
$istyle RemoveObservers LeftButtonPressEvent
$istyle AddObserver LeftButtonPressEvent \
[list StartZoom $iren]
$istyle RemoveObservers LeftButtonReleaseEvent
$istyle AddObserver LeftButtonReleaseEvent \
[list EndZoom $iren $master $slave]
# Zoom out
$istyle RemoveObservers RightButtonPressEvent
$istyle AddObserver RightButtonPressEvent \
[list ZoomOut $iren $master $slave]
$istyle RemoveObservers RightButtonReleaseEvent
# Pan
$istyle RemoveObservers MiddleButtonPressEvent
$istyle AddObserver MiddleButtonPressEvent \
[list Pan $iren $master $slave]
$istyle RemoveObservers MiddleButtonReleaseEvent
}
#
# Update the display
#
proc MandelbrotUpdate {} {
global MAX_ITERATIONS_1 MAX_ITERATIONS_2 RANGE
global manView julView manRange julRange
mandelbrot1 SetMaximumNumberOfIterations [expr int($MAX_ITERATIONS_1)]
mandelbrot2 SetMaximumNumberOfIterations [expr int($MAX_ITERATIONS_1)]
set tmp [mandelbrot1 GetOriginCX]
set cr [lindex $tmp 0]
set ci [lindex $tmp 1]
set xr [lindex $tmp 2]
set xi [lindex $tmp 3]
mandelbrot1 Update
set tmp [[mandelbrot1 GetOutput] GetScalarRange]
set min [lindex $tmp 0]
set max [lindex $tmp 1]
$manRange configure -text "C = $cr + i $ci, Mandelbrot Range: $min - $max"
eval table1 SetTableRange [expr $min - 1] $max
set MAX_ITERATIONS_1 [expr $min + $RANGE]
mandelbrot2 Update
set tmp [[mandelbrot2 GetOutput] GetScalarRange]
set min [lindex $tmp 0]
set max [lindex $tmp 1]
$julRange configure -text "X = $xr + i $xi, Julia Range: $min - $max"
eval table2 SetTableRange [expr $min - 1] $max
set MAX_ITERATIONS_2 [expr $min + $RANGE]
$manView Render
$julView Render
}
#
# Reset both sets
#
proc Reset {} {
global MAX_ITERATIONS_1 MAX_ITERATIONS_2 RANGE XRAD
set MAX_ITERATIONS_2 $RANGE
set MAX_ITERATIONS_1 $RANGE
set sample [expr 1.3 / $XRAD]
mandelbrot1 SetSampleCX $sample $sample $sample $sample
mandelbrot1 SetOriginCX -0.72 0.22 0.0 0.0
set sample [expr 1.3 / $XRAD]
mandelbrot2 SetSampleCX $sample $sample $sample $sample
mandelbrot2 SetOriginCX -0.72 0.22 0.0 0.0
MandelbrotUpdate
}
#
# Zoom in
#
proc StartZoom {iren} {
global X Y
set pos [$iren GetEventPosition]
set X [lindex $pos 0]
set Y [lindex $pos 1]
}
proc EndZoom {iren master slave} {
global X Y XRAD YRAD
# Put origin in middle.
set pos [$iren GetEventPosition]
set x [expr [lindex $pos 0] - $XRAD]
set y [expr [lindex $pos 1] - $YRAD]
set X [expr $X - $XRAD]
set Y [expr $Y - $YRAD]
# Sort
if {$X < $x} {
set tmp $X
set X $x
set x $tmp
}
if {$Y < $y} {
set tmp $Y
set Y $y
set y $tmp
}
# Middle/radius
set xMid [expr 0.5 * ($x + $X)]
set yMid [expr 0.5 * ($y + $Y)]
set xDim [expr ($X - $x)]
set yDim [expr ($Y - $y)]
# Determine scale
if { $xDim <= 4 && $yDim <= 4} {
# Box too small. Zoom into point.
set scale 0.5
} else {
# Relative to window dimensions
set xDim [expr 1.0 * $xDim / (2*$XRAD)]
set yDim [expr 1.0 * $yDim / (2*$YRAD)]
# Take the largest
if {$xDim > $yDim} {
set scale $xDim
} else {
set scale $yDim
}
}
mandelbrot$master Pan $xMid $yMid 0.0
mandelbrot$master Zoom $scale
mandelbrot$slave CopyOriginAndSample mandelbrot$master
MandelbrotUpdate
}
#
# Zoom out
#
proc ZoomOut {iren master slave} {
global XRAD YRAD
# Put origin in middle.
set pos [$iren GetEventPosition]
set x [expr [lindex $pos 0] - $XRAD]
set y [expr [lindex $pos 1] - $YRAD]
set scale 2.0
# Compute new origin.
mandelbrot$master Pan $x $y 0.0
mandelbrot$master Zoom $scale
mandelbrot$slave CopyOriginAndSample mandelbrot$master
MandelbrotUpdate
}
#
# Pan
#
proc Pan {iren master slave} {
global XRAD YRAD
# Put origin in middle.
set pos [$iren GetEventPosition]
set x [expr [lindex $pos 0] - $XRAD]
set y [expr [lindex $pos 1] - $YRAD]
set scale 2.0
# Compute new origin.
mandelbrot$master Pan $x $y 0.0
mandelbrot$slave CopyOriginAndSample mandelbrot$master
MandelbrotUpdate
}
MandelbrotUpdate
|