Changeset 136
- Timestamp:
- Nov 11, 2005, 10:50:56 PM (19 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/zoo/field/tool.xml
r112 r136 45 45 <about><label>3D Field</label></about> 46 46 <component> 47 <style>-color yellow</style> 47 48 <mesh>output.mesh(m3d)</mesh> 48 49 <values></values> -
trunk/gui/scripts/contourresult.tcl
r115 r136 70 70 option add *ContourResult.controlBackground gray widgetDefault 71 71 option add *ContourResult.controlDarkBackground #999999 widgetDefault 72 option add *ContourResult.plotBackground black widgetDefault 73 option add *ContourResult.plotForeground white widgetDefault 72 74 option add *ContourResult.font \ 73 75 -*-helvetica-medium-r-normal-*-*-120-* widgetDefault … … 76 78 inherit itk::Widget 77 79 78 itk_option define - foreground foreground Foreground ""79 itk_option define - background background Background ""80 itk_option define -plotforeground plotForeground Foreground "" 81 itk_option define -plotbackground plotBackground Background "" 80 82 81 83 constructor {args} { # defined below } … … 95 97 protected method _3dView {theta phi} 96 98 protected method _fixLimits {} 99 protected method _slicertip {axis} 97 100 protected method _color2rgb {color} 98 101 … … 109 112 private variable _limits ;# autoscale min/max for all axes 110 113 private variable _view ;# view params for 3D view 111 112 private common _counter 0 ;# used for auto-generated names113 114 } 114 115 115 116 itk::usual ContourResult { 116 117 keep -background -foreground -cursor -font 118 keep -plotbackground -plotforeground 117 119 } 118 120 … … 124 126 pack propagate $itk_component(hull) no 125 127 126 set _slicer(axis) "" 127 set _slicer(plane) "" 128 set _slicer(xplane) "" 129 set _slicer(yplane) "" 130 set _slicer(zplane) "" 131 set _slicer(xslice) "" 132 set _slicer(yslice) "" 133 set _slicer(zslice) "" 128 134 set _slicer(readout) "" 129 135 set _view(theta) 0 … … 138 144 pack $itk_component(controls) -side right -fill y 139 145 146 itk_component add zoom { 147 frame $itk_component(controls).zoom 148 } { 149 usual 150 rename -background -controlbackground controlBackground Background 151 } 152 pack $itk_component(zoom) -side top 153 140 154 itk_component add reset { 141 button $itk_component( controls).reset \155 button $itk_component(zoom).reset \ 142 156 -borderwidth 1 -padx 1 -pady 1 \ 143 157 -bitmap ContourResult-reset \ … … 152 166 153 167 itk_component add zoomin { 154 button $itk_component( controls).zin \168 button $itk_component(zoom).zin \ 155 169 -borderwidth 1 -padx 1 -pady 1 \ 156 170 -bitmap ContourResult-zoomin \ … … 165 179 166 180 itk_component add zoomout { 167 button $itk_component( controls).zout \181 button $itk_component(zoom).zout \ 168 182 -borderwidth 1 -padx 1 -pady 1 \ 169 183 -bitmap ContourResult-zoomout \ … … 177 191 Rappture::Tooltip::for $itk_component(zoomout) "Zoom out" 178 192 193 # 194 # Create slicer controls... 195 # 196 itk_component add slicers { 197 frame $itk_component(controls).slicers 198 } { 199 usual 200 rename -background -controlbackground controlBackground Background 201 } 202 pack $itk_component(slicers) -side bottom -padx 4 -pady 4 203 grid rowconfigure $itk_component(slicers) 1 -weight 1 204 205 # 206 # X-value slicer... 207 # 179 208 itk_component add xslice { 180 label $itk_component( controls).xslice \209 label $itk_component(slicers).xslice \ 181 210 -borderwidth 1 -relief raised -padx 1 -pady 1 \ 182 211 -bitmap ContourResult-xslice … … 187 216 } 188 217 bind $itk_component(xslice) <ButtonPress> \ 189 [itcl::code $this _slice axis x] 190 Rappture::Tooltip::for $itk_component(xslice) "Slice along x-axis" 191 192 itk_component add yslice { 193 label $itk_component(controls).yslice \ 194 -borderwidth 1 -relief raised -padx 1 -pady 1 \ 195 -bitmap ContourResult-yslice 196 } { 197 usual 198 ignore -borderwidth 199 rename -highlightbackground -controlbackground controlBackground Background 200 } 201 bind $itk_component(yslice) <ButtonPress> \ 202 [itcl::code $this _slice axis y] 203 Rappture::Tooltip::for $itk_component(yslice) "Slice along y-axis" 204 205 itk_component add zslice { 206 label $itk_component(controls).zslice \ 207 -borderwidth 1 -relief raised -padx 1 -pady 1 \ 208 -bitmap ContourResult-zslice 209 } { 210 usual 211 ignore -borderwidth 212 rename -highlightbackground -controlbackground controlBackground Background 213 } 214 bind $itk_component(zslice) <ButtonPress> \ 215 [itcl::code $this _slice axis z] 216 Rappture::Tooltip::for $itk_component(zslice) "Slice along z-axis" 217 218 itk_component add slicer { 219 ::scale $itk_component(controls).slicer -from 100 -to 0 \ 220 -width 10 -orient vertical -showvalue off \ 218 [itcl::code $this _slice axis x toggle] 219 Rappture::Tooltip::for $itk_component(xslice) \ 220 "Toggle the X cut plane on/off" 221 grid $itk_component(xslice) -row 0 -column 0 -sticky ew -padx 1 222 223 itk_component add xslicer { 224 ::scale $itk_component(slicers).xval -from 100 -to 0 \ 225 -width 10 -orient vertical -showvalue off -state disabled \ 221 226 -borderwidth 1 -highlightthickness 0 \ 222 -command [itcl::code $this _slice move ]227 -command [itcl::code $this _slice move x] 223 228 } { 224 229 usual … … 228 233 rename -troughcolor -controldarkbackground controlDarkBackground Background 229 234 } 230 pack $itk_component(slicer) -side bottom -padx 4 -pady 4 231 Rappture::Tooltip::for $itk_component(slicer) "Move the cut plane" 235 grid $itk_component(xslicer) -row 1 -column 0 -padx 1 236 Rappture::Tooltip::for $itk_component(xslicer) \ 237 "@[itcl::code $this _slicertip x]" 238 239 # 240 # Y-value slicer... 241 # 242 itk_component add yslice { 243 label $itk_component(slicers).yslice \ 244 -borderwidth 1 -relief raised -padx 1 -pady 1 \ 245 -bitmap ContourResult-yslice 246 } { 247 usual 248 ignore -borderwidth 249 rename -highlightbackground -controlbackground controlBackground Background 250 } 251 bind $itk_component(yslice) <ButtonPress> \ 252 [itcl::code $this _slice axis y toggle] 253 Rappture::Tooltip::for $itk_component(yslice) \ 254 "Toggle the Y cut plane on/off" 255 grid $itk_component(yslice) -row 0 -column 1 -sticky ew -padx 1 256 257 itk_component add yslicer { 258 ::scale $itk_component(slicers).yval -from 100 -to 0 \ 259 -width 10 -orient vertical -showvalue off -state disabled \ 260 -borderwidth 1 -highlightthickness 0 \ 261 -command [itcl::code $this _slice move y] 262 } { 263 usual 264 ignore -borderwidth 265 ignore -highlightthickness 266 rename -highlightbackground -controlbackground controlBackground Background 267 rename -troughcolor -controldarkbackground controlDarkBackground Background 268 } 269 grid $itk_component(yslicer) -row 1 -column 1 -padx 1 270 Rappture::Tooltip::for $itk_component(yslicer) \ 271 "@[itcl::code $this _slicertip y]" 272 273 # 274 # Z-value slicer... 275 # 276 itk_component add zslice { 277 label $itk_component(slicers).zslice \ 278 -borderwidth 1 -relief raised -padx 1 -pady 1 \ 279 -bitmap ContourResult-zslice 280 } { 281 usual 282 ignore -borderwidth 283 rename -highlightbackground -controlbackground controlBackground Background 284 } 285 grid $itk_component(zslice) -row 0 -column 2 -sticky ew -padx 1 286 bind $itk_component(zslice) <ButtonPress> \ 287 [itcl::code $this _slice axis z toggle] 288 Rappture::Tooltip::for $itk_component(zslice) \ 289 "Toggle the Z cut plane on/off" 290 291 itk_component add zslicer { 292 ::scale $itk_component(slicers).zval -from 100 -to 0 \ 293 -width 10 -orient vertical -showvalue off -state disabled \ 294 -borderwidth 1 -highlightthickness 0 \ 295 -command [itcl::code $this _slice move z] 296 } { 297 usual 298 ignore -borderwidth 299 ignore -highlightthickness 300 rename -highlightbackground -controlbackground controlBackground Background 301 rename -troughcolor -controldarkbackground controlDarkBackground Background 302 } 303 grid $itk_component(zslicer) -row 1 -column 2 -padx 1 304 Rappture::Tooltip::for $itk_component(zslicer) \ 305 "@[itcl::code $this _slicertip z]" 232 306 233 307 # … … 242 316 vtkRenderWindow $this-renWin 243 317 $this-renWin AddRenderer $this-ren 318 $this-renWin LineSmoothingOn 319 $this-renWin PolygonSmoothingOn 244 320 vtkRenderWindowInteractor $this-iren 245 321 $this-iren SetRenderWindow $this-renWin … … 430 506 itcl::body Rappture::ContourResult::_rebuild {} { 431 507 _clear 508 set id 0 432 509 433 510 # determine the dimensionality from the topmost (raised) object … … 435 512 set dataobj [lindex $dlist end] 436 513 if {$dataobj != ""} { 437 set _dims [ $dataobj components -dimensions]514 set _dims [lindex [lsort [$dataobj components -dimensions]] end] 438 515 } else { 439 516 set _dims "0D" 440 517 } 441 518 519 # 520 # LOOKUP TABLE FOR COLOR CONTOURS 521 # 522 # use vmin/vmax if possible, otherwise get from data 523 if {$_limits(vmin) == "" || $_limits(vmax) == ""} { 524 foreach {v0 v1} [$pd GetScalarRange] break 525 } else { 526 set v0 $_limits(vmin) 527 set v1 $_limits(vmax) 528 } 529 530 set lu $this-lookup$id 531 vtkLookupTable $lu 532 $lu SetTableRange $v0 $v1 533 $lu SetHueRange 0.66667 0.0 534 $lu Build 535 536 lappend _obj2vtk($dataobj) $lu 537 538 if {$_dims == "3D"} { 539 # 540 # 3D LIGHTS (on both sides of all three axes) 541 # 542 set x0 $_limits(xmin) 543 set x1 $_limits(xmax) 544 set xm [expr {0.5*($x0+$x1)}] 545 set y0 $_limits(ymin) 546 set y1 $_limits(ymax) 547 set ym [expr {0.5*($y0+$y1)}] 548 set z0 $_limits(zmin) 549 set z1 $_limits(zmax) 550 set zm [expr {0.5*($z0+$z1)}] 551 set xr [expr {$x1-$x0}] 552 set yr [expr {$y1-$y0}] 553 set zr [expr {$z1-$z0}] 554 555 set lt $this-light$id 556 vtkLight $lt 557 $lt SetColor 1 1 1 558 $lt SetAttenuationValues 0 0 0 559 $lt SetFocalPoint $xm $ym $zm 560 $lt SetLightTypeToHeadlight 561 $this-ren AddLight $lt 562 lappend _lights($this-ren) $lt 563 564 } else { 565 } 566 442 567 # scan through all data objects and build the contours 443 set _counter 0568 set firstobj 1 444 569 foreach dataobj [get] { 445 570 foreach comp [$dataobj components] { 446 571 # 447 # LOOKUP TABLE FOR COLOR CONTOURS448 #449 # use vmin/vmax if possible, otherwise get from data450 if {$_limits(vmin) == "" || $_limits(vmax) == ""} {451 foreach {v0 v1} [$pd GetScalarRange] break452 } else {453 set v0 $_limits(vmin)454 set v1 $_limits(vmax)455 }456 457 set lu $this-lookup$_counter458 vtkLookupTable $lu459 $lu SetTableRange $v0 $v1460 $lu SetHueRange 0.66667 0.0461 $lu Build462 463 lappend _obj2vtk($dataobj) $lu464 465 #466 572 # Add color contours. 467 573 # 468 if {$ _counter == 0} {574 if {$firstobj} { 469 575 if {$_dims == "3D"} { 470 pack $itk_component(slicer) -side bottom -padx 4 -pady 4 471 pack $itk_component(zslice) -side bottom -padx 4 -pady 4 472 pack $itk_component(yslice) -side bottom -padx 4 -pady 4 473 pack $itk_component(xslice) -side bottom -padx 4 -pady 4 474 475 # 476 # 3D LIGHTS (on both sides of all three axes) 477 # 478 set xm [expr {0.5*($_limits(xmax)+$_limits(xmin))}] 479 set ym [expr {0.5*($_limits(ymax)+$_limits(ymin))}] 480 set zm [expr {0.5*($_limits(zmax)+$_limits(zmin))}] 481 set xr [expr {$_limits(xmax)-$_limits(xmin)}] 482 set yr [expr {$_limits(ymax)-$_limits(ymin)}] 483 set zr [expr {$_limits(zmax)-$_limits(zmin)}] 484 485 set lt $this-lightxm$_counter 486 vtkLight $lt 487 $lt SetColor 1 1 1 488 $lt SetAttenuationValues 0 0 0 489 $lt SetFocalPoint $xm $ym $zm 490 $lt SetPosition [expr {$xm-$xr}] 0 0 491 $this-ren AddLight $lt 492 lappend _lights($this-ren) $lt 493 494 set lt $this-lightxp$_counter 495 vtkLight $lt 496 $lt SetColor 1 1 1 497 $lt SetAttenuationValues 0 0 0 498 $lt SetFocalPoint $xm $ym $zm 499 $lt SetPosition [expr {$xm+$xr}] 0 0 500 $this-ren AddLight $lt 501 lappend _lights($this-ren) $lt 502 503 set lt $this-lightym$_counter 504 vtkLight $lt 505 $lt SetColor 1 1 1 506 $lt SetAttenuationValues 0 0 0 507 $lt SetFocalPoint $xm $ym $zm 508 $lt SetPosition 0 [expr {$ym-$yr}] 0 509 $this-ren AddLight $lt 510 lappend _lights($this-ren) $lt 511 512 set lt $this-lightyp$_counter 513 vtkLight $lt 514 $lt SetColor 1 1 1 515 $lt SetAttenuationValues 0 0 0 516 $lt SetFocalPoint $xm $ym $zm 517 $lt SetPosition 0 [expr {$ym+$yr}] 0 518 $this-ren AddLight $lt 519 lappend _lights($this-ren) $lt 520 521 set lt $this-lightzm$_counter 522 vtkLight $lt 523 $lt SetColor 1 1 1 524 $lt SetAttenuationValues 0 0 0 525 $lt SetFocalPoint $xm $ym $zm 526 $lt SetPosition 0 0 [expr {$zm-$zr}] 527 $this-ren AddLight $lt 528 lappend _lights($this-ren) $lt 529 530 set lt $this-lightzp$_counter 531 vtkLight $lt 532 $lt SetColor 1 1 1 533 $lt SetAttenuationValues 0 0 0 534 $lt SetFocalPoint $xm $ym $zm 535 $lt SetPosition 0 0 [expr {$zm+$zr}] 536 $this-ren AddLight $lt 537 lappend _lights($this-ren) $lt 576 pack $itk_component(slicers) -side bottom -padx 4 -pady 4 577 pack $itk_component(reset) -side left 578 pack $itk_component(zoomin) -side left 579 pack $itk_component(zoomout) -side left 538 580 539 581 # … … 544 586 vtkPoints { 545 587 # handle cloud of 3D points 546 set pd $this-polydata$ _counter588 set pd $this-polydata$id 547 589 vtkPolyData $pd 548 590 $pd SetPoints $mesh 549 591 [$pd GetPointData] SetScalars [$dataobj values $comp] 550 592 551 set tr $this-triangles$ _counter593 set tr $this-triangles$id 552 594 vtkDelaunay3D $tr 553 595 $tr SetInput $pd … … 555 597 set source [$tr GetOutput] 556 598 557 set mp $this-mapper$ _counter599 set mp $this-mapper$id 558 600 vtkPolyDataMapper $mp 559 601 … … 562 604 vtkUnstructuredGrid { 563 605 # handle 3D grid with connectivity 564 set gr $this-grdata$ _counter606 set gr $this-grdata$id 565 607 vtkUnstructuredGrid $gr 608 $gr ShallowCopy $mesh 609 [$gr GetPointData] SetScalars [$dataobj values $comp] 610 set source $gr 611 612 lappend _obj2vtk($dataobj) $gr 613 } 614 vtkRectilinearGrid { 615 # handle 3D grid with connectivity 616 set gr $this-grdata$id 617 vtkRectilinearGrid $gr 566 618 $gr ShallowCopy $mesh 567 619 [$gr GetPointData] SetScalars [$dataobj values $comp] … … 576 628 577 629 # 578 # 3D CUT PLANE630 # 3D ISOSURFACES 579 631 # 580 set pl $this-cutplane$_counter 581 vtkPlane $pl 582 set _slicer(plane) $pl 583 _slice axis "z" 584 585 set ct $this-cutter$_counter 586 vtkCutter $ct 587 $ct SetInput $source 588 $ct SetCutFunction $pl 589 590 set mp $this-cutmapper$_counter 632 set iso $this-iso$id 633 vtkContourFilter $iso 634 $iso SetInput $source 635 636 set mp $this-isomap$id 591 637 vtkPolyDataMapper $mp 592 $mp SetInput [$ct GetOutput] 638 $mp SetInput [$iso GetOutput] 639 640 set ac $this-isoactor$id 641 vtkActor $ac 642 $ac SetMapper $mp 643 [$ac GetProperty] SetOpacity 0.3 644 [$ac GetProperty] SetDiffuse 0.5 645 [$ac GetProperty] SetAmbient 0.7 646 [$ac GetProperty] SetSpecular 10.0 647 [$ac GetProperty] SetSpecularPower 200.0 648 $this-ren AddActor $ac 649 650 lappend _obj2vtk($dataobj) $iso $mp $ac 651 lappend _actors($this-ren) $ac 652 653 catch {unset style} 654 array set style [lindex [$dataobj components -style $comp] 0] 655 if {[info exists style(-color)]} { 656 $mp ScalarVisibilityOff ;# take color from actor 657 eval [$ac GetProperty] SetColor [_color2rgb $style(-color)] 658 } 659 660 if {[info exists style(-opacity)]} { 661 [$ac GetProperty] SetOpacity $style(-opacity) 662 } 663 664 set levels 5 665 if {[info exists style(-levels)]} { 666 set levels $style(-levels) 667 } 668 if {$levels == 1} { 669 $iso SetValue 0 [expr {0.5*($v1-$v0)+$v0}] 670 } else { 671 $iso GenerateValues [expr {$levels+2}] $v0 $v1 672 } 673 674 # 675 # 3D CUT PLANES 676 # 677 if {$id == 0} { 678 foreach axis {x y z} norm {{1 0 0} {0 1 0} {0 0 1}} { 679 set pl $this-${axis}cutplane$id 680 vtkPlane $pl 681 eval $pl SetNormal $norm 682 set _slicer(${axis}plane) $pl 683 684 set ct $this-${axis}cutter$id 685 vtkCutter $ct 686 $ct SetInput $source 687 $ct SetCutFunction $pl 688 689 set mp $this-${axis}cutmapper$id 690 vtkPolyDataMapper $mp 691 $mp SetInput [$ct GetOutput] 692 $mp SetScalarRange $v0 $v1 693 $mp SetLookupTable $lu 694 695 lappend _obj2vtk($dataobj) $pl $ct $mp 696 697 set ac $this-${axis}actor$id 698 vtkActor $ac 699 $ac VisibilityOff 700 $ac SetMapper $mp 701 $ac SetPosition 0 0 0 702 [$ac GetProperty] SetColor 0 0 0 703 set _slicer(${axis}slice) $ac 704 705 $this-ren AddActor $ac 706 lappend _actors($this-ren) $ac 707 lappend _obj2vtk($dataobj) $ac 708 } 709 710 # 711 # CUT PLANE READOUT 712 # 713 set tx $this-text$id 714 vtkTextMapper $tx 715 set tp [$tx GetTextProperty] 716 eval $tp SetColor [_color2rgb $itk_option(-plotforeground)] 717 $tp SetVerticalJustificationToTop 718 set _slicer(readout) $tx 719 720 set txa $this-texta$id 721 vtkActor2D $txa 722 $txa SetMapper $tx 723 [$txa GetPositionCoordinate] \ 724 SetCoordinateSystemToNormalizedDisplay 725 [$txa GetPositionCoordinate] SetValue 0.02 0.98 726 727 $this-ren AddActor $txa 728 lappend _actors($this-ren) $txa 729 730 lappend _obj2vtk($dataobj) $tx $txa 731 732 # turn off all slicers by default 733 foreach axis {x y z} { 734 $itk_component(${axis}slicer) configure -state normal 735 $itk_component(${axis}slicer) set 50 736 _slice move $axis 50 737 _slice axis $axis off 738 } 739 } 740 741 } else { 742 pack forget $itk_component(slicers) 743 pack $itk_component(reset) -side top 744 pack $itk_component(zoomin) -side top 745 pack $itk_component(zoomout) -side top 746 747 set pd $this-polydata$id 748 vtkPolyData $pd 749 $pd SetPoints [$dataobj mesh $comp] 750 [$pd GetPointData] SetScalars [$dataobj values $comp] 751 752 set tr $this-triangles$id 753 vtkDelaunay2D $tr 754 $tr SetInput $pd 755 $tr SetTolerance 0.0000000000001 756 set source [$tr GetOutput] 757 758 set mp $this-mapper$id 759 vtkPolyDataMapper $mp 760 $mp SetInput $source 593 761 $mp SetScalarRange $v0 $v1 594 762 $mp SetLookupTable $lu 595 763 596 lappend _obj2vtk($dataobj) $pl $ct $mp 597 598 set ac $this-actor$_counter 764 set ac $this-actor$id 599 765 vtkActor $ac 600 766 $ac SetMapper $mp … … 603 769 $this-ren AddActor $ac 604 770 lappend _actors($this-ren) $ac 605 lappend _obj2vtk($dataobj) $ac606 607 set olf $this-3dolfilter$_counter608 vtkOutlineFilter $olf609 $olf SetInput $source610 611 set olm $this-3dolmapper$_counter612 vtkPolyDataMapper $olm613 $olm SetInput [$olf GetOutput]614 615 set ola $this-3dolactor$_counter616 vtkActor $ola617 $ola SetMapper $olm618 eval [$ola GetProperty] SetColor 0 0 0619 $this-ren AddActor $ola620 lappend _actors($this-ren) $ola621 622 lappend _obj2vtk($dataobj) $olf $olm $ola623 624 #625 # CUT PLANE READOUT626 #627 set tx $this-text$_counter628 vtkTextMapper $tx629 set tp [$tx GetTextProperty]630 eval $tp SetColor [_color2rgb $itk_option(-foreground)]631 $tp SetVerticalJustificationToTop632 set _slicer(readout) $tx633 634 set txa $this-texta$_counter635 vtkActor2D $txa636 $txa SetMapper $tx637 [$txa GetPositionCoordinate] \638 SetCoordinateSystemToNormalizedDisplay639 [$txa GetPositionCoordinate] SetValue 0.02 0.98640 641 $this-ren AddActor $txa642 lappend _actors($this-ren) $txa643 644 lappend _obj2vtk($dataobj) $tx $txa645 } else {646 pack forget $itk_component(xslice)647 pack forget $itk_component(yslice)648 pack forget $itk_component(zslice)649 pack forget $itk_component(slicer)650 651 set pd $this-polydata$_counter652 vtkPolyData $pd653 $pd SetPoints [$dataobj mesh $comp]654 [$pd GetPointData] SetScalars [$dataobj values $comp]655 656 set tr $this-triangles$_counter657 vtkDelaunay2D $tr658 $tr SetInput $pd659 $tr SetTolerance 0.0000000000001660 set source [$tr GetOutput]661 662 set mp $this-mapper$_counter663 vtkPolyDataMapper $mp664 $mp SetInput $source665 $mp SetScalarRange $v0 $v1666 $mp SetLookupTable $lu667 668 set ac $this-actor$_counter669 vtkActor $ac670 $ac SetMapper $mp671 $ac SetPosition 0 0 0672 [$ac GetProperty] SetColor 0 0 0673 $this-ren AddActor $ac674 lappend _actors($this-ren) $ac675 771 676 772 lappend _obj2vtk($dataobj) $pd $tr $mp $ac 677 773 } 678 } 679 680 # 681 # Add color lines 682 # 683 if {$_counter > 0} { 684 set cf $this-clfilter$_counter 774 } else { 775 # 776 # Add color lines 777 # 778 set cf $this-clfilter$id 685 779 vtkContourFilter $cf 686 780 $cf SetInput $source 687 781 $cf GenerateValues 20 $v0 $v1 688 782 689 set mp $this-clmapper$ _counter783 set mp $this-clmapper$id 690 784 vtkPolyDataMapper $mp 691 785 $mp SetInput [$cf GetOutput] … … 693 787 $mp SetLookupTable $lu 694 788 695 set ac $this-clactor$ _counter789 set ac $this-clactor$id 696 790 vtkActor $ac 697 791 $ac SetMapper $mp … … 707 801 # Add an outline around the data 708 802 # 709 set olf $this-olfilter$_counter 710 vtkOutlineFilter $olf 711 $olf SetInput $source 712 713 set olm $this-olmapper$_counter 714 vtkPolyDataMapper $olm 715 $olm SetInput [$olf GetOutput] 716 717 set ola $this-olactor$_counter 718 vtkActor $ola 719 $ola SetMapper $olm 720 eval [$ola GetProperty] SetColor 0 0 0 721 $this-ren AddActor $ola 722 lappend _actors($this-ren) $ola 723 724 lappend _obj2vtk($dataobj) $olf $olm $ola 803 if {$id == 0} { 804 set olf $this-olfilter$id 805 vtkOutlineFilter $olf 806 $olf SetInput $source 807 808 set olm $this-olmapper$id 809 vtkPolyDataMapper $olm 810 $olm SetInput [$olf GetOutput] 811 812 set ola $this-olactor$id 813 vtkActor $ola 814 $ola SetMapper $olm 815 eval [$ola GetProperty] SetColor [_color2rgb $itk_option(-plotforeground)] 816 $this-ren AddActor $ola 817 lappend _actors($this-ren) $ola 818 819 lappend _obj2vtk($dataobj) $olf $olm $ola 820 821 if {$_dims == "3D"} { 822 # pick a good scale factor for text 823 if {$xr < $yr} { 824 set tscale [expr {0.1*$xr}] 825 } else { 826 set tscale [expr {0.1*$yr}] 827 } 828 829 foreach {i axis px py pz rx ry rz} { 830 0 x $xm 0 0 90 0 0 831 1 y 0 $ym 0 90 -90 0 832 2 z $x1 0 $zm 90 0 -45 833 } { 834 set length "[expr {[set ${axis}1]-[set ${axis}0]}]" 835 836 set vtx $this-${axis}label$id 837 vtkVectorText $vtx 838 $vtx SetText "$axis" 839 840 set vmp $this-${axis}lmap$id 841 vtkPolyDataMapper $vmp 842 $vmp SetInput [$vtx GetOutput] 843 844 set vac $this-${axis}lact$id 845 vtkActor $vac 846 $vac SetMapper $vmp 847 $vac SetPosition [expr $px] [expr $py] [expr $pz] 848 $vac SetOrientation $rx $ry $rz 849 $vac SetScale $tscale 850 $this-ren AddActor $vac 851 852 lappend _obj2vtk($dataobj) $vtx $vmp $vac 853 lappend _actors($this-ren) $vac 854 855 $vmp Update 856 foreach {xx0 xx1 yy0 yy1 zz0 zz1} [$vac GetBounds] break 857 switch -- $axis { 858 x { 859 set dx [expr {-0.5*($xx1-$xx0)}] 860 set dy 0 861 set dz [expr {1.3*($zz0-$zz1)}] 862 } 863 y { 864 set dx 0 865 set dy [expr {0.5*($yy1-$yy0)}] 866 set dz [expr {$zz0-$zz1}] 867 } 868 z { 869 set dx [expr {0.2*$tscale}] 870 set dy $dx 871 set dz [expr {-0.5*($zz1-$zz0)}] 872 } 873 } 874 $vac AddPosition $dx $dy $dz 875 } 876 } 877 } 725 878 726 879 # 727 880 # Add a legend with the scale. 728 881 # 729 set lg $this-legend$_counter 730 vtkScalarBarActor $lg 731 $lg SetLookupTable $lu 732 [$lg GetPositionCoordinate] SetCoordinateSystemToNormalizedViewport 733 [$lg GetPositionCoordinate] SetValue 0.1 0.1 734 $lg SetOrientationToHorizontal 735 $lg SetWidth 0.8 736 $lg SetHeight 1.0 737 738 set tp [$lg GetLabelTextProperty] 739 eval $tp SetColor [_color2rgb $itk_option(-foreground)] 740 $tp BoldOff 741 $tp ItalicOff 742 $tp ShadowOff 743 #eval $tp SetShadowColor [_color2rgb gray] 744 745 $this-ren2 AddActor2D $lg 746 lappend _actors($this-ren2) $lg 747 lappend _obj2vtk($dataobj) $lg 748 749 incr _counter 750 } 882 if {$id == 0} { 883 set lg $this-legend$id 884 vtkScalarBarActor $lg 885 $lg SetLookupTable $lu 886 [$lg GetPositionCoordinate] SetCoordinateSystemToNormalizedViewport 887 [$lg GetPositionCoordinate] SetValue 0.1 0.1 888 $lg SetOrientationToHorizontal 889 $lg SetWidth 0.8 890 $lg SetHeight 1.0 891 892 set tp [$lg GetLabelTextProperty] 893 eval $tp SetColor [_color2rgb $itk_option(-plotforeground)] 894 $tp BoldOff 895 $tp ItalicOff 896 $tp ShadowOff 897 #eval $tp SetShadowColor [_color2rgb gray] 898 899 $this-ren2 AddActor2D $lg 900 lappend _actors($this-ren2) $lg 901 lappend _obj2vtk($dataobj) $lg 902 } 903 904 incr id 905 } 906 set firstobj 0 751 907 } 752 908 _fixLimits … … 790 946 set _obj2vtk($dataobj) "" 791 947 } 792 set _slicer(axis) "" 793 set _slicer(plane) "" 948 set _slicer(xplane) "" 949 set _slicer(yplane) "" 950 set _slicer(zplane) "" 951 set _slicer(xslice) "" 952 set _slicer(yslice) "" 953 set _slicer(zslice) "" 794 954 set _slicer(readout) "" 795 955 } … … 891 1051 892 1052 # ---------------------------------------------------------------------- 893 # USAGE: _slice axis x|y|z 894 # USAGE: _slice move <newval>1053 # USAGE: _slice axis x|y|z ?on|off|toggle? 1054 # USAGE: _slice move x|y|z <newval> 895 1055 # 896 1056 # Called automatically when the user drags the slider to move the … … 900 1060 # ---------------------------------------------------------------------- 901 1061 itcl::body Rappture::ContourResult::_slice {option args} { 902 if {$_slicer( plane) == ""} {1062 if {$_slicer(xplane) == ""} { 903 1063 # no slicer? then bail out! 904 1064 return … … 906 1066 switch -- $option { 907 1067 axis { 908 if {[llength $args] != 1} {909 error "wrong # args: should be \"_slice axis x yz\""1068 if {[llength $args] < 1 || [llength $args] > 2} { 1069 error "wrong # args: should be \"_slice axis x|y|z ?on|off|toggle?\"" 910 1070 } 911 1071 set axis [lindex $args 0] 912 913 switch -- $axis { 914 x { $_slicer(plane) SetNormal 1 0 0 } 915 y { $_slicer(plane) SetNormal 0 1 0 } 916 z { $_slicer(plane) SetNormal 0 0 1 } 917 default { 918 error "bad axis \"$axis\": should be x, y, z" 919 } 920 } 921 922 set _slicer(axis) $axis 923 $itk_component(slicer) set 50 924 _slice move 50 1072 set op [lindex $args 1] 1073 if {$op == ""} { set op "on" } 1074 1075 if {[$itk_component(${axis}slice) cget -relief] == "raised"} { 1076 set current "off" 1077 } else { 1078 set current "on" 1079 } 1080 1081 if {$op == "toggle"} { 1082 if {$current == "on"} { set op "off" } else { set op "on" } 1083 } 1084 1085 if {$op} { 1086 $itk_component(${axis}slicer) configure -state normal 1087 $_slicer(${axis}slice) VisibilityOn 1088 $itk_component(${axis}slice) configure -relief sunken 1089 } else { 1090 $itk_component(${axis}slicer) configure -state disabled 1091 $_slicer(${axis}slice) VisibilityOff 1092 $itk_component(${axis}slice) configure -relief raised 1093 } 925 1094 $this-renWin Render 926 927 foreach a {x y z} {928 $itk_component(${a}slice) configure -relief raised929 }930 $itk_component(${axis}slice) configure -relief sunken931 1095 } 932 1096 move { 933 if {[llength $args] != 1} { 934 error "wrong # args: should be \"_slice move newval\"" 935 } 936 set newval [lindex $args 0] 1097 if {[llength $args] != 2} { 1098 error "wrong # args: should be \"_slice move x|y|z newval\"" 1099 } 1100 set axis [lindex $args 0] 1101 set newval [lindex $args 1] 937 1102 938 1103 set xm [expr {0.5*($_limits(xmax)+$_limits(xmin))}] … … 940 1105 set zm [expr {0.5*($_limits(zmax)+$_limits(zmin))}] 941 1106 942 set a $_slicer(axis)943 1107 set newval [expr {0.01*($newval-50) 944 *($_limits(${a }max)-$_limits(${a}min))945 + 0.5*($_limits(${a }max)+$_limits(${a}min))}]1108 *($_limits(${axis}max)-$_limits(${axis}min)) 1109 + 0.5*($_limits(${axis}max)+$_limits(${axis}min))}] 946 1110 947 1111 # show the current value in the readout 948 1112 if {$_slicer(readout) != ""} { 949 $_slicer(readout) SetInput "$a = $newval"1113 $_slicer(readout) SetInput "$axis = $newval" 950 1114 } 951 1115 952 1116 # keep a little inside the volume, or the slice will disappear! 953 if {$newval == $_limits(${a }min)} {954 set range [expr {$_limits(${a }max)-$_limits(${a}min)}]1117 if {$newval == $_limits(${axis}min)} { 1118 set range [expr {$_limits(${axis}max)-$_limits(${axis}min)}] 955 1119 set newval [expr {$newval + 1e-6*$range}] 956 1120 } 957 1121 958 1122 # xfer new value to the proper dimension and move the cut plane 959 set ${a }m $newval960 $_slicer( plane) SetOrigin $xm $ym $zm1123 set ${axis}m $newval 1124 $_slicer(${axis}plane) SetOrigin $xm $ym $zm 961 1125 962 1126 $this-renWin Render … … 1016 1180 1017 1181 # ---------------------------------------------------------------------- 1182 # USAGE: _slicertip <axis> 1183 # 1184 # Used internally to generate a tooltip for the x/y/z slicer controls. 1185 # Returns a message that includes the current slicer value. 1186 # ---------------------------------------------------------------------- 1187 itcl::body Rappture::ContourResult::_slicertip {axis} { 1188 set val [$itk_component(${axis}slicer) get] 1189 set val [expr {0.01*($val-50) 1190 *($_limits(${axis}max)-$_limits(${axis}min)) 1191 + 0.5*($_limits(${axis}max)+$_limits(${axis}min))}] 1192 return "Move the [string toupper $axis] cut plane.\nCurrently: $axis = $val" 1193 } 1194 1195 # ---------------------------------------------------------------------- 1018 1196 # USAGE: _color2rgb <color> 1019 1197 # … … 1030 1208 1031 1209 # ---------------------------------------------------------------------- 1032 # CONFIGURATION OPTION: - background1033 # ---------------------------------------------------------------------- 1034 itcl::configbody Rappture::ContourResult:: background {1035 foreach {r g b} [_color2rgb $itk_option(- background)] break1210 # CONFIGURATION OPTION: -plotbackground 1211 # ---------------------------------------------------------------------- 1212 itcl::configbody Rappture::ContourResult::plotbackground { 1213 foreach {r g b} [_color2rgb $itk_option(-plotbackground)] break 1036 1214 $this-ren SetBackground $r $g $b 1037 1215 $this-renWin Render … … 1041 1219 1042 1220 # ---------------------------------------------------------------------- 1043 # CONFIGURATION OPTION: - foreground1044 # ---------------------------------------------------------------------- 1045 itcl::configbody Rappture::ContourResult:: foreground {1221 # CONFIGURATION OPTION: -plotforeground 1222 # ---------------------------------------------------------------------- 1223 itcl::configbody Rappture::ContourResult::plotforeground { 1046 1224 after cancel [itcl::code $this _rebuild] 1047 1225 after idle [itcl::code $this _rebuild] -
trunk/gui/scripts/energyLevels.tcl
r115 r136 97 97 private variable _edefmax "" ;# max for default "zoom" view 98 98 private variable _ehomo "" ;# energy of HOMO level in topmost dataset 99 private variable _lhomo "" ;# label for HOMO level 99 100 private variable _elumo "" ;# energy of LUMO level in topmost dataset 101 private variable _llumo "" ;# label for LUMO level 100 102 private variable _hilite "" ;# item currently highlighted 101 103 } … … 252 254 if {"" == $units} { 253 255 set vals [$dataobj values -column $index] 254 if {[regexp {(^|[[:space:]])HOMO([[:space:]]|$)} $vals]} { 255 if {$lpos >= 0} { 256 # more than one labels column -- bail out 257 set lpos -1 258 break 259 } 256 if {$lpos != $epos} { 260 257 set lpos $index 258 break 261 259 } 262 260 } … … 438 436 # the bottom up. 439 437 # 440 set e2y [expr {($y 1-$y0)/($_emax-$_emin)}]438 set e2y [expr {($yzoom1-$yzoom0)/($_emax-$_emin)}] 441 439 442 440 set title "" … … 455 453 456 454 foreach eval [$dataobj values -column $ecol] { 457 set y [expr {($eval-$_emin)*$e2y + $y 0}]455 set y [expr {($eval-$_emin)*$e2y + $yzoom0}] 458 456 $c create line $xx0 $y $xx1 $y -fill $color -width 1 459 457 } … … 481 479 lval [$dataobj values -column $lcol] { 482 480 483 if { $lval == "HOMO"} {481 if {[string equal -nocase $lval "HOMO"]} { 484 482 set nhomo $n 483 set _lhomo $lval 485 484 set nlumo [expr {$n+1}] 486 } elseif {$lval == "LUMO"} { 485 set _llumo "LUMO" 486 } elseif {[string equal -nocase $lval "Ground State"]} { 487 set nhomo $n 488 set _lhomo $lval 489 set nlumo [expr {$n+1}] 490 set _llumo "1st Excited State" 491 } elseif {[string equal -nocase $lval "LUMO"] 492 || [string equal -nocase $lval "1st Excited State"]} { 487 493 set nlumo $n 494 set _llumo $lval 488 495 } 489 496 incr n … … 498 505 set _edefmax [expr {$_elumo + 0.3*$gap}] 499 506 500 set y [expr {($_ehomo-$_emin)*$e2y + $y 0}]507 set y [expr {($_ehomo-$_emin)*$e2y + $yzoom0}] 501 508 set id [$c create rectangle $xx0 $y $xx1 $y0 \ 502 509 -stipple EnergyLevels-rdiag \ … … 519 526 # draw the lines for the "zoom" view (fixed up below) 520 527 set color $itk_option(-foreground) 521 $c create line $x0 $y 0 $x1 $y0 -fill $color -tags zmin522 $c create line $x0 $y 0 $x1 $y0 -fill $color -tags zmax523 524 $c create line $x1 $y 0 $x2 $y0 -fill $color -tags zoomup525 $c create line $x1 $y 0 $x2 $y1 -fill $color -tags zoomdn526 527 $c create line $x2 $y 0 $x3 $y0 -fill $color528 $c create line $x2 $y 1 $x3 $y1 -fill $color528 $c create line $x0 $yzoom0 $x1 $yzoom0 -fill $color -tags zmin 529 $c create line $x0 $yzoom0 $x1 $yzoom0 -fill $color -tags zmax 530 531 $c create line $x1 $yzoom0 $x2 $yzoom0 -fill $color -tags zoomup 532 $c create line $x1 $yzoom0 $x2 $yzoom1 -fill $color -tags zoomdn 533 534 $c create line $x2 $yzoom0 $x3 $yzoom0 -fill $color 535 $c create line $x2 $yzoom1 $x3 $yzoom1 -fill $color 529 536 } 530 537 … … 533 540 # 534 541 if {$what == "zoom" || $what == "all"} { 535 set e2y [expr {($y 1-$y0)/($_emax-$_emin)}]536 537 set y [expr {($_eviewmin-$_emin)*$e2y + $y 0}]542 set e2y [expr {($yzoom1-$yzoom0)/($_emax-$_emin)}] 543 544 set y [expr {($_eviewmin-$_emin)*$e2y + $yzoom0}] 538 545 $c coords zmin $x0 $y $x1 $y 539 $c coords zoomup $x1 $y $x2 $y 0540 541 set y [expr {($_eviewmax-$_emin)*$e2y + $y 0}]546 $c coords zoomup $x1 $y $x2 $yzoom0 547 548 set y [expr {($_eviewmax-$_emin)*$e2y + $yzoom0}] 542 549 $c coords zmax $x0 $y $x1 $y 543 $c coords zoomdn $x1 $y $x2 $y 1550 $c coords zoomdn $x1 $y $x2 $yzoom1 544 551 545 552 # redraw all levels in the current view 546 553 $c delete zlevels zlabels 547 554 548 set e2y [expr {($y 1-$y0)/($_eviewmax-$_eviewmin)}]555 set e2y [expr {($yzoom1-$yzoom0)/($_eviewmax-$_eviewmin)}] 549 556 foreach dataobj $dlist { 550 557 set ecol $_dobj2cols($dataobj-energy) … … 556 563 set n 0 557 564 foreach eval [$dataobj values -column $ecol] { 558 if {$eval >= $_eviewmin && $eval <= $_eviewmax} {559 set y [expr {($eval-$_eviewmin)*$e2y + $y0}]565 set y [expr {($eval-$_eviewmin)*$e2y + $yzoom0}] 566 if {$y >= $y1 && $y <= $y0} { 560 567 set id [$c create line $xx2 $y $xx3 $y \ 561 568 -fill $color -width 1 \ … … 570 577 set units [$topdobj columns -units $ecol] 571 578 572 set yy0 [expr {($_ehomo-$_eviewmin)*$e2y + $y0}] 573 set yy1 [expr {($_elumo-$_eviewmin)*$e2y + $y0}] 574 $c create line [expr {$x3-10}] $yy0 [expr {$x3-10}] $yy1 \ 575 -arrow both -fill $itk_option(-foreground) \ 576 -tags zlabels 577 $c create text [expr {$x3-15}] [expr {0.5*($yy0+$yy1)}] \ 578 -anchor e -text "Eg = [expr {$_elumo-$_ehomo}] $units" \ 579 -tags zlabels 580 581 # label the HOMO level 582 set tid [$c create text [expr {0.5*($x2+$x3)}] $yy0 -anchor c \ 583 -text "HOMO = $_ehomo $units" \ 584 -fill $itk_option(-leveltextforeground) \ 585 -tags zlabels] 586 587 foreach {xb0 yb0 xb1 yb1} [$c bbox $tid] break 588 set tid2 [$c create rectangle \ 589 [expr {$xb0-1}] [expr {$yb0-1}] \ 590 [expr {$xb1+1}] [expr {$yb1+1}] \ 591 -outline $itk_option(-leveltextforeground) \ 592 -fill $itk_option(-leveltextbackground) \ 593 -tags zlabels] 594 $c lower $tid2 $tid 595 596 # label the LUMO level 597 set tid [$c create text [expr {0.5*($x2+$x3)}] $yy1 -anchor c \ 598 -text "LUMO = $_elumo $units" \ 599 -fill $itk_option(-leveltextforeground) \ 600 -tags zlabels] 601 602 foreach {xb0 yb0 xb1 yb1} [$c bbox $tid] break 603 set tid2 [$c create rectangle \ 604 [expr {$xb0-1}] [expr {$yb0-1}] \ 605 [expr {$xb1+1}] [expr {$yb1+1}] \ 606 -outline $itk_option(-leveltextforeground) \ 607 -fill $itk_option(-leveltextbackground) \ 608 -tags zlabels] 609 $c lower $tid2 $tid 610 611 set id [$c create rectangle $xx2 $yy0 $xx3 $y0 \ 612 -stipple EnergyLevels-rdiag \ 613 -outline "" -fill $itk_option(-shadecolor) \ 614 -tags zlabels] 615 $c lower $id 579 set yy0 [expr {($_ehomo-$_eviewmin)*$e2y + $yzoom0}] 580 set yy1 [expr {($_elumo-$_eviewmin)*$e2y + $yzoom0}] 581 582 set textht [font metrics $itk_option(-font) -linespace] 583 if {$yy0-$yy1 >= 1.5*$textht} { 584 $c create line [expr {$x3-10}] $yy0 [expr {$x3-10}] $yy1 \ 585 -arrow both -fill $itk_option(-foreground) \ 586 -tags zlabels 587 $c create text [expr {$x3-15}] [expr {0.5*($yy0+$yy1)}] \ 588 -anchor e -text "Eg = [expr {$_elumo-$_ehomo}] $units" \ 589 -tags zlabels 590 591 # label the HOMO level 592 set tid [$c create text [expr {0.5*($x2+$x3)}] $yy0 -anchor c \ 593 -text "$_lhomo = $_ehomo $units" \ 594 -fill $itk_option(-leveltextforeground) \ 595 -tags zlabels] 596 597 foreach {xb0 yb0 xb1 yb1} [$c bbox $tid] break 598 set tid2 [$c create rectangle \ 599 [expr {$xb0-1}] [expr {$yb0-1}] \ 600 [expr {$xb1+1}] [expr {$yb1+1}] \ 601 -outline $itk_option(-leveltextforeground) \ 602 -fill $itk_option(-leveltextbackground) \ 603 -tags zlabels] 604 $c lower $tid2 $tid 605 606 # label the LUMO level 607 set tid [$c create text [expr {0.5*($x2+$x3)}] $yy1 -anchor c \ 608 -text "$_llumo = $_elumo $units" \ 609 -fill $itk_option(-leveltextforeground) \ 610 -tags zlabels] 611 612 foreach {xb0 yb0 xb1 yb1} [$c bbox $tid] break 613 set tid2 [$c create rectangle \ 614 [expr {$xb0-1}] [expr {$yb0-1}] \ 615 [expr {$xb1+1}] [expr {$yb1+1}] \ 616 -outline $itk_option(-leveltextforeground) \ 617 -fill $itk_option(-leveltextbackground) \ 618 -tags zlabels] 619 $c lower $tid2 $tid 620 } 621 622 if {$yy0 < $y0} { 623 set id [$c create rectangle $xx2 $yy0 $xx3 $y0 \ 624 -stipple EnergyLevels-rdiag \ 625 -outline "" -fill $itk_option(-shadecolor) \ 626 -tags zlabels] 627 $c lower $id 628 } 616 629 } 617 630 } … … 653 666 654 667 _getLayout 655 set y2e [expr {($_emax-$_emin)/($y 1-$y0)}]668 set y2e [expr {($_emax-$_emin)/($yzoom1-$yzoom0)}] 656 669 657 670 if {$x > $x1} { 658 671 return 659 672 } 660 set midE [expr {($y-$y 0)*$y2e + $_emin}]673 set midE [expr {($y-$yzoom0)*$y2e + $_emin}] 661 674 set delE [expr {$_eviewmax - $_eviewmin}] 662 675 _view $midE $delE … … 731 744 # touching a line? then find the level and show its info 732 745 if {"" != $id} { 733 set e2y [expr {($y 1-$y0)/($_eviewmax-$_eviewmin)}]746 set e2y [expr {($yzoom1-$yzoom0)/($_eviewmax-$_eviewmin)}] 734 747 735 748 # put the dataobj list in order according to -raise options … … 750 763 set n 0 751 764 foreach eval [$dataobj values -column $ecol] { 752 set ylevel [expr {($eval-$_eviewmin)*$e2y + $y 0}]765 set ylevel [expr {($eval-$_eviewmin)*$e2y + $yzoom0}] 753 766 if {$y >= $ylevel-3 && $y <= $ylevel+3} { 754 767 set found 1 … … 787 800 788 801 if {$eval == $_ehomo || $eval == $_elumo} { 802 $itk_component(graph) itemconfigure $dataobj-$level -width 2 803 set _hilite "$dataobj $level" 789 804 # don't pop up info for the HOMO/LUMO levels 790 805 return … … 792 807 793 808 _getLayout 794 set e2y [expr {($y 1-$y0)/($_eviewmax-$_eviewmin)}]795 set y [expr {($eval-$_eviewmin)*$e2y + $y 0}]809 set e2y [expr {($yzoom1-$yzoom0)/($_eviewmax-$_eviewmin)}] 810 set y [expr {($eval-$_eviewmin)*$e2y + $yzoom0}] 796 811 797 812 set tid [$c create text [expr {0.5*($x2+$x3)}] $y -anchor c \ … … 847 862 # at least a little room for the labels. 848 863 # 849 set size [font measure $itk_option(-font) " HOMO= X.XXXXXXe-XX eV"]864 set size [font measure $itk_option(-font) "$_llumo = X.XXXXXXe-XX eV"] 850 865 set size [expr {$size + 6*$itk_option(-padding)}] 866 867 set textht [font metrics $itk_option(-font) -linespace] 868 set ypad [expr {int(0.5*($textht + 6))}] 851 869 852 870 if {$size > $w-20} { … … 886 904 set y0 [expr {$h - $itk_option(-padding)}] 887 905 906 upvar yzoom0 yzoom0 907 set yzoom0 [expr {$y0 - $ypad}] 908 888 909 upvar y1 y1 889 910 set y1 $itk_option(-padding) 911 912 upvar yzoom1 yzoom1 913 set yzoom1 [expr {$y1 + $ypad}] 890 914 } 891 915 -
trunk/gui/scripts/field.tcl
r115 r136 41 41 private variable _comp2xy ;# maps component name => x,y vectors 42 42 private variable _comp2vtk ;# maps component name => vtkFloatArray 43 private variable _comp2style ;# maps component name => style settings 43 44 private variable _comp2cntls ;# maps component name => x,y control points 44 45 … … 109 110 110 111 # ---------------------------------------------------------------------- 111 # USAGE: components ?-name|-dimensions ? ?<pattern>?112 # USAGE: components ?-name|-dimensions|-style? ?<pattern>? 112 113 # 113 114 # Returns a list of names or types for the various components of … … 119 120 flag what -name default 120 121 flag what -dimensions 122 flag what -style 121 123 } 122 124 … … 135 137 -name { lappend rlist $name } 136 138 -dimensions { lappend rlist $_comp2dims($name) } 139 -style { lappend rlist $_comp2style($name) } 137 140 } 138 141 } … … 249 252 } 250 253 v - vlin - vlog { 251 foreach {vmin vmax} [$yv GetRange] break 254 catch {unset style} 255 array set style $_comp2style($comp) 256 if {[info exists style(-min)] && [info exists style(-max)]} { 257 # This component has its own hard-coded 258 # min/max range. Ignore it for overall limits. 259 set vmin $min 260 set vmax $max 261 } else { 262 foreach {vmin vmax} [$yv GetRange] break 263 } 252 264 set axis vaxis 253 265 } … … 381 393 catch {unset _comp2vtk} 382 394 catch {unset _comp2dims} 395 catch {unset _comp2style} 383 396 384 397 # … … 395 408 && [$_field element $cname.values] != ""} { 396 409 set type "points-on-mesh" 397 } 410 } elseif {[$_field element $cname.vtk] != ""} { 411 set type "vtk" 412 } 413 414 set _comp2style($cname) "" 398 415 399 416 if {$type == "1D"} { … … 484 501 set _comp2dims($cname) "[$mobj dimensions]D" 485 502 set _comp2vtk($cname) [list $mobj $farray] 503 set _comp2style($cname) [$_field get $cname.style] 486 504 incr _counter 487 505 } else { … … 521 539 puts "WARNING: can't find mesh $path for field component" 522 540 } 541 } elseif {$type == "vtk"} { 542 # 543 # Extract native vtk data from the XML and use a reader 544 # to load it. 545 # 546 vtkRectilinearGridReader $this-gr 547 $this-gr SetInputString [$_field get $cname.vtk] 548 549 550 set _comp2dims($cname) "[$mobj dimensions]D" 551 set _comp2vtk($cname) [list $mobj $farray] 552 set _comp2style($cname) [$_field get $cname.style] 553 incr _counter 523 554 } 524 555 } -
trunk/gui/scripts/mesh.tcl
r115 r136 34 34 public proc release {obj} 35 35 36 private method _buildNodesElements {xmlobj path} 37 private method _buildRectMesh {xmlobj path} 36 38 private method _getVtkElement {npts} 37 39 … … 42 44 private variable _units "m m m" ;# system of units for x, y, z 43 45 private variable _limits ;# limits xmin, xmax, ymin, ymax, ... 46 private variable _pdata "" ;# name of vtkPointData object 47 private variable _gdata "" ;# name of vtkDataSet object 44 48 45 49 private common _xp2obj ;# used for fetch/release ref counting … … 112 116 } 113 117 114 # create the vtk objects containing points and connectivity115 vtkPoints $this-points116 vtkUnstructuredGrid $this-grid117 118 118 foreach lim {xmin xmax ymin ymax zmin zmax} { 119 119 set _limits($lim) "" 120 120 } 121 121 122 # 123 # Extract each node and add it to the points list. 124 # 125 foreach comp [$xmlobj children -type node $path] { 126 set xyz [$xmlobj get $path.$comp] 127 128 # make sure we have x,y,z 129 while {[llength $xyz] < 3} { 130 lappend xyz "0" 131 } 132 133 # extract each point and add it to the points list 134 foreach {x y z} $xyz break 135 foreach dim {x y z} units $_units { 136 set v [Rappture::Units::convert [set $dim] \ 137 -context $units -to $units -units off] 138 139 set $dim $v ;# save back to real x/y/z variable 140 141 if {"" == $_limits(${dim}min)} { 142 set _limits(${dim}min) $v 143 set _limits(${dim}max) $v 144 } else { 145 if {$v < $_limits(${dim}min)} { set _limits(${dim}min) $v } 146 if {$v > $_limits(${dim}max)} { set _limits(${dim}max) $v } 147 } 148 } 149 $this-points InsertNextPoint $x $y $z 150 } 151 $this-grid SetPoints $this-points 152 153 # 154 # Extract each element and add it to the mesh. 155 # 156 foreach comp [$xmlobj children -type element $path] { 157 set nlist [$_mesh get $comp.nodes] 158 set elem [_getVtkElement [llength $nlist]] 159 160 set i 0 161 foreach n $nlist { 162 [$elem GetPointIds] SetId $i $n 163 incr i 164 } 165 $this-grid InsertNextCell [$elem GetCellType] [$elem GetPointIds] 122 if {[$_mesh element vtk] != ""} { 123 _buildRectMesh $xmlobj $path 124 } elseif {[$_mesh element node] != "" && [$_mesh element element] != ""} { 125 _buildNodesElements $xmlobj $path 126 } else { 127 error "can't find mesh data in $path" 166 128 } 167 129 } … … 174 136 itcl::delete object $_mesh 175 137 176 rename $this-points "" 177 rename $this-grid "" 138 catch {rename $this-points ""} 139 catch {rename $this-grid ""} 140 catch {rename $this-dset ""} 178 141 179 142 foreach type [array names _pts2elem] { … … 188 151 # ---------------------------------------------------------------------- 189 152 itcl::body Rappture::Mesh::points {} { 190 # not implemented 191 return $this-points 153 return $_pdata 192 154 } 193 155 … … 239 201 # ---------------------------------------------------------------------- 240 202 itcl::body Rappture::Mesh::mesh {} { 241 return $ this-grid203 return $_gdata 242 204 } 243 205 … … 250 212 switch -- $what { 251 213 -points { 252 return [$ this-pointsGetNumberOfPoints]214 return [$_pdata GetNumberOfPoints] 253 215 } 254 216 -elements { 255 return [$ this-pointsGetNumberOfCells]217 return [$_gdata GetNumberOfCells] 256 218 } 257 219 default { … … 314 276 315 277 # ---------------------------------------------------------------------- 278 # USAGE: _buildNodesElements <xmlobj> <path> 279 # 280 # Used internally to build a mesh representation based on nodes and 281 # elements stored in the XML. 282 # ---------------------------------------------------------------------- 283 itcl::body Rappture::Mesh::_buildNodesElements {xmlobj path} { 284 # create the vtk objects containing points and connectivity 285 vtkPoints $this-points 286 set _pdata $this-points 287 vtkUnstructuredGrid $this-grid 288 set _gdata $this-grid 289 290 # 291 # Extract each node and add it to the points list. 292 # 293 foreach comp [$xmlobj children -type node $path] { 294 set xyz [$xmlobj get $path.$comp] 295 296 # make sure we have x,y,z 297 while {[llength $xyz] < 3} { 298 lappend xyz "0" 299 } 300 301 # extract each point and add it to the points list 302 foreach {x y z} $xyz break 303 foreach dim {x y z} units $_units { 304 set v [Rappture::Units::convert [set $dim] \ 305 -context $units -to $units -units off] 306 307 set $dim $v ;# save back to real x/y/z variable 308 309 if {"" == $_limits(${dim}min)} { 310 set _limits(${dim}min) $v 311 set _limits(${dim}max) $v 312 } else { 313 if {$v < $_limits(${dim}min)} { set _limits(${dim}min) $v } 314 if {$v > $_limits(${dim}max)} { set _limits(${dim}max) $v } 315 } 316 } 317 $this-points InsertNextPoint $x $y $z 318 } 319 $this-grid SetPoints $this-points 320 321 # 322 # Extract each element and add it to the mesh. 323 # 324 foreach comp [$xmlobj children -type element $path] { 325 set nlist [$_mesh get $comp.nodes] 326 set elem [_getVtkElement [llength $nlist]] 327 328 set i 0 329 foreach n $nlist { 330 [$elem GetPointIds] SetId $i $n 331 incr i 332 } 333 $this-grid InsertNextCell [$elem GetCellType] [$elem GetPointIds] 334 } 335 } 336 337 # ---------------------------------------------------------------------- 338 # USAGE: _buildRectMesh <xmlobj> <path> 339 # 340 # Used internally to build a mesh representation based on a native 341 # VTK file for a rectangular mesh. 342 # ---------------------------------------------------------------------- 343 itcl::body Rappture::Mesh::_buildRectMesh {xmlobj path} { 344 vtkRectilinearGridReader $this-gr 345 $this-gr ReadFromInputStringOn 346 $this-gr SetInputString [$xmlobj get $path.vtk] 347 348 set _gdata [$this-gr GetOutput] 349 set _pdata [$_gdata GetPointData] 350 351 $_gdata Update 352 foreach name {xmin xmax ymin ymax zmin zmax} val [$_gdata GetBounds] { 353 set _limits($name) $val 354 } 355 } 356 357 # ---------------------------------------------------------------------- 316 358 # USAGE: _getVtkElement <npts> 317 359 # -
trunk/gui/scripts/resultviewer.tcl
r126 r136 207 207 } 208 208 ::Rappture::Field { 209 switch -- [$dataobj components -dimensions] { 209 set dims [lindex [lsort [$dataobj components -dimensions]] end] 210 switch -- $dims { 210 211 1D { 211 212 set mode "xy"
Note: See TracChangeset
for help on using the changeset viewer.