1 | # ---------------------------------------------------------------------- |
---|
2 | # COMPONENT: nanovisviewer::isomarker - Marker for 3D volume rendering |
---|
3 | # |
---|
4 | # This widget performs volume rendering on 3D scalar/vector datasets. |
---|
5 | # It connects to the Nanovis server running on a rendering farm, |
---|
6 | # transmits data, and displays the results. |
---|
7 | # ====================================================================== |
---|
8 | # AUTHOR: Michael McLennan, Purdue University |
---|
9 | # Copyright (c) 2004-2005 Purdue Research Foundation |
---|
10 | # |
---|
11 | # See the file "license.terms" for information on usage and |
---|
12 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
13 | # ====================================================================== |
---|
14 | package require Itk |
---|
15 | package require BLT |
---|
16 | package require Img |
---|
17 | |
---|
18 | itcl::class Rappture::NanovisViewer::IsoMarker { |
---|
19 | private variable _value ""; # Absolute value of marker. |
---|
20 | private variable _label "" |
---|
21 | private variable _tick "" |
---|
22 | private variable _canvas "" |
---|
23 | private variable _nvobj ""; # Parent nanovis object. |
---|
24 | private variable _active_motion 0 |
---|
25 | private variable _active_press 0 |
---|
26 | private common _normalIcon [Rappture::icon nvlegendmark] |
---|
27 | private common _activeIcon [Rappture::icon nvlegendmark2] |
---|
28 | |
---|
29 | constructor {c obj args} { |
---|
30 | set _canvas $c |
---|
31 | set _nvobj $obj |
---|
32 | |
---|
33 | set w [winfo width $_canvas] |
---|
34 | set h [winfo height $_canvas] |
---|
35 | set _tick [$c create image 0 $h \ |
---|
36 | -image $_normalIcon -anchor s \ |
---|
37 | -tags "$this $obj" -state hidden] |
---|
38 | set _label [$c create text 0 $h \ |
---|
39 | -anchor n -fill white -font "Helvetica 6" \ |
---|
40 | -tags "$this $obj" -state hidden] |
---|
41 | $c bind $_tick <Enter> [itcl::code $this HandleEvent "enter"] |
---|
42 | $c bind $_tick <Leave> [itcl::code $this HandleEvent "leave"] |
---|
43 | $c bind $_tick <ButtonPress-1> \ |
---|
44 | [itcl::code $this HandleEvent "start" %x %y] |
---|
45 | $c bind $_tick <B1-Motion> \ |
---|
46 | [itcl::code $this HandleEvent "update" %x %y] |
---|
47 | $c bind $_tick <ButtonRelease-1> \ |
---|
48 | [itcl::code $this HandleEvent "end" %x %y] |
---|
49 | } |
---|
50 | destructor { |
---|
51 | $_canvas delete $this |
---|
52 | } |
---|
53 | |
---|
54 | public method GetAbsoluteValue {} { |
---|
55 | return $_value |
---|
56 | } |
---|
57 | public method GetRelativeValue {} { |
---|
58 | array set limits [$_nvobj get_limits] |
---|
59 | if { $limits(vmax) == $limits(vmin) } { |
---|
60 | set limits(vmin) 0.0 |
---|
61 | set limits(vmax) 1.0 |
---|
62 | } |
---|
63 | return [expr {($_value-$limits(vmin))/($limits(vmax) - $limits(vmin))}] |
---|
64 | } |
---|
65 | public method Activate { bool } { |
---|
66 | if { $bool || $_active_press || $_active_motion } { |
---|
67 | $_canvas itemconfigure $_label -state normal |
---|
68 | $_canvas itemconfigure $_tick -image $_activeIcon |
---|
69 | } else { |
---|
70 | $_canvas itemconfigure $_label -state hidden |
---|
71 | $_canvas itemconfigure $_tick -image $_normalIcon |
---|
72 | } |
---|
73 | } |
---|
74 | public method Show {} { |
---|
75 | SetAbsoluteValue $_value |
---|
76 | $_canvas itemconfigure $_tick -state normal |
---|
77 | $_canvas raise $_tick |
---|
78 | } |
---|
79 | public method Hide {} { |
---|
80 | $_canvas itemconfigure $_tick -state hidden |
---|
81 | } |
---|
82 | public method GetScreenPosition { } { |
---|
83 | set x [GetRelativeValue] |
---|
84 | if { $x < 0.0 } { |
---|
85 | set x 0.0 |
---|
86 | } elseif { $x > 1.0 } { |
---|
87 | set x 1.0 |
---|
88 | } |
---|
89 | set low 10 |
---|
90 | set w [winfo width $_canvas] |
---|
91 | set high [expr {$w - 10}] |
---|
92 | set x [expr {round($x*($high - $low) + $low)}] |
---|
93 | return $x |
---|
94 | } |
---|
95 | public method SetAbsoluteValue { x } { |
---|
96 | set _value $x |
---|
97 | set y 31 |
---|
98 | $_canvas itemconfigure $_label -text [format %.4g $_value] |
---|
99 | set x [GetScreenPosition] |
---|
100 | $_canvas coords $_tick $x [expr {$y+3}] |
---|
101 | $_canvas coords $_label $x [expr {$y+5}] |
---|
102 | } |
---|
103 | public method SetRelativeValue { x } { |
---|
104 | array set limits [$_nvobj get_limits] |
---|
105 | if { $limits(vmax) == $limits(vmin) } { |
---|
106 | set limits(vmin) 0.0 |
---|
107 | set limits(vmax) 1.0 |
---|
108 | } |
---|
109 | set r [expr $limits(vmax) - $limits(vmin)] |
---|
110 | SetAbsoluteValue [expr {($x * $r) + $limits(vmin)}] |
---|
111 | } |
---|
112 | public method HandleEvent { option args } { |
---|
113 | switch -- $option { |
---|
114 | enter { |
---|
115 | set _active_motion 1 |
---|
116 | Activate yes |
---|
117 | $_canvas raise $_tick |
---|
118 | } |
---|
119 | leave { |
---|
120 | set _active_motion 0 |
---|
121 | Activate no |
---|
122 | } |
---|
123 | start { |
---|
124 | $_canvas raise $_tick |
---|
125 | set _active_press 1 |
---|
126 | Activate yes |
---|
127 | } |
---|
128 | update { |
---|
129 | set w [winfo width $_canvas] |
---|
130 | set x [lindex $args 0] |
---|
131 | SetRelativeValue [expr {double($x-10)/($w-20)}] |
---|
132 | $_nvobj OverIsoMarker $this $x |
---|
133 | $_nvobj UpdateTransferFunction |
---|
134 | } |
---|
135 | end { |
---|
136 | set x [lindex $args 0] |
---|
137 | if { ![$_nvobj RemoveDuplicateIsoMarker $this $x]} { |
---|
138 | eval HandleEvent update $args |
---|
139 | } |
---|
140 | set _active_press 0 |
---|
141 | Activate no |
---|
142 | } |
---|
143 | default { |
---|
144 | error "bad option \"$option\": should be start, update, end" |
---|
145 | } |
---|
146 | } |
---|
147 | } |
---|
148 | } |
---|
149 | |
---|