- Timestamp:
- May 27, 2015, 2:36:55 PM (9 years ago)
- Location:
- trunk/gui/scripts
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/field.tcl
r5610 r5611 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] { … … 324 314 error "method \"mesh\" is not implemented for Rappture::Mesh" 325 315 } 326 if {[info exists _comp2unirect2d($cname)]} {327 error "method \"mesh\" is not implemented for unirect2d"328 }329 if {[info exists _comp2unirect3d($cname)]} {330 error "method \"mesh\" is not implemented for unirect3d"331 }332 316 error "can't get field mesh: Unknown component \"$cname\": should be one of [join [lsort [array names _comp2dims]] {, }]" 333 317 } … … 357 341 return [lindex $_comp2mesh($cname) 1] ;# return vector 358 342 } 359 if {[info exists _comp2unirect2d($cname)]} {360 error "method \"values\" is not implemented for unirect2d"361 }362 if {[info exists _comp2unirect3d($cname)]} {363 error "method \"values\" is not implemented for unirect3d"364 }365 343 error "can't get field values. Unknown component \"$cname\": should be one of [join [lsort [array names _comp2dims]] {, }]" 366 344 } … … 378 356 return $_comp2dx($cname) ;# return gzipped, base64-encoded DX data 379 357 } 380 if {[info exists _comp2unirect2d($cname)]} {381 set blob [$_comp2unirect2d($cname) blob]382 lappend blob "values" $_values383 return $blob384 }385 if {[info exists _comp2unirect3d($cname)]} {386 return [$_comp2unirect3d($cname) blob]387 }388 358 if {[info exists _comp2mesh($cname)]} { 389 359 error "method \"blob\" not implemented for Rappture::Mesh" 390 360 } 391 if { [info exists _comp2vtk($cname)]} {361 if {[info exists _comp2vtk($cname)]} { 392 362 error "method \"blob\" not implemented for VTK file data" 393 363 } … … 750 720 } 751 721 array unset _comp2vtk 752 foreach name [array names _comp2unirect2d] {753 eval itcl::delete object $_comp2unirect2d($name)754 }755 foreach name [array names _comp2unirect3d] {756 eval itcl::delete object $_comp2unirect3d($name)757 }758 722 catch {unset _comp2xy} 759 723 catch {unset _comp2dx} 760 724 catch {unset _comp2dims} 761 725 catch {unset _comp2style} 762 array unset _comp2unirect2d763 array unset _comp2unirect3d764 726 array unset _dataobj2type 765 727 # … … 1320 1282 set data [Rappture::encoding::decode -as zb64 $data] 1321 1283 return [Rappture::DxToVtk $data] 1322 }1323 # unirect2d (deprecated)1324 # This can be removed when the nanovis server with support for loading VTK1325 # vector data is released1326 if {[info exists _comp2unirect2d($cname)]} {1327 set label $cname1328 regsub -all { } $label {_} label1329 set elemSize [numComponents $cname]1330 set numValues [$_comp2unirect2d($cname) numpoints]1331 append out "# vtk DataFile Version 3.0\n"1332 append out "[hints label]\n"1333 append out "ASCII\n"1334 append out [$_comp2unirect2d($cname) vtkdata]1335 append out "POINT_DATA $numValues\n"1336 if {$elemSize == 3} {1337 append out "VECTORS $label double\n"1338 } else {1339 append out "SCALARS $label double $elemSize\n"1340 append out "LOOKUP_TABLE default\n"1341 }1342 # values for VTK are x-fastest1343 append out $_values1344 append out "\n"1345 return $out1346 }1347 # unirect3d (deprecated)1348 if {[info exists _comp2unirect3d($cname)]} {1349 set vector [$_comp2unirect3d($cname) values]1350 set label $cname1351 regsub -all { } $label {_} label1352 set elemSize [numComponents $cname]1353 set numValues [expr [$vector length] / $elemSize]1354 append out "# vtk DataFile Version 3.0\n"1355 append out "[hints label]\n"1356 append out "ASCII\n"1357 append out [$_comp2unirect3d($cname) vtkdata]1358 append out "POINT_DATA $numValues\n"1359 if {$elemSize == 3} {1360 append out "VECTORS $label double\n"1361 } else {1362 append out "SCALARS $label double $elemSize\n"1363 append out "LOOKUP_TABLE default\n"1364 }1365 # values for VTK are x-fastest1366 append out [$vector range 0 end]1367 append out "\n"1368 return $out1369 1284 } 1370 1285 # Points on mesh: Construct VTK file output. … … 1458 1373 lappend _comp2fldName($cname) $name 1459 1374 1460 # Handle bizarre cases that are due to be removed.1461 if { $element == "unirect3d" } {1462 # Special case: unirect3d (deprecated) + flow.1463 set vectorsize [numComponents $cname]1464 set _type unirect3d1465 set _dim 31466 if { $_viewer == "" } {1467 set _viewer flowvis1468 }1469 set _comp2dims($cname) "3D"1470 set _comp2unirect3d($cname) \1471 [Rappture::Unirect3d \#auto $_xmlobj $_field $cname $vectorsize]1472 set _comp2style($cname) [$_field get $cname.style]1473 set limits {}1474 foreach axis { x y z } {1475 lappend limits $axis [$_comp2unirect3d($cname) limits $axis]1476 }1477 # Get the data limits1478 set vector [$_comp2unirect3d($cname) values]1479 set minmax [VectorLimits $vector $vectorsize]1480 lappend limits $cname $minmax1481 lappend limits v $minmax1482 set _comp2limits($cname) $limits1483 if {[$_field element $cname.flow] != ""} {1484 set _comp2flowhints($cname) \1485 [Rappture::FlowHints ::\#auto $_field $cname $_units]1486 }1487 incr _counter1488 return 11489 }1490 if { $element == "unirect2d" && [$_field element $cname.flow] != "" } {1491 # Special case: unirect2d (deprecated) + flow.1492 set vectorsize [numComponents $cname]1493 set _type unirect2d1494 set _dim 21495 if { $_viewer == "" } {1496 set _viewer "flowvis"1497 }1498 set _comp2dims($cname) "2D"1499 set _comp2unirect2d($cname) \1500 [Rappture::Unirect2d \#auto $_xmlobj $path]1501 set _comp2style($cname) [$_field get $cname.style]1502 set _comp2flowhints($cname) \1503 [Rappture::FlowHints ::\#auto $_field $cname $_units]1504 set _values [$_field get $cname.values]1505 set limits {}1506 foreach axis { x y z } {1507 lappend limits $axis [$_comp2unirect2d($cname) limits $axis]1508 }1509 set xv [blt::vector create \#auto]1510 $xv set $_values1511 set minmax [VectorLimits $xv $vectorsize]1512 lappend limits $cname $minmax1513 lappend limits v $minmax1514 blt::vector destroy $xv1515 set _comp2limits($cname) $limits1516 incr _counter1517 return 11518 }1519 1375 switch -- $element { 1520 1376 "cloud" { … … 1532 1388 set mesh [Rappture::Unirect2d::fetch $_xmlobj $path] 1533 1389 set _type unirect2d 1390 } 1391 "unirect3d" { 1392 set mesh [Rappture::Unirect3d::fetch $_xmlobj $path] 1393 set _type unirect3d 1534 1394 } 1535 1395 } -
trunk/gui/scripts/unirect2d.tcl
r5610 r5611 29 29 public proc release {obj} 30 30 31 public method blob {}32 31 public method dimensions {} { 33 32 return 2 … … 49 48 private method GetSize { obj path varName } 50 49 51 private variable _axisOrder "x y"52 50 private variable _xMax 0 53 51 private variable _xMin 0 … … 125 123 GetSize $m "yaxis.numpoints" _yNum 126 124 foreach {key path} { 127 group about.group128 125 label about.label 129 126 color about.color 130 127 style about.style 131 type about.type132 128 xlabel xaxis.label 133 129 xdesc xaxis.description … … 182 178 183 179 # ---------------------------------------------------------------------- 184 # method blob185 # Returns a Tcl list that represents the Tcl command and data to186 # recreate the uniform rectangular grid on the nanovis server.187 # ----------------------------------------------------------------------188 itcl::body Rappture::Unirect2d::blob {} {189 set data "unirect2d"190 lappend data "xmin" $_xMin "xmax" $_xMax "xnum" $_xNum191 lappend data "ymin" $_yMin "ymax" $_yMax "ynum" $_yNum192 return $data193 }194 195 # ----------------------------------------------------------------------196 180 # method limits <axis> 197 181 # Returns a list {min max} representing the limits for the -
trunk/gui/scripts/unirect3d.tcl
r5610 r5611 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 … … 40 41 return $_numPoints 41 42 } 42 public method order {} {43 return _axisOrder;44 }45 43 public method units { axis } 46 public method values {}47 44 public method vtkdata {{what -partial}} {} 48 45 … … 51 48 private method GetSize { obj path varName } 52 49 53 private variable _axisOrder "x y z"54 50 private variable _xMax 0 55 51 private variable _xMin 0 … … 61 57 private variable _zMin 0 62 58 private variable _zNum 0; # Number of points along z-axis 63 private variable _compNum 1; # Number of components in values64 private variable _values ""; # BLT vector containing the values65 59 private variable _hints 66 60 private variable _vtkdata "" 67 61 private variable _numPoints 0 68 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 } 69 111 } 70 112 … … 72 114 # Constructor 73 115 # ---------------------------------------------------------------------- 74 itcl::body Rappture::Unirect3d::constructor {xmlobj field cname {numComponents 1}} {116 itcl::body Rappture::Unirect3d::constructor {xmlobj path} { 75 117 if {![Rappture::library isvalid $xmlobj]} { 76 118 error "bad value \"$xmlobj\": should be Rappture::library" 77 119 } 78 set path [$field get $cname.mesh]79 120 set m [$xmlobj element -as object $path] 80 121 GetValue $m "xaxis.min" _xMin … … 87 128 GetSize $m "yaxis.numpoints" _yNum 88 129 GetSize $m "zaxis.numpoints" _zNum 89 set _compNum $numComponents90 130 foreach {key path} { 91 group about.group92 131 label about.label 93 132 color about.color 94 133 style about.style 95 type about.type96 134 xlabel xaxis.label 97 135 xdesc xaxis.description … … 112 150 zmin zaxis.min 113 151 zmax zaxis.max 114 order about.axisorder115 152 } { 116 153 set str [$m get $path] 117 if {"" != $str} {118 set _hints($key) $str119 }120 }121 foreach {key} { axisorder } {122 set str [$field get $cname.$key]123 154 if {"" != $str} { 124 155 set _hints($key) $str … … 130 161 set _vtkdata "" 131 162 return 132 }133 set _values [blt::vector create #auto]134 $_values set [$field get "$cname.values"]135 set n [expr $_numPoints * $_compNum]136 if { [$_values length] != $n } {137 error "wrong \# of values in \"$cname.values\": expected $n values, got [$_values length]"138 163 } 139 164 append out "DATASET STRUCTURED_POINTS\n" … … 165 190 # ---------------------------------------------------------------------- 166 191 itcl::body Rappture::Unirect3d::destructor {} { 167 if { $_values != "" } { 168 blt::vector destroy $_values 169 } 170 } 171 172 # ---------------------------------------------------------------------- 173 # method blob 174 # Returns a Tcl list that represents the Tcl command and data to 175 # recreate the uniform rectangular grid on the nanovis server. 176 # ---------------------------------------------------------------------- 177 itcl::body Rappture::Unirect3d::blob {} { 178 set data "unirect3d" 179 lappend data "xmin" $_xMin "xmax" $_xMax "xnum" $_xNum 180 lappend data "ymin" $_yMin "ymax" $_yMax "ynum" $_yNum 181 lappend data "zmin" $_zMin "zmax" $_zMax "znum" $_zNum 182 lappend data "axisorder" $_axisOrder 183 if { [$_values length] > 0 } { 184 lappend data "values" [$_values range 0 end] 185 } 186 return $data 187 } 188 189 # ---------------------------------------------------------------------- 190 # method values 191 # Returns a BLT vector that represents the field values 192 # ---------------------------------------------------------------------- 193 itcl::body Rappture::Unirect3d::values {} { 194 return $_values 192 # empty 195 193 } 196 194 … … 217 215 set max $_zMax 218 216 } 219 v - vlin - vlog {220 if { [$_values length] > 0 } {221 set min [blt::vector expr min($_values)]222 set max [blt::vector expr max($_values)]223 } else {224 set min 0.0225 set max 1.0226 }227 }228 217 default { 229 218 error "unknown axis description \"$which\"" … … 277 266 set _hints(ylabel) "$_hints(zlabel) ($_hints(zunits))" 278 267 } 279 280 268 if {[info exists _hints(group)] && [info exists _hints(label)]} { 281 269 # pop-up help for each curve
Note: See TracChangeset
for help on using the changeset viewer.