Changeset 5001
- Timestamp:
- Feb 11, 2015, 2:15:48 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/field.tcl
r5000 r5001 68 68 private variable _limits; # maps axis name => {z0 z1} limits 69 69 private variable _field "" 70 private variable _comp2fldName ; 71 private variable _comp2type ; 72 private variable _comp2size ; 73 private variable _comp2assoc; 70 private variable _comp2fldName ; # cname => field names. 71 private variable _comp2type ; # cname => type (e.g. "vectors") 72 private variable _comp2size ; # cname => # of components in element 73 private variable _comp2assoc; # cname => association (e.g. pointdata) 74 74 private variable _fld2Components; # field name => number of components 75 75 private variable _fld2Label; # field name => label … … 83 83 84 84 constructor {xmlobj path} { 85 85 # defined below 86 86 } 87 87 destructor { 88 88 # defined below 89 89 } 90 90 public method blob { cname } … … 126 126 } 127 127 public method viewer {} { 128 128 return $_viewer 129 129 } 130 130 protected method Build {} … … 144 144 private variable _comp2cntls ;# maps component name => x,y control points 145 145 private variable _comp2extents 146 private variable _comp2limits; 146 private variable _comp2limits; # Array of limits per component 147 147 private variable _type "" 148 148 private variable _comp2flowhints … … 228 228 } 229 229 foreach name [array names _comp2mesh] { 230 231 232 230 # Data is in the form of a mesh and a vector. 231 foreach { mesh vector } $_comp2mesh($name) break 232 # Release the mesh (may be shared) 233 233 set class [$mesh info class] 234 234 ${class}::release $mesh 235 235 # Destroy the vector 236 236 blt::vector destroy $vector 237 237 } … … 312 312 } 313 313 if {[info exists _comp2vtk($cname)]} { 314 314 # FIXME: extract mesh from VTK file data. 315 315 error "method \"mesh\" is not implemented for VTK file data" 316 316 } … … 348 348 } 349 349 if { [info exists _comp2vtk($cname)] } { 350 350 # FIXME: extract the values from the VTK file data 351 351 error "method \"values\" is not implemented for VTK file data" 352 352 } … … 355 355 } 356 356 if { [info exists _comp2mesh($cname)] } { 357 357 set vector [lindex $_comp2mesh($cname) 1] 358 358 return [$vector range 0 end] 359 359 } … … 380 380 } 381 381 if { [info exists _comp2vtk($cname)] } { 382 382 error "blob not implemented for VTK file data" 383 383 } 384 384 if {[info exists _comp2dx($cname)]} { … … 424 424 switch -- $which { 425 425 x - xlin { 426 427 426 set pos 0; set log 0; set axis x 427 } 428 428 xlog { 429 430 429 set pos 0; set log 1; set axis x 430 } 431 431 y - ylin - v - vlin { 432 433 432 set pos 1; set log 0; set axis y 433 } 434 434 ylog - vlog { 435 436 435 set pos 1; set log 1; set axis y 436 } 437 437 default { 438 438 error "bad axis \"$which\": should be x, xlin, xlog, y, ylin, ylog, v, vlin, vlog" … … 471 471 default { 472 472 if {[info exists _comp2limits($cname)]} { 473 474 473 array set limits $_comp2limits($cname) 474 switch -- $which { 475 475 x - xlin - xlog { 476 476 set axis x 477 477 foreach {axisMin axisMax} $limits(x) break 478 478 } 479 479 y - ylin - ylog { 480 480 set axis y 481 481 foreach {axisMin axisMax} $limits(y) break 482 482 } 483 483 z - zlin - zlog { 484 484 set axis z 485 485 foreach {axisMin axisMax} $limits(z) break 486 486 } 487 487 v - vlin - vlog { 488 488 set axis v 489 490 491 492 493 494 489 foreach {axisMin axisMax} $limits(v) break 490 } 491 default { 492 if { ![info exists limits($which)] } { 493 error "limits: unknown axis \"$which\"" 494 } 495 495 set axis v 496 497 498 496 foreach {axisMin axisMax} $limits($which) break 497 } 498 } 499 499 } else { 500 500 set axisMin 0 ;# HACK ALERT! must be OpenDX data … … 770 770 set type "" 771 771 if { ([$_field element $cname.constant] != "" && 772 773 772 [$_field element $cname.domain] != "") || 773 [$_field element $cname.xy] != "" } { 774 774 set type "1D" 775 775 } elseif { [$_field element $cname.mesh] != "" && 776 776 [$_field element $cname.values] != ""} { 777 777 set type "points-on-mesh" 778 778 } elseif { [$_field element $cname.vtk] != ""} { 779 780 781 782 783 779 set type "vtk" 780 set viewer [$_field get "about.view"] 781 if { $viewer != "" } { 782 set _viewer $viewer 783 } 784 784 } elseif {[$_field element $cname.opendx] != ""} { 785 785 global env … … 798 798 } elseif {[$_field element $cname.dicom] != ""} { 799 799 set type "dicom" 800 800 } 801 801 set _comp2style($cname) "" 802 802 if { $type == "" } { … … 871 871 } 872 872 } elseif {$type == "points-on-mesh"} { 873 873 if { ![BuildPointsOnMesh $cname] } { 874 874 continue; # Ignore this component 875 875 } … … 1178 1178 set dataAttrs [$dataset GetPointData] 1179 1179 if { $dataAttrs == ""} { 1180 1180 puts stderr "WARNING: No point data found in \"$_path\"" 1181 1181 rename $reader "" 1182 1182 return 0 … … 1215 1215 set _dim 0 1216 1216 if { $xmax > $xmin } { 1217 1217 incr _dim 1218 1218 } 1219 1219 if { $ymax > $ymin } { 1220 1220 incr _dim 1221 1221 } 1222 1222 if { $zmax > $zmin } { 1223 1223 incr _dim 1224 1224 } 1225 1225 if { $_viewer == "" } { 1226 1227 1228 1229 1230 1226 if { $_dim == 2 } { 1227 set _viewer contour 1228 } else { 1229 set _viewer isosurface 1230 } 1231 1231 } 1232 1232 set _comp2dims($cname) ${_dim}D … … 1263 1263 set dataAttrs [$dataset GetPointData] 1264 1264 if { $dataAttrs == ""} { 1265 1265 puts stderr "WARNING: No point data found in \"$_path\"" 1266 1266 rename $reader "" 1267 1267 return 0 … … 1271 1271 set numArrays [$dataAttrs GetNumberOfArrays] 1272 1272 if { $numArrays > 0 } { 1273 1274 1275 1276 1273 for {set i 0} {$i < [$dataAttrs GetNumberOfArrays] } {incr i} { 1274 set array [$dataAttrs GetArray $i] 1275 set fname [$dataAttrs GetArrayName $i] 1276 foreach {min max} [$array GetRange -1] break 1277 1277 if {$i == 0} { 1278 1278 set vmin $min 1279 1279 set vmax $max 1280 1280 } 1281 1281 lappend limits $fname [list $min $max] 1282 1282 set _fld2Units($fname) "" 1283 1283 set _fld2Label($fname) $fname 1284 1284 # Let the VTK file override the <type> designated. 1285 1285 set _fld2Components($fname) [$array GetNumberOfComponents] 1286 1286 lappend _comp2fldName($cname) $fname 1287 1287 } 1288 1288 } 1289 1289 … … 1297 1297 # vtkdata -- 1298 1298 # 1299 # 1300 # 1299 # Returns a string representing the mesh and field data for a specific 1300 # component in the legacy VTK file format. 1301 1301 # 1302 1302 itcl::body Rappture::Field::vtkdata {cname} { … … 1316 1316 # Points on mesh: Construct VTK file output. 1317 1317 if { [info exists _comp2mesh($cname)] } { 1318 1319 1318 # Data is in the form mesh and vector 1319 foreach {mesh vector} $_comp2mesh($cname) break 1320 1320 set label $cname 1321 1321 regsub -all { } $label {_} label 1322 1323 1324 1325 1322 append out "# vtk DataFile Version 3.0\n" 1323 append out "[hints label]\n" 1324 append out "ASCII\n" 1325 append out [$mesh vtkdata] 1326 1326 1327 1327 if { $_comp2assoc($cname) == "pointdata" } { … … 1369 1369 VerifyVtkDataSet $out 1370 1370 } 1371 1371 return $out 1372 1372 } 1373 1373 error "can't find vtkdata for $cname" … … 1377 1377 # BuildPointsOnMesh -- 1378 1378 # 1379 # 1380 # 1381 # 1379 # Parses the field XML description to build a mesh and values vector 1380 # representing the field. Right now we handle the deprecated types 1381 # of "cloud", "unirect2d", and "unirect3d" (mostly for flows). 1382 1382 # 1383 1383 itcl::body Rappture::Field::BuildPointsOnMesh {cname} { … … 1388 1388 set path [$_field get $cname.mesh] 1389 1389 if {[$_xmlobj element $path] == ""} { 1390 1391 1390 # Unknown mesh designated. 1391 return 0 1392 1392 } 1393 1393 set viewer [$_field get "about.view"] … … 1409 1409 # Handle bizarre cases that hopefully will be deprecated. 1410 1410 if { $element == "unirect3d" } { 1411 1411 # Special case: unirect3d (should be deprecated) + flow. 1412 1412 if { [$_field element $cname.extents] != "" } { 1413 1413 set vectorsize [$_field get $cname.extents] … … 1416 1416 } 1417 1417 set _type unirect3d 1418 1418 set _dim 3 1419 1419 if { $_viewer == "" } { 1420 1420 set _viewer flowvis 1421 1421 } 1422 1423 1424 1425 1422 set _comp2dims($cname) "3D" 1423 set _comp2unirect3d($cname) \ 1424 [Rappture::Unirect3d \#auto $_xmlobj $_field $cname $vectorsize] 1425 set _comp2style($cname) [$_field get $cname.style] 1426 1426 set limits {} 1427 1427 foreach axis { x y z } { … … 1434 1434 lappend limits v $minmax 1435 1435 set _comp2limits($cname) $limits 1436 1437 1438 1439 1440 1441 1436 if {[$_field element $cname.flow] != ""} { 1437 set _comp2flowhints($cname) \ 1438 [Rappture::FlowHints ::\#auto $_field $cname $_units] 1439 } 1440 incr _counter 1441 return 1 1442 1442 } 1443 1443 if { $element == "unirect2d" && [$_field element $cname.flow] != "" } { 1444 1444 # Special case: unirect2d (normally deprecated) + flow. 1445 1445 if { [$_field element $cname.extents] != "" } { 1446 1446 set vectorsize [$_field get $cname.extents] … … 1449 1449 } 1450 1450 set _type unirect2d 1451 1451 set _dim 2 1452 1452 if { $_viewer == "" } { 1453 1453 set _viewer "flowvis" 1454 1454 } 1455 1456 1457 1458 1459 1460 1461 1455 set _comp2dims($cname) "2D" 1456 set _comp2unirect2d($cname) \ 1457 [Rappture::Unirect2d \#auto $_xmlobj $path] 1458 set _comp2style($cname) [$_field get $cname.style] 1459 set _comp2flowhints($cname) \ 1460 [Rappture::FlowHints ::\#auto $_field $cname $_units] 1461 set _values [$_field get $cname.values] 1462 1462 set limits {} 1463 1463 foreach axis { x y z } { … … 1471 1471 blt::vector destroy $xv 1472 1472 set _comp2limits($cname) $limits 1473 1474 1473 incr _counter 1474 return 1 1475 1475 } 1476 1476 switch -- $element { 1477 1478 1477 "cloud" { 1478 set mesh [Rappture::Cloud::fetch $_xmlobj $path] 1479 1479 set _type cloud 1480 1481 1482 1480 } 1481 "mesh" { 1482 set mesh [Rappture::Mesh::fetch $_xmlobj $path] 1483 1483 set _type mesh 1484 }1485 1484 } 1485 "unirect2d" { 1486 1486 if { $_viewer == "" } { 1487 1487 set _viewer "heightmap" 1488 1488 } 1489 1489 set mesh [Rappture::Unirect2d::fetch $_xmlobj $path] 1490 1490 set _type unirect2d 1491 1491 } 1492 1492 } 1493 1493 if { ![$mesh isvalid] } { … … 1514 1514 return 0 1515 1515 1516 1517 1516 # 1D data: Create vectors for graph widget. 1517 # The prophet tool currently outputs 1D clouds with fields 1518 1518 # Band Structure Lab used to (see isosurface1 test in rappture-bat) 1519 1520 1521 1522 1523 1524 1525 1526 1527 1519 # 1520 # Is there a natural growth path in generating output from 1D to 1521 # higher dimensions? If there isn't, let's kill this in favor 1522 # or explicitly using a <curve> instead. Otherwise, the features 1523 # (methods such as xmarkers) or the <curve> need to be added 1524 # to the <field>. 1525 # 1526 #set xv [blt::vector create x$_counter] 1527 #set yv [blt::vector create y$_counter] 1528 1528 1529 1529 # This only works with a Cloud mesh type, since the points method 1530 1530 # is not implemented for the Mesh object 1531 1531 #$xv set [$mesh points] 1532 1532 # TODO: Put field values in yv 1533 1534 1535 1536 1533 #set _comp2dims($cname) "1D" 1534 #set _comp2xy($cname) [list $xv $yv] 1535 #incr _counter 1536 #return 1 1537 1537 } 1538 1538 if {$_dim == 2} { 1539 1540 1541 1539 # 2D data: By default surface or contour plot using heightmap widget. 1540 set v [blt::vector create \#auto] 1541 $v set [$_field get $cname.values] 1542 1542 if { [$v length] == 0 } { 1543 1543 return 0 … … 1566 1566 } 1567 1567 } 1568 1569 1570 1568 set _comp2dims($cname) "[$mesh dimensions]D" 1569 set _comp2mesh($cname) [list $mesh $v] 1570 set _comp2style($cname) [$_field get $cname.style] 1571 1571 if {[$_field element $cname.flow] != ""} { 1572 1572 set _comp2flowhints($cname) \ 1573 1573 [Rappture::FlowHints ::\#auto $_field $cname $_units] 1574 1574 } 1575 1576 1575 incr _counter 1576 array unset _comp2limits $cname 1577 1577 foreach axis { x y z } { 1578 1578 lappend _comp2limits($cname) $axis [$mesh limits $axis] … … 1581 1581 lappend _comp2limits($cname) $cname $minmax 1582 1582 lappend _comp2limits($cname) v $minmax 1583 1583 return 1 1584 1584 } 1585 1585 if {$_dim == 3} { 1586 1586 # 3D data: By default isosurfaces plot using isosurface widget. 1587 1587 if { $_viewer == "" } { 1588 1588 set _viewer "isosurface" 1589 1589 } 1590 1591 1590 set v [blt::vector create \#auto] 1591 $v set [$_field get $cname.values] 1592 1592 if { [$v length] == 0 } { 1593 1593 return 0 … … 1627 1627 lappend _comp2limits($cname) $cname $minmax 1628 1628 lappend _comp2limits($cname) v $minmax 1629 1629 return 1 1630 1630 } 1631 1631 error "unhandled case in field dim=$_dim element=$element"
Note: See TracChangeset
for help on using the changeset viewer.