- Timestamp:
- Feb 19, 2013, 3:15:17 PM (12 years ago)
- Location:
- branches/Rappture 1.2/gui/scripts
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Rappture 1.2/gui/scripts/cloud.tcl
r3289 r3310 160 160 append out "POINTS $_numPoints float\n" 161 161 append out $_points 162 append out "POINT_DATA $_numPoints\n"163 162 set _vtkdata $out 164 163 } -
branches/Rappture 1.2/gui/scripts/field.tcl
r3306 r3310 102 102 private variable _comp2cntls ;# maps component name => x,y control points 103 103 private variable _comp2extents 104 private variable _comp2limits 104 private variable _comp2limits; # Array of limits per component 105 105 private variable _type "" 106 106 private variable _comp2flowhints … … 424 424 x - xlin - xlog { 425 425 set axis x 426 set axisMax $limits(xmax) 427 set axisMin $limits(xmin) 426 foreach {axisMin axisMax} $limits(x) break 428 427 } 429 428 y - ylin - ylog { 430 429 set axis y 431 set axisMax $limits(ymax) 432 set axisMin $limits(ymin) 430 foreach {axisMin axisMax} $limits(y) break 433 431 } 434 432 z - zlin - zlog { 435 433 set axis y 436 set axisMax $limits(zmax) 437 set axisMin $limits(zmin) 434 foreach {axisMin axisMax} $limits(z) break 438 435 } 439 436 v - vlin - vlog { 440 437 set axis v 441 set axisMax $limits(vmax) 442 set axisMin $limits(vmin) 438 foreach {axisMin axisMax} $limits(v) break 439 } 440 default { 441 if { ![info exists limits($which)] } { 442 error "limits: unknown axis \"$which\"" 443 } 444 set axis v 445 foreach {axisMin axisMax} $limits($which) break 443 446 } 444 447 } … … 1061 1064 if { $_viewer == "" } { 1062 1065 if { $_dim == 2 } { 1063 set _viewer heightmap1066 set _viewer contour 1064 1067 } else { 1065 1068 set _viewer isosurface … … 1067 1070 } 1068 1071 set _comp2dims($cname) ${_dim}D 1069 lappend limits xmin $xmin xmax $xmax ymin $ymin ymax $ymax 1072 lappend limits x [list $xmin $xmax] 1073 lappend limits y [list $ymin $ymax] 1074 lappend limits z [list $zmin $zmax] 1070 1075 set dataAttrs [$dataset GetPointData] 1071 1076 if { $dataAttrs == ""} { … … 1083 1088 set name [$dataAttrs GetArrayName $i] 1084 1089 foreach {min max} [$array GetRange] break 1085 lappend limits $name -min $min $name-max $max1090 lappend limits $name [list $min $max] 1086 1091 lappend _fieldNames $name 1087 1092 lappend _fieldUnits "" … … 1089 1094 } 1090 1095 } 1091 puts stderr "_fieldNames=$_fieldNames" 1092 lappend limits vmin $vmin vmax $vmax 1096 lappend limits v [list $vmin $vmax] 1093 1097 set _comp2limits($cname) $limits 1094 1098 $reader Delete … … 1097 1101 1098 1102 # 1099 # vtkdata ?<cname>?1103 # vtkdata -- 1100 1104 # 1101 1105 # Returns a string representing the mesh and field data for a specific 1102 # component in basicVTK file format.1106 # component in the legacy VTK file format. 1103 1107 # 1104 1108 itcl::body Rappture::Field::vtkdata {cname} { … … 1132 1136 append out "ASCII\n" 1133 1137 append out [$mesh vtkdata] 1138 append out "POINT_DATA [$vector length]\n" 1134 1139 append out "SCALARS $label float\n" 1135 1140 append out "LOOKUP_TABLE default\n" … … 1140 1145 } 1141 1146 1147 # 1148 # BuildPointsOnMesh -- 1149 # 1150 # Parses the field XML description to build a mesh and values vector 1151 # representing the field. Right now we handle the deprecated types 1152 # of "cloud", "unirect2d", and "unirect3d" (mostly for flows). 1153 # 1142 1154 itcl::body Rappture::Field::BuildPointsOnMesh {cname} { 1143 1155 # … … 1243 1255 set label [hints zlabel] 1244 1256 if { $label != "" } { 1257 set _fieldLabels $label 1245 1258 set _fieldNames $label 1246 1259 regsub -all { } $_fieldNames {_} _fieldNames 1247 set _fieldLabels $label1248 1260 } 1249 1261 set units [hints zunits] … … 1251 1263 set _fieldUnits $units 1252 1264 } 1265 array unset _comp2limits $cname 1266 lappend _comp2limits($cname) x [$mesh limits x] 1267 lappend _comp2limits($cname) y [$mesh limits y] 1268 lappend _comp2limits($cname) $label [$vector limits] 1269 lappend _comp2limits($cname) v [$vector limits] 1253 1270 return 1254 1271 } elseif {$_dim == 3} { … … 1283 1300 set _fieldUnits $units 1284 1301 } 1302 lappend _comp2limits($cname) x [$mesh limits x] 1303 lappend _comp2limits($cname) y [$mesh limits y] 1304 lappend _comp2limits($cname) z [$mesh limits z] 1305 lappend _comp2limits($cname) $label [$vector limits] 1306 lappend _comp2limits($cname) v [$vector limits] 1285 1307 return 1286 1308 } … … 1321 1343 fconfigure $f -translation binary -encoding binary 1322 1344 set vtkdata [read $f] 1345 close $f 1323 1346 file delete $tmpfile 1324 close $f1325 1347 return $vtkdata 1326 1348 } -
branches/Rappture 1.2/gui/scripts/mesh.tcl
r3304 r3310 56 56 57 57 private method ReadNodesElements {xmlobj path} 58 private method _buildRectMesh {xmlobj path}59 private method _getVtkElement {npts}60 61 private variable _pts2elem ; # maps # points => vtk element62 58 63 59 private variable _points "" ; # name of vtkPointData object … … 89 85 private method ReadTriangles { xmlobj path } 90 86 private method ReadVtk { xmlobj path } 91 private method _buildNodesElements {xmlobj path}92 87 } 93 88 … … 162 157 } 163 158 164 foreach lim {xmin xmax ymin ymax zmin zmax} {165 set _limits($lim) ""166 }167 159 # Meshes comes in a variety of flavors 168 160 # … … 241 233 blt::mesh destroy $_bltmesh 242 234 } 243 catch {rename $this-points ""}244 catch {rename $this-grid ""}245 catch {rename $this-dset ""}246 foreach type [array names _pts2elem] {247 rename $_pts2elem($type) ""248 }249 235 } 250 236 … … 425 411 } 426 412 return $value 427 }428 429 # ----------------------------------------------------------------------430 # USAGE: _buildNodesElements <xmlobj> <path>431 #432 # Used internally to build a mesh representation based on nodes and433 # elements stored in the XML.434 # ----------------------------------------------------------------------435 itcl::body Rappture::Mesh::_buildNodesElements {xmlobj path} {436 # create the vtk objects containing points and connectivity437 438 set _vtkpoints $this-points439 vtkPoints $_vtkpoints440 441 #442 # Extract each node and add it to the points list.443 #444 foreach comp [$xmlobj children -type node $path] {445 set xyz [$xmlobj get $path.$comp]446 447 # make sure we have x,y,z448 while {[llength $xyz] < 3} {449 lappend xyz "0"450 }451 452 # extract each point and add it to the points list453 foreach {x y z} $xyz break454 foreach dim {x y z} units $_units {455 set v [Rappture::Units::convert [set $dim] \456 -context $units -to $units -units off]457 458 set $dim $v ;# save back to real x/y/z variable459 460 if {"" == $_limits(${dim}min)} {461 set _limits(${dim}min) $v462 set _limits(${dim}max) $v463 } else {464 if {$v < $_limits(${dim}min)} { set _limits(${dim}min) $v }465 if {$v > $_limits(${dim}max)} { set _limits(${dim}max) $v }466 }467 }468 $_vtkpoints InsertNextPoint $x $y $z469 }470 471 set _vtkgrid $this-grid472 vtkUnstructuredGrid $_vtkgrid473 $_vtkgrid SetPoints $_vtkpoints474 475 #476 # Extract each element and add it to the mesh.477 #478 foreach comp [$xmlobj children -type element $path] {479 set nlist [$_mesh get $comp.nodes]480 set elem [_getVtkElement [llength $nlist]]481 482 set i 0483 foreach n $nlist {484 [$elem GetPointIds] SetId $i $n485 incr i486 }487 $_vtkgrid InsertNextCell [$elem GetCellType] [$elem GetPointIds]488 }489 }490 491 # ----------------------------------------------------------------------492 # USAGE: _buildRectMesh <xmlobj> <path>493 #494 # Used internally to build a mesh representation based on a native495 # VTK file for a rectangular mesh.496 # ----------------------------------------------------------------------497 itcl::body Rappture::Mesh::_buildRectMesh {xmlobj path} {498 vtkRectilinearGridReader $this-gr499 $this-gr ReadFromInputStringOn500 $this-gr SetInputString [$xmlobj get $path.vtk]501 502 set _vtkgrid [$this-gr GetOutput]503 set _points [$_vtkgrid GetPointData]504 505 $_vtkgrid Update506 foreach name {xmin xmax ymin ymax zmin zmax} val [$_vtkgrid GetBounds] {507 set _limits($name) $val508 }509 }510 511 # ----------------------------------------------------------------------512 # USAGE: _getVtkElement <npts>513 #514 # Used internally to find (or allocate, if necessary) a vtk element515 # that can be used to build up a mesh. The element depends on the516 # number of points passed in. 4 points is a tetrahedron, 5 points517 # is a pyramid, etc.518 # ----------------------------------------------------------------------519 itcl::body Rappture::Mesh::_getVtkElement {npts} {520 if {![info exists _pts2elem($npts)]} {521 switch -- $npts {522 3 {523 set _pts2elem($npts) $this-elem3524 vtkTriangle $_pts2elem($npts)525 }526 4 {527 set _pts2elem($npts) $this-elem4528 vtkTetra $_pts2elem($npts)529 }530 5 {531 set _pts2elem($npts) $this-elem5532 vtkPyramid $_pts2elem($npts)533 }534 6 {535 set _pts2elem($npts) $this-elem6536 vtkWedge $_pts2elem($npts)537 }538 8 {539 set _pts2elem($npts) $this-elem8540 vtkVoxel $_pts2elem($npts)541 }542 }543 }544 return $_pts2elem($npts)545 413 } 546 414 … … 570 438 append out "$x $y 0\n" 571 439 } 572 append out "POINT_DATA $_numPoints\n"573 440 set _vtkdata $out 574 441 foreach axis {x y} { … … 583 450 append out "$x $y $z\n" 584 451 } 585 append out "POINT_DATA $_numPoints\n"586 452 set _vtkdata $out 587 453 foreach axis {x y z} { … … 596 462 itcl::body Rappture::Mesh::ReadVtk { xmlobj path } { 597 463 set _type "vtk" 598 if { $_dim < 1 } { 599 error "can't read vtk mesh: no dimension specified" 600 } 464 465 # Create a VTK file with the mesh in it. 466 set _vtkdata [$xmlobj get $path.vtk] 467 append out "# vtk DataFile Version 3.0\n" 468 append out "mesh\n" 469 append out "ASCII\n" 470 append out "$_vtkdata\n" 601 471 602 472 # Write the contents to a file just in case it's binary. … … 604 474 set f [open "$tmpfile" "w"] 605 475 fconfigure $f -translation binary -encoding binary 606 puts $f [$xmlobj get vtk]476 puts $f $out 607 477 close $f 608 478 609 # Read the data into a polydata output 610 set _vtkreader $this-datasetreader 611 vtkDataSetReader $_vtkreader 612 $_vtkreader SetFileName $tmpfile 613 $_vtkreader Update 614 set _vtkoutput [$_vtkreader GetOutput] 615 set _vtkpoints [$_vtkoutput GetPointData] 479 # Read the data back into a vtk dataset and query the bounds. 480 set reader $this-datasetreader 481 vtkDataSetReader $reader 482 $reader SetFileName $tmpfile 483 $reader Update 484 set output [$reader GetOutput] 485 foreach { 486 _limits(xmin) _limits(xmax) 487 _limits(ymin) _limits(ymax) 488 _limits(zmin) _limits(zmax) 489 } [$output GetBounds] break 490 set _dim 3; # Hard coding all vtk meshes to 3D? 491 if { $_limits(zmin) >= $_limits(zmax) } { 492 set _dim 2 493 } 616 494 file delete $tmpfile 495 rename $output "" 496 rename $reader "" 617 497 set _isValid 1 618 498 } … … 654 534 append out "ORIGIN 0 0 0\n" 655 535 set _numPoints [expr $xNum * $yNum] 656 append out "POINT_DATA $_numPoints\n"657 536 set _vtkdata $out 658 537 foreach axis {x y} { … … 669 548 append out "ORIGIN 0 0 0\n" 670 549 set _numPoints [expr $xNum * $yNum * zNum] 671 append out "POINT_DATA $_numPoints\n"672 550 set _vtkdata $out 673 551 foreach axis {x y z} { … … 726 604 append out [$zv range 0 end] 727 605 append out "\n" 728 append out "POINT_DATA $_numPoints\n"729 606 set _vtkdata $out 730 607 foreach axis {x y z} { … … 746 623 append out "Z_COORDINATES 1 double\n" 747 624 append out "0\n" 748 append out "POINT_DATA $_numPoints\n"749 625 foreach axis {x y} { 750 626 if { [info exists ${axis}Min] } { … … 852 728 append out "CELL_TYPES $numCells\n" 853 729 append out $celltypes 854 append out "POINT_DATA $_numPoints\n"855 730 set _limits(xmin) [$xv min] 856 731 set _limits(xmax) [$xv max] … … 893 768 append out "CELL_TYPES $numCells\n" 894 769 append out $celltypes 895 append out "POINT_DATA $_numPoints\n"896 770 set _limits(xmin) [$xv min] 897 771 set _limits(xmax) [$xv max] … … 953 827 append out "CELL_TYPES $count\n" 954 828 append out $celltypes 955 append out "POINT_DATA $_numPoints\n"956 829 set _limits(xmin) [$xv min] 957 830 set _limits(xmax) [$xv max] … … 1169 1042 append out $celltypes 1170 1043 append out "\n" 1171 append out "POINT_DATA $_numPoints\n"1172 1044 set _vtkdata $out 1173 1045 set _isValid 1 -
branches/Rappture 1.2/gui/scripts/unirect2d.tcl
r3217 r3310 154 154 append out "SPACING $xSpace $ySpace 0\n" 155 155 append out "ORIGIN 0 0 0\n" 156 append out "POINT_DATA $_numPoints\n"157 156 set _vtkdata $out 158 157 }
Note: See TracChangeset
for help on using the changeset viewer.