Changeset 4474 for branches/1.3/gui/scripts/mesh.tcl
- Timestamp:
- Jul 9, 2014 8:33:55 PM (10 years ago)
- Location:
- branches/1.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.3
- Property svn:mergeinfo changed
/trunk merged: 3917,3921-3923,3934,3996,4021,4030,4133,4136-4138,4140,4189,4250,4259,4395,4401,4442
- Property svn:mergeinfo changed
-
branches/1.3/gui/scripts/mesh.tcl
r4472 r4474 27 27 private variable _dim 0; # Dimension of mesh (1, 2, or 3) 28 28 private variable _type ""; # Indicates the type of mesh. 29 private variable _units "m m m" ; # System of units for x, y, z 29 private variable _axis2units; # System of units for x, y, z 30 private variable _axis2labels; # 31 private variable _hints 30 32 private variable _limits ; # Array of mesh limits. Keys are 31 33 # xmin, xmax, ymin, ymax, ... … … 46 48 public method dimensions {} 47 49 public method limits {which} 50 public method units { axis } 51 public method label { axis } 48 52 public method hints {{key ""}} 49 53 public method isvalid {} { … … 52 56 public proc fetch {xmlobj path} 53 57 public proc release {obj} 54 public method vtkdata { }58 public method vtkdata {{what -partial}} 55 59 public method type {} { 56 60 return $_type … … 59 63 return $_numPoints 60 64 } 61 65 public method numcells {} { 66 return $_numCells 67 } 62 68 63 69 private common _xp2obj ; # used for fetch/release ref counting … … 73 79 private method GetDouble { path } 74 80 private method GetInt { path } 81 private method InitHints {} 75 82 private method ReadGrid { path } 76 83 private method ReadUnstructuredGrid { path } … … 149 156 set _limits($axis) "" 150 157 } 151 set u [$_mesh get units] 152 if {"" != $u} { 153 while {[llength $u] < 3} { 154 lappend u [lindex $u end] 155 } 156 set _units $u 158 set units [$_mesh get units] 159 set first [lindex $units 0] 160 foreach u $units axis { x y z } { 161 if { $u != "" } { 162 set _axis2units($axis) $u 163 } else { 164 set _axis2units($axis) $first 165 } 166 } 167 foreach label [$_mesh get labels] axis { x y z } { 168 if { $label != "" } { 169 set _axis2labels($axis) $label 170 } else { 171 set _axis2labels($axis) [string toupper $axis] 172 } 157 173 } 158 174 … … 200 216 } 201 217 set _isValid $result 218 InitHints 202 219 } 203 220 … … 226 243 # arrays before generating output to send to the remote render server. 227 244 # 228 itcl::body Rappture::Mesh::vtkdata {} { 229 return $_vtkdata 245 itcl::body Rappture::Mesh::vtkdata {{what -partial}} { 246 if {$what == "-full"} { 247 append out "# vtk DataFile Version 3.0\n" 248 append out "[hints label]\n" 249 append out "ASCII\n" 250 append out $_vtkdata 251 return $out 252 } else { 253 return $_vtkdata 254 } 230 255 } 231 256 … … 237 262 itcl::body Rappture::Mesh::points {} { 238 263 return "" 264 } 265 266 # 267 # units -- 268 # 269 # Returns the units of the given axis. 270 # 271 itcl::body Rappture::Mesh::units { axis } { 272 if { ![info exists _axis2units($axis)] } { 273 return "" 274 } 275 return $_axis2units($axis) 276 } 277 278 # 279 # label -- 280 # 281 # Returns the label of the given axis. 282 # 283 itcl::body Rappture::Mesh::label { axis } { 284 if { ![info exists _axis2labels($axis)] } { 285 return "" 286 } 287 return $_axis2labels($axis) 239 288 } 240 289 … … 344 393 # ---------------------------------------------------------------------- 345 394 itcl::body Rappture::Mesh::hints {{keyword ""}} { 346 foreach key {label color units} { 347 set str [$_mesh get $key] 395 if {$keyword != ""} { 396 if {[info exists _hints($keyword)]} { 397 return $_hints($keyword) 398 } 399 return "" 400 } 401 return [array get _hints] 402 } 403 404 # ---------------------------------------------------------------------- 405 # USAGE: InitHints 406 # 407 # Returns a list of key/value pairs for various hints about plotting 408 # this mesh. If a particular <keyword> is specified, then it returns 409 # the hint for that <keyword>, if it exists. 410 # ---------------------------------------------------------------------- 411 itcl::body Rappture::Mesh::InitHints {} { 412 foreach {key path} { 413 camera camera.position 414 color about.color 415 label about.label 416 style about.style 417 units units 418 } { 419 set str [$_mesh get $path] 348 420 if {"" != $str} { 349 set hints($key) $str 350 } 351 } 352 353 if {$keyword != ""} { 354 if {[info exists hints($keyword)]} { 355 return $hints($keyword) 356 } 357 return "" 358 } 359 return [array get hints] 421 set _hints($key) $str 422 } 423 } 360 424 } 361 425 … … 367 431 } 368 432 if { [scan $string "%d" _dim] == 1 } { 369 if { $_dim == 2 || $_dim == 3 } {433 if { $_dim == 1 || $_dim == 2 || $_dim == 3 } { 370 434 return 1 371 435 } 372 436 } 373 puts stderr "WARNING: bad <dim> tag value \"$string\": should be 2 or 3."437 puts stderr "WARNING: bad <dim> tag value \"$string\": should be 1, 2 or 3." 374 438 return 0 375 439 } … … 471 535 return 0 472 536 } 473 if { $numCurvilinear < 2 } {474 puts stderr "WARNING: bad grid \"$path\": curvilinear grid must be 2D or 3D."475 return 0476 }477 537 set points [$_xmlobj get $path.grid.points] 478 538 if { $points == "" } { … … 480 540 return 0 481 541 } 482 if { ![info exists xNum] || ![info exists yNum]} {483 puts stderr "WARNING: bad grid \"$path\": invalid dimensions for curvilinear grid: missing <xdim> or <ydim>from grid description."542 if { ![info exists xNum] } { 543 puts stderr "WARNING: bad grid \"$path\": invalid dimensions for curvilinear grid: missing <xdim> from grid description." 484 544 return 0 485 545 } … … 493 553 set _dim 3 494 554 set _numPoints [expr $xNum * $yNum * $zNum] 555 set _numCells [expr ($xNum - 1) * ($yNum - 1) * ($zNum - 1)] 495 556 if { ($_numPoints*3) != $numCoords } { 496 puts stderr "WARNING: bad grid \"$path\": invalid grid: \# of points does not match dimensions <xdim> * <ydim> "557 puts stderr "WARNING: bad grid \"$path\": invalid grid: \# of points does not match dimensions <xdim> * <ydim> * <zdim>" 497 558 return 0 498 559 } … … 512 573 append out "\n" 513 574 set _vtkdata $out 514 } else {575 } elseif { [info exists yNum] } { 515 576 set _dim 2 516 577 set _numPoints [expr $xNum * $yNum] 578 set _numCells [expr ($xNum - 1) * ($yNum - 1)] 517 579 if { ($_numPoints*2) != $numCoords } { 518 puts stderr "WARNING: bad grid \"$path\": \# of points does not match dimensions <xdim> * <ydim> * <zdim>"580 puts stderr "WARNING: bad grid \"$path\": \# of points does not match dimensions <xdim> * <ydim>" 519 581 return 0 520 582 } … … 527 589 set _limits($axis) [$vector limits] 528 590 } 591 set _limits(z) [list 0 0] 529 592 $zv seq 0 0 [$xv length] 530 593 $all merge $xv $yv $zv … … 535 598 append out "\n" 536 599 set _vtkdata $out 600 } else { 601 set _dim 1 602 set _numPoints $xNum 603 set _numCells [expr $xNum - 1] 604 if { $_numPoints != $numCoords } { 605 puts stderr "WARNING: bad grid \"$path\": \# of points does not match <xdim>" 606 return 0 607 } 608 set _limits(x) [$xv limits] 609 set _limits(y) [list 0 0] 610 set _limits(z) [list 0 0] 611 $yv seq 0 0 [$xv length] 612 $zv seq 0 0 [$xv length] 613 $all merge $xv $yv $zv 614 append out "DATASET STRUCTURED_GRID\n" 615 append out "DIMENSIONS $xNum 1 1\n" 616 append out "POINTS $_numPoints double\n" 617 append out [$all range 0 end] 618 append out "\n" 619 set _vtkdata $out 537 620 } 538 621 blt::vector destroy $all $xv $yv $zv … … 541 624 if { $numRectilinear == 0 && $numUniform > 0} { 542 625 # This is the special case where all axes 2D/3D are uniform. 543 # This results in a STRUCTURE_POINTS 544 if { $_dim == 2 } { 626 # This results in a STRUCTURED_POINTS 627 if { $_dim == 1 } { 628 set xSpace [expr ($xMax - $xMin) / double($xNum - 1)] 629 set _numPoints $xNum 630 set _numCells [expr $xNum - 1] 631 append out "DATASET STRUCTURED_POINTS\n" 632 append out "DIMENSIONS $xNum 1 1\n" 633 append out "ORIGIN $xMin 0 0\n" 634 append out "SPACING $xSpace 0 0\n" 635 set _vtkdata $out 636 set _limits(x) [list $xMin $xMax] 637 set _limits(y) [list 0 0] 638 set _limits(z) [list 0 0] 639 } elseif { $_dim == 2 } { 545 640 set xSpace [expr ($xMax - $xMin) / double($xNum - 1)] 546 641 set ySpace [expr ($yMax - $yMin) / double($yNum - 1)] 547 642 set _numPoints [expr $xNum * $yNum] 643 set _numCells [expr ($xNum - 1) * ($yNum - 1)] 548 644 append out "DATASET STRUCTURED_POINTS\n" 549 645 append out "DIMENSIONS $xNum $yNum 1\n" … … 554 650 set _limits($axis) [list [set ${axis}Min] [set ${axis}Max]] 555 651 } 652 set _limits(z) [list 0 0] 556 653 } elseif { $_dim == 3 } { 557 654 set xSpace [expr ($xMax - $xMin) / double($xNum - 1)] … … 559 656 set zSpace [expr ($zMax - $zMin) / double($zNum - 1)] 560 657 set _numPoints [expr $xNum * $yNum * $zNum] 658 set _numCells [expr ($xNum - 1) * ($yNum - 1) * ($zNum - 1)] 561 659 append out "DATASET STRUCTURED_POINTS\n" 562 660 append out "DIMENSIONS $xNum $yNum $zNum\n" … … 584 682 } 585 683 set yv [blt::vector create \#auto] 586 if { [info exists yMin] } { 587 $yv seq $yMin $yMax $yNum 684 if { $_dim > 1 } { 685 if { [info exists yMin] } { 686 $yv seq $yMin $yMax $yNum 687 } else { 688 $yv set [$_xmlobj get $path.grid.ycoords] 689 set yMin [$yv min] 690 set yMax [$yv max] 691 set yNum [$yv length] 692 } 588 693 } else { 589 $yv set [$_xmlobj get $path.grid.ycoords] 590 set yMin [$yv min] 591 set yMax [$yv max] 592 set yNum [$yv length] 694 set yNum 1 593 695 } 594 696 set zv [blt::vector create \#auto] … … 607 709 if { $_dim == 3 } { 608 710 set _numPoints [expr $xNum * $yNum * $zNum] 711 set _numCells [expr ($xNum - 1) * ($yNum - 1) * ($zNum - 1)] 609 712 append out "DATASET RECTILINEAR_GRID\n" 610 713 append out "DIMENSIONS $xNum $yNum $zNum\n" … … 626 729 } elseif { $_dim == 2 } { 627 730 set _numPoints [expr $xNum * $yNum] 731 set _numCells [expr ($xNum - 1) * ($yNum - 1)] 628 732 append out "DATASET RECTILINEAR_GRID\n" 629 733 append out "DIMENSIONS $xNum $yNum 1\n" … … 641 745 } 642 746 } 747 set _limits(z) [list 0 0] 748 set _vtkdata $out 749 } elseif { $_dim == 1 } { 750 set _numPoints $xNum 751 set _numCells [expr $xNum - 1] 752 append out "DATASET RECTILINEAR_GRID\n" 753 append out "DIMENSIONS $xNum 1 1\n" 754 append out "X_COORDINATES $xNum double\n" 755 append out [$xv range 0 end] 756 append out "\n" 757 append out "Y_COORDINATES 1 double\n" 758 append out "0\n" 759 append out "Z_COORDINATES 1 double\n" 760 append out "0\n" 761 if { [info exists xMin] } { 762 set _limits(x) [list $xMin $xMax] 763 } 764 set _limits(y) [list 0 0] 765 set _limits(z) [list 0 0] 643 766 set _vtkdata $out 644 767 } else { … … 660 783 set _vtkdata $out 661 784 set _limits(x) [$xv limits] 662 set _limits(y) [$yv limits] 785 if { $_dim > 1 } { 786 set _limits(y) [$yv limits] 787 } else { 788 set _limits(y) [list 0 0] 789 } 663 790 if { $_dim == 3 } { 664 791 set _limits(z) [$zv limits] 792 } else { 793 set _limits(z) [list 0 0] 665 794 } 666 795 return 1 … … 692 821 if { $_dim == 3 } { 693 822 set _limits(z) [$zv limits] 823 } else { 824 set _limits(z) [list 0 0] 694 825 } 695 826 set _vtkdata $out … … 722 853 if { $_dim == 3 } { 723 854 set _limits(z) [$zv limits] 855 } else { 856 set _limits(z) [list 0 0] 724 857 } 725 858 set _vtkdata $out … … 750 883 set _limits(x) [$xv limits] 751 884 set _limits(y) [$yv limits] 752 if { $_dim == 3 } { 753 set _limits(z) [$zv limits] 754 } 885 set _limits(z) [$zv limits] 886 755 887 set _vtkdata $out 756 888 return 1 … … 780 912 set _limits(x) [$xv limits] 781 913 set _limits(y) [$yv limits] 782 if { $_dim == 3 } { 783 set _limits(z) [$zv limits] 784 } 914 set _limits(z) [$zv limits] 915 785 916 set _vtkdata $out 786 917 return 1 … … 810 941 set _limits(x) [$xv limits] 811 942 set _limits(y) [$yv limits] 812 if { $_dim == 3 } { 813 set _limits(z) [$zv limits] 814 } 943 set _limits(z) [$zv limits] 944 815 945 set _vtkdata $out 816 946 return 1 … … 840 970 set _limits(x) [$xv limits] 841 971 set _limits(y) [$yv limits] 842 if { $_dim == 3 } { 843 set _limits(z) [$zv limits] 844 } 972 set _limits(z) [$zv limits] 973 845 974 set _vtkdata $out 846 975 return 1 … … 854 983 set celltype [GetCellType $celltypes] 855 984 } 856 if { $_dim == 2 } { 857 set _numPoints [$xv length] 858 set data {} 859 set count 0 860 set _numCells 0 861 set celltypes {} 862 foreach line $lines { 863 set length [llength $line] 864 if { $length == 0 } { 865 continue 866 } 867 if { $numCellTypes > 1 } { 868 set cellType [GetCellType [lindex $cellTypes $_numCells]] 869 } 870 set numIndices [GetNumIndices $celltype] 871 if { $numIndices > 0 && $numIndices != $length } { 872 puts stderr "WARNING: bad unstructured grid \"$path\": wrong \# of indices specified for celltype $celltype on line \"$line\"" 873 return 0 874 } 875 append data " $numIndices $line\n" 876 lappend celltypes $celltype 877 incr count $length; # Include the indices 878 incr count; # and the number of indices 879 incr _numCells 880 } 881 append out "DATASET UNSTRUCTURED_GRID\n" 882 append out "POINTS $_numPoints double\n" 883 set all [blt::vector create \#auto] 884 $all merge $xv $yv $zv 885 append out [$all range 0 end] 886 blt::vector destroy $all 887 append out "CELLS $_numCells $count\n" 888 append out $data 889 append out "CELL_TYPES $_numCells\n" 890 append out $celltypes 891 set _limits(x) [$xv limits] 892 set _limits(y) [$yv limits] 985 986 set _numPoints [$xv length] 987 set data {} 988 set count 0 989 set _numCells 0 990 set celltypes {} 991 foreach line $lines { 992 set length [llength $line] 993 if { $length == 0 } { 994 continue 995 } 996 if { $numCellTypes > 1 } { 997 set cellType [GetCellType [lindex $cellTypes $_numCells]] 998 } 999 set numIndices [GetNumIndices $celltype] 1000 if { $numIndices > 0 && $numIndices != $length } { 1001 puts stderr "WARNING: bad unstructured grid \"$path\": wrong \# of indices specified for celltype $celltype on line \"$line\"" 1002 return 0 1003 } else { 1004 set numIndices $length 1005 } 1006 append data " $numIndices $line\n" 1007 lappend celltypes $celltype 1008 incr count $length; # Include the indices 1009 incr count; # and the number of indices 1010 incr _numCells 1011 } 1012 append out "DATASET UNSTRUCTURED_GRID\n" 1013 append out "POINTS $_numPoints double\n" 1014 set all [blt::vector create \#auto] 1015 $all merge $xv $yv $zv 1016 append out [$all range 0 end] 1017 blt::vector destroy $all 1018 append out "CELLS $_numCells $count\n" 1019 append out $data 1020 append out "CELL_TYPES $_numCells\n" 1021 append out $celltypes 1022 set _limits(x) [$xv limits] 1023 set _limits(y) [$yv limits] 1024 if { $_dim < 3 } { 1025 set _limits(z) [list 0 0] 893 1026 } else { 894 set _numPoints [$xv length] 895 896 set data {} 897 set count 0 898 set _numCells 0 899 foreach line $lines { 900 set length [llength $line] 901 if { $length == 0 } { 902 continue 903 } 904 if { $numCellTypes > 1 } { 905 set cellType [GetCellType [lindex $cellTypes $_numCells]] 906 } 907 set numIndices [GetNumIndices $celltype] 908 if { $numIndices > 0 && $numIndices != $length } { 909 puts stderr "WARNING: bad unstructured grid \"$path\": wrong \# of indices specified for celltype $celltype on line \"$line\"" 910 return 0 911 } 912 append data " $length $line\n" 913 incr count $length 914 incr count 915 incr _numCells 916 } 917 append out "DATASET UNSTRUCTURED_GRID\n" 918 append out "POINTS $_numPoints double\n" 919 set all [blt::vector create \#auto] 920 $all merge $xv $yv $zv 921 append out [$all range 0 end] 922 blt::vector destroy $all 923 append out "\n" 924 append out "CELLS $_numCells $count\n" 925 append out $data 926 append out "CELL_TYPES $_numCells\n" 927 append out $celltypes 928 set _limits(x) [$xv limits] 929 set _limits(y) [$yv limits] 930 set _limits(z) [$zv limits] 931 } 1027 set _limits(z) [$zv limits] 1028 } 1029 932 1030 set _vtkdata $out 933 1031 return 1 … … 969 1067 # <xcoords>, <ycoords>, <zcoords>. Split and convert into 970 1068 # 3 vectors, one for each coordinate. 971 if { $_dim == 2 } { 1069 if { $_dim == 1 } { 1070 set xcoords [$_xmlobj get $path.unstructured.xcoords] 1071 set ycoords [$_xmlobj get $path.unstructured.ycoords] 1072 set zcoords [$_xmlobj get $path.unstructured.zcoords] 1073 set data [$_xmlobj get $path.unstructured.points] 1074 if { $ycoords != "" } { 1075 put stderr "can't specify <ycoords> with a 1D mesh" 1076 return 0 1077 } 1078 if { $zcoords != "" } { 1079 put stderr "can't specify <zcoords> with a 1D mesh" 1080 return 0 1081 } 1082 if { $xcoords != "" } { 1083 set xv [blt::vector create \#auto] 1084 $xv set $xcoords 1085 } elseif { $data != "" } { 1086 Rappture::ReadPoints $data dim points 1087 if { $points == "" } { 1088 puts stderr "WARNING: bad unstructured grid \"$path\": no <points> found." 1089 return 0 1090 } 1091 if { $dim != 1 } { 1092 puts stderr "WARNING: bad unstructured grid \"$path\": \# of coordinates per point is \"$dim\": does not agree with dimension specified for mesh \"$_dim\"" 1093 return 0 1094 } 1095 set xv [blt::vector create \#auto] 1096 $xv set $points 1097 } else { 1098 puts stderr "WARNING: bad unstructured grid \"$path\": no points specified." 1099 return 0 1100 } 1101 set yv [blt::vector create \#auto] 1102 set zv [blt::vector create \#auto] 1103 $yv seq 0 0 [$xv length]; # Make an all zeroes vector. 1104 $zv seq 0 0 [$xv length]; # Make an all zeroes vector. 1105 } elseif { $_dim == 2 } { 972 1106 set xcoords [$_xmlobj get $path.unstructured.xcoords] 973 1107 set ycoords [$_xmlobj get $path.unstructured.ycoords] … … 1072 1206 # ---------------------------------------------------------------------- 1073 1207 itcl::body Rappture::Mesh::ReadNodesElements {path} { 1074 set type "nodeselements"1208 set _type "nodeselements" 1075 1209 set count 0 1076 1210 … … 1091 1225 set _limits(x) [$xv limits] 1092 1226 set _limits(y) [$yv limits] 1227 set _limits(z) [list 0 0] 1093 1228 # 2D Dataset. All Z coordinates are 0 1094 1229 $zv seq 0.0 0.0 $_numPoints
Note: See TracChangeset
for help on using the changeset viewer.