- Timestamp:
- May 31, 2015, 4:36:54 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/transferfunctioneditor.tcl
r5562 r5640 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 3 2 # ---------------------------------------------------------------------- 4 # COMPONENT: transferfunctioneditor - Rudimentary editor for 3D volume 3 # COMPONENT: transferfunctioneditor - Rudimentary editor for 3D volume 5 4 # transfer functions 6 5 # 7 # This class is used to modify transfer functions used in volume rendering 6 # This class is used to modify transfer functions used in volume rendering 8 7 # on 3D scalar/vector datasets. 9 8 # … … 20 19 21 20 itcl::class Rappture::TransferFunctionEditor { 22 private variable _nextId 0; # Used to create unique marker names23 private variable _values; # Relative values for each marker.24 private variable _limits; # Over limits of transfer function.25 private variable _labels; # Label id for each marker.26 private variable _ticks; # Tick id for each marker.27 private variable _canvas ""28 private variable _name ""; # Name of transfer function.29 private variable _activeMotion 030 private variable _activePress 031 private variable _id2name32 private common _normalIcon [Rappture::icon nvlegendmark]33 private common _activeIcon [Rappture::icon nvlegendmark2]34 public variable command ""35 36 private method SetAbsoluteValue { name x }37 private method GetAbsoluteValue { name }38 private method ContinueDrag { name x y }39 private method EnterTick { name }40 private method GetOverlappingMarkers { x y }41 private method GetScreenPosition { name }42 private method LeaveTick { name }43 private method SetRelativeValue { name x }44 private method GetRelativeValue { name }45 private method RemoveDuplicateMarkers {name x y}46 private method SetScreenPosition { name }47 private method SetVisibility { name bool }48 private method StartDrag { name x y }49 private method StopDrag { name x y }50 private method Activate { name }51 private method Deactivate { name }52 private method UpdateViewer {}53 54 21 constructor {c name args} {} 55 destructor {} 22 destructor {} 56 23 public method limits { min max } 57 24 public method names {} … … 65 32 public method hideMarkers { {list {}} } 66 33 public method showMarkers { {limits {}} } 67 } 68 69 itcl::body Rappture::TransferFunctionEditor::constructor {c name args} { 34 35 public variable command "" 36 37 private method SetAbsoluteValue { name x } 38 private method GetAbsoluteValue { name } 39 private method ContinueDrag { name x y } 40 private method EnterTick { name } 41 private method GetOverlappingMarkers { x y } 42 private method GetScreenPosition { name } 43 private method LeaveTick { name } 44 private method SetRelativeValue { name x } 45 private method GetRelativeValue { name } 46 private method RemoveDuplicateMarkers {name x y} 47 private method SetScreenPosition { name } 48 private method SetVisibility { name bool } 49 private method StartDrag { name x y } 50 private method StopDrag { name x y } 51 private method Activate { name } 52 private method Deactivate { name } 53 private method UpdateViewer {} 54 55 private variable _nextId 0; # Used to create unique marker names 56 private variable _values; # Relative values for each marker. 57 private variable _limits; # Over limits of transfer function. 58 private variable _labels; # Label id for each marker. 59 private variable _ticks; # Tick id for each marker. 60 private variable _canvas "" 61 private variable _name ""; # Name of transfer function. 62 private variable _activeMotion 0 63 private variable _activePress 0 64 private variable _id2name 65 66 private common _normalIcon [Rappture::icon nvlegendmark] 67 private common _activeIcon [Rappture::icon nvlegendmark2] 68 } 69 70 itcl::body Rappture::TransferFunctionEditor::constructor {c name args} { 70 71 set _canvas $c 71 72 set _name $name 72 set _limits [list 0.0 1.0] 73 set _limits [list 0.0 1.0] 73 74 eval configure $args 74 75 } 75 76 76 itcl::body Rappture::TransferFunctionEditor::limits { min max } { 77 itcl::body Rappture::TransferFunctionEditor::limits { min max } { 77 78 set _limits [list $min $max] 78 79 } 79 80 80 itcl::body Rappture::TransferFunctionEditor::names {} { 81 itcl::body Rappture::TransferFunctionEditor::names {} { 81 82 return [lsort [array names _values]] 82 83 } 83 84 84 itcl::body Rappture::TransferFunctionEditor::values {} { 85 itcl::body Rappture::TransferFunctionEditor::values {} { 85 86 set list {} 86 87 foreach name [array names _ticks] { 87 88 lappend list [GetRelativeValue $name] 88 89 } 89 90 return [lsort -real $list] 90 91 } 91 92 92 itcl::body Rappture::TransferFunctionEditor::absoluteValues {} { 93 itcl::body Rappture::TransferFunctionEditor::absoluteValues {} { 93 94 set list {} 94 95 foreach name [array names _values] { 95 96 lappend list [GetAbsoluteValue $name] 96 97 } 97 98 return $list 98 99 } 99 100 100 itcl::body Rappture::TransferFunctionEditor::deleteMarker { x y } { 101 itcl::body Rappture::TransferFunctionEditor::deleteMarker { x y } { 101 102 foreach marker [GetOverlappingMarkers $x $y] { 102 103 $_canvas delete $_ticks($marker) … … 110 111 } 111 112 112 itcl::body Rappture::TransferFunctionEditor::newMarker { x y state } { 113 itcl::body Rappture::TransferFunctionEditor::newMarker { x y state } { 113 114 foreach id [$_canvas find overlapping \ 114 115 [expr $x-5] [expr $y-5] [expr $x+5] [expr $y+5]] { 115 116 if { [info exists _id2name($id)] } { 116 117 puts stderr "Too close to existing marker" 117 118 118 return; # Too close to existing marker 119 } 119 120 } 120 121 set name "tick[incr _nextId]" … … 132 133 $_canvas bind $_ticks($name) <Leave> [itcl::code $this LeaveTick $name] 133 134 $_canvas bind $_ticks($name) <ButtonPress-1> \ 134 135 [itcl::code $this StartDrag $name %x %y] 135 136 $_canvas bind $_ticks($name) <B1-Motion> \ 136 137 [itcl::code $this ContinueDrag $name %x %y] 137 138 $_canvas bind $_ticks($name) <ButtonRelease-1> \ 138 139 [itcl::code $this StopDrag $name %x %y] 139 140 140 141 SetRelativeValue $name [expr {double($x-10)/($w-20)}] … … 182 183 } 183 184 184 itcl::body Rappture::TransferFunctionEditor::GetScreenPosition { name } { 185 itcl::body Rappture::TransferFunctionEditor::GetScreenPosition { name } { 185 186 set x [GetRelativeValue $name] 186 187 if { $x < 0.0 } { 187 188 set x 0.0 188 189 } elseif { $x > 1.0 } { 189 set x 1.0 190 } 191 set low 10 190 set x 1.0 191 } 192 set low 10 192 193 set w [winfo width $_canvas] 193 194 set high [expr {$w - 10}] … … 196 197 } 197 198 198 itcl::body Rappture::TransferFunctionEditor::SetScreenPosition { name } { 199 itcl::body Rappture::TransferFunctionEditor::SetScreenPosition { name } { 199 200 set value $_values($name) 200 201 set x [GetScreenPosition $name] … … 250 251 251 252 itcl::body Rappture::TransferFunctionEditor::StartDrag { name x y } { 252 $_canvas raise $_ticks($name) 253 $_canvas raise $_ticks($name) 253 254 set _activePress 1 254 255 Activate $name … … 258 259 259 260 itcl::body Rappture::TransferFunctionEditor::StopDrag { name x y } { 260 ContinueDrag $name $x $y 261 ContinueDrag $name $x $y 261 262 RemoveDuplicateMarkers $name $x $y 262 263 set _activePress 0 … … 280 281 set list {} 281 282 foreach id [$_canvas find overlapping $x $y $x $y] { 282 283 284 283 if { [info exists _id2name($id)] } { 284 lappend list $_id2name($id) 285 } 285 286 } 286 287 return $list … … 289 290 itcl::body Rappture::TransferFunctionEditor::hideMarkers { {list {}} } { 290 291 if { $list == "" } { 291 292 set list [array names _values] 292 293 } 293 294 foreach name $list { 294 295 SetVisibility $name 0 295 296 } 296 297 } … … 298 299 itcl::body Rappture::TransferFunctionEditor::showMarkers { {limits {}} } { 299 300 if { $limits != "" } { 300 301 302 SetScreenPosition $name 303 301 set _limits $limits 302 foreach name [array names _values] { 303 SetScreenPosition $name 304 } 304 305 } 305 306 foreach name [array names _values] { 306 307 SetVisibility $name 1 307 308 } 308 309 } … … 310 311 itcl::body Rappture::TransferFunctionEditor::RemoveDuplicateMarkers {name x y} { 311 312 foreach marker [GetOverlappingMarkers $x $y] { 312 313 Activate $marker 313 if { $marker != $name } { 314 Activate $marker 314 315 set markerx [GetScreenPosition $marker] 315 316 if { ($x < ($markerx-3)) || ($x > ($markerx+3)) } { 316 317 continue 317 318 } 318 319 320 321 322 319 $_canvas delete $_ticks($marker) 320 $_canvas delete $_labels($marker) 321 array unset _ticks $marker 322 array unset _labels $marker 323 array unset _values $marker 323 324 bell 324 325 } 325 326 } 326 327 } … … 328 329 itcl::body Rappture::TransferFunctionEditor::addMarkers { values } { 329 330 foreach value $values { 330 331 331 set name [newMarker 0 0 hidden] 332 SetRelativeValue $name $value 332 333 } 333 334 } … … 335 336 itcl::body Rappture::TransferFunctionEditor::removeMarkers { names } { 336 337 if { $names == "" } { 337 338 set names [array names _values] 338 339 } 339 340 foreach name $names { 340 341 342 343 344 341 $_canvas delete $_ticks($name) 342 $_canvas delete $_labels($name) 343 array unset _ticks $name 344 array unset _labels $name 345 array unset _values $name 345 346 } 346 347 UpdateViewer … … 351 352 # now that a marker position has changed. 352 353 if { $command != "" } { 353 354 } 355 } 354 eval uplevel \#0 $command 355 } 356 }
Note: See TracChangeset
for help on using the changeset viewer.