1 | # -*- mode: tcl; indent-tabs-mode: nil -*- |
---|
2 | |
---|
3 | # ---------------------------------------------------------------------- |
---|
4 | # COMPONENT: nanovisviewer::isomarker - Marker for 3D volume rendering |
---|
5 | # |
---|
6 | # This widget performs volume rendering on 3D scalar/vector datasets. |
---|
7 | # It connects to the Nanovis server running on a rendering farm, |
---|
8 | # transmits data, and displays the results. |
---|
9 | # ====================================================================== |
---|
10 | # AUTHOR: Michael McLennan, Purdue University |
---|
11 | # Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
12 | # |
---|
13 | # See the file "license.terms" for information on usage and |
---|
14 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
15 | # ====================================================================== |
---|
16 | package require Itk |
---|
17 | package require BLT |
---|
18 | package require Img |
---|
19 | |
---|
20 | itcl::class Rappture::IsoMarker { |
---|
21 | private variable _value 0.0; # Absolute value of marker. |
---|
22 | private variable _label "" |
---|
23 | private variable _tick "" |
---|
24 | private variable _canvas "" |
---|
25 | private variable _nvobj ""; # Parent nanovis object. |
---|
26 | private variable _tf ""; # Transfer function that this marker is |
---|
27 | # associated with. |
---|
28 | private variable _activeMotion 0 |
---|
29 | private variable _activePress 0 |
---|
30 | private common _normalIcon [Rappture::icon nvlegendmark] |
---|
31 | private common _activeIcon [Rappture::icon nvlegendmark2] |
---|
32 | private method EnterTick {} |
---|
33 | private method LeaveTick {} |
---|
34 | private method StartDrag { x y } |
---|
35 | private method ContinueDrag { x y } |
---|
36 | private method StopDrag { x y } |
---|
37 | |
---|
38 | constructor {c obj tf args} {} |
---|
39 | destructor {} |
---|
40 | public method transferfunc {} |
---|
41 | public method activate { bool } |
---|
42 | public method visible { bool } |
---|
43 | public method screenpos {} |
---|
44 | public method absval { {x "-get"} } |
---|
45 | public method relval { {x "-get"} } |
---|
46 | } |
---|
47 | |
---|
48 | itcl::body Rappture::IsoMarker::constructor {c obj tf args} { |
---|
49 | set _canvas $c |
---|
50 | set _nvobj $obj |
---|
51 | set _tf $tf |
---|
52 | set w [winfo width $_canvas] |
---|
53 | set h [winfo height $_canvas] |
---|
54 | set _tick [$c create image 0 $h \ |
---|
55 | -image $_normalIcon -anchor s \ |
---|
56 | -tags "tick $this $obj" -state hidden] |
---|
57 | set _label [$c create text 0 $h \ |
---|
58 | -anchor n -fill white -font "Helvetica 8" \ |
---|
59 | -tags "labels $this $obj" -state hidden] |
---|
60 | $c bind $_tick <Enter> [itcl::code $this EnterTick] |
---|
61 | $c bind $_tick <Leave> [itcl::code $this LeaveTick] |
---|
62 | $c bind $_tick <ButtonPress-1> [itcl::code $this StartDrag %x %y] |
---|
63 | $c bind $_tick <B1-Motion> [itcl::code $this ContinueDrag %x %y] |
---|
64 | $c bind $_tick <ButtonRelease-1> [itcl::code $this StopDrag %x %y] |
---|
65 | } |
---|
66 | |
---|
67 | itcl::body Rappture::IsoMarker::destructor {} { |
---|
68 | if { [winfo exists $_canvas] } { |
---|
69 | $_canvas delete $this |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | itcl::body Rappture::IsoMarker::transferfunc {} { |
---|
74 | return $_tf |
---|
75 | } |
---|
76 | |
---|
77 | itcl::body Rappture::IsoMarker::activate { bool } { |
---|
78 | if { $bool || $_activePress || $_activeMotion } { |
---|
79 | $_canvas itemconfigure $_label -state normal |
---|
80 | $_canvas itemconfigure $_tick -image $_activeIcon |
---|
81 | $_canvas itemconfigure title -state hidden |
---|
82 | } else { |
---|
83 | $_canvas itemconfigure $_label -state hidden |
---|
84 | $_canvas itemconfigure $_tick -image $_normalIcon |
---|
85 | $_canvas itemconfigure title -state normal |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | itcl::body Rappture::IsoMarker::visible { bool } { |
---|
90 | if { $bool } { |
---|
91 | absval $_value |
---|
92 | $_canvas itemconfigure $_tick -state normal |
---|
93 | $_canvas raise $_tick |
---|
94 | } else { |
---|
95 | $_canvas itemconfigure $_tick -state hidden |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | itcl::body Rappture::IsoMarker::screenpos { } { |
---|
100 | set x [relval] |
---|
101 | if { $x < 0.0 } { |
---|
102 | set x 0.0 |
---|
103 | } elseif { $x > 1.0 } { |
---|
104 | set x 1.0 |
---|
105 | } |
---|
106 | set low 10 |
---|
107 | set w [winfo width $_canvas] |
---|
108 | set high [expr {$w - 10}] |
---|
109 | set x [expr {round($x*($high - $low) + $low)}] |
---|
110 | return $x |
---|
111 | } |
---|
112 | |
---|
113 | itcl::body Rappture::IsoMarker::absval { {x "-get"} } { |
---|
114 | if { $x != "-get" } { |
---|
115 | set _value $x |
---|
116 | set y 31 |
---|
117 | $_canvas itemconfigure $_label -text [format %g $_value] |
---|
118 | set x [screenpos] |
---|
119 | $_canvas coords $_tick $x [expr {$y+3}] |
---|
120 | $_canvas coords $_label $x [expr {$y+5}] |
---|
121 | } |
---|
122 | return $_value |
---|
123 | } |
---|
124 | |
---|
125 | itcl::body Rappture::IsoMarker::relval { {x "-get"} } { |
---|
126 | foreach {min max} [$_nvobj limits $_tf] break |
---|
127 | if { $x == "-get" } { |
---|
128 | if { $max == $min } { |
---|
129 | if { $max == 0.0 } { |
---|
130 | set min 0.0 |
---|
131 | set max 1.0 |
---|
132 | } else { |
---|
133 | set max [expr $min + 1.0] |
---|
134 | } |
---|
135 | } |
---|
136 | return [expr {($_value - $min) / ($max - $min)}] |
---|
137 | } |
---|
138 | if { $max == $min } { |
---|
139 | set min 0.0 |
---|
140 | set max 1.0 |
---|
141 | } |
---|
142 | if { [catch {expr $max - $min} r] != 0 } { |
---|
143 | return 0.0 |
---|
144 | } |
---|
145 | absval [expr {($x * $r) + $min}] |
---|
146 | } |
---|
147 | |
---|
148 | itcl::body Rappture::IsoMarker::EnterTick {} { |
---|
149 | set _activeMotion 1 |
---|
150 | activate yes |
---|
151 | $_canvas raise $_tick |
---|
152 | } |
---|
153 | |
---|
154 | itcl::body Rappture::IsoMarker::LeaveTick {} { |
---|
155 | set _activeMotion 0 |
---|
156 | activate no |
---|
157 | } |
---|
158 | |
---|
159 | itcl::body Rappture::IsoMarker::StartDrag { x y } { |
---|
160 | $_canvas raise $_tick |
---|
161 | set _activePress 1 |
---|
162 | activate yes |
---|
163 | $_canvas itemconfigure limits -state hidden |
---|
164 | $_canvas itemconfigure title -state hidden |
---|
165 | } |
---|
166 | |
---|
167 | itcl::body Rappture::IsoMarker::StopDrag { x y } { |
---|
168 | if { ![$_nvobj removeDuplicateMarker $this $x]} { |
---|
169 | ContinueDrag $x $y |
---|
170 | } |
---|
171 | set _activePress 0 |
---|
172 | activate no |
---|
173 | $_canvas itemconfigure limits -state normal |
---|
174 | $_canvas itemconfigure title -state normal |
---|
175 | } |
---|
176 | |
---|
177 | itcl::body Rappture::IsoMarker::ContinueDrag { x y } { |
---|
178 | set w [winfo width $_canvas] |
---|
179 | relval [expr {double($x-10)/($w-20)}] |
---|
180 | $_nvobj overMarker $this $x |
---|
181 | $_nvobj updateTransferFunctions |
---|
182 | $_canvas raise $_tick |
---|
183 | set _activePress 1 |
---|
184 | activate yes |
---|
185 | $_canvas itemconfigure limits -state hidden |
---|
186 | $_canvas itemconfigure title -state hidden |
---|
187 | } |
---|