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