- Timestamp:
- May 29, 2015, 8:00:56 PM (9 years ago)
- Location:
- branches/1.3
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.3
- Property svn:mergeinfo changed
/trunk merged: 5610-5612,5630,5632-5636
- Property svn:mergeinfo changed
-
branches/1.3/examples/zoo/mesh/mesh.tcl
r5629 r5638 21 21 $xv seq 0 1 50 22 22 23 set hide no 24 23 25 switch -- $meshtype { 24 26 "cloud" { 25 set mesh output.mesh 26 27 $driver put $mesh.about.label "cloud in unstructured mesh" 28 $driver put $mesh.dim 2 29 $driver put $mesh.units "m" 30 $driver put $mesh.hide "yes" 31 32 set points {} 33 foreach y [$xv range 0 end] { 34 foreach x [$xv range 0 end] { 35 append points "$x $y\n" 36 } 37 } 38 $driver put $mesh.unstructured.points $points 39 $driver put $mesh.unstructured.celltypes "" 27 set mesh output.mesh 28 29 $driver put $mesh.about.label "Mesh" 30 $driver put $mesh.about.description "cloud in unstructured mesh" 31 $driver put $mesh.dim 2 32 $driver put $mesh.units "m" 33 $driver put $mesh.hide $hide 34 35 set points {} 36 foreach y [$xv range 0 end] { 37 foreach x [$xv range 0 end] { 38 append points "$x $y\n" 39 } 40 } 41 $driver put $mesh.unstructured.points $points 42 $driver put $mesh.unstructured.celltypes "" 40 43 } 41 44 "regular" { 42 set mesh output.mesh 43 44 $driver put $mesh.about.label "uniform grid mesh" 45 $driver put $mesh.dim 2 46 $driver put $mesh.units "m" 47 $driver put $mesh.hide "yes" 48 49 $driver put $mesh.grid.xaxis.min 0.0 50 $driver put $mesh.grid.xaxis.max 1.0 51 $driver put $mesh.grid.xaxis.numpoints 50 52 $driver put $mesh.grid.yaxis.min 0.0 53 $driver put $mesh.grid.yaxis.max 1.0 54 $driver put $mesh.grid.yaxis.numpoints 50 45 set mesh output.mesh 46 47 $driver put $mesh.about.label "Mesh" 48 $driver put $mesh.about.description "uniform grid mesh" 49 $driver put $mesh.dim 2 50 $driver put $mesh.units "m" 51 $driver put $mesh.hide $hide 52 53 $driver put $mesh.grid.xaxis.min 0.0 54 $driver put $mesh.grid.xaxis.max 1.0 55 $driver put $mesh.grid.xaxis.numpoints 50 56 $driver put $mesh.grid.yaxis.min 0.0 57 $driver put $mesh.grid.yaxis.max 1.0 58 $driver put $mesh.grid.yaxis.numpoints 50 55 59 } 56 60 "irregular" { 57 set mesh output.mesh 58 59 $driver put $mesh.about.label "irregular grid mesh" 60 $driver put $mesh.dim 2 61 $driver put $mesh.units "m" 62 $driver put $mesh.hide "yes" 63 64 $driver put $mesh.grid.xcoords [$xv range 0 end] 65 $driver put $mesh.grid.ycoords [$xv range 0 end] 61 set mesh output.mesh 62 63 $driver put $mesh.about.label "Mesh" 64 $driver put $mesh.about.description "irregular rectilinear grid mesh" 65 $driver put $mesh.dim 2 66 $driver put $mesh.units "m" 67 $driver put $mesh.hide $hide 68 69 $driver put $mesh.grid.xcoords [$xv range 0 end] 70 $driver put $mesh.grid.ycoords [$xv range 0 end] 66 71 } 67 72 "hybrid" { 68 set mesh output.mesh 69 70 $driver put $mesh.about.label "hybrid regular and irregular grid mesh" 71 $driver put $mesh.dim 2 72 $driver put $mesh.units "m" 73 $driver put $mesh.hide "yes" 74 75 $driver put $mesh.units "m" 76 $driver put $mesh.grid.xcoords [$xv range 0 end] 77 $driver put $mesh.grid.yaxis.min 0.0 78 $driver put $mesh.grid.yaxis.max 1.0 79 $driver put $mesh.grid.yaxis.numpoints 50 73 set mesh output.mesh 74 75 $driver put $mesh.about.label "Mesh" 76 $driver put $mesh.about.description "hybrid regular and irregular rectilinear grid mesh" 77 $driver put $mesh.dim 2 78 $driver put $mesh.units "m" 79 $driver put $mesh.hide $hide 80 81 $driver put $mesh.grid.xcoords [$xv range 0 end] 82 $driver put $mesh.grid.yaxis.min 0.0 83 $driver put $mesh.grid.yaxis.max 1.0 84 $driver put $mesh.grid.yaxis.numpoints 50 85 } 86 "structured" { 87 set mesh output.mesh 88 89 $driver put $mesh.about.label "Mesh" 90 $driver put $mesh.about.description "Structured (Curvilinear) Grid" 91 $driver put $mesh.dim 2 92 $driver put $mesh.units "m" 93 $driver put $mesh.hide $hide 94 95 $driver put $mesh.grid.xdim 50 96 $driver put $mesh.grid.ydim 50 97 set points {} 98 foreach y [$xv range 0 end] { 99 foreach x [$xv range 0 end] { 100 append points "$x $y\n" 101 } 102 } 103 $driver put $mesh.grid.points $points 80 104 } 81 105 "triangular" { 82 set mesh output.mesh 83 84 $driver put $mesh.about.label "triangles in unstructured mesh" 85 $driver put $mesh.dim 2 86 $driver put $mesh.units "m" 87 $driver put $mesh.hide "yes" 88 89 $driver put -type file -compress no $mesh.unstructured.points \ 90 points.txt 91 $driver put -type file -compress no $mesh.unstructured.triangles \ 92 triangles.txt 106 set mesh output.mesh 107 108 $driver put $mesh.about.label "Mesh" 109 $driver put $mesh.about.description "triangles in unstructured mesh" 110 $driver put $mesh.dim 2 111 $driver put $mesh.units "m" 112 $driver put $mesh.hide $hide 113 114 $driver put -type file -compress no $mesh.unstructured.points \ 115 points.txt 116 $driver put -type file -compress no $mesh.unstructured.triangles \ 117 triangles.txt 93 118 } 94 119 "generic" { 95 set mesh output.mesh 96 97 $driver put $mesh.about.label "nodes and elements mesh" 98 $driver put $mesh.dim 2 99 $driver put $mesh.units "m" 100 $driver put $mesh.hide "yes" 101 102 set count 0 103 set f [open "points.txt" "r"] 104 set points [read $f] 105 close $f 106 foreach { x y } $points { 107 $driver put $mesh.node($count) "$x $y" 108 incr count 109 } 110 set count 0 111 set f [open "triangles.txt" "r"] 112 set triangles [read $f] 113 close $f 114 foreach { a b c } $triangles { 115 $driver put $mesh.element($count).nodes "$a $b $c" 116 incr count 117 } 120 set mesh output.mesh 121 122 $driver put $mesh.about.label "Mesh" 123 $driver put $mesh.about.description "nodes and elements mesh" 124 $driver put $mesh.dim 2 125 $driver put $mesh.units "m" 126 $driver put $mesh.hide $hide 127 128 set count 0 129 set f [open "points.txt" "r"] 130 set points [read $f] 131 close $f 132 foreach { x y } $points { 133 $driver put $mesh.node($count) "$x $y" 134 incr count 135 } 136 set count 0 137 set f [open "triangles.txt" "r"] 138 set triangles [read $f] 139 close $f 140 foreach { a b c } $triangles { 141 $driver put $mesh.element($count).nodes "$a $b $c" 142 incr count 143 } 118 144 } 119 145 "unstructured" { 120 set mesh output.mesh 121 122 $driver put $mesh.about.label "Unstructured Grid" 123 $driver put $mesh.dim 2 124 $driver put $mesh.units "m" 125 $driver put $mesh.hide "yes" 126 127 $driver put -type file -compress no $mesh.unstructured.points points.txt 128 set cells {} 129 set f [open "triangles.txt" "r"] 130 set triangles [read $f] 131 close $f 132 foreach { a b c } $triangles { 133 append cells "$a $b $c\n" 134 } 135 $driver put $mesh.unstructured.cells $cells 136 $driver put $mesh.unstructured.celltypes "triangle" 146 set mesh output.mesh 147 148 $driver put $mesh.about.label "Mesh" 149 $driver put $mesh.about.description "Unstructured Grid" 150 $driver put $mesh.dim 2 151 $driver put $mesh.units "m" 152 $driver put $mesh.hide $hide 153 154 $driver put -type file -compress no $mesh.unstructured.points points.txt 155 set cells {} 156 set f [open "triangles.txt" "r"] 157 set triangles [read $f] 158 close $f 159 foreach { a b c } $triangles { 160 append cells "$a $b $c\n" 161 } 162 $driver put $mesh.unstructured.cells $cells 163 $driver put $mesh.unstructured.celltypes "triangle" 137 164 } 138 165 "cells" { 139 set mesh output.mesh 140 141 $driver put $mesh.about.label \ 142 "Unstructured Grid with Heterogeneous Cells" 143 $driver put $mesh.dim 2 144 $driver put $mesh.units "m" 145 $driver put $mesh.hide "yes" 146 147 set celltypes {} 148 set f [open "triangles.txt" "r"] 149 set triangles [read $f] 150 close $f 151 foreach { a b c } $triangles { 152 append cells "$a $b $c\n" 153 append celltypes "triangle\n" 154 } 155 $driver put -type file -compress no $mesh.unstructured.points points.txt 156 $driver put $mesh.unstructured.celltypes $celltypes 157 $driver put $mesh.unstructured.cells $cells 166 set mesh output.mesh 167 168 $driver put $mesh.about.label "Mesh" 169 $driver put $mesh.about.description \ 170 "Unstructured Grid with Heterogeneous Cells" 171 $driver put $mesh.dim 2 172 $driver put $mesh.units "m" 173 $driver put $mesh.hide $hide 174 175 set celltypes {} 176 set f [open "triangles.txt" "r"] 177 set triangles [read $f] 178 close $f 179 foreach { a b c } $triangles { 180 append cells "$a $b $c\n" 181 append celltypes "triangle\n" 182 } 183 $driver put -type file -compress no $mesh.unstructured.points points.txt 184 $driver put $mesh.unstructured.celltypes $celltypes 185 $driver put $mesh.unstructured.cells $cells 158 186 } 159 187 "vtkmesh" { 160 set mesh output.mesh 161 162 $driver put $mesh.about.label "vtk mesh" 163 $driver put $mesh.dim 2 164 $driver put $mesh.units "m" 165 $driver put $mesh.hide "yes" 166 $driver put -type file -compress no $mesh.vtk mesh.vtk 188 set mesh output.mesh 189 190 $driver put $mesh.about.label "Mesh" 191 $driver put $mesh.about.description "vtk mesh" 192 $driver put $mesh.dim 2 193 $driver put $mesh.units "m" 194 $driver put $mesh.hide $hide 195 $driver put -type file -compress no $mesh.vtk mesh.vtk 167 196 } 168 197 "vtkfield" { 169 198 170 171 172 199 $driver put output.field(substrate).about.label "Substrate Surface" 200 $driver put -type file -compress no \ 201 output.field(substrate).component.vtk file.vtk 173 202 $driver put output.string.current "" 174 175 203 Rappture::result $driver 204 exit 0 176 205 } 177 206 default { 178 207 error "unknown mesh type \"$meshtype\"" 179 208 } 180 209 } -
branches/1.3/examples/zoo/mesh/tool.xml
- Property svn:mime-type changed from application/xml to text/xml
r3752 r5638 51 51 <option> 52 52 <about> 53 <label>mesh as a structured (curvilinear) grid</label> 54 <description>Structured 2D grid.</description> 55 </about> 56 <value>structured</value> 57 </option> 58 <option> 59 <about> 53 60 <label>mesh as unstructured grid</label> 54 61 <description>Unstructured 2D grid.</description> -
branches/1.3/gui/scripts/cloud.tcl
r5615 r5638 25 25 } 26 26 public method points {} 27 public method mesh {}28 27 public method units { axis } 29 28 public method label { axis } … … 216 215 217 216 # ---------------------------------------------------------------------- 218 # USAGE: mesh219 #220 # Returns the vtk object representing the mesh.221 # ----------------------------------------------------------------------222 itcl::body Rappture::Cloud::mesh {} {223 return $_points224 }225 226 # ----------------------------------------------------------------------227 217 # USAGE: dimensions 228 218 # -
branches/1.3/gui/scripts/field.tcl
r5615 r5638 152 152 private variable _comp2vtk; # cname => vtk file data 153 153 private variable _comp2dx; # cname => OpenDX data 154 private variable _comp2unirect2d; # cname => unirect2d obj155 private variable _comp2unirect3d; # cname => unirect3d obj156 154 private variable _comp2style; # cname => style settings 157 155 private variable _comp2cntls; # cname => x,y control points (1D only) … … 160 158 private variable _comp2mesh; # list: mesh obj, BLT vector of values 161 159 # valid for cloud,mesh,unirect2d 162 private variable _values ""; # Only for unirect2d - list of values163 164 160 private common _alwaysConvertDX 0; # If set, convert DX and store as VTK, 165 161 # even if viewer is nanovis/flowvis … … 221 217 foreach name [array names _comp2xy] { 222 218 eval blt::vector destroy $_comp2xy($name) 223 }224 foreach name [array names _comp2unirect2d] {225 itcl::delete object $_comp2unirect2d($name)226 }227 foreach name [array names _comp2unirect3d] {228 itcl::delete object $_comp2unirect3d($name)229 219 } 230 220 foreach name [array names _comp2flowhints] { … … 306 296 # 307 297 # For 1D data (curve), returns a BLT vector of x values for the field 308 # component <name>. Otherwise, this method is unused 298 # component <name>. Otherwise, this method is unused. 309 299 # ---------------------------------------------------------------------- 310 300 itcl::body Rappture::Field::mesh {{cname -overall}} { … … 316 306 } 317 307 if {[info exists _comp2vtk($cname)]} { 318 # FIXME: extract mesh from VTK file data.319 308 error "method \"mesh\" is not implemented for VTK file data" 320 309 } … … 323 312 } 324 313 if {[info exists _comp2mesh($cname)]} { 325 # FIXME: This only works for cloud 326 set mesh [lindex $_comp2mesh($cname) 0] 327 return [$mesh points] 328 } 329 if {[info exists _comp2unirect2d($cname)]} { 330 # FIXME: unirect2d mesh is a list: xMin xMax xNum yMin yMax yNum 331 return [$_comp2unirect2d($cname) mesh] 332 } 333 if {[info exists _comp2unirect3d($cname)]} { 334 # This returns a list of x,y,z points 335 return [$_comp2unirect3d($cname) mesh] 314 error "method \"mesh\" is not implemented for Rappture::Mesh" 336 315 } 337 316 error "can't get field mesh: Unknown component \"$cname\": should be one of [join [lsort [array names _comp2dims]] {, }]" … … 342 321 # 343 322 # For 1D data (curve), returns a BLT vector of field values (y coords) 344 # for the field component <name>. Otherwise, this method is unused 323 # for the field component <name>. Otherwise, this method is unused. 324 # The number of elements in the vector should be a multiple of the 325 # return value of [numComponents] 345 326 # ---------------------------------------------------------------------- 346 327 itcl::body Rappture::Field::values {cname} { … … 351 332 return [lindex $_comp2xy($cname) 1] ;# return yv 352 333 } 353 if { [info exists _comp2vtk($cname)] } { 354 # FIXME: extract the values from the VTK file data 334 if {[info exists _comp2vtk($cname)]} { 355 335 error "method \"values\" is not implemented for VTK file data" 356 336 } … … 358 338 error "method \"values\" is not implemented for DX file data" 359 339 } 360 if { [info exists _comp2mesh($cname)] } { 361 set vector [lindex $_comp2mesh($cname) 1] 362 return [$vector range 0 end] 363 } 364 if {[info exists _comp2unirect2d($cname)]} { 365 return $_values 366 } 367 if {[info exists _comp2unirect3d($cname)]} { 368 return [$_comp2unirect3d($cname) values] 340 if {[info exists _comp2mesh($cname)]} { 341 return [lindex $_comp2mesh($cname) 1] ;# return vector 369 342 } 370 343 error "can't get field values. Unknown component \"$cname\": should be one of [join [lsort [array names _comp2dims]] {, }]" … … 383 356 return $_comp2dx($cname) ;# return gzipped, base64-encoded DX data 384 357 } 385 if {[info exists _comp2unirect2d($cname)]} { 386 set blob [$_comp2unirect2d($cname) blob] 387 lappend blob "values" $_values 388 return $blob 389 } 390 if {[info exists _comp2unirect3d($cname)]} { 391 return [$_comp2unirect3d($cname) blob] 392 } 393 if { [info exists _comp2vtk($cname)] } { 394 error "blob not implemented for VTK file data" 358 if {[info exists _comp2mesh($cname)]} { 359 error "method \"blob\" not implemented for Rappture::Mesh" 360 } 361 if {[info exists _comp2vtk($cname)]} { 362 error "method \"blob\" not implemented for VTK file data" 395 363 } 396 364 if {[info exists _comp2xy($cname)]} { 397 error " blobnot implemented for XY data"365 error "method \"blob\" not implemented for XY data" 398 366 } 399 367 error "can't get field blob: Unknown component \"$cname\": should be one of [join [lsort [array names _comp2dims]] {, }]" … … 752 720 } 753 721 array unset _comp2vtk 754 foreach name [array names _comp2unirect2d] {755 eval itcl::delete object $_comp2unirect2d($name)756 }757 foreach name [array names _comp2unirect3d] {758 eval itcl::delete object $_comp2unirect3d($name)759 }760 722 catch {unset _comp2xy} 761 723 catch {unset _comp2dx} 762 724 catch {unset _comp2dims} 763 725 catch {unset _comp2style} 764 array unset _comp2unirect2d765 array unset _comp2unirect3d766 726 array unset _dataobj2type 767 727 # … … 1122 1082 # Returns the data storage type of the field. 1123 1083 # 1124 # FIXME: What are the valid types? 1084 # Types: 1085 # 1D,cloud,dicom,dx,mesh,ucd,unirect2d,unirect3d,vtk 1125 1086 # 1126 1087 itcl::body Rappture::Field::type {} { … … 1322 1283 set data [Rappture::encoding::decode -as zb64 $data] 1323 1284 return [Rappture::DxToVtk $data] 1324 }1325 # unirect2d (deprecated)1326 # This can be removed when the nanovis server with support for loading VTK1327 # vector data is released1328 if {[info exists _comp2unirect2d($cname)]} {1329 set label $cname1330 regsub -all { } $label {_} label1331 set elemSize [numComponents $cname]1332 set numValues [$_comp2unirect2d($cname) numpoints]1333 append out "# vtk DataFile Version 3.0\n"1334 append out "[hints label]\n"1335 append out "ASCII\n"1336 append out [$_comp2unirect2d($cname) vtkdata]1337 append out "POINT_DATA $numValues\n"1338 if {$elemSize == 3} {1339 append out "VECTORS $label double\n"1340 } else {1341 append out "SCALARS $label double $elemSize\n"1342 append out "LOOKUP_TABLE default\n"1343 }1344 # values for VTK are x-fastest1345 append out $_values1346 append out "\n"1347 return $out1348 }1349 # unirect3d (deprecated)1350 if {[info exists _comp2unirect3d($cname)]} {1351 set vector [$_comp2unirect3d($cname) values]1352 set label $cname1353 regsub -all { } $label {_} label1354 set elemSize [numComponents $cname]1355 set numValues [expr [$vector length] / $elemSize]1356 append out "# vtk DataFile Version 3.0\n"1357 append out "[hints label]\n"1358 append out "ASCII\n"1359 append out [$_comp2unirect3d($cname) vtkdata]1360 append out "POINT_DATA $numValues\n"1361 if {$elemSize == 3} {1362 append out "VECTORS $label double\n"1363 } else {1364 append out "SCALARS $label double $elemSize\n"1365 append out "LOOKUP_TABLE default\n"1366 }1367 # values for VTK are x-fastest1368 append out [$vector range 0 end]1369 append out "\n"1370 return $out1371 1285 } 1372 1286 # Points on mesh: Construct VTK file output. … … 1460 1374 lappend _comp2fldName($cname) $name 1461 1375 1462 # Handle bizarre cases that are due to be removed.1463 if { $element == "unirect3d" } {1464 # Special case: unirect3d (deprecated) + flow.1465 set vectorsize [numComponents $cname]1466 set _type unirect3d1467 set _dim 31468 if { $_viewer == "" } {1469 set _viewer flowvis1470 }1471 set _comp2dims($cname) "3D"1472 set _comp2unirect3d($cname) \1473 [Rappture::Unirect3d \#auto $_xmlobj $_field $cname $vectorsize]1474 set _comp2style($cname) [$_field get $cname.style]1475 set limits {}1476 foreach axis { x y z } {1477 lappend limits $axis [$_comp2unirect3d($cname) limits $axis]1478 }1479 # Get the data limits1480 set vector [$_comp2unirect3d($cname) values]1481 set minmax [VectorLimits $vector $vectorsize]1482 lappend limits $cname $minmax1483 lappend limits v $minmax1484 set _comp2limits($cname) $limits1485 if {[$_field element $cname.flow] != ""} {1486 set _comp2flowhints($cname) \1487 [Rappture::FlowHints ::\#auto $_field $cname $_units]1488 }1489 incr _counter1490 return 11491 }1492 if { $element == "unirect2d" && [$_field element $cname.flow] != "" } {1493 # Special case: unirect2d (deprecated) + flow.1494 set vectorsize [numComponents $cname]1495 set _type unirect2d1496 set _dim 21497 if { $_viewer == "" } {1498 set _viewer "flowvis"1499 }1500 set _comp2dims($cname) "2D"1501 set _comp2unirect2d($cname) \1502 [Rappture::Unirect2d \#auto $_xmlobj $path]1503 set _comp2style($cname) [$_field get $cname.style]1504 set _comp2flowhints($cname) \1505 [Rappture::FlowHints ::\#auto $_field $cname $_units]1506 set _values [$_field get $cname.values]1507 set limits {}1508 foreach axis { x y z } {1509 lappend limits $axis [$_comp2unirect2d($cname) limits $axis]1510 }1511 set xv [blt::vector create \#auto]1512 $xv set $_values1513 set minmax [VectorLimits $xv $vectorsize]1514 lappend limits $cname $minmax1515 lappend limits v $minmax1516 blt::vector destroy $xv1517 set _comp2limits($cname) $limits1518 incr _counter1519 return 11520 }1521 1376 switch -- $element { 1522 1377 "cloud" { … … 1534 1389 set mesh [Rappture::Unirect2d::fetch $_xmlobj $path] 1535 1390 set _type unirect2d 1391 } 1392 "unirect3d" { 1393 set mesh [Rappture::Unirect3d::fetch $_xmlobj $path] 1394 set _type unirect3d 1536 1395 } 1537 1396 } -
branches/1.3/gui/scripts/flowvisviewer.tcl
r5600 r5638 1137 1137 foreach cname [$dataobj components] { 1138 1138 set tag $dataobj-$cname 1139 set isvtk 0 1140 # FIXME: Would like to use the type method of the dataobj 1141 # but the returned value isn't well defined now 1142 if {[catch { 1143 # Send the data as one huge base64-encoded mess -- yuck! 1139 if {[$dataobj type] == "dx"} { 1144 1140 set data [$dataobj blob $cname] 1145 } ]}{1141 } else { 1146 1142 set data [$dataobj vtkdata $cname] 1147 set isvtk 11148 1143 } 1149 1144 set nbytes [string length $data] -
branches/1.3/gui/scripts/mesh.tcl
r5629 r5638 23 23 24 24 itcl::class Rappture::Mesh { 25 private variable _xmlobj "" ; # Ref to XML obj with device data26 private variable _mesh "" ; # Lib obj representing this mesh27 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, z30 private variable _axis2labels; #31 private variable _hints32 private variable _limits ; # Array of mesh limits. Keys are33 # xmin, xmax, ymin, ymax, ...34 private variable _numPoints 0 ; # # of points in mesh35 private variable _numCells 0 ; # # of cells in mesh36 private variable _vtkdata ""; # Mesh in vtk file format.37 private variable _isValid 0; # Indicates if the mesh is valid.38 25 constructor {xmlobj path} { 39 26 # defined below … … 65 52 return $_numCells 66 53 } 67 68 private common _xp2obj ; # used for fetch/release ref counting69 private common _obj2ref ; # used for fetch/release ref counting70 54 71 55 private method ReadNodesElements {path} … … 91 75 private method GetCellType { name } 92 76 private method GetNumIndices { type } 77 78 private variable _xmlobj ""; # Ref to XML obj with device data 79 private variable _mesh ""; # Lib obj representing this mesh 80 private variable _dim 0; # Dimension of mesh (1, 2, or 3) 81 private variable _type ""; # Indicates the type of mesh. 82 private variable _axis2units; # System of units for x, y, z 83 private variable _axis2labels; # 84 private variable _hints 85 private variable _limits; # Array of mesh limits. Keys are 86 # xmin, xmax, ymin, ymax, ... 87 private variable _numPoints 0; # Number of points in mesh 88 private variable _numCells 0; # Number of cells in mesh 89 private variable _vtkdata ""; # Mesh in vtk file format. 90 private variable _isValid 0; # Indicates if the mesh is valid. 91 92 private common _xp2obj; # used for fetch/release ref counting 93 private common _obj2ref; # used for fetch/release ref counting 93 94 } 94 95 … … 539 540 set numCoords [$all length] 540 541 if { [info exists zNum] } { 542 if { ![info exists yNum] || ![info exists xNum] } { 543 puts stderr "WARNING: bad grid \"$path\": missing grid dimension" 544 blt::vector destroy $all $xv $yv $zv 545 return 0 546 } 541 547 set _dim 3 542 548 set _numPoints [expr $xNum * $yNum * $zNum] … … 544 550 if { ($_numPoints*3) != $numCoords } { 545 551 puts stderr "WARNING: bad grid \"$path\": invalid grid: \# of points does not match dimensions <xdim> * <ydim> * <zdim>" 552 blt::vector destroy $all $xv $yv $zv 546 553 return 0 547 554 } 548 555 if { ($numCoords % 3) != 0 } { 549 556 puts stderr "WARNING: bad grid \"$path\": wrong \# of coordinates for 3D grid" 557 blt::vector destroy $all $xv $yv $zv 550 558 return 0 551 559 } … … 558 566 append out "DIMENSIONS $xNum $yNum $zNum\n" 559 567 append out "POINTS $_numPoints double\n" 560 append out [$all range 0 end] 561 append out "\n" 568 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 569 append out "$x $y $z\n" 570 } 562 571 set _vtkdata $out 563 572 } elseif { [info exists yNum] } { 573 if { ![info exists xNum] } { 574 puts stderr "WARNING: bad grid \"$path\": missing grid dimension" 575 blt::vector destroy $all $xv $yv $zv 576 return 0 577 } 564 578 set _dim 2 565 579 set _numPoints [expr $xNum * $yNum] … … 567 581 if { ($_numPoints*2) != $numCoords } { 568 582 puts stderr "WARNING: bad grid \"$path\": \# of points does not match dimensions <xdim> * <ydim>" 583 blt::vector destroy $all $xv $yv $zv 569 584 return 0 570 585 } 571 586 if { ($numCoords % 2) != 0 } { 572 587 puts stderr "WARNING: bad grid \"$path\": wrong \# of coordinates for 2D grid" 588 blt::vector destroy $all $xv $yv $zv 573 589 return 0 574 590 } 591 $all split $xv $yv 575 592 foreach axis {x y} { 576 593 set vector [set ${axis}v] … … 583 600 append out "DIMENSIONS $xNum $yNum 1\n" 584 601 append out "POINTS $_numPoints double\n" 585 append out [$all range 0 end] 586 append out "\n" 602 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 603 append out "$x $y $z\n" 604 } 587 605 set _vtkdata $out 588 606 } else { … … 592 610 if { $_numPoints != $numCoords } { 593 611 puts stderr "WARNING: bad grid \"$path\": \# of points does not match <xdim>" 612 blt::vector destroy $all $xv $yv $zv 594 613 return 0 595 614 } 615 $all dup $xv 596 616 set _limits(x) [$xv limits] 597 617 set _limits(y) [list 0 0] … … 603 623 append out "DIMENSIONS $xNum 1 1\n" 604 624 append out "POINTS $_numPoints double\n" 605 append out [$all range 0 end] 606 append out "\n" 625 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 626 append out "$x $y $z\n" 627 } 607 628 set _vtkdata $out 608 629 } … … 815 836 set celltypes {} 816 837 foreach { a b c } $triangles { 817 append data " 838 append data "3 $a $b $c\n" 818 839 append celltypes "5\n" 819 840 incr _numCells … … 822 843 append out "POINTS $_numPoints double\n" 823 844 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 824 append out " 845 append out "$x $y $z\n" 825 846 } 826 847 set count [expr $_numCells * 4] … … 847 868 set celltypes {} 848 869 foreach { a b c d } $quads { 849 append data " 870 append data "4 $a $b $c $d\n" 850 871 append celltypes "9\n" 851 872 incr _numCells … … 854 875 append out "POINTS $_numPoints double\n" 855 876 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 856 append out " 877 append out "$x $y $z\n" 857 878 } 858 879 set count [expr $_numCells * 5] … … 884 905 continue 885 906 } 886 append data " 907 append data "$numIndices $line\n" 887 908 incr _numCells 888 909 set count [expr $count + $numIndices + 1] … … 891 912 append out "POINTS $_numPoints double\n" 892 913 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 893 append out " 914 append out "$x $y $z\n" 894 915 } 895 916 append out "VERTICES $_numCells $count\n" … … 918 939 continue 919 940 } 920 append data " 941 append data "$numIndices $line\n" 921 942 incr _numCells 922 943 set count [expr $count + $numIndices + 1] … … 925 946 append out "POINTS $_numPoints double\n" 926 947 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 927 append out " 948 append out "$x $y $z\n" 928 949 } 929 950 append out "LINES $_numCells $count\n" … … 952 973 continue 953 974 } 954 append data " 975 append data "$numIndices $line\n" 955 976 incr _numCells 956 977 set count [expr $count + $numIndices + 1] … … 959 980 append out "POINTS $_numPoints double\n" 960 981 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 961 append out " 982 append out "$x $y $z\n" 962 983 } 963 984 append out "POLYGONS $_numCells $count\n" … … 986 1007 continue 987 1008 } 988 append data " 1009 append data "$numIndices $line\n" 989 1010 incr _numCells 990 1011 set count [expr $count + $numIndices + 1] … … 993 1014 append out "POINTS $_numPoints double\n" 994 1015 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 995 append out " 1016 append out "$x $y $z\n" 996 1017 } 997 1018 append out "TRIANGLE_STRIPS $_numCells $count\n" … … 1015 1036 set celltypes {} 1016 1037 foreach { a b c d } $tetras { 1017 append data " 1038 append data "4 $a $b $c $d\n" 1018 1039 append celltypes "10\n" 1019 1040 incr _numCells … … 1022 1043 append out "POINTS $_numPoints double\n" 1023 1044 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 1024 append out " 1045 append out "$x $y $z\n" 1025 1046 } 1026 1047 set count [expr $_numCells * 5] … … 1044 1065 set celltypes {} 1045 1066 foreach { a b c d e f g h } $hexas { 1046 append data " 1067 append data "8 $a $b $c $d $e $f $g $h\n" 1047 1068 append celltypes "12\n" 1048 1069 incr _numCells … … 1051 1072 append out "POINTS $_numPoints double\n" 1052 1073 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 1053 append out " 1074 append out "$x $y $z\n" 1054 1075 } 1055 1076 set count [expr $_numCells * 9] … … 1073 1094 set celltypes {} 1074 1095 foreach { a b c d e f } $wedges { 1075 append data " 1096 append data "6 $a $b $c $d $e $f\n" 1076 1097 append celltypes "13\n" 1077 1098 incr _numCells … … 1080 1101 append out "POINTS $_numPoints double\n" 1081 1102 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 1082 append out " 1103 append out "$x $y $z\n" 1083 1104 } 1084 1105 set count [expr $_numCells * 7] … … 1102 1123 set celltypes {} 1103 1124 foreach { a b c d e } $pyramids { 1104 append data " 1125 append data "5 $a $b $c $d $e\n" 1105 1126 append celltypes "14\n" 1106 1127 incr _numCells … … 1109 1130 append out "POINTS $_numPoints double\n" 1110 1131 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 1111 append out " 1132 append out "$x $y $z\n" 1112 1133 } 1113 1134 set count [expr $_numCells * 6] … … 1152 1173 set numIndices $length 1153 1174 } 1154 append data " 1155 lappend celltypesout $celltype1175 append data "$numIndices $line\n" 1176 append celltypesout "$celltype\n" 1156 1177 incr count $length; # Include the indices 1157 1178 incr count; # and the number of indices … … 1160 1181 append out "DATASET UNSTRUCTURED_GRID\n" 1161 1182 append out "POINTS $_numPoints double\n" 1162 set all [blt::vector create \#auto] 1163 $all merge $xv $yv $zv 1164 append out [$all range 0 end] 1165 blt::vector destroy $all 1183 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 1184 append out "$x $y $z\n" 1185 } 1166 1186 append out "CELLS $_numCells $count\n" 1167 1187 append out $data … … 1437 1457 } 1438 1458 set celltype $node2celltype($numNodes) 1439 append celltypes " 1459 append celltypes "$celltype\n" 1440 1460 if { $celltype == 12 } { 1441 1461 # Formerly used voxels instead of hexahedrons. We're converting … … 1448 1468 set nodeList $newList 1449 1469 } 1450 append data " 1470 append data "$numNodes $nodeList\n" 1451 1471 incr _numCells 1452 1472 incr count $numNodes … … 1462 1482 append out "CELL_TYPES $_numCells\n" 1463 1483 append out $celltypes 1464 append out "\n"1465 1484 set _vtkdata $out 1466 1485 set _isValid 1 -
branches/1.3/gui/scripts/unirect2d.tcl
r5596 r5638 29 29 public proc release {obj} 30 30 31 public method blob {}32 31 public method dimensions {} { 33 32 return 2 … … 39 38 public method label { axis } 40 39 public method limits {axis} 41 public method mesh {}42 40 public method numpoints {} { 43 41 return $_numPoints … … 50 48 private method GetSize { obj path varName } 51 49 52 private variable _axisOrder "x y"53 50 private variable _xMax 0 54 51 private variable _xMin 0 … … 126 123 GetSize $m "yaxis.numpoints" _yNum 127 124 foreach {key path} { 128 group about.group129 125 label about.label 130 126 color about.color 131 127 style about.style 132 type about.type133 128 xlabel xaxis.label 134 129 xdesc xaxis.description … … 183 178 184 179 # ---------------------------------------------------------------------- 185 # method blob186 # Returns a Tcl list that represents the Tcl command and data to187 # recreate the uniform rectangular grid on the nanovis server.188 # ----------------------------------------------------------------------189 itcl::body Rappture::Unirect2d::blob {} {190 set data "unirect2d"191 lappend data "xmin" $_xMin "xmax" $_xMax "xnum" $_xNum192 lappend data "ymin" $_yMin "ymax" $_yMax "ynum" $_yNum193 return $data194 }195 196 # ----------------------------------------------------------------------197 # method mesh198 # Returns a Tcl list that represents the mesh limits and dims.199 # ----------------------------------------------------------------------200 itcl::body Rappture::Unirect2d::mesh {} {201 lappend out $_xMin $_xMax $_xNum $_yMin $_yMax $_yNum202 return $out203 }204 205 # ----------------------------------------------------------------------206 180 # method limits <axis> 207 181 # Returns a list {min max} representing the limits for the -
branches/1.3/gui/scripts/unirect3d.tcl
r5596 r5638 2 2 3 3 # ---------------------------------------------------------------------- 4 # COMPONENT: unirect3d - represents a uniform rectangular 2-D mesh.4 # COMPONENT: unirect3d - represents a uniform rectangular 3-D mesh. 5 5 # 6 6 # This object represents one field in an XML description of a device. … … 20 20 21 21 itcl::class Rappture::Unirect3d { 22 constructor {xmlobj field cname {numComponents 1}} {22 constructor {xmlobj path} { 23 23 # defined below 24 24 } … … 26 26 # defined below 27 27 } 28 29 public method blob {} 28 public proc fetch {xmlobj path} 29 public proc release {obj} 30 30 31 public method dimensions {} { 31 32 return 3 … … 37 38 public method label { axis } 38 39 public method limits {axis} 39 public method mesh {}40 40 public method numpoints {} { 41 41 return $_numPoints 42 42 } 43 public method order {} {44 return _axisOrder;45 }46 43 public method units { axis } 47 public method values {}48 44 public method vtkdata {{what -partial}} {} 49 45 … … 52 48 private method GetSize { obj path varName } 53 49 54 private variable _axisOrder "x y z"55 50 private variable _xMax 0 56 51 private variable _xMin 0 … … 62 57 private variable _zMin 0 63 58 private variable _zNum 0; # Number of points along z-axis 64 private variable _compNum 1; # Number of components in values65 private variable _values ""; # BLT vector containing the values66 59 private variable _hints 67 60 private variable _vtkdata "" 68 61 private variable _numPoints 0 69 62 private variable _isValid 0; # Indicates if the data is valid. 63 64 private common _xp2obj ; # used for fetch/release ref counting 65 private common _obj2ref ; # used for fetch/release ref counting 66 } 67 68 # 69 # fetch <xmlobj> <path> 70 # 71 # Clients use this instead of a constructor to fetch the Mesh for a 72 # particular <path> in the <xmlobj>. When the client is done with the mesh, 73 # he calls "release" to decrement the reference count. When the mesh is no 74 # longer needed, it is cleaned up automatically. 75 # 76 itcl::body Rappture::Unirect3d::fetch {xmlobj path} { 77 set handle "$xmlobj|$path" 78 if {[info exists _xp2obj($handle)]} { 79 set obj $_xp2obj($handle) 80 incr _obj2ref($obj) 81 return $obj 82 } 83 set obj [Rappture::Unirect3d ::#auto $xmlobj $path] 84 set _xp2obj($handle) $obj 85 set _obj2ref($obj) 1 86 return $obj 87 } 88 89 # ---------------------------------------------------------------------- 90 # USAGE: Rappture::Unirect3d::release <obj> 91 # 92 # Clients call this when they're no longer using a Mesh fetched 93 # previously by the "fetch" proc. This decrements the reference 94 # count for the mesh and destroys the object when it is no longer 95 # in use. 96 # ---------------------------------------------------------------------- 97 itcl::body Rappture::Unirect3d::release { obj } { 98 if { ![info exists _obj2ref($obj)] } { 99 error "can't find reference count for $obj" 100 } 101 incr _obj2ref($obj) -1 102 if {$_obj2ref($obj) <= 0} { 103 unset _obj2ref($obj) 104 foreach handle [array names _xp2obj] { 105 if {$_xp2obj($handle) == $obj} { 106 unset _xp2obj($handle) 107 } 108 } 109 itcl::delete object $obj 110 } 70 111 } 71 112 … … 73 114 # Constructor 74 115 # ---------------------------------------------------------------------- 75 itcl::body Rappture::Unirect3d::constructor {xmlobj field cname {numComponents 1}} {116 itcl::body Rappture::Unirect3d::constructor {xmlobj path} { 76 117 if {![Rappture::library isvalid $xmlobj]} { 77 118 error "bad value \"$xmlobj\": should be Rappture::library" 78 119 } 79 set path [$field get $cname.mesh]80 120 set m [$xmlobj element -as object $path] 81 121 GetValue $m "xaxis.min" _xMin … … 88 128 GetSize $m "yaxis.numpoints" _yNum 89 129 GetSize $m "zaxis.numpoints" _zNum 90 set _compNum $numComponents91 130 foreach {key path} { 92 group about.group93 131 label about.label 94 132 color about.color 95 133 style about.style 96 type about.type97 134 xlabel xaxis.label 98 135 xdesc xaxis.description … … 113 150 zmin zaxis.min 114 151 zmax zaxis.max 115 order about.axisorder116 152 } { 117 153 set str [$m get $path] 118 if {"" != $str} {119 set _hints($key) $str120 }121 }122 foreach {key} { axisorder } {123 set str [$field get $cname.$key]124 154 if {"" != $str} { 125 155 set _hints($key) $str … … 131 161 set _vtkdata "" 132 162 return 133 }134 set _values [blt::vector create #auto]135 $_values set [$field get "$cname.values"]136 set n [expr $_numPoints * $_compNum]137 if { [$_values length] != $n } {138 error "wrong \# of values in \"$cname.values\": expected $n values, got [$_values length]"139 163 } 140 164 append out "DATASET STRUCTURED_POINTS\n" … … 166 190 # ---------------------------------------------------------------------- 167 191 itcl::body Rappture::Unirect3d::destructor {} { 168 if { $_values != "" } { 169 blt::vector destroy $_values 170 } 171 } 172 173 # ---------------------------------------------------------------------- 174 # method blob 175 # Returns a Tcl list that represents the Tcl command and data to 176 # recreate the uniform rectangular grid on the nanovis server. 177 # ---------------------------------------------------------------------- 178 itcl::body Rappture::Unirect3d::blob {} { 179 set data "unirect3d" 180 lappend data "xmin" $_xMin "xmax" $_xMax "xnum" $_xNum 181 lappend data "ymin" $_yMin "ymax" $_yMax "ynum" $_yNum 182 lappend data "zmin" $_zMin "zmax" $_zMax "znum" $_zNum 183 lappend data "axisorder" $_axisOrder 184 if { [$_values length] > 0 } { 185 lappend data "values" [$_values range 0 end] 186 } 187 return $data 188 } 189 190 # ---------------------------------------------------------------------- 191 # method mesh 192 # Returns a Tcl list that represents the points of the uniform 193 # grid. Each point has x,y and z values in the list. 194 # ---------------------------------------------------------------------- 195 itcl::body Rappture::Unirect3d::mesh {} { 196 set dx [expr {($_xMax - $_xMin) / double($_xNum - 1)}] 197 set dy [expr {($_yMax - $_yMin) / double($_yNum - 1)}] 198 set dz [expr {($_zMax - $_zMin) / double($_zNum - 1)}] 199 foreach {a b c} $_axisOrder break 200 for { set i 0 } { $i < [set _${a}Num] } { incr i } { 201 set v1 [expr {[set _${a}Min] + (double($i) * [set d${a}])}] 202 for { set j 0 } { $j < [set _${b}Num] } { incr j } { 203 set v2 [expr {[set _${b}Min] + (double($i) * [set d${b}])}] 204 for { set k 0 } { $k < [set _${c}Num] } { incr k } { 205 set v3 [expr {[set _${c}Min] + (double($i) * [set d${c}])}] 206 lappend data $v1 $v2 $v3 207 } 208 } 209 } 210 return $data 211 } 212 213 # ---------------------------------------------------------------------- 214 # method values 215 # Returns a BLT vector that represents the field values 216 # ---------------------------------------------------------------------- 217 itcl::body Rappture::Unirect3d::values {} { 218 return $_values 192 # empty 219 193 } 220 194 … … 241 215 set max $_zMax 242 216 } 243 v - vlin - vlog {244 if { [$_values length] > 0 } {245 set min [blt::vector expr min($_values)]246 set max [blt::vector expr max($_values)]247 } else {248 set min 0.0249 set max 1.0250 }251 }252 217 default { 253 218 error "unknown axis description \"$which\"" … … 301 266 set _hints(ylabel) "$_hints(zlabel) ($_hints(zunits))" 302 267 } 303 304 268 if {[info exists _hints(group)] && [info exists _hints(label)]} { 305 269 # pop-up help for each curve
Note: See TracChangeset
for help on using the changeset viewer.