Ignore:
Timestamp:
May 31, 2015 5:06:46 PM (9 years ago)
Author:
ldelgass
Message:

Don't need to rely on nanovis to return limits any more, so cleanup some old
code. Also sync up nanovis and flowvis viewers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/flowvisviewer.tcl

    r5612 r5642  
    129129    private variable _dlist ""         ;# list of data objects
    130130    private variable _obj2ovride       ;# maps dataobj => style override
    131     private variable _serverDatasets   ;# contains all the dataobj-component
     131    private variable _datasets         ;# contains all the dataobj-component
    132132                                       ;# to volumes in the server
    133     private variable _recvdDatasets    ;# list of data objs to send to server
    134133    private variable _dataset2style    ;# maps dataobj-component to transfunc
    135134    private variable _style2datasets   ;# maps tf back to list of
     
    223222    $_arcball quaternion [ViewToQuaternion]
    224223
    225     set _limits(v) [list 0.0 1.0]
    226224    set _reset 1
    227225
     
    593591# ----------------------------------------------------------------------
    594592itcl::body Rappture::FlowvisViewer::add {dataobj {settings ""}} {
     593    if { ![$dataobj isvalid] } {
     594        return;                         # Object doesn't contain valid data.
     595    }
    595596    array set params {
    596597        -color auto
     
    698699        if { $pos >= 0 } {
    699700            set _dlist [lreplace $_dlist $pos $pos]
    700             array unset _limits $dataobj-*
    701701            array unset _obj2ovride $dataobj-*
    702             array unset _dataset2flow $dataobj-*
    703             array unset _serverDatasets $dataobj-*
    704             array unset _dataset2style $dataobj-*
    705702            set changed 1
    706703        }
     
    708705    # If anything changed, then rebuild the plot
    709706    if {$changed} {
    710         # Repair the reverse lookup
    711         foreach tf [array names _style2datasets] {
    712             set list {}
    713             foreach {dataobj cname} $_style2datasets($tf) break
    714             if { [info exists _serverDatasets($dataobj-$cname)] } {
    715                 lappend list $dataobj $cname
    716             }
    717             if { $list == "" } {
    718                 array unset _style2datasets $tf
    719             } else {
    720                 set _style2datasets($tf) $list
    721             }
    722         }
    723707        $_dispatcher event -idle !rebuild
    724708    }
     
    758742            set _limits($cname) $limits(v)
    759743        }
    760         foreach axis {x y z v} {
     744        foreach axis {x y z} {
    761745            foreach { min max } [$dataobj limits $axis] break
    762746            if {"" != $min && "" != $max} {
     
    834818                }
    835819                default {
    836                     error "bad download format $_downloadPopup(format)"
     820                    error "bad download format \"$_downloadPopup(format)\""
    837821                }
    838822            }
     
    917901
    918902    # disconnected -- no more data sitting on server
    919     array unset _serverDatasets
     903    array unset _datasets
    920904}
    921905
     
    967951    array set info $args
    968952    set bytes [ReceiveBytes $info(-bytes)]
    969     ReceiveEcho <<line "<read $info(-bytes) bytes"
    970     switch -- $info(-type)  {
     953    switch -- $info(-type) {
    971954        "image" {
     955            #puts stderr "received image [image width $_image(plot)]x[image height $_image(plot)]"
    972956            $_image(plot) configure -data $bytes
    973             #puts stderr "image received [image width $_image(plot)] by [image height $_image(plot)]"
    974957        }
    975958        "print" {
     
    982965        }
    983966        default {
    984             puts stderr "unknown download type $info(-type)"
     967            puts stderr "unknown image type $info(-type)"
    985968        }
    986969    }
     
    10581041#       The procedure is the response from the render server to each "data
    10591042#       follows" command.  The server sends back a "data" command invoked our
    1060 #       the slave interpreter.  The purpose is to collect the min/max of the
    1061 #       volume sent to the render server.  Since the client (flowvisviewer)
    1062 #       doesn't parse 3D data formats, we rely on the server (nanovis) to
    1063 #       tell us what the limits are.  Once we've received the limits to all
    1064 #       the data we've sent (tracked by _recvdDatasets) we can then determine
    1065 #       what the transfer functions are for these volumes.
    1066 #
    1067 #
    1068 #       Note: There is a considerable tradeoff in having the server report
    1069 #             back what the data limits are.  It means that much of the code
    1070 #             having to do with transfer-functions has to wait for the data
    1071 #             to come back, since the isomarkers are calculated based upon
    1072 #             the data limits.  The client code is much messier because of
    1073 #             this.  The alternative is to parse any of the 3D formats on the
    1074 #             client side.
     1043#       the slave interpreter.  The purpose was to collect the min/max of the
     1044#       volume sent to the render server.  This is no longer needed since we
     1045#       already know the limits.
    10751046#
    10761047itcl::body Rappture::FlowvisViewer::ReceiveData { args } {
     
    10831054
    10841055    set tag $info(tag)
    1085     set parts [split $tag -]
    1086 
    1087     #
    1088     # Volumes don't exist until we're told about them.
    1089     #
    1090     set dataobj [lindex $parts 0]
    1091     set _serverDatasets($tag) 0
    10921056    set _limits($tag) [list $info(min) $info(max)]
    1093 
    1094     unset _recvdDatasets($tag)
    1095     if { [array size _recvdDatasets] == 0 } {
    1096         updateTransferFunctions
    1097     }
    10981057}
    10991058
     
    11361095
    11371096    set _first ""
    1138     foreach dataobj [get] {
     1097    foreach dataobj [get -objects] {
     1098        if { [info exists _obj2ovride($dataobj-raise)] &&  $_first == "" } {
     1099            set _first $dataobj
     1100        }
    11391101        foreach cname [$dataobj components] {
    11401102            set tag $dataobj-$cname
    1141             if {[$dataobj type] == "dx"} {
    1142                 set data [$dataobj blob $cname]
    1143             } else {
    1144                 set data [$dataobj vtkdata $cname]
    1145             }
    1146             set nbytes [string length $data]
    1147             if { $_reportClientInfo }  {
    1148                 set info {}
    1149                 lappend info "tool_id"       [$dataobj hints toolid]
    1150                 lappend info "tool_name"     [$dataobj hints toolname]
    1151                 lappend info "tool_title"    [$dataobj hints tooltitle]
    1152                 lappend info "tool_command"  [$dataobj hints toolcommand]
    1153                 lappend info "tool_revision" [$dataobj hints toolrevision]
    1154                 lappend info "dataset_label" [$dataobj hints label]
    1155                 lappend info "dataset_size"  $nbytes
    1156                 lappend info "dataset_tag"   $tag
    1157                 SendCmd "clientinfo [list $info]"
    1158             }
    1159             set numComponents [$dataobj numComponents $cname]
    1160             # I have a field. Is a vector field or a volume field?
    1161             if { $numComponents == 1 } {
    1162                 SendCmd "volume data follows $nbytes $tag"
    1163             } else {
    1164                 if {[SendFlowCmd $dataobj $cname $nbytes $numComponents] < 0} {
    1165                     continue
     1103            if { ![info exists _datasets($tag)] } {
     1104                if { [$dataobj type] == "dx" } {
     1105                    set data [$dataobj blob $cname]
     1106                } else {
     1107                    set data [$dataobj vtkdata $cname]
    11661108                }
    1167             }
    1168             SendData $data
    1169             NameTransferFunction $dataobj $cname
    1170             set _recvdDatasets($tag) 1
    1171         }
    1172     }
    1173 
    1174     set _first [lindex [get] 0]
     1109                set nbytes [string length $data]
     1110                if { $_reportClientInfo }  {
     1111                    set info {}
     1112                    lappend info "tool_id"       [$dataobj hints toolid]
     1113                    lappend info "tool_name"     [$dataobj hints toolname]
     1114                    lappend info "tool_title"    [$dataobj hints tooltitle]
     1115                    lappend info "tool_command"  [$dataobj hints toolcommand]
     1116                    lappend info "tool_revision" [$dataobj hints toolrevision]
     1117                    lappend info "dataset_label" [$dataobj hints label]
     1118                    lappend info "dataset_size"  $nbytes
     1119                    lappend info "dataset_tag"   $tag
     1120                    SendCmd "clientinfo [list $info]"
     1121                }
     1122                set numComponents [$dataobj numComponents $cname]
     1123                # I have a field. Is a vector field or a volume field?
     1124                if { $numComponents == 1 } {
     1125                    SendCmd "volume data follows $nbytes $tag"
     1126                } else {
     1127                    if {[SendFlowCmd $dataobj $cname $nbytes $numComponents] < 0} {
     1128                        continue
     1129                    }
     1130                }
     1131                SendData $data
     1132                set _datasets($tag) 1
     1133                NameTransferFunction $dataobj $cname
     1134            }
     1135        }
     1136    }
    11751137
    11761138    # Turn off cutplanes for all volumes
     
    11791141    }
    11801142
    1181     # Reset the camera and other view parameters
    1182     InitSettings -axesvisible -gridvisible \
    1183         -opacity -light2side -isosurfaceshading \
    1184         -ambient -diffuse -specularlevel -specularexponent \
    1185         -volume -outlinevisible -cutplanesvisible \
     1143    InitSettings -volume -outlinevisible -cutplanesvisible \
    11861144        -xcutplanevisible -ycutplanevisible -zcutplanevisible \
    11871145        -xcutplaneposition -ycutplaneposition -zcutplaneposition
    11881146
    1189     # nothing to send -- activate the proper volume
     1147    if { $_reset } {
     1148        InitSettings -axesvisible -gridvisible \
     1149            -opacity -light2side -isosurfaceshading \
     1150            -ambient -diffuse -specularlevel -specularexponent
     1151
     1152        #
     1153        # Reset the camera and other view parameters
     1154        #
     1155        if {"" != $_first} {
     1156            set axis [$_first hints updir]
     1157            if { "" != $axis } {
     1158                SendCmd "up $axis"
     1159            }
     1160            set location [$_first hints camera]
     1161            if { $location != "" } {
     1162                array set _view $location
     1163            }
     1164        }
     1165        set _settings(-qw)    $_view(-qw)
     1166        set _settings(-qx)    $_view(-qx)
     1167        set _settings(-qy)    $_view(-qy)
     1168        set _settings(-qz)    $_view(-qz)
     1169        set _settings(-xpan)  $_view(-xpan)
     1170        set _settings(-ypan)  $_view(-ypan)
     1171        set _settings(-zoom)  $_view(-zoom)
     1172
     1173        set q [ViewToQuaternion]
     1174        $_arcball quaternion $q
     1175        SendCmd "camera orient $q"
     1176        SendCmd "camera reset"
     1177        PanCamera
     1178        SendCmd "camera zoom $_view(-zoom)"
     1179    }
     1180
    11901181    if {"" != $_first} {
    1191         set axis [$_first hints updir]
    1192         if {"" != $axis} {
    1193             SendCmd "up $axis"
    1194         }
    1195         set location [$_first hints camera]
    1196         if { $location != "" } {
    1197             array set _view $location
    1198         }
    1199     }
    1200     set _settings(-qw)    $_view(-qw)
    1201     set _settings(-qx)    $_view(-qx)
    1202     set _settings(-qy)    $_view(-qy)
    1203     set _settings(-qz)    $_view(-qz)
    1204     set _settings(-xpan)  $_view(-xpan)
    1205     set _settings(-ypan)  $_view(-ypan)
    1206     set _settings(-zoom)  $_view(-zoom)
    1207 
    1208     set q [ViewToQuaternion]
    1209     $_arcball quaternion $q
    1210     SendCmd "camera orient $q"
    1211     SendCmd "camera reset"
    1212     PanCamera
    1213     SendCmd "camera zoom $_view(-zoom)"
    1214 
    1215     foreach dataobj [get] {
    1216         foreach cname [$dataobj components] {
    1217             NameTransferFunction $dataobj $cname
    1218         }
    1219     }
    1220 
    1221     # nothing to send -- activate the proper ivol
    1222     set _first [lindex [get] 0]
    1223     if {"" != $_first} {
    1224         set axis [$_first hints updir]
    1225         if {"" != $axis} {
    1226             SendCmd "up $axis"
    1227         }
    1228         set location [$_first hints camera]
    1229         if { $location != "" } {
    1230             array set _view $location
    1231         }
    12321182        set cname [lindex [$_first components] 0]
    12331183        set _activeTf [lindex $_dataset2style($_first-$cname) 0]
    1234     }
    1235 
    1236     # sync the state of slicers
    1237     set vols [CurrentDatasets -cutplanes]
    1238     foreach axis {x y z} {
    1239         set pos [expr {0.01*$_settings(-${axis}cutplaneposition)}]
    1240         SendCmd "cutplane position $pos $axis $vols"
    1241     }
    1242     SendCmd "volume data state $_settings(-volume)"
    1243     EventuallyRedrawLegend
     1184        # Make sure we display the proper transfer function in the legend.
     1185        updateTransferFunctions
     1186    }
    12441187
    12451188    # Actually write the commands to the server socket.  If it fails, we don't
     
    12591202# ----------------------------------------------------------------------
    12601203itcl::body Rappture::FlowvisViewer::CurrentDatasets {{what -all}} {
    1261     return ""
     1204    set rlist ""
    12621205    if { $_first == "" } {
    12631206        return
    12641207    }
    1265     foreach tag [array names _serverDatasets *-*] {
    1266         if {[string match $_first-* $tag]} {
     1208    foreach cname [$_first components] {
     1209        set tag $_first-$cname
     1210        if { [info exists _datasets($tag)] && $_datasets($tag) } {
    12671211            array set style {
    12681212                -cutplanes 1
    12691213            }
    1270             foreach {dataobj cname} [split $tag -] break
    1271             array set style [lindex [$dataobj components -style $cname] 0]
    1272             if {$what != "-cutplanes" || $style(-cutplanes)} {
    1273                 lappend rlist $_serverDatasets($tag)
     1214            array set style [lindex [$_first components -style $cname] 0]
     1215            if { $what != "-cutplanes" || $style(-cutplanes) } {
     1216                lappend rlist $tag
    12741217            }
    12751218        }
     
    19431886
    19441887itcl::body Rappture::FlowvisViewer::limits { cname } {
    1945     set _limits(v) [list 0.0 1.0]
    1946     if { ![info exists _style2datasets($cname)] } {
    1947         puts stderr "no _style2datasets for cname=($cname)"
    1948         return [array get _limits]
    1949     }
    1950     set min ""; set max ""
    1951     foreach tag [GetDatasetsWithComponent $cname] {
    1952         if { ![info exists _serverDatasets($tag)] } {
    1953             puts stderr "$tag not in _serverDatasets?"
    1954             continue
    1955         }
    1956         if { ![info exists _limits($tag)] } {
    1957             puts stderr "$tag no min?"
    1958             continue
    1959         }
    1960         foreach {vmin vmax} $_limits($tag) break
    1961         if { $min == "" || $min > $vmin } {
    1962             set min $vmin
    1963         }
    1964         if { $max == "" || $max < $vmax } {
    1965             set max $vmax
    1966         }
    1967     }
    1968     if { $min != "" && $max != "" } {
    1969         set _limits(v) [list $min $max]
    1970         set _limits($cname) [list $min $max]
     1888    if { ![info exists _limits($cname)] } {
     1889        puts stderr "no limits for cname=($cname)"
     1890        return [list 0.0 1.0]
    19711891    }
    19721892    return $_limits($cname)
     
    30222942    set list ""
    30232943    foreach tag $_volcomponents($cname) {
    3024         if { ![info exists _serverDatasets($tag)] } {
     2944        if { ![info exists _datasets($tag)] } {
    30252945            continue
    30262946        }
Note: See TracChangeset for help on using the changeset viewer.