File: OrthogonalPlanesWithTkPhoto.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 (120 lines) | stat: -rw-r--r-- 3,941 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

#////////////////////////////////////////////////
package require vtk
package require vtkinteraction

# Image pipeline

vtkVolume16Reader reader
  reader SetDataDimensions 64 64
  reader SetDataByteOrderToLittleEndian
  reader SetFilePrefix "$VTK_DATA_ROOT/Data/headsq/quarter"
  reader SetImageRange 1 93
  reader SetDataSpacing 3.2 3.2 1.5
  reader Update

vtkImageCast cast
cast SetInputConnection [reader GetOutputPort]
cast SetOutputScalarType [[reader GetOutput] GetScalarType]
cast ClampOverflowOn

# Make the image a little bigger
vtkImageResample resample
resample SetInputConnection [cast GetOutputPort]
resample SetAxisMagnificationFactor 0 2
resample SetAxisMagnificationFactor 1 2
resample SetAxisMagnificationFactor 2 1

set range [[reader GetOutput] GetScalarRange]
set l [lindex $range 0]
set h [lindex $range 1]

wm withdraw .
toplevel .c
wm title .c "Tcl Version of vtkImageDataToTkPhoto"
wm protocol .c WM_DELETE_WINDOW ::vtk::cb_exit

# Create the three orthogonal views
set mode 0
set m [menu .c.mm -tearoff 0]
$m add radiobutton -label "unsigned char" -value -1 -variable mode -command CastToUnsignedChar
$m add radiobutton -label "unsigned short" -value 0 -variable mode -command CastToUnsignedShort
$m add radiobutton -label "unsigned int" -value 1 -variable mode -command CastToUnsignedInt
$m add radiobutton -label "float" -value 2 -variable mode -command CastToFloat

set tphoto [image create photo]
set cphoto [image create photo]
set sphoto [image create photo]
grid [label .c.t -image $tphoto] -row 0 -column 0
bind .c.t <Button1-Motion> "SetPosition transverse %W %x %y"
bind .c.t <Button-3> "$m post %X %Y"
grid [label .c.c -image $cphoto] -row 1 -column 0
bind .c.c <Button1-Motion> "SetPosition coronal %W %x %y"
bind .c.c <Button-3> "$m post %X %Y"
grid [label .c.s -image $sphoto] -row 0 -column 1
bind .c.s <Button1-Motion> "SetPosition sagittal %W %x %y"
bind .c.s <Button-3> "$m post %X %Y"

grid [scale .c.w -label Window -orient horizontal -from 1 -to [expr ($h - $l) / 2] -command SetWindow ] -row 2 -columnspan 2 -sticky ew
grid [scale .c.l -label Level -orient horizontal -from $l -to $h -command SetWindow ] -row 3 -columnspan 2 -sticky ew
grid [label .c.text -textvariable Label -bd 2 -relief raised] -row 4 -columnspan 2 -sticky ew
set Label "Use the right mouse button to change data type"
.c.w set 1370
.c.l set 1268
reader Update

set d [[reader GetOutput] GetDimensions]
set Position(x) [expr int ( [lindex $d 0] / 2.0 ) ]
set Position(y) [expr int ( [lindex $d 1] / 2.0 ) ]
set Position(z) [expr int ( [lindex $d 2] / 2.0 ) ]
# Scale = 255 / window
# Shift = Window / 2 - level

proc SetPosition { orientation widget x y } {
  global Label Position
  set i [$widget cget -image]
  set w [image width $i]
  set h [image height $i]
  switch $orientation {
    transverse { set Position(x) $x; set Position(y) [expr $h - $y - 1] }
    coronal { set Position(x) $x; set Position(z) $y }
    sagittal { set Position(y) [expr $w - $x - 1]; set Position(z) $y }
  }
  set Label "$orientation Position: $Position(x), $Position(y), $Position(z)"
  SetImages
}

proc SetWindow { foo } {
  SetImages
}

proc SetImages {} {
  global Position tphoto sphoto cphoto
  set Window [.c.w get]
  set Level [.c.l get]
  vtkImageDataToTkPhoto [resample GetOutputPort] $tphoto $Position(z) transverse $Window $Level
  vtkImageDataToTkPhoto [resample GetOutputPort] $sphoto $Position(x) sagittal $Window $Level
  vtkImageDataToTkPhoto [resample GetOutputPort] $cphoto $Position(y) coronal $Window $Level
}

proc CastToUnsignedChar {} {
  cast SetOutputScalarTypeToUnsignedChar
  SetImages
}
proc CastToUnsignedShort {} {
  cast SetOutputScalarTypeToUnsignedShort
  SetImages
}
proc CastToUnsignedInt {} {
  cast SetOutputScalarTypeToUnsignedInt
  SetImages
}
proc CastToFloat {} {
  cast SetOutputScalarTypeToFloat
  SetImages
}

# Prime the pump
SetImages
#///////////////////////////////////////////////////