Ignore:
Timestamp:
May 30, 2009, 8:07:17 PM (15 years ago)
Author:
gah
Message:

Fix volume management routines to handle deletion

File:
1 edited

Legend:

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

    r1475 r1478  
    1717
    1818#include <assert.h>
     19#include <errno.h>
    1920#include <fcntl.h>
    2021#include <fstream>
     
    106107int NanoVis::updir = Y_POS;
    107108NvCamera* NanoVis::cam = NULL;
    108 NanoVis::VolumeMap NanoVis::volumeMap;
    109 int  NanoVis::_last_data_id = 0;
     109vector<Volume *>  NanoVis::volumes;
    110110vector<HeightMap*> NanoVis::heightMap;
    111 VolumeRenderer* NanoVis::vol_renderer = 0;
    112 PointSetRenderer* NanoVis::pointset_renderer = 0;
     111VolumeRenderer* NanoVis::vol_renderer = NULL;
     112PointSetRenderer* NanoVis::pointset_renderer = NULL;
    113113vector<PointSet*> NanoVis::pointSet;
    114 PlaneRenderer* NanoVis::plane_render = 0;
     114PlaneRenderer* NanoVis::plane_render = NULL;
    115115Texture2D* NanoVis::plane[10];
    116116NvColorTableRenderer* NanoVis::color_table_renderer = NULL;
     
    426426    if (path == NULL) {
    427427        fprintf(stderr, "can't find program \"%s\"\n", fileName);
    428         assert(path != NULL);
    429     }
    430     printf("cg program compiling: %s\n", path);
     428        Trace("can't find program \"%s\"\n", fileName);
     429    }
     430    Trace("cg program compiling: %s\n", path);
    431431    fflush(stdout);
    432432    CGprogram program;
     
    434434                                      entryPoint, NULL);
    435435    cgGLLoadProgram(program);
    436 
    437436    CGerror LastError = cgGetError();
    438     if (LastError)
    439         {
    440             printf("Error message: %s\n", cgGetLastListing(context));
    441         }
    442 
     437    if (LastError) {
     438        printf("Error message: %s\n", cgGetLastListing(context));
     439        Trace("Error message: %s\n", cgGetLastListing(context));
     440    }
     441    Trace("successfully compiled program: %s\n", path);
    443442    delete [] path;
    444 
    445443    return program;
    446444}
     
    514512 */
    515513Volume *
    516 NanoVis::load_volume(int volDataID, int width, int height, int depth,
     514NanoVis::load_volume(int dataID, int width, int height, int depth,
    517515                     int n_component, float* data, double vmin,
    518516                     double vmax, double nzero_min)
    519517{
    520     NanoVis::VolumeMap::iterator iter  = volumeMap.find(volDataID);
    521     if (iter != volumeMap.end())
    522     {
    523         Volume* vol = iter->second;
    524         if (vol != NULL)
    525         {
    526             iter->second = NULL;
    527 
    528             if (vol->pointsetIndex != -1)
    529             {
    530                 // TBD
    531                 /*
    532                 if (((unsigned  int) vol->pointsetIndex) < pointSet.size() &&
    533                     pointSet[vol->pointsetIndex] != NULL) {
    534                     delete pointSet[vol->pointsetIndex];
    535                     pointSet[vol->pointsetIndex] = 0;
    536                 }
    537                 */
    538             }
    539         }
    540         vol->unref();
    541     }
    542 
    543     Volume* newVol = new Volume(0.f, 0.f, 0.f, width, height, depth, 1.,
    544                                n_component, data, vmin, vmax, nzero_min);
    545     newVol->setDataID(volDataID);
    546     volumeMap[volDataID] = newVol;
    547    
    548    
    549     fprintf(stderr, "VOLID=%d, # of volumes=%d\n", volDataID, volumeMap.size());
    550     return newVol;
     518    // Check if we're attempting to load the volume into an already
     519    // occupied slot.
     520
     521       
     522    Volume* volPtr = new Volume(0.f, 0.f, 0.f, width, height, depth, 1.,
     523                                n_component, data, vmin, vmax, nzero_min);
     524    if (dataID < 0) {
     525        dataID = volumes.size();
     526        volumes.push_back(volPtr);
     527    } else {
     528        int i;
     529        // Create new slots it needed.
     530        for (i = volumes.size(); i <= dataID; i++) {
     531            volumes.push_back(NULL);
     532        }
     533        assert (volumes[dataID] == NULL);
     534        volumes[dataID] = volPtr;
     535    }
     536    volPtr->dataID(dataID);
     537    fprintf(stderr, "VOLID=%d, # of volume slots=%d\n", dataID,
     538            volumes.size());
     539    return volPtr;
    551540}
    552541
     
    12411230        srcRowPtr += bytesPerRow;
    12421231    }
    1243     writev(0, iov, nRecs);
     1232    if (writev(0, iov, nRecs) < 0) {
     1233        fprintf(stderr, "write failed: %s\n", strerror(errno));
     1234    }
    12441235    free(iov);
    12451236    stats.nFrames++;
     
    12811272    iov[1].iov_base = (char *)data;
    12821273    iov[1].iov_len = dlen;
    1283     writev(0, iov, nRecs);
     1274    if (writev(0, iov, nRecs) < 0) {
     1275        fprintf(stderr, "write failed: %s\n", strerror(errno));
     1276    }
    12841277    free(iov);
    12851278    // stats.nFrames++;
     
    15471540    xMin = yMin = zMin = wMin = DBL_MAX;
    15481541    xMax = yMax = zMax = wMax = -DBL_MAX;
    1549     NanoVis::VolumeMap::iterator iter;
    1550     for (iter = volumeMap.begin(); iter != volumeMap.end(); ++iter)
    1551     {
    1552         Volume *volPtr = iter->second;
    1553 
     1542    vector<Volume *>::iterator iter;
     1543    for (iter = volumes.begin(); iter != volumes.end(); ++iter) {
     1544        Volume *volPtr;
     1545
     1546        volPtr = (*iter);
    15541547        if (volPtr == NULL) {
    1555             continue;
    1556         }
    1557         if (!volPtr->visible()) {
    1558             continue;
     1548            continue;                   // Empty slot.
    15591549        }
    15601550        if (xMin > volPtr->xAxis.min()) {
     
    18791869            volPtr->disable_cutplane(1);
    18801870            volPtr->disable_cutplane(2);
    1881            
    1882             NanoVis::vol_renderer->add_volume(volPtr,
    1883                 NanoVis::get_transfunc("default"));
     1871            volPtr->transferFunction(NanoVis::get_transfunc("default"));
     1872
    18841873            float dx0 = -0.5;
    18851874            float dy0 = -0.5*volPtr->height/volPtr->width;
     
    22782267        iov[2].iov_len = 1;
    22792268        iov[2].iov_base = (char *)'\n';
    2280         writev(0, iov, 3);
     2269        if (writev(0, iov, 3) < 0) {
     2270            fprintf(stderr, "write failed: %s\n", strerror(errno));
     2271        }
    22812272        if (debug_flag) {
    22822273            fprintf(stderr, "leaving xinetd_listen\n");
     
    25572548}
    25582549
    2559 int NanoVis::generate_data_identifier()
    2560 {
    2561     return _last_data_id++;
    2562 }
    2563 
    2564 void NanoVis::remove_volume(int volDataID)
    2565 {
    2566 
    2567     NanoVis::VolumeMap::iterator iter  = volumeMap.find(volDataID);
    2568     if (iter != volumeMap.end())
    2569     {
    2570         (*iter).second->unref();
    2571         volumeMap.erase(iter);
    2572     }
    2573 }
     2550void
     2551NanoVis::remove_volume(size_t index)
     2552{
     2553    fprintf(stderr, "index=%d #volumes=%d\n", index, volumes.size());
     2554    assert(index < volumes.size());
     2555    Volume* volPtr;
     2556    volPtr = volumes[index];
     2557    if (volPtr == NULL)  {
     2558        return;                         // Empty slot
     2559    }
     2560    delete volPtr;                      // Delete the volume and mark the
     2561    volumes[index] = NULL;              // slot as empty.
     2562}
Note: See TracChangeset for help on using the changeset viewer.