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