Changeset 1493 for trunk


Ignore:
Timestamp:
Jun 8, 2009 8:31:59 AM (15 years ago)
Author:
gah
Message:

Changed vector id to name

Location:
trunk/packages/vizservers/nanovis
Files:
20 edited

Legend:

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

    r1484 r1493  
    9191extern Texture2D* plane[10];
    9292
    93 extern bool load_volume_stream(Rappture::Outcome &status, int index,
    94                         std::iostream& fin);
    95 extern bool load_volume_stream_odx(Rappture::Outcome &status, int index,
    96         const char *buf, int nBytes);
    97 extern bool load_volume_stream2(Rappture::Outcome &status, int index,
    98         std::iostream& fin);
    99 
    100 extern bool load_vector_stream(Rappture::Outcome &result, int index,
    101         size_t length, char *bytes);
    102 extern bool load_vector_stream2(Rappture::Outcome &result, int index,
    103         size_t length, char *bytes);
    104 extern bool MakeVectorFieldFromUnirect3d(Rappture::Outcome &result,
    105         Rappture::Unirect3d &data);
    106 
    107 extern void load_volume(int index, int width, int height, int depth,
    108             int n_component, float* data, double vmin, double vmax,
    109             double nzero_min);
    11093// Tcl interpreter for incoming messages
    11194
     
    301284    hmPtr = new HeightMap();
    302285    hmPtr->setHeight(xMin, yMin, xMax, yMax, xNum, yNum, heights);
    303     hmPtr->setColorMap(NanoVis::get_transfunc("default"));
     286    hmPtr->transferFunction(NanoVis::get_transfunc("default"));
    304287    hmPtr->setVisible(true);
    305288    hmPtr->setLineContourVisible(true);
     
    353336    hmPtr = NanoVis::heightMap[index];
    354337    if (hmPtr == NULL) {
    355         Tcl_AppendResult(interp, "no heightmap defined for index \"",
    356                          Tcl_GetString(objPtr), "\"", (char*)NULL);
    357         return TCL_ERROR;
     338        if (interp != NULL) {
     339            Tcl_AppendResult(interp, "no heightmap defined for index \"",
     340                             Tcl_GetString(objPtr), "\"", (char*)NULL);
     341        }
     342        return TCL_ERROR;
    358343    }
    359344    *hmPtrPtr = hmPtr;
     
    361346}
    362347
     348
    363349/*
    364350 * ----------------------------------------------------------------------
    365  * FUNCTION: GetVolumeDataID
     351 * FUNCTION: GetVolumeFromObj
    366352 *
    367353 * Used internally to decode a series of volume index values and
     
    375361 */
    376362static int
    377 GetVolumeIndex(Tcl_Interp *interp, Tcl_Obj *objPtr, unsigned int *idPtr)
    378 {
    379     int index;
    380     if (Tcl_GetIntFromObj(interp, objPtr, &index) != TCL_OK) {
    381         return TCL_ERROR;
    382     }
    383     if (index < 0) {
    384         Tcl_AppendResult(interp, "can't have negative index \"",
    385                          Tcl_GetString(objPtr), "\"", (char*)NULL);
    386         return TCL_ERROR;
    387     }
    388     if (index >= (int)NanoVis::volumes.size()) {
    389         Tcl_AppendResult(interp, "index \"", Tcl_GetString(objPtr),
    390                          "\" is out of range", (char*)NULL);
    391         return TCL_ERROR;
    392     }
    393     if (NanoVis::volumes[index] == NULL) {
    394         Tcl_AppendResult(interp, "can't find volume \"", Tcl_GetString(objPtr),
    395                      "\"", (char*)NULL);
    396         return TCL_ERROR;
    397     }
    398     *idPtr = (unsigned int)index;
     363GetVolumeFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, Volume **volPtrPtr)
     364{
     365    const char *string;
     366    string = Tcl_GetString(objPtr);
     367
     368    Tcl_HashEntry *hPtr;
     369    hPtr = Tcl_FindHashEntry(&NanoVis::volumeTable, string);
     370    if (hPtr == NULL) {
     371        if (interp != NULL) {
     372            Tcl_AppendResult(interp, "can't find a volume name \"",
     373                         string, "\"", (char*)NULL);
     374        }
     375        return TCL_ERROR;
     376    }
     377    *volPtrPtr = (Volume *)Tcl_GetHashValue(hPtr);
    399378    return TCL_OK;
    400379}
     
    402381/*
    403382 * ----------------------------------------------------------------------
    404  * FUNCTION: GetVolumeFromObj
     383 * FUNCTION: GetVolumes()
    405384 *
    406385 * Used internally to decode a series of volume index values and
     
    414393 */
    415394static int
    416 GetVolumeFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, Volume **volPtrPtr)
    417 {
    418     unsigned int index;
    419     if (GetVolumeIndex(interp, objPtr, &index) != TCL_OK) {
    420         return TCL_ERROR;
    421     }
    422     Volume *volPtr;
    423     volPtr = NanoVis::volumes[index];
    424     if (volPtr == NULL) {
    425         Tcl_AppendResult(interp, "no volume defined for index \"",
    426                          Tcl_GetString(objPtr), "\"", (char*)NULL);
    427         return TCL_ERROR;
    428     }
    429     *volPtrPtr = volPtr;
    430     return TCL_OK;
    431 }
    432 
    433 /*
    434  * ----------------------------------------------------------------------
    435  * FUNCTION: GetVolumeIndices()
    436  *
    437  * Used internally to decode a series of volume index values and
    438  * store then in the specified vector.  If there are no volume index
    439  * arguments, this means "all volumes" to most commands, so all
    440  * active volume indices are stored in the vector.
    441  *
    442  * Updates pushes index values into the vector.  Returns TCL_OK or
    443  * TCL_ERROR to indicate an error.
    444  * ----------------------------------------------------------------------
    445  */
    446 static int
    447 GetVolumeIndices(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv,
    448                  vector<unsigned int>* vectorPtr)
    449 {
    450     if (objc == 0) {
    451         vector<Volume *>::iterator iter;
    452         for (iter = NanoVis::volumes.begin(); iter != NanoVis::volumes.end();
    453              ++iter) {
    454             if ((*iter) != NULL) {
    455                 vectorPtr->push_back((*iter)->dataID());
    456             }
    457         }
    458     } else {
    459         vector<Volume *>::iterator iter;
    460         for (int n = 0; n < objc; n++) {
    461             unsigned int index;
    462 
    463             if (GetVolumeIndex(interp, objv[n], &index) != TCL_OK) {
    464                 return TCL_ERROR;
    465             }
    466             if (NanoVis::volumes[index] != NULL) {
    467                 vectorPtr->push_back(index);
    468             }
    469         }
    470     }
    471     return TCL_OK;
    472 }
    473 
    474 /*
    475  * ----------------------------------------------------------------------
    476  * FUNCTION: GetVolumes()
    477  *
    478  * Used internally to decode a series of volume index values and
    479  * store then in the specified vector.  If there are no volume index
    480  * arguments, this means "all volumes" to most commands, so all
    481  * active volume indices are stored in the vector.
    482  *
    483  * Updates pushes index values into the vector.  Returns TCL_OK or
    484  * TCL_ERROR to indicate an error.
    485  * ----------------------------------------------------------------------
    486  */
    487 static int
    488395GetVolumes(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv,
    489396           vector<Volume *>* vectorPtr)
     
    491398    if (objc == 0) {
    492399        // No arguments. Get all volumes.
    493         vector<Volume *>::iterator iter;
    494         for (iter = NanoVis::volumes.begin(); iter != NanoVis::volumes.end();
    495              ++iter) {
    496             if ((*iter) != NULL) {
    497                 vectorPtr->push_back((*iter));
    498             }
    499         }
     400        Tcl_HashSearch iter;
     401        Tcl_HashEntry *hPtr;
     402        for (hPtr = Tcl_FirstHashEntry(&NanoVis::volumeTable, &iter);
     403             hPtr != NULL; hPtr = Tcl_NextHashEntry(&iter)) {
     404            Volume *volPtr;
     405            volPtr = (Volume *)Tcl_GetHashValue(hPtr);
     406            vectorPtr->push_back(volPtr);
     407        }
    500408    } else {
    501409        // Get the volumes associated with the given index arguments.
     
    947855    }
    948856
    949     const char *string = Tcl_GetString(objv[1]);
     857    const char *name;
     858    name = Tcl_GetString(objv[1]);
    950859    TransferFunction *tf;
    951     tf = NanoVis::get_transfunc(string);
     860    tf = NanoVis::get_transfunc(name);
    952861    if (tf == NULL) {
    953         Tcl_AppendResult(interp, "unknown transfer function \"", string, "\"",
     862        Tcl_AppendResult(interp, "unknown transfer function \"", name, "\"",
    954863                             (char*)NULL);
    955864        return TCL_ERROR;
    956865    }
    957     const char *label;
    958     label = Tcl_GetString(objv[1]);
    959866    int w, h;
    960867    if ((Tcl_GetIntFromObj(interp, objv[2], &w) != TCL_OK) ||
     
    965872        NanoVis::SetVolumeRanges();
    966873    }
    967     NanoVis::render_legend(tf, Volume::valueMin, Volume::valueMax, w, h, label);
     874    NanoVis::render_legend(tf, Volume::valueMin, Volume::valueMax, w, h, name);
    968875    return TCL_OK;
    969876}
     
    12011108    }
    12021109    Trace("parsing volume data identifier\n");
    1203     vector<Volume *>::iterator iter;
    1204     for (iter = volumes.begin(); iter != volumes.end(); iter++) {
    1205         Trace("volDataID: %d\n", (*iter)->dataID());
    1206         NanoVis::vol_renderer->addAnimatedVolume((*iter));
     1110    Tcl_HashSearch iter;
     1111    Tcl_HashEntry *hPtr;
     1112    for (hPtr = Tcl_FirstHashEntry(&NanoVis::volumeTable, &iter); hPtr != NULL;
     1113         hPtr = Tcl_NextHashEntry(&iter)) {
     1114        Volume *volPtr;
     1115        volPtr = (Volume *)Tcl_GetHashValue(hPtr);
     1116        NanoVis::vol_renderer->addAnimatedVolume(volPtr);
    12071117    }
    12081118    return TCL_OK;
     
    12721182    fflush(stdout);
    12731183
    1274     Volume *volPtr = 0;
    1275     int volDataID = -1;
    1276     if (strcmp(header, "<HDR>") == 0) {
     1184    Volume *volPtr;
     1185    volPtr = NULL;                      // Supress compiler warning.
     1186    if (strncmp(header, "<HDR>", 5) == 0) {
    12771187        printf("ZincBlende stream is in\n");
    12781188        fflush(stdout);
    1279         //std::stringstream fdata(std::ios_base::out|std::ios_base::in|std::ios_base::binary);
     1189         //std::stringstream fdata(std::ios_base::out|std::ios_base::in|std::ios_base::binary);
    12801190        //fdata.write(buf.bytes(),buf.size());
    12811191        //vol = NvZincBlendeReconstructor::getInstance()->loadFromStream(fdata);
     
    12881198        if (volPtr == NULL) {
    12891199            Tcl_AppendResult(interp, "can't get volume instance", (char *)NULL);
    1290             return TCL_OK;
     1200            return TCL_ERROR;
    12911201        }
    12921202        printf("finish loading\n");
     
    12951205        // INSOO
    12961206        // TBD..
    1297         volDataID = NanoVis::volumes.size();  // Next identifier available
     1207        // Next identifier available
    12981208        float dx0 = -0.5;
    12991209        float dy0 = -0.5*volPtr->height/volPtr->width;
    13001210        float dz0 = -0.5*volPtr->depth/volPtr->width;
    13011211        volPtr->location(Vector3(dx0, dy0, dz0));
    1302         volPtr->dataID(volDataID);
    1303         NanoVis::volumes.push_back(volPtr);
     1212        int isNew;
     1213        Tcl_HashEntry *hPtr;
     1214        hPtr = Tcl_CreateHashEntry(&NanoVis::volumeTable, tag, &isNew);
     1215        if (!isNew) {
     1216            Tcl_AppendResult(interp, "volume \"", tag, "\" already exists.",
     1217                             (char *)NULL);
     1218            return TCL_ERROR;
     1219        }
     1220        Tcl_SetHashValue(hPtr, volPtr);
     1221        volPtr->name(Tcl_GetHashKey(&NanoVis::volumeTable, hPtr));
    13041222#if __TEST_CODE__
    1305     } else if (strcmp(header, "<FET>") == 0) {
     1223    } else if (strncmp(header, "<FET>", 5) == 0) {
    13061224        printf("FET loading...\n");
    13071225        fflush(stdout);
    13081226        std::stringstream fdata;
    13091227        fdata.write(buf.bytes(),buf.size());
    1310         if (!load_volume_stream3(err, n, fdata)) {
     1228        volPtr = load_volume_stream3(err, tag, fdata);
     1229        if (volPtr == NULL) {
    13111230            Tcl_AppendResult(interp, err.remark(), (char*)NULL);
    13121231            return TCL_ERROR;
    13131232        }
    13141233#endif  /*__TEST_CODE__*/
    1315     } else if (strcmp(header, "<ODX>") == 0) {
     1234    } else if (strncmp(header, "<ODX>", 5) == 0) {
    13161235        /*
    13171236        Rappture::Outcome err;
     
    13191238        printf("Loading DX using OpenDX library...\n");
    13201239        fflush(stdout);
    1321         if (!load_volume_stream_odx(err, n, buf.bytes()+5, buf.size()-5)) {
     1240        volPtr = load_volume_stream_odx(err, n, buf.bytes()+5, buf.size()-5);
     1241        if (volPtr == NULL) {
    13221242            Tcl_AppendResult(interp, err.remark(), (char*)NULL);
    13231243            return TCL_ERROR;
     
    13251245        */
    13261246    } else {
    1327         printf("test\n");
    1328 #ifdef notdef
    1329         Rappture::Unirect3d *dataPtr;
    1330 
    1331         dataPtr = new Rappture::Unirect3d(1);
    1332         if (!dataPtr->ImportDx(result, 1, buf.size(), (char *)buf.bytes())) {
    1333             Tcl_AppendResult(interp, result.remark(), (char *)NULL);
    1334             delete dataPtr;
    1335             return TCL_ERROR;
    1336         }
    1337 #if !ISO_TEST
    1338         dataPtr->Resample(context, 30);
    1339 #endif
    1340         volPtr = NanoVis::load_volume(-1, nx, ny, nz, 4, data, vmin, vmax,
    1341                                       nzero_min);
    1342    
    1343         volPtr->xAxis.SetRange(dataPtr->xMin(), dataPtr->xMin() + (nx * dx));
    1344         volPtr->yAxis.SetRange(dataPtr->yMin(), dataPtr->yMin() + (ny * dy));
    1345         volPtr->zAxis.SetRange(dataPtr->zMin(), dataPtr->zMin() + (nz * dz));
    1346         volPtr->wAxis.SetRange(vmin, vmax);
    1347         volPtr->update_pending = true;
    1348        
    1349         flowPtr->SetData(dataPtr);
    1350 #endif
    13511247        printf("OpenDX loading...\n");
    13521248        fflush(stdout);
    13531249        std::stringstream fdata;
    1354         fdata.write(buf.bytes(),buf.size());
     1250        fdata.write(buf.bytes(), buf.size());
    13551251        if (buf.size() <= 0) {
    13561252            fprintf(stderr, "data buffer is empty\n");
    13571253            abort();
    13581254        }
    1359         bool result;
    13601255        Rappture::Outcome context;
    13611256#if ISO_TEST
    1362         result = load_volume_stream2(context, volPtr->dataID(), fdata);
     1257        volPtr = load_volume_stream2(context, tag, fdata);
    13631258#else
    1364         result = load_volume_stream(context, volPtr->dataID(), fdata);
     1259        volPtr = load_volume_stream(context, tag, fdata);
    13651260#endif
    1366         if (!result) {
     1261        if (volPtr == NULL) {
    13671262            Tcl_AppendResult(interp, context.remark(), (char*)NULL);
    13681263            return TCL_ERROR;
     
    13791274        //volPtr->n_slices(512-n);
    13801275        //volPtr->n_slices(256-n);
    1381         volPtr->n_slices(256);
    13821276        volPtr->disable_cutplane(0);
    13831277        volPtr->disable_cutplane(1);
     
    13941288
    13951289        // FIXME: strlen(info) is the return value of sprintf
    1396         sprintf(info, "nv>data tag %s id %d min %g max %g vmin %g vmax %g\n",
    1397                 tag, volDataID, volPtr->wAxis.min(), volPtr->wAxis.max(),
     1290        sprintf(info, "nv>data tag %s min %g max %g vmin %g vmax %g\n", tag,
     1291                volPtr->wAxis.min(), volPtr->wAxis.max(),
    13981292                Volume::valueMin, Volume::valueMax);
    13991293        nWritten  = write(0, info, strlen(info));
     
    14401334    }
    14411335    return (*proc) (clientData, interp, objc, objv);
     1336}
     1337
     1338/*
     1339 *---------------------------------------------------------------------------
     1340 *
     1341 * VolumeDeleteOp --
     1342 *
     1343 *---------------------------------------------------------------------------
     1344 */
     1345/*ARGSUSED*/
     1346static int
     1347VolumeDeleteOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1348               Tcl_Obj *const *objv)
     1349{
     1350    int i;
     1351
     1352    for (i = 2; i < objc; i++) {
     1353        Volume *volPtr;
     1354
     1355        if (GetVolumeFromObj(interp, objv[i], &volPtr) != TCL_OK) {
     1356            return TCL_ERROR;
     1357        }
     1358        NanoVis::remove_volume(volPtr);
     1359    }
     1360    NanoVis::EventuallyRedraw();
     1361    return TCL_OK;
     1362}
     1363
     1364/*
     1365 *---------------------------------------------------------------------------
     1366 *
     1367 * VolumeExistsOp --
     1368 *
     1369 *---------------------------------------------------------------------------
     1370 */
     1371/*ARGSUSED*/
     1372static int
     1373VolumeExistsOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1374               Tcl_Obj *const *objv)
     1375{
     1376    bool value;
     1377    Volume *volPtr;
     1378
     1379    value = false;
     1380    if (GetVolumeFromObj(NULL, objv[2], &volPtr) == TCL_OK) {
     1381        value = true;
     1382    }
     1383    Tcl_SetBooleanObj(Tcl_GetObjResult(interp), (int)value);
     1384    return TCL_OK;
     1385}
     1386
     1387/*
     1388 *---------------------------------------------------------------------------
     1389 *
     1390 * VolumeNamesOp --
     1391 *
     1392 *---------------------------------------------------------------------------
     1393 */
     1394/*ARGSUSED*/
     1395static int
     1396VolumeNamesOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1397              Tcl_Obj *const *objv)
     1398{
     1399    Tcl_Obj *listObjPtr;
     1400    listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL);
     1401    Tcl_HashEntry *hPtr;
     1402    Tcl_HashSearch iter;
     1403    for (hPtr = Tcl_FirstHashEntry(&NanoVis::volumeTable, &iter); hPtr != NULL;
     1404         hPtr = Tcl_NextHashEntry(&iter)) {
     1405        Volume *volPtr;
     1406        volPtr = (Volume *)Tcl_GetHashValue(hPtr);
     1407        Tcl_Obj *objPtr;
     1408        objPtr = Tcl_NewStringObj(volPtr->name(), -1);
     1409        Tcl_ListObjAppendElement(interp, listObjPtr, objPtr);
     1410    }
     1411    Tcl_SetObjResult(interp, listObjPtr);
     1412    return TCL_OK;
    14421413}
    14431414
     
    15851556                         Tcl_Obj *const *objv)
    15861557{
    1587     TransferFunction *tf;
     1558    TransferFunction *tfPtr;
    15881559    const char *name = Tcl_GetString(objv[3]);
    1589     tf = NanoVis::get_transfunc(name);
    1590     if (tf == NULL) {
     1560    tfPtr = NanoVis::get_transfunc(name);
     1561    if (tfPtr == NULL) {
    15911562        Tcl_AppendResult(interp, "transfer function \"", name,
    15921563                         "\" is not defined", (char*)NULL);
     
    15991570    vector<Volume *>::iterator iter;
    16001571    for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    1601         (*iter)->transferFunction(tf);
     1572        Trace("setting %s with transfer function %s\n", (*iter)->name(),
     1573              tfPtr->name());
     1574        (*iter)->transferFunction(tfPtr);
    16021575#ifdef POINTSET
    16031576        // TBD..
     
    16871660             Tcl_Obj *const *objv)
    16881661{
    1689     Volume *volPtr;
    1690     size_t i;
    1691    
    1692     volPtr = NULL;
    16931662    // Find the first volume in the vector.
    1694     for (i = 0; i < NanoVis::volumes.size(); i++) {
    1695         if (NanoVis::volumes[i] != NULL) {
    1696             volPtr = NanoVis::volumes[i];
    1697             break;
    1698         }
    1699     }
    1700     if (volPtr != NULL) {
     1663    Tcl_HashEntry *hPtr;
     1664    Tcl_HashSearch iter;
     1665    hPtr = Tcl_FirstHashEntry(&NanoVis::volumeTable, &iter);
     1666    if (hPtr != NULL) {
     1667        Volume *volPtr;
     1668        volPtr = (Volume *)Tcl_GetHashValue(hPtr);
    17011669        volPtr->data_enabled(false);
    17021670        volPtr->visible(false);
     
    17081676    {"animation", 2, VolumeAnimationOp,   3, 0, "oper ?args?",},
    17091677    {"axis",      2, VolumeAxisOp,        4, 0, "label axis value ?indices?",},
    1710     {"data",      1, VolumeDataOp,        3, 0, "oper ?args?",},
     1678    {"data",      2, VolumeDataOp,        3, 0, "oper ?args?",},
     1679    {"delete",    2, VolumeDeleteOp,      3, 0, "?name...?",},
     1680    {"exists",    1, VolumeExistsOp,      3, 3, "name",},
     1681    {"names",     1, VolumeNamesOp,       2, 3, "?pattern?",},
    17111682    {"outline",   1, VolumeOutlineOp,     3, 0, "oper ?args?",},
    17121683    {"shading",   2, VolumeShadingOp,     3, 0, "oper ?args?",},
     
    17511722// ============================= FLOW ==================================
    17521723
    1753 static int
    1754 FlowDataFollowsOp(ClientData clientData, Tcl_Interp *interp, int objc,
    1755                     Tcl_Obj *const *objv)
    1756 {
    1757     Rappture::Outcome result;
    1758 
    1759     Trace("Flow Data Loading\n");
    1760 
    1761     int nbytes;
    1762     if (Tcl_GetIntFromObj(interp, objv[3], &nbytes) != TCL_OK) {
    1763         return TCL_ERROR;
    1764     }
    1765     int extents;
    1766     if (Tcl_GetIntFromObj(interp, objv[4], &extents) != TCL_OK) {
    1767         return TCL_ERROR;
    1768     }
    1769 
    1770     Rappture::Buffer buf;
    1771     if (GetDataStream(interp, buf, nbytes) != TCL_OK) {
    1772         return TCL_ERROR;
    1773     }
    1774     int n = NanoVis::n_volumes;
    1775     if (strncmp(buf.bytes(), "<DX>", 4) == 0) {
    1776         if (!load_vector_stream2(result, n, buf.size(), (char *)buf.bytes())) {
    1777             Tcl_AppendResult(interp, result.remark(), (char *)NULL);
    1778             return TCL_ERROR;
    1779         }
    1780 #ifdef notdef
    1781     } else if (strncmp(buf.bytes(), "<unirect3d>", 4) == 0) {
    1782 
    1783         Rappture::Unirect3d data;
    1784         Tcl_CmdInfo cmdInfo;
    1785 
    1786         /* Set the clientdata field of the unirect3d command to contain
    1787          * the local data structure. */
    1788         if (!Tcl_GetCommandInfo(interp, "unirect3d", &cmdInfo)) {
    1789             return TCL_ERROR;
    1790         }
    1791         data.extents(extents);
    1792         cmdInfo.objClientData = (ClientData)&data;     
    1793         Tcl_SetCommandInfo(interp, "unirect3d", &cmdInfo);
    1794         if (Tcl_Eval(interp, (const char *)buf.bytes()) != TCL_OK) {
    1795             return TCL_ERROR;
    1796         }
    1797         if (!data.isInitialized()) {
    1798             return TCL_ERROR;
    1799         }
    1800         if (!MakeVectorFieldFromUnirect3d(result, data)) {
    1801             Tcl_AppendResult(interp, result.remark(), (char *)NULL);
    1802             return TCL_ERROR;
    1803         }
    1804 #endif
    1805     }
    1806 
    1807     Volume *volPtr = NanoVis::volume[NanoVis::n_volumes];
    1808     //
    1809     // BE CAREFUL:  Set the number of slices to something
    1810     //   slightly different for each volume.  If we have
    1811     //   identical volumes at exactly the same position
    1812     //   with exactly the same number of slices, the second
    1813     //   volume will overwrite the first, so the first won't
    1814     //   appear at all.
    1815     //
    1816     volPtr->set_n_slice(256-n);
    1817     // volPtr->set_n_slice(512-n);
    1818     volPtr->disable_cutplane(0);
    1819     volPtr->disable_cutplane(1);
    1820     volPtr->disable_cutplane(2);
    1821     volPtr->transferFunction(NanoVis::get_transfunc("default"));
    1822 
    1823     float dx0 = -0.5;
    1824     float dy0 = -0.5*volPtr->height/volPtr->width;
    1825     float dz0 = -0.5*volPtr->depth/volPtr->width;
    1826     volPtr->move(Vector3(dx0, dy0, dz0));
    1827     return TCL_OK;
    1828 }
    1829 
    1830 static Rappture::CmdSpec flowDataOps[] = {
    1831     {"follows",   1, FlowDataFollowsOp, 4, 4, "size",},
    1832 };
    1833 static int nFlowDataOps = NumCmdSpecs(flowDataOps);
    1834 
    1835 static int
    1836 FlowDataOp(ClientData clientData, Tcl_Interp *interp, int objc,
    1837              Tcl_Obj *const *objv)
    1838 {
    1839     Tcl_ObjCmdProc *proc;
    1840 
    1841     proc = Rappture::GetOpFromObj(interp, nFlowDataOps, flowDataOps,
    1842                                   Rappture::CMDSPEC_ARG2, objc, objv, 0);
    1843     if (proc == NULL) {
    1844         return TCL_ERROR;
    1845     }
    1846     return (*proc) (clientData, interp, objc, objv);
    1847 }
    18481724
    18491725// INSOO
     
    22902166    hmPtr->setHeight(grid.xMin(), grid.yMin(), grid.xMax(), grid.yMax(),
    22912167                     grid.xNum(), grid.yNum(), grid.acceptValues());
    2292     hmPtr->setColorMap(NanoVis::get_transfunc("default"));
     2168    hmPtr->transferFunction(NanoVis::get_transfunc("default"));
    22932169    hmPtr->setVisible(true);
    22942170    hmPtr->setLineContourVisible(true);
     
    24312307        return TCL_ERROR;
    24322308    }
    2433     TransferFunction *tf;
    2434     tf = hmPtr->getColorMap();
    2435     if (tf == NULL) {
     2309    TransferFunction *tfPtr;
     2310    tfPtr = hmPtr->transferFunction();
     2311    if (tfPtr == NULL) {
    24362312        Tcl_AppendResult(interp, "no transfer function defined for heightmap \"",
    24372313                         Tcl_GetString(objv[2]), "\"", (char*)NULL);
     
    24472323    }
    24482324
    2449     NanoVis::render_legend(tf, HeightMap::valueMin, HeightMap::valueMax, w, h,
    2450       "label");
     2325    NanoVis::render_legend(tfPtr, HeightMap::valueMin, HeightMap::valueMax,
     2326                w, h, "label");
    24512327    return TCL_OK;
    24522328}
     
    25212397    float maxy = 3.5f;
    25222398    hmPtr->setHeight(minx, miny, maxx, maxy, 20, 20, data);
    2523     hmPtr->setColorMap(NanoVis::get_transfunc("default"));
     2399    hmPtr->transferFunction(NanoVis::get_transfunc("default"));
    25242400    hmPtr->setVisible(true);
    25252401    hmPtr->setLineContourVisible(true);
     
    25412417    const char *name;
    25422418    name = Tcl_GetString(objv[2]);
    2543     TransferFunction *tf;
    2544     tf = NanoVis::get_transfunc(name);
    2545     if (tf == NULL) {
     2419    TransferFunction *tfPtr;
     2420    tfPtr = NanoVis::get_transfunc(name);
     2421    if (tfPtr == NULL) {
    25462422        Tcl_AppendResult(interp, "transfer function \"", name,
    25472423                         "\" is not defined", (char*)NULL);
     
    25542430    vector<HeightMap *>::iterator iter;
    25552431    for (iter = imap.begin(); iter != imap.end(); iter++) {
    2556         (*iter)->setColorMap(tf);
     2432        (*iter)->transferFunction(tfPtr);
    25572433    }
    25582434    return TCL_OK;
     
    29052781    Tcl_CreateObjCommand(interp, "test", TestCmd, NULL, NULL);
    29062782#endif
    2907 
     2783    Tcl_InitHashTable(&NanoVis::volumeTable, TCL_STRING_KEYS);
    29082784    // create a default transfer function
    29092785    if (Tcl_Eval(interp, def_transfunc) != TCL_OK) {
  • trunk/packages/vizservers/nanovis/FlowCmd.cpp

    r1484 r1493  
    5353
    5454Rappture::SwitchSpec FlowCmd::_switches[] = {
     55    {Rappture::SWITCH_BOOLEAN, "-arrows", "boolean",
     56        offsetof(FlowValues, showArrows), 0},
     57    {Rappture::SWITCH_CUSTOM, "-axis", "axis",
     58        offsetof(FlowValues, slicePos.axis), 0, 0, &axisSwitch},
     59    {Rappture::SWITCH_FLOAT, "-diffuse", "value",
     60        offsetof(FlowValues, diffuse), 0},
     61    {Rappture::SWITCH_BOOLEAN, "-hide", "boolean",
     62        offsetof(FlowValues, isHidden), 0},
     63    {Rappture::SWITCH_FLOAT, "-opacity", "value",
     64        offsetof(FlowValues, opacity), 0},
     65    {Rappture::SWITCH_BOOLEAN, "-outline", "boolean",
     66        offsetof(FlowValues, showOutline), 0},
     67    {Rappture::SWITCH_CUSTOM, "-position", "number",
     68        offsetof(FlowValues, slicePos), 0, 0, &positionSwitch},
    5569    {Rappture::SWITCH_BOOLEAN, "-slice", "boolean",
    5670        offsetof(FlowValues, sliceVisible), 0},
    57     {Rappture::SWITCH_CUSTOM, "-axis", "axis",
    58         offsetof(FlowValues, slicePos.axis), 0, 0, &axisSwitch},
    59     {Rappture::SWITCH_BOOLEAN, "-hide", "boolean",
    60         offsetof(FlowValues, isHidden), 0},
    61     {Rappture::SWITCH_CUSTOM, "-position", "number",
    62         offsetof(FlowValues, slicePos), 0, 0, &positionSwitch},
     71    {Rappture::SWITCH_FLOAT, "-specular", "value",
     72        offsetof(FlowValues, specular), 0},
    6373    {Rappture::SWITCH_CUSTOM, "-transferfunction", "name",
    6474        offsetof(FlowValues, tfPtr), 0, 0, &transferFunctionSwitch},
    6575    {Rappture::SWITCH_BOOLEAN, "-volume", "boolean",
    6676        offsetof(FlowValues, showVolume), 0},
    67     {Rappture::SWITCH_BOOLEAN, "-outline", "boolean",
    68         offsetof(FlowValues, showOutline), 0},
    69     {Rappture::SWITCH_FLOAT, "-diffuse", "value",
    70         offsetof(FlowValues, diffuse), 0},
    71     {Rappture::SWITCH_FLOAT, "-opacity", "value",
    72         offsetof(FlowValues, opacity), 0},
    73     {Rappture::SWITCH_FLOAT, "-specular", "value",
    74         offsetof(FlowValues, specular), 0},
    7577    {Rappture::SWITCH_END}
    7678};
     
    295297    }
    296298     if (_volPtr != NULL) {
    297          assert((size_t)_volId == _volPtr->dataID());
    298          fprintf(stderr, "from ~FlowCmd volId=%d\n", _volId);
    299          NanoVis::remove_volume(_volId);
     299         NanoVis::remove_volume(_volPtr);
    300300         _volPtr = NULL;
    301301    }
     
    510510{
    511511    if (_volPtr != NULL) {
    512         assert((size_t)_volId == _volPtr->dataID());
    513         fprintf(stderr, "from ScaleVectorField volId=%d\n", _volId);
    514         NanoVis::remove_volume(_volId);
     512        fprintf(stderr, "from ScaleVectorField volId=%s\n", _volPtr->name());
     513        NanoVis::remove_volume(_volPtr);
    515514        _volPtr = NULL;
    516515    }
     
    563562
    564563    if (NanoVis::velocityArrowsSlice != NULL) {
    565         NanoVis::velocityArrowsSlice->vectorField(volPtr->id,
     564        NanoVis::velocityArrowsSlice->vectorField(_volPtr->id,
    566565            //*(volPtr->get_location()),
    567566            1.0f,
    568             volPtr->aspect_ratio_height / volPtr->aspect_ratio_width,
    569             volPtr->aspect_ratio_depth / volPtr->aspect_ratio_width
     567            _volPtr->aspect_ratio_height / _volPtr->aspect_ratio_width,
     568            _volPtr->aspect_ratio_depth / _volPtr->aspect_ratio_width
    570569            //,volPtr->wAxis.max()
    571570            );
     571        Trace("Arrows enabled set to %d\n", _sv.showArrows);
     572        NanoVis::velocityArrowsSlice->axis(_sv.slicePos.axis);
     573        NanoVis::velocityArrowsSlice->slicePos(_sv.slicePos.value);
     574        NanoVis::velocityArrowsSlice->enabled(_sv.showArrows);
    572575    }
    573576    FlowParticles *particlesPtr;
     
    628631{
    629632    Volume *volPtr;
    630     /* Reuse the volume index. The first time it's -1, which means to generate
    631      * a new volume slot. */
    632     volPtr = NanoVis::load_volume(_volId, _dataPtr->xNum(), _dataPtr->yNum(),
     633    volPtr = NanoVis::load_volume(_name, _dataPtr->xNum(), _dataPtr->yNum(),
    633634        _dataPtr->zNum(), 4, data, NanoVis::magMin, NanoVis::magMax, 0);
    634     /* Save the volume index.  This only matters the first time through. */
    635     _volId = volPtr->dataID();
    636635    volPtr->xAxis.SetRange(_dataPtr->xMin(), _dataPtr->xMax());
    637636    volPtr->yAxis.SetRange(_dataPtr->yMin(), _dataPtr->yMax());
     
    646645    // volPtr->set_n_slice(512- _volIndex);
    647646    // TBD..
    648     volPtr->n_slices(256);
     647    //volPtr->n_slices(256-n);
    649648    volPtr->disable_cutplane(0);
    650649    volPtr->disable_cutplane(1);
  • trunk/packages/vizservers/nanovis/FlowCmd.h

    r1478 r1493  
    136136    TransferFunction *tfPtr;
    137137    FlowPosition slicePos;
     138    int showArrows;
    138139    int sliceVisible;
    139140    int showVolume;
  • trunk/packages/vizservers/nanovis/HeightMap.cpp

    r1188 r1493  
    3030    _contour(0),
    3131    _topContour(0),
    32     _colorMap(0),
     32    _tfPtr(0),
    3333    _indexBuffer(0),
    3434    _indexCount(0),
     
    4343    _shader = new NvShader();
    4444    _shader->loadFragmentProgram("heightcolor.cg", "main");
    45     _tf = _shader->getNamedParameterFromFP("tf");
     45    _tfParam = _shader->getNamedParameterFromFP("tf");
    4646}
    4747
     
    5555
    5656    // TMP
    57     //if (_colorMap) delete _colorMap;
     57    //if (_tfPtr) delete _tfPtr;
    5858}
    5959
     
    9393        glDisableClientState(GL_NORMAL_ARRAY);
    9494       
    95         if (_colorMap) {
     95        if (_tfPtr) {
    9696            // PUT vertex program here
    9797            //
     
    101101            cgGLEnableProfile(CG_PROFILE_FP30);
    102102           
    103             cgGLSetTextureParameter(_tf, _colorMap->id);
    104             cgGLEnableTextureParameter(_tf);
     103            cgGLSetTextureParameter(_tfParam, _tfPtr->id());
     104            cgGLEnableTextureParameter(_tfParam);
    105105           
    106106            glEnable(GL_TEXTURE_1D);
    107             _colorMap->getTexture()->activate();
     107            _tfPtr->getTexture()->activate();
    108108           
    109109            glEnableClientState(GL_TEXTURE_COORD_ARRAY);
     
    128128       
    129129        glDisableClientState(GL_VERTEX_ARRAY);
    130         if (_colorMap) {
    131             _colorMap->getTexture()->deactivate();
     130        if (_tfPtr != NULL) {
     131            _tfPtr->getTexture()->deactivate();
    132132            glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    133133           
     
    388388   
    389389    ContourLineFilter lineFilter;
    390     //lineFilter.setColorMap(_colorMap);
     390    //lineFilter.transferFunction(_tfPtr);
    391391    _contour = lineFilter.create(0.0f, 1.0f, 10, heightMap, xNum, yNum);
    392392   
     
    439439    }
    440440    return vertices;
    441 }
    442 
    443 void HeightMap::setColorMap(TransferFunction* colorMap)
    444 {
    445     //if (colorMap) colorMap->addRef();
    446     //if (_colorMap) _colorMap->unrefDelete();
    447     _colorMap = colorMap;
    448441}
    449442
     
    501494
    502495    ContourLineFilter lineFilter;
    503     //lineFilter.setColorMap(_colorMap);
     496    //lineFilter.transferFunction(_tfPtr);
    504497    _contour = lineFilter.create(0.0f, 1.0f, 10, vertices, xNum_, yNum_);
    505498   
     
    568561        glDisableClientState(GL_NORMAL_ARRAY);
    569562       
    570         if (_colorMap) {
     563        if (_tfPtr != NULL) {
    571564            cgGLBindProgram(_shader->getFP());
    572565            cgGLEnableProfile(CG_PROFILE_FP30);
    573566           
    574             cgGLSetTextureParameter(_tf, _colorMap->id);
    575             cgGLEnableTextureParameter(_tf);
     567            cgGLSetTextureParameter(_tfParam, _tfPtr->id());
     568            cgGLEnableTextureParameter(_tfParam);
    576569           
    577570            glEnable(GL_TEXTURE_1D);
    578             _colorMap->getTexture()->activate();
     571            _tfPtr->getTexture()->activate();
    579572           
    580573            glEnableClientState(GL_TEXTURE_COORD_ARRAY);
     
    602595       
    603596        glDisableClientState(GL_VERTEX_ARRAY);
    604         if (_colorMap) {
    605             _colorMap->getTexture()->deactivate();
     597        if (_tfPtr != NULL) {
     598            _tfPtr->getTexture()->deactivate();
    606599            glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    607600           
  • trunk/packages/vizservers/nanovis/HeightMap.h

    r1188 r1493  
    2626    unsigned int _textureBufferObjectID;
    2727    int _vertexCount;
    28     CGparameter _tf;
     28    CGparameter _tfParam;
    2929    R2Geometry* _contour;
    3030    R2Geometry* _topContour;
    31     TransferFunction* _colorMap;
     31    TransferFunction* _tfPtr;
    3232    NvShader* _shader;
    3333    int *_indexBuffer;
     
    9090     *@brief Define a color map for color shading of heightmap
    9191     */
    92     void setColorMap(TransferFunction* colorMap);
    93 
     92    void transferFunction(TransferFunction* tfPtr) {
     93        _tfPtr = tfPtr;
     94    }
    9495    /**
    9596     *@brief Get the color map defined for shading of this heightmap
    9697     */
    97     TransferFunction *getColorMap(void) {
    98         return _colorMap;
     98    TransferFunction *transferFunction(void) {
     99        return _tfPtr;
    99100    }
    100101    /**
  • trunk/packages/vizservers/nanovis/NvColorTableShader.h

    r580 r1493  
    2525{
    2626    cgGLSetTextureParameter(_dataParam, plane->id);
    27     cgGLSetTextureParameter(_tfParam, tf->id);
     27    cgGLSetTextureParameter(_tfParam, tf->id());
    2828    cgGLEnableTextureParameter(_dataParam);
    2929    cgGLEnableTextureParameter(_tfParam);
  • trunk/packages/vizservers/nanovis/PlaneRenderer.cpp

    r1478 r1493  
    5050
    5151int
    52 PlaneRenderer::add_plane(Texture2D* _p, TransferFunction* _tf)
     52PlaneRenderer::add_plane(Texture2D* _p, TransferFunction* tfPtr)
    5353{
    5454    int ret = n_planes;
    5555
    5656    plane.push_back(_p);
    57     tf.push_back(_tf);
     57    tf.push_back(tfPtr);
    5858
    5959    if(ret==0)
     
    9595
    9696    //if no active plane
    97     if(active_plane == -1)
     97    if (active_plane == -1)
    9898        return;
    9999
     
    112112PlaneRenderer::activate_shader(int index)
    113113{
    114 
    115114    cgGLSetTextureParameter(m_data_param, plane[index]->id);
    116     cgGLSetTextureParameter(m_tf_param, tf[index]->id);
     115    cgGLSetTextureParameter(m_tf_param, tf[index]->id());
    117116    cgGLEnableTextureParameter(m_data_param);
    118117    cgGLEnableTextureParameter(m_tf_param);
  • trunk/packages/vizservers/nanovis/TransferFunction.cpp

    r1475 r1493  
    2828    _data = new float[_size];
    2929    memcpy(_data, data, sizeof(float) * _size);
    30 
    3130    _tex->initialize_float_rgba(_data);
    32     id = _tex->id;
     31    _id = _tex->id;
    3332}
    3433
  • trunk/packages/vizservers/nanovis/TransferFunction.h

    r1475 r1493  
    2828    float* _data;
    2929    Texture1D* _tex;            //the texture storing the colors
    30    
     30    const char *_name;
     31    GLuint _id;                 //OpenGL's texture identifier
    3132protected :
    3233    ~TransferFunction();
    3334public:
    34     GLuint id;                  //OpenGL's texture identifier
    35 
    3635    TransferFunction(int size, float *data);
    3736    void update(float *data);
    3837    void update(int size, float *data);
     38    GLuint id(void) {
     39        return _id;
     40    }
     41    void id(GLuint id) {
     42        _id = id;
     43    }
    3944    Texture1D* getTexture(void) {
    4045        return _tex;
     
    4348        return _data;
    4449    }
    45     int getSize() const;
     50    int getSize() const {
     51        return _size;
     52    }
     53    const char *name(void) const {
     54        return _name;
     55    }
     56    void name(const char *name) {
     57        _name = name;
     58    }
    4659};
    4760
    48 inline int TransferFunction::getSize() const
    49 {
    50     return _size;
    51 }
    5261#endif
  • trunk/packages/vizservers/nanovis/VelocityArrowsSlice.cpp

    r1490 r1493  
    265265void VelocityArrowsSlice::render()
    266266{
    267         //if (!_enabled || (_vectorFieldGraphicsID == 0)) return;       
    268         if (!_enabled) return;
    269 
    270         if (_dirty)
    271         {
    272                 computeSamplingTicks();
    273                 queryVelocity();
    274                 _dirty = false;
    275         }
    276 
    277 
    278         glPushMatrix();
    279        
    280         glScalef(_vfXscale,_vfYscale, _vfZscale);
    281         glTranslatef(-0.5f, -0.5f, -0.5f);
    282         if (_renderMode == LINES)
    283         {
    284 
    285                 glDisable(GL_TEXTURE_2D);
    286                 glLineWidth(2.0);
    287                 glColor3f(_arrowColor.x, _arrowColor.y, _arrowColor.z);
    288                 glBegin(GL_LINES);
    289                 Vector3 pos;
    290                 Vector3 pos2;
    291                 Vector3 vel(1, 0, 0);
    292                 Vector3 v, v2;
    293                 if (_axis == 2)
    294                 {
    295                         int index = 0;
    296                         for (int y = 1; y <= _tickCountY; ++y)
    297                                 for (int x = 1; x <= _tickCountX; ++x, ++index)
    298                                 {
    299                                         pos = this->_samplingPositions[index];
    300                                         pos2 = this->_velocities[index].scale(_projectionVector).scale(_maxVelocityScale) + pos;
    301                                         glVertex3f(pos.x, pos.y, pos.z);
    302                                         glVertex3f(pos2.x, pos2.y, pos2.z);
    303                                         /*v = pos - pos2;
    304                                        
    305                                        
    306                                         v2.x = 1;
    307                                         v2.y = 1;
    308                                         v2.z = (-(x1-x2)-(y1-y2))/(z1-z2)
    309                                         adj = v.length() / (4 * sqrt((x3^2)+(y3^2)+(z3^2)));
    310                                         x3 *= adj
    311                                         y3 *= adj
    312                                         z3 *= adj
    313                                         */
    314 
    315                                 }
    316                 }
    317                 else if (_axis == 1)
    318                 {
    319                         int index = 0;
    320                         for (int z = 1; z <= _tickCountZ; ++z)
    321                                 for (int x = 1; x <= _tickCountX; ++x, ++index)
    322                                 {
    323                                         pos = _samplingPositions[index];
    324                                         pos2 = this->_velocities[index].scale(_projectionVector).scale(_maxVelocityScale) + pos;
    325 
    326                                         glVertex3f(pos.x, pos.y, pos.z);
    327                                         glVertex3f(pos2.x, pos2.y, pos2.z);
    328                                 }
    329                 }
    330                 else if (_axis == 0)
    331                 {
    332                         int index = 0;
    333                         for (int z = 1; z <= _tickCountZ; ++z)
    334                                 for (int y = 1; y <= _tickCountY; ++y, ++index)
    335                                 {
    336                                         pos = _samplingPositions[index];
    337                                         pos2 = this->_velocities[index].scale(_projectionVector).scale(_maxVelocityScale) + pos;
    338 
    339                                         glVertex3f(pos.x, pos.y, pos.z);
    340                                         glVertex3f(pos2.x, pos2.y, pos2.z);
    341                                 }
    342                 }
    343                
    344                 glEnd();
    345                 glLineWidth(1.0);
    346         }
    347         else
    348         {
    349                 glColor3f(_arrowColor.x, _arrowColor.y, _arrowColor.z);
    350                 glEnable(GL_BLEND);
    351                 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    352                 glEnable(GL_POINT_SPRITE_NV);
    353                 glPointSize(20);                               
    354                 glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_NV);
    355 
    356 #ifdef USE_NANOVIS_LIB
    357                 _arrowsTex->activate();
    358 #else
    359                 _arrowsTex->bind(0);
    360                 glEnable(GL_TEXTURE_2D);
    361 #endif
    362                 glPointParameterfARB( GL_POINT_FADE_THRESHOLD_SIZE_ARB, 0.0f );
    363 
    364                 glPointParameterfARB( GL_POINT_SIZE_MIN_ARB, 1.0f);
    365                 glPointParameterfARB( GL_POINT_SIZE_MAX_ARB, 100.0f);
    366                 glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE );
    367 
    368                 cgGLBindProgram(_particleVP);
    369                 cgGLBindProgram(_particleFP);
    370                 cgGLEnableProfile(CG_PROFILE_VP40);
    371                 cgGLEnableProfile(CG_PROFILE_FP40);
    372 
    373                 cgGLSetTextureParameter(_vectorParticleParam, _vectorFieldGraphicsID);
    374                 cgGLEnableTextureParameter(_vectorParticleParam);
    375 
    376 
    377                 //cgSetParameter1f(_mvTanHalfFOVParam, -tan(_fov * 0.5) * _screenHeight * 0.5);
    378                
    379                 cgGLSetStateMatrixParameter(_mvpParticleParam,
    380                                                 CG_GL_MODELVIEW_PROJECTION_MATRIX,
    381                                                 CG_GL_MATRIX_IDENTITY);
    382                 cgGLSetStateMatrixParameter(_mvParticleParam,
    383                                                 CG_GL_MODELVIEW_MATRIX,
    384                                                 CG_GL_MATRIX_IDENTITY);
    385 
    386                 glEnableClientState(GL_VERTEX_ARRAY);
    387                 glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vertexBufferGraphicsID);
    388                 glVertexPointer(3, GL_FLOAT, 0, 0);
    389                 //glEnableClientState(GL_COLOR_ARRAY);
    390 
    391                 // TBD..
    392                 glDrawArrays(GL_POINTS, 0, _pointCount);
    393                 glPointSize(1);
    394                 glDrawArrays(GL_POINTS, 0, _pointCount);
    395 
    396                 glDisableClientState(GL_VERTEX_ARRAY);
    397                
    398                 cgGLDisableProfile(CG_PROFILE_VP40);
    399                 cgGLDisableProfile(CG_PROFILE_FP40);
    400 
    401                 glDepthMask(GL_TRUE);
    402                
    403                 glDisable(GL_POINT_SPRITE_NV);
    404                 glDisable(GL_VERTEX_PROGRAM_POINT_SIZE_NV);
    405 
    406                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    407                 glDisable(GL_BLEND);
    408 #ifdef USE_NANOVIS_LIB
    409                 _arrowsTex->deactivate();
    410 #else
    411                 _arrowsTex->unbind();
    412 #endif
    413         }
    414         glPopMatrix();
    415 }
    416 
    417 void VelocityArrowsSlice::enabled(bool e)
    418 {
    419         _enabled = e;
    420 }
    421 
    422 void VelocityArrowsSlice::vectorField(unsigned int vfGraphicsID,
    423                                 float xScale, float yScale, float zScale)
     267    //if (!_enabled || (_vectorFieldGraphicsID == 0)) return;   
     268    if (!_enabled) return;
     269   
     270    if (_dirty) {
     271        computeSamplingTicks();
     272        queryVelocity();
     273        _dirty = false;
     274    }
     275   
     276   
     277    glPushMatrix();
     278   
     279    glScalef(_vfXscale,_vfYscale, _vfZscale);
     280    glTranslatef(-0.5f, -0.5f, -0.5f);
     281    if (_renderMode == LINES) {
     282       
     283        glDisable(GL_TEXTURE_2D);
     284        glLineWidth(2.0);
     285        glColor3f(_arrowColor.x, _arrowColor.y, _arrowColor.z);
     286        glBegin(GL_LINES);
     287        Vector3 pos;
     288        Vector3 pos2;
     289        Vector3 vel(1, 0, 0);
     290        Vector3 v, v2;
     291        if (_axis == 2) {
     292            int index = 0;
     293            for (int y = 1; y <= _tickCountY; ++y) {
     294                for (int x = 1; x <= _tickCountX; ++x, ++index) {
     295                    pos = this->_samplingPositions[index];
     296                    pos2 = this->_velocities[index].scale(_projectionVector).scale(_maxVelocityScale) + pos;
     297                    glVertex3f(pos.x, pos.y, pos.z);
     298                    glVertex3f(pos2.x, pos2.y, pos2.z);
     299                    /*v = pos - pos2;
     300                     
     301                   
     302                    v2.x = 1;
     303                    v2.y = 1;
     304                    v2.z = (-(x1-x2)-(y1-y2))/(z1-z2)
     305                    adj = v.length() / (4 * sqrt((x3^2)+(y3^2)+(z3^2)));
     306                    x3 *= adj
     307                    y3 *= adj
     308                    z3 *= adj
     309                    */
     310                   
     311                }
     312            }
     313        } else if (_axis == 1) {
     314            int index = 0;
     315            for (int z = 1; z <= _tickCountZ; ++z)
     316                for (int x = 1; x <= _tickCountX; ++x, ++index) {
     317                    pos = _samplingPositions[index];
     318                    pos2 = this->_velocities[index].scale(_projectionVector).scale(_maxVelocityScale) + pos;
     319                   
     320                    glVertex3f(pos.x, pos.y, pos.z);
     321                    glVertex3f(pos2.x, pos2.y, pos2.z);
     322                }
     323        } else if (_axis == 0) {
     324            int index = 0;
     325            for (int z = 1; z <= _tickCountZ; ++z)
     326                for (int y = 1; y <= _tickCountY; ++y, ++index) {
     327                    pos = _samplingPositions[index];
     328                    pos2 = this->_velocities[index].scale(_projectionVector).scale(_maxVelocityScale) + pos;
     329                   
     330                    glVertex3f(pos.x, pos.y, pos.z);
     331                    glVertex3f(pos2.x, pos2.y, pos2.z);
     332                }
     333        }
     334       
     335        glEnd();
     336        glLineWidth(1.0);
     337    } else {
     338        glColor3f(_arrowColor.x, _arrowColor.y, _arrowColor.z);
     339        glEnable(GL_BLEND);
     340        glBlendFunc(GL_SRC_ALPHA, GL_ONE);
     341        glEnable(GL_POINT_SPRITE_NV);
     342        glPointSize(20);                               
     343        glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_NV);
     344       
     345#ifdef USE_NANOVIS_LIB
     346        _arrowsTex->activate();
     347#else
     348        _arrowsTex->bind(0);
     349        glEnable(GL_TEXTURE_2D);
     350#endif
     351        glPointParameterfARB( GL_POINT_FADE_THRESHOLD_SIZE_ARB, 0.0f );
     352       
     353        glPointParameterfARB( GL_POINT_SIZE_MIN_ARB, 1.0f);
     354        glPointParameterfARB( GL_POINT_SIZE_MAX_ARB, 100.0f);
     355        glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE );
     356       
     357        cgGLBindProgram(_particleVP);
     358        cgGLBindProgram(_particleFP);
     359        cgGLEnableProfile(CG_PROFILE_VP40);
     360        cgGLEnableProfile(CG_PROFILE_FP40);
     361       
     362        cgGLSetTextureParameter(_vectorParticleParam, _vectorFieldGraphicsID);
     363        cgGLEnableTextureParameter(_vectorParticleParam);
     364       
     365       
     366        //cgSetParameter1f(_mvTanHalfFOVParam, -tan(_fov * 0.5) * _screenHeight * 0.5);
     367       
     368        cgGLSetStateMatrixParameter(_mvpParticleParam,
     369                                    CG_GL_MODELVIEW_PROJECTION_MATRIX,
     370                                    CG_GL_MATRIX_IDENTITY);
     371        cgGLSetStateMatrixParameter(_mvParticleParam,
     372                                    CG_GL_MODELVIEW_MATRIX,
     373                                    CG_GL_MATRIX_IDENTITY);
     374       
     375        glEnableClientState(GL_VERTEX_ARRAY);
     376        glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vertexBufferGraphicsID);
     377        glVertexPointer(3, GL_FLOAT, 0, 0);
     378        //glEnableClientState(GL_COLOR_ARRAY);
     379       
     380        // TBD..
     381        glDrawArrays(GL_POINTS, 0, _pointCount);
     382        glPointSize(1);
     383        glDrawArrays(GL_POINTS, 0, _pointCount);
     384       
     385        glDisableClientState(GL_VERTEX_ARRAY);
     386       
     387        cgGLDisableProfile(CG_PROFILE_VP40);
     388        cgGLDisableProfile(CG_PROFILE_FP40);
     389       
     390        glDepthMask(GL_TRUE);
     391       
     392        glDisable(GL_POINT_SPRITE_NV);
     393        glDisable(GL_VERTEX_PROGRAM_POINT_SIZE_NV);
     394       
     395        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     396        glDisable(GL_BLEND);
     397#ifdef USE_NANOVIS_LIB
     398        _arrowsTex->deactivate();
     399#else
     400        _arrowsTex->unbind();
     401#endif
     402    }
     403    glPopMatrix();
     404}
     405
     406
     407void
     408VelocityArrowsSlice::vectorField(unsigned int vfGraphicsID,
     409                                 float xScale, float yScale, float zScale)
    424410{
    425411    _vectorFieldGraphicsID = vfGraphicsID;
  • trunk/packages/vizservers/nanovis/VelocityArrowsSlice.h

    r1489 r1493  
    132132        void queryVelocity();
    133133        void render();
    134         void enabled(bool e);
    135         bool enabled() const;
    136         void tickCountForMinSizeAxis(int tickCount);
     134    void enabled(bool enabled) {
     135        _enabled = enabled;
     136    }
     137    bool enabled(void) const {
     138        return _enabled;
     139    }
     140    void tickCountForMinSizeAxis(int tickCount);
    137141    int tickCountForMinSizeAxis() const;
    138142    void arrowColor(const Vector3& color);
    139         void renderMode(RenderMode mode);
    140         RenderMode renderMode() const;
     143    void renderMode(RenderMode mode);
     144    RenderMode renderMode() const;
    141145};
    142146
     
    151155}
    152156
    153 
    154 inline bool VelocityArrowsSlice::enabled() const
    155 {
    156         return _enabled;
    157 }
    158157
    159158inline int VelocityArrowsSlice::tickCountForMinSizeAxis() const
  • trunk/packages/vizservers/nanovis/Volume.cpp

    r1478 r1493  
    3131    _diffuse(3.),               // default value
    3232    _opacity_scale(10.),        // default value
     33    _name(NULL),
    3334    _n_components(n),
    3435    _nonzero_min(nz_min),
     
    4748    size(s)
    4849{
    49     _volumeDataID = -1;
    50 
    5150    _tex = new Texture3D(w, h, d, NVIS_FLOAT, NVIS_LINEAR_INTERP, n);
    5251    int fcount = width * height * depth * _n_components;
  • trunk/packages/vizservers/nanovis/Volume.h

    r1478 r1493  
     1
    12/*
    23 * ----------------------------------------------------------------------
     
    5455                                        // the object is to appear like
    5556                                        // plastic
    56     int _volumeDataID;
     57    const char *_name;
    5758    Vector3 _physical_min;
    5859    Vector3 _physical_max;
     
    222223    Vector3& getPhysicalBBoxMax();
    223224
    224     void dataID(size_t index) {
    225         _volumeDataID = index;
    226     }
    227     size_t dataID(void) const {
    228         return _volumeDataID;
     225    const char *name(void) {
     226        return _name;
     227    }
     228    void name(const char *name) {
     229        _name = name;
    229230    }
    230231};
  • trunk/packages/vizservers/nanovis/VolumeInterpolator.cpp

    r1478 r1493  
    144144                             refPtr->wAxis.max(),
    145145                             refPtr->nonzero_min());
     146        /*
    146147        _referenceOfVolume = refPtr->dataID();
     148        */
    147149        _volume->n_slices(256-1);
    148150        _volume->disable_cutplane(0);
     
    155157        _volume->opacity_scale(refPtr->opacity_scale());
    156158        _volume->isosurface(0);
    157         Trace("VOL : location %f %f %f\n\tid : %d\n", loc.x, loc.y, loc.z,
    158                 refPtr->dataID());
     159        Trace("VOL : location %f %f %f\n\tid : %s\n", loc.x, loc.y, loc.z,
     160                refPtr->name());
    159161    }
    160162    _volumes.push_back(_volume);
    161     Trace("a Volume[%d] is added to VolumeInterpolator\n", refPtr->dataID());
     163    Trace("a Volume[%s] is added to VolumeInterpolator\n", refPtr->name());
    162164}
    163165
  • trunk/packages/vizservers/nanovis/VolumeRenderer.cpp

    r1478 r1493  
    8888}
    8989
    90 void VolumeRenderer::render_all_points()
    91 {
    92 #ifdef notdef
    93     double x0 = 0;
    94     double y0 = 0;
    95     double z0 = 0;
    96    
    97     for(int i=0; i<n_volumes; i++){
    98         int volume_index = i;
    99         if(!volume[i]->visible())
    100             continue; //skip this volume
    101        
    102         Vector3* location = volume[volume_index]->get_location();
    103         Vector4 shift_4d(location->x, location->y, location->z, 0);
    104        
    105         glPushMatrix();
    106         glTranslatef(shift_4d.x, shift_4d.y, shift_4d.z);
    107        
    108         if (volume[volume_index]->outline()) {
    109             float olcolor[3];
    110             volume[volume_index]->get_outline_color(olcolor);
    111             draw_bounding_box(x0, y0, z0, x0+1, y0+1, z0+1,
    112                 (double)olcolor[0], (double)olcolor[1], (double)olcolor[2], 1.5);
    113         }
    114        
    115         glPopMatrix();
    116     }
    117 #endif
    118 }
    11990
    12091void
     
    132103    // Determine the volumes that are to be rendered.
    133104    vector<Volume *> volumes;
    134     for (size_t i = 0; i < NanoVis::volumes.size(); i++) {
     105    Tcl_HashEntry *hPtr;
     106    Tcl_HashSearch iter;
     107    for (hPtr = Tcl_FirstHashEntry(&NanoVis::volumeTable, &iter); hPtr != NULL;
     108         hPtr = Tcl_NextHashEntry(&iter)) {
    135109        Volume* volPtr;
    136    
    137         volPtr = NanoVis::volumes[i];
    138         Trace("volume %d: %x id=%d\n", i, volPtr,
    139               (volPtr != NULL) ? volPtr->dataID() : -1);
    140         if (volPtr == NULL) {
    141             continue;                   // Empty slot in volume vector.
    142         }
     110        volPtr = (Volume *)Tcl_GetHashValue(hPtr);
     111        Trace("volume %s addr=%x\n", volPtr->name(), volPtr);
    143112        if(!volPtr->visible()) {
    144             Trace("volume [%d] %d skipped, size=%d id=%d\n", volPtr->dataID(),
    145                   volPtr->visible(), volumes.size(), volPtr->dataID());
    146113            continue;                   // Skip this volume
    147114        }
     115        // BE CAREFUL: Set the number of slices to something slightly
     116        // different for each volume.  If we have identical volumes at exactly
     117        // the same position with exactly the same number of slices, the
     118        // second volume will overwrite the first, so the first won't appear
     119        // at all.
    148120        volumes.push_back(volPtr);
     121        volPtr->n_slices(256 - volumes.size());
    149122    }
    150123
     
    162135        volPtr = volumes[i];
    163136
    164         Trace("render: volume [%d] rendering visible=%d\n", volPtr->dataID(),
    165               volPtr->visible());
    166137        int n_slices = volPtr->n_slices();
    167138        if (volPtr->isosurface()) {
     
    249220        size_t n_actual_slices;
    250221       
    251         if (volPtr->data()) {
     222        if (volPtr->data_enabled()) {
    252223            n_actual_slices = (int)(fabs(zNear-zFar)/z_step + 1);
    253224            polys[i] = new ConvexPolygon*[n_actual_slices];
     
    380351       
    381352    } //iterate all volumes
    382     //fprintf(stderr, "total slices: %d\n", total_rendered_slices);
     353    fprintf(stderr, "total slices: %d\n", total_rendered_slices);
    383354    Trace("end loop\n");
    384355   
    385     //We sort all the polygons according to their eye-space depth, from farthest to the closest.
    386     //This step is critical for correct blending
    387    
    388     SortElement* slices = (SortElement*)malloc(sizeof(SortElement)*total_rendered_slices);
     356    // We sort all the polygons according to their eye-space depth, from
     357    // farthest to the closest.  This step is critical for correct blending
     358   
     359    SortElement* slices = (SortElement*)
     360        malloc(sizeof(SortElement) * total_rendered_slices);
    389361   
    390362    size_t counter = 0;
     
    405377    glEnable(GL_BLEND);
    406378   
    407     for(size_t i = 0; i <total_rendered_slices; i++){
     379    for(size_t i = 0; i < total_rendered_slices; i++){
    408380        Volume* volPtr;
    409381
     
    417389                 volPtr->aspect_ratio_depth);
    418390       
     391#ifdef notdef
     392        Trace("shading slice: volume %s addr=%x slice=%d, volume=%d\n",
     393              volPtr->name(), volPtr, slice_index, volume_index);
     394#endif
    419395        activate_volume_shader(volPtr, false);
    420396        glPopMatrix();
     
    426402        deactivate_volume_shader();
    427403    }
    428    
    429404   
    430405    glDisable(GL_DEPTH_TEST);
     
    445420}
    446421
    447 void
    448 VolumeRenderer::render(int volDataID)
    449 {
    450     assert(volDataID >= 0 && (size_t)volDataID < NanoVis::volumes.size());
    451     Volume* vol;
    452     vol = NanoVis::volumes[volDataID];
    453     if ((vol == NULL) || (!vol->visible())) {
    454         Trace("volume [%d] skipped\n", volDataID);
    455         return;                         // Empty slot or volume is not to be
    456                                         // rendered.
    457     }
    458     Trace("volume [%d] rendering visible=%d\n", vol->dataID(),
    459           vol->visible());
    460     int n_slices = vol->n_slices();
    461 
    462     //volume start location
    463     Vector3 loc = vol->location();
    464     Vector4 shift_4d(loc.x, loc.y, loc.z, 0);
    465    
    466     double x0 = 0;
    467     double y0 = 0;
    468     double z0 = 0;
    469    
    470     Mat4x4 model_view_no_trans, model_view_trans;
    471     Mat4x4 model_view_no_trans_inverse, model_view_trans_inverse;
    472    
    473     double zNear, zFar;
    474    
    475     //initialize volume plane with world coordinates
    476     Plane volume_planes[6];
    477     volume_planes[0].set_coeffs(1, 0, 0, -x0);
    478     volume_planes[1].set_coeffs(-1, 0, 0, x0+1);
    479     volume_planes[2].set_coeffs(0, 1, 0, -y0);
    480     volume_planes[3].set_coeffs(0, -1, 0, y0+1);
    481     volume_planes[4].set_coeffs(0, 0, 1, -z0);
    482     volume_planes[5].set_coeffs(0, 0, -1, z0+1);
    483    
    484     glPushMatrix();
    485    
    486     glScalef(vol->aspect_ratio_width,
    487              vol->aspect_ratio_height,
    488              vol->aspect_ratio_depth);
    489    
    490     glEnable(GL_DEPTH_TEST);
    491    
    492     GLfloat mv_no_trans[16];
    493     glGetFloatv(GL_MODELVIEW_MATRIX, mv_no_trans);
    494    
    495     model_view_no_trans = Mat4x4(mv_no_trans);
    496     model_view_no_trans_inverse = model_view_no_trans.inverse();
    497    
    498     glPopMatrix();
    499    
    500     //get modelview matrix with translation
    501     glPushMatrix();
    502     glTranslatef(shift_4d.x, shift_4d.y, shift_4d.z);
    503     glScalef(vol->aspect_ratio_width,
    504              vol->aspect_ratio_height,
    505              vol->aspect_ratio_depth);
    506     GLfloat mv_trans[16];
    507     glGetFloatv(GL_MODELVIEW_MATRIX, mv_trans);
    508    
    509     model_view_trans = Mat4x4(mv_trans);
    510     model_view_trans_inverse = model_view_trans.inverse();
    511    
    512     //draw volume bounding box
    513     if (vol->outline()) {
    514         draw_bounding_box(x0, y0, z0, x0+1, y0+1, z0+1, 0.8, 0.1, 0.1, 1.5);
    515     }
    516     glPopMatrix();
    517    
    518     //transform volume_planes to eye coordinates.
    519     for(int i=0; i<6; i++)
    520         volume_planes[i].transform(model_view_no_trans);
    521    
    522     get_near_far_z(mv_no_trans, zNear, zFar);
    523     //fprintf(stderr, "zNear:%f, zFar:%f\n", zNear, zFar);
    524     //fflush(stderr);
    525    
    526     //compute actual rendering slices
    527     float z_step = fabs(zNear-zFar)/n_slices;           
    528     int n_actual_slices = (int)(fabs(zNear-zFar)/z_step + 1);
    529     //fprintf(stderr, "slices: %d\n", n_actual_slices);
    530     //fflush(stderr);
    531    
    532     static ConvexPolygon staticPoly;   
    533     float slice_z;
    534    
    535     Vector4 vert1 = (Vector4(-10, -10, -0.5, 1));
    536     Vector4 vert2 = (Vector4(-10, +10, -0.5, 1));
    537     Vector4 vert3 = (Vector4(+10, +10, -0.5, 1));
    538     Vector4 vert4 = (Vector4(+10, -10, -0.5, 1));
    539    
    540     glEnable(GL_BLEND);
    541    
    542     if(slice_mode){
    543         glEnable(GL_DEPTH_TEST);
    544        
    545         //render the cut planes
    546         for(int i=0; i<vol->get_cutplane_count(); i++){
    547             float offset = vol->get_cutplane(i)->offset;
    548             int axis = vol->get_cutplane(i)->orient;
    549            
    550             if (axis==1) {
    551                 vert1 = Vector4(-10, -10, offset, 1);
    552                 vert2 = Vector4(-10, +10, offset, 1);
    553                 vert3 = Vector4(+10, +10, offset, 1);
    554                 vert4 = Vector4(+10, -10, offset, 1);
    555             } else if(axis==2){
    556                 vert1 = Vector4(offset, -10, -10, 1);
    557                 vert2 = Vector4(offset, +10, -10, 1);
    558                 vert3 = Vector4(offset, +10, +10, 1);
    559                 vert4 = Vector4(offset, -10, +10, 1);
    560             } else if(axis==3) {
    561                 vert1 = Vector4(-10, offset, -10, 1);
    562                 vert2 = Vector4(+10, offset, -10, 1);
    563                 vert3 = Vector4(+10, offset, +10, 1);
    564                 vert4 = Vector4(-10, offset, +10, 1);
    565             }
    566            
    567             vert1 = model_view_no_trans.transform(vert1);
    568             vert2 = model_view_no_trans.transform(vert2);
    569             vert3 = model_view_no_trans.transform(vert3);
    570             vert4 = model_view_no_trans.transform(vert4);
    571            
    572             ConvexPolygon *poly;
    573             poly = &staticPoly;
    574             poly->vertices.clear();
    575            
    576             poly->append_vertex(vert1);
    577             poly->append_vertex(vert2);
    578             poly->append_vertex(vert3);
    579             poly->append_vertex(vert4);
    580            
    581             for(int k=0; k<6; k++){
    582                 poly->clip(volume_planes[k], true);
    583             }
    584            
    585             //poly->transform(model_view_inverse);
    586             //poly->translate(shift_4d);
    587             //poly->transform(model_view);
    588             poly->transform(model_view_no_trans_inverse);
    589             poly->transform(model_view_trans);
    590            
    591             glPushMatrix();
    592             glScalef(vol->aspect_ratio_width, vol->aspect_ratio_height,
    593                      vol->aspect_ratio_depth);
    594            
    595             activate_volume_shader(vol, true);
    596             glPopMatrix();
    597            
    598             glBegin(GL_POLYGON);
    599             poly->Emit(true);
    600             glEnd();
    601            
    602             deactivate_volume_shader();
    603         }
    604     } //slice_mode
    605    
    606    
    607     if(volume_mode){
    608         glEnable(GL_DEPTH_TEST);
    609        
    610         for (int i=0; i<n_actual_slices; i++){
    611             slice_z = zFar + i * z_step;        //back to front
    612            
    613             ConvexPolygon *poly;
    614             poly = &staticPoly;
    615             poly->vertices.clear();
    616            
    617             //Setting Z-coordinate
    618             vert1.z = slice_z;
    619             vert2.z = slice_z;
    620             vert3.z = slice_z;
    621             vert4.z = slice_z;
    622            
    623             poly->append_vertex(vert1);
    624             poly->append_vertex(vert2);
    625             poly->append_vertex(vert3);
    626             poly->append_vertex(vert4);
    627            
    628             for(int k=0; k<6; k++){
    629                 poly->clip(volume_planes[k], true);
    630             }
    631            
    632             //move the volume to the proper location
    633             //poly->transform(model_view_inverse);
    634             //poly->translate(shift_4d);
    635             //poly->transform(model_view);
    636            
    637             poly->transform(model_view_no_trans_inverse);
    638             poly->transform(model_view_trans);
    639            
    640             glPushMatrix();
    641             glScalef(vol->aspect_ratio_width, vol->aspect_ratio_height,
    642                      vol->aspect_ratio_depth);
    643            
    644             /*
    645             //draw slice lines only
    646             glDisable(GL_BLEND);
    647             glDisable(GL_TEXTURE_3D);
    648             glDisable(GL_TEXTURE_2D);
    649             glLineWidth(1.0);
    650             glColor3f(1,1,1);
    651             glBegin(GL_LINE_LOOP);
    652             poly->Emit(false);
    653             glEnd();
    654             */
    655            
    656             activate_volume_shader(vol, true);
    657             glPopMatrix();
    658            
    659             glBegin(GL_POLYGON);
    660             poly->Emit(true);
    661             glEnd();
    662            
    663             deactivate_volume_shader();
    664            
    665         }
    666     } //volume_mode
    667    
    668     glDisable(GL_BLEND);
    669     glDisable(GL_DEPTH_TEST);
    670 }
    671  
    672422void
    673423VolumeRenderer::draw_bounding_box(float x0, float y0, float z0,
     
    793543
    794544void
    795 VolumeRenderer::activate_volume_shader(Volume* vol, bool slice_mode)
     545VolumeRenderer::activate_volume_shader(Volume* volPtr, bool slice_mode)
    796546{
    797547    //vertex shader
    798548    _stdVertexShader->bind();
    799     TransferFunction *tf  = vol->transferFunction();
    800     if (vol->volume_type() == Volume::CUBIC) {
    801         //regular cubic volume
    802         _regularVolumeShader->bind(tf->id, vol, slice_mode);
    803     } else if (vol->volume_type() == Volume::ZINCBLENDE) {
    804         _zincBlendeShader->bind(tf->id, vol, slice_mode);
     549    TransferFunction *tfPtr  = volPtr->transferFunction();
     550    if (volPtr->volume_type() == Volume::CUBIC) {
     551        Trace("regular volume shader: volume=%s tf=%s slice_mode=%d\n",
     552              volPtr->name(), tfPtr->name(), slice_mode);
     553        _regularVolumeShader->bind(tfPtr->id(), volPtr, slice_mode);
     554    } else if (volPtr->volume_type() == Volume::ZINCBLENDE) {
     555        Trace("zincblende volume shader: volume=%s tf=%s slice_mode=%d\n",
     556              volPtr->name(), tfPtr->name(), slice_mode);
     557        _zincBlendeShader->bind(tfPtr->id(), volPtr, slice_mode);
    805558    }
    806559}
     
    879632   
    880633    if (fread(&bfType, sizeof(short int), 1, f) != 1) {
    881         fprintf(stderr, "can't read %d bytes from font file \"%s\"\n",
    882                 sizeof(short int), filename);
     634        fprintf(stderr, "can't read %lu bytes from font file \"%s\"\n",
     635                (unsigned long)sizeof(short int), filename);
    883636        goto error;
    884637    }
  • trunk/packages/vizservers/nanovis/VolumeRenderer.h

    r1478 r1493  
    100100    ~VolumeRenderer();
    101101
    102     void add_volume(Volume* _vol, TransferFunction* _tf);
    103     void render(int volumeID);
    104     void render_all();  //render all enabled volumes;
    105     void render_all_points(void); //render all enabled volumes;
     102    void render_all();                  //render all enabled volumes;
    106103    void specular(float val);
    107104    void diffuse(float val);
    108     void set_slice_mode(bool val); //control independently.
     105    void set_slice_mode(bool val);      //control independently.
    109106    void set_volume_mode(bool val);
    110     void switch_slice_mode(); //switch_cutplane_mode
     107    void switch_slice_mode();           //switch_cutplane_mode
    111108    void switch_volume_mode();
    112109
  • trunk/packages/vizservers/nanovis/dxReader.cpp

    r1478 r1493  
    4747/* Load a 3D volume from a dx-format file
    4848 */
    49 bool
    50 load_volume_stream2(Rappture::Outcome &result, int volDataID, std::iostream& fin)
     49Volume *
     50load_volume_stream2(Rappture::Outcome &result, const char *tag,
     51                    std::iostream& fin)
    5152{
    52     printf("load_volume_stream2\n");
     53    printf("load_volume_stream2 %s\n", tag);
    5354    Rappture::MeshTri2D xymesh;
    5455    int dummy, nx, ny, nz, nxy, npts;
     
    118119                } else {
    119120                    result.error("triangularization failed");
    120                     return false;
     121                    return NULL;
    121122                }
    122123                unlink(fpts), unlink(fcells);
     
    143144            result.addError("don't know how to handle multiple non-zero"
    144145                            " delta values");
    145             return false;
     146            return NULL;
    146147        }
    147148            } else if (sscanf(start, "object %d class array type %s rank 0 items %d data follows", &dummy, type, &npts) == 3) {
     
    149150                    result.addError("inconsistent data: expected %d points "
    150151                                    " but found %d points", nx*ny*nz, npts);
    151                     return false;
     152                    return NULL;
    152153                } else if (!isrect && (npts != nxy*nz)) {
    153154                    result.addError("inconsistent data: expected %d points "
    154155                                    " but found %d points", nxy*nz, npts);
    155                     return false;
     156                    return NULL;
    156157                }
    157158                break;
     
    160161                    result.addError("inconsistent data: expected %d points "
    161162                                    " but found %d points", nx*ny*nz, npts);
    162                     return false;
     163                    return NULL;
    163164                }
    164165                break;
     
    172173    if (fin.eof()) {
    173174        result.addError("EOF found: expecting %d points", npts);
    174         return false;
     175        return NULL;
    175176    }
    176     Volume *volPtr = 0;
     177    Volume *volPtr = NULL;
    177178    if (isrect) {
    178179        double dval[6];
     
    220221            result.addError("inconsistent data: expected %d points "
    221222                            " but found %d points", nx*ny*nz, nread);
    222             return false;
     223            return NULL;
    223224        }
    224225       
     
    247248        dz = nz;
    248249       
    249         volPtr = NanoVis::load_volume(volDataID, nx, ny, nz, 4, data,
     250        volPtr = NanoVis::load_volume(tag, nx, ny, nz, 4, data,
    250251                                      vmin, vmax, nzero_min);
    251252        volPtr->xAxis.SetRange(x0, x0 + (nx * dx));
     
    269270                result.addError("after %d of %d points: can't read number",
    270271                                nread, npts);
    271                 return false;
     272                return NULL;
    272273            } else {
    273274                int nid = nxy*iz + ixy;
     
    286287            result.addError("inconsistent data: expected %d points "
    287288                            "but found %d points", nxy*nz, nread);
    288             return false;
     289            return NULL;
    289290        }
    290291       
     
    387388        }
    388389       
    389         volPtr = NanoVis::load_volume(volDataID, nx, ny, nz, 4, data,
    390                                       field.valueMin(), field.valueMax(), nzero_min);
     390        volPtr = NanoVis::load_volume(tag, nx, ny, nz, 4, data,
     391                field.valueMin(), field.valueMax(), nzero_min);
    391392        volPtr->xAxis.SetRange(field.rangeMin(Rappture::xaxis),
    392393                               field.rangeMax(Rappture::xaxis));
     
    409410        printf("volume moved\n");
    410411    }
    411     return true;
     412    return volPtr;
    412413}
    413414
    414 bool
    415 load_volume_stream(Rappture::Outcome &result, int volDataID, std::iostream& fin)
     415Volume *
     416load_volume_stream(Rappture::Outcome &result, const char *tag,
     417                   std::iostream& fin)
    416418{
    417419    printf("load_volume_stream\n");
     
    431433        if (fin.fail()) {
    432434            result.error("error in data stream");
    433             return false;
     435            return NULL;
    434436        }
    435437        for (start=line; *start == ' ' || *start == '\t'; start++)
     
    490492                } else {
    491493                    result.error("triangularization failed");
    492                     return false;
     494                    return NULL;
    493495                }
    494496                unlink(fpts);
     
    507509                    result.addError("inconsistent data: expected %d points"
    508510                                    " but found %d points", nx*ny*nz, npts);
    509                     return false;
     511                    return NULL;
    510512                } else if (!isrect && (npts != nxy*nz)) {
    511513                    result.addError("inconsistent data: expected %d points"
    512514                                    " but found %d points", nx*ny*nz, npts);
    513                     return false;
     515                    return NULL;
    514516                }
    515517                break;
     
    518520                    result.addError("inconsistent data: expected %d points"
    519521                                    " but found %d points", nx*ny*nz, npts);
    520                     return false;
     522                    return NULL;
    521523                }
    522524                break;
     
    527529    if (fin.eof()) {
    528530        result.error("data not found in stream");
    529         return false;
     531        return NULL;
    530532    }
    531533    Volume *volPtr = 0;
     
    545547            if (fin.fail()) {
    546548                result.addError("error reading data points");
    547                 return false;
     549                return NULL;
    548550            }
    549551            int n = sscanf(line, "%lg %lg %lg %lg %lg %lg", &dval[0], &dval[1], &dval[2], &dval[3], &dval[4], &dval[5]);
     
    568570            result.addError("inconsistent data: expected %d points"
    569571                            " but found %d points", nx*ny*nz, npts);
    570             return false;
     572            return NULL;
    571573        }
    572574       
     
    653655        }
    654656#endif 
    655         fprintf(stdout,"End Data Stats DataID = %i\n",volDataID);
    656657        fprintf(stdout,"nx = %i ny = %i nz = %i\n",nx,ny,nz);
    657658        fprintf(stdout,"dx = %lg dy = %lg dz = %lg\n",dx,dy,dz);
     
    659660        fflush(stdout);
    660661       
    661         volPtr = NanoVis::load_volume(volDataID, nx, ny, nz, 4, data,
    662                                       field.valueMin(), field.valueMax(), nzero_min);
     662        volPtr = NanoVis::load_volume(tag, nx, ny, nz, 4, data,
     663                field.valueMin(), field.valueMax(), nzero_min);
    663664        volPtr->xAxis.SetRange(field.rangeMin(Rappture::xaxis),
    664665                               field.rangeMax(Rappture::xaxis));
     
    695696                result.addError("after %d of %d points: can't read number",
    696697                                nread, npts);
    697                 return false;
     698                return NULL;
    698699            } else {
    699700                int nid = nxy*iz + ixy;
     
    712713            result.addError("inconsistent data: expected %d points"
    713714                            " but found %d points", nx*ny*nz, npts);
    714             return false;
     715            return NULL;
    715716        }
    716717       
     
    804805        }
    805806       
    806         volPtr = NanoVis::load_volume(volDataID, nx, ny, nz, 4, data,
    807                                       field.valueMin(), field.valueMax(), nzero_min);
     807        volPtr = NanoVis::load_volume(tag, nx, ny, nz, 4, data,
     808                field.valueMin(), field.valueMax(), nzero_min);
    808809        volPtr->xAxis.SetRange(field.rangeMin(Rappture::xaxis),
    809810                               field.rangeMax(Rappture::xaxis));
     
    838839        volPtr->location(Vector3(dx0, dy0, dz0));
    839840    }
    840     return true;
     841    return volPtr;
    841842}
    842843
    843844
    844 bool
    845 load_volume_stream_insoo(Rappture::Outcome &result, int volDataID,
     845Volume *
     846load_volume_stream_insoo(Rappture::Outcome &result, const char *tag,
    846847                         std::iostream& fin)
    847848{
     
    862863        if (fin.fail()) {
    863864            result.addError("line \"%s\"error in data stream");
    864             return false;
     865            return NULL;
    865866        }
    866867        for (start=line; *start == ' ' || *start == '\t'; start++)
     
    921922                } else {
    922923                    result.error("triangularization failed");
    923                     return false;
     924                    return NULL;
    924925                }
    925926                unlink(fpts), unlink(fcells);
     
    937938                    result.addError("inconsistent data: expected %d points"
    938939                                    " but found %d points", nx*ny*nz, npts);
    939                     return false;
     940                    return NULL;
    940941                } else if (!isrect && (npts != nxy*nz)) {
    941942                    result.addError("inconsistent data: expected %d points"
    942943                                    " but found %d points", nx*ny*nz, npts);
    943                     return false;
     944                    return NULL;
    944945                }
    945946                break;
     
    948949                    result.addError("inconsistent data: expected %d points"
    949950                                    " but found %d points", nx*ny*nz, npts);
    950                     return false;
     951                    return NULL;
    951952                }
    952953                break;
     
    958959    if (fin.eof()) {
    959960        result.error("data not found in stream");
    960         return false;
     961        return NULL;
    961962    }
    962963
     
    977978            if (fin.fail()) {
    978979                result.error("error reading data points");
    979                 return false;
     980                return NULL;
    980981            }
    981982            int n = sscanf(line, "%lg %lg %lg %lg %lg %lg", &dval[0], &dval[1], &dval[2], &dval[3], &dval[4], &dval[5]);
     
    10021003            result.addError("inconsistent data: expected %d points"
    10031004                            " but found %d points", nx*ny*nz, npts);
    1004             return false;
     1005            return NULL;
    10051006        }
    10061007       
     
    11321133            */
    11331134
    1134         volPtr = NanoVis::load_volume(volDataID, nx, ny, nz, 4, data,
    1135                                       field.valueMin(), field.valueMax(), nzero_min);
     1135        volPtr = NanoVis::load_volume(tag, nx, ny, nz, 4, data,
     1136                field.valueMin(), field.valueMax(), nzero_min);
    11361137        volPtr->xAxis.SetRange(field.rangeMin(Rappture::xaxis),
    11371138                               field.rangeMax(Rappture::xaxis));
     
    11701171                        nread, npts);
    11711172                result.error(mesg);
    1172                 return false;
     1173                return NULL;
    11731174            } else {
    11741175                int nid = nxy*iz + ixy;
     
    11871188            result.addError("inconsistent data: expected %d points"
    11881189                            " but found %d points", nx*ny*nz, npts);
    1189             return false;
     1190            return NULL;
    11901191        }
    11911192       
     
    12791280        }
    12801281       
    1281         volPtr = NanoVis::load_volume(volDataID, nx, ny, nz, 4, data,
    1282                                       field.valueMin(), field.valueMax(), nzero_min);
     1282        volPtr = NanoVis::load_volume(tag, nx, ny, nz, 4, data,
     1283                field.valueMin(), field.valueMax(), nzero_min);
    12831284        volPtr->xAxis.SetRange(field.rangeMin(Rappture::xaxis),
    12841285                               field.rangeMax(Rappture::xaxis));
     
    13131314        volPtr->location(Vector3(dx0, dy0, dz0));
    13141315    }
    1315     return true;
     1316    return volPtr;
    13161317}
  • trunk/packages/vizservers/nanovis/dxReader2.cpp

    r1478 r1493  
    1616/* Load a 3D volume from a dx-format file the new way
    1717 */
    18 bool
    19 load_volume_stream_odx(Rappture::Outcome &context, int userID, const char *buf,
    20                       int nBytes)
     18Volume *
     19load_volume_stream_odx(Rappture::Outcome &context, const char *tag,
     20                        const char *buf, int nBytes)
    2121{
    2222    char dxfilename[128];
     
    2424    if (nBytes <= 0) {
    2525        context.error("empty data buffer\n");
    26         return false;
     26        return NULL;
    2727    }
    2828
     
    4242        context.addError("Can't read %d bytes from file \"%s\"\n",
    4343                         nBytes, dxfilename);
    44         return false;
     44        return NULL;
    4545    }
    4646
     
    4949    if (unlink(dxfilename) != 0) {
    5050        context.addError("Error deleting dx file: %s\n", dxfilename);
    51         return false;
     51        return NULL;
    5252    }
    5353
     
    8888    computeSimpleGradient(data, nx, ny, nz);
    8989
    90     fprintf(stdout,"End Data Stats userID = %i\n",userID);
    9190    fprintf(stdout,"nx = %i ny = %i nz = %i\n",nx,ny,nz);
    9291    fprintf(stdout,"dx = %lg dy = %lg dz = %lg\n",dx,dy,dz);
     
    9594
    9695    Volume *volPtr;
    97     volPtr = NanoVis::load_volume(userID, nx, ny, nz, 4, data,
     96    volPtr = NanoVis::load_volume(tag, nx, ny, nz, 4, data,
    9897                                  dxObj.dataMin(),
    9998                                  dxObj.dataMax(),
     
    117116    float dz0 = -0.5*dz/dx;
    118117    volPtr->location(Vector3(dx0, dy0, dz0));
    119     return true;
     118    return volPtr;
    120119}
  • trunk/packages/vizservers/nanovis/nanovis.cpp

    r1484 r1493  
    7777
    7878extern void NvInitCG(); // in Shader.cpp
    79 extern bool load_vector_stream2(Rappture::Outcome &result, int index,
    80         size_t length, char *string);
    8179
    8280// Indicates "up" axis:  x=1, y=2, z=3, -x=-1, -y=-2, -z=-3
     
    107105int NanoVis::updir = Y_POS;
    108106NvCamera* NanoVis::cam = NULL;
    109 vector<Volume *>  NanoVis::volumes;
     107Tcl_HashTable NanoVis::volumeTable;
    110108vector<HeightMap*> NanoVis::heightMap;
    111109VolumeRenderer* NanoVis::vol_renderer = NULL;
     
    174172
    175173// maps transfunc name to TransferFunction object
    176 static Tcl_HashTable tftable;
     174Tcl_HashTable NanoVis::tfTable;
    177175
    178176// pointers to 2D planes, currently handle up 10
     
    513511 */
    514512Volume *
    515 NanoVis::load_volume(int dataID, int width, int height, int depth,
    516                      int n_component, float* data, double vmin,
    517                      double vmax, double nzero_min)
    518 {
    519     // Check if we're attempting to load the volume into an already
    520     // occupied slot.
    521 
    522        
    523     Volume* volPtr = new Volume(0.f, 0.f, 0.f, width, height, depth, 1.,
    524                                 n_component, data, vmin, vmax, nzero_min);
    525     if (dataID < 0) {
    526         dataID = volumes.size();
    527         volumes.push_back(volPtr);
    528     } else {
    529         int i;
    530         // Create new slots it needed.
    531         for (i = volumes.size(); i <= dataID; i++) {
    532             volumes.push_back(NULL);
    533         }
    534         assert (volumes[dataID] == NULL);
    535         volumes[dataID] = volPtr;
    536     }
    537     volPtr->dataID(dataID);
    538     fprintf(stderr, "VOLID=%d, # of volume slots=%d\n", dataID,
    539             volumes.size());
     513NanoVis::load_volume(const char *name, int width, int height, int depth,
     514                     int n_component, float* data, double vmin, double vmax,
     515                     double nzero_min)
     516{
     517    Tcl_HashEntry *hPtr;
     518    hPtr = Tcl_FindHashEntry(&NanoVis::volumeTable, name);
     519    if (hPtr != NULL) {
     520        Volume *volPtr;
     521        Trace("volume \"%s\" already exists", name);
     522        volPtr = (Volume *)Tcl_GetHashValue(hPtr);
     523        remove_volume(volPtr);
     524    }
     525    int isNew;
     526    hPtr = Tcl_CreateHashEntry(&NanoVis::volumeTable, name, &isNew);
     527    Volume* volPtr;
     528    volPtr = new Volume(0.f, 0.f, 0.f, width, height, depth, 1., n_component,
     529                data, vmin, vmax, nzero_min);
     530    Tcl_SetHashValue(hPtr, volPtr);
     531    volPtr->name(Tcl_GetHashKey(&NanoVis::volumeTable, hPtr));
    540532    return volPtr;
    541533}
     
    547539    Tcl_HashEntry *hPtr;
    548540
    549     hPtr = Tcl_FindHashEntry(&tftable, name);
     541    hPtr = Tcl_FindHashEntry(&tfTable, name);
    550542    if (hPtr == NULL) {
    551543        return NULL;
     
    560552    int isNew;
    561553    Tcl_HashEntry *hPtr;
    562     TransferFunction *tf;
    563 
    564     hPtr = Tcl_CreateHashEntry(&tftable, name, &isNew);
     554    TransferFunction *tfPtr;
     555
     556    hPtr = Tcl_CreateHashEntry(&tfTable, name, &isNew);
    565557    if (isNew) {
    566         tf = new TransferFunction(n, data);
    567         Tcl_SetHashValue(hPtr, (ClientData)tf);
     558        tfPtr = new TransferFunction(n, data);
     559        tfPtr->name(Tcl_GetHashKey(&tfTable, hPtr));
     560        Tcl_SetHashValue(hPtr, tfPtr);
    568561    } else {
    569562        /*
     
    571564         * objects may be holding its pointer.  We must update it.
    572565         */
    573         tf = (TransferFunction *)Tcl_GetHashValue(hPtr);
    574         tf->update(n, data);
    575     }
    576     return tf;
     566        tfPtr = (TransferFunction *)Tcl_GetHashValue(hPtr);
     567        tfPtr->update(n, data);
     568    }
     569    return tfPtr;
    577570}
    578571
     
    916909
    917910    // init table of transfer functions
    918     Tcl_InitHashTable(&tftable, TCL_STRING_KEYS);
     911    Tcl_InitHashTable(&tfTable, TCL_STRING_KEYS);
    919912
    920913    //check if performance query is supported
     
    15421535    xMin = yMin = zMin = wMin = DBL_MAX;
    15431536    xMax = yMax = zMax = wMax = -DBL_MAX;
    1544     vector<Volume *>::iterator iter;
    1545     for (iter = volumes.begin(); iter != volumes.end(); ++iter) {
     1537    Tcl_HashEntry *hPtr;
     1538    Tcl_HashSearch iter;
     1539    for (hPtr = Tcl_FirstHashEntry(&volumeTable, &iter); hPtr != NULL;
     1540         hPtr = Tcl_NextHashEntry(&iter)) {
    15461541        Volume *volPtr;
    15471542
    1548         volPtr = (*iter);
    1549         if (volPtr == NULL) {
    1550             continue;                   // Empty slot.
    1551         }
     1543        volPtr = (Volume *)Tcl_GetHashValue(hPtr);
    15521544        if (xMin > volPtr->xAxis.min()) {
    15531545            xMin = volPtr->xAxis.min();
     
    25552547
    25562548void
    2557 NanoVis::remove_volume(size_t index)
    2558 {
    2559     fprintf(stderr, "index=%d #volumes=%d\n", index, volumes.size());
    2560     assert(index < volumes.size());
    2561     Volume* volPtr;
    2562     volPtr = volumes[index];
    2563     if (volPtr == NULL)  {
    2564         return;                         // Empty slot
    2565     }
    2566     delete volPtr;                      // Delete the volume and mark the
    2567     volumes[index] = NULL;              // slot as empty.
     2549NanoVis::remove_volume(Volume *volPtr)
     2550{
     2551    Tcl_HashEntry *hPtr;
     2552    hPtr = Tcl_FindHashEntry(&volumeTable, volPtr->name());
     2553    if (hPtr != NULL) {
     2554        Tcl_DeleteHashEntry(hPtr);
     2555    }
     2556    delete volPtr;                     
    25682557}
    25692558
  • trunk/packages/vizservers/nanovis/nanovis.h

    r1484 r1493  
    4343#include "global.h"
    4444#include "socket/Socket.h"
     45#include "rappture.h"
    4546#include "NvCamera.h"
    4647#include "ConvexPolygon.h"
     
    131132    static vector<HeightMap*> heightMap;
    132133    static unsigned char* screen_buffer;
    133     static vector<Volume *> volumes;
     134    static Tcl_HashTable volumeTable;
    134135    static vector<NvVectorField*> flow;
    135136    static Grid* grid;
    136137    static R2Fonts* fonts;
    137     static int n_volumes;
    138138    static int updir;
    139139    static NvCamera *cam;
     
    155155    static Tcl_DString cmdbuffer;
    156156
    157     static int _last_data_id;
    158157public :
    159158    static TransferFunction* get_transfunc(const char *name);
     
    184183    static int render_legend(TransferFunction *tf, double min, double max,
    185184        int width, int height, const char* volArg);
    186     static Volume *load_volume(int volDataID, int width, int height, int depth,
    187         int n, float* data, double vmin, double vmax, double nzero_min);
     185    static Volume *load_volume(const char *tag, int width, int height,
     186                int depth, int n, float* data, double vmin, double vmax,
     187                double nzero_min);
    188188    static void xinetd_listen(void);
    189189    static int render_2d_contour(HeightMap* heightmap, int width, int height);
     
    233233    };
    234234    static void EventuallyRedraw(unsigned int flag = 0);
    235     static void remove_volume(size_t index);
    236     static int generate_data_identifier();
     235    static void remove_volume(Volume *volPtr);
     236    static Tcl_HashTable tfTable;
    237237};
    238238
     239extern Volume *load_volume_stream(Rappture::Outcome &status, const char *tag,
     240                        std::iostream& fin);
     241extern Volume *load_volume_stream_odx(Rappture::Outcome &status,
     242        const char *tag, const char *buf, int nBytes);
     243extern Volume *load_volume_stream2(Rappture::Outcome &status, const char *tag,
     244        std::iostream& fin);
     245
     246extern Volume *load_vector_stream(Rappture::Outcome &result, const char *tag,
     247        size_t length, char *bytes);
     248extern Volume *load_vector_stream2(Rappture::Outcome &result, const char *tag,
     249        size_t length, char *bytes);
     250
    239251
    240252#endif  /* __NANOVIS_H__ */
Note: See TracChangeset for help on using the changeset viewer.