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

Changed vector id to name

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.