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/FlowCmd.cpp

    r1475 r1478  
    186186   
    187187    glPushMatrix();
    188     Vector3 *originPtr = volPtr->get_location();
    189     glTranslatef(originPtr->x, originPtr->y, originPtr->z);
     188    Vector3 origin = volPtr->location();
     189    glTranslatef(origin.x, origin.y, origin.z);
    190190
    191191    double sx, sy, sz;
     
    272272    _interp = interp;
    273273    _hashPtr = hPtr;
    274     _volDataID = -1;                    /* Indicates that no volume slot has
    275                                          * been allocated for this vector. */
    276274    _sv.sliceVisible = 1;
    277275    _sv.tfPtr = NanoVis::get_transfunc("default");
    278276    _volPtr = NULL;
     277    _volId = -1;
    279278    _cmdToken = Tcl_CreateObjCommand(interp, (char *)_name,
    280279        (Tcl_ObjCmdProc *)FlowInstObjCmd, this, FlowInstDeleteProc);
     
    296295    }
    297296     if (_volPtr != NULL) {
    298         _volPtr->unref();
    299         _volPtr = NULL;
    300         NanoVis::remove_volume(_volDataID);
    301         NanoVis::vol_renderer->remove_volume(_volDataID);
     297         assert((size_t)_volId == _volPtr->dataID());
     298         fprintf(stderr, "from ~FlowCmd volId=%d\n", _volId);
     299         NanoVis::remove_volume(_volId);
     300         _volPtr = NULL;
    302301    }
    303302
     
    497496
    498497void
    499 FlowCmd::InitVectorField(void)
    500 {
    501     if (_volPtr != NULL) {
    502         _volPtr->unref();
    503         _volPtr = NULL;
    504         NanoVis::remove_volume(_volDataID);
    505         NanoVis::vol_renderer->remove_volume(_volDataID);
    506     }
    507     // Remove the associated vector field.
    508     if (_fieldPtr != NULL) {
    509         delete _fieldPtr;
    510         _fieldPtr = NULL;
    511     }
    512    
    513 }
    514 
    515 void
    516498FlowCmd::InitializeParticles(void)
    517499{
     
    528510{
    529511    if (_volPtr != NULL) {
    530         _volPtr->unref();
     512        assert((size_t)_volId == _volPtr->dataID());
     513        fprintf(stderr, "from ScaleVectorField volId=%d\n", _volId);
     514        NanoVis::remove_volume(_volId);
    531515        _volPtr = NULL;
    532         NanoVis::remove_volume(_volDataID);
    533         NanoVis::vol_renderer->remove_volume(_volDataID);
    534516    }
    535517    float *vdata;
     
    546528    _volPtr = volPtr;
    547529
     530    // Remove the associated vector field.
     531    if (_fieldPtr != NULL) {
     532        delete _fieldPtr;
     533    }
    548534    _fieldPtr = new NvVectorField();
    549535    if (_fieldPtr == NULL) {
     
    556542    depth  = NanoVis::zMax - NanoVis::zMin;
    557543
    558     Vector3 *locationPtr = _volPtr->get_location();
     544    Vector3 loc = _volPtr->location();
    559545    /*This is wrong. Need to compute origin. */
    560     NanoVis::xOrigin = locationPtr->x;
    561     NanoVis::yOrigin = locationPtr->y;
    562     NanoVis::zOrigin = locationPtr->z;
    563 
    564     _fieldPtr->setVectorField(_volPtr, *locationPtr,
     546    NanoVis::xOrigin = loc.x;
     547    NanoVis::yOrigin = loc.y;
     548    NanoVis::zOrigin = loc.z;
     549
     550    _fieldPtr->setVectorField(_volPtr, loc,
    565551        1.0f, height / width, depth  / width, NanoVis::magMax);
    566552
    567553    if (NanoVis::licRenderer != NULL) {
    568         NanoVis::licRenderer->setVectorField(_volPtr->id,
    569                 *locationPtr,
     554        NanoVis::licRenderer->setVectorField(_volPtr->id, loc,
    570555                1.0f / _volPtr->aspect_ratio_width,
    571556                1.0f / _volPtr->aspect_ratio_height,
     
    632617FlowCmd::MakeVolume(float *data)
    633618{
    634     if (_volDataID < 0) {
    635         _volDataID = NanoVis::generate_data_identifier();
    636         Trace("VolumeDataID is %d\n", _volDataID);
    637     }
    638619    Volume *volPtr;
    639     volPtr = NanoVis::load_volume(_volDataID, _dataPtr->xNum(),
    640         _dataPtr->yNum(), _dataPtr->zNum(), 4, data,
    641         NanoVis::magMin, NanoVis::magMax, 0);
     620    /* Reuse the volume index. The first time it's -1, which means to generate
     621     * a new volume slot. */
     622    volPtr = NanoVis::load_volume(_volId, _dataPtr->xNum(), _dataPtr->yNum(),
     623        _dataPtr->zNum(), 4, data, NanoVis::magMin, NanoVis::magMax, 0);
     624    /* Save the volume index.  This only matters the first time through. */
     625    _volId = volPtr->dataID();
    642626    volPtr->xAxis.SetRange(_dataPtr->xMin(), _dataPtr->xMax());
    643627    volPtr->yAxis.SetRange(_dataPtr->yMin(), _dataPtr->yMax());
     
    645629    volPtr->wAxis.SetRange(NanoVis::magMin, NanoVis::magMax);
    646630
    647     /*volPtr->update_pending = false;*/
    648631    Vector3 physicalMin(NanoVis::xMin, NanoVis::yMin, NanoVis::zMin);
    649632    Vector3 physicalMax(NanoVis::xMax, NanoVis::yMax, NanoVis::zMax);
     
    653636    // volPtr->set_n_slice(512- _volIndex);
    654637    // TBD..
    655     volPtr->set_n_slice(256);
     638    volPtr->n_slices(256);
    656639    volPtr->disable_cutplane(0);
    657640    volPtr->disable_cutplane(1);
    658641    volPtr->disable_cutplane(2);
    659642
    660     NanoVis::vol_renderer->add_volume(volPtr, _sv.tfPtr);
    661     volPtr->data(_sv.showVolume);
     643    // Automatically set the volume with the previously configured values.
     644    volPtr->transferFunction(_sv.tfPtr);
     645    volPtr->data_enabled(_sv.showVolume);
    662646    volPtr->outline(_sv.showOutline);
    663647    volPtr->opacity_scale(_sv.opacity);
    664648    volPtr->specular(_sv.specular);
    665649    volPtr->diffuse(_sv.diffuse);
    666 
     650    Trace("volume is now %d %d\n", _sv.showVolume, volPtr->visible());
     651    volPtr->visible(_sv.showVolume);
    667652    float dx0 = -0.5;
    668653    float dy0 = -0.5*volPtr->height/volPtr->width;
    669654    float dz0 = -0.5*volPtr->depth/volPtr->width;
    670     volPtr->move(Vector3(dx0, dy0, dz0));
     655    volPtr->location(Vector3(dx0, dy0, dz0));
    671656    Volume::update_pending = true;
    672657    return volPtr;
     
    785770        return TCL_ERROR;
    786771    }
     772    Rappture::Unirect3d *dataPtr;
     773    dataPtr = new Rappture::Unirect3d(nComponents);
     774
    787775    FlowCmd *flowPtr = (FlowCmd *)clientData;
    788776    size_t length = buf.size();
    789777    char *bytes = (char *)buf.bytes();
    790778    if ((length > 4) && (strncmp(bytes, "<DX>", 4) == 0)) {
    791         Rappture::Unirect3d *dataPtr;
    792         dataPtr = new Rappture::Unirect3d(nComponents);
    793779        if (!dataPtr->ImportDx(result, nComponents, length - 4, bytes + 4)) {
    794780            Tcl_AppendResult(interp, result.remark(), (char *)NULL);
     
    798784        flowPtr->SetData(dataPtr);
    799785    } else if ((length > 10) && (strncmp(bytes, "unirect3d ", 10) == 0)) {
    800         Rappture::Unirect3d *dataPtr;
    801         dataPtr = new Rappture::Unirect3d(nComponents);
    802786        if (dataPtr->ParseBuffer(interp, buf) != TCL_OK) {
    803787            delete dataPtr;
     
    812796            return TCL_ERROR;
    813797        }
    814         Rappture::Unirect3d *dataPtr;
    815         dataPtr = new Rappture::Unirect3d(nComponents);
    816798        dataPtr->Convert(u2dPtr);
    817799        flowPtr->SetData(dataPtr);
     
    819801    } else {
    820802        fprintf(stderr, "header is %.14s\n", buf.bytes());
    821         Rappture::Unirect3d *dataPtr;
    822803        dataPtr = new Rappture::Unirect3d(nComponents);
    823804        if (!dataPtr->ImportDx(result, nComponents, length, bytes)) {
     
    833814        size_t length;
    834815
    835         length = sprintf(info, "nv>data tag %s id 0 min %g max %g vmin %g vmax %g\n",
    836                          flowPtr->name(), NanoVis::magMin,
    837                          NanoVis::magMax, NanoVis::xMin, NanoVis::xMax);
     816        length = sprintf(info, "nv>data tag %s min %g max %g\n",
     817                flowPtr->name(), dataPtr->magMin(), dataPtr->magMax());
    838818        nWritten  = write(0, info, length);
    839819        assert(nWritten == (ssize_t)strlen(info));
     
    10301010    /*
    10311011     * Step 2.  Generate the vector field from each data set.
    1032      *          Delete the currently generated fields.
    10331012     */
    10341013    for (flowPtr = FirstFlow(&iter); flowPtr != NULL;
    10351014         flowPtr = NextFlow(&iter)) {
    10361015        if (!flowPtr->isDataLoaded()) {
    1037             continue;
    1038         }
    1039         flowPtr->InitVectorField();
    1040         if (!flowPtr->visible()) {
    1041             continue;
    1042         }
    1043         flowPtr->InitializeParticles();
     1016            continue;                   // Flow exists, but no data has
     1017                                        // been loaded yet.
     1018        }
     1019        if (flowPtr->visible()) {
     1020            flowPtr->InitializeParticles();
     1021        }
    10441022        if (!flowPtr->ScaleVectorField()) {
    10451023            return false;
    10461024        }
     1025        // FIXME: This doesn't work when there is more than one flow.
    10471026        licRenderer->set_offset(flowPtr->GetRelativePosition());
    10481027    }
Note: See TracChangeset for help on using the changeset viewer.