Changeset 5121 for branches/uq/gui/scripts/mesh.tcl
- Timestamp:
- Mar 11, 2015 10:26:15 AM (9 years ago)
- Location:
- branches/uq
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/uq
- Property svn:mergeinfo changed
-
branches/uq/gui/scripts/mesh.tcl
r4798 r5121 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 2 3 3 # ---------------------------------------------------------------------- … … 18 18 package require Itcl 19 19 20 namespace eval Rappture { 21 # forward declaration 20 namespace eval Rappture { 21 # forward declaration 22 22 } 23 23 24 24 itcl::class Rappture::Mesh { 25 private variable _xmlobj "" ; 26 private variable _mesh "" ; 27 private variable _dim 0;# Dimension of mesh (1, 2, or 3)28 private variable _type ""; 29 private variable _axis2units; 30 private variable _axis2labels; # 31 private variable _hints 32 private variable _limits ; # Array of mesh limits. Keys are33 34 private variable _numPoints 0 ; 35 private variable _numCells 0 ;# # of cells in mesh36 private variable _vtkdata ""; 25 private variable _xmlobj "" ; # Ref to XML obj with device data 26 private variable _mesh "" ; # Lib obj representing this mesh 27 private variable _dim 0; # Dimension of mesh (1, 2, or 3) 28 private variable _type ""; # Indicates the type of mesh. 29 private variable _axis2units; # System of units for x, y, z 30 private variable _axis2labels; # 31 private variable _hints 32 private variable _limits ; # Array of mesh limits. Keys are 33 # xmin, xmax, ymin, ymax, ... 34 private variable _numPoints 0 ; # # of points in mesh 35 private variable _numCells 0 ; # # of cells in mesh 36 private variable _vtkdata ""; # Mesh in vtk file format. 37 37 private variable _isValid 0; # Indicates if the mesh is valid. 38 constructor {xmlobj path} { 39 # defined below 40 } 41 destructor { 42 # defined below 38 constructor {xmlobj path} { 39 # defined below 40 } 41 destructor { 42 # defined below 43 43 } 44 44 public method points {} … … 58 58 public method vtkdata {{what -partial}} 59 59 public method type {} { 60 60 return $_type 61 61 } 62 62 public method numpoints {} { 63 63 return $_numPoints 64 64 } 65 65 public method numcells {} { 66 67 } 68 69 private common _xp2obj ; 70 private common _obj2ref ; 71 private variable _xv 72 private variable _yv 73 private variable _zv 74 private variable _xCoords "";# For the blt contour only75 private variable _yCoords "";# For the blt contour only76 66 return $_numCells 67 } 68 69 private common _xp2obj ; # used for fetch/release ref counting 70 private common _obj2ref ; # used for fetch/release ref counting 71 private variable _xv "" 72 private variable _yv "" 73 private variable _zv "" 74 private variable _xCoords ""; # For the blt contour only 75 private variable _yCoords ""; # For the blt contour only 76 77 77 private method ReadNodesElements {path} 78 private method GetCellCount { xNum yNum zNum } 79 private method GetDimension { path } 80 private method GetDouble { path } 81 private method GetInt { path } 82 private method InitHints {} 78 private method GetDimension { path } 79 private method GetDouble { path } 80 private method GetInt { path } 81 private method InitHints {} 83 82 private method ReadGrid { path } 84 83 private method ReadUnstructuredGrid { path } … … 165 164 foreach u $units axis { x y z } { 166 165 if { $u != "" } { 167 set _axis2units($axis) $u 166 set _axis2units($axis) $u 168 167 } else { 169 set _axis2units($axis) $first 168 set _axis2units($axis) $first 170 169 } 171 170 } … … 180 179 # Meshes comes in a variety of flavors 181 180 # 182 # Dimensionality is determined from the <dimension> tag. 181 # Dimensionality is determined from the <dimension> tag. 183 182 # 184 183 # <vtk> described mesh 185 184 # <element> + <node> definitions 186 # <grid> rectangular mesh 185 # <grid> rectangular mesh 187 186 # <unstructured> homogeneous cell type mesh. 188 187 … … 190 189 set subcount 0 191 190 foreach cname [$_mesh children] { 192 193 194 195 196 } 197 191 foreach type { vtk grid unstructured } { 192 if { $cname == $type } { 193 incr subcount 194 break 195 } 196 } 198 197 } 199 198 if {[$_mesh element "node"] != "" || … … 207 206 } 208 207 if { $subcount > 1 } { 209 208 puts stderr "WARNING: too many mesh types specified for \"$path\"." 210 209 return 211 210 } 212 211 set result 0 213 212 if { [$_mesh element "vtk"] != ""} { 214 213 set result [ReadVtk $path] 215 214 } elseif {[$_mesh element "grid"] != "" } { 216 215 set result [ReadGrid $path] 217 216 } elseif {[$_mesh element "unstructured"] != "" } { 218 217 set result [ReadUnstructuredGrid $path] 219 218 } elseif {[$_mesh element "node"] != "" && [$_mesh element "element"] != ""} { 220 219 set result [ReadNodesElements $path] … … 232 231 233 232 if { $_xCoords != "" } { 234 233 blt::vector destroy $_xCoords 235 234 } 236 235 if { $_yCoords != "" } { 237 238 } 239 } 240 241 # 242 # vtkdata -- 243 # 244 # 245 # 246 # 247 # 248 # 236 blt::vector destroy $_yCoords 237 } 238 } 239 240 # 241 # vtkdata -- 242 # 243 # This is called by the field object to generate a VTK file to send to 244 # the remote render server. Returns the vtkDataSet object containing 245 # (at this point) just the mesh. The field object doesn't know (or 246 # care) what type of mesh is used. The field object will add field 247 # arrays before generating output to send to the remote render server. 249 248 # 250 249 itcl::body Rappture::Mesh::vtkdata {{what -partial}} { 251 250 if {$what == "-full"} { 252 251 append out "# vtk DataFile Version 3.0\n" 253 254 252 append out "[hints label]\n" 253 append out "ASCII\n" 255 254 append out $_vtkdata 256 255 return $out … … 341 340 itcl::body Rappture::Mesh::mesh { {type "vtk"} } { 342 341 switch $type { 343 "vtk" { 344 345 346 default { 347 348 342 "vtk" { 343 return "" 344 } 345 default { 346 error "Requested mesh type \"$type\" is unknown." 347 } 349 348 } 350 349 } … … 427 426 } 428 427 } 428 foreach {key path} { 429 toolid tool.id 430 toolname tool.name 431 toolcommand tool.execute 432 tooltitle tool.title 433 toolrevision tool.version.application.revision 434 } { 435 set str [$_xmlobj get $path] 436 if { "" != $str } { 437 set _hints($key) $str 438 } 439 } 429 440 } 430 441 … … 432 443 set string [$_xmlobj get $path.dim] 433 444 if { $string == "" } { 434 445 puts stderr "WARNING: no tag <dim> found in mesh \"$path\"." 435 446 return 0 436 447 } … … 468 479 return 0 469 480 } 470 # Create a VTK file with the mesh in it. 481 # Create a VTK file with the mesh in it. 471 482 set _vtkdata [$_xmlobj get $path.vtk] 472 483 append out "# vtk DataFile Version 3.0\n" … … 500 511 } 501 512 502 itcl::body Rappture::Mesh::GetCellCount { xNum yNum zNum } {503 set numCells 1504 if { $xNum > 0 } {505 set numCells [expr $numCells * $xNum]506 }507 if { $yNum > 0 } {508 set numCells [expr $numCells * $yNum]509 }510 if { $zNum > 0 } {511 set numCells [expr $numCells * $zNum]512 }513 return $numCells514 }515 516 513 itcl::body Rappture::Mesh::ReadGrid { path } { 517 514 set _type "grid" … … 524 521 set numCurvilinear 0 525 522 foreach axis { x y z } { 526 527 528 529 530 531 532 533 534 523 set min [$_xmlobj get "$path.grid.${axis}axis.min"] 524 set max [$_xmlobj get "$path.grid.${axis}axis.max"] 525 set num [$_xmlobj get "$path.grid.${axis}axis.numpoints"] 526 set coords [$_xmlobj get "$path.grid.${axis}coords"] 527 set dim [$_xmlobj get "$path.grid.${axis}dim"] 528 if { $min != "" && $max != "" && $num != "" && $num > 0 } { 529 set ${axis}Min $min 530 set ${axis}Max $max 531 set ${axis}Num $num 535 532 if {$min > $max} { 536 puts stderr "ERROR: grid $axis min can't be greater than max"533 puts stderr "ERROR: grid $axis axis minimum larger than maximum" 537 534 return 0 538 535 } 539 540 541 542 543 536 incr numUniform 537 } elseif { $coords != "" } { 538 incr numRectilinear 539 set ${axis}Coords $coords 540 } elseif { $dim != "" } { 544 541 set ${axis}Num $dim 545 542 incr numCurvilinear … … 548 545 set _dim [expr $numRectilinear + $numUniform + $numCurvilinear] 549 546 if { $_dim == 0 } { 550 547 # No data found. 551 548 puts stderr "WARNING: bad grid \"$path\": no data found" 552 549 return 0 553 550 } 554 551 if { $numCurvilinear > 0 } { … … 563 560 return 0 564 561 } 565 562 if { ![info exists xNum] } { 566 563 puts stderr "WARNING: bad grid \"$path\": invalid dimensions for curvilinear grid: missing <xdim> from grid description." 567 564 return 0 … … 575 572 if { [info exists zNum] } { 576 573 set _dim 3 577 578 set _numCells [ GetCellCount $xNum $yNum $zNum]579 if { ($_numPoints *3) != $numCoords } {574 set _numPoints [expr $xNum * $yNum * $zNum] 575 set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1) * ($zNum > 1 ? ($zNum - 1) : 1)] 576 if { ($_numPoints*3) != $numCoords } { 580 577 puts stderr "WARNING: bad grid \"$path\": invalid grid: \# of points does not match dimensions <xdim> * <ydim> * <zdim>" 581 578 return 0 … … 586 583 } 587 584 $all split $xv $yv $zv 588 585 foreach axis {x y z} { 589 586 set vector [set ${axis}v] 590 587 set _limits($axis) [$vector limits] 591 592 593 594 588 } 589 append out "DATASET STRUCTURED_GRID\n" 590 append out "DIMENSIONS $xNum $yNum $zNum\n" 591 append out "POINTS $_numPoints double\n" 595 592 append out [$all range 0 end] 596 593 append out "\n" 597 594 set _vtkdata $out 598 595 } elseif { [info exists yNum] } { 599 596 set _dim 2 600 601 set _numCells [ GetCellCount $xNum $yNum 0]602 if { ($_numPoints *2) != $numCoords } {597 set _numPoints [expr $xNum * $yNum] 598 set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1)] 599 if { ($_numPoints*2) != $numCoords } { 603 600 puts stderr "WARNING: bad grid \"$path\": \# of points does not match dimensions <xdim> * <ydim>" 604 601 return 0 … … 608 605 return 0 609 606 } 610 607 foreach axis {x y} { 611 608 set vector [set ${axis}v] 612 609 set _limits($axis) [$vector limits] 613 610 } 614 611 set _limits(z) [list 0 0] 615 612 $zv seq 0 0 [$xv length] 616 613 $all merge $xv $yv $zv 617 618 619 614 append out "DATASET STRUCTURED_GRID\n" 615 append out "DIMENSIONS $xNum $yNum 1\n" 616 append out "POINTS $_numPoints double\n" 620 617 append out [$all range 0 end] 621 618 append out "\n" 622 619 set _vtkdata $out 623 620 } else { 624 621 set _dim 1 625 622 set _numPoints $xNum 626 set _numCells [ GetCellCount $xNum 0 0]623 set _numCells [expr $xNum - 1] 627 624 if { $_numPoints != $numCoords } { 628 625 puts stderr "WARNING: bad grid \"$path\": \# of points does not match <xdim>" … … 635 632 $zv seq 0 0 [$xv length] 636 633 $all merge $xv $yv $zv 637 638 639 634 append out "DATASET STRUCTURED_GRID\n" 635 append out "DIMENSIONS $xNum 1 1\n" 636 append out "POINTS $_numPoints double\n" 640 637 append out [$all range 0 end] 641 638 append out "\n" 642 643 639 set _vtkdata $out 640 } 644 641 blt::vector destroy $all $xv $yv $zv 645 642 return 1 646 643 } 647 644 if { $numRectilinear == 0 && $numUniform > 0} { 648 # This is the special case where all axes 2D/3D are uniform. 645 # This is the special case where all axes 2D/3D are uniform. 649 646 # This results in a STRUCTURED_POINTS 650 647 if { $_dim == 1 } { 651 set xSpacing 0 652 if { $xNum > 1 } { 653 set xSpacing [expr ($xMax - $xMin) / double($xNum - 1)] 654 } 655 set _numPoints $xNum 656 set _numCells [GetCellCount $xNum 0 0] 657 append out "DATASET STRUCTURED_POINTS\n" 658 append out "DIMENSIONS $xNum 1 1\n" 659 append out "ORIGIN $xMin 0 0\n" 660 append out "SPACING $xSpacing 0 0\n" 661 set _vtkdata $out 648 if {$xNum == 1} { 649 set xSpace 0 650 } else { 651 set xSpace [expr ($xMax - $xMin) / double($xNum - 1)] 652 } 653 set _numPoints $xNum 654 set _numCells [expr $xNum - 1] 655 append out "DATASET STRUCTURED_POINTS\n" 656 append out "DIMENSIONS $xNum 1 1\n" 657 append out "ORIGIN $xMin 0 0\n" 658 append out "SPACING $xSpace 0 0\n" 659 set _vtkdata $out 662 660 set _limits(x) [list $xMin $xMax] 663 661 set _limits(y) [list 0 0] 664 662 set _limits(z) [list 0 0] 665 } elseif { $_dim == 2 } { 666 set xSpacing 0 667 set ySpacing 0 668 if { $xNum > 1 } { 669 set xSpacing [expr ($xMax - $xMin) / double($xNum - 1)] 670 } 671 if { $yNum > 1 } { 672 set ySpacing [expr ($yMax - $yMin) / double($yNum - 1)] 673 } 674 set _numPoints [expr $xNum * $yNum] 675 set _numCells [GetCellCount $xNum $yNum 0] 676 append out "DATASET STRUCTURED_POINTS\n" 677 append out "DIMENSIONS $xNum $yNum 1\n" 678 append out "ORIGIN $xMin $yMin 0\n" 679 append out "SPACING $xSpacing $ySpacing 0\n" 680 set _vtkdata $out 681 foreach axis {x y} { 682 set _limits($axis) [list [set ${axis}Min] [set ${axis}Max]] 683 } 663 } elseif { $_dim == 2 } { 664 if {$xNum == 1} { 665 set xSpace 0 666 } else { 667 set xSpace [expr ($xMax - $xMin) / double($xNum - 1)] 668 } 669 if {$yNum == 1} { 670 set ySpace 0 671 } else { 672 set ySpace [expr ($yMax - $yMin) / double($yNum - 1)] 673 } 674 set _numPoints [expr $xNum * $yNum] 675 set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1)] 676 append out "DATASET STRUCTURED_POINTS\n" 677 append out "DIMENSIONS $xNum $yNum 1\n" 678 append out "ORIGIN $xMin $yMin 0\n" 679 append out "SPACING $xSpace $ySpace 0\n" 680 set _vtkdata $out 681 foreach axis {x y} { 682 set _limits($axis) [list [set ${axis}Min] [set ${axis}Max]] 683 } 684 684 set _limits(z) [list 0 0] 685 } elseif { $_dim == 3 } { 686 set xSpacing 0 687 set ySpacing 0 688 set zSpacing 0 689 if {$xNum > 1} { 690 set xSpacing [expr ($xMax - $xMin) / double($xNum - 1)] 691 } 692 if {$yNum > 1} { 693 set ySpacing [expr ($yMax - $yMin) / double($yNum - 1)] 694 } 695 if {$zNum > 1} { 696 set zSpacing [expr ($zMax - $zMin) / double($zNum - 1)] 697 } 698 set _numPoints [expr $xNum * $yNum * $zNum] 699 set _numCells [GetCellCount $xNum $yNum $zNum] 700 append out "DATASET STRUCTURED_POINTS\n" 701 append out "DIMENSIONS $xNum $yNum $zNum\n" 702 append out "ORIGIN $xMin $yMin $zMin\n" 703 append out "SPACING $xSpacing $ySpacing $zSpacing\n" 704 set _vtkdata $out 705 foreach axis {x y z} { 706 set _limits($axis) [list [set ${axis}Min] [set ${axis}Max]] 707 } 708 } else { 709 puts stderr "WARNING: bad grid \"$path\": bad dimension \"$_dim\"" 685 } elseif { $_dim == 3 } { 686 if {$xNum == 1} { 687 set xSpace 0 688 } else { 689 set xSpace [expr ($xMax - $xMin) / double($xNum - 1)] 690 } 691 if {$yNum == 1} { 692 set ySpace 0 693 } else { 694 set ySpace [expr ($yMax - $yMin) / double($yNum - 1)] 695 } 696 if {$zNum == 1} { 697 set zSpace 0 698 } else { 699 set zSpace [expr ($zMax - $zMin) / double($zNum - 1)] 700 } 701 set _numPoints [expr $xNum * $yNum * $zNum] 702 set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1) * ($zNum > 1 ? ($zNum - 1) : 1)] 703 append out "DATASET STRUCTURED_POINTS\n" 704 append out "DIMENSIONS $xNum $yNum $zNum\n" 705 append out "ORIGIN $xMin $yMin $zMin\n" 706 append out "SPACING $xSpace $ySpace $zSpace\n" 707 set _vtkdata $out 708 foreach axis {x y z} { 709 set _limits($axis) [list [set ${axis}Min] [set ${axis}Max]] 710 } 711 } else { 712 puts stderr "WARNING: bad grid \"$path\": bad dimension \"$_dim\"" 710 713 return 0 711 712 714 } 715 return 1 713 716 } 714 717 # This is the hybrid case. Some axes are uniform, others are nonuniform. 715 718 set xv [blt::vector create \#auto] 716 719 if { [info exists xMin] } { 717 718 } else { 719 720 721 722 720 $xv seq $xMin $xMax $xNum 721 } else { 722 $xv set [$_xmlobj get $path.grid.xcoords] 723 set xMin [$xv min] 724 set xMax [$xv max] 725 set xNum [$xv length] 723 726 } 724 727 set yv [blt::vector create \#auto] … … 737 740 set zv [blt::vector create \#auto] 738 741 if { $_dim == 3 } { 739 740 741 742 743 744 745 746 747 } else { 748 742 if { [info exists zMin] } { 743 $zv seq $zMin $zMax $zNum 744 } else { 745 $zv set [$_xmlobj get $path.grid.zcoords] 746 set zMin [$zv min] 747 set zMax [$zv max] 748 set zNum [$zv length] 749 } 750 } else { 751 set zNum 1 749 752 } 750 753 if { $_dim == 3 } { 751 752 set _numCells [ GetCellCount $xNum $yNum $zNum]753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 754 set _numPoints [expr $xNum * $yNum * $zNum] 755 set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1) * ($zNum > 1 ? ($zNum - 1) : 1)] 756 append out "DATASET RECTILINEAR_GRID\n" 757 append out "DIMENSIONS $xNum $yNum $zNum\n" 758 append out "X_COORDINATES $xNum double\n" 759 append out [$xv range 0 end] 760 append out "\n" 761 append out "Y_COORDINATES $yNum double\n" 762 append out [$yv range 0 end] 763 append out "\n" 764 append out "Z_COORDINATES $zNum double\n" 765 append out [$zv range 0 end] 766 append out "\n" 767 set _vtkdata $out 768 foreach axis {x y z} { 769 if { [info exists ${axis}Min] } { 770 set _limits($axis) [list [set ${axis}Min] [set ${axis}Max]] 771 } 772 } 770 773 } elseif { $_dim == 2 } { 771 772 set _numCells [ GetCellCount $xNum $yNum 0]773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 774 set _numPoints [expr $xNum * $yNum] 775 set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1)] 776 append out "DATASET RECTILINEAR_GRID\n" 777 append out "DIMENSIONS $xNum $yNum 1\n" 778 append out "X_COORDINATES $xNum double\n" 779 append out [$xv range 0 end] 780 append out "\n" 781 append out "Y_COORDINATES $yNum double\n" 782 append out [$yv range 0 end] 783 append out "\n" 784 append out "Z_COORDINATES 1 double\n" 785 append out "0\n" 786 foreach axis {x y} { 787 if { [info exists ${axis}Min] } { 788 set _limits($axis) [list [set ${axis}Min] [set ${axis}Max]] 789 } 790 } 788 791 set _limits(z) [list 0 0] 789 792 set _vtkdata $out 790 793 } elseif { $_dim == 1 } { 791 794 set _numPoints $xNum 792 set _numCells [ GetCellCount $xNum 0 0]793 794 795 796 797 798 799 800 801 795 set _numCells [expr $xNum - 1] 796 append out "DATASET RECTILINEAR_GRID\n" 797 append out "DIMENSIONS $xNum 1 1\n" 798 append out "X_COORDINATES $xNum double\n" 799 append out [$xv range 0 end] 800 append out "\n" 801 append out "Y_COORDINATES 1 double\n" 802 append out "0\n" 803 append out "Z_COORDINATES 1 double\n" 804 append out "0\n" 802 805 if { [info exists xMin] } { 803 806 set _limits(x) [list $xMin $xMax] … … 805 808 set _limits(y) [list 0 0] 806 809 set _limits(z) [list 0 0] 807 808 } else { 809 810 set _vtkdata $out 811 } else { 812 puts stderr "WARNING: bad grid \"$path\": invalid dimension \"$_dim\"" 810 813 return 0 811 814 } 812 blt::vector destroy $xv $yv $zv 815 blt::vector destroy $xv $yv $zv 813 816 return 1 814 817 } … … 844 847 set celltypes {} 845 848 foreach { a b c } $triangles { 846 847 848 849 append data " 3 $a $b $c\n" 850 append celltypes "5\n" 851 incr _numCells 849 852 } 850 853 append out "DATASET UNSTRUCTURED_GRID\n" 851 854 append out "POINTS $_numPoints double\n" 852 855 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 853 856 append out " $x $y $z\n" 854 857 } 855 858 set count [expr $_numCells * 4] … … 876 879 set celltypes {} 877 880 foreach { a b c d } $quads { 878 879 880 881 append data " 4 $a $b $c $d\n" 882 append celltypes "9\n" 883 incr _numCells 881 884 } 882 885 append out "DATASET UNSTRUCTURED_GRID\n" 883 886 append out "POINTS $_numPoints double\n" 884 887 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 885 888 append out " $x $y $z\n" 886 889 } 887 890 set count [expr $_numCells * 5] … … 913 916 continue 914 917 } 915 916 918 append data " $numIndices $line\n" 919 incr _numCells 917 920 set count [expr $count + $numIndices + 1] 918 921 } … … 920 923 append out "POINTS $_numPoints double\n" 921 924 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 922 925 append out " $x $y $z\n" 923 926 } 924 927 append out "VERTICES $_numCells $count\n" … … 947 950 continue 948 951 } 949 950 952 append data " $numIndices $line\n" 953 incr _numCells 951 954 set count [expr $count + $numIndices + 1] 952 955 } … … 954 957 append out "POINTS $_numPoints double\n" 955 958 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 956 959 append out " $x $y $z\n" 957 960 } 958 961 append out "LINES $_numCells $count\n" … … 981 984 continue 982 985 } 983 984 986 append data " $numIndices $line\n" 987 incr _numCells 985 988 set count [expr $count + $numIndices + 1] 986 989 } … … 988 991 append out "POINTS $_numPoints double\n" 989 992 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 990 993 append out " $x $y $z\n" 991 994 } 992 995 append out "POLYGONS $_numCells $count\n" … … 1015 1018 continue 1016 1019 } 1017 1018 1020 append data " $numIndices $line\n" 1021 incr _numCells 1019 1022 set count [expr $count + $numIndices + 1] 1020 1023 } … … 1022 1025 append out "POINTS $_numPoints double\n" 1023 1026 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 1024 1027 append out " $x $y $z\n" 1025 1028 } 1026 1029 append out "TRIANGLE_STRIPS $_numCells $count\n" … … 1044 1047 set celltypes {} 1045 1048 foreach { a b c d } $tetras { 1046 1047 1048 1049 append data " 4 $a $b $c $d\n" 1050 append celltypes "10\n" 1051 incr _numCells 1049 1052 } 1050 1053 append out "DATASET UNSTRUCTURED_GRID\n" 1051 1054 append out "POINTS $_numPoints double\n" 1052 1055 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 1053 1056 append out " $x $y $z\n" 1054 1057 } 1055 1058 set count [expr $_numCells * 5] … … 1073 1076 set celltypes {} 1074 1077 foreach { a b c d e f g h } $hexas { 1075 1076 1077 1078 append data " 8 $a $b $c $d $e $f $g $h\n" 1079 append celltypes "12\n" 1080 incr _numCells 1078 1081 } 1079 1082 append out "DATASET UNSTRUCTURED_GRID\n" 1080 1083 append out "POINTS $_numPoints double\n" 1081 1084 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 1082 1085 append out " $x $y $z\n" 1083 1086 } 1084 1087 set count [expr $_numCells * 9] … … 1102 1105 set celltypes {} 1103 1106 foreach { a b c d e f } $wedges { 1104 1105 1106 1107 append data " 6 $a $b $c $d $e $f\n" 1108 append celltypes "13\n" 1109 incr _numCells 1107 1110 } 1108 1111 append out "DATASET UNSTRUCTURED_GRID\n" 1109 1112 append out "POINTS $_numPoints double\n" 1110 1113 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 1111 1114 append out " $x $y $z\n" 1112 1115 } 1113 1116 set count [expr $_numCells * 7] … … 1131 1134 set celltypes {} 1132 1135 foreach { a b c d e } $pyramids { 1133 1134 1135 1136 append data " 5 $a $b $c $d $e\n" 1137 append celltypes "14\n" 1138 incr _numCells 1136 1139 } 1137 1140 append out "DATASET UNSTRUCTURED_GRID\n" 1138 1141 append out "POINTS $_numPoints double\n" 1139 1142 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 1140 1143 append out " $x $y $z\n" 1141 1144 } 1142 1145 set count [expr $_numCells * 6] … … 1150 1153 1151 1154 set _vtkdata $out 1152 return 1 1155 return 1 1153 1156 } 1154 1157 … … 1217 1220 # Step 1: Verify that there's only one cell tag of any kind. 1218 1221 set numCells 0 1219 foreach type { 1222 foreach type { 1220 1223 cells 1221 hexahedrons 1222 lines 1223 polygons 1224 pyramids 1224 hexahedrons 1225 lines 1226 polygons 1227 pyramids 1225 1228 quads 1226 tetrahedrons 1227 triangles 1229 tetrahedrons 1230 triangles 1228 1231 trianglestrips 1229 vertices 1230 wedges 1232 vertices 1233 wedges 1231 1234 } { 1232 1235 set data [$_xmlobj get $path.unstructured.$type] … … 1238 1241 set celltypes [$_xmlobj get $path.unstructured.celltypes] 1239 1242 if { $numCells == 0 && $celltypes != "" } { 1240 1243 puts stderr "WARNING: bad unstuctured grid \"$path\": no <cells> description found." 1241 1244 return 0 1242 1245 } … … 1245 1248 return 0 1246 1249 } 1247 foreach type { cells 1248 vertices lines polygons trianglestrips 1249 triangles quads 1250 tetrahedrons hexahedrons wedges pyramids } { 1250 foreach type { 1251 cells 1252 hexahedrons 1253 lines 1254 polygons 1255 pyramids 1256 quads 1257 tetrahedrons 1258 triangles 1259 trianglestrips 1260 vertices 1261 wedges 1262 } { 1251 1263 set data [$_xmlobj get $path.unstructured.$type] 1252 1264 if { $data != "" } { … … 1254 1266 } 1255 1267 } 1256 # Step 2: Allow points to be specified as <points> or 1268 # Step 2: Allow points to be specified as <points> or 1257 1269 # <xcoords>, <ycoords>, <zcoords>. Split and convert into 1258 1270 # 3 vectors, one for each coordinate. … … 1402 1414 set data {} 1403 1415 foreach cname [$_xmlobj children -type node $path] { 1404 1405 } 1416 append data "[$_xmlobj get $path.$cname]\n" 1417 } 1406 1418 Rappture::ReadPoints $data _dim points 1407 1419 if { $_dim == 2 } { 1408 1409 1410 1411 1412 1413 1414 1420 set all [blt::vector create \#auto] 1421 set xv [blt::vector create \#auto] 1422 set yv [blt::vector create \#auto] 1423 set zv [blt::vector create \#auto] 1424 $all set $points 1425 $all split $xv $yv 1426 set _numPoints [$xv length] 1415 1427 set _limits(x) [$xv limits] 1416 1428 set _limits(y) [$yv limits] 1417 1429 set _limits(z) [list 0 0] 1418 1419 1420 1421 1422 1430 # 2D Dataset. All Z coordinates are 0 1431 $zv seq 0.0 0.0 $_numPoints 1432 $all merge $xv $yv $zv 1433 set points [$all range 0 end] 1434 blt::vector destroy $all $xv $yv $zv 1423 1435 } elseif { $_dim == 3 } { 1424 1425 1426 1427 1428 1429 1430 1436 set all [blt::vector create \#auto] 1437 set xv [blt::vector create \#auto] 1438 set yv [blt::vector create \#auto] 1439 set zv [blt::vector create \#auto] 1440 $all set $points 1441 $all split $xv $yv $zv 1442 set _numPoints [$xv length] 1431 1443 set _limits(x) [$xv limits] 1432 1444 set _limits(y) [$yv limits] 1433 1445 set _limits(z) [$zv limits] 1434 1435 1436 } else { 1437 1446 set points [$all range 0 end] 1447 blt::vector destroy $all $xv $yv $zv 1448 } else { 1449 error "bad dimension \"$_dim\" for nodes mesh" 1438 1450 } 1439 1451 array set node2celltype { 1440 1441 1442 1443 1444 1452 3 5 1453 4 10 1454 8 12 1455 6 13 1456 5 14 1445 1457 } 1446 1458 set count 0 … … 1451 1463 foreach cname [$_xmlobj children -type element $path] { 1452 1464 set nodeList [$_mesh get $cname.nodes] 1453 1454 1455 1456 1457 1458 1459 1465 set numNodes [llength $nodeList] 1466 if { ![info exists node2celltype($numNodes)] } { 1467 puts stderr "WARNING: bad nodes/elements mesh \$path\": unknown number of indices \"$_numNodes\": should be 3, 4, 5, 6, or 8" 1468 return 0 1469 } 1470 set celltype $node2celltype($numNodes) 1471 append celltypes " $celltype\n" 1460 1472 if { $celltype == 12 } { 1461 1473 # Formerly used voxels instead of hexahedrons. We're converting … … 1467 1479 } 1468 1480 set nodeList $newList 1469 } 1470 1471 1472 incr count $numNodes 1473 incr count;# One extra for the VTK celltype id.1481 } 1482 append data " $numNodes $nodeList\n" 1483 incr _numCells 1484 incr count $numNodes 1485 incr count; # One extra for the VTK celltype id. 1474 1486 } 1475 1487 … … 1484 1496 append out "\n" 1485 1497 set _vtkdata $out 1486 set _isValid 1 1498 set _isValid 1 1487 1499 } 1488 1500
Note: See TracChangeset
for help on using the changeset viewer.