Changeset 5611 for trunk/gui/scripts/unirect3d.tcl
- Timestamp:
- May 27, 2015, 2:36:55 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.