Changeset 3288 for branches/Rappture 1.2/gui/scripts/mesh.tcl
- Timestamp:
- Feb 8, 2013 2:20:22 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Rappture 1.2/gui/scripts/mesh.tcl
r3271 r3288 65 65 private common _xp2obj ; # used for fetch/release ref counting 66 66 private common _obj2ref ; # used for fetch/release ref counting 67 67 private variable _isValid 0 68 68 private variable _vtkoutput "" 69 69 private variable _vtkreader "" … … 77 77 private variable _yValues ""; # For the blt contour only 78 78 79 private method GetDimension {} 80 private method GetDouble { path } 81 private method GetInt { path } 82 private method ReadBltCloudMesh { path } 83 private method ReadBltGridMesh { path } 84 private method ReadBltMesh { path } 85 private method ReadBltTriangleMesh { path } 86 private method ReadCells { xmlobj path } 79 87 private method ReadCloud { xmlobj path } 80 88 private method ReadGrid { xmlobj path } 81 89 private method ReadTriangles { xmlobj path } 82 90 private method ReadVtk { xmlobj path } 83 private method GetBltCloudMesh { path }84 private method GetBltGridMesh { path }85 private method GetBltTriangleMesh { path }86 private method GetBltMesh { path }87 private method GetDouble { path }88 private method GetInt { path }89 private method GetDimension {}90 91 private method _buildNodesElements {xmlobj path} 91 92 } … … 171 172 # <element> + <node> definitions 172 173 # <cloud> x,y coordinates or x,y,z coordinates 173 # <unirect> uniform rectangular grid (2D) or cubes (3D) 174 # <rectangle> non-uniform rectangular mesh 174 # <grid> rectangular mesh 175 # <triangles> triangular mesh 176 # <cells> homogeneous cell type mesh. 177 178 # Check that only one mesh type was defined. 179 set subcount 0 180 foreach cname [$_mesh children] { 181 foreach type { vtk cloud grid triangles cells } { 182 if { [$_mesh element $type] != "" } { 183 incr subcount 184 break 185 } 186 } 187 } 188 set elemcount 0 189 foreach cname [$_mesh children] { 190 foreach type { node element } { 191 if { [$_mesh element $type] != "" } { 192 incr elemcount 193 break 194 } 195 } 196 } 197 if { $elemcount > 0 } { 198 incr $subcount 199 } 200 if { $subcount > 1 } { 201 puts stderr "too many mesh types specified: picking first found." 202 } 175 203 if { [$_mesh element vtk] != ""} { 176 204 ReadVtk $xmlobj $path … … 181 209 } elseif {[$_mesh element triangles] != "" } { 182 210 ReadTriangles $xmlobj $path 211 } elseif {[$_mesh element cells] != "" } { 212 ReadCells $xmlobj $path 183 213 } elseif {[$_mesh element node] != "" && [$_mesh element element] != ""} { 184 214 ReadNodesElements $xmlobj $path 185 } else {186 error "can't find mesh data in $path"187 215 } 188 216 } … … 296 324 "blt" { 297 325 if { $_bltmesh == "" } { 298 GetBltMesh326 ReadBltMesh 299 327 return $_bltmesh 300 328 } … … 558 586 set _vtkdata $out 559 587 foreach axis {x y z} { 560 set vector [set ${axis}v]588 set vector [set ${axis}v] 561 589 set _limits(${axis}min) [${vector} min] 562 590 set _limits(${axis}max) [${vector} max] … … 587 615 set _vtkpoints [$_vtkoutput GetPointData] 588 616 file delete $tmpfile 617 set _isValid 1 589 618 } 590 619 … … 614 643 } 615 644 if { $numNonUniform == 0 && $numUniform > 0 } { 616 # Specially handle the case where all axes are uniform. 617 # This means we can use a vtkImageData to represent the data 618 # instead of a vtkRectlinearGrid. 619 # Vtk points are always 3D 645 # Specially handle the case where all axes are uniform. This means we 646 # can use a vtkImageData to represent the data instead of a 647 # vtkRectlinearGrid. Vtk points are always 3D 620 648 if { $_dim == 2 } { 621 649 append out "DATASET STRUCTURED_POINTS\n" … … 650 678 error "bad dimension of mesh \"$_dim\"" 651 679 } 680 set _isValid 1 652 681 return 1 653 682 } … … 729 758 } 730 759 blt::vector destroy $xv $yv $zv 760 set _isValid 1 731 761 return 1 762 } 763 764 itcl::body Rappture::Mesh::ReadCells { xmlobj path } { 765 set _type "cells" 766 set celltype [$xmlobj get $path.cells.celltype] 767 array set type2vertices { 768 triangle 3 769 quad 4 770 tetraheadron 4 771 voxel 8 772 hexaheadron 8 773 wedge 6 774 pyramid 5 775 } 776 array set type2dim { 777 triangle 2 778 quad 2 779 tetraheadron 3 780 voxel 3 781 hexaheadron 3 782 wedge 3 783 pyramid 3 784 } 785 array set type2vtkid { 786 triangle 5 787 quad 9 788 tetraheadron 10 789 voxel 11 790 hexaheadron 12 791 wedge 13 792 pyramid 14 793 } 794 if { ![info exists type2vertices($celltype)] } { 795 puts stderr "unknown celltype \"$celltype\"" 796 return 0 797 } 798 set numVertices $type2vertices($celltype) 799 set _dim $type2dim($celltype) 800 set vtkid $type2vtkid($celltype) 801 802 set points [$xmlobj get $path.cells.points] 803 set xvalues [$xmlobj get $path.cells.xvalues] 804 set yvalues [$xmlobj get $path.cells.yvalues] 805 if { $_dim == 2 } { 806 if { $xvalues != "" && $yvalues != "" } { 807 set xv [blt::vector create \#auto] 808 set yv [blt::vector create \#auto] 809 $xv set $xvalues 810 $yx set $yvalues 811 } elseif { $points != "" } { 812 set all [blt::vector create \#auto] 813 $all set $points 814 set xv [blt::vector create \#auto] 815 set yv [blt::vector create \#auto] 816 $all split $xv $yv 817 } else { 818 puts stderr "missing either xvalues, yvalues, or points for $celltype cell mesh" 819 return 0 820 } 821 set _numPoints [$xv length] 822 set numIndices 0 823 set data {} 824 set indices [$xmlobj get $path.cells.indices] 825 foreach { a b c } $indices { 826 append data " $numVertices $a $b $c\n" 827 incr numIndices 828 } 829 set celltypes {} 830 for { set i 0 } { $i < $numIndices } { incr i } { 831 append celltypes "$vtkid\n" 832 } 833 append out "DATASET UNSTRUCTURED_GRID\n" 834 append out "POINTS $_numPoints float\n" 835 foreach x [$xv range 0 end] y [$yv range 0 end] { 836 append out " $x $y 0\n" 837 } 838 append out "CELLS $numIndices [expr $numIndices * 4]\n" 839 append out $data 840 append out "CELL_TYPES $numIndices\n" 841 append out $celltypes 842 append out "POINT_DATA $_numPoints\n" 843 set _limits(xmin) [$xv min] 844 set _limits(xmax) [$xv max] 845 set _limits(ymin) [$yv min] 846 set _limits(ymax) [$yv max] 847 } else { 848 set zvalues [$xmlobj get $path.cells.zvalues] 849 if { $xvalues != "" && $yvalues != "" && $zvalues != "" } { 850 set xv [blt::vector create \#auto] 851 set yv [blt::vector create \#auto] 852 set zv [blt::vector create \#auto] 853 $xv set $xvalues 854 $yx set $yvalues 855 $zx set $yvalues 856 } elseif { $points != "" } { 857 set all [blt::vector create \#auto] 858 $all set $points 859 set xv [blt::vector create \#auto] 860 set yv [blt::vector create \#auto] 861 set zv [blt::vector create \#auto] 862 $all split $xv $yv $zv 863 } else { 864 puts stderr "missing either xvalues, yvalues, zvalues, or points for $celltype cell mesh" 865 return 0 866 } 867 set _numPoints [$xv length] 868 set data {} 869 set indices [$xmlobj get $path.cells.indices] 870 set numIndices 0 871 foreach { a b c } $indices { 872 append data " $numVertices $a $b $c\n" 873 incr numIndices 874 } 875 set celltypes {} 876 for { set i 0 } { $i < $numIndices } { incr i } { 877 append celltypes "$vtkid\n" 878 } 879 append out "DATASET UNSTRUCTURED_GRID\n" 880 append out "POINTS $_numPoints float\n" 881 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 882 append out " $x $y $z\n" 883 } 884 append out "CELLS $numIndices [expr $numIndices * 4]\n" 885 append out $data 886 append out "CELL_TYPES $numIndices\n" 887 append out $celltypes 888 append out "POINT_DATA $_numPoints\n" 889 set _limits(xmin) [$xv min] 890 set _limits(xmax) [$xv max] 891 set _limits(ymin) [$yv min] 892 set _limits(ymax) [$yv max] 893 set _limits(zmin) [$zv min] 894 set _limits(zmax) [$zv max] 895 } 896 set _vtkdata $out 897 set _isValid 1 732 898 } 733 899 … … 784 950 set _limits(ymax) [$yv max] 785 951 set _vtkdata $out 786 } 787 788 itcl::body Rappture::Mesh::GetBltGridMesh { path } { 952 set _isValid 1 953 } 954 955 itcl::body Rappture::Mesh::ReadBltGridMesh { path } { 789 956 if { $_dim != 2 } { 790 957 error "must be 2D mesh for BLT" … … 841 1008 } 842 1009 843 itcl::body Rappture::Mesh:: GetBltTriangleMesh { path } {1010 itcl::body Rappture::Mesh::ReadBltTriangleMesh { path } { 844 1011 set _xv [blt::vector create \#auto] 845 1012 set _yv [blt::vector create \#auto] … … 856 1023 } 857 1024 858 itcl::body Rappture::Mesh:: GetBltCloudMesh { path } {1025 itcl::body Rappture::Mesh::ReadBltCloudMesh { path } { 859 1026 # Read the points into a vector and split them into individual coordinate 860 1027 # arrays. … … 883 1050 } 884 1051 885 itcl::body Rappture::Mesh:: GetBltMesh { path } {1052 itcl::body Rappture::Mesh::ReadBltMesh { path } { 886 1053 if { $_dim != 2 } { 887 1054 error "dimension of mesh $_dim is not 2" … … 889 1056 switch -- $_type { 890 1057 "cloud" { 891 set _bltmesh [ GetBltCloudMesh $path ]1058 set _bltmesh [ReadBltCloudMesh $path ] 892 1059 } 893 1060 "unirect" { 894 set _bltmesh [ GetBltRegularMesh $path]1061 set _bltmesh [ReadBltRegularMesh $path] 895 1062 } 896 1063 "rectangle" { 897 set _bltmesh [ GetBltIrregularMesh $path]1064 set _bltmesh [ReadBltIrregularMesh $path] 898 1065 } 899 1066 "triangle" { 900 set _bltmesh [ GetBltTriangleMesh $path]1067 set _bltmesh [ReadBltTriangleMesh $path] 901 1068 } 902 1069 default { … … 989 1156 } 990 1157 set _vtkdata $out 991 } 1158 set _isValid 1 1159 }
Note: See TracChangeset
for help on using the changeset viewer.