[3330] | 1 | # -*- mode: tcl; indent-tabs-mode: nil -*- |
---|
[988] | 2 | |
---|
[908] | 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 |
---|
[3177] | 11 | # Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
[908] | 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 | |
---|
[1436] | 20 | itcl::class Rappture::IsoMarker { |
---|
[2744] | 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 |
---|
[1929] | 27 | # associated with. |
---|
[1943] | 28 | private variable _activeMotion 0 |
---|
| 29 | private variable _activePress 0 |
---|
| 30 | private common _normalIcon [Rappture::icon nvlegendmark] |
---|
| 31 | private common _activeIcon [Rappture::icon nvlegendmark2] |
---|
[908] | 32 | |
---|
[1247] | 33 | constructor {c obj tf args} { |
---|
[1943] | 34 | set _canvas $c |
---|
| 35 | set _nvobj $obj |
---|
| 36 | set _tf $tf |
---|
| 37 | set w [winfo width $_canvas] |
---|
| 38 | set h [winfo height $_canvas] |
---|
| 39 | set _tick [$c create image 0 $h \ |
---|
| 40 | -image $_normalIcon -anchor s \ |
---|
[1929] | 41 | -tags "$this $obj" -state hidden] |
---|
[1943] | 42 | set _label [$c create text 0 $h \ |
---|
[1929] | 43 | -anchor n -fill white -font "Helvetica 8" \ |
---|
| 44 | -tags "$this $obj" -state hidden] |
---|
[1943] | 45 | $c bind $_tick <Enter> [itcl::code $this HandleEvent "enter"] |
---|
| 46 | $c bind $_tick <Leave> [itcl::code $this HandleEvent "leave"] |
---|
| 47 | $c bind $_tick <ButtonPress-1> \ |
---|
[1929] | 48 | [itcl::code $this HandleEvent "start" %x %y] |
---|
[1943] | 49 | $c bind $_tick <B1-Motion> \ |
---|
[1929] | 50 | [itcl::code $this HandleEvent "update" %x %y] |
---|
[1943] | 51 | $c bind $_tick <ButtonRelease-1> \ |
---|
[1929] | 52 | [itcl::code $this HandleEvent "end" %x %y] |
---|
[908] | 53 | } |
---|
| 54 | destructor { |
---|
[1943] | 55 | $_canvas delete $this |
---|
[908] | 56 | } |
---|
[1376] | 57 | public method transferfunc {} { |
---|
[1943] | 58 | return $_tf |
---|
[971] | 59 | } |
---|
[1376] | 60 | public method activate { bool } { |
---|
[1943] | 61 | if { $bool || $_activePress || $_activeMotion } { |
---|
| 62 | $_canvas itemconfigure $_label -state normal |
---|
| 63 | $_canvas itemconfigure $_tick -image $_activeIcon |
---|
[1929] | 64 | } else { |
---|
[1943] | 65 | $_canvas itemconfigure $_label -state hidden |
---|
| 66 | $_canvas itemconfigure $_tick -image $_normalIcon |
---|
[1929] | 67 | } |
---|
[908] | 68 | } |
---|
[1376] | 69 | public method visible { bool } { |
---|
[1929] | 70 | if { $bool } { |
---|
[1943] | 71 | absval $_value |
---|
| 72 | $_canvas itemconfigure $_tick -state normal |
---|
| 73 | $_canvas raise $_tick |
---|
[1929] | 74 | } else { |
---|
[1943] | 75 | $_canvas itemconfigure $_tick -state hidden |
---|
[1929] | 76 | } |
---|
[908] | 77 | } |
---|
[1376] | 78 | public method screenpos { } { |
---|
[1929] | 79 | set x [relval] |
---|
| 80 | if { $x < 0.0 } { |
---|
| 81 | set x 0.0 |
---|
| 82 | } elseif { $x > 1.0 } { |
---|
| 83 | set x 1.0 |
---|
| 84 | } |
---|
| 85 | set low 10 |
---|
[1943] | 86 | set w [winfo width $_canvas] |
---|
[1929] | 87 | set high [expr {$w - 10}] |
---|
| 88 | set x [expr {round($x*($high - $low) + $low)}] |
---|
| 89 | return $x |
---|
[908] | 90 | } |
---|
[1376] | 91 | public method absval { {x "-get"} } { |
---|
[1929] | 92 | if { $x != "-get" } { |
---|
[1943] | 93 | set _value $x |
---|
[1929] | 94 | set y 31 |
---|
[1943] | 95 | $_canvas itemconfigure $_label -text [format %.2g $_value] |
---|
[1929] | 96 | set x [screenpos] |
---|
[1943] | 97 | $_canvas coords $_tick $x [expr {$y+3}] |
---|
| 98 | $_canvas coords $_label $x [expr {$y+5}] |
---|
[1929] | 99 | } |
---|
[1943] | 100 | return $_value |
---|
[908] | 101 | } |
---|
[1376] | 102 | public method relval { {x "-get"} } { |
---|
[1929] | 103 | if { $x == "-get" } { |
---|
[1943] | 104 | array set limits [$_nvobj limits $_tf] |
---|
[1929] | 105 | if { $limits(vmax) == $limits(vmin) } { |
---|
| 106 | if { $limits(vmax) == 0.0 } { |
---|
| 107 | set limits(vmin) 0.0 |
---|
| 108 | set limits(vmax) 1.0 |
---|
| 109 | } else { |
---|
| 110 | set limits(vmax) [expr $limits(vmin) + 1.0] |
---|
| 111 | } |
---|
| 112 | } |
---|
[1943] | 113 | return [expr {($_value-$limits(vmin))/ |
---|
[1929] | 114 | ($limits(vmax) - $limits(vmin))}] |
---|
| 115 | } |
---|
[1943] | 116 | array set limits [$_nvobj limits $_tf] |
---|
[1929] | 117 | if { $limits(vmax) == $limits(vmin) } { |
---|
[3362] | 118 | set limits(vmin) 0.0 |
---|
| 119 | set limits(vmax) 1.0 |
---|
[1929] | 120 | } |
---|
[2744] | 121 | if { [catch {expr $limits(vmax) - $limits(vmin)} r] != 0 } { |
---|
| 122 | return 0.0 |
---|
| 123 | } |
---|
[1929] | 124 | absval [expr {($x * $r) + $limits(vmin)}] |
---|
[908] | 125 | } |
---|
[1376] | 126 | private method HandleEvent { option args } { |
---|
[1929] | 127 | switch -- $option { |
---|
| 128 | enter { |
---|
[1943] | 129 | set _activeMotion 1 |
---|
[1929] | 130 | activate yes |
---|
[1943] | 131 | $_canvas raise $_tick |
---|
[1929] | 132 | } |
---|
| 133 | leave { |
---|
[1943] | 134 | set _activeMotion 0 |
---|
[1929] | 135 | activate no |
---|
| 136 | } |
---|
| 137 | start { |
---|
[1943] | 138 | $_canvas raise $_tick |
---|
| 139 | set _activePress 1 |
---|
[1929] | 140 | activate yes |
---|
[1943] | 141 | $_canvas itemconfigure limits -state hidden |
---|
[1929] | 142 | } |
---|
| 143 | update { |
---|
[1943] | 144 | set w [winfo width $_canvas] |
---|
[1929] | 145 | set x [lindex $args 0] |
---|
| 146 | relval [expr {double($x-10)/($w-20)}] |
---|
[1943] | 147 | $_nvobj overmarker $this $x |
---|
| 148 | $_nvobj updatetransferfuncs |
---|
[1929] | 149 | } |
---|
| 150 | end { |
---|
| 151 | set x [lindex $args 0] |
---|
[1943] | 152 | if { ![$_nvobj rmdupmarker $this $x]} { |
---|
[1929] | 153 | eval HandleEvent update $args |
---|
| 154 | } |
---|
[1943] | 155 | set _activePress 0 |
---|
[1929] | 156 | activate no |
---|
[1943] | 157 | $_canvas itemconfigure limits -state normal |
---|
[1929] | 158 | } |
---|
| 159 | default { |
---|
| 160 | error "bad option \"$option\": should be start, update, end" |
---|
| 161 | } |
---|
| 162 | } |
---|
[908] | 163 | } |
---|
| 164 | } |
---|