source: trunk/gui/scripts/isomarker.tcl @ 1128

Last change on this file since 1128 was 1013, checked in by gah, 16 years ago

isomarker fixes (markers grouped by transfer-function not volume)

File size: 4.7 KB
Line 
1
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# ======================================================================
15package require Itk
16package require BLT
17package require Img
18
19itcl::class Rappture::NanovisViewer::IsoMarker {
20    private variable _value     "";     # 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 _ivol      "";     # Transfer function that this marker is
26                                        # associated with.
27    private variable _active_motion   0
28    private variable _active_press    0
29    private common   _normalIcon [Rappture::icon nvlegendmark]
30    private common   _activeIcon [Rappture::icon nvlegendmark2]
31
32    constructor {c obj ivol args} {
33        set _canvas $c
34        set _nvobj $obj
35        set _ivol $ivol
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 \
40                -tags "$this $obj" -state hidden]
41        set _label [$c create text 0 $h \
42                -anchor n -fill white -font "Helvetica 8" \
43                -tags "$this $obj" -state hidden]
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> \
47            [itcl::code $this HandleEvent "start" %x %y]
48        $c bind $_tick <B1-Motion> \
49            [itcl::code $this HandleEvent "update" %x %y]
50        $c bind $_tick <ButtonRelease-1> \
51            [itcl::code $this HandleEvent "end" %x %y]
52    }
53    destructor {
54        $_canvas delete $this
55    }
56    public method GetVolume {} {
57        return $_ivol
58    }
59    public method GetAbsoluteValue {} {
60        return $_value
61    }
62    public method GetRelativeValue {} {
63        array set limits [$_nvobj GetLimits $_ivol]
64        if { $limits(max) == $limits(min) } {
65            if { $limits(max) == 0.0 } {
66                set limits(min) 0.0
67                set limits(max) 1.0
68            } else {
69                set limits(max) [expr $limits(min) + 1.0]
70            }
71        }
72        return [expr {($_value-$limits(min))/($limits(max) - $limits(min))}]
73    }
74    public method Activate { bool } {
75        if  { $bool || $_active_press || $_active_motion } {
76            $_canvas itemconfigure $_label -state normal
77            $_canvas itemconfigure $_tick -image $_activeIcon
78        } else {
79            $_canvas itemconfigure $_label -state hidden
80            $_canvas itemconfigure $_tick -image $_normalIcon
81        }
82    }
83    public method Show {} {
84        SetAbsoluteValue $_value
85        $_canvas itemconfigure $_tick -state normal
86        $_canvas raise $_tick
87    }
88    public method Hide {} {
89        $_canvas itemconfigure $_tick -state hidden
90    }
91    public method GetScreenPosition { } {
92        set x [GetRelativeValue]
93        if { $x < 0.0 } {
94            set x 0.0
95        } elseif { $x > 1.0 } {
96            set x 1.0
97        }
98        set low 10
99        set w [winfo width $_canvas]
100        set high [expr {$w  - 10}]
101        set x [expr {round($x*($high - $low) + $low)}]
102        return $x
103    }
104    public method SetAbsoluteValue { x } {
105        set _value $x
106        set y 31
107        $_canvas itemconfigure $_label -text [format %.2g $_value]
108        set x [GetScreenPosition]
109        $_canvas coords $_tick $x [expr {$y+3}]
110        $_canvas coords $_label $x [expr {$y+5}]
111    }
112    public method SetRelativeValue { x } {
113        array set limits [$_nvobj GetLimits $_ivol]
114        if { $limits(max) == $limits(min) } {
115            set limits(min) 0.0
116            set limits(max) 1.0
117        }
118        set r [expr $limits(max) - $limits(min)]
119        SetAbsoluteValue [expr {($x * $r) + $limits(min)}]
120    }
121    public method HandleEvent { option args } {
122        switch -- $option {
123            enter {
124                set _active_motion 1
125                Activate yes
126                $_canvas raise $_tick
127            }
128            leave {
129                set _active_motion 0
130                Activate no
131            }
132            start {
133                $_canvas raise $_tick
134                set _active_press 1
135                Activate yes
136                $_canvas itemconfigure limits -state hidden
137            }
138            update {
139                set w [winfo width $_canvas]
140                set x [lindex $args 0]
141                SetRelativeValue [expr {double($x-10)/($w-20)}]
142                $_nvobj OverIsoMarker $this $x
143                $_nvobj UpdateTransferFunctions
144            }
145            end {
146                set x [lindex $args 0]
147                if { ![$_nvobj RemoveDuplicateIsoMarker $this $x]} {
148                    eval HandleEvent update $args
149                }
150                set _active_press 0
151                Activate no
152                $_canvas itemconfigure limits -state normal
153            }
154            default {
155                error "bad option \"$option\": should be start, update, end"
156            }
157        }
158    }
159}
Note: See TracBrowser for help on using the repository browser.