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

Last change on this file since 1555 was 1479, checked in by gah, 15 years ago
File size: 4.6 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::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 tf_        "";     # 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 tf args} {
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 \
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 transferfunc {} {
57        return $tf_
58    }
59    public method activate { bool } {
60        if  { $bool || $active_press_ || $active_motion_ } {
61            $canvas_ itemconfigure $label_ -state normal
62            $canvas_ itemconfigure $tick_ -image $activeIcon_
63        } else {
64            $canvas_ itemconfigure $label_ -state hidden
65            $canvas_ itemconfigure $tick_ -image $normalIcon_
66        }
67    }
68    public method visible { bool } {
69        if { $bool } {
70            absval $value_
71            $canvas_ itemconfigure $tick_ -state normal
72            $canvas_ raise $tick_
73        } else {
74            $canvas_ itemconfigure $tick_ -state hidden
75        }
76    }
77    public method screenpos { } {
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
85        set w [winfo width $canvas_]
86        set high [expr {$w  - 10}]
87        set x [expr {round($x*($high - $low) + $low)}]
88        return $x
89    }
90    public method absval { {x "-get"} } {
91        if { $x != "-get" } {
92            set value_ $x
93            set y 31
94            $canvas_ itemconfigure $label_ -text [format %.2g $value_]
95            set x [screenpos]
96            $canvas_ coords $tick_ $x [expr {$y+3}]
97            $canvas_ coords $label_ $x [expr {$y+5}]
98        }
99        return $value_
100    }
101    public method relval  { {x "-get"} } {
102        if { $x == "-get" } {
103            array set limits [$nvobj_ limits $tf_]
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            }
112            return [expr {($value_-$limits(vmin))/
113                          ($limits(vmax) - $limits(vmin))}]
114        }
115        array set limits [$nvobj_ limits $tf_]
116        if { $limits(vmax) == $limits(vmin) } {
117            set limits(min) 0.0
118            set limits(max) 1.0
119        }
120        set r [expr $limits(vmax) - $limits(vmin)]
121        absval [expr {($x * $r) + $limits(vmin)}]
122    }
123    private method HandleEvent { option args } {
124        switch -- $option {
125            enter {
126                set active_motion_ 1
127                activate yes
128                $canvas_ raise $tick_
129            }
130            leave {
131                set active_motion_ 0
132                activate no
133            }
134            start {
135                $canvas_ raise $tick_
136                set active_press_ 1
137                activate yes
138                $canvas_ itemconfigure limits -state hidden
139            }
140            update {
141                set w [winfo width $canvas_]
142                set x [lindex $args 0]
143                relval [expr {double($x-10)/($w-20)}]
144                $nvobj_ overmarker $this $x
145                $nvobj_ updatetransferfuncs
146            }
147            end {
148                set x [lindex $args 0]
149                if { ![$nvobj_ rmdupmarker $this $x]} {
150                    eval HandleEvent update $args
151                }
152                set active_press_ 0
153                activate no
154                $canvas_ itemconfigure limits -state normal
155            }
156            default {
157                error "bad option \"$option\": should be start, update, end"
158            }
159        }
160    }
161}
Note: See TracBrowser for help on using the repository browser.