Changeset 1429 for trunk


Ignore:
Timestamp:
May 11, 2009 4:39:13 PM (15 years ago)
Author:
gah
Message:

Initial commit of new flow visualization command structure

Location:
trunk/packages/vizservers/nanovis
Files:
2 added
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/nanovis/Command.cpp

    r1382 r1429  
    141141static Tcl_ObjCmdProc CameraCmd;
    142142static Tcl_ObjCmdProc CutplaneCmd;
    143 static Tcl_ObjCmdProc FlowCmd;
     143extern Tcl_AppInitProc FlowCmdInitProc;
    144144static Tcl_ObjCmdProc GridCmd;
    145145static Tcl_ObjCmdProc LegendCmd;
     
    17251725// ========================= VOLUME END ==================================
    17261726
     1727#ifdef notdef
    17271728// ============================= FLOW ==================================
    17281729
     
    19571958        return TCL_ERROR;
    19581959    }
    1959     NanoVis::lic_on = state;
     1960    /* NanoVis::lic_on = state; */
    19601961    return TCL_OK;
    19611962}
     
    19731974        return TCL_ERROR;
    19741975    }
     1976#ifdef notdef
    19751977    switch (axis) {
    19761978    case 0 :
     
    19841986        break;
    19851987    }
     1988#endif
    19861989    return TCL_OK;
    19871990}
     
    20532056    }
    20542057
    2055     NanoVis::particle_on = state;
     2058    /* NanoVis::particle_on = state; */
    20562059    return TCL_OK;
    20572060}
     
    21992202
    22002203// ============================ FLOW END ==================================
     2204#endif
    22012205
    22022206static int
     
    28322836    Tcl_Interp *interp;
    28332837    interp = Tcl_CreateInterp();
     2838    /*
    28342839    Tcl_MakeSafe(interp);
    2835 
     2840    */
    28362841    Tcl_CreateObjCommand(interp, "axis",        AxisCmd,        NULL, NULL);
    28372842    Tcl_CreateObjCommand(interp, "camera",      CameraCmd,      NULL, NULL);
    28382843    Tcl_CreateObjCommand(interp, "cutplane",    CutplaneCmd,    NULL, NULL);
    2839     Tcl_CreateObjCommand(interp, "flow",        FlowCmd,        NULL, NULL);
     2844    if (FlowCmdInitProc(interp) != TCL_OK) {
     2845        return NULL;
     2846    }
    28402847    Tcl_CreateObjCommand(interp, "grid",        GridCmd,        NULL, NULL);
    28412848    Tcl_CreateObjCommand(interp, "heightmap",   HeightMapCmd,   NULL, NULL);
  • trunk/packages/vizservers/nanovis/FlowCmds.cpp

    r1380 r1429  
    4242#include <assert.h>
    4343#include <stdlib.h>
    44 #include <tcl.h>
     44#include <stddef.h>
     45/*#include <tcl.h>*/
     46#include "Vector4.h"
    4547#include "Switch.h"
     48#include "Unirect.h"
     49#include "FlowCmd.h"
     50
    4651#include <RpField1D.h>
    4752#include <RpFieldRect3D.h>
     
    7075#include "RenderContext.h"
    7176#include "NvLIC.h"
    72 #include "Unirect.h"
    73 #include "FlowCmd.h"
    7477
    7578static Tcl_HashTable flowTable;
    7679
    77 static int
    78 GetFlowFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, FlowCmd **flowPtrPtr)
    79 {
    80     Tcl_HashEntry *hPtr;
    81     hPtr = Tcl_FindHashEntry(&flowTable, Tcl_GetString(objPtr));
    82     if (hPtr == NULL) {
    83         if (interp != NULL) {
    84             Tcl_AppendResult(interp, "can't find a flow \"",
    85                              Tcl_GetString(objPtr), "\"", (char *)NULL);
    86         }
    87         return TCL_ERROR;
    88     }
    89     *flowPtrPtr = (FlowCmd *)Tcl_GetHashValue(hPtr);
    90     return TCL_OK;
    91 }
     80extern bool load_vector_stream2(Rappture::Outcome &result, int index,
     81        size_t length, Rappture::Unirect3d *dataPtr);
     82
     83/*
     84    physicalMin.set(dataPtr->xMin(), dataPtr->yMin(), dataPtr->zMin());
     85    physicalMax.set(dataPtr->xMax(), dataPtr->yMax(), dataPtr->zMax());
     86*/
     87static float *
     88MakeFlowVector(Rappture::Unirect3d *dataPtr, double minMag, double maxMag)
     89{
     90    float *data = new float[4* dataPtr->nValues()];
     91    if (data == NULL) {
     92        return NULLL;
     93    }
     94    memset(data, 0, sizeof(float) * 4 * dataPtr->nValues());
     95    float *destPtr = data;
     96    float *srcPtr = dataPtr->values();
     97    for (size_t iz=0; iz < dataPtr->zNum(); iz++) {
     98        for (size_t iy=0; iy < dataPtr->yNum(); iy++) {
     99            for (size_t ix=0; ix < dataPtr->xNum(); ix++) {
     100                double vx, vy, vz, vm;
     101                vx = values[0];
     102                vy = values[1];
     103                vz = values[2];
     104                vm = sqrt(vx*vx + vy*vy + vz*vz);
     105                destPtr[0] = vm / maxMag;
     106                destPtr[1] = vx /(2.0*maxMag) + 0.5;
     107                destPtr[2] = vy /(2.0*maxMag) + 0.5;
     108                destPtr[3] = vz /(2.0*maxMag) + 0.5;
     109                srcPtr += 3;
     110                destPtr += 4;
     111            }
     112        }
     113    }
     114    return data;
     115}
     116
     117static Volume *
     118MakeFlowVolume(Rappture::Unirect3d *dataPtr, double minMag, double maxMag,
     119               float *data)
     120{
     121    Volume *volPtr;
     122
     123    ivol = NanoVis::n_volumes;
     124    volPtr = NanoVis::load_volume(ivol, dataPtr->xNum(), dataPtr->yNum(),
     125        dataPtr->zNum(), 4, data, minMag, maxMag, 0);
     126    volPtr->xAxis.SetRange(dataPtr->xMin(), dataPtr->xMax());
     127    volPtr->yAxis.SetRange(dataPtr->yMin(), dataPtr->yMax());
     128    volPtr->zAxis.SetRange(dataPtr->zMin(), dataPtr->zMax());
     129    volPtr->wAxis.SetRange(minMag, maxMag);
     130    volPtr->update_pending = true;
     131    volPtr->setPhysicalBBox(physicalMin, physicalMax);
     132    //
     133    // BE CAREFUL:  Set the number of slices to something
     134    //   slightly different for each volume.  If we have
     135    //   identical volumes at exactly the same position
     136    //   with exactly the same number of slices, the second
     137    //   volume will overwrite the first, so the first won't
     138    //   appear at all.
     139    //
     140    volPtr->set_n_slice(256-n);
     141    // volPtr->set_n_slice(512-n);
     142    volPtr->disable_cutplane(0);
     143    volPtr->disable_cutplane(1);
     144    volPtr->disable_cutplane(2);
     145   
     146    NanoVis::vol_renderer->add_volume(volPtr,
     147        NanoVis::get_transfunc("default"));
     148   
     149    float dx0 = -0.5;
     150    float dy0 = -0.5*volPtr->height/volPtr->width;
     151    float dz0 = -0.5*volPtr->depth/volPtr->width;
     152    volPtr->move(Vector3(dx0, dy0, dz0));
     153    return volPtr;
     154}
     155
    92156
    93157static int
     
    95159               Tcl_Obj *const *objv)
    96160{
    97     Rappture::Outcome context;
     161    Rappture::Outcome result;
    98162
    99163    const char *fileName;
     
    106170    }
    107171    Rappture::Buffer buf;
    108     if (!buf.load(context, fileName)) {
     172    if (!buf.load(result, fileName)) {
    109173        Tcl_AppendResult(interp, "can't load data from \"", fileName, "\": ",
    110                          context.remark(), (char *)NULL);
     174                         result.remark(), (char *)NULL);
    111175        return TCL_ERROR;
    112176    }
     
    114178    FlowCmd *flowPtr = (FlowCmd *)clientData;
    115179    if (strncmp(buf.bytes(), "<DX>", 4) == 0) {
    116         Rappture::Unirect3d data;
    117         if (!load_vector_stream2(context, buf.size(), (char *)buf.bytes(),
    118                                  data)) {
    119             Tcl_AppendResult(interp, context.remark(), (char *)NULL);
     180        Rappture::Unirect3d *dataPtr;
     181
     182        dataPtr = new Rappture::Unirect3d();
     183        if (!dataPtr->ReadVectorDataFromDx(result, buf.size(),
     184                (char *)buf.bytes())) {
     185            Tcl_AppendResult(interp, result.remark(), (char *)NULL);
     186            delete dataPtr;
    120187            return TCL_ERROR;
    121188        }
    122         flowPtr->dataPtr = &data;
     189        flowPtr->dataPtr = dataPtr;
    123190    } else if (strncmp(buf.bytes(), "<unirect3d>", 4) == 0) {
    124         Rappture::Unirect3d data;
     191        Rappture::Unirect3d *dataPtr;
    125192        Tcl_CmdInfo cmdInfo;
    126193
     
    130197            return TCL_ERROR;
    131198        }
    132         data.extents(extents);
    133         cmdInfo.objClientData = (ClientData)&data;     
     199        dataPtr = new Rappture::Unirect3d();
     200        dataPtr->extents(extents);
     201        cmdInfo.objClientData = (ClientData)dataPtr;   
    134202        Tcl_SetCommandInfo(interp, "unirect3d", &cmdInfo);
    135203        if (Tcl_Eval(interp, (const char *)buf.bytes()) != TCL_OK) {
     204            delete dataPtr;
    136205            return TCL_ERROR;
    137206        }
    138         if (!data.isInitialized()) {
     207        if (!dataPtr->isInitialized()) {
     208            delete dataPtr;
    139209            return TCL_ERROR;
    140210        }
    141         flowPtr->dataPtr = &data;
     211        flowPtr->dataPtr = dataPtr;
    142212    }
    143213
     
    174244                    Tcl_Obj *const *objv)
    175245{
    176     Rappture::Outcome context;
     246    Rappture::Outcome result;
    177247
    178248    Trace("Flow Data Loading\n");
     
    192262    FlowCmd *flowPtr = (FlowCmd *)clientData;
    193263    if (strncmp(buf.bytes(), "<DX>", 4) == 0) {
    194         if (!load_vector_stream2(context, buf.size(), (char *)buf.bytes(),
    195                 flowPtr)) {
    196             Tcl_AppendResult(interp, context.remark(), (char *)NULL);
     264        Rappture::Unirect3d *dataPtr;
     265
     266        dataPtr = new Rappture::Unirect3d();
     267        if (!dataPtr->ReadVectorDataFromDx(result, buf.size(),
     268                (char *)buf.bytes())) {
     269            Tcl_AppendResult(interp, result.remark(), (char *)NULL);
     270            delete dataPtr;
    197271            return TCL_ERROR;
    198272        }
     273        flowPtr->dataPtr = dataPtr;
    199274    } else if (strncmp(buf.bytes(), "<unirect3d>", 4) == 0) {
    200         Rappture::Unirect3d data;
     275        Rappture::Unirect3d *dataPtr;
    201276        Tcl_CmdInfo cmdInfo;
    202277
    203278        /* Set the clientdata field of the unirect3d command to contain
    204279         * the local data structure. */
     280        dataPtr = new Rappture::Unirect3d();
    205281        if (!Tcl_GetCommandInfo(interp, "unirect3d", &cmdInfo)) {
    206282            return TCL_ERROR;
    207283        }
    208         data.extents(extents);
    209         cmdInfo.objClientData = (ClientData)&data;     
     284        dataPtr->extents(extents);
     285        cmdInfo.objClientData = (ClientData)dataPtr;   
    210286        Tcl_SetCommandInfo(interp, "unirect3d", &cmdInfo);
    211287        if (Tcl_Eval(interp, (const char *)buf.bytes()) != TCL_OK) {
     288            delete dataPtr;
    212289            return TCL_ERROR;
    213290        }
    214         if (!data.isInitialized()) {
     291        if (!dataPtr->isInitialized()) {
     292            delete dataPtr;
    215293            return TCL_ERROR;
    216294        }
    217         if (!SetVectorFieldDataFromUnirect3d(context, data, flowPtr)) {
    218             Tcl_AppendResult(interp, context.remark(), (char *)NULL);
    219             return TCL_ERROR;
    220         }
    221     }
    222     if (flowPtr->volPtr != NULL) {
    223         delete flowPtr->volPtr;
    224     }
    225     #ifdef notdef
     295        flowPtr->dataPtr = dataPtr;
     296    }
     297#ifdef notdef
    226298    // FIXME: Move this to flow pending routine.
    227299
     
    249321    float dz0 = -0.5*flowPtr->volPtr->depth/flowPtr->volPtr->width;
    250322    flowPtr->volPtr->move(Vector3(dx0, dy0, dz0));
    251     #endif
     323#endif
    252324    return TCL_OK;
    253325}
     
    273345}
    274346
    275 
     347/*
     348 *      Can configure axis of stream plane, the position on the axis, and if
     349 *      the stream plane is visible.
     350 *
     351 */
    276352static Rappture::SwitchSpec streamSwitches[] =
    277353{
     
    284360
    285361static int
    286 FlowStreamConfigureOp(ClientData clientData, Tcl_Interp *interp, int objc,
     362FlowSliceConfigureOp(ClientData clientData, Tcl_Interp *interp, int objc,
    287363                     Tcl_Obj *const *objv)
    288364{
     
    295371    streamPtr = flowPtr->streams + axis;
    296372
    297     if (Rappture::ParseSwitches(interp, streamSwitches, objc - 3, objv + 3,
     373    if (flowPtr->ParseRappture::ParseSwitches(interp, streamSwitches, objc - 3, objv + 3,
    298374        streamPtr, SWITCH_DEFAULTS) < 0) {
    299375        return TCL_ERROR;
    300376    }
     377    // Save the values in the stream
     378    streamPtr->axis;
    301379    NanoVis::lic_slice_x = streamPtr->position;
    302380    NanoVis::licRenderer->set_axis(axis);
     
    324402    return (*proc) (clientData, interp, objc, objv);
    325403}
    326 
    327 static int
    328 FlowParticlesVisibleOp(ClientData clientData, Tcl_Interp *interp, int objc,
    329              Tcl_Obj *const *objv)
    330 {
    331     bool state;
    332     if (GetBooleanFromObj(interp, objv[3], &state) != TCL_OK) {
    333         return TCL_ERROR;
    334     }
    335 
    336     NanoVis::particle_on = state;
    337     return TCL_OK;
    338 }
    339 
    340 static Rappture::CmdSpec flowParticlesOps[] = {
    341     {"visible",    1, FlowParticlesVisibleOp,  4, 4, "on|off",},
    342 };
    343 static int nFlowParticlesOps = NumCmdSpecs(flowParticlesOps);
    344 
    345 static int
    346 FlowParticlesOp(ClientData clientData, Tcl_Interp *interp, int objc,
    347              Tcl_Obj *const *objv)
    348 {
    349     Tcl_ObjCmdProc *proc;
    350 
    351     proc = Rappture::GetOpFromObj(interp, nFlowParticlesOps, flowParticlesOps,
    352                                   Rappture::CMDSPEC_ARG2, objc, objv, 0);
    353     if (proc == NULL) {
    354         return TCL_ERROR;
    355     }
    356     return (*proc) (clientData, interp, objc, objv);
    357 }
    358 
    359404
    360405static int
     
    387432}
    388433
    389 static Rappture::SwitchSpec flowSwitches[] =
    390 {
    391     {Rappture::SWITCH_BOOLEAN, "-lic", "boolean",
    392         offsetof(FlowCmd, lic), 0},
     434static Rappture::SwitchSpec streamSwitches[] =
     435{
    393436    {Rappture::SWITCH_BOOLEAN, "-hide", "boolean",
    394         offsetof(FlowCmd, hidden), 0},
     437        offsetof(Stream, hidden), 0},
     438    {Rappture::SWITCH_FLOAT, "-position", "number",
     439        offsetof(Stream, position), 0},
    395440    {Rappture::SWITCH_END}
    396441};
    397442
     443static Rappture::SwitchParseProc AxisSwitchProc;
     444
     445static Rappture:;SwitchCustom axisSwitch = {
     446    AxisSwitchProc, NULL, 0,
     447};
     448
     449/*
     450 *---------------------------------------------------------------------------
     451 *
     452 * AxisSwitch --
     453 *
     454 *      Convert a Tcl_Obj representing the label of a child node into its
     455 *      integer node id.
     456 *
     457 * Results:
     458 *      The return value is a standard Tcl result.
     459 *
     460 *---------------------------------------------------------------------------
     461 */
     462/*ARGSUSED*/
     463static int
     464AxisSwitch(
     465    ClientData clientData,      /* Flag indicating if the node is considered
     466                                 * before or after the insertion position. */
     467    Tcl_Interp *interp,         /* Interpreter to send results back to */
     468    const char *switchName,     /* Not used. */
     469    Tcl_Obj *objPtr,            /* String representation */
     470    char *record,               /* Structure record */
     471    int offset,                 /* Not used. */
     472    int flags)                  /* Not used. */
     473{
     474    const char *string = Tcl_GetString(objPtr);
     475    if (string[1] == '\0') {
     476        FlowCmd::SliceAxis *axisPtr = (FlowCmd::SliceAxis *)(record + offset);
     477        char c;
     478        c = tolower((unsigned char)string[0]);
     479        if (c == 'x') {
     480            *axisPtr = FlowCmd::SliceAxis::AXIS_X;
     481            return TCL_OK;
     482        } else if (c == 'y') {
     483            *axisPtr = FlowCmd::SliceAxis::AXIS_Y;
     484            return TCL_OK;
     485        } else if (c == 'z') {
     486            *axisPtr = FlowCmd::SliceAxis::AXIS_Z;
     487            return TCL_OK;
     488        }
     489        /*FALLTHRU*/
     490    }
     491    Tcl_AppendResult(interp, "bad axis \"", string,
     492                     "\": should be x, y, or z", (char*)NULL);
     493    return TCL_ERROR;
     494}
     495
    398496static int
    399497FlowConfigureOp(ClientData clientData, Tcl_Interp *interp, int objc,
    400498                Tcl_Obj *const *objv)
    401499{
    402     int axis;
    403     if (GetAxisFromObj(interp, objv[3], &axis) != TCL_OK) {
    404         return TCL_ERROR;
    405     }
    406     FlowCmd *flowPtr = (FlowCmd *)clientData;
    407     if (Rappture::ParseSwitches(interp, flowSwitches, objc - 3, objv + 3,
    408         flowPtr, SWITCH_DEFAULTS) < 0) {
    409         return TCL_ERROR;
    410     }
     500    FlowCmd *flowPtr = (FlowCmd *)clientData;
     501
     502    if (flowPtr->ParseSwitches(interp, objc - 3, objv + 3) != TCL_OK) {
     503        return TCL_ERROR;
     504    }
     505    flowPtr->SetAxis();
     506    flowPtr->SetSlicePosition();
     507    flowPtr->SliceVisible();
     508    flowPtr->Visible();
    411509    return TCL_OK;
    412510}
     
    421519};
    422520
    423 static int
    424 FlowInjectorAddOp(ClientData clientData, Tcl_Interp *interp, int objc,
    425                 Tcl_Obj *const *objv)
     521
     522static int
     523FlowParticlesAddOp(ClientData clientData, Tcl_Interp *interp, int objc,
     524                   Tcl_Obj *const *objv)
     525{
     526    FlowCmd *flowPtr = (FlowCmd *)clientData;
     527
     528    if (flowPtr->CreatePlane(interp, objv[3])) {
     529        return TCL_ERROR;
     530    }
     531    Particles *particlesPtr;
     532    if (flowPtr->GetPlane(interp, objv[3], &particlesPtr) != TCL_OK) {
     533        return TCL_ERROR;
     534    }
     535    if (particlesPtr->ParseSwitches(interp, objc - 4, objv + 4) != TCL_OK) {
     536        flowPtr->DestroyPlane(particlesPtr);
     537        return TCL_ERROR;
     538    }
     539    particlesPtr->SetPosition();
     540    particlesPtr->SetColor();
     541    particlesPtr->SetAxis();
     542    particlesPtr->Visible();
     543    return TCL_OK;
     544}
     545
     546static int
     547FlowParticlesConfigureOp(ClientData clientData, Tcl_Interp *interp, int objc,
     548                         Tcl_Obj *const *objv)
     549{
     550    FlowCmd *flowPtr = (FlowCmd *)clientData;
     551
     552    Particles *particlesPtr;
     553    if (flowPtr->GetPlane(interp, objv[3], &particlesPtr) != TCL_OK) {
     554        return TCL_ERROR;
     555    }
     556    if (particlesPtr->ParseSwitches(interp, objc - 4, objv + 4) != TCL_OK) {
     557        return TCL_ERROR;
     558    }
     559    particlesPtr->SetPosition();
     560    particlesPtr->SetColor();
     561    particlesPtr->SetAxis();
     562    particlesPtr->Visible();
     563    return TCL_OK;
     564}
     565
     566static int
     567FlowParticlesDeleteOp(ClientData clientData, Tcl_Interp *interp, int objc,
     568                      Tcl_Obj *const *objv)
     569{
     570    FlowCmd *flowPtr = (FlowCmd *)clientData;
     571    int i;
     572    for (i = 3; i < objc; i++) {
     573        Particles *particlesPtr;
     574
     575        if (flowPtr->GetPlane(interp, objv[i], &particlesPtr)!=TCL_OK) {
     576            return TCL_ERROR;
     577        }
     578        flowPtr->DestroyPlane(particlesPtr);
     579    }
     580    return TCL_OK;
     581}
     582
     583static int
     584FlowParticlesNamesOp(ClientData clientData, Tcl_Interp *interp, int objc,
     585                     Tcl_Obj *const *objv)
     586{
     587    FlowCmd *flowPtr = (FlowCmd *)clientData;
     588    Tcl_Obj *listObjPtr;
     589    listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL);
     590    ParticlesIterator iter;
     591    Particles *particlesPtr;
     592    for (particlesPtr = flowPtr->FirstPlane(&iter); particlesPtr != NULL;
     593         particlesPtr = flowPtr->NextPlane(&iter)) {
     594
     595        objPtr = Tcl_NewStringObj(particlesPtr->Name(), -1);
     596        Tcl_ListObjAppendElement(interp, listObjPtr, objPtr);
     597    }
     598    Tcl_SetObjResult(interp, listObjPtr);
     599    return TCL_OK;
     600}
     601
     602/*
     603 *---------------------------------------------------------------------------
     604 *
     605 * FlowParticlesObjCmd --
     606 *
     607 *      This procedure is invoked to process commands on behalf of the flow
     608 *      object.
     609 *
     610 * Results:
     611 *      A standard Tcl result.
     612 *
     613 * Side effects:
     614 *      See the user documentation.
     615 *
     616 * $flow particles oper $name
     617 *---------------------------------------------------------------------------
     618 */
     619static Rappture::CmdSpec flowParticlesOps[] = {
     620    {"add",        1, FlowParticlesAddOp,        3, 0, "name ?switches?",},
     621    {"configure",  1, FlowParticlesConfigureOp,  3, 0, "name ?switches?",},
     622    {"delete",     1, FlowParticlesDeleteOp,     3, 0, "?name...?"},
     623    {"names",      1, FlowParticlesNamesOp,      3, 4, "?pattern?"},
     624};
     625
     626static int nFlowInjectorOps = NumCmdSpecs(flowInjectorOps);
     627
     628static int
     629FlowInjectorOp(ClientData clientData, Tcl_Interp *interp, int objc,
     630               Tcl_Obj *const *objv)
     631{
     632    Tcl_ObjCmdProc *proc;
     633    proc = Rappture::GetOpFromObj(interp, nFlowInjectorOps, flowInjectorOps,
     634        Rappture::CMDSPEC_ARG1, objc, objv, 0);
     635    if (proc == NULL) {
     636        return TCL_ERROR;
     637    }
     638    FlowCmd *flowPtr = (FlowCmd *)clientData;
     639    Tcl_Preserve(flowPtr);
     640    int result;
     641    result = (*proc) (clientData, interp, objc, objv);
     642    Tcl_Release(flowPtr);
     643    return result;
     644}
     645
     646static int
     647FlowShapeAddOp(ClientData clientData, Tcl_Interp *interp, int objc,
     648               Tcl_Obj *const *objv)
    426649{
    427650    FlowCmd *flowPtr = (FlowCmd *)clientData;
     
    456679
    457680static int
    458 FlowInjectorDeleteOp(ClientData clientData, Tcl_Interp *interp, int objc,
     681FlowShapeDeleteOp(ClientData clientData, Tcl_Interp *interp, int objc,
    459682                   Tcl_Obj *const *objv)
    460683{
     
    476699
    477700static int
    478 FlowInjectorNamesOp(ClientData clientData, Tcl_Interp *interp, int objc,
     701FlowShapeNamesOp(ClientData clientData, Tcl_Interp *interp, int objc,
    479702             Tcl_Obj *const *objv)
    480703{
     
    483706    Tcl_HashSearch iter;
    484707    Tcl_Obj *listObjPtr;
     708
    485709    listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL);
    486710    for (hPtr = Tcl_FirstHashEntry(&flowPtr->injectTable, &iter);
     
    498722
    499723static int
    500 FlowInjectorConfigureOp(ClientData clientData, Tcl_Interp *interp, int objc,
     724FlowShapeConfigureOp(ClientData clientData, Tcl_Interp *interp, int objc,
    501725                        Tcl_Obj *const *objv)
    502726{
     
    519743}
    520744
    521 
    522 /*
    523  *---------------------------------------------------------------------------
    524  *
    525  * FlowInjectorObjCmd --
     745/*
     746 *---------------------------------------------------------------------------
     747 *
     748 * FlowShapeOp--
    526749 *
    527750 *      This procedure is invoked to process commands on behalf of the flow
     
    536759 *---------------------------------------------------------------------------
    537760 */
    538 static Rappture::CmdSpec flowInjectorOps[] = {
    539     {"add",        1, FlowInjectorAddOp,        3, 0, "name ?switches?",},
    540     {"configure",  1, FlowInjectorConfigureOp,  3, 5, "name ?switches?",},
    541     {"delete",     1, FlowInjectorDeleteOp,     3, 0, "?name...?"},
    542     {"names",      1, FlowInjectorNamesOp,      3, 4, "?pattern?"},
     761static Rappture::CmdSpec flowShapeOps[] = {
     762    {"add",        1, FlowShapeAddOp,        3, 0, "name ?switches?",},
     763    {"configure",  1, FlowShapeConfigureOp,  3, 5, "name ?switches?",},
     764    {"delete",     1, FlowShapeDeleteOp,     3, 0, "?name...?"},
     765    {"names",      1, FlowShapeNamesOp,      3, 4, "?pattern?"},
    543766};
    544767
    545 static int nFlowInjectorOps = NumCmdSpecs(flowInjectorOps);
    546 
    547 static int
    548 FlowInjectorOp(ClientData clientData, Tcl_Interp *interp, int objc,
     768static int nFlowShapeOps = NumCmdSpecs(flowShapeOps);
     769
     770static int
     771FlowShapeOp(ClientData clientData, Tcl_Interp *interp, int objc,
    549772               Tcl_Obj *const *objv)
    550773{
    551774    Tcl_ObjCmdProc *proc;
    552     proc = Rappture::GetOpFromObj(interp, nFlowInjectorOps, flowInjectorOps,
     775    proc = Rappture::GetOpFromObj(interp, nFlowShapeOps, flowShapeOps,
    553776        Rappture::CMDSPEC_ARG1, objc, objv, 0);
    554777    if (proc == NULL) {
     
    566789 *---------------------------------------------------------------------------
    567790 *
    568  * FlowShapeOp--
     791 * FlowInstObjCmd --
    569792 *
    570793 *      This procedure is invoked to process commands on behalf of the flow
     
    579802 *---------------------------------------------------------------------------
    580803 */
    581 static Rappture::CmdSpec flowShapeOps[] = {
    582     {"add",        1, FlowInjectorAddOp,        3, 0, "name ?switches?",},
    583     {"configure",  1, FlowInjectorConfigureOp,  3, 5, "name ?switches?",},
    584     {"delete",     1, FlowInjectorDeleteOp,     3, 0, "?name...?"},
    585     {"names",      1, FlowInjectorNamesOp,      3, 4, "?pattern?"},
     804static Rappture::CmdSpec flowInstOps[] = {
     805    {"configure",   1, FlowConfigureOp,  3, 5, "?switches?",},
     806    {"data",        1, FlowDataOp,       4, 0, "oper ?args?"},
     807    {"particles",   1, FlowParticlesOp,  3, 0, "oper ?args?",},
     808    {"shape",       2, FlowShapeOp,      3, 0, "oper ?args?",},
    586809};
    587 
    588 static int nFlowShapeOps = NumCmdSpecs(flowShapeOps);
    589 
    590 static int
    591 FlowShapeOp(ClientData clientData, Tcl_Interp *interp, int objc,
     810static int nFlowInstOps = NumCmdSpecs(flowInstOps);
     811
     812static int
     813FlowInstObjCmd(ClientData clientData, Tcl_Interp *interp, int objc,
    592814               Tcl_Obj *const *objv)
    593815{
    594816    Tcl_ObjCmdProc *proc;
    595     proc = Rappture::GetOpFromObj(interp, nFlowShapeOps, flowShapeOps,
     817    proc = Rappture::GetOpFromObj(interp, nFlowInstOps, flowInstOps,
    596818        Rappture::CMDSPEC_ARG1, objc, objv, 0);
    597819    if (proc == NULL) {
     
    609831 *---------------------------------------------------------------------------
    610832 *
    611  * FlowInstObjCmd --
    612  *
    613  *      This procedure is invoked to process commands on behalf of the flow
    614  *      object.
    615  *
    616  * Results:
    617  *      A standard Tcl result.
    618  *
    619  * Side effects:
    620  *      See the user documentation.
    621  *
    622  *---------------------------------------------------------------------------
    623  */
    624 static Rappture::CmdSpec flowInstOps[] = {
    625     {"configure",   1, FlowConfigureOp,  3, 5, "?switches?",},
    626     {"data",        1, FlowDataOp,       4, 0, "oper ?args?"},
    627     {"injector",    1, FlowInjectorOp,   3, 0, "oper ?args?",},
    628     {"particles",   1, FlowParticlesOp,  3, 0, "oper ?args?",},
    629     {"shape",       2, FlowShapeOp,      3, 0, "oper ?args?",},
    630     {"stream",      2, FlowStreamOp,     4, 0, "oper axis ?args?",},
    631 };
    632 static int nFlowInstOps = NumCmdSpecs(flowInstOps);
    633 
    634 static int
    635 FlowInstObjCmd(ClientData clientData, Tcl_Interp *interp, int objc,
    636                Tcl_Obj *const *objv)
    637 {
    638     Tcl_ObjCmdProc *proc;
    639     proc = Rappture::GetOpFromObj(interp, nFlowInstOps, flowInstOps,
    640         Rappture::CMDSPEC_ARG1, objc, objv, 0);
    641     if (proc == NULL) {
    642         return TCL_ERROR;
    643     }
    644     FlowCmd *flowPtr = (FlowCmd *)clientData;
    645     Tcl_Preserve(flowPtr);
    646     int result;
    647     result = (*proc) (clientData, interp, objc, objv);
    648     Tcl_Release(flowPtr);
    649     return result;
    650 }
    651 
    652 /*
    653  *---------------------------------------------------------------------------
    654  *
    655833 * FlowInstDeleteProc --
    656834 *
     
    667845{
    668846    FlowCmd *flowPtr = (FlowCmd *)clientData;
    669 
    670     if (flowPtr->hashPtr != NULL) {
    671         Tcl_DeleteHashEntry(flowPtr->hashPtr);
    672     }
    673847    delete flowPtr;
    674848}
     
    686860          Tcl_Obj *const *objv)
    687861{
    688     const char *name;
    689     name = Tcl_GetString(objv[2]);
    690 
    691     Tcl_HashEntry *hPtr;
    692     int isNew;
    693     hPtr = Tcl_CreateHashEntry(&flowTable, name, &isNew);
    694     if (!isNew) {
    695         Tcl_AppendResult(interp, "flow \"", name, "\" already exists.",
    696                          (char *)NULL);
    697         return TCL_ERROR;
    698     }
    699     Tcl_CmdInfo cmdInfo;
    700     if (Tcl_GetCommandInfo(interp, name, &cmdInfo)) {
    701         Tcl_AppendResult(interp, "an another command \"", name,
    702                          "\" already exists.", (char *)NULL);
    703         return TCL_ERROR;
    704     }   
    705     FlowCmd *flowPtr;
    706     flowPtr = new FlowCmd;
    707     if (flowPtr == NULL) {
    708         Tcl_AppendResult(interp, "can't allocate a flow object \"", name,
    709                          "\"", (char *)NULL);
    710         return TCL_ERROR;
    711     }
    712     flowPtr->hashPtr = hPtr;
    713     flowPtr->name = Tcl_GetHashKey(&flowTable, hPtr);
    714     flowPtr->cmdToken = Tcl_CreateObjCommand(interp, (char *)name,
    715         (Tcl_ObjCmdProc *)FlowInstObjCmd, flowPtr, FlowInstDeleteProc);
    716     Tcl_SetHashValue(hPtr, flowPtr);
    717     flowPtr->volPtr = NULL;
    718     return TCL_OK;
     862    return FlowCmd::NewFlow(interp, Tcl_GetString(objv[2]));
    719863}
    720864
     
    736880        FlowCmd *flowPtr;
    737881
    738         if (GetFlowFromObj(interp, objv[i], &flowPtr) != TCL_OK) {
     882        if (FlowCmd::GetFlowFromObj(interp, objv[i], &flowPtr) != TCL_OK) {
    739883            return TCL_ERROR;
    740884        }
    741         Tcl_DeleteCommandFromToken(interp, flowPtr->cmdToken);
    742 #ifdef notdef
    743         NanoVis::flowVisRenderer->removeVectorField(flowPtr);
    744 #endif
    745885        delete flowPtr;
    746886    }
     
    8901030
    8911031    // Generate the latest frame and send it back to the client
    892     if (NanoVis::licRenderer->isActivated()) {
    893         NanoVis::licRenderer->convolve();
    894     }
    895     NanoVis::flowVisRenderer->advect();
     1032    NanoVis::licRenderer->convolve();
     1033    FlowCmd::AdvectFlows();
    8961034    NanoVis::offscreen_buffer_capture();  //enable offscreen render
    8971035    NanoVis::display();
     
    9431081        return TCL_ERROR;
    9441082    }
    945 
    946     if (NanoVis::licRenderer) {
    947         NanoVis::licRenderer->activate();
    948     }
    949     if (NanoVis::flowVisRenderer) {
    950         NanoVis::flowVisRenderer->activate();
    951     }
     1083    if (NanoVis::licRenderer == NULL) {
     1084        Tcl_AppendResult(interp, "no lic renderer.", (char *)NULL);
     1085        return TCL_ERROR;
     1086    }
     1087    if (NanoVis::flowVisRenderer == NULL) {
     1088        Tcl_AppendResult(interp, "no flow renderer.", (char *)NULL);
     1089        return TCL_ERROR;
     1090    }
     1091    NanoVis::licRenderer->activate();
     1092    NanoVis::flowVisRenderer->activate();
    9521093
    9531094    // Save the old dimensions of the offscreen buffer.
     
    9661107    Trace("FLOW started\n");
    9671108
    968     Rappture::Outcome context;
     1109    Rappture::Outcome result;
    9691110    Rappture::AVTranslate movie(width, height, frameRate, bitRate);
    9701111
     
    9741115    }
    9751116
    976     movie.init(context, fileName);
     1117    movie.init(result, fileName);
    9771118
    9781119    for (int i = 0; i < numFrames; i++) {
    9791120        // Generate the latest frame and send it back to the client
    980         if (NanoVis::licRenderer &&
    981             NanoVis::licRenderer->isActivated()) {
    982             NanoVis::licRenderer->convolve();
    983         }
    984         if (NanoVis::flowVisRenderer &&
    985             NanoVis::flowVisRenderer->isActivated()) {
    986             NanoVis::flowVisRenderer->advect();
    987         }
     1121        NanoVis::licRenderer->convolve();
     1122        FlowCmd::AdvectFlows();
    9881123        NanoVis::offscreen_buffer_capture();  //enable offscreen render
    9891124        NanoVis::display();
     
    9941129        // This is done before bmp_write_to_file because bmp_write_to_file
    9951130        // turns rgb data to bgr
    996         movie.append(context, NanoVis::screen_buffer, pad);
     1131        movie.append(result, NanoVis::screen_buffer, pad);
    9971132        // NanoVis::bmp_write_to_file(frame_count, fileName);
    9981133    }
    9991134
    1000     movie.done(context);
     1135    movie.done(result);
    10011136    Trace("FLOW end\n");
    10021137
     
    10111146    // FIXME: find a way to get the data from the movie object as a void*
    10121147    Rappture::Buffer data;
    1013     if (!data.load(context, fileName)) {
     1148    if (!data.load(result, fileName)) {
    10141149        Tcl_AppendResult(interp, "can't load data from temporary movie file \"",
    1015                 fileName, "\": ", context.remark(), (char *)NULL);
     1150                fileName, "\": ", result.remark(), (char *)NULL);
    10161151        return TCL_ERROR;
    10171152    }
     
    10881223}
    10891224
    1090 #ifdef notdef
    1091 void
    1092 MapFlowVectors(Tcl_Interp *interp)
    1093 {
    1094     double xMin, xMax, yMin, yMax, zMin, zMax, wMin, wMax;
    1095 
    1096     if (debug_flag) {
    1097         fprintf(stderr, "in SetHeightmapRanges\n");
    1098     }
    1099     xMin = yMin = zMin = wMin = DBL_MAX;
    1100     xMax = yMax = zMax = wMax = -DBL_MAX;
    1101     Tcl_HashEntry *hPtr;
    1102     Tcl_HashSearch iter;
    1103     for (hPtr = Tcl_FirstHashEntry(&flowTable, &iter); hPtr != NULL;
    1104         hPtr = Tcl_NextHashEntry(&iter)) {
    1105         FlowCmd *flowPtr;
    1106         flowPtr = (FlowCmd *)Tcl_GetHashValue(hPtr);
    1107 
    1108         flowPtr->
    1109 
    1110     for (unsigned int i = 0; i < heightMap.size(); i++) {
    1111         HeightMap *hmPtr;
    1112 
    1113         hmPtr = heightMap[i];
    1114         if (hmPtr == NULL) {
    1115             continue;
    1116         }
    1117         if (xMin > hmPtr->xAxis.min()) {
    1118             xMin = hmPtr->xAxis.min();
    1119         }
    1120         if (xMax < hmPtr->xAxis.max()) {
    1121             xMax = hmPtr->xAxis.max();
    1122         }
    1123         if (yMin > hmPtr->yAxis.min()) {
    1124             yMin = hmPtr->yAxis.min();
    1125         }
    1126         if (yMax < hmPtr->yAxis.max()) {
    1127             yMax = hmPtr->yAxis.max();
    1128         }
    1129         if (zMin > hmPtr->zAxis.min()) {
    1130             zMin = hmPtr->zAxis.min();
    1131         }
    1132         if (zMax < hmPtr->zAxis.max()) {
    1133             zMax = hmPtr->zAxis.max();
    1134         }
    1135         if (wMin > hmPtr->wAxis.min()) {
    1136             wMin = hmPtr->wAxis.min();
    1137         }
    1138         if (wMax < hmPtr->wAxis.max()) {
    1139             wMax = hmPtr->wAxis.max();
    1140         }
    1141     }
    1142     if ((xMin < DBL_MAX) && (xMax > -DBL_MAX)) {
    1143         grid->xAxis.SetScale(xMin, xMax);
    1144     }
    1145     if ((yMin < DBL_MAX) && (yMax > -DBL_MAX)) {
    1146         grid->yAxis.SetScale(yMin, yMax);
    1147     }
    1148     if ((zMin < DBL_MAX) && (zMax > -DBL_MAX)) {
    1149         grid->zAxis.SetScale(zMin, zMax);
    1150     }
    1151     if ((wMin < DBL_MAX) && (wMax > -DBL_MAX)) {
    1152         HeightMap::valueMin = grid->yAxis.min();
    1153         HeightMap::valueMax = grid->yAxis.max();
    1154     }
    1155     for (unsigned int i = 0; i < heightMap.size(); i++) {
    1156         HeightMap *hmPtr;
    1157 
    1158         hmPtr = heightMap[i];
    1159         if (hmPtr == NULL) {
    1160             continue;
    1161         }
    1162         hmPtr->MapToGrid(grid);
    1163     }
    1164     HeightMap::update_pending = false;
    1165     if (debug_flag) {
    1166         fprintf(stderr, "leaving SetHeightmapRanges\n");
    1167     }
    1168 }
    1169 
    1170     Tcl_Obj *listObjPtr;
    1171     listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL);
    1172 
    1173     Tcl_HashEntry *hPtr;
    1174     Tcl_HashSearch iter;
    1175     for (hPtr = Tcl_FirstHashEntry(&flowTable, &iter); hPtr != NULL;
    1176         hPtr = Tcl_NextHashEntry(&iter)) {
    1177         FlowCmd *flowPtr;
    1178         flowPtr = (FlowCmd *)Tcl_GetHashValue(hPtr);
    1179         if (flowPtr->fieldPtr != NULL) {
    1180             delete flowPtr->fieldPtr; // Remove the vector field.
    1181             flowPtr->fieldPtr = NULL;
    1182         }
    1183     }
    1184 
    1185 
    1186             Volume *volPtr;
    1187             volPtr = NanoVis::load_volume(index, nx, ny, nz, 4, data,
    1188                         field.valueMin(), field.valueMax(), nzero_min);
    1189             volPtr->xAxis.SetRange(field.rangeMin(Rappture::xaxis),
    1190                    field.rangeMax(Rappture::xaxis));
    1191             volPtr->yAxis.SetRange(field.rangeMin(Rappture::yaxis),
    1192                    field.rangeMax(Rappture::yaxis));
    1193             volPtr->zAxis.SetRange(field.rangeMin(Rappture::zaxis),
    1194                    field.rangeMax(Rappture::zaxis));
    1195             volPtr->wAxis.SetRange(field.valueMin(), field.valueMax());
    1196             volPtr->update_pending = true;
    1197             delete [] data;
    1198 #endif
  • trunk/packages/vizservers/nanovis/LoadVector.cpp

    r1380 r1429  
    1212#include "FlowCmd.h"
    1313
    14 static INLINE char *
    15 skipspaces(char *string)
     14   
     15
     16bool
     17ScaleVectorFieldData(Rappture::Outcome &context, Rappture::Unirect3d *dataPtr)
    1618{
    17     while (isspace(*string)) {
    18         string++;
    19     }
    20     return string;
    21 }
    22 
    23 static INLINE char *
    24 getline(char **stringPtr, char *endPtr)
    25 {
    26     char *line, *p;
    27 
    28     line = skipspaces(*stringPtr);
    29     for (p = line; p < endPtr; p++) {
    30         if (*p == '\n') {
    31             *p++ = '\0';
    32             *stringPtr = p;
    33             return line;
    34         }
    35     }
    36     *stringPtr = p;
    37     return line;
    38 }
    39 
    40 bool
    41 SetVectorFieldData(Rappture::Outcome &context,
    42                    float xMin, float xMax, size_t xNum,
    43                    float yMin, float yMax, size_t yNum,
    44                    float zMin, float zMax, size_t zNum,
    45                    size_t nValues, float *values, Unirect3d *dataPtr)
    46 {
     19    float *values = dataPtr->values();
     20    float *nValues = dataPtr->nValues();
    4721#ifdef notdef
    4822    double max_x = -1e21, min_x = 1e21;
     
    7448            xNum, yNum, zNum, xNum * yNum * zNum);
    7549   
    76     // Generate the uniformly sampled rectangle that we need for a volume
    7750    float *destPtr = data;
    7851    float *srcPtr = values;
     
    9770        }
    9871    }
    99     dataPtr->xMin(xMin);
    100     dataPtr->xMax(xMax);
    101     dataPtr->xNum(xNum);
    102     dataPtr->yMin(yMin);
    103     dataPtr->yMax(yMax);
     72    dataPtr->SetValues(xMin, xMax, xNum, yMin, yMax(yMax);
    10473    dataPtr->yNum(yNum);
    10574    dataPtr->yMin(zMin);
     
    11382
    11483bool
    115 SetResampledVectorFieldData(Rappture::Outcome &context,
    116                             float xMin, float xMax, size_t xNum,
    117                             float yMin, float yMax, size_t yNum,
    118                             float zMin, float zMax, size_t zNum,
    119                             size_t nValues, float *values, FlowCmd *flowPtr)
     84ScaleResampledVectorFieldData(Rappture::Outcome &context,
     85                              Rappture::Unirect3d *dataPtr)
    12086{
    121     Rappture::Mesh1D xgrid(xMin, xMax, xNum);
    122     Rappture::Mesh1D ygrid(yMin, yMax, yNum);
    123     Rappture::Mesh1D zgrid(zMin, zMax, zNum);
     87    Rappture::Mesh1D xgrid(dataPtr->xMin(), dataPtr->xMax(), dataPtr->xNum());
     88    Rappture::Mesh1D ygrid(dataPtr->yMin(), dataPtr->yMax(), dataPtr->yNum());
     89    Rappture::Mesh1D zgrid(dataPtr->zMin(), dataPtr->zMax(), dataPtr->zNum());
    12490    Rappture::FieldRect3D xfield(xgrid, ygrid, zgrid);
    12591    Rappture::FieldRect3D yfield(xgrid, ygrid, zgrid);
     
    135101    max_mag = -1e21, nzero_min = min_mag = 1e21;
    136102    size_t i, j;
    137     for (i = j = 0; i < nValues; i += 3, j++) {
     103    for (i = j = 0; i < dataPtr->nValues(); i += 3, j++) {
    138104        double vx, vy, vz, vm;
    139105
    140         vx = values[i];
    141         vy = values[i+1];
    142         vz = values[i+2];
     106        vx = dataPtr->values[i];
     107        vy = dataPtr->values[i+1];
     108        vz = dataPtr->values[i+2];
    143109       
    144110        xfield.define(j, vx);
     
    217183        }
    218184    }
    219    
     185    dataPtr->zMin()
    220186    flowPtr->xMin = xMin;
    221187    flowPtr->xMax = xMax;
     
    246212
    247213
    248 #ifdef notdef
    249214/*
    250215 * Load a 3D vector field from a dx-format file
     
    371336}
    372337
    373 #endif
  • trunk/packages/vizservers/nanovis/Makefile.in

    r1392 r1429  
    104104                Event.o \
    105105                Unirect.o \
     106                FlowCmd.o \
     107                FlowCmds.o \
     108                LoadVector.o \
     109                Switch.o \
    106110                GradientFilter.o \
    107111                Grid.o \
  • trunk/packages/vizservers/nanovis/NvFlowVisRenderer.h

    r1370 r1429  
    4444        void reset();
    4545        void render();
     46
     47        void addVectorField(Volume* volPtr, const Vector3& ori, float scaleX,
     48                float scaleY, float scaleZ, float max);
    4649
    4750        void addVectorField(const std::string& vfName, Volume* volPtr, const Vector3& ori, float scaleX, float scaleY, float scaleZ, float max);
  • trunk/packages/vizservers/nanovis/NvLIC.cpp

    r1370 r1429  
    308308    float x1, x2, y, px, py;
    309309   
     310    glPushMatrix();
    310311    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
    311312   
     
    313314    glLoadIdentity();
    314315    glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT);
     316
     317    /*glPushMatrix();*/
    315318    glViewport(0, 0, (GLsizei) NPIX, (GLsizei) NPIX);
    316319    //glTranslatef(-1.0, -1.0, 0.0);
     
    397400    glPopMatrix();
    398401    glMatrixMode(GL_PROJECTION);
    399     glPopMatrix();
     402    /*glPopMatrix();*/
    400403    glMatrixMode(GL_MODELVIEW);
    401404}
     
    488491
    489492void
    490 NvLIC::setVectorField(unsigned int texID, const Vector3& ori, float scaleX, float scaleY,
    491                       float scaleZ, float max)
     493NvLIC::setVectorField(unsigned int texID, const Vector3& ori,
     494                      float scaleX, float scaleY, float scaleZ, float max)
    492495{
    493496    Trace("NvLIC: vector field is assigned [%d]\n", texID);
     
    531534NvLIC::set_offset(float v)
    532535{
    533         switch (axis)
    534         {
    535         case 0 : offset.x = v; break;
    536         case 1 : offset.y = v; break;
    537         case 2 : offset.z = v; break;
    538         }
    539 
    540         get_slice();
     536    switch (axis) {
     537    case 0 : offset.x = v; break;
     538    case 1 : offset.y = v; break;
     539    case 2 : offset.z = v; break;
     540    }
     541    get_slice();
    541542}
    542543
  • trunk/packages/vizservers/nanovis/NvParticleRenderer.cpp

    r1380 r1429  
    2525#include <stdlib.h>
    2626
    27 
    2827#define NV_32
    2928
     
    5150    m_vertex_array = new RenderVertexArray(psys_width*psys_height, 3, GL_FLOAT);
    5251
    53     assert(glGetError()==0);
     52    assert(CheckGL(AT));
    5453
    5554    glGenFramebuffersEXT(2, psys_fbo);
     
    131130    glDeleteFramebuffersEXT(2, psys_fbo);
    132131
     132    delete m_vertex_array;
     133    delete _advectionShader;
    133134    free(data);
    134135}
     
    244245    if (reborn)
    245246        reset();
    246 
     247   
    247248    glDisable(GL_BLEND);
    248249    glDisable(GL_DEPTH_TEST);
  • trunk/packages/vizservers/nanovis/Switch.h

    r1384 r1429  
    3434#  include <stddef.h>
    3535#endif /* HAVE_STDDEF_H */
    36 
    37 #ifdef offsetof
    38 #define SwitchOffset(type, field) ((int) offsetof(type, field))
    39 #else
    40 #define SwitchOffset(type, field) ((int) ((char *) &((type *) 0)->field))
    41 #endif
    4236
    4337namespace Rappture {
  • trunk/packages/vizservers/nanovis/Trace.h

    r1200 r1429  
    55#include <GL/glut.h>
    66
     7#define MAKE_STRING(x) #x
     8#define NEWSTRING(x) MAKE_STRING(x)
     9#define AT __FILE__ ":" NEWSTRING(__LINE__)
     10
    711extern void Trace(const char* format, ...);
    812extern bool CheckFBO(GLenum *statusPtr);
  • trunk/packages/vizservers/nanovis/Unirect.cpp

    r1381 r1429  
    11
     2#include <float.h>
    23#include <tcl.h>
    34#include <Unirect.h>
     5#include "RpField1D.h"
     6#include "RpFieldRect3D.h"
    47
    58extern int GetFloatFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
    69        float *valuePtr);
    710extern int GetAxisFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, int *indexPtr);
     11
     12static INLINE char *
     13skipspaces(char *string)
     14{
     15    while (isspace(*string)) {
     16        string++;
     17    }
     18    return string;
     19}
     20
     21static INLINE char *
     22getline(char **stringPtr, char *endPtr)
     23{
     24    char *line, *p;
     25
     26    line = skipspaces(*stringPtr);
     27    for (p = line; p < endPtr; p++) {
     28        if (*p == '\n') {
     29            *p++ = '\0';
     30            *stringPtr = p;
     31            return line;
     32        }
     33    }
     34    *stringPtr = p;
     35    return line;
     36}
    837
    938int
     
    3059    axis3 = 0;                  /* X-axis */
    3160
    32     int extents = 1;
    3361    values = NULL;
    3462    num[0] = num[1] = num[2] = nValues = 0;
     
    115143            }
    116144        } else if ((c == 'u') && (strcmp(string, "units") == 0)) {
    117             vUnits_ = strdup(Tcl_GetString(objv[i+1]));
     145            _vUnits = strdup(Tcl_GetString(objv[i+1]));
    118146        } else if ((c == 'o') && (strcmp(string, "order") == 0)) {
    119147            Tcl_Obj **axes;
     
    142170        return TCL_ERROR;
    143171    }
    144     if (nValues != (num[0] * num[1] * num[2] * extents)) {
     172    if ((size_t)nValues != (num[0] * num[1] * num[2] * _nComponents)) {
    145173        Tcl_AppendResult(interp,
    146174                "wrong number of values: must be xnum*ynum*znum*extents",
     
    149177    }
    150178   
    151     fprintf(stderr, "generating %dx%dx%dx%d = %d points\n",
    152             num[0], num[1], num[2], extents, num[0]*num[1]*num[2]*extents);
    153 
    154179    if ((axis1 != 2) || (axis2 != 1) || (axis3 != 0)) {
    155180        // Reorder the data into x, y, z where x varies fastest and so on.
     
    165190
    166191                for (x = 0; x < num[2]; x++) {
    167                     int i, v;
     192                    int i;
    168193                   
    169194                    /* Compute the index from the data's described ordering. */
    170195                    i = ((z*num[axis2]*num[axis3]) + (y*num[axis3]) + x) * 3;
    171                     for(v = 0; v < extents; v++) {
     196                    for(size_t v = 0; v < _nComponents; v++) {
    172197                        dp[v] = values[i+v];
    173198                    }
    174                     dp += extents;
     199                    dp += _nComponents;
    175200                }
    176201            }
     
    180205    }
    181206
    182     values_ = values;
    183     nValues_ = nValues;
    184     extents_ = extents;
     207    _values = values;
     208    _nValues = nValues;
    185209    if (units[3] != NULL) {
    186         vUnits_ = strdup(units[3]);
    187     }
    188     xMin_ = min[axis3];
    189     xMax_ = max[axis3];
    190     xNum_ = num[axis3];
     210        _vUnits = strdup(units[3]);
     211    }
     212    _xMin = min[axis3];
     213    _xMax = max[axis3];
     214    _xNum = num[axis3];
    191215    if (units[axis3] != NULL) {
    192         xUnits_ = strdup(units[axis3]);
    193     }
    194     yMin_ = min[axis2];
    195     yMax_ = max[axis2];
    196     yNum_ = num[axis2];
     216        _xUnits = strdup(units[axis3]);
     217    }
     218    _yMin = min[axis2];
     219    _yMax = max[axis2];
     220    _yNum = num[axis2];
    197221    if (units[axis2] != NULL) {
    198         yUnits_ = strdup(units[axis2]);
    199     }
    200     zMin_ = min[axis1];
    201     zMax_ = max[axis1];
    202     zNum_ = num[axis1];
     222        _yUnits = strdup(units[axis2]);
     223    }
     224    _zMin = min[axis1];
     225    _zMax = max[axis1];
     226    _zNum = num[axis1];
    203227    if (units[axis1] != NULL) {
    204         zUnits_ = strdup(units[axis1]);
    205     }
    206     initialized_ = true;
     228        _zUnits = strdup(units[axis1]);
     229    }
     230    _initialized = true;
    207231    return TCL_OK;
    208232}
     
    225249    axis[1] = 0;                        /* Y-axis */
    226250
    227     extents_ = 1;
    228     xNum_ = yNum_ = nValues_ = 0;
    229     xMin_ = yMin_ = xMax_ = yMax_ = 0.0f;
    230     if (xUnits_ != NULL) {
    231         free(xUnits_);
    232     }
    233     if (yUnits_ != NULL) {
    234         free(yUnits_);
    235     }
    236     if (vUnits_ != NULL) {
    237         free(vUnits_);
    238     }
    239     xUnits_ = yUnits_ = vUnits_ = NULL;
    240     if (values_ != NULL) {
    241         delete [] values_;
    242     }
    243     values_ = NULL;
     251    _xNum = _yNum = _nValues = 0;
     252    _xMin = _yMin = _xMax = _yMax = 0.0f;
     253    if (_xUnits != NULL) {
     254        free(_xUnits);
     255    }
     256    if (_yUnits != NULL) {
     257        free(_yUnits);
     258    }
     259    if (_vUnits != NULL) {
     260        free(_vUnits);
     261    }
     262    _xUnits = _yUnits = _vUnits = NULL;
     263    if (_values != NULL) {
     264        delete [] _values;
     265    }
     266    _values = NULL;
    244267
    245268    int i;
     
    251274        c = string[0];
    252275        if ((c == 'x') && (strcmp(string, "xmin") == 0)) {
    253             if (GetFloatFromObj(interp, objv[i+1], &xMin_) != TCL_OK) {
     276            if (GetFloatFromObj(interp, objv[i+1], &_xMin) != TCL_OK) {
    254277                return TCL_ERROR;
    255278            }
    256279        } else if ((c == 'x') && (strcmp(string, "xmax") == 0)) {
    257             if (GetFloatFromObj(interp, objv[i+1], &xMax_) != TCL_OK) {
     280            if (GetFloatFromObj(interp, objv[i+1], &_xMax) != TCL_OK) {
    258281                return TCL_ERROR;
    259282            }
     
    268291                return TCL_ERROR;
    269292            }
    270             xNum_ = n;
     293            _xNum = n;
    271294        } else if ((c == 'x') && (strcmp(string, "xunits") == 0)) {
    272             xUnits_ = strdup(Tcl_GetString(objv[i+1]));
     295            _xUnits = strdup(Tcl_GetString(objv[i+1]));
    273296        } else if ((c == 'y') && (strcmp(string, "ymin") == 0)) {
    274             if (GetFloatFromObj(interp, objv[i+1], &yMin_) != TCL_OK) {
     297            if (GetFloatFromObj(interp, objv[i+1], &_yMin) != TCL_OK) {
    275298                return TCL_ERROR;
    276299            }
    277300        } else if ((c == 'y') && (strcmp(string, "ymax") == 0)) {
    278             if (GetFloatFromObj(interp, objv[i+1], &yMax_) != TCL_OK) {
     301            if (GetFloatFromObj(interp, objv[i+1], &_yMax) != TCL_OK) {
    279302                return TCL_ERROR;
    280303            }
     
    289312                return TCL_ERROR;
    290313            }
    291             yNum_ = n;
     314            _yNum = n;
    292315        } else if ((c == 'y') && (strcmp(string, "yunits") == 0)) {
    293             yUnits_ = strdup(Tcl_GetString(objv[i+1]));
     316            _yUnits = strdup(Tcl_GetString(objv[i+1]));
    294317        } else if ((c == 'v') && (strcmp(string, "values") == 0)) {
    295318            Tcl_Obj **vobj;
     
    304327                return TCL_ERROR;
    305328            }
    306             nValues_ = n;
    307             values_ = new float[nValues_];
     329            _nValues = n;
     330            _values = new float[_nValues];
    308331            size_t j;
    309             for (j = 0; j < nValues_; j++) {
    310                 if (GetFloatFromObj(interp, vobj[j], values_ + j)!=TCL_OK) {
     332            for (j = 0; j < _nValues; j++) {
     333                if (GetFloatFromObj(interp, vobj[j], _values + j)!=TCL_OK) {
    311334                    return TCL_ERROR;
    312335                }
    313336            }
    314337        } else if ((c == 'u') && (strcmp(string, "units") == 0)) {
    315             vUnits_ = strdup(Tcl_GetString(objv[i+1]));
     338            _vUnits = strdup(Tcl_GetString(objv[i+1]));
    316339        } else if ((c == 'e') && (strcmp(string, "extents") == 0)) {
    317340            int n;
     
    325348                return TCL_ERROR;
    326349            }
    327             extents_ = n;
     350            _nComponents = n;
    328351        } else if ((c == 'a') && (strcmp(string, "axisorder") == 0)) {
    329352            Tcl_Obj **order;
     
    350373        }
    351374    }
    352     if (values_ == NULL) {
     375    if (_values == NULL) {
    353376        Tcl_AppendResult(interp, "missing \"values\" key", (char *)NULL);
    354377        return TCL_ERROR;
    355378    }
    356     if (nValues_ != (xNum_ * yNum_ * extents_)) {
     379    if (_nValues != (_xNum * _yNum * _nComponents)) {
    357380        Tcl_AppendResult(interp,
    358381                "wrong number of values: must be xnum*ynum*extents",
     
    361384    }
    362385   
    363     fprintf(stderr, "generating %dx%dx%d = %d points\n",
    364             xNum_, yNum_, extents_, xNum_ * yNum_ * extents_);
    365 
    366386#ifndef notdef
    367387    if ((axis[0] != 1) || (axis[1] != 0)) {
     
    371391        float *data, *dp;
    372392
    373         dp = data = new float[nValues_];
    374         for (y = 0; y < yNum_; y++) {
     393        dp = data = new float[_nValues];
     394        for (y = 0; y < _yNum; y++) {
    375395            size_t x;
    376396
    377             for (x = 0; x < xNum_; x++) {
     397            for (x = 0; x < _xNum; x++) {
    378398                size_t i, v;
    379399                   
    380400                /* Compute the index from the data's described ordering. */
    381                 i = (y + (yNum_ * x)) * extents_;
    382                 for(v = 0; v < extents_; v++) {
    383                     dp[v] = values_[i+v];
     401                i = (y + (_yNum * x)) * _nComponents;
     402                for(v = 0; v < _nComponents; v++) {
     403                    dp[v] = _values[i+v];
    384404                }
    385                 dp += extents_;
    386             }
    387         }
    388         delete [] values_;
    389         values_ = data;
     405                dp += _nComponents;
     406            }
     407        }
     408        delete [] _values;
     409        _values = data;
    390410    }
    391411#endif
    392     initialized_ = true;
     412    _initialized = true;
    393413    return TCL_OK;
    394414}
     415
     416
     417bool
     418Rappture::Unirect3d::ReadVectorDataFromDx(Rappture::Outcome &result,
     419        size_t length, char *string)
     420{
     421    size_t nx, ny, nz, npts;
     422    double x0, y0, z0, dx, dy, dz, ddx, ddy, ddz;
     423    char *p, *endPtr;
     424
     425    dx = dy = dz = 0.0;         // Suppress compiler warning.
     426    x0 = y0 = z0 = 0.0;         // May not have an origin line.
     427    for (p = string, endPtr = p + length; p < endPtr; /*empty*/) {
     428        char *line;
     429
     430        line = getline(&p, endPtr);
     431        if (line == endPtr) {
     432            break;
     433        }
     434        if ((line[0] == '#') || (line == '\0')) {
     435            continue;           // Skip blank or comment lines.
     436        }
     437        if (sscanf(line, "object %*d class gridpositions counts %d %d %d",
     438                   &nx, &ny, &nz) == 3) {
     439            if ((nx < 0) || (ny < 0) || (nz < 0)) {
     440                result.addError("invalid grid size: x=%d, y=%d, z=%d",
     441                        nx, ny, nz);
     442                return false;
     443            }
     444        } else if (sscanf(line, "origin %lg %lg %lg", &x0, &y0, &z0) == 3) {
     445            // found origin
     446        } else if (sscanf(line, "delta %lg %lg %lg", &ddx, &ddy, &ddz) == 3) {
     447            // found one of the delta lines
     448            if (ddx != 0.0) {
     449                dx = ddx;
     450            } else if (ddy != 0.0) {
     451                dy = ddy;
     452            } else if (ddz != 0.0) {
     453                dz = ddz;
     454            }
     455        } else if (sscanf(line, "object %*d class array type %*s shape 3"
     456                " rank 1 items %d data follows", &npts) == 1) {
     457            printf("#points=%d\n", npts);
     458            if (npts != nx*ny*nz) {
     459                result.addError("inconsistent data: expected %d points"
     460                                " but found %d points", nx*ny*nz, npts);
     461                return false;
     462            }
     463            break;
     464        } else if (sscanf(line, "object %*d class array type %*s rank 0"
     465                " times %d data follows", &npts) == 1) {
     466            if (npts != nx*ny*nz) {
     467                result.addError("inconsistent data: expected %d points"
     468                                " but found %d points", nx*ny*nz, npts);
     469                return false;
     470            }
     471            break;
     472        }
     473    }
     474    if (npts != nx*ny*nz) {
     475        result.addError("inconsistent data: expected %d points"
     476                        " but found %d points", nx*ny*nz, npts);
     477        return false;
     478    }
     479
     480    _initialized = false;
     481    _xValueMin = _yValueMin = _zValueMin = FLT_MAX;
     482    _xValueMax = _yValueMax = _zValueMax = -FLT_MAX;
     483    _xMin = x0, _yMin = y0, _zMin = z0;
     484    _xNum = nx, _yNum = ny, _zNum = nz;
     485    _xMax = _xMin + dx * _xNum;
     486    _yMax = _yMin + dy * _yNum;
     487    _zMax = _zMin + dz * _zNum;
     488    if (_values != NULL) {
     489        delete [] _values;
     490    }
     491    _values = new float[npts * _nComponents];
     492    _nValues = 0;
     493    for (size_t ix = 0; ix < _xNum; ix++) {
     494        for (size_t iy = 0; iy < _yNum; iy++) {
     495            for (size_t iz = 0; iz < _zNum; iz++) {
     496                char *line;
     497                if ((p == endPtr) || (_nValues > (size_t)npts)) {
     498                    break;
     499                }
     500                line = getline(&p, endPtr);
     501                if ((line[0] == '#') || (line[0] == '\0')) {
     502                    continue;   // Skip blank or comment lines.
     503                }
     504                double vx, vy, vz;
     505                if (sscanf(line, "%lg %lg %lg", &vx, &vy, &vz) == 3) {
     506                    int nindex = (iz*nx*ny + iy*nx + ix) * 3;
     507                    if (vx < _xValueMin) {
     508                        _xValueMin = vx;
     509                    } else if (vx > _xValueMax) {
     510                        _xValueMax = vx;
     511                    }
     512                    if (vy < _yValueMin) {
     513                        _yValueMin = vy;
     514                    } else if (vy > _yValueMax) {
     515                        _yValueMax = vy;
     516                    }
     517                    if (vz < _zValueMin) {
     518                        _zValueMin = vz;
     519                    } else if (vz > _zValueMax) {
     520                        _zValueMax = vz;
     521                    }
     522                    if (nindex >= (npts*3)) {
     523                        fprintf(stderr, "nindex=%d, npts=%d, z=%d, y=%d, x=%d\n",
     524                                nindex, npts, iz, iy, ix);
     525                    }
     526                    _values[nindex] = vx;
     527                    _values[nindex+1] = vy;
     528                    _values[nindex+2] = vz;
     529                    _nValues++;
     530                }
     531            }
     532        }
     533    }
     534    // make sure that we read all of the expected points
     535    if (_nValues != npts) {
     536        result.addError("inconsistent data: expected %d points"
     537                        " but found %d points", npts, _nValues);
     538        delete []  _values;
     539        _values = NULL;
     540        return false;
     541    }
     542    _nValues *= _nComponents;
     543    _initialized = true;
     544    return true;
     545}
     546
     547
     548bool
     549Rappture::Unirect3d::Resample(Rappture::Outcome &result, int nSamples)
     550{
     551    Rappture::Mesh1D xgrid(_xMin, _xMax, _xNum);
     552    Rappture::Mesh1D ygrid(_yMin, _yMax, _yNum);
     553    Rappture::Mesh1D zgrid(_zMin, _zMax, _zNum);
     554    Rappture::FieldRect3D xfield(xgrid, ygrid, zgrid);
     555    Rappture::FieldRect3D yfield(xgrid, ygrid, zgrid);
     556    Rappture::FieldRect3D zfield(xgrid, ygrid, zgrid);
     557
     558    size_t i, j;
     559    for (i = 0, j = 0; i < _nValues; i += _nComponents, j++) {
     560        double vx, vy, vz;
     561
     562        vx = _values[i];
     563        vy = _values[i+1];
     564        vz = _values[i+2];
     565       
     566        xfield.define(j, vx);
     567        yfield.define(j, vy);
     568        zfield.define(j, vz);
     569    }
     570    // Figure out a good mesh spacing
     571    double dx, dy, dz;
     572    dx = xfield.rangeMax(Rappture::xaxis) - xfield.rangeMin(Rappture::xaxis);
     573    dy = xfield.rangeMax(Rappture::yaxis) - xfield.rangeMin(Rappture::yaxis);
     574    dz = xfield.rangeMax(Rappture::zaxis) - xfield.rangeMin(Rappture::zaxis);
     575
     576    double dmin;
     577    dmin = pow((dx*dy*dz)/(nSamples*nSamples*nSamples), 0.333);
     578   
     579    printf("dx:%lf dy:%lf dz:%lf dmin:%lf\n", dx, dy, dz, dmin);
     580
     581    /* Recompute new number of points for each axis. */
     582    _xNum = (size_t)ceil(dx/dmin);
     583    _yNum = (size_t)ceil(dy/dmin);
     584    _zNum = (size_t)ceil(dz/dmin);
     585   
     586#ifndef NV40
     587    // must be an even power of 2 for older cards
     588    _xNum = (int)pow(2.0, ceil(log10((double)_xNum)/log10(2.0)));
     589    _yNum = (int)pow(2.0, ceil(log10((double)_yNum)/log10(2.0)));
     590    _zNum = (int)pow(2.0, ceil(log10((double)_zNum)/log10(2.0)));
     591#endif
     592
     593    size_t n = _nComponents * _xNum * _yNum * _zNum;
     594    float *data = new float[n];
     595    memset(data, 0, sizeof(float) * n);
     596   
     597    // Generate the uniformly sampled rectangle that we need for a volume
     598    float *destPtr = data;
     599    for (size_t i = 0; i < _zNum; i++) {
     600        double z;
     601
     602        z = _zMin + (i * dmin);
     603        for (size_t j = 0; j < _yNum; j++) {
     604            double y;
     605               
     606            y = _yMin + (j * dmin);
     607            for (size_t k = 0; k < _xNum; k++) {
     608                double x;
     609
     610                x = _xMin + (k * dmin);
     611                destPtr[0] = xfield.value(x, y, z);
     612                destPtr[1] = yfield.value(x, y, z);
     613                destPtr[2] = zfield.value(x, y, z);
     614            }
     615        }
     616    }
     617    delete [] _values;
     618    _values = data;
     619    _nValues = _xNum * _yNum * _zNum * _nComponents;
     620    return true;
     621}
     622
  • trunk/packages/vizservers/nanovis/Unirect.h

    r1381 r1429  
    77
    88class Unirect3d {
    9     size_t xNum_, yNum_, zNum_;
    10     size_t nValues_;
    11     int extents_;
    12 
    13     float xMin_, xMax_;
    14     float yMin_, yMax_;
    15     float zMin_, zMax_;
    16     float vMin_, vMax_;
    17 
    18     char *xUnits_;
    19     char *yUnits_;
    20     char *zUnits_;
    21     char *vUnits_;
    22 
    23     float *values_;
    24     bool initialized_;
     9    size_t _xNum, _yNum, _zNum;
     10    size_t _nValues;
     11    size_t _nComponents;
     12    float _xMin, _xMax, _yMin, _yMax, _zMin, _zMax;
     13    float _xValueMin, _xValueMax;
     14    float _yValueMin, _yValueMax;
     15    float _zValueMin, _zValueMax;
     16    char *_xUnits;
     17    char *_yUnits;
     18    char *_zUnits;
     19    char *_vUnits;
     20
     21    float *_values;
     22    bool _initialized;
    2523
    2624public:
     
    2826              float yMin, float yMax, size_t yNum,
    2927              float zMin, float zMax, size_t zNum,
    30               size_t nValues, float *values) {
    31         xMax_ = xMax;
    32         xMin_ = xMin;
    33         xNum_ = xNum;
    34         yMax_ = yMax;
    35         yMin_ = yMin;
    36         yNum_ = yNum;
    37         zMax_ = zMax;
    38         zMin_ = zMin;
    39         zNum_ = zNum;
    40         nValues_ = nValues;
    41         values_ = values;
    42         initialized_ = true;
    43     }
    44 
    45     Unirect3d(void) {
    46         values_ = NULL;
    47         initialized_ = false;
    48         xNum_ = yNum_ = zNum_ = 0;
    49         nValues_ = 0;
    50         xUnits_ = yUnits_ = zUnits_ = vUnits_ = NULL;
     28              size_t nValues, float *values, size_t nComponents)
     29    {
     30        SetValues(xMin, xMax, xNum, yMin, yMax, yNum, zMin, zMax, zNum,
     31                  nValues, values, nComponents);
     32    }
     33
     34    Unirect3d(size_t nComponents = 1) {
     35        _values = NULL;
     36        _initialized = false;
     37        _xNum = _yNum = _zNum = 0;
     38        _nValues = 0;
     39        _xUnits = _yUnits = _zUnits = _vUnits = NULL;
     40        _nComponents = nComponents;
    5141    }
    5242    ~Unirect3d(void) {
    53         if (values_ != NULL) {
    54             delete [] values_;
    55         }
    56         if (xUnits_ != NULL) {
    57             free(xUnits_);
    58         }
    59         if (yUnits_ != NULL) {
    60             free(yUnits_);
    61         }
    62         if (zUnits_ != NULL) {
    63             free(zUnits_);
    64         }
    65         if (vUnits_ != NULL) {
    66             free(vUnits_);
    67         }
     43        if (_values != NULL) {
     44            delete [] _values;
     45        }
     46        if (_xUnits != NULL) {
     47            free(_xUnits);
     48        }
     49        if (_yUnits != NULL) {
     50            free(_yUnits);
     51        }
     52        if (_zUnits != NULL) {
     53            free(_zUnits);
     54        }
     55        if (_vUnits != NULL) {
     56            free(_vUnits);
     57        }
     58    }
     59    void SetValues(float xMin, float xMax, size_t xNum,
     60                   float yMin, float yMax, size_t yNum,
     61                   float zMin, float zMax, size_t zNum,
     62                   size_t nValues, float *values, size_t nComponents) {
     63        _xMax = xMax;
     64        _xMin = xMin;
     65        _xNum = xNum;
     66        _yMax = yMax;
     67        _yMin = yMin;
     68        _yNum = yNum;
     69        _zMax = zMax;
     70        _zMin = zMin;
     71        _zNum = zNum;
     72        _nValues = nValues;
     73        _values = values;
     74        _initialized = true;
     75        _nComponents = nComponents;
    6876    }
    6977    size_t xNum(void) {
    70         return xNum_;
     78        return _xNum;
    7179    }
    7280    size_t yNum(void) {
    73         return yNum_;
     81        return _yNum;
    7482    }
    7583    size_t zNum(void) {
    76         return zNum_;
     84        return _zNum;
    7785    }
    7886    float xMin(void) {
    79         return xMin_;
     87        return _xMin;
    8088    }
    8189    float yMin(void) {
    82         return yMin_;
     90        return _yMin;
    8391    }
    8492    float zMin(void) {
    85         return zMin_;
     93        return _zMin;
    8694    }
    8795    float xMax(void) {
    88         return xMax_;
     96        return _xMax;
    8997    }
    9098    float yMax(void) {
    91         return yMax_;
     99        return _yMax;
    92100    }
    93101    float zMax(void) {
    94         return zMax_;
     102        return _zMax;
     103    }
     104    float xValueMin(void) {
     105        return _xValueMin;
     106    }
     107    float yValueMin(void) {
     108        return _yValueMin;
     109    }
     110    float zValueMin(void) {
     111        return _zValueMin;
     112    }
     113    float xValueMax(void) {
     114        return _xValueMax;
     115    }
     116    float yValueMax(void) {
     117        return _yValueMax;
     118    }
     119    float zValueMax(void) {
     120        return _zValueMax;
     121    }
     122    size_t nComponents(void) {
     123        return _nComponents;
    95124    }
    96125    const char *xUnits(void) {
    97         return xUnits_;
     126        return _xUnits;
    98127    }
    99128    const char *yUnits(void) {
    100         return yUnits_;
     129        return _yUnits;
    101130    }
    102131    const char *zUnits(void) {
    103         return zUnits_;
     132        return _zUnits;
    104133    }
    105134    const char *vUnits(void) {
    106         return vUnits_;
     135        return _vUnits;
     136    }
     137    const float *values(void) {
     138        return _values;
     139    }
     140    const float *SaveValues(void) {
     141        float *values;
     142        values = _values;
     143        _values = NULL;
     144        _nValues = 0;
     145        return values;
     146    }
     147    size_t nValues(void) {
     148        return _nValues;
     149    }
     150    int LoadData(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv);
     151
     152    bool ReadVectorDataFromDx(Rappture::Outcome &result, size_t length,
     153        char *string);
     154    bool Resample(Rappture::Outcome &context, int nSamples = 30);
     155    bool isInitialized(void) {
     156        return _initialized;
     157    }
     158};
     159
     160class Unirect2d {
     161    size_t _xNum, _yNum;
     162    size_t _nValues;
     163    size_t _nComponents;
     164
     165    float _xMin, _xMax;
     166    float _yMin, _yMax;
     167    float _xValueMin, _xValueMax;
     168    float _yValueMin, _yValueMax;
     169
     170    char *_xUnits;
     171    char *_yUnits;
     172    char *_vUnits;
     173
     174    float *_values;
     175    bool _initialized;
     176
     177public:
     178    Unirect2d(size_t nComponents = 1) {
     179        _values = NULL;
     180        _initialized = false;
     181        _xNum = _yNum = 0;
     182        _nValues = 0;
     183        _xUnits = _yUnits = _vUnits = NULL;
     184        _nComponents = nComponents;
     185    }
     186    ~Unirect2d(void) {
     187        if (_values != NULL) {
     188            delete [] _values;
     189        }
     190        if (_xUnits != NULL) {
     191            free(_xUnits);
     192        }
     193        if (_yUnits != NULL) {
     194            free(_yUnits);
     195        }
     196        if (_vUnits != NULL) {
     197            free(_vUnits);
     198        }
     199    }
     200    size_t xNum(void) {
     201        return _xNum;
     202    }
     203    size_t yNum(void) {
     204        return _yNum;
     205    }
     206    float xMin(void) {
     207        return _xMin;
     208    }
     209    float yMin(void) {
     210        return _yMin;
     211    }
     212    float xMax(void) {
     213        return _xMax;
     214    }
     215    float yMax(void) {
     216        return _yMax;
     217    }
     218    const char *xUnits(void) {
     219        return _xUnits;
     220    }
     221    const char *yUnits(void) {
     222        return _yUnits;
     223    }
     224    const char *vUnits(void) {
     225        return _vUnits;
    107226    }
    108227    float *values(void) {
    109         return values_;
    110     }
    111     float *SaveValues(void) {
     228        return _values;
     229    }
     230    float *acceptValues(void) {
    112231        float *values;
    113         values = values_;
    114         values_ = NULL;
    115         nValues_ = 0;
     232        values = _values;
     233        _values = NULL;
     234        _nValues = 0;
    116235        return values;
    117236    }
    118237    size_t nValues(void) {
    119         return nValues_;
    120     }
    121     size_t extents(void) {
    122         return extents_;
    123     }
    124     void extents(size_t extents) {
    125         extents_ = extents;
     238        return _nValues;
    126239    }
    127240    int LoadData(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv);
    128241    bool isInitialized(void) {
    129         return initialized_;
     242        return _initialized;
    130243    }
    131244};
    132245
    133 class Unirect2d {
    134     size_t xNum_, yNum_;
    135     size_t nValues_;
    136     size_t extents_;
    137 
    138     float xMin_, xMax_;
    139     float yMin_, yMax_;
    140     float vMin_, vMax_;
    141 
    142     char *xUnits_;
    143     char *yUnits_;
    144     char *vUnits_;
    145 
    146     float *values_;
    147     bool initialized_;
    148 
    149 public:
    150     Unirect2d(void) {
    151         values_ = NULL;
    152         initialized_ = false;
    153         xNum_ = yNum_ = 0;
    154         nValues_ = 0;
    155         xUnits_ = yUnits_ = vUnits_ = NULL;
    156     }
    157     ~Unirect2d(void) {
    158         if (values_ != NULL) {
    159             delete [] values_;
    160         }
    161         if (xUnits_ != NULL) {
    162             free(xUnits_);
    163         }
    164         if (yUnits_ != NULL) {
    165             free(yUnits_);
    166         }
    167         if (vUnits_ != NULL) {
    168             free(vUnits_);
    169         }
    170     }
    171     size_t xNum(void) {
    172         return xNum_;
    173     }
    174     size_t yNum(void) {
    175         return yNum_;
    176     }
    177     float xMin(void) {
    178         return xMin_;
    179     }
    180     float yMin(void) {
    181         return yMin_;
    182     }
    183     float xMax(void) {
    184         return xMax_;
    185     }
    186     float yMax(void) {
    187         return yMax_;
    188     }
    189     const char *xUnits(void) {
    190         return xUnits_;
    191     }
    192     const char *yUnits(void) {
    193         return yUnits_;
    194     }
    195     const char *vUnits(void) {
    196         return vUnits_;
    197     }
    198     float *values(void) {
    199         return values_;
    200     }
    201     float *acceptValues(void) {
    202         float *values;
    203         values = values_;
    204         values_ = NULL;
    205         nValues_ = 0;
    206         return values;
    207     }
    208     size_t nValues(void) {
    209         return nValues_;
    210     }
    211     size_t extents(void) {
    212         return extents_;
    213     }
    214     void extents(size_t extents) {
    215         extents_ = extents;
    216     }
    217     int LoadData(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv);
    218     bool isInitialized(void) {
    219         return initialized_;
    220     }
    221 };
    222 
    223246}
    224247
  • trunk/packages/vizservers/nanovis/Volume.cpp

    r1370 r1429  
    4949    int fcount = width * height * depth * n_components;
    5050    _data = new float[fcount];
    51     if (data) {
     51    if (data != NULL) {
    5252        Trace("data is copied\n");
    5353        memcpy(_data, data, fcount * sizeof(float));
  • trunk/packages/vizservers/nanovis/VolumeRenderer.cpp

    r1374 r1429  
    8989}
    9090
     91/*
     92 * FIXME:  This is a good example of the wrong data structures being used.
     93 *         The volumes should be in a list not a vector.  Each list
     94 *         element should contain pointers to both the volume and the
     95 *         transfer function.  The shouldn't be parallel vectors. 
     96 *
     97 *         And there shouldn't be one vector for "all" volumes and another
     98 *         for those being rendered, unless you work to keep them in sync. 
     99 *         Use one master list instead.
     100 */
     101void
     102VolumeRenderer::remove_volume(size_t volIndex)
     103{
     104    vector<Volume *>::iterator vIter;
     105    vector<TransferFunction *>::iterator tfIter;
     106
     107    assert(volIndex < volume.size());
     108    assert(volIndex < tf.size());
     109
     110    vIter = volume.begin();
     111    tfIter = tf.begin();
     112    size_t i;
     113    for (i = 0; i < volIndex; i++) {
     114        tfIter++;
     115        vIter++;
     116    }
     117    volume.erase(vIter);
     118    tf.erase(tfIter);
     119    n_volumes--;
     120}
     121
    91122void
    92123VolumeRenderer::shade_volume(Volume* _vol, TransferFunction* _tf)
     
    177208
    178209    for(int vol_index = 0; vol_index< num_volumes; vol_index++) {
     210        cur_vol = NULL;
     211        cur_tf = NULL;
     212#ifdef notdef
    179213        if (vol_index != n_volumes) {
    180214            cur_vol = volume[vol_index];
     
    184218            cur_tf = ani_tf;
    185219        }
    186    
     220#else
     221        cur_vol = volume[vol_index];
     222        cur_tf = tf[vol_index];
     223#endif
     224
    187225        polys[vol_index] = NULL;
    188226        actual_slices[vol_index] = 0;
    189227
    190         if(!cur_vol->is_enabled())
     228        if(!cur_vol->is_enabled()) {
    191229            continue; //skip this volume
     230        }
    192231
    193232        int n_slices = cur_vol->get_n_slice();
  • trunk/packages/vizservers/nanovis/VolumeRenderer.h

    r1374 r1429  
    106106
    107107    int add_volume(Volume* _vol, TransferFunction* _tf);
     108    void remove_volume(size_t volIndex);
    108109    // add a volume and its transfer function
    109110    // we require a transfer function when a
  • trunk/packages/vizservers/nanovis/config.h

    r1370 r1429  
    3131#define PROTOTYPE               1
    3232
    33 //#define NEW_FLOW_ENGINE
     33#define NEW_FLOW_ENGINE         1
    3434
    3535/*
  • trunk/packages/vizservers/nanovis/dxReader.cpp

    r1384 r1429  
    162162    }
    163163    return new Rappture::Unirect3d(x0, x0 + dx * nx, nx, y0, y0 + dy * ny, ny,
    164                                    z0, z0 + dz * nz, nz, nValues, values);
     164                                   z0, z0 + dz * nz, nz, nValues, values, 3);
    165165}
    166166
    167167
     168#ifdef notdef
    168169/*
    169170 * Load a 3D vector field from a dx-format file
     
    363364    return true;
    364365}
     366#endif
    365367
    366368/* Load a 3D volume from a dx-format file
     
    744746    while (!fin.eof()) {
    745747        fin.getline(line, sizeof(line) - 1);
    746         fprintf(stderr, "line is %s\n", line);
    747748        if (fin.fail()) {
    748749            result.error("error in data stream");
     
    840841        }
    841842    }
    842     fprintf(stderr, "found nx=%d ny=%d, nz=%d, x0=%f, y0=%f, z0=%f\n",
    843             nx, ny, nz, x0, y0, z0);
    844843    // read data points
    845844    if (fin.eof()) {
     
    869868                int nindex = iz*nx*ny + iy*nx + ix;
    870869                field.define(nindex, dval[p]);
    871                 fprintf(stderr,"nindex = %i\tdval[%i] = %lg\n", nindex, p,
    872                         dval[p]);
    873870                fflush(stderr);
    874871                nread++;
     
    11771174    while (!fin.eof()) {
    11781175        fin.getline(line, sizeof(line) - 1);
    1179         fprintf(stderr, "line is %s\n", line);
    11801176        if (fin.fail()) {
    11811177            result.addError("line \"%s\"error in data stream");
     
    12731269    }
    12741270
    1275     fprintf(stderr, "found nx=%d ny=%d, nz=%d, x0=%f, y0=%f, z0=%f\n",
    1276             nx, ny, nz, x0, y0, z0);
    12771271    // read data points
    12781272    if (fin.eof()) {
  • trunk/packages/vizservers/nanovis/nanovis.cpp

    r1381 r1429  
    6969#include <R2/R2Fonts.h>
    7070
     71#include "Unirect.h"
     72#include "Switch.h"
     73#include "FlowCmd.h"
     74
    7175#define SIZEOF_BMP_HEADER   54
    7276
     
    126130FILE *NanoVis::recfile = NULL;
    127131
    128 bool NanoVis::lic_on = false;
    129 bool NanoVis::particle_on = false;
    130 bool NanoVis::vector_on = false;
    131132bool NanoVis::axis_on = true;
    132133bool NanoVis::config_pending = false;
    133134bool NanoVis::debug_flag = false;
    134 bool NanoVis::lic_slice_x_visible = false;
    135 bool NanoVis::lic_slice_y_visible = false;
    136 bool NanoVis::lic_slice_z_visible = false;
    137135
    138136Tcl_Interp *NanoVis::interp;
     
    427425    int result;
    428426
     427#ifdef notdef
    429428    if (NanoVis::debug_flag) {
    430429        fprintf(stderr, "in ExecuteCommand(%s)\n", Tcl_DStringValue(dsPtr));
    431430    }
    432 
     431#endif
    433432    gettimeofday(&tv, NULL);
    434433    start = CVT2SECS(tv);
    435434
     435#ifdef notdef
    436436    if (NanoVis::logfile != NULL) {
    437437        fprintf(NanoVis::logfile, "%s", Tcl_DStringValue(dsPtr));
    438438        fflush(NanoVis::logfile);
    439439    }
     440#endif
    440441    if (NanoVis::recfile != NULL) {
    441442        fprintf(NanoVis::recfile, "%s", Tcl_DStringValue(dsPtr));
     
    450451    stats.cmdTime += finish - start;
    451452    stats.nCommands++;
     453#ifdef notdef
    452454    if (NanoVis::debug_flag) {
    453455        fprintf(stderr, "leaving ExecuteCommand status=%d\n", result);
    454456    }
     457#endif
    455458    return result;
    456459}
     
    506509    volume[index] = new Volume(0.f, 0.f, 0.f, width, height, depth, 1.,
    507510                               n_component, data, vmin, vmax, nzero_min);
     511    fprintf(stderr, "VOLINDEX=%d, n_volumes=%d\n", index, n_volumes);
    508512    return volume[index];
    509513}
     
    665669    }
    666670   
    667     if (screen_buffer) {
    668         delete[] screen_buffer;
     671    if (screen_buffer != NULL) {
     672        delete [] screen_buffer;
    669673        screen_buffer = NULL;
    670674    }
     
    827831
    828832
    829 #if PROTOTYPE
    830     licRenderer = new NvLIC(NMESH, NPIX, NPIX, lic_axis, Vector3(lic_slice_x, lic_slice_y, lic_slice_z), g_context);
    831 #endif
     833    licRenderer = new NvLIC(NMESH, NPIX, NPIX, lic_axis,
     834                            Vector3(lic_slice_x, lic_slice_y, lic_slice_z),
     835                            g_context);
    832836
    833837    ImageLoaderFactory::getInstance()->addLoaderImpl("bmp", new BMPImageLoaderImpl());
     
    835839    grid->setFont(fonts);
    836840
     841#ifdef notdef
    837842    pointset_renderer = new PointSetRenderer();
     843#endif
    838844}
    839845
     
    10411047            sprintf(filename, "/tmp/flow_animation/image%03d.bmp", frame_number);
    10421048
    1043         printf("Writing %s\n", filename);
     1049        fprintf(stderr, "Writing %s\n", filename);
    10441050        f = fopen(filename, "wb");
    10451051        if (f == 0) {
     
    10521058        }
    10531059    }
    1054     ssize_t nWritten;
    1055     nWritten = fwrite(header, SIZEOF_BMP_HEADER, 1, f);
    1056     assert(nWritten == SIZEOF_BMP_HEADER);
    1057     nWritten = fwrite(screen_buffer, (3*win_width+pad)*win_height, 1, f);
    1058     assert(nWritten == (3*win_width+pad)*win_height);
     1060    if (fwrite(header, SIZEOF_BMP_HEADER, 1, f) != 1) {
     1061        Trace("can't write header: short write\n");
     1062    }
     1063    if (fwrite(screen_buffer, (3*win_width+pad)*win_height, 1, f) != 1) {
     1064        Trace("can't write data: short write\n");
     1065    }
    10591066    fclose(f);
    10601067}
     
    16331640        fprintf(stderr, "in display\n");
    16341641    }
     1642
     1643    if (FlowCmd::flags & FlowCmd::MAP_PENDING) {
     1644        FlowCmd::MapFlows();
     1645    }
    16351646    //assert(glGetError()==0);
    16361647    if (HeightMap::update_pending) {
     
    17011712        if ((licRenderer != NULL) && (licRenderer->isActivated())) {
    17021713            licRenderer->render();
    1703         }
    1704 
     1714            /*FlowCmd::SetupFlows();*/
     1715        }
     1716#ifdef notdef
    17051717        if ((flowVisRenderer != NULL) && (flowVisRenderer->isActivated())) {
    17061718            flowVisRenderer->render();
     1719        }
     1720#endif
     1721        if (FlowCmd::flags & FlowCmd::REDRAW_PENDING) {
     1722            FlowCmd::RenderFlows();
    17071723        }
    17081724
     
    17321748        perf->disable();
    17331749    }
    1734 
    17351750    perf->reset();
    17361751    if (debug_flag) {
    17371752        fprintf(stderr, "leaving display\n");
    17381753    }
     1754
    17391755
    17401756}
     
    19231939                break;
    19241940        case '5' :
    1925                 {
    1926                         printf("vector field deleted (vf_name2)\n");
     194186              {
     1942a                       printf("vector field deleted (vf_name2)\n");
    19271943                        NanoVis::flowVisRenderer->removeVectorField("vf_name2");
    19281944                }
     
    20632079    int status = TCL_OK;
    20642080
    2065     //
    20662081    //  Read and execute as many commands as we can from stdin...
    2067     //
     2082
    20682083    bool isComplete = false;
    2069     while (status == TCL_OK) {
     2084    while ((!feof(NanoVis::stdin)) && (status == TCL_OK)) {
    20702085        //
    20712086        //  Read the next command from the buffer.  First time through we
     
    20882103                    break;
    20892104                }
    2090                 DoExit(0);
     2105                DoExit(100);
    20912106            }
    20922107            ch = (char)c;
     
    21032118            break;
    21042119        }
    2105 
    21062120        if (isComplete) {
    21072121            // back to original flags during command evaluation...
     
    21672181#endif
    21682182    if (feof(NanoVis::stdin)) {
    2169         DoExit(0);
     2183        DoExit(90);
    21702184    }
    21712185    if (debug_flag) {
     
    23362350
    23372351    glutMainLoop();
    2338     DoExit(0);
     2352    DoExit(80);
    23392353}
    23402354
  • trunk/packages/vizservers/nanovis/nanovis.h

    r1370 r1429  
    137137    static float lic_slice_y;
    138138    static float lic_slice_z;
    139     static bool lic_slice_x_visible;
    140     static bool lic_slice_y_visible;
    141     static bool lic_slice_z_visible;
    142139    static int lic_axis;        /* 0:x, 1:y, 2:z */
    143140
     
    149146
    150147    static bool debug_flag;
    151     static bool lic_on;
    152     static bool particle_on;
    153     static bool vector_on;
    154148
    155149    static Tcl_Interp *interp;
Note: See TracChangeset for help on using the changeset viewer.