2 # @file bshow_magnify.tcl
4 # @brief Procedures for rendering the magnifying window in Bshow.
6 # @author Bernard Heymann
7 # @date Created: 20010516
8 # @date Modified: 20161102
17 ## @brief Window to show a region magnified.
20 # @param y Coordinates on the canvas.
22 proc Magnify { x y } {
24 global magnification magsize maglock show_cross
26 if ![Bimage exists $theimg] {
27 tk_dialog .dialog "No image in memory!" \
28 {Please read in an appropriate image first.} \
33 set wc [getControlWindow $theimg]
36 if ![winfo exists $w] {
39 set nslices [Bimage get $theimg nslices]
41 frame $w.frame -relief ridge -borderwidth 2 -bg black
46 canvas $m -width 200 -height 200
48 grid $m -in $w.frame -sticky nw -padx 2 -pady 2
49 grid rowconfig $w.frame 0 -weight 1 -minsize 0
50 grid columnconfig $w.frame 0 -weight 1 -minsize 0
52 image create photo theimg0
53 $m create image 0 0 -image theimg0 -anchor nw -tags magimage
59 canvas $m -width 150 -height 150
60 canvas $m1 -width 150 -height 150
61 canvas $m2 -width 150 -height 150
63 grid $m $m1 -in $w.frame -sticky nw -padx 2 -pady 2
64 grid $m2 -in $w.frame -sticky nw -padx 2 -pady 2
65 grid rowconfig $w.frame 0 -weight 1 -minsize 0
66 grid columnconfig $w.frame 0 -weight 1 -minsize 0
68 image create photo theimg0
69 $m create image 0 0 -image theimg0 -anchor nw -tags magimage
70 image create photo theimg1
71 $m1 create image 0 0 -image theimg1 -anchor nw -tags magimage
72 image create photo theimg2
73 $m2 create image 0 0 -image theimg2 -anchor nw -tags magimage
77 label $w.n.x_tag -font $helv12 -text X
78 entry $w.n.x -width 6 -validate key -vcmd { string is double %P }
79 label $w.n.y_tag -font $helv12 -text Y
80 entry $w.n.y -width 6 -validate key -vcmd { string is double %P }
81 checkbutton $w.n.cross -text "Crosses" -variable show_cross
85 label $w.p.size_tag -font $helv12 -text "Size"
86 entry $w.p.size -width 6 -validate key -vcmd { string is double %P }
87 $w.p.size insert 0 $magsize
88 label $w.p.mag_tag -font $helv12 -text "Magnification"
89 entry $w.p.mag -width 6 -validate key -vcmd { string is double %P }
90 $w.p.mag insert 0 $magnification
93 label $w.q.slice_tag -font $helv12 -text "Slice"
94 scale $w.q.slice -from 0 -to [expr [Bimage get $theimg nslices] - 1] -orient horizontal -length 175 \
96 $w.q.slice set [$wc.slice.scale get]
99 label $w.r.range_tag -font $helv12 -text "Range"
100 entry $w.r.range -width 3 -validate key -validatecommand {check_length %P 3}
101 $w.r.range insert 0 5
102 label $w.r.speed_tag -font $helv12 -text "Speed"
103 entry $w.r.speed -width 3 -validate key -validatecommand {check_length %P 3}
104 $w.r.speed insert 0 15
105 button $w.r.animate -text Animate \
106 -relief raised -command animateSlices -font $helv12
107 tk_optionMenu $w.r.axis aniaxis x y z
110 label $w.instr.lock -font $helv12 -text "Press l to lock into xy position"
111 label $w.instr.mag -font $helv12 -text "Press m to decrease magnification"
113 pack $w.n.x_tag $w.n.x $w.n.y_tag $w.n.y $w.n.cross \
114 -side left -ipadx 3 -ipady 2
115 pack $w.p.size_tag $w.p.size $w.p.mag_tag $w.p.mag \
116 -side left -ipadx 3 -ipady 2
117 pack $w.q.slice_tag $w.q.slice \
118 -side left -ipadx 3 -ipady 2
119 pack $w.r.range_tag $w.r.range \
120 $w.r.speed_tag $w.r.speed $w.r.animate \
121 $w.r.axis -side left -ipadx 2 -ipady 2
122 pack $w.q $w.r $w.p $w.n -side bottom -fill x
123 pack $w.instr.lock $w.instr.mag -side left -ipadx 10
124 pack $w.instr $w.frame -side top -fill both -expand yes
127 wm title $w "Magnify"
128 wm iconname $w "Magnify"
133 bind .wmag <Control-w> { destroy .wmag }
134 bind .wmag <Command-w> { destroy .wmag }
135 bind . <Key-l> { set maglock [expr 1 - $maglock] }
137 if { $magnification > 0.1 } { set magnification [expr $magnification / 2.0] }
138 .wmag.p.mag delete 0 end
139 .wmag.p.mag insert 0 $magnification
143 proc drawCross { c lx ly } {
144 $c create line [expr $lx - 5] $ly [expr $lx + 5] $ly -fill yellow -width 1 -tags cross
145 $c create line $lx [expr $ly - 5] $lx [expr $ly + 5] -fill yellow -width 1 -tags cross
148 ## @brief Updates the magnifying window.
151 # @param y Coordinates within the image.
152 # @param currSlice Current slice (defaults to main window's slice unless animating)
153 # @param updatesource Procedure calling update (mouse or slicer)
155 proc updateMagnify { x y currSlice updatesource } {
156 global theimg fom_cutoff
157 global mag3D show_cross project_item
158 global magnification magsize maglock
159 global show_boxes show_bad show_filaments
160 global fom_cutoff show_markers
161 global show_comp show_comp_labels comp_selected line_width
162 global show_box_labels box_color box_select_color bad_color bad_select_color
163 global filament_color filament_first_color filament_select_color
166 if ![winfo exists $w] { return }
167 if { $maglock && $updatesource=="mouse" } { return }
168 if { $x > [Bimage get $theimg width] } { return }
169 if { $y < 0 } { return }
174 set wc [getControlWindow $theimg]
175 set scale [$wc.scale.scale get]
176 set n [$wc.image.scale get]
177 set mg_item [micrographItem $n]
179 if { $currSlice=="default" } {
180 set z [$wc.slice.scale get]
185 set magnification [$w.p.mag get]
186 set magsize [$w.p.size get]
190 set width [expr int($magnification*$sx)]
191 set height [expr int($magnification*$sy)]
192 set nslices [Bimage get $theimg nslices]
194 $w.frame.c delete cross box bad node marker component link
195 $w.frame.c configure -width $width -height $height -scrollregion "0 0 $width $height"
198 if { $nslices > 1 } {
200 $w.frame.c1 delete cross box bad node marker component link
201 $w.frame.c2 delete cross box bad node marker component link
202 $w.frame.c1 configure -width $width -height $height -scrollregion "0 0 $width $height"
203 $w.frame.c2 configure -width $width -height $height -scrollregion "0 0 $width $height"
205 wm minsize $w [expr 2*$width+60] [expr 2*$height+210]
206 Bimage magnify $theimg $n $x $y $z $magnification $sx $sy $sz
207 # puts "Mag image extracted"
209 set lx [expr $width/2]
210 set ly [expr $height/2]
212 drawCross $w.frame.c $lx $ly
214 drawCross $w.frame.c1 $lx $ly
215 drawCross $w.frame.c2 $lx $ly
218 if { $maglock==0 || $updatesource=="slicer" } {
225 if [winfo exists .wbox] {
227 set ids [Bmg box $mg_item ids $fom_cutoff]
229 drawMagBox $id $x $y $z
233 set ids [Bmg box $mg_item ids bad]
235 drawMagBox $id $x $y $z
240 if [winfo exists .wfil] {
241 if { $show_filaments } {
242 set rad [.wfil.node_radius.entry get]
243 set ids [Bmg node $mg_item ids]
246 foreach {fid nid} $ids {
247 set loc [Bmg node $mg_item location $fid $nid]
248 if { $pfid == $fid } {
249 set color $filament_color
251 set color $filament_first_color
253 drawMagSphere [lindex $loc 0] [lindex $loc 1] [lindex $loc 2] \
254 $x $y $z $rad $color $line_width $nid node
255 if { $pfid == $fid } {
256 drawMagLine [lindex $loc 0] [lindex $loc 1] [lindex $loc 2] \
257 [lindex $ploc 0] [lindex $ploc 1] [lindex $ploc 2] \
258 $x $y $z 1 $filament_color link
267 if [winfo exists .wtomo] {
268 if { $show_markers } {
269 set ids [Bmg marker $mg_item ids $fom_cutoff]
271 drawMagMarker $id $x $y $z
276 if [winfo exists .wmod] {
278 set comps [Bmodel component $project_item img_coords $fom_cutoff]
279 if { $show_comp_labels } {
280 foreach {id cx cy cz rad color} $comps {
281 drawMagSphere $cx $cy $cz $x $y $z $rad $color $line_width $id component
284 foreach {id cx cy cz rad color} $comps {
285 drawMagSphere $cx $cy $cz $x $y $z $rad $color $line_width "" component
288 set links [Bmodel link $project_item img_coords $fom_cutoff]
289 foreach {x1 y1 z1 x2 y2 z2 rad color} $links {
290 drawMagLine $x1 $y1 $z1 $x2 $y2 $z2 $x $y $z $rad $color link
297 ## @brief Draws a box in the magnification window.
299 # @param id Box identifier.
301 # @param pty Coordinates within the image.
302 # @param ptz Current slice (defaults to main window's slice unless animating)
304 proc drawMagBox { id ptx pty ptz } {
308 if ![winfo exists $w] { return }
311 if ![winfo exists $wb] { return }
314 global show_box_labels box_color box_select_color bad_color bad_select_color
316 set wc [getControlWindow $theimg]
318 set magnification [$w.p.mag get]
319 set magsize [$w.p.size get]
320 set slice_num [$wc.slice.scale get]
321 set h [Bimage get $theimg height]
322 set n [$wc.image.scale get]
323 set mg_item [micrographItem $n]
324 set loc [Bmg box $mg_item location $id]
325 set x [lindex $loc 0]
326 # set y [expr ($h - [lindex $loc 1] - 1) ]
327 set y [yFlip [lindex $loc 1]]
328 set z [lindex $loc 2]
331 set xrad [expr [$wb.box_size.x get]*0.5]
332 set yrad [expr [$wb.box_size.y get]*0.5]
333 set zrad [expr [$wb.box_size.z get]*0.5]
335 set xrad [expr [$wb.bad_radius.e get]*1.0]
340 set pty [expr $h - $pty]
341 set nslices [Bimage get $theimg nslices]
343 set xr [expr abs($ptx - $x)]
344 set yr [expr abs($pty - $y)]
345 set zr [expr abs($ptz - $z)]
347 set xdiff [expr ($ptx - $x)*$magnification]
348 set ydiff [expr ($pty - $y)*$magnification]
349 set zdiff [expr ($ptz - $z)*$magnification]
351 set lx [expr $magnification*$magsize/2]
352 set ly [expr $magnification*$magsize/2]
354 set idtag [format "box%d" $id]
356 if { $zr <= $zrad } {
358 if { $zrad > 0 } { set fac [expr sqrt(1-(($zr*$zr)/($zrad*$zrad)))] }
359 set xy_x_radius [expr $magnification * $xrad * $fac]
360 set xy_y_radius [expr $magnification * $yrad * $fac]
361 set xmin [expr ($lx-$xdiff-$xrad*$magnification)]
362 set xmax [expr ($lx-$xdiff+$xrad*$magnification) + $magnification - 1]
363 set ymin [expr ($ly-$ydiff-$yrad*$magnification)]
364 set ymax [expr ($ly-$ydiff+$yrad*$magnification) + $magnification - 1]
365 set cxmin [expr ($lx-$xdiff-$xy_x_radius)]
366 set cxmax [expr ($lx-$xdiff+$xy_x_radius) + $magnification - 1]
367 set cymin [expr ($ly-$ydiff-$xy_y_radius)]
368 set cymax [expr ($ly-$ydiff+$xy_y_radius) + $magnification - 1]
370 $w.frame.c create oval $cxmin $cymin $cxmax $cymax -outline $box_color -width 1 -tags [list box $idtag]
371 $w.frame.c create rect $xmin $ymin $xmax $ymax -outline $box_color -width 1 -tags [list box $idtag]
372 if { $show_box_labels } {
373 $w.frame.c create text [expr $lx-$xdiff] [expr $ly-$ydiff] -text $id -fill $box_color -tags [list box $idtag]
376 $w.frame.c create oval $cxmin $cymin $cxmax $cymax -outline $bad_color -width 1 -tags bad
380 if { $nslices > 1 } {
381 if { [expr $xrad*$xrad-$xr*$xr] >= 0 } {
382 set yz_z_radius [expr $magnification * $zrad * sqrt(1-(($xr*$xr)/($xrad*$xrad)))]
383 set yz_y_radius [expr $magnification * $yrad * sqrt(1-(($xr*$xr)/($xrad*$xrad)))]
384 set xmin [expr ($lx-$zdiff-$zrad*$magnification)]
385 set xmax [expr ($lx-$zdiff+$zrad*$magnification) + $magnification - 1]
386 set ymin [expr ($ly-$ydiff-$yrad*$magnification)]
387 set ymax [expr ($ly-$ydiff+$yrad*$magnification) + $magnification - 1]
388 set cxmin [expr ($lx-$zdiff-$yz_z_radius)]
389 set cxmax [expr ($lx-$zdiff+$yz_z_radius) + $magnification - 1]
390 set cymin [expr ($ly-$ydiff-$yz_y_radius)]
391 set cymax [expr ($ly-$ydiff+$yz_y_radius) + $magnification - 1]
393 $w.frame.c1 create oval $cxmin $cymin $cxmax $cymax -outline $box_color -width 1 -tags [list box $idtag]
394 $w.frame.c1 create rect $xmin $ymin $xmax $ymax -outline $box_color -width 1 -tags [list box $idtag]
395 if { $show_box_labels } {
396 $w.frame.c1 create text [expr $lx-$zdiff] [expr $ly-$ydiff] -text $id -fill $box_color -tags [list box $idtag]
399 $w.frame.c1 create oval $cxmin $cymin $cxmax $cymax -outline $bad_color -width 1 -tags bad
403 if { [expr $yrad*$yrad-$yr*$yr] >= 0 } {
404 set xz_x_radius [expr $magnification * $xrad * sqrt(1-(($yr*$yr)/($yrad*$yrad)))]
405 set xz_z_radius [expr $magnification * $zrad * sqrt(1-(($yr*$yr)/($yrad*$yrad)))]
406 set xmin [expr ($lx-$xdiff-$xrad*$magnification)]
407 set xmax [expr ($lx-$xdiff+$xrad*$magnification) + $magnification - 1]
408 set ymin [expr ($ly+$zdiff-$zrad*$magnification)]
409 set ymax [expr ($ly+$zdiff+$zrad*$magnification) + $magnification - 1]
410 set cxmin [expr ($lx-$xdiff-$xz_x_radius)]
411 set cxmax [expr ($lx-$xdiff+$xz_x_radius) + $magnification - 1]
412 set cymin [expr ($ly+$zdiff-$xz_z_radius)]
413 set cymax [expr ($ly+$zdiff+$xz_z_radius) + $magnification - 1]
415 $w.frame.c2 create oval $cxmin $cymin $cxmax $cymax -outline $box_color -width 1 -tags [list box $idtag]
416 $w.frame.c2 create rect $xmin $ymin $xmax $ymax -outline $box_color -width 1 -tags [list box $idtag]
417 if { $show_box_labels } {
418 $w.frame.c2 create text [expr $lx-$xdiff] [expr $ly+$zdiff] -text $id -fill $box_color -tags [list box $idtag]
421 $w.frame.c2 create oval $cxmin $cymin $cxmax $cymax -outline $bad_color -width 1 -tags bad
427 ## @brief Draws a marker in the magnification window.
429 # @param id Marker identifier.
431 # @param pty Coordinates within the image.
432 # @param ptz Current slice (defaults to main window's slice unless animating)
434 proc drawMagMarker { id ptx pty ptz } {
438 if ![winfo exists $w] { return }
439 global project_item markers_selected marker_radius
440 global show_marker_errors show_marker_labels
441 global marker_color marker_select_color error_color error_select_color
443 set wc [getControlWindow $theimg]
445 set magnification [$w.p.mag get]
446 set magsize [$w.p.size get]
447 set slice_num [$wc.slice.scale get]
448 set h [Bimage get $theimg height]
449 set n [$wc.image.scale get]
450 set mg_item [micrographItem $n]
451 set locerr [Bmg marker $mg_item location $id]
452 set x [lindex $locerr 0]
453 set y [expr ($h - [lindex $locerr 1] - 1) ]
454 set z [lindex $locerr 2]
455 set ex [expr $x + [lindex $locerr 3] ]
456 set ey [expr $y - [lindex $locerr 4] ]
457 set ez [expr $z + [lindex $locerr 5]]
459 set idtag [format "m%d" $id]
461 set pty [expr $h - $pty]
462 set nslices [Bimage get $theimg nslices]
464 set xr [expr $ptx - $x]
465 set yr [expr $pty - $y]
466 set zr [expr $ptz - $z]
468 set xdiff [expr $xr*$magnification]
469 set ydiff [expr $yr*$magnification]
470 set zdiff [expr $zr*$magnification]
471 set exdiff [expr ($ptx - $ex)*$magnification]
472 set eydiff [expr ($pty - $ey)*$magnification]
475 set ezdiff [expr ($ptz - $ez)*$magnification]
480 set lx [expr $magnification*$magsize/2]
481 set ly [expr $magnification*$magsize/2]
483 # set rad [expr $marker_radius*$magnification]
484 set rad [expr $marker_radius]
485 set rad2 [expr $rad*$rad]
487 if { [lsearch $markers_selected $id] >= 0 } {
488 set markcolorshow $marker_select_color;
489 set errcolorshow $error_select_color;
491 set markcolorshow $marker_color;
492 set errcolorshow $error_color;
495 if { [expr $rad2-$zr*$zr] >= 0 } {
496 set xy_radius [expr $magnification*sqrt($rad2-$zr*$zr)]
497 set xmin [expr ($lx-$xdiff-$xy_radius)]
498 set xmax [expr ($lx-$xdiff+$xy_radius) + $magnification - 1]
499 set ymin [expr ($ly-$ydiff-$xy_radius)]
500 set ymax [expr ($ly-$ydiff+$xy_radius) + $magnification - 1]
501 $w.frame.c create oval $xmin $ymin $xmax $ymax -outline $markcolorshow -width 1 -tags marker
502 if { $show_marker_labels } {
503 $w.frame.c create text [expr $lx-$xdiff+$rad*$magnification+10] [expr $ly-$ydiff] -text $id -fill $markcolorshow -tags [list marker $idtag]
505 if { $show_marker_errors } {
506 $w.frame.c create line [expr $lx-$xdiff] [expr $ly-$ydiff] [expr $lx-$exdiff] [expr $ly-$eydiff] -fill $errcolorshow -width 2 -tags [list marker $idtag]
510 if { $nslices > 1 } {
511 if { [expr $rad2-$xr*$xr] >= 0 } {
512 set yz_radius [expr $magnification*sqrt($rad2-$xr*$xr)]
513 set xmin [expr ($lx-$zdiff-$yz_radius)]
514 set xmax [expr ($lx-$zdiff+$yz_radius) + $magnification - 1]
515 set ymin [expr ($ly-$ydiff-$yz_radius)]
516 set ymax [expr ($ly-$ydiff+$yz_radius) + $magnification - 1]
517 $w.frame.c1 create oval $xmin $ymin $xmax $ymax -outline $markcolorshow -width 1 -tags marker
518 if { $show_marker_labels } {
519 $w.frame.c1 create text [expr $lx-$zdiff+$rad*$magnification+10] [expr $ly-$ydiff] -text $id -fill $markcolorshow -tags [list marker $idtag]
521 if { $show_marker_errors } {
522 $w.frame.c1 create line [expr $lx-$zdiff] [expr $ly-$ydiff] [expr $lx-$ezdiff] [expr $ly-$eydiff] -fill $errcolorshow -width 2 -tags [list marker $idtag]
526 if { [expr $rad2-$yr*$yr] >= 0 } {
527 set xz_radius [expr $magnification*sqrt($rad2-$yr*$yr)]
528 set xmin [expr ($lx-$xdiff-$xz_radius)]
529 set xmax [expr ($lx-$xdiff+$xz_radius) + $magnification - 1]
530 set ymin [expr ($ly+$zdiff-$xz_radius)]
531 set ymax [expr ($ly+$zdiff+$xz_radius) + $magnification - 1]
532 $w.frame.c2 create oval $xmin $ymin $xmax $ymax -outline $markcolorshow -width 1 -tags marker
533 if { $show_marker_labels } {
534 $w.frame.c2 create text [expr $lx-$xdiff+$rad*$magnification+10] [expr $ly+$zdiff] -text $id -fill $markcolorshow -tags [list marker $idtag]
536 if { $show_marker_errors } {
537 $w.frame.c2 create line [expr $lx-$xdiff] [expr $ly+$zdiff] [expr $lx-$exdiff] [expr $ly+$ezdiff] -fill $errcolorshow -width 2 -tags [list marker $idtag]
543 proc drawMagSphere { x y z ptx pty ptz rad col width lbl tag } {
547 if ![winfo exists $w] { return }
553 set magnification [$w.p.mag get]
554 set magsize [$w.p.size get]
556 set rm [expr $rad * $magnification]
557 if { $rm < 1 } { set rm 1 }
559 set lx [expr 0.5 * $magnification * $magsize]
562 set max [expr $lx + $rm]
563 set m2 [expr $lx * $lx]
565 set xr [expr ($ptx - $x)*$magnification]
566 set yr [expr ($y - $pty)*$magnification]
567 set zr [expr ($ptz - $z)*$magnification]
569 # Test if within the magnification window
570 set xr2 [expr $xr*$xr]
571 if { $xr2 > $m2 } { return }
573 set yr2 [expr $yr*$yr]
574 if { $yr2 > $m2 } { return }
576 set zr2 [expr $zr*$zr]
577 if { $zr2 > $m2 } { return }
579 set xxd [expr $lx - $xr]
580 set yyd [expr $ly - $yr]
582 set mag_1 [expr $magnification - 1]
584 set rm2 [expr $rm*$rm]
586 set dz2 [expr $rm2 - $zr2]
589 set xy_radius [expr sqrt($dz2)]
590 set xmin [expr $xxd - $xy_radius]
591 set xmax [expr $xxd + $xy_radius + $mag_1]
592 set ymin [expr $yyd - $xy_radius]
593 set ymax [expr $yyd + $xy_radius + $mag_1]
594 $c create oval $xmin $ymin $xmax $ymax -outline $col -width $width -tags $tag
595 if { [string length $lbl] } {
596 $c create text $xmax $ymax -text $lbl -fill $col -anchor w -tags $tag
601 set xzd [expr $lx - $zr]
602 set yzd [expr $ly + $zr]
603 set dx2 [expr $rm2 - $xr2]
605 set yz_radius [expr sqrt($dx2)]
606 set xmin [expr $xzd - $yz_radius]
607 set xmax [expr $xzd + $yz_radius + $mag_1]
608 set ymin [expr $yyd - $yz_radius]
609 set ymax [expr $yyd + $yz_radius + $mag_1]
610 $c1 create oval $xmin $ymin $xmax $ymax -outline $col -width $width -tags $tag
611 if { [string length $lbl] } {
612 $c1 create text $xmax $ymax -text $lbl -fill $col -anchor w -tags $tag
616 set dy2 [expr $rm2 - $yr2]
618 set xz_radius [expr sqrt($dy2)]
619 set xmin [expr $xxd - $xz_radius]
620 set xmax [expr $xxd + $xz_radius + $mag_1]
621 set ymin [expr $yzd - $xz_radius]
622 set ymax [expr $yzd + $xz_radius + $mag_1]
623 $c2 create oval $xmin $ymin $xmax $ymax -outline $col -width $width -tags $tag
624 if { [string length $lbl] } {
625 $c2 create text $xmax $ymax -text $lbl -fill $col -anchor w -tags $tag
631 proc drawMagLine { xs ys zs xe ye ze ptx pty ptz width col tag } {
633 if ![winfo exists $w] { return }
639 set magnification [$w.p.mag get]
640 set magsize [$w.p.size get]
642 set width [expr int($width * $magnification)]
643 if { $width < 1 } { set width 1 }
645 set xsr [expr $ptx - $xs]
646 set ysr [expr $ys - $pty]
647 set zsr [expr $ptz - $zs]
648 set xer [expr $ptx - $xe]
649 set yer [expr $ye - $pty]
650 set zer [expr $ptz - $ze]
652 set xsdiff [expr $xsr*$magnification]
653 set ysdiff [expr $ysr*$magnification]
654 set zsdiff [expr $zsr*$magnification]
655 set xediff [expr $xer*$magnification]
656 set yediff [expr $yer*$magnification]
657 set zediff [expr $zer*$magnification]
659 set magdim [expr $magnification*$magsize]
660 set lx [expr $magdim * 0.5]
661 set ly [expr $magdim * 0.5]
664 if { $zer != $zsr } {
665 set z [expr $zsr / (1.0*($ze - $zs))]
667 if { abs($zsr) < 0.5 } { set z 0.5 }
670 set xmin [expr $lx - $xsdiff]
671 set xmax [expr $lx - $xediff]
672 set ymin [expr $ly - $ysdiff]
673 set ymax [expr $ly - $yediff]
674 if { $xmin == $xmax && $ymin == $ymax } { set ymax [expr $ymax + 1] }
676 if { $z >= 0.0 && $z <= 1.0 } {
677 $c create line $xmin $ymin $xmax $ymax -fill $col -smooth yes -width $width -tags $tag
683 set x [expr $xsr / (1.0*($xe - $xs))]
685 if { abs($xsr) < 0.5 } { set x 0.5 }
688 set zmin [expr $ly - $zsdiff]
689 set zmax [expr $ly - $zediff]
690 if { $x >= 0.0 && $x <= 1.0 } {
691 if { $zmin == $zmax && $ymin == $ymax } { set ymax [expr $ymax + 1] }
692 $c1 create line $zmin $ymin $zmax $ymax -fill $col -smooth yes -width $width -tags $tag
697 set y [expr $ysr / (1.0*($ys - $ye))]
699 if { abs($ysr) < 0.5 } { set y 0.5 }
702 set zmin [expr $magdim - $zmin]
703 set zmax [expr $magdim - $zmax]
704 if { $y >= 0.0 && $y <= 1.0 } {
705 if { $xmin == $xmax && $zmin == $zmax } { set zmax [expr $zmax + 1] }
706 $c2 create line $xmin $zmin $xmax $zmax -fill $col -smooth yes -width $width -tags $tag
711 proc changeSlice { deltaslice } {
712 global maglock theimg
716 if { $maglock == 1 } {
717 updateMagnify [$w.n.x get] [$w.n.y get] $deltaslice slicer
719 set wc [getControlWindow $theimg]
720 $wc.slice.scale set [$w.q.slice get]
724 proc updateSlicer { aniaxis anidirection } {
729 set z [$w.q.slice get]
730 if { $aniaxis == "x" } {
731 if { $anidirection == 1 } { updateMagnify [expr $x + 1] $y $z slicer }
732 if { $anidirection == 0 } { updateMagnify [expr $x - 1] $y $z slicer }
734 if { $aniaxis == "y" } {
735 if { $anidirection == 1 } { updateMagnify $x [expr $y + 1] $z slicer }
736 if { $anidirection == 0 } { updateMagnify $x [expr $y - 1] $z slicer }
738 if { $aniaxis == "z" } {
739 if { $anidirection == 1 } {$w.q.slice set [expr [$w.q.slice get] + 1] }
740 if { $anidirection == 0 } {$w.q.slice set [expr [$w.q.slice get] - 1] }
744 proc animateSlices {} {
751 if ![winfo exists $w] { return }
752 if { $aniaxis=="x" } {
753 set anisource "$w.n.x"
754 set lim [expr [Bimage get $theimg width] - 1]
756 if { $aniaxis=="y" } {
757 set anisource "$w.n.y"
758 set lim [expr [Bimage get $theimg height] - 1]
760 if { $aniaxis=="z" } {
761 set anisource "$w.q.slice"
762 set lim [expr [Bimage get $theimg nslices] - 1]
764 set aniceiling [expr [$anisource get] + [$w.r.range get]]
765 set anifloor [expr [$anisource get] - [$w.r.range get]]
766 if { $aniceiling > $lim } { set aniceiling $lim }
767 if { $anifloor < 0 } { set anifloor 0 }
769 set speed [$w.r.speed get]
770 if { $speed == "" || $speed < 0 } {
773 if { $speed > 200 } {
776 $w.r.speed delete 0 end
777 $w.r.speed insert 0 $speed
779 if { $aniproc2 == 0 } {
780 $w.r.animate configure -text "Stop"
781 $w.r.axis configure -state disabled
782 $w.r.range configure -state disabled
783 $w.r.speed configure -state disabled
786 $w.r.animate configure -text "Animate"
787 $w.r.axis configure -state normal
788 $w.r.range configure -state normal
789 $w.r.speed configure -state normal
793 while { [winfo exists $w] && $aniproc2 == 1 } {
794 set slice [$anisource get]
795 if { $slice == $aniceiling } {
798 if { $slice == $anifloor } {
801 after [expr 1000/[$w.r.speed get]]
802 updateSlicer $aniaxis $anidirection
807 proc check_length {newstring max_length} {
808 return [expr {[string length $newstring] <= $max_length}]