- Timestamp:
- Feb 11, 2015 2:20:19 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/field.tcl
r5001 r5002 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 2 # ---------------------------------------------------------------------- 3 3 # COMPONENT: field - extracts data from an XML description of a field … … 25 25 # unirect2d (deprecated) 26 26 # cloud (x,y point coordinates) (deprecated) 27 # mesh 27 # mesh 28 28 # 3D Datasets 29 # vtk 29 # vtk 30 30 # unirect3d (deprecated) 31 31 # cloud (x,y,z coordinates) (deprecated) 32 # mesh 32 # mesh 33 33 # dx (FIXME: make dx-to-vtk converter work) 34 34 # ucd avs … … 46 46 # With <views>, can specify which viewer for specific datasets. So it's OK 47 47 # for the same dataset to be viewed in more than one way. 48 # o Any 2D dataset can be viewed as a contour/heightmap. 48 # o Any 2D dataset can be viewed as a contour/heightmap. 49 49 # o Any 3D dataset can be viewed as a isosurface. 50 # o Any 2D dataset with vector data can be streamlines or flow. 50 # o Any 2D dataset with vector data can be streamlines or flow. 51 51 # o Any 3D uniform rectilinear dataset can be viewed as a volume. 52 52 # o Any 3D dataset with vector data can be streamlines or flow. … … 59 59 package require BLT 60 60 61 namespace eval Rappture { 62 # forward declaration 61 namespace eval Rappture { 62 # forward declaration 63 63 } 64 64 … … 75 75 private variable _fld2Label; # field name => label 76 76 private variable _fld2Units; # field name => units 77 private variable _hints 77 private variable _hints 78 78 private variable _viewer ""; # Hints which viewer to use 79 79 private variable _isValid 0; # Indicates if the field contains … … 82 82 private variable _alwaysConvertDX 0; 83 83 84 constructor {xmlobj path} { 85 # defined below 86 } 87 destructor { 88 # defined below 84 constructor {xmlobj path} { 85 # defined below 86 } 87 destructor { 88 # defined below 89 89 } 90 90 public method blob { cname } … … 126 126 } 127 127 public method viewer {} { 128 return $_viewer 128 return $_viewer 129 129 } 130 130 protected method Build {} 131 131 protected method _getValue {expr} 132 132 133 private variable _path ""; # Path of this object in the XML 133 private variable _path ""; # Path of this object in the XML 134 134 private variable _units "" ; # system of units for this field 135 135 private variable _zmax 0 ;# length of the device … … 143 143 private variable _comp2style ;# maps component name => style settings 144 144 private variable _comp2cntls ;# maps component name => x,y control points 145 private variable _comp2extents 145 private variable _comp2extents 146 146 private variable _comp2limits; # Array of limits per component 147 private variable _type "" 148 private variable _comp2flowhints 147 private variable _type "" 148 private variable _comp2flowhints 149 149 private variable _comp2mesh ;# list of: mesh object, BLT vector of values 150 150 private variable _values "" ;# Only used for unirect2d - list of values 151 151 private common _counter 0 ;# counter for unique vector names 152 152 153 private method AvsToVtk { cname contents } 154 private method DicomToVtk { cname contents } 155 private method BuildPointsOnMesh { cname } 156 protected method GetAssociation { cname } 157 protected method GetTypeAndSize { cname } 158 protected method ReadVtkDataSet { cname contents } 159 private method InitHints {} 160 161 private method VerifyVtkDataSet { contents } 153 private method AvsToVtk { cname contents } 154 private method DicomToVtk { cname contents } 155 private method BuildPointsOnMesh { cname } 156 protected method GetAssociation { cname } 157 protected method GetTypeAndSize { cname } 158 protected method ReadVtkDataSet { cname contents } 159 private method InitHints {} 160 161 private method VerifyVtkDataSet { contents } 162 162 private method VectorLimits { vector vectorsize {comp -1} } 163 163 } … … 284 284 # Now handle the tests. 285 285 switch -- $params(what) { 286 -name { 286 -name { 287 287 set rlist $components 288 288 } 289 -style { 289 -style { 290 290 foreach cname $components { 291 291 if { [info exists _comp2style($cname)] } { 292 lappend rlist $_comp2style($cname) 292 lappend rlist $_comp2style($cname) 293 293 } 294 294 } … … 399 399 # USAGE: valueLimits <cname> 400 400 # 401 # Returns an array for the requested component with a list {min max} 401 # Returns an array for the requested component with a list {min max} 402 402 # representing the limits for each axis. 403 403 # ---------------------------------------------------------------------- … … 423 423 1D { 424 424 switch -- $which { 425 x - xlin { 426 set pos 0; set log 0; set axis x 425 x - xlin { 426 set pos 0; set log 0; set axis x 427 427 } 428 xlog { 429 set pos 0; set log 1; set axis x 428 xlog { 429 set pos 0; set log 1; set axis x 430 430 } 431 y - ylin - v - vlin { 432 set pos 1; set log 0; set axis y 431 y - ylin - v - vlin { 432 set pos 1; set log 0; set axis y 433 433 } 434 ylog - vlog { 435 set pos 1; set log 1; set axis y 434 ylog - vlog { 435 set pos 1; set log 1; set axis y 436 436 } 437 437 default { … … 471 471 default { 472 472 if {[info exists _comp2limits($cname)]} { 473 array set limits $_comp2limits($cname) 473 array set limits $_comp2limits($cname) 474 474 switch -- $which { 475 475 x - xlin - xlog { … … 536 536 itcl::body Rappture::Field::fieldlimits {} { 537 537 foreach cname [array names _comp2limits] { 538 array set limits $_comp2limits($cname) 538 array set limits $_comp2limits($cname) 539 539 foreach fname [fieldnames $cname] { 540 540 if { ![info exists limits($fname)] } { … … 562 562 return "" 563 563 } 564 564 565 565 # ---------------------------------------------------------------------- 566 566 # USAGE: controls get ?<name>? … … 786 786 if { [info exists env(VTKVOLUME)] } { 787 787 set _viewer "vtkvolume" 788 } 788 } 789 789 set type "opendx" 790 790 } elseif {[$_field element $cname.dx] != ""} { … … 808 808 set extents [$_field get $cname.extents] 809 809 } else { 810 set extents 1 810 set extents 1 811 811 } 812 812 set _comp2extents($cname) $extents … … 972 972 return 0 973 973 } 974 # Sanity check. Verify that all components of the field have the same 974 # Sanity check. Verify that all components of the field have the same 975 975 # dimension. 976 976 set dim "" … … 989 989 # the label and units for each field will be specified there. 990 990 # 991 # FIXME: Test that every <field><component> has the same field names, 991 # FIXME: Test that every <field><component> has the same field names, 992 992 # units, components. 993 993 # … … 1061 1061 # isunirect2d -- 1062 1062 # 1063 # Returns if the field is a unirect2d object. 1063 # Returns if the field is a unirect2d object. 1064 1064 # 1065 1065 itcl::body Rappture::Field::isunirect2d { } { … … 1070 1070 # isunirect3d -- 1071 1071 # 1072 # Returns if the field is a unirect3d object. 1072 # Returns if the field is a unirect3d object. 1073 1073 # 1074 1074 itcl::body Rappture::Field::isunirect3d { } { … … 1079 1079 # flowhints -- 1080 1080 # 1081 # Returns the hints associated with a flow vector field. 1081 # Returns the hints associated with a flow vector field. 1082 1082 # 1083 1083 itcl::body Rappture::Field::flowhints { cname } { … … 1091 1091 # style -- 1092 1092 # 1093 # Returns the style associated with a component of the field. 1093 # Returns the style associated with a component of the field. 1094 1094 # 1095 1095 itcl::body Rappture::Field::style { cname } { … … 1128 1128 # extents -- 1129 1129 # 1130 # Returns if the field is a unirect2d object. 1130 # Returns if the field is a unirect2d object. 1131 1131 # 1132 1132 itcl::body Rappture::Field::extents {{cname -overall}} { … … 1144 1144 } 1145 1145 return $max 1146 } 1146 } 1147 1147 if { $cname == "component0"} { 1148 1148 set cname [lindex [components -name] 0] … … 1161 1161 set f [open "$tmpfile" "w"] 1162 1162 fconfigure $f -translation binary -encoding binary 1163 puts $f $contents 1163 puts $f $contents 1164 1164 close $f 1165 1165 … … 1195 1195 set f [open "$tmpfile" "w"] 1196 1196 fconfigure $f -translation binary -encoding binary 1197 puts $f $contents 1197 puts $f $contents 1198 1198 close $f 1199 1199 … … 1236 1236 for { set i 0 } { $i < $numPoints } { incr i } { 1237 1237 set point [$dataset GetPoint $i] 1238 $xv append [lindex $point 0] 1238 $xv append [lindex $point 0] 1239 1239 } 1240 1240 set yv [blt::vector create \#auto] … … 1253 1253 set numTuples [$array GetNumberOfTuples] 1254 1254 for { set i 0 } { $i < $numTuples } { incr i } { 1255 $yv append [$array GetComponent $i 0] 1255 $yv append [$array GetComponent $i 0] 1256 1256 } 1257 1257 $xv sort $yv 1258 1258 set _comp2xy($cname) [list $xv $yv] 1259 1259 } 1260 lappend limits x [list $xmin $xmax] 1261 lappend limits y [list $ymin $ymax] 1260 lappend limits x [list $xmin $xmax] 1261 lappend limits y [list $ymin $ymax] 1262 1262 lappend limits z [list $zmin $zmax] 1263 1263 set dataAttrs [$dataset GetPointData] … … 1287 1287 } 1288 1288 } 1289 1289 1290 1290 lappend limits v [list $vmin $vmax] 1291 1291 set _comp2limits($cname) $limits … … 1304 1304 set cname "component" 1305 1305 } 1306 # DX: Convert DX to VTK 1306 # DX: Convert DX to VTK 1307 1307 if {[info exists _comp2dx($cname)]} { 1308 1308 set data $_comp2dx($cname) … … 1310 1310 return [Rappture::DxToVtk $data] 1311 1311 } 1312 # VTK file data: 1312 # VTK file data: 1313 1313 if { [info exists _comp2vtk($cname)] } { 1314 1314 return $_comp2vtk($cname) … … 1364 1364 } 1365 1365 } 1366 append out [$vector range 0 end] 1366 append out [$vector range 0 end] 1367 1367 append out "\n" 1368 1368 if 0 { … … 1413 1413 set vectorsize [$_field get $cname.extents] 1414 1414 } else { 1415 set vectorsize 1 1415 set vectorsize 1 1416 1416 } 1417 1417 set _type unirect3d … … 1428 1428 lappend limits $axis [$_comp2unirect3d($cname) limits $axis] 1429 1429 } 1430 # Get the data limits 1430 # Get the data limits 1431 1431 set vector [$_comp2unirect3d($cname) values] 1432 1432 set minmax [VectorLimits $vector $vectorsize] … … 1446 1446 set vectorsize [$_field get $cname.extents] 1447 1447 } else { 1448 set vectorsize 1 1448 set vectorsize 1 1449 1449 } 1450 1450 set _type unirect2d … … 1482 1482 set mesh [Rappture::Mesh::fetch $_xmlobj $path] 1483 1483 set _type mesh 1484 } 1484 } 1485 1485 "unirect2d" { 1486 1486 if { $_viewer == "" } { … … 1497 1497 set _dim [$mesh dimensions] 1498 1498 if { $_dim == 3 } { 1499 set dim 0 1499 set dim 0 1500 1500 foreach axis {x y z} { 1501 1501 foreach {min max} [$mesh limits $axis] { … … 1518 1518 # Band Structure Lab used to (see isosurface1 test in rappture-bat) 1519 1519 # 1520 # Is there a natural growth path in generating output from 1D to 1520 # Is there a natural growth path in generating output from 1D to 1521 1521 # higher dimensions? If there isn't, let's kill this in favor 1522 1522 # or explicitly using a <curve> instead. Otherwise, the features 1523 # (methods such as xmarkers) or the <curve> need to be added 1523 # (methods such as xmarkers) or the <curve> need to be added 1524 1524 # to the <field>. 1525 # 1525 # 1526 1526 #set xv [blt::vector create x$_counter] 1527 1527 #set yv [blt::vector create y$_counter] … … 1535 1535 #incr _counter 1536 1536 #return 1 1537 } 1537 } 1538 1538 if {$_dim == 2} { 1539 1539 # 2D data: By default surface or contour plot using heightmap widget. … … 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. … … 1719 1719 "tcoords" 2 1720 1720 "tensors" 9 1721 "vectors" 3 1721 "vectors" 3 1722 1722 } 1723 1723 set type [$_field get $cname.elemtype] 1724 1724 if { $type == "" } { 1725 1725 set type "scalars" 1726 } 1726 } 1727 1727 if { ![info exists type2components($type)] } { 1728 1728 error "unknown <elemtype> \"$type\" in field" … … 1741 1741 set _comp2assoc($cname) "pointdata" 1742 1742 return 1743 } 1743 } 1744 1744 switch -- $assoc { 1745 1745 "pointdata" - "celldata" - "fielddata" {
Note: See TracChangeset
for help on using the changeset viewer.