Changeset 2722 for trunk


Ignore:
Timestamp:
Dec 8, 2011, 2:34:01 PM (13 years ago)
Author:
gah
Message:

vtkvolume additional viewer for dx files

Location:
trunk/gui
Files:
6 edited

Legend:

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

    r2721 r2722  
    5151    private variable _comp2vtk   ;# maps component name => vtkFloatArray
    5252    private variable _comp2vtkstreamlines   ;# maps component name => vtkFloatArray
     53    private variable _comp2vtkvolume   ;# maps component name => vtkFloatArray
    5354    private variable _comp2volume   ;# maps component name => vtkFloatArray
    5455    private variable _comp2dx    ;# maps component name => OpenDX data
     
    605606            }
    606607        } elseif {[$_field element $cname.opendx] != ""} {
    607             set type "dx"
     608            global env
     609            if { [info exists env(VTKVOLUME)] } {
     610                set type "vtkvolume"
     611            } else {
     612                set type "dx"
     613            }
    608614        } elseif {[$_field element $cname.dx] != ""} {
    609             set type "dx"
     615            global env
     616            if { [info exists env(VTKVOLUME)] } {
     617                set type "vtkvolume"
     618            } else {
     619                set type "dx"
     620            }
    610621        }
    611622        set _comp2style($cname) ""
     
    798809            set _comp2style($cname) [$_field get $cname.style]
    799810            incr _counter
     811        } elseif {$type == "vtkvolume"} {
     812            set _comp2dims($cname) "3D"
     813            # Allow redirects to another element.
     814            set data [$_field get -decode no $cname.dx]
     815            set data [Rappture::encoding::decode -as zb64 $data]
     816            if 1 {
     817            set file "/tmp/junk.dx"
     818            set f [open $file "w"]
     819            puts $f $data
     820            close $f
     821            }
     822            set data [Rappture::ConvertDxToVtk $data]
     823            set _comp2vtkvolume($cname) $data
     824            set _comp2style($cname) [$_field get $cname.style]
     825            incr _counter
    800826        } elseif {$type == "vtkstreamlines2"} {
    801827            set _comp2dims($cname) "3D"
     
    803829            set _comp2style($cname) [$_field get $cname.style]
    804830            incr _counter
    805         } elseif {$type == "dx"} {
     831        } elseif {$type == "dx" } {
    806832            #
    807833            # HACK ALERT!  Extract gzipped, base64-encoded OpenDX
     
    9941020    }
    9951021    if {[info exists _comp2dx($what)]} {
    996         set data $_comp2dx($what)
    997         if { $data == "" } {
    998             return ""
    999         }
    1000         set data  [$_field get -decode yes $data]
    1001         set data [Rappture::ConvertDxToVtk $data]
    1002         return $data
     1022        return $_comp2dx($what)
    10031023    }
    10041024    if {[info exists _comp2unirect2d($what)]} {
  • trunk/gui/scripts/field3dresult.tcl

    r2504 r2722  
    5959            set servers [Rappture::VisViewer::GetServerList "nanovis"]
    6060        }
    61         "vtkcontour" - "vtkstreamlines" {
     61        "vtkcontour" - "vtkstreamlines" - "vtkvolume" - "vtkviewer"  {
    6262            set servers [Rappture::VisViewer::GetServerList "vtkvis"]
    6363        }
     
    8080                itk_component add renderer {
    8181                    Rappture::FlowvisViewer $itk_interior.ren $servers
     82                }
     83            }
     84            "vtkvolume" {
     85                itk_component add renderer {
     86                    Rappture::VtkVolumeViewer $itk_interior.ren $servers
    8287                }
    8388            }
  • trunk/gui/scripts/resultviewer.tcl

    r2565 r2722  
    206206# ----------------------------------------------------------------------
    207207itcl::body Rappture::ResultViewer::_plotAdd {dataobj {settings ""}} {
     208    puts stderr "ResultViewer _plotAdd info class [$dataobj info class]"
    208209    switch -- [$dataobj info class] {
    209210        ::Rappture::DataTable {
     
    252253        ::Rappture::Field {
    253254            set dims [lindex [lsort [$dataobj components -dimensions]] end]
     255            puts stderr "ResultViewer in Field dims=$dims"
    254256            switch -- $dims {
    255257                1D {
     
    287289                    set mode "field3D"
    288290                    if {![info exists _mode2widget($mode)]} {
     291                        puts stderr "type=$type"
    289292                        switch -- [$dataobj type] {
    290293                            "vtk" {
     
    298301                                }
    299302                            }
     303                            "vtkvolume" {
     304                                set fmt "vtkvolume"
     305                            }
    300306                            "vtkstreamlines" {
    301307                                set fmt "vtkstreamlines"
  • trunk/gui/scripts/sequenceresult.tcl

    r2268 r2722  
    482482                    }
    483483                    3D {
    484                         Rappture::Field3DResult $viewer
     484                        set fmt [$dataobj type]
     485                        switch -- $fmt {
     486                            "opendx" - "dx" - "points-on-mesh" {
     487                                set fmt "nanovis"
     488                                set extents [$dataobj extents]
     489                                if { $extents > 1 } {
     490                                    set fmt "flowvis"
     491                                }
     492                            }
     493                        }
     494                        Rappture::Field3DResult $viewer -mode $fmt
    485495                    }
    486496                    default {
  • trunk/gui/scripts/vtkvolumeviewer.tcl

    r2718 r2722  
    260260        cutplane-wireframe      0
    261261        cutplane-opacity        100
    262         volume-edges            0
    263262        volume-lighting         1
    264263        volume-opacity          40
     
    10901089
    10911090    if { $_reset } {
    1092         InitSettings volume-edges volume-lighting volume-opacity \
    1093             volume-wireframe
     1091        InitSettings volume-lighting
    10941092        Zoom reset
    10951093        set _reset 0
     
    13381336    }
    13391337    switch -- $what {
    1340         "volume-opacity" {
    1341             set val $_settings(volume-opacity)
    1342             set sval [expr { 0.01 * double($val) }]
    1343             foreach dataset [CurrentDatasets -visible] {
    1344                 SendCmd "polydata opacity $sval $dataset"
    1345             }
    1346         }
    1347         "volume-wireframe" {
    1348             set bool $_settings(volume-wireframe)
    1349             foreach dataset [CurrentDatasets -visible] {
    1350                 SendCmd "polydata wireframe $bool $dataset"
    1351             }
    1352         }
    13531338        "volume-visible" {
    13541339            set bool $_settings(volume-visible)
    13551340            foreach dataset [CurrentDatasets -visible] {
    1356                 SendCmd "polydata visible $bool $dataset"
     1341                SendCmd "volume visible $bool $dataset"
    13571342            }
    13581343            if { $bool } {
     
    13671352            set bool $_settings(volume-lighting)
    13681353            foreach dataset [CurrentDatasets -visible] {
    1369                 SendCmd "polydata lighting $bool $dataset"
    1370             }
    1371         }
    1372         "volume-edges" {
    1373             set bool $_settings(volume-edges)
    1374             foreach dataset [CurrentDatasets -visible] {
    1375                 SendCmd "polydata edges $bool $dataset"
     1354                SendCmd "volume lighting $bool $dataset"
    13761355            }
    13771356        }
     
    15781557
    15791558itcl::body Rappture::VtkVolumeViewer::ColorsToColormap { colors } {
     1559puts stderr colors=$colors
    15801560    switch -- $colors {
    15811561        "grey-to-blue" {
     
    19101890        -font "Arial 9"
    19111891
    1912     checkbutton $inner.wireframe \
    1913         -text "Show Wireframe" \
    1914         -variable [itcl::scope _settings(volume-wireframe)] \
    1915         -command [itcl::code $this AdjustSetting volume-wireframe] \
    1916         -font "Arial 9"
    1917 
    19181892    checkbutton $inner.lighting \
    19191893        -text "Enable Lighting" \
    19201894        -variable [itcl::scope _settings(volume-lighting)] \
    19211895        -command [itcl::code $this AdjustSetting volume-lighting] \
    1922         -font "Arial 9"
    1923 
    1924     checkbutton $inner.edges \
    1925         -text "Show Edges" \
    1926         -variable [itcl::scope _settings(volume-edges)] \
    1927         -command [itcl::code $this AdjustSetting volume-edges] \
    19281896        -font "Arial 9"
    19291897
     
    19701938    blt::table $inner \
    19711939        0,0 $inner.volume    -anchor w -pady 2 \
    1972         1,0 $inner.wireframe -anchor w -pady 2 \
    19731940        2,0 $inner.lighting  -anchor w -pady 2 \
    1974         3,0 $inner.edges     -anchor w -pady 2 \
    1975         4,0 $inner.opacity_l -anchor w -pady 2 \
    1976         5,0 $inner.opacity   -fill x   -pady 2 \
    19771941        6,0 $inner.field_l     -anchor w -pady 2  \
    19781942        6,1 $inner.field       -anchor w -pady 2  \
     
    23822346    }
    23832347
    2384     SendCmd "polydata add $tag"
    2385     SendCmd "polydata edges $settings(-edges) $tag"
    2386     set _settings(volume-edges) $settings(-edges)
    2387     SendCmd "polydata color [Color2RGB $settings(-color)] $tag"
    2388     SendCmd "polydata lighting $settings(-lighting) $tag"
     2348    SendCmd "volume lighting $settings(-lighting) $tag"
    23892349    set _settings(volume-lighting) $settings(-lighting)
    2390     SendCmd "polydata linecolor [Color2RGB $settings(-edgecolor)] $tag"
    2391     SendCmd "polydata linewidth $settings(-linewidth) $tag"
    2392     SendCmd "polydata opacity $settings(-opacity) $tag"
    2393     set _settings(volume-opacity) $settings(-opacity)
    2394     SendCmd "polydata wireframe $settings(-wireframe) $tag"
    2395     set _settings(volume-wireframe) $settings(-wireframe)
    2396     set _settings(volume-opacity) [expr $settings(-opacity) * 100.0]
    23972350    SetColormap $dataobj $comp
    23982351}
  • trunk/gui/src/RpConvertDxToVtk.c

    r2721 r2722  
    4545}
    4646
     47static int
     48GetPoints(Tcl_Interp *interp, int nPoints, char **stringPtr,
     49          const char *endPtr, Tcl_Obj *objPtr)
     50{
     51    int nValues;
     52    int i;
     53    const char *p;
     54    char mesg[2000];
     55
     56    nValues = 0;
     57    p = *stringPtr;
     58    for (i = 0; i < nPoints; i++) {
     59        double value;
     60        char *nextPtr;
     61               
     62        if (p >= endPtr) {
     63            Tcl_AppendResult(interp, "unexpected EOF in reading points",
     64                             (char *)NULL);
     65            return TCL_ERROR;
     66        }
     67        value = strtod(p, &nextPtr);
     68        if (nextPtr == p) {
     69            Tcl_AppendResult(interp, "bad value found in reading points",
     70                             (char *)NULL);
     71            return TCL_ERROR;
     72        }
     73        p = nextPtr;
     74        sprintf(mesg, "%.15g\n", value);
     75        Tcl_AppendToObj(objPtr, mesg, -1);
     76    }
     77    *stringPtr = p;
     78    return TCL_OK;
     79}
     80
    4781/*
    4882 *  ConvertDxToVtk string
     
    5387                  Tcl_Obj *const *objv)
    5488{
    55     Tcl_Obj *objPtr;
     89    Tcl_Obj *objPtr, *pointsObjPtr;
    5690    char *p, *pend;
    5791    char *string;
     
    5993    double delta[3];
    6094    double origin[3];
    61     double xMax, yMax, zMax, xMin, yMin, zMin;
    62     double maxValue[3], minValue[3];
    6395    int count[3];
    6496    int length, nComponents, nValues, nPoints;
    65     int xNum, yNum, zNum;
    66     size_t ix;
    6797
    6898    nComponents = nPoints = 0;
     
    77107    }
    78108    string = Tcl_GetStringFromObj(objv[1], &length);
     109    pointsObjPtr = Tcl_NewStringObj("", -1);
    79110    for (p = string, pend = p + length; p < pend; /*empty*/) {
    80111        char *line;
     
    82113
    83114        line = GetLine(&p, pend);
    84         if (line == pend) {
     115        if (line >= pend) {
    85116            break;                      /* EOF */
    86117        }
     
    96127                return TCL_ERROR;
    97128            }
     129#ifdef notdef
     130            fprintf(stderr, "found gridpositions counts %d %d %d\n",
     131                    count[0], count[1], count[2]);
     132#endif
    98133        } else if (sscanf(line, "origin %lg %lg %lg", origin, origin + 1,
    99134                origin + 2) == 3) {
    100135            /* Found origin. */
     136#ifdef notdef
     137            fprintf(stderr, "found origin %g %g %g\n",
     138                    origin[0], origin[1], origin[2]);
     139#endif
    101140        } else if (sscanf(line, "delta %lg %lg %lg", &ddx, &ddy, &ddz) == 3) {
    102141            if (nComponents == 3) {
     
    107146            delta[nComponents] = sqrt((ddx * ddx) + (ddy * ddy) + (ddz * ddz));
    108147            nComponents++;
     148#ifdef notdef
     149            fprintf(stderr, "found delta %g %g %g\n", ddx, ddy, ddx);
     150#endif
    109151        } else if (sscanf(line, "object %*d class array type %*s shape 3"
    110152                " rank 1 items %d data follows", &nPoints) == 1) {
     153            fprintf(stderr, "found class array type shape 3 nPoints=%d\n",
     154                    nPoints);
    111155            if (nPoints < 0) {
    112156                sprintf(mesg, "bad # points %d", nPoints);
     
    114158                return TCL_ERROR;
    115159            }   
    116             printf("#points=%d\n", nPoints);
    117160            if (nPoints != count[0]*count[1]*count[2]) {
    118161                sprintf(mesg, "inconsistent data: expected %d points"
     
    122165                return TCL_ERROR;
    123166            }
    124             break;
     167            if (GetPoints(interp, nPoints, &p, pend, pointsObjPtr) != TCL_OK) {
     168                return TCL_ERROR;
     169            }
    125170        } else if (sscanf(line, "object %*d class array type %*s rank 0"
    126                 " times %d data follows", &nPoints) == 1) {
     171                " items %d data follows", &nPoints) == 1) {
     172#ifdef notdef
     173            fprintf(stderr, "found class array type rank 0 nPoints=%d\n",
     174                nPoints);
     175#endif
    127176            if (nPoints != count[0]*count[1]*count[2]) {
    128177                sprintf(mesg, "inconsistent data: expected %d points"
     
    132181                return TCL_ERROR;
    133182            }
    134             break;
     183            if (GetPoints(interp, nPoints, &p, pend, pointsObjPtr) != TCL_OK) {
     184                return TCL_ERROR;
     185            }
     186#ifdef notdef
     187        } else {
     188            fprintf(stderr, "unknown line (%.80s)\n", line);
     189#endif
    135190        }
    136191    }
     
    155210    sprintf(mesg, "POINT_DATA %d\n", nPoints);
    156211    Tcl_AppendToObj(objPtr, mesg, -1);
    157 
    158     minValue[0] = minValue[1] = minValue[2] = DBL_MAX;
    159     maxValue[0] = maxValue[1] = maxValue[2] = -DBL_MAX;
    160     xMin = origin[0], yMin = origin[1], zMin = origin[2];
    161     xNum = count[0], yNum = count[1], zNum = count[2];
    162     xMax = origin[0] + delta[0] * count[0];
    163     yMax = origin[1] + delta[1] * count[1];
    164     zMax = origin[2] + delta[2] * count[2];
    165     nValues = 0;
    166     for (ix = 0; ix < xNum; ix++) {
    167         size_t iy;
    168 
    169         for (iy = 0; iy < yNum; iy++) {
    170             size_t iz;
    171 
    172             for (iz = 0; iz < zNum; iz++) {
    173                 const char *line;
    174                 double vx, vy, vz;
    175 
    176                 if ((p == pend) || (nValues > (size_t)nPoints)) {
    177                     break;
    178                 }
    179                 line = GetLine(&p, pend);
    180                 if ((line[0] == '#') || (line[0] == '\n')) {
    181                     continue;           /* Skip blank or comment lines. */
    182                 }
    183                 if (sscanf(line, "%lg %lg %lg", &vx, &vy, &vz) == 3) {
    184                     if (vx < minValue[0]) {
    185                         minValue[0] = vx;
    186                     } else if (vx > maxValue[0]) {
    187                         maxValue[0] = vx;
    188                     }
    189                     if (vy < minValue[1]) {
    190                         minValue[1] = vy;
    191                     } else if (vy > maxValue[1]) {
    192                         maxValue[1] = vy;
    193                     }
    194                     if (vz < minValue[2]) {
    195                         minValue[2] = vz;
    196                     } else if (vz > maxValue[2]) {
    197                         maxValue[2] = vz;
    198                     }
    199                     sprintf(mesg, "%g %g %g\n", vx, vy, vz);
    200                     Tcl_AppendToObj(objPtr, mesg, -1);
    201                     nValues++;
    202                 }
    203             }
    204         }
    205     }
    206     /* Make sure that we read all of the expected points. */
    207     if (nValues != (size_t)nPoints) {
    208         sprintf(mesg, "inconsistent data: expected %d points"
    209                         " but found %d points", nPoints, nValues);
    210         Tcl_AppendResult(interp, mesg, (char *)NULL);
    211         Tcl_DecrRefCount(objPtr);
    212         return TCL_ERROR;
    213     }
     212    Tcl_AppendObjToObj(objPtr, pointsObjPtr);
     213    Tcl_DecrRefCount(pointsObjPtr);
    214214    Tcl_SetObjResult(interp, objPtr);
    215215    return TCL_OK;
Note: See TracChangeset for help on using the changeset viewer.