Changeset 1475 for trunk/packages


Ignore:
Timestamp:
May 29, 2009, 1:13:42 PM (15 years ago)
Author:
vrinside
Message:

mofified a way of dealing with volumes by adding reference counts to data objects.

  • To-do : check any memory leaks for graphics objects
Location:
trunk/packages/vizservers/nanovis
Files:
15 edited

Legend:

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

    r1474 r1475  
    363363/*
    364364 * ----------------------------------------------------------------------
    365  * FUNCTION: GetVolumeIndex
     365 * FUNCTION: GetVolumeDataID
    366366 *
    367367 * Used internally to decode a series of volume index values and
     
    375375 */
    376376static int
    377 GetVolumeIndex(Tcl_Interp *interp, Tcl_Obj *objPtr, unsigned int *indexPtr)
    378 {
    379     int index;
    380     if (Tcl_GetIntFromObj(interp, objPtr, &index) != TCL_OK) {
     377GetVolumeDataID(Tcl_Interp *interp, Tcl_Obj *objPtr, unsigned int *dataIDPtr)
     378{
     379    int volDataID;
     380    if (Tcl_GetIntFromObj(interp, objPtr, &volDataID) != TCL_OK) {
    381381        return TCL_ERROR;
    382382    }
     
    386386        return TCL_ERROR;
    387387    }
     388        /*
    388389    if (index >= (int)NanoVis::volume.size()) {
    389390        Tcl_AppendResult(interp, "index \"", Tcl_GetString(objPtr),
     
    391392        return TCL_ERROR;
    392393    }
    393     *indexPtr = (unsigned int)index;
     394        */
     395
     396    NanoVis::VolumeMap::iterator iter = NanoVis::volumeMap.find(volDataID);
     397    if (iter == NanoVis::volumeMap.end())
     398    {
     399        Tcl_AppendResult(interp, "dataID \"", Tcl_GetString(objPtr),
     400                     "\" is out found", (char*)NULL);
     401        return TCL_ERROR;
     402    }
     403
     404    *dataIDPtr = (unsigned int)volDataID;
    394405    return TCL_OK;
    395406}
     
    411422GetVolumeFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, Volume **volPtrPtr)
    412423{
    413     unsigned int index;
    414     if (GetVolumeIndex(interp, objPtr, &index) != TCL_OK) {
     424    unsigned int volDataID;
     425    if (GetVolumeDataID(interp, objPtr, &volDataID) != TCL_OK) {
    415426        return TCL_ERROR;
    416427    }
    417428    Volume *vol;
    418     vol = NanoVis::volume[index];
     429    vol = NanoVis::volumeMap[volDataID];
    419430    if (vol == NULL) {
    420         Tcl_AppendResult(interp, "no volume defined for index \"",
     431        Tcl_AppendResult(interp, "no volume defined for volDataID \"",
    421432                         Tcl_GetString(objPtr), "\"", (char*)NULL);
    422433        return TCL_ERROR;
    423434    }
    424435    *volPtrPtr = vol;
     436    //printf("volume [%d] found\n", vol->getDataID());
    425437    return TCL_OK;
    426438}
     
    428440/*
    429441 * ----------------------------------------------------------------------
    430  * FUNCTION: GetVolumeIndices()
     442 * FUNCTION: GetVolumeDataIDs()
    431443 *
    432444 * Used internally to decode a series of volume index values and
     
    440452 */
    441453static int
    442 GetVolumeIndices(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv,
     454GetVolumeDataIDs(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv,
    443455                 vector<unsigned int>* vectorPtr)
    444456{
    445457    if (objc == 0) {
    446         for (unsigned int n = 0; n < NanoVis::volume.size(); n++) {
    447             if (NanoVis::volume[n] != NULL) {
    448                 vectorPtr->push_back(n);
    449             }
     458        NanoVis::VolumeMap::iterator iter;
     459        for (iter = NanoVis::volumeMap.begin(); iter != NanoVis::volumeMap.end(); ++iter) {
     460                if ((*iter).second != NULL) {
     461                        vectorPtr->push_back((*iter).first);
     462                }
    450463        }
    451464    } else {
     465        NanoVis::VolumeMap::iterator iter;
    452466        for (int n = 0; n < objc; n++) {
    453             unsigned int index;
    454 
    455             if (GetVolumeIndex(interp, objv[n], &index) != TCL_OK) {
     467            unsigned int volDataID;
     468
     469            if (GetVolumeDataID(interp, objv[n], &volDataID) != TCL_OK) {
    456470                return TCL_ERROR;
    457471            }
    458             if (NanoVis::volume[index] != NULL) {
    459                 vectorPtr->push_back(index);
     472
     473            iter = NanoVis::volumeMap.find(volDataID);
     474            if ((iter != NanoVis::volumeMap.end()) && ((*iter).second != 0)) {
     475                vectorPtr->push_back(volDataID);
    460476            }
    461477        }
     
    482498{
    483499    if (objc == 0) {
    484         for (unsigned int n = 0; n < NanoVis::volume.size(); n++) {
    485             if (NanoVis::volume[n] != NULL) {
    486                 vectorPtr->push_back(NanoVis::volume[n]);
     500       NanoVis::VolumeMap::iterator iter;
     501        for (iter = NanoVis::volumeMap.begin(); iter != NanoVis::volumeMap.end(); ++iter) {
     502            if ((*iter).second != NULL) {
     503                vectorPtr->push_back((*iter).second);
    487504            }
    488505        }
     
    11851202{
    11861203    vector<unsigned int> ivol;
    1187     if (GetVolumeIndices(interp, objc - 3, objv + 3, &ivol) != TCL_OK) {
    1188         return TCL_ERROR;
    1189     }
    1190     Trace("parsing volume index\n");
     1204    if (GetVolumeDataIDs(interp, objc - 3, objv + 3, &ivol) != TCL_OK) {
     1205        return TCL_ERROR;
     1206    }
     1207    Trace("parsing volume data identifier\n");
    11911208    vector<unsigned int>::iterator iter;
    11921209    for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    1193         Trace("index: %d\n", *iter);
    1194         NanoVis::vol_renderer->addAnimatedVolume(NanoVis::volume[*iter], *iter);
     1210        Trace("volDataID: %d\n", *iter);
     1211        NanoVis::vol_renderer->addAnimatedVolume(NanoVis::volumeMap[*iter], *iter);
    11951212    }
    11961213    return TCL_OK;
     
    12391256        return TCL_ERROR;
    12401257    }
    1241     int n = NanoVis::n_volumes;
    12421258    char header[6];
    12431259    memcpy(header, buf.bytes(), sizeof(char) * 5);
     
    12601276    printf("Checking header[%s]\n", header);
    12611277    fflush(stdout);
     1278
     1279    Volume *volPtr = 0;
     1280    int volDataID = -1;
    12621281    if (strcmp(header, "<HDR>") == 0) {
    1263         Volume* vol = NULL;
    1264 
    12651282        printf("ZincBlende stream is in\n");
    12661283        fflush(stdout);
     
    12701287
    12711288#if _LOCAL_ZINC_TEST_
    1272         vol = NvZincBlendeReconstructor::getInstance()->loadFromMemory(b);
     1289        volPtr = NvZincBlendeReconstructor::getInstance()->loadFromMemory(b);
    12731290#else
    1274         vol = NvZincBlendeReconstructor::getInstance()->loadFromMemory((void*) buf.bytes());
     1291        volPtr = NvZincBlendeReconstructor::getInstance()->loadFromMemory((void*) buf.bytes());
    12751292#endif  /*_LOCAL_ZINC_TEST_*/
    1276         if (vol == NULL) {
     1293        if (volPtr == NULL) {
    12771294            Tcl_AppendResult(interp, "can't get volume instance", (char *)NULL);
    12781295            return TCL_OK;
     
    12801297        printf("finish loading\n");
    12811298        fflush(stdout);
    1282         while (NanoVis::n_volumes <= n) {
    1283             NanoVis::volume.push_back((Volume*) NULL);
    1284             NanoVis::n_volumes++;
    1285         }
    1286 
    1287         if (NanoVis::volume[n] != NULL) {
    1288             delete NanoVis::volume[n];
    1289             NanoVis::volume[n] = NULL;
     1299
     1300        // INSOO
     1301        // TBD..
     1302        volDataID = NanoVis::generate_data_identifier();
     1303        NanoVis::VolumeMap::iterator iter;
     1304        iter = NanoVis::volumeMap.find(volDataID);
     1305        if (iter != NanoVis::volumeMap.end())
     1306        {
     1307            if (iter->second != NULL) {
     1308                iter->second->unref();
     1309                iter->second = 0;
     1310            }
    12901311        }
    12911312
    12921313        float dx0 = -0.5;
    1293         float dy0 = -0.5*vol->height/vol->width;
    1294         float dz0 = -0.5*vol->depth/vol->width;
    1295         vol->move(Vector3(dx0, dy0, dz0));
    1296 
    1297         NanoVis::volume[n] = vol;
     1314        float dy0 = -0.5*volPtr->height/volPtr->width;
     1315        float dz0 = -0.5*volPtr->depth/volPtr->width;
     1316        volPtr->move(Vector3(dx0, dy0, dz0));
     1317
     1318        NanoVis::volumeMap[volDataID] = volPtr;
    12981319#if __TEST_CODE__
    12991320    } else if (strcmp(header, "<FET>") == 0) {
     
    13081329#endif  /*__TEST_CODE__*/
    13091330    } else if (strcmp(header, "<ODX>") == 0) {
     1331        /*
    13101332        Rappture::Outcome err;
    13111333
     
    13161338            return TCL_ERROR;
    13171339        }
     1340        */
    13181341    } else {
     1342        volDataID = NanoVis::generate_data_identifier();
     1343        printf("test\n");
    13191344#ifdef notdef
    13201345        Rappture::Unirect3d *dataPtr;
     
    13291354        dataPtr->Resample(context, 30);
    13301355#endif
    1331         Volume *volPtr;
    1332         volPtr = NanoVis::load_volume(index, nx, ny, nz, 4, data, vmin, vmax,
     1356        volPtr = NanoVis::load_volume(volDataID, nx, ny, nz, 4, data, vmin, vmax,
    13331357                                  nzero_min);
    13341358   
     
    13531377        Rappture::Outcome context;
    13541378#if ISO_TEST
    1355         result = load_volume_stream2(context, n, fdata);
     1379        result = load_volume_stream2(context, volDataID, fdata);
    13561380#else
    1357         result = load_volume_stream(context, n, fdata);
     1381        result = load_volume_stream(context, volDataID, fdata);
    13581382#endif
    13591383        if (!result) {
     
    13611385            return TCL_ERROR;
    13621386        }
     1387        volPtr = NanoVis::volumeMap[volDataID];
    13631388    }
    13641389
     
    13691394    // overwrite the first, so the first won't appear at all.
    13701395    //
    1371     if (NanoVis::volume[n] != NULL) {
    1372         //NanoVis::volume[n]->set_n_slice(512-n);
    1373         NanoVis::volume[n]->set_n_slice(256-n);
    1374         NanoVis::volume[n]->disable_cutplane(0);
    1375         NanoVis::volume[n]->disable_cutplane(1);
    1376         NanoVis::volume[n]->disable_cutplane(2);
    1377 
    1378         NanoVis::vol_renderer->add_volume(NanoVis::volume[n],
     1396    if (volPtr != NULL) {
     1397        //volPtr->set_n_slice(512-n);
     1398        //volPtr->set_n_slice(256-n);
     1399        volPtr->set_n_slice(256);
     1400        volPtr->disable_cutplane(0);
     1401        volPtr->disable_cutplane(1);
     1402        volPtr->disable_cutplane(2);
     1403
     1404        NanoVis::vol_renderer->add_volume(volPtr,
    13791405                                          NanoVis::get_transfunc("default"));
    1380     }
    1381 
    1382     {
    1383         Volume *volPtr;
     1406
    13841407        char info[1024];
    13851408        ssize_t nWritten;
     
    13881411            NanoVis::SetVolumeRanges();
    13891412        }
    1390         volPtr = NanoVis::volume[n];
     1413
    13911414        // FIXME: strlen(info) is the return value of sprintf
    13921415        sprintf(info, "nv>data tag %s id %d min %g max %g vmin %g vmax %g\n",
    1393                 tag, n, volPtr->wAxis.min(), volPtr->wAxis.max(),
     1416                tag, volDataID, volPtr->wAxis.min(), volPtr->wAxis.max(),
    13941417                Volume::valueMin, Volume::valueMax);
    13951418        nWritten  = write(0, info, strlen(info));
     
    16831706             Tcl_Obj *const *objv)
    16841707{
    1685     NanoVis::volume[1]->data(false);
    1686     NanoVis::volume[1]->visible(false);
     1708    NanoVis::VolumeMap::iterator iter = NanoVis::volumeMap.find(1);
     1709    if (iter != NanoVis::volumeMap.end())
     1710    {
     1711        NanoVis::volumeMap[1]->data(false);
     1712        NanoVis::volumeMap[1]->visible(false);
     1713    }
    16871714    return TCL_OK;
    16881715}
     
    24132440        NanoVis::SetHeightmapRanges();
    24142441    }
     2442
    24152443    NanoVis::render_legend(tf, HeightMap::valueMin, HeightMap::valueMax, w, h,
    2416         "label");
     2444       "label");
    24172445    return TCL_OK;
    24182446}
  • trunk/packages/vizservers/nanovis/FlowCmd.cpp

    r1474 r1475  
    272272    _interp = interp;
    273273    _hashPtr = hPtr;
    274     _volIndex = -1;                     /* Indicates that no volume slot has
     274    _volDataID = -1;                    /* Indicates that no volume slot has
    275275                                         * been allocated for this vector. */
    276276    _sv.sliceVisible = 1;
     
    296296    }
    297297     if (_volPtr != NULL) {
    298         delete _volPtr;
     298        _volPtr->unref();
    299299        _volPtr = NULL;
    300         NanoVis::volume[_volIndex] = NULL;
    301         NanoVis::vol_renderer->remove_volume(_volIndex);
     300        NanoVis::remove_volume(_volDataID);
     301        NanoVis::vol_renderer->remove_volume(_volDataID);
    302302    }
    303303
     
    500500{
    501501    if (_volPtr != NULL) {
    502         delete _volPtr;
     502        _volPtr->unref();
    503503        _volPtr = NULL;
    504         NanoVis::volume[_volIndex] = NULL;
    505         NanoVis::vol_renderer->remove_volume(_volIndex);
     504        NanoVis::remove_volume(_volDataID);
     505        NanoVis::vol_renderer->remove_volume(_volDataID);
    506506    }
    507507    // Remove the associated vector field.
     
    528528{
    529529    if (_volPtr != NULL) {
    530         delete _volPtr;
     530        _volPtr->unref();
    531531        _volPtr = NULL;
    532         NanoVis::volume[_volIndex] = NULL;
    533         NanoVis::vol_renderer->remove_volume(_volIndex);
     532        NanoVis::remove_volume(_volDataID);
     533        NanoVis::vol_renderer->remove_volume(_volDataID);
    534534    }
    535535    float *vdata;
     
    632632FlowCmd::MakeVolume(float *data)
    633633{
    634     if (_volIndex < 0) {
    635         _volIndex = NanoVis::n_volumes;
    636         Trace("VolumeIndex is %d\n", _volIndex);
     634    if (_volDataID < 0) {
     635        _volDataID = NanoVis::generate_data_identifier();
     636        Trace("VolumeDataID is %d\n", _volDataID);
    637637    }
    638638    Volume *volPtr;
    639     volPtr = NanoVis::load_volume(_volIndex, _dataPtr->xNum(),
     639    volPtr = NanoVis::load_volume(_volDataID, _dataPtr->xNum(),
    640640        _dataPtr->yNum(), _dataPtr->zNum(), 4, data,
    641641        NanoVis::magMin, NanoVis::magMax, 0);
     
    650650    volPtr->setPhysicalBBox(physicalMin, physicalMax);
    651651
    652     volPtr->set_n_slice(256 - _volIndex);
     652    //volPtr->set_n_slice(256 - _volIndex);
    653653    // volPtr->set_n_slice(512- _volIndex);
     654    // TBD..
     655    volPtr->set_n_slice(256);
    654656    volPtr->disable_cutplane(0);
    655657    volPtr->disable_cutplane(1);
  • trunk/packages/vizservers/nanovis/FlowCmd.h

    r1474 r1475  
    169169                                         * flow.  This isn't the same thing as
    170170                                         * a normal volume displayed. */
    171     int _volIndex;                      /* The index of slot in the volume
     171    int _volDataID;                     /* The index of slot in the volume
    172172                                         * vector. -1 indicates that a slot
    173173                                         * hasn't been previously allocated.
  • trunk/packages/vizservers/nanovis/R2/include/R2/R2Object.h

    r580 r1475  
    3737        --_referenceCount;
    3838    }
    39     delete this;
     39
     40    if (_referenceCount <= 0) delete this;
    4041}
    4142
  • trunk/packages/vizservers/nanovis/TransferFunction.cpp

    r973 r1475  
    5151TransferFunction::update(int size, float *data)
    5252{
    53     assert((size*4) == _size);
     53    // TBD..
     54    //assert((size*4) == _size);
    5455    update(data);
    5556}
  • trunk/packages/vizservers/nanovis/TransferFunction.h

    r973 r1475  
    2020
    2121#include "Texture1D.h"
     22#include <R2/R2Object.h>
    2223
    2324
    24 class TransferFunction{
     25class TransferFunction : public R2Object {
    2526    int _size;                  //the resolution of the color map, how many
    2627                                //(RGBA) quadraples
     
    2829    Texture1D* _tex;            //the texture storing the colors
    2930   
     31protected :
     32    ~TransferFunction();
    3033public:
    3134    GLuint id;                  //OpenGL's texture identifier
    3235
    3336    TransferFunction(int size, float *data);
    34     ~TransferFunction();
    3537    void update(float *data);
    3638    void update(int size, float *data);
     
    4143        return _data;
    4244    }
     45    int getSize() const;
    4346};
    4447
     48inline int TransferFunction::getSize() const
     49{
     50    return _size;
     51}
    4552#endif
  • trunk/packages/vizservers/nanovis/Volume.cpp

    r1474 r1475  
    4646    iso_surface(0)
    4747{
     48    _volumeDataID = -1;
     49
    4850    tex = new Texture3D(w, h, d, NVIS_FLOAT, NVIS_LINEAR_INTERP, n);
    4951    int fcount = width * height * depth * n_components;
  • trunk/packages/vizservers/nanovis/Volume.h

    r1474 r1475  
    2525#include "Vector3.h"
    2626#include "AxisRange.h"
     27#include "R2/R2Object.h"
    2728
    2829struct CutPlane{
     
    3940enum {CUBIC, VOLQD, ZINCBLENDE};
    4041
    41 class Volume {
     42class Volume : public R2Object {
    4243public:
     44    int                         _volumeDataID;
     45
    4346    int width;                  // The resolution of the data (how many points
    4447                                // in each direction.
     
    103106    int iso_surface;
    104107
     108public :
    105109    Volume(float x, float y, float z, int width, int height, int depth,
    106110           float size, int n_component, float* data, double vmin, double vmax,
    107111           double nonzero_min);
    108112
    109  
     113protected :
    110114    ~Volume();
    111115       
     116public :
    112117    void visible(bool value) {
    113118        enabled = value;
     
    183188    Vector3& getPhysicalBBoxMin();
    184189    Vector3& getPhysicalBBoxMax();
     190
     191    void setDataID(int id);
     192    int getDataID() const;
    185193};
    186194
     
    314322}
    315323
     324inline void
     325Volume::setDataID(int id)
     326{
     327        _volumeDataID = id;
     328}
     329
     330inline int
     331Volume::getDataID() const
     332{
     333        return _volumeDataID;
     334}
     335
    316336#endif
  • trunk/packages/vizservers/nanovis/VolumeInterpolator.cpp

    r1474 r1475  
    120120    _volumes.clear();
    121121
    122     if (_volume) delete _volume;
     122    if (_volume) _volume->unref();
    123123}
    124124
  • trunk/packages/vizservers/nanovis/VolumeRenderer.cpp

    r1474 r1475  
    2929
    3030VolumeRenderer::VolumeRenderer():
    31   n_volumes(0),
    3231  slice_mode(false),
    3332  volume_mode(true)
    3433{
    35     volume.clear();
    36     tf.clear();
     34    volumes.clear();
    3735
    3836    init_shaders();
     
    5048VolumeRenderer::~VolumeRenderer()
    5149{
     50    remove_all_volumes();
     51
    5252    delete _zincBlendeShader;
    5353    delete _regularVolumeShader;
     
    7676}
    7777
    78 
    79 int
    80 VolumeRenderer::add_volume(Volume* _vol, TransferFunction* _tf)
    81 {
    82   volume.push_back(_vol);
    83   tf.push_back(_tf);
    84 
    85   int ret = n_volumes;
    86   n_volumes++;
    87   return ret;
     78void
     79VolumeRenderer::remove_all_volumes()
     80{
     81    vector<VolumeData*>::iterator iter;
     82    for (iter = volumes.begin(); iter != volumes.end(); ++iter)
     83    {
     84        delete (*iter);
     85    }
     86    volumes.clear();
     87}
     88
     89void
     90VolumeRenderer::add_volume(Volume* vol, TransferFunction* tf)
     91{
     92    VolumeData * volData = new VolumeData(vol, tf);
     93    volumes.push_back(volData);
     94    printf("volume[%d] added\n", volData->volume->getDataID());
    8895}
    8996
     
    99106 */
    100107void
    101 VolumeRenderer::remove_volume(size_t volIndex)
    102 {
    103     vector<Volume *>::iterator vIter;
    104     vector<TransferFunction *>::iterator tfIter;
    105 
    106     assert(volIndex < volume.size());
    107     assert(volIndex < tf.size());
    108 
    109     vIter = volume.begin();
    110     tfIter = tf.begin();
    111     size_t i;
    112     for (i = 0; i < volIndex; i++) {
    113         tfIter++;
    114         vIter++;
    115     }
    116     volume.erase(vIter);
    117     tf.erase(tfIter);
    118     n_volumes--;
     108VolumeRenderer::remove_volume(size_t volDataID)
     109{
     110    std::vector<VolumeData*>::iterator iter;
     111    for (iter = volumes.begin(); iter != volumes.end(); ++iter)
     112    {
     113        if ((*iter)->volume->getDataID() == volDataID)
     114        {
     115                delete (*iter);
     116                volumes.erase(iter);
     117                break;
     118        }
     119    }
    119120}
    120121
     
    122123VolumeRenderer::shade_volume(Volume* _vol, TransferFunction* _tf)
    123124{
    124     for (unsigned int i=0; i < volume.size(); i++) {
    125         if (volume[i] == _vol) {
    126             tf[i] = _tf;
    127         }
    128     }
    129 }
     125    if (_vol == 0) printf("shade volume : null vol parameter\n");
     126    for (unsigned int i=0; i < volumes.size(); i++) {
     127        if (volumes[i]->volume == _vol) {
     128            if (_tf != volumes[i]->tf)
     129            {
     130                _tf->ref();
     131
     132                if (volumes[i]->tf)
     133                    volumes[i]->tf->unref();
     134
     135                volumes[i]->tf = _tf;
     136                printf("transfer function changed [volid %d]\n", volumes[i]->volume->getDataID());
     137            }
     138        }
     139    }
     140}
     141
    130142
    131143TransferFunction*
    132144VolumeRenderer::get_volume_shading(Volume* _vol)
    133145{
    134     for (unsigned int i=0; i < volume.size(); i++) {
    135         if (volume[i] == _vol) {
    136             return tf[i];
     146    for (unsigned int i=0; i < volumes.size(); i++) {
     147        if (volumes[i]->volume == _vol) {
     148            return volumes[i]->tf;
    137149        }
    138150    }
    139151    return NULL;
    140152}
     153
    141154
    142155struct SortElement {
     
    193206    TransferFunction* ani_tf = 0;
    194207    int total_rendered_slices = 0;
    195     int num_volumes = n_volumes;
     208    int num_volumes = volumes.size();
    196209
    197210    if (_volumeInterpolator->is_started()) {
    198211        ++num_volumes;
    199         ani_tf = tf[_volumeInterpolator->getReferenceVolumeID()];
     212        ani_tf = volumes[_volumeInterpolator->getReferenceVolumeID()]->tf;
    200213        ani_vol = _volumeInterpolator->getVolume();
    201214    }
     
    206219    int* actual_slices = new int[num_volumes];
    207220
    208     for(int vol_index = 0; vol_index< num_volumes; vol_index++) {
     221
     222    Volume* vol;
     223    int vol_index = 0;
     224    std::vector<VolumeData*>::iterator iter;
     225    for (iter = volumes.begin(); iter != volumes.end(); ++iter, ++vol_index) {
    209226        cur_vol = NULL;
    210227        cur_tf = NULL;
    211228#ifdef notdef
    212229        if (vol_index != n_volumes) {
    213             cur_vol = volume[vol_index];
    214             cur_tf = tf[vol_index];
     230            cur_vol = (*iter)->volume;
     231            cur_tf = (*iter)->tf;
    215232        } else {
    216233            cur_vol = ani_vol;
     
    218235        }
    219236#else
    220         cur_vol = volume[vol_index];
    221         cur_tf = tf[vol_index];
     237        cur_vol = (*iter)->volume;
     238        cur_tf = (*iter)->tf;
    222239#endif
    223240
     
    226243
    227244        if(!cur_vol->visible()) {
     245            //printf("volume [%d] skipped\n", cur_vol->getDataID());
    228246            continue; //skip this volume
    229247        }
     
    474492        ConvexPolygon* cur = polys[volume_index][slice_index];
    475493       
     494#ifdef notdef
    476495        if (volume_index == n_volumes) {
    477496            cur_vol = ani_vol;
    478497            cur_tf = ani_tf;
    479498        } else {
    480             cur_vol = volume[volume_index];
    481             cur_tf = tf[volume_index];
     499            cur_vol = volumes[volume_index]->volume;
     500            cur_tf = volumes[volume_index]->tf;
    482501        }
     502#else
     503        cur_vol = volumes[volume_index]->volume;
     504        cur_tf = volumes[volume_index]->tf;
     505#endif
    483506       
    484507       
     
    516539}
    517540
    518 void VolumeRenderer::render(int volume_index)
    519 {
    520   int n_slices = volume[volume_index]->get_n_slice();
     541void VolumeRenderer::render(int volDataID)
     542{
     543    Volume* vol = 0;
     544    TransferFunction* tf = 0;
     545    std::vector<VolumeData*>::iterator iter;
     546    for (iter = volumes.begin(); iter != volumes.end(); ++iter)
     547    {
     548        if ((*iter)->volume && ((*iter)->volume->getDataID() == volDataID))
     549        {
     550            vol = (*iter)->volume;
     551            tf = (*iter)->tf;
     552            break;
     553        }
     554    }
     555
     556    if (vol == 0) return;
     557
     558  int n_slices = vol->get_n_slice();
    521559
    522560  //volume start location
    523   Vector4 shift_4d(volume[volume_index]->location.x,
    524                    volume[volume_index]->location.y,
    525                    volume[volume_index]->location.z, 0);
     561  Vector4 shift_4d(vol->location.x,
     562                   vol->location.y,
     563                   vol->location.z, 0);
    526564
    527565  double x0 = 0;
     
    545583  glPushMatrix();
    546584
    547   glScalef(volume[volume_index]->aspect_ratio_width,
    548           volume[volume_index]->aspect_ratio_height,
    549           volume[volume_index]->aspect_ratio_depth);
     585  glScalef(vol->aspect_ratio_width,
     586          vol->aspect_ratio_height,
     587          vol->aspect_ratio_depth);
    550588
    551589  glEnable(GL_DEPTH_TEST);
     
    562600  glPushMatrix();
    563601  glTranslatef(shift_4d.x, shift_4d.y, shift_4d.z);
    564   glScalef(volume[volume_index]->aspect_ratio_width,
    565           volume[volume_index]->aspect_ratio_height,
    566           volume[volume_index]->aspect_ratio_depth);
     602  glScalef(vol->aspect_ratio_width,
     603          vol->aspect_ratio_height,
     604          vol->aspect_ratio_depth);
    567605  GLfloat mv_trans[16];
    568606  glGetFloatv(GL_MODELVIEW_MATRIX, mv_trans);
     
    572610
    573611  //draw volume bounding box
    574   if (volume[volume_index]->outline()) {
     612  if (vol->outline()) {
    575613      draw_bounding_box(x0, y0, z0, x0+1, y0+1, z0+1, 0.8, 0.1, 0.1, 1.5);
    576614  }
     
    605643
    606644  //render the cut planes
    607   for(int i=0; i<volume[volume_index]->get_cutplane_count(); i++){
    608     float offset = volume[volume_index]->get_cutplane(i)->offset;
    609     int axis = volume[volume_index]->get_cutplane(i)->orient;
     645  for(int i=0; i<vol->get_cutplane_count(); i++){
     646    float offset = vol->get_cutplane(i)->offset;
     647    int axis = vol->get_cutplane(i)->orient;
    610648
    611649    if (axis==1) {
     
    651689
    652690    glPushMatrix();
    653     glScalef(volume[volume_index]->aspect_ratio_width, volume[volume_index]->aspect_ratio_height, volume[volume_index]->aspect_ratio_depth);
    654 
    655     activate_volume_shader(volume[volume_index], tf[volume_index], true);
     691    glScalef(vol->aspect_ratio_width, vol->aspect_ratio_height, vol->aspect_ratio_depth);
     692
     693    activate_volume_shader(vol, tf, true);
    656694    glPopMatrix();
    657695
     
    699737
    700738    glPushMatrix();
    701     glScalef(volume[volume_index]->aspect_ratio_width, volume[volume_index]->aspect_ratio_height, volume[volume_index]->aspect_ratio_depth);
     739    glScalef(vol->aspect_ratio_width, vol->aspect_ratio_height, vol->aspect_ratio_depth);
    702740   
    703741   /*
     
    713751    */
    714752   
    715     activate_volume_shader(volume[volume_index], tf[volume_index], true);
     753    activate_volume_shader(vol, tf, true);
    716754    glPopMatrix();
    717755
     
    919957void VolumeRenderer::switch_volume_mode() { volume_mode = (!volume_mode); }
    920958
    921 void VolumeRenderer::enable_volume(int index){
    922   volume[index]->visible(true);
    923 }
    924 
    925 void VolumeRenderer::disable_volume(int index){
    926   volume[index]->visible(false);
     959void VolumeRenderer::enable_volume(int volDataID)
     960{
     961   printf("enable volume [%d]\n", volDataID);
     962   std::vector<VolumeData*>::iterator iter;
     963   for (iter = volumes.begin(); iter != volumes.end(); ++iter)
     964   {
     965       if ((*iter)->volume && ((*iter)->volume->getDataID() == volDataID))
     966       {
     967          (*iter)->volume->visible(true);
     968          printf("volume [%d] is visible\n", volDataID);
     969       }
     970   }
     971}
     972
     973void VolumeRenderer::disable_volume(int volDataID)
     974{
     975   printf("disable volume [%d]\n", volDataID);
     976   std::vector<VolumeData*>::iterator iter;
     977   for (iter = volumes.begin(); iter != volumes.end(); ++iter)
     978   {
     979       if ((*iter)->volume && ((*iter)->volume->getDataID() == volDataID))
     980       {
     981          (*iter)->volume->visible(false);
     982          printf("volume [%d] is visible\n", volDataID);
     983       }
     984   }
    927985}
    928986
  • trunk/packages/vizservers/nanovis/VolumeRenderer.h

    r1474 r1475  
    3939#include "VolumeInterpolator.h"
    4040
     41class VolumeData {
     42        friend class VolumeRenderer;
     43        friend class NanoVis;
     44private :
     45        Volume* volume;
     46        TransferFunction* tf;
     47public :
     48        VolumeData() : volume(0), tf(0) {}
     49        VolumeData(Volume* vol, TransferFunction* t) : volume(vol), tf(t)
     50        {
     51                if (volume) volume->ref();
     52                if (tf) tf->ref();
     53        }
     54        ~VolumeData()
     55        {
     56                if (volume) volume->unref();
     57                if (tf) tf->unref();
     58        }
     59};
     60
    4161class VolumeRenderer {
    4262    friend class NanoVis;
    4363private:
    44     std::vector <Volume*> volume;           //!<- array of volumes
    45     std::vector <TransferFunction*> tf;    //!<- array of corresponding transfer functions
     64    std::vector<VolumeData*> volumes;    //!<- array of volumes
    4665    VolumeInterpolator* _volumeInterpolator;
    47 
    48     int n_volumes;
    4966
    5067    bool slice_mode;    //!<- enable cut planes
     
    105122    ~VolumeRenderer();
    106123
    107     int add_volume(Volume* _vol, TransferFunction* _tf);
    108     void remove_volume(size_t volIndex);
     124    void add_volume(Volume* _vol, TransferFunction* _tf);
     125    void remove_all_volumes();
     126    void remove_volume(size_t volDataID);
    109127    // add a volume and its transfer function
    110128    // we require a transfer function when a
     
    113131    TransferFunction* get_volume_shading(Volume* _vol);
    114132
    115     void render(int volume_index);
     133    void render(int volumeID);
    116134    void render_all();  //render all enabled volumes;
    117135    void render_all_points(void); //render all enabled volumes;
     
    122140    void switch_slice_mode(); //switch_cutplane_mode
    123141    void switch_volume_mode();
    124     void enable_volume(int index); //enable a volume
    125     void disable_volume(int index); //disable a volume
     142    void enable_volume(int volumeDataID); //enable a volume
     143    void disable_volume(int volumeDataID); //disable a volume
    126144
    127145    void clearAnimatedVolumeInfo(void) {
  • trunk/packages/vizservers/nanovis/dxReader.cpp

    r1474 r1475  
    4848 */
    4949bool
    50 load_volume_stream2(Rappture::Outcome &result, int index, std::iostream& fin)
     50load_volume_stream2(Rappture::Outcome &result, int volDataID, std::iostream& fin)
    5151{
    5252    printf("load_volume_stream2\n");
     
    174174        return false;
    175175    }
     176    Volume *volPtr = 0;
    176177    if (isrect) {
    177178        double dval[6];
     
    246247        dz = nz;
    247248       
    248         Volume *volPtr;
    249         volPtr = NanoVis::load_volume(index, nx, ny, nz, 4, data,
     249        volPtr = NanoVis::load_volume(volDataID, nx, ny, nz, 4, data,
    250250                                      vmin, vmax, nzero_min);
    251251        volPtr->xAxis.SetRange(x0, x0 + (nx * dx));
     
    387387        }
    388388       
    389         Volume *volPtr;
    390         volPtr = NanoVis::load_volume(index, nx, ny, nz, 4, data,
     389        volPtr = NanoVis::load_volume(volDataID, nx, ny, nz, 4, data,
    391390                                      field.valueMin(), field.valueMax(), nzero_min);
    392391        volPtr->xAxis.SetRange(field.rangeMin(Rappture::xaxis),
     
    406405    float dy0 = -0.5*dy/dx;
    407406    float dz0 = -0.5*dz/dx;
    408     NanoVis::volume[index]->move(Vector3(dx0, dy0, dz0));
     407    if (volPtr) volPtr->move(Vector3(dx0, dy0, dz0));
     408     printf("volume moved\n");
    409409    return true;
    410410}
    411411
    412412bool
    413 load_volume_stream(Rappture::Outcome &result, int index, std::iostream& fin)
     413load_volume_stream(Rappture::Outcome &result, int volDataID, std::iostream& fin)
    414414{
    415415    printf("load_volume_stream\n");
     
    527527        return false;
    528528    }
     529    Volume *volPtr = 0;
    529530    if (isrect) {
    530531        Rappture::Mesh1D xgrid(x0, x0+nx*dx, nx);
     
    650651        }
    651652#endif 
    652         fprintf(stdout,"End Data Stats index = %i\n",index);
     653        fprintf(stdout,"End Data Stats DataID = %i\n",volDataID);
    653654        fprintf(stdout,"nx = %i ny = %i nz = %i\n",nx,ny,nz);
    654655        fprintf(stdout,"dx = %lg dy = %lg dz = %lg\n",dx,dy,dz);
     
    656657        fflush(stdout);
    657658       
    658         Volume *volPtr;
    659         volPtr = NanoVis::load_volume(index, nx, ny, nz, 4, data,
     659        volPtr = NanoVis::load_volume(volDataID, nx, ny, nz, 4, data,
    660660                                      field.valueMin(), field.valueMax(), nzero_min);
    661661        volPtr->xAxis.SetRange(field.rangeMin(Rappture::xaxis),
     
    802802        }
    803803       
    804         Volume *volPtr;
    805         volPtr = NanoVis::load_volume(index, nx, ny, nz, 4, data,
     804        volPtr = NanoVis::load_volume(volDataID, nx, ny, nz, 4, data,
    806805                                      field.valueMin(), field.valueMax(), nzero_min);
    807806        volPtr->xAxis.SetRange(field.rangeMin(Rappture::xaxis),
     
    834833    float dy0 = -0.5*dy/dx;
    835834    float dz0 = -0.5*dz/dx;
    836     NanoVis::volume[index]->move(Vector3(dx0, dy0, dz0));
     835    if (volPtr) volPtr->move(Vector3(dx0, dy0, dz0));
    837836    return true;
    838837}
     
    840839
    841840bool
    842 load_volume_stream_insoo(Rappture::Outcome &result, int index,
     841load_volume_stream_insoo(Rappture::Outcome &result, int volDataID,
    843842                         std::iostream& fin)
    844843{
     
    958957    }
    959958
     959    Volume* volPtr = 0;
    960960    if (isrect) {
    961961        Rappture::Mesh1D xgrid(x0, x0+nx*dx, nx);
     
    11211121            }
    11221122
    1123             fprintf(stdout,"End Data Stats index = %i\n",index);
     1123            fprintf(stdout,"End Data Stats volDataID = %i\n",volDataID);
    11241124            fprintf(stdout,"nx = %i ny = %i nz = %i\n",nx,ny,nz);
    11251125            fprintf(stdout,"dx = %lg dy = %lg dz = %lg\n",dx,dy,dz);
     
    11281128            */
    11291129
    1130         Volume *volPtr;
    1131         volPtr = NanoVis::load_volume(index, nx, ny, nz, 4, data,
     1130        volPtr = NanoVis::load_volume(volDataID, nx, ny, nz, 4, data,
    11321131                                      field.valueMin(), field.valueMax(), nzero_min);
    11331132        volPtr->xAxis.SetRange(field.rangeMin(Rappture::xaxis),
     
    12761275        }
    12771276       
    1278         Volume *volPtr;
    1279         volPtr = NanoVis::load_volume(index, nx, ny, nz, 4, data,
     1277        volPtr = NanoVis::load_volume(volDataID, nx, ny, nz, 4, data,
    12801278                                      field.valueMin(), field.valueMax(), nzero_min);
    12811279        volPtr->xAxis.SetRange(field.rangeMin(Rappture::xaxis),
     
    13081306    float dy0 = -0.5*dy/dx;
    13091307    float dz0 = -0.5*dz/dx;
    1310     NanoVis::volume[index]->move(Vector3(dx0, dy0, dz0));
     1308    if (volPtr) volPtr->move(Vector3(dx0, dy0, dz0));
    13111309    return true;
    13121310}
  • trunk/packages/vizservers/nanovis/dxReader2.cpp

    r1382 r1475  
    1717 */
    1818bool
    19 load_volume_stream_odx(Rappture::Outcome &context, int index, const char *buf,
     19load_volume_stream_odx(Rappture::Outcome &context, int userID, const char *buf,
    2020                       int nBytes)
    2121{
     
    8888    computeSimpleGradient(data, nx, ny, nz);
    8989
    90     fprintf(stdout,"End Data Stats index = %i\n",index);
     90    fprintf(stdout,"End Data Stats userID = %i\n",userID);
    9191    fprintf(stdout,"nx = %i ny = %i nz = %i\n",nx,ny,nz);
    9292    fprintf(stdout,"dx = %lg dy = %lg dz = %lg\n",dx,dy,dz);
     
    9595
    9696    Volume *volPtr;
    97     volPtr = NanoVis::load_volume(index, nx, ny, nz, 4, data,
     97    volPtr = NanoVis::load_volume(userID, nx, ny, nz, 4, data,
    9898                                  dxObj.dataMin(),
    9999                                  dxObj.dataMax(),
     
    116116    float dy0 = -0.5*dy/dx;
    117117    float dz0 = -0.5*dz/dx;
    118     NanoVis::volume[index]->move(Vector3(dx0, dy0, dz0));
     118    volPtr->move(Vector3(dx0, dy0, dz0));
    119119    return true;
    120120}
  • trunk/packages/vizservers/nanovis/nanovis.cpp

    r1474 r1475  
    106106int NanoVis::updir = Y_POS;
    107107NvCamera* NanoVis::cam = NULL;
    108 int NanoVis::n_volumes = 0;
    109 vector<Volume*> NanoVis::volume;
     108NanoVis::VolumeMap NanoVis::volumeMap;
     109int  NanoVis::_last_data_id = 0;
    110110vector<HeightMap*> NanoVis::heightMap;
    111111VolumeRenderer* NanoVis::vol_renderer = 0;
     
    514514 */
    515515Volume *
    516 NanoVis::load_volume(int index, int width, int height, int depth,
     516NanoVis::load_volume(int volDataID, int width, int height, int depth,
    517517                     int n_component, float* data, double vmin,
    518518                     double vmax, double nzero_min)
    519519{
    520     while (n_volumes <= index) {
    521         volume.push_back(NULL);
    522         n_volumes++;
    523     }
    524 
    525     Volume* vol = volume[index];
    526     if (vol != NULL) {
    527         volume[index] = NULL;
    528 
    529         if (vol->pointsetIndex != -1) {
    530             if (((unsigned  int) vol->pointsetIndex) < pointSet.size() &&
    531                 pointSet[vol->pointsetIndex] != NULL) {
    532                 delete pointSet[vol->pointsetIndex];
    533                 pointSet[vol->pointsetIndex] = 0;
     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                */
    534538            }
    535539        }
    536         delete vol;
    537     }
    538     volume[index] = new Volume(0.f, 0.f, 0.f, width, height, depth, 1.,
     540        vol->unref();
     541    }
     542
     543    Volume* newVol = new Volume(0.f, 0.f, 0.f, width, height, depth, 1.,
    539544                               n_component, data, vmin, vmax, nzero_min);
    540     fprintf(stderr, "VOLINDEX=%d, n_volumes=%d\n", index, n_volumes);
    541     return volume[index];
     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;
    542551}
    543552
     
    15381547    xMin = yMin = zMin = wMin = DBL_MAX;
    15391548    xMax = yMax = zMax = wMax = -DBL_MAX;
    1540     for (unsigned int i = 0; i < volume.size(); i++) {
    1541         Volume *volPtr;
    1542 
    1543         volPtr = volume[i];
     1549    NanoVis::VolumeMap::iterator iter;
     1550    for (iter = volumeMap.begin(); iter != volumeMap.end(); ++iter)
     1551    {
     1552        Volume *volPtr = iter->second;
     1553
    15441554        if (volPtr == NULL) {
    15451555            continue;
     
    25462556    return TCL_OK;
    25472557}
     2558
     2559int NanoVis::generate_data_identifier()
     2560{
     2561    return _last_data_id++;
     2562}
     2563
     2564void 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}
  • trunk/packages/vizservers/nanovis/nanovis.h

    r1431 r1475  
    109109    static NVISid final_fbo, final_color_tex, final_depth_rb;
    110110public:
     111    typedef std::map<int, Volume*> VolumeMap;
     112public:
    111113    static VolumeRenderer* vol_renderer;
    112114    static PointSetRenderer* pointset_renderer;
     
    128130    static vector<HeightMap*> heightMap;
    129131    static unsigned char* screen_buffer;
    130     static vector<Volume*> volume;
     132    static VolumeMap volumeMap;
    131133    static vector<NvVectorField*> flow;
    132134    static Grid* grid;
     
    152154    static Tcl_DString cmdbuffer;
    153155
     156    static int _last_data_id;
     157public :
    154158    static TransferFunction* get_transfunc(const char *name);
    155159    static TransferFunction* DefineTransferFunction(const char *name,
     
    179183    static int render_legend(TransferFunction *tf, double min, double max,
    180184        int width, int height, const char* volArg);
    181     static Volume *load_volume(int index, int width, int height, int depth,
     185    static Volume *load_volume(int volDataID, int width, int height, int depth,
    182186        int n, float* data, double vmin, double vmax, double nzero_min);
    183187    static void xinetd_listen(void);
     
    228232    };
    229233    static void EventuallyRedraw(unsigned int flag = 0);
     234    static void remove_volume(int volUserID);
     235    static int generate_data_identifier();
    230236};
    231237
Note: See TracChangeset for help on using the changeset viewer.