Changeset 4612 for nanovis


Ignore:
Timestamp:
Aug 2, 2014 11:06:20 AM (10 years ago)
Author:
ldelgass
Message:

merge r3597 from trunk

Location:
nanovis/branches/1.1
Files:
4 deleted
22 edited
3 copied

Legend:

Unmodified
Added
Removed
  • nanovis/branches/1.1

  • nanovis/branches/1.1/Command.cpp

    r3568 r4612  
    2626 *        o Use Tcl command option parser to reduce size of procedures, remove
    2727 *          lots of extra error checking code. (almost there)
    28  *        o Convert GetVolumeIndices to GetVolumes.  Goal is to remove
    29  *          all references of Nanovis::volume[] from this file.  Don't
    30  *          want to know how volumes are stored. Same for heightmaps.
    31  *        o Rationalize volume id scheme. Right now it's the index in
    32  *          the vector. 1) Use a list instead of a vector. 2) carry
    33  *          an id field that's a number that gets incremented each new volume.
    3428 *        o Add bookkeeping for volumes, heightmaps, flows, etc. to track
    35  *          1) id #  2) simulation # 3) include/exclude.  The include/exclude
     29 *          1) simulation # 2) include/exclude.  The include/exclude
    3630 *          is to indicate whether the item should contribute to the overall
    3731 *          limits of the axes.
     
    4539
    4640#include <RpField1D.h>
    47 #include <RpFieldRect3D.h>
    48 #include <RpFieldPrism3D.h>
    4941#include <RpEncode.h>
    5042#include <RpOutcome.h>
     
    5547#include "nanovis.h"
    5648#include "CmdProc.h"
     49#include "FlowCmd.h"
    5750#include "Trace.h"
    5851#ifdef USE_POINTSET_RENDERER
     
    109102}";
    110103
    111 static Tcl_ObjCmdProc AxisCmd;
    112 static Tcl_ObjCmdProc CameraCmd;
    113 static Tcl_ObjCmdProc CutplaneCmd;
    114 extern Tcl_AppInitProc FlowCmdInitProc;
    115 static Tcl_ObjCmdProc GridCmd;
    116 static Tcl_ObjCmdProc LegendCmd;
    117 static Tcl_ObjCmdProc ScreenCmd;
    118 static Tcl_ObjCmdProc SnapshotCmd;
    119 static Tcl_ObjCmdProc TransfuncCmd;
    120 static Tcl_ObjCmdProc Unirect2dCmd;
    121 static Tcl_ObjCmdProc UpCmd;
    122 static Tcl_ObjCmdProc VolumeCmd;
    123 
    124104bool
    125105GetBooleanFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, bool *boolPtr)
     
    22282208    return interp;
    22292209}
    2230 
    2231 
  • nanovis/branches/1.1/Doxyfile.in

    r3567 r4612  
    599599# subdirectory from a directory tree whose root is specified with the INPUT tag.
    600600
    601 EXCLUDE                = @srcdir@/newmat11 @srcdir@/CircularQueue.h @srcdir@/ParticleEmitter.h @srcdir@/ParticleEmitter.cpp @srcdir@/ParticleSystem.h @srcdir@/ParticleSystem.cpp @srcdir@/ParticleSystemFactory.h @srcdir@/ParticleSystemFactory.cpp @srcdir@/BucketSort.h @srcdir@/BucketSort.cpp @srcdir@/PCASplit.h @srcdir@/PCASplit.cpp @srcdir@/PointSet.h @srcdir@/PointSet.cpp @srcdir@/PointSetRenderer.h @srcdir@/PointSetRenderer.cpp @srcdir@/PointShader.h @srcdir@/PointShader.cpp @srcdir@/NvVectorField.h @srcdir@/NvVectorField.cpp @srcdir@/NvFlowVisRenderer.h @srcdir@/NvFlowVisRenderer.cpp
     601EXCLUDE                = @srcdir@/newmat11 @srcdir@/CircularQueue.h @srcdir@/ParticleEmitter.h @srcdir@/ParticleEmitter.cpp @srcdir@/ParticleSystem.h @srcdir@/ParticleSystem.cpp @srcdir@/ParticleSystemFactory.h @srcdir@/ParticleSystemFactory.cpp @srcdir@/BucketSort.h @srcdir@/BucketSort.cpp @srcdir@/PCASplit.h @srcdir@/PCASplit.cpp @srcdir@/PointSet.h @srcdir@/PointSet.cpp @srcdir@/PointSetRenderer.h @srcdir@/PointSetRenderer.cpp @srcdir@/PointShader.h @srcdir@/PointShader.cpp
    602602
    603603# The EXCLUDE_SYMLINKS tag can be used select whether or not files or
  • nanovis/branches/1.1/FlowCmd.cpp

    r3584 r4612  
    1616#include <unistd.h>
    1717#include <poll.h>
     18
    1819#include <tcl.h>
    1920
    20 #include <RpField1D.h>
    21 #include <RpFieldRect3D.h>
    22 #include <RpFieldPrism3D.h>
    2321#include <RpOutcome.h>
    2422
     
    2927#include "nanovis.h"
    3028#include "CmdProc.h"
     29#include "Command.h"
    3130#include "FlowCmd.h"
    3231#include "FlowTypes.h"
     32#include "Flow.h"
    3333#include "FlowBox.h"
    3434#include "FlowParticles.h"
     
    3636#include "TransferFunction.h"
    3737#include "NvLIC.h"
    38 #include "Trace.h"
    3938#include "Unirect.h"
    4039#include "VelocityArrowsSlice.h"
    4140#include "Volume.h"
     41#include "Trace.h"
    4242
    4343using namespace vrmath;
     
    6868};
    6969
    70 Rappture::SwitchSpec FlowCmd::_switches[] = {
     70Rappture::SwitchSpec Flow::_switches[] = {
    7171    {Rappture::SWITCH_FLOAT, "-ambient", "value",
    7272     offsetof(FlowValues, ambient), 0},
     
    128128};
    129129
    130 static Tcl_ObjCmdProc FlowInstObjCmd;
    131 static Tcl_CmdDeleteProc FlowInstDeleteProc;
    132 
    133 FlowCmd::FlowCmd(Tcl_Interp *interp, const char *name) :
    134     _interp(interp),
    135     _name(name),
    136     _data(NULL),
    137     _volume(NULL),
    138     _field(NULL)
    139 {
    140     memset(&_sv, 0, sizeof(FlowValues));
    141     _sv.sliceVisible = 1;
    142     _sv.transferFunction = NanoVis::getTransferFunction("default");
    143 
    144     _cmdToken = Tcl_CreateObjCommand(_interp, (char *)name,
    145                                      (Tcl_ObjCmdProc *)FlowInstObjCmd,
    146                                      this, FlowInstDeleteProc);
    147 }
    148 
    149 FlowCmd::~FlowCmd()
    150 {
    151     TRACE("Enter");
    152 
    153     Rappture::FreeSwitches(_switches, &_sv, 0);
    154     if (_field != NULL) {
    155         delete _field;
    156     }
    157     if (_data != NULL) {
    158         delete _data;
    159     }
    160     if (_volume != NULL) {
    161         NanoVis::removeVolume(_volume);
    162         _volume = NULL;
    163     }
    164     for (BoxHashmap::iterator itr = _boxTable.begin();
    165          itr != _boxTable.end(); ++itr) {
    166         delete itr->second;
    167     }
    168     _boxTable.clear();
    169     for (ParticlesHashmap::iterator itr = _particlesTable.begin();
    170          itr != _particlesTable.end(); ++itr) {
    171         delete itr->second;
    172     }
    173     _particlesTable.clear();
    174 }
    175 
    176 void
    177 FlowCmd::getBounds(Vector3f& min,
    178                    Vector3f& max,
    179                    bool onlyVisible)
    180 {
    181     TRACE("Enter");
    182 
    183     if (onlyVisible && !visible())
    184         return;
    185 
    186 #if 0  // Using volume bounds instead of these
    187     if (isDataLoaded()) {
    188         Vector3f umin, umax;
    189         Rappture::Unirect3d *unirect = data();
    190         unirect->getWorldSpaceBounds(umin, umax);
    191         if (min.x > umin.x) {
    192             min.x = umin.x;
    193         }
    194         if (max.x < umax.x) {
    195             max.x = umax.x;
    196         }
    197         if (min.y > umin.y) {
    198             min.y = umin.y;
    199         }
    200         if (max.y < umax.y) {
    201             max.y = umax.y;
    202         }
    203         if (min.z > umin.z) {
    204             min.z = umin.z;
    205         }
    206         if (max.z < umax.z) {
    207             max.z = umax.z;
    208         }
    209     }
    210 #endif
    211     for (BoxHashmap::iterator itr = _boxTable.begin();
    212          itr != _boxTable.end(); ++itr) {
    213         FlowBox *box = itr->second;
    214         if (!onlyVisible || box->visible()) {
    215             Vector3f fbmin, fbmax;
    216             box->getWorldSpaceBounds(fbmin, fbmax,
    217                                      getVolume());
    218             if (min.x > fbmin.x) {
    219                 min.x = fbmin.x;
    220             }
    221             if (max.x < fbmax.x) {
    222                 max.x = fbmax.x;
    223             }
    224             if (min.y > fbmin.y) {
    225                 min.y = fbmin.y;
    226             }
    227             if (max.y < fbmax.y) {
    228                 max.y = fbmax.y;
    229             }
    230             if (min.z > fbmin.z) {
    231                 min.z = fbmin.z;
    232             }
    233             if (max.z < fbmax.z) {
    234                 max.z = fbmax.z;
    235             }
    236         }
    237     }
    238 }
    239 
    240 void
    241 FlowCmd::resetParticles()
    242 {
    243     for (ParticlesHashmap::iterator itr = _particlesTable.begin();
    244          itr != _particlesTable.end(); ++itr) {
    245         itr->second->reset();
    246     }
    247 }
    248 
    249 void
    250 FlowCmd::advect()
    251 {
    252     NvVectorField *fieldPtr = getVectorField();
    253     fieldPtr->active(true);
    254     for (ParticlesHashmap::iterator itr = _particlesTable.begin();
    255          itr != _particlesTable.end(); ++itr) {
    256         if (itr->second->visible()) {
    257             itr->second->advect();
    258         }
    259     }
    260 }
    261 
    262 void
    263 FlowCmd::render()
    264 {
    265     _field->active(true);
    266     _field->render();
    267     for (ParticlesHashmap::iterator itr = _particlesTable.begin();
    268          itr != _particlesTable.end(); ++itr) {
    269         if (itr->second->visible()) {
    270             itr->second->render();
    271         }
    272     }
    273     renderBoxes();
    274 }
    275 
    276 FlowParticles *
    277 FlowCmd::createParticles(const char *particlesName)
    278 {
    279     ParticlesHashmap::iterator itr = _particlesTable.find(particlesName);
    280     if (itr != _particlesTable.end()) {
    281         TRACE("Deleting existing particle injection plane '%s'", particlesName);
    282         delete itr->second;
    283         _particlesTable.erase(itr);
    284     }
    285     FlowParticles *particles = new FlowParticles(particlesName);
    286     _particlesTable[particlesName] = particles;
    287     return particles;
    288 }
    289 
    290 FlowParticles *
    291 FlowCmd::getParticles(const char *particlesName)
    292 {
    293     ParticlesHashmap::iterator itr;
    294     itr = _particlesTable.find(particlesName);
    295     if (itr == _particlesTable.end()) {
    296         TRACE("Can't find particle injection plane '%s' in '%s'", particlesName, name());
    297         return NULL;
    298     }
    299     return itr->second;
    300 }
    301 
    302 void
    303 FlowCmd::deleteParticles(const char *particlesName)
    304 {
    305     ParticlesHashmap::iterator itr = _particlesTable.find(particlesName);
    306     if (itr == _particlesTable.end()) {
    307         TRACE("Can't find particle injection plane '%s' in '%s'", particlesName, name());
    308         return;
    309     }
    310     delete itr->second;
    311     _particlesTable.erase(itr);
    312 }
    313 
    314 void
    315 FlowCmd::getParticlesNames(std::vector<std::string>& names)
    316 {
    317     for (ParticlesHashmap::iterator itr = _particlesTable.begin();
    318          itr != _particlesTable.end(); ++itr) {
    319         names.push_back(std::string(itr->second->name()));
    320     }
    321 }
    322 
    323 FlowBox *
    324 FlowCmd::createBox(const char *boxName)
    325 {
    326     BoxHashmap::iterator itr = _boxTable.find(boxName);
    327     if (itr != _boxTable.end()) {
    328         TRACE("Deleting existing box '%s'", boxName);
    329         delete itr->second;
    330         _boxTable.erase(itr);
    331     }
    332     FlowBox *box = new FlowBox(boxName);
    333     _boxTable[boxName] = box;
    334     return box;
    335 }
    336 
    337 FlowBox *
    338 FlowCmd::getBox(const char *boxName)
    339 {
    340     BoxHashmap::iterator itr = _boxTable.find(boxName);
    341     if (itr == _boxTable.end()) {
    342         TRACE("Can't find box '%s' in '%s'", boxName, name());
    343         return NULL;
    344     }
    345     return itr->second;
    346 }
    347 
    348 void
    349 FlowCmd::deleteBox(const char *boxName)
    350 {
    351     BoxHashmap::iterator itr = _boxTable.find(boxName);
    352     if (itr == _boxTable.end()) {
    353         TRACE("Can't find box '%s' in '%s'", boxName, name());
    354         return;
    355     }
    356     delete itr->second;
    357     _boxTable.erase(itr);
    358 }
    359 
    360 void FlowCmd::getBoxNames(std::vector<std::string>& names)
    361 {
    362     for (BoxHashmap::iterator itr = _boxTable.begin();
    363          itr != _boxTable.end(); ++itr) {
    364         names.push_back(std::string(itr->second->name()));
    365     }
    366 }
    367 
    368 void
    369 FlowCmd::initializeParticles()
    370 {
    371     for (ParticlesHashmap::iterator itr = _particlesTable.begin();
    372          itr != _particlesTable.end(); ++itr) {
    373         itr->second->initialize();
    374     }
    375 }
    376 
    377 bool
    378 FlowCmd::scaleVectorField()
    379 {
    380     if (_volume != NULL) {
    381         TRACE("Removing existing volume: %s", _volume->name());
    382         NanoVis::removeVolume(_volume);
    383         _volume = NULL;
    384     }
    385     float *vdata = getScaledVector();
    386     if (vdata == NULL) {
    387         return false;
    388     }
    389     Volume *volume = makeVolume(vdata);
    390     delete [] vdata;
    391     if (volume == NULL) {
    392         return false;
    393     }
    394     _volume = volume;
    395 
    396     // Remove the associated vector field.
    397     if (_field != NULL) {
    398         delete _field;
    399     }
    400     _field = new NvVectorField();
    401     if (_field == NULL) {
    402         return false;
    403     }
    404 
    405     Vector3f scale = volume->getPhysicalScaling();
    406     Vector3f location = _volume->location();
    407 
    408     _field->setVectorField(_volume,
    409                            location,
    410                            scale.x,
    411                            scale.y,
    412                            scale.z,
    413                            NanoVis::magMax);
    414 
    415     if (NanoVis::licRenderer != NULL) {
    416         NanoVis::licRenderer->
    417             setVectorField(_volume->textureID(),
    418                            location,
    419                            scale.x,
    420                            scale.y,
    421                            scale.z,
    422                            _volume->wAxis.max());
    423         setCurrentPosition();
    424         setAxis();
    425         setActive();
    426     }
    427 
    428     if (NanoVis::velocityArrowsSlice != NULL) {
    429         NanoVis::velocityArrowsSlice->
    430             setVectorField(_volume->textureID(),
    431                            location,
    432                            scale.x,
    433                            scale.y,
    434                            scale.z,
    435                            _volume->wAxis.max());
    436         NanoVis::velocityArrowsSlice->axis(_sv.slicePos.axis);
    437         NanoVis::velocityArrowsSlice->slicePos(_sv.slicePos.value);
    438         NanoVis::velocityArrowsSlice->enabled(_sv.showArrows);
    439     }
    440 
    441     for (ParticlesHashmap::iterator itr = _particlesTable.begin();
    442          itr != _particlesTable.end(); ++itr) {
    443         itr->second->setVectorField(_volume,
    444                                     location,
    445                                     scale.x,
    446                                     scale.y,
    447                                     scale.z,
    448                                     _volume->wAxis.max());
    449     }
    450     return true;
    451 }
    452 
    453 void
    454 FlowCmd::renderBoxes()
    455 {
    456     for (BoxHashmap::iterator itr = _boxTable.begin();
    457          itr != _boxTable.end(); ++itr) {
    458         if (itr->second->visible()) {
    459             itr->second->render(_volume);
    460         }
    461     }
    462 }
    463 
    464 float *
    465 FlowCmd::getScaledVector()
    466 {
    467     assert(_data->nComponents() == 3);
    468     size_t n = _data->nValues() / _data->nComponents() * 4;
    469     float *data = new float[n];
    470     if (data == NULL) {
    471         return NULL;
    472     }
    473     memset(data, 0, sizeof(float) * n);
    474     float *destPtr = data;
    475     const float *values = _data->values();
    476     for (size_t iz = 0; iz < _data->zNum(); iz++) {
    477         for (size_t iy = 0; iy < _data->yNum(); iy++) {
    478             for (size_t ix = 0; ix < _data->xNum(); ix++) {
    479                 double vx, vy, vz, vm;
    480                 vx = values[0];
    481                 vy = values[1];
    482                 vz = values[2];
    483                 vm = sqrt(vx*vx + vy*vy + vz*vz);
    484                 destPtr[0] = vm / NanoVis::magMax;
    485                 destPtr[1] = vx /(2.0*NanoVis::magMax) + 0.5;
    486                 destPtr[2] = vy /(2.0*NanoVis::magMax) + 0.5;
    487                 destPtr[3] = vz /(2.0*NanoVis::magMax) + 0.5;
    488                 values += 3;
    489                 destPtr += 4;
    490             }
    491         }
    492     }
    493     return data;
    494 }
    495 
    496 Volume *
    497 FlowCmd::makeVolume(float *data)
    498 {
    499     Volume *volume =
    500         NanoVis::loadVolume(_name.c_str(),
    501                             _data->xNum(),
    502                             _data->yNum(),
    503                             _data->zNum(),
    504                             4, data,
    505                             NanoVis::magMin, NanoVis::magMax, 0);
    506     volume->xAxis.setRange(_data->xMin(), _data->xMax());
    507     volume->yAxis.setRange(_data->yMin(), _data->yMax());
    508     volume->zAxis.setRange(_data->zMin(), _data->zMax());
    509 
    510     TRACE("min=%g %g %g max=%g %g %g mag=%g %g",
    511           NanoVis::xMin, NanoVis::yMin, NanoVis::zMin,
    512           NanoVis::xMax, NanoVis::yMax, NanoVis::zMax,
    513           NanoVis::magMin, NanoVis::magMax);
    514 
    515     volume->disableCutplane(0);
    516     volume->disableCutplane(1);
    517     volume->disableCutplane(2);
    518 
    519     /* Initialize the volume with the previously configured values. */
    520     volume->transferFunction(_sv.transferFunction);
    521     volume->dataEnabled(_sv.showVolume);
    522     volume->twoSidedLighting(_sv.twoSidedLighting);
    523     volume->outline(_sv.showOutline);
    524     volume->opacityScale(_sv.opacity);
    525     volume->ambient(_sv.ambient);
    526     volume->diffuse(_sv.diffuse);
    527     volume->specularLevel(_sv.specular);
    528     volume->specularExponent(_sv.specularExp);
    529     volume->visible(_sv.showVolume);
    530 
    531     Vector3f volScaling = volume->getPhysicalScaling();
    532     Vector3f loc(volScaling);
    533     loc *= -0.5;
    534     volume->location(loc);
    535 
    536     Volume::updatePending = true;
    537     return volume;
    538 }
    539 
    540130static int
    541131FlowDataFileOp(ClientData clientData, Tcl_Interp *interp, int objc,
     
    566156    Rappture::Unirect3d *dataPtr;
    567157    dataPtr = new Rappture::Unirect3d(nComponents);
    568     FlowCmd *flowPtr = (FlowCmd *)clientData;
     158    Flow *flow = (Flow *)clientData;
    569159    size_t length = buf.size();
    570160    char *bytes = (char *)buf.bytes();
     
    603193        return TCL_ERROR;
    604194    }
    605     flowPtr->data(dataPtr);
     195    flow->data(dataPtr);
    606196    NanoVis::eventuallyRedraw(NanoVis::MAP_FLOWS);
    607197    return TCL_OK;
     
    649239    dataPtr = new Rappture::Unirect3d(nComponents);
    650240
    651     FlowCmd *flowPtr = (FlowCmd *)clientData;
     241    Flow *flow = (Flow *)clientData;
    652242    size_t length = buf.size();
    653243    char *bytes = (char *)buf.bytes();
     
    699289    TRACE("magMin = %lg magMax = %lg",
    700290          dataPtr->magMin(), dataPtr->magMax());
    701     flowPtr->data(dataPtr);
     291    flow->data(dataPtr);
    702292    {
    703293        char info[1024];
     
    706296
    707297        length = sprintf(info, "nv>data tag %s min %g max %g\n",
    708                          flowPtr->name(), dataPtr->magMin(), dataPtr->magMax());
     298                         flow->name(), dataPtr->magMin(), dataPtr->magMax());
    709299        nWritten  = write(1, info, length);
    710300        assert(nWritten == (ssize_t)strlen(info));
     
    732322    }
    733323    return (*proc) (clientData, interp, objc, objv);
    734 }
    735 
    736 float
    737 FlowCmd::getRelativePosition(FlowPosition *posPtr)
    738 {
    739     if (posPtr->flags == RELPOS) {
    740         return posPtr->value;
    741     }
    742     switch (posPtr->axis) {
    743     case AXIS_X: 
    744         return (posPtr->value - NanoVis::xMin) /
    745             (NanoVis::xMax - NanoVis::xMin);
    746     case AXIS_Y: 
    747         return (posPtr->value - NanoVis::yMin) /
    748             (NanoVis::yMax - NanoVis::yMin);
    749     case AXIS_Z: 
    750         return (posPtr->value - NanoVis::zMin) /
    751             (NanoVis::zMax - NanoVis::zMin);
    752     }
    753     return 0.0;
    754 }
    755 
    756 float
    757 FlowCmd::getRelativePosition()
    758 {
    759     return FlowCmd::getRelativePosition(&_sv.slicePos);
    760 }
    761 
    762 /* Static NanoVis class commands. */
    763 
    764 FlowCmd *
    765 NanoVis::getFlow(const char *name)
    766 {
    767     FlowHashmap::iterator itr = flowTable.find(name);
    768     if (itr == flowTable.end()) {
    769         TRACE("Can't find flow '%s'", name);
    770         return NULL;
    771     }
    772     return itr->second;
    773 }
    774 
    775 FlowCmd *
    776 NanoVis::createFlow(Tcl_Interp *interp, const char *name)
    777 {
    778     FlowHashmap::iterator itr = flowTable.find(name);
    779     if (itr != flowTable.end()) {
    780         ERROR("Flow '%s' already exists", name);
    781         return NULL;
    782     }
    783     FlowCmd *flow = new FlowCmd(interp, name);
    784     flowTable[name] = flow;
    785     return flow;
    786 }
    787 
    788 /**
    789  * \brief Delete flow object and hash table entry
    790  *
    791  * This is called by the flow command instance delete callback
    792  */
    793 void
    794 NanoVis::deleteFlow(const char *name)
    795 {
    796     FlowHashmap::iterator itr = flowTable.find(name);
    797     if (itr != flowTable.end()) {
    798         delete itr->second;
    799         flowTable.erase(itr);
    800     }
    801 }
    802 
    803 /**
    804  * \brief Delete all flow object commands
    805  *
    806  * This will also delete the flow objects and hash table entries
    807  */
    808 void
    809 NanoVis::deleteFlows(Tcl_Interp *interp)
    810 {
    811     FlowHashmap::iterator itr;
    812     for (itr = flowTable.begin();
    813          itr != flowTable.end(); ++itr) {
    814         Tcl_DeleteCommandFromToken(interp, itr->second->getCommandToken());
    815     }
    816     flowTable.clear();
    817 }
    818 
    819 bool
    820 NanoVis::mapFlows()
    821 {
    822     TRACE("Enter");
    823 
    824     flags &= ~MAP_FLOWS;
    825 
    826     /*
    827      * Step 1. Get the overall min and max magnitudes of all the
    828      *         flow vectors.
    829      */
    830     magMin = DBL_MAX, magMax = -DBL_MAX;
    831 
    832     for (FlowHashmap::iterator itr = flowTable.begin();
    833          itr != flowTable.end(); ++itr) {
    834         FlowCmd *flow = itr->second;
    835         double min, max;
    836         if (!flow->isDataLoaded()) {
    837             continue;
    838         }
    839         Rappture::Unirect3d *data = flow->data();
    840         min = data->magMin();
    841         max = data->magMax();
    842         if (min < magMin) {
    843             magMin = min;
    844         }
    845         if (max > magMax) {
    846             magMax = max;
    847         }
    848         if (data->xMin() < xMin) {
    849             xMin = data->xMin();
    850         }
    851         if (data->yMin() < yMin) {
    852             yMin = data->yMin();
    853         }
    854         if (data->zMin() < zMin) {
    855             zMin = data->zMin();
    856         }
    857         if (data->xMax() > xMax) {
    858             xMax = data->xMax();
    859         }
    860         if (data->yMax() > yMax) {
    861             yMax = data->yMax();
    862         }
    863         if (data->zMax() > zMax) {
    864             zMax = data->zMax();
    865         }
    866     }
    867 
    868     TRACE("magMin=%g magMax=%g", NanoVis::magMin, NanoVis::magMax);
    869 
    870     /*
    871      * Step 2. Generate the vector field from each data set.
    872      */
    873     for (FlowHashmap::iterator itr = flowTable.begin();
    874          itr != flowTable.end(); ++itr) {
    875         FlowCmd *flow = itr->second;
    876         if (!flow->isDataLoaded()) {
    877             continue; // Flow exists, but no data has been loaded yet.
    878         }
    879         if (flow->visible()) {
    880             flow->initializeParticles();
    881         }
    882         if (!flow->scaleVectorField()) {
    883             return false;
    884         }
    885         // FIXME: This doesn't work when there is more than one flow.
    886         licRenderer->setOffset(flow->getRelativePosition());
    887         velocityArrowsSlice->slicePos(flow->getRelativePosition());
    888     }
    889     advectFlows();
    890     return true;
    891 }
    892 
    893 void
    894 NanoVis::getFlowBounds(Vector3f& min,
    895                        Vector3f& max,
    896                        bool onlyVisible)
    897 {
    898     TRACE("Enter");
    899 
    900     min.set(FLT_MAX, FLT_MAX, FLT_MAX);
    901     max.set(-FLT_MAX, -FLT_MAX, -FLT_MAX);
    902 
    903     for (FlowHashmap::iterator itr = flowTable.begin();
    904          itr != flowTable.end(); ++itr) {
    905         itr->second->getBounds(min, max, onlyVisible);
    906     }
    907 }
    908 
    909 void
    910 NanoVis::renderFlows()
    911 {
    912     for (FlowHashmap::iterator itr = flowTable.begin();
    913          itr != flowTable.end(); ++itr) {
    914         FlowCmd *flow = itr->second;
    915         if (flow->isDataLoaded() && flow->visible()) {
    916             flow->render();
    917         }
    918     }
    919     flags &= ~REDRAW_PENDING;
    920 }
    921 
    922 void
    923 NanoVis::resetFlows()
    924 {
    925     if (licRenderer->active()) {
    926         NanoVis::licRenderer->reset();
    927     }
    928     for (FlowHashmap::iterator itr = flowTable.begin();
    929          itr != flowTable.end(); ++itr) {
    930         FlowCmd *flow = itr->second;
    931         if (flow->isDataLoaded() && flow->visible()) {
    932             flow->resetParticles();
    933         }
    934     }
    935 }   
    936 
    937 void
    938 NanoVis::advectFlows()
    939 {
    940     for (FlowHashmap::iterator itr = flowTable.begin();
    941          itr != flowTable.end(); ++itr) {
    942         FlowCmd *flow = itr->second;
    943         if (flow->isDataLoaded() && flow->visible()) {
    944             flow->advect();
    945         }
    946     }
    947324}
    948325
     
    969346    const char *string = Tcl_GetString(objPtr);
    970347    if (string[1] == '\0') {
    971         FlowCmd::SliceAxis *axisPtr = (FlowCmd::SliceAxis *)(record + offset);
     348        Flow::SliceAxis *axisPtr = (Flow::SliceAxis *)(record + offset);
    972349        char c;
    973350        c = tolower((unsigned char)string[0]);
    974351        if (c == 'x') {
    975             *axisPtr = FlowCmd::AXIS_X;
     352            *axisPtr = Flow::AXIS_X;
    976353            return TCL_OK;
    977354        } else if (c == 'y') {
    978             *axisPtr = FlowCmd::AXIS_Y;
     355            *axisPtr = Flow::AXIS_Y;
    979356            return TCL_OK;
    980357        } else if (c == 'z') {
    981             *axisPtr = FlowCmd::AXIS_Z;
     358            *axisPtr = Flow::AXIS_Z;
    982359            return TCL_OK;
    983360        }
     
    1175552                Tcl_Obj *const *objv)
    1176553{
    1177     FlowCmd *flowPtr = (FlowCmd *)clientData;
    1178 
    1179     if (flowPtr->parseSwitches(interp, objc - 2, objv + 2) != TCL_OK) {
     554    Flow *flow = (Flow *)clientData;
     555
     556    if (flow->parseSwitches(interp, objc - 2, objv + 2) != TCL_OK) {
    1180557        return TCL_ERROR;
    1181558    }
     
    1188565                   Tcl_Obj *const *objv)
    1189566{
    1190     FlowCmd *flow = (FlowCmd *)clientData;
     567    Flow *flow = (Flow *)clientData;
    1191568    const char *particlesName = Tcl_GetString(objv[3]);
    1192569    FlowParticles *particles = flow->createParticles(particlesName);
     
    1212589                         Tcl_Obj *const *objv)
    1213590{
    1214     FlowCmd *flow = (FlowCmd *)clientData;
     591    Flow *flow = (Flow *)clientData;
    1215592    const char *particlesName = Tcl_GetString(objv[3]);
    1216593    FlowParticles *particles = flow->getParticles(particlesName);
     
    1233610                      Tcl_Obj *const *objv)
    1234611{
    1235     FlowCmd *flow = (FlowCmd *)clientData;
     612    Flow *flow = (Flow *)clientData;
    1236613    for (int i = 3; i < objc; i++) {
    1237614        flow->deleteParticles(Tcl_GetString(objv[i]));
     
    1245622                     Tcl_Obj *const *objv)
    1246623{
    1247     FlowCmd *flow = (FlowCmd *)clientData;
     624    Flow *flow = (Flow *)clientData;
    1248625    Tcl_Obj *listObjPtr;
    1249626    listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL);
     
    1288665        return TCL_ERROR;
    1289666    }
    1290     FlowCmd *flowPtr = (FlowCmd *)clientData;
    1291     Tcl_Preserve(flowPtr);
     667    Flow *flow = (Flow *)clientData;
     668    Tcl_Preserve(flow);
    1292669    int result;
    1293670    result = (*proc) (clientData, interp, objc, objv);
    1294     Tcl_Release(flowPtr);
     671    Tcl_Release(flow);
    1295672    return result;
    1296673}
     
    1300677             Tcl_Obj *const *objv)
    1301678{
    1302     FlowCmd *flow = (FlowCmd *)clientData;
     679    Flow *flow = (Flow *)clientData;
    1303680    const char *boxName = Tcl_GetString(objv[3]);
    1304681    FlowBox *box = flow->createBox(boxName);
     
    1322699                   Tcl_Obj *const *objv)
    1323700{
    1324     FlowCmd *flow = (FlowCmd *)clientData;
     701    Flow *flow = (Flow *)clientData;
    1325702    const char *boxName = Tcl_GetString(objv[3]);
    1326703    FlowBox *box = flow->getBox(boxName);
     
    1341718                Tcl_Obj *const *objv)
    1342719{
    1343     FlowCmd *flow = (FlowCmd *)clientData;
     720    Flow *flow = (Flow *)clientData;
    1344721    for (int i = 3; i < objc; i++) {
    1345722        flow->deleteBox(Tcl_GetString(objv[i]));
     
    1353730               Tcl_Obj *const *objv)
    1354731{
    1355     FlowCmd *flow = (FlowCmd *)clientData;
     732    Flow *flow = (Flow *)clientData;
    1356733    Tcl_Obj *listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL);
    1357734    std::vector<std::string> names;
     
    1393770        return TCL_ERROR;
    1394771    }
    1395     FlowCmd *flowPtr = (FlowCmd *)clientData;
    1396     Tcl_Preserve(flowPtr);
     772    Flow *flow = (Flow *)clientData;
     773    Tcl_Preserve(flow);
    1397774    int result;
    1398775    result = (*proc) (clientData, interp, objc, objv);
    1399     Tcl_Release(flowPtr);
     776    Tcl_Release(flow);
    1400777    return result;
    1401778}
     
    1414791             Tcl_Obj *const *objv)
    1415792{
    1416     FlowCmd *flowPtr = (FlowCmd *)clientData;
     793    Flow *flow = (Flow *)clientData;
    1417794   
    1418795    const char *string = Tcl_GetString(objv[1]);
    1419796    TransferFunction *tf;
    1420     tf = flowPtr->getTransferFunction();
     797    tf = flow->getTransferFunction();
    1421798    if (tf == NULL) {
    1422799        Tcl_AppendResult(interp, "unknown transfer function \"", string, "\"",
     
    1455832 * \return A standard Tcl result.
    1456833 */
    1457 static int
     834int
    1458835FlowInstObjCmd(ClientData clientData, Tcl_Interp *interp, int objc,
    1459836               Tcl_Obj *const *objv)
     
    1466843    }
    1467844    assert(CheckGL(AT));
    1468     FlowCmd *flow = (FlowCmd *)clientData;
     845    Flow *flow = (Flow *)clientData;
    1469846    Tcl_Preserve(flow);
    1470847    int result = (*proc) (clientData, interp, objc, objv);
     
    1478855 * This is called only when the command associated with the flow is destroyed.
    1479856 */
    1480 static void
     857void
    1481858FlowInstDeleteProc(ClientData clientData)
    1482859{
    1483     FlowCmd *flow = (FlowCmd *)clientData;
     860    Flow *flow = (Flow *)clientData;
    1484861    NanoVis::deleteFlow(flow->name());
    1485862}
     
    1496873        return TCL_ERROR;
    1497874    }
    1498     FlowCmd *flow = NanoVis::createFlow(interp, name);
     875    Flow *flow = NanoVis::createFlow(interp, name);
    1499876    if (flow == NULL) {
    1500877        Tcl_AppendResult(interp, "Flow \"", name, "\" already exists",
     
    1516893{
    1517894    for (int i = 2; i < objc; i++) {
    1518         FlowCmd *flow = NanoVis::getFlow(Tcl_GetString(objv[i]));
     895        Flow *flow = NanoVis::getFlow(Tcl_GetString(objv[i]));
    1519896        if (flow != NULL) {
    1520897            Tcl_DeleteCommandFromToken(interp, flow->getCommandToken());
     
    1530907{
    1531908    bool value = false;
    1532     FlowCmd *flow = NanoVis::getFlow(Tcl_GetString(objv[2]));
     909    Flow *flow = NanoVis::getFlow(Tcl_GetString(objv[2]));
    1533910    if (flow != NULL) {
    1534911        value = true;
     
    1577954    for (NanoVis::FlowHashmap::iterator itr = NanoVis::flowTable.begin();
    1578955         itr != NanoVis::flowTable.end(); ++itr) {
    1579         FlowCmd *flow = itr->second;
     956        Flow *flow = itr->second;
    1580957        Tcl_Obj *objPtr = Tcl_NewStringObj(flow->name(), -1);
    1581958        Tcl_ListObjAppendElement(interp, listObjPtr, objPtr);
     
    16681045};
    16691046
    1670 Rappture::SwitchSpec FlowCmd::videoSwitches[] = {
     1047static Rappture::SwitchSpec flowVideoSwitches[] = {
    16711048    {Rappture::SWITCH_INT, "-bitrate", "value",
    16721049     offsetof(FlowVideoSwitches, bitRate), 0},
     
    18721249    switches.formatObjPtr = Tcl_NewStringObj("mpeg1video", 10);
    18731250    Tcl_IncrRefCount(switches.formatObjPtr);
    1874     if (Rappture::ParseSwitches(interp, FlowCmd::videoSwitches,
     1251    if (Rappture::ParseSwitches(interp, flowVideoSwitches,
    18751252                objc - 3, objv + 3, &switches, SWITCH_DEFAULTS) < 0) {
    18761253        return TCL_ERROR;
     
    19181295    tmpFileName[length] = '\0';
    19191296    rmdir(tmpFileName);
    1920     Rappture::FreeSwitches(FlowCmd::videoSwitches, &switches, 0);
     1297    Rappture::FreeSwitches(flowVideoSwitches, &switches, 0);
    19211298    return result;
    19221299}
  • nanovis/branches/1.1/FlowCmd.h

    r3567 r4612  
    2525#define FLOWCMD_H
    2626
    27 #include <tr1/unordered_map>
    28 #include <vector>
    29 #include <string>
    30 
    3127#include <tcl.h>
    3228
    33 #include <vrmath/Vector3f.h>
    34 
    35 #include "Switch.h"
    36 #include "FlowTypes.h"
    37 #include "FlowParticles.h"
    38 #include "FlowBox.h"
    39 #include "NvLIC.h"
    40 #include "NvParticleRenderer.h"
    41 #include "NvVectorField.h"
    42 #include "Unirect.h"
    43 #include "Volume.h"
    44 #include "TransferFunction.h"
    45 
    46 struct FlowValues {
    47     TransferFunction *transferFunction;
    48     FlowPosition slicePos;
    49     int showArrows;
    50     int sliceVisible;
    51     int showVolume;
    52     int showOutline;
    53     int isHidden;
    54     int twoSidedLighting;
    55     float ambient;     ///< Ambient volume shading
    56     float diffuse;     ///< Diffuse volume shading
    57     float specular;    ///< Specular level volume shading
    58     float specularExp; ///< Specular exponent volume shading
    59     float opacity;     ///< Volume opacity scaling
    60 };
    61 
    62 class FlowCmd
    63 {
    64 public:
    65     enum SliceAxis { AXIS_X, AXIS_Y, AXIS_Z };
    66 
    67     FlowCmd(Tcl_Interp *interp, const char *name);
    68 
    69     ~FlowCmd();
    70 
    71     void getBounds(vrmath::Vector3f& min,
    72                    vrmath::Vector3f& max,
    73                    bool onlyVisible);
    74 
    75     FlowParticles *createParticles(const char *particlesName);
    76 
    77     FlowParticles *getParticles(const char *particlesName);
    78 
    79     void deleteParticles(const char *particlesName);
    80 
    81     void getParticlesNames(std::vector<std::string>& names);
    82 
    83     void render();
    84 
    85     void advect();
    86 
    87     void resetParticles();
    88 
    89     void initializeParticles();
    90 
    91     FlowBox *createBox(const char *boxName);
    92 
    93     FlowBox *getBox(const char *boxName);
    94 
    95     void deleteBox(const char *boxName);
    96 
    97     void getBoxNames(std::vector<std::string>& names);
    98 
    99     float *getScaledVector();
    100 
    101     Volume *makeVolume(float *data);
    102    
    103     void initVectorField();
    104 
    105     NvVectorField *getVectorField()
    106     {
    107         return _field;
    108     }
    109 
    110     bool scaleVectorField();
    111 
    112     bool visible()
    113     {
    114         return !_sv.isHidden;
    115     }
    116 
    117     const char *name() const
    118     {
    119         return _name.c_str();
    120     }
    121 
    122     bool isDataLoaded()
    123     {
    124         return (_data != NULL);
    125     }
    126 
    127     Rappture::Unirect3d *data()
    128     {
    129         return _data;
    130     }
    131 
    132     void data(Rappture::Unirect3d *data)
    133     {
    134         if (_data != NULL) {
    135             delete _data;
    136         }
    137         _data = data;
    138     }
    139 
    140     void activateSlice()
    141     {
    142         /* Must set axis before offset or position goes to wrong axis. */
    143         NanoVis::licRenderer->setAxis(_sv.slicePos.axis);
    144         NanoVis::licRenderer->setOffset(_sv.slicePos.value);
    145         NanoVis::licRenderer->active(true);
    146     }
    147 
    148     void ceactivateSlice()
    149     {
    150         NanoVis::licRenderer->active(false);
    151     }
    152 
    153     SliceAxis getAxis()
    154     {
    155         return (SliceAxis)_sv.slicePos.axis;
    156     }
    157 
    158     TransferFunction *getTransferFunction()
    159     {
    160         return _sv.transferFunction;
    161     }
    162 
    163     float getRelativePosition();
    164 
    165     void setAxis()
    166     {
    167         NanoVis::licRenderer->setAxis(_sv.slicePos.axis);
    168     }
    169 
    170     void setAxis(FlowCmd::SliceAxis axis)
    171     {
    172         _sv.slicePos.axis = axis;
    173         NanoVis::licRenderer->setAxis(_sv.slicePos.axis);
    174     }
    175 
    176     void setCurrentPosition(float position)
    177     {
    178         _sv.slicePos.value = position;
    179         NanoVis::licRenderer->setOffset(_sv.slicePos.value);
    180     }
    181 
    182     void setCurrentPosition()
    183     {
    184         NanoVis::licRenderer->setOffset(_sv.slicePos.value);
    185     }
    186 
    187     void setActive(bool state)
    188     {
    189         _sv.sliceVisible = state;
    190         NanoVis::licRenderer->active(state);
    191     }
    192 
    193     void setActive()
    194     {
    195         NanoVis::licRenderer->active(_sv.sliceVisible);
    196     }
    197 
    198     void setVectorField(NvVectorField *field)
    199     {
    200         deleteVectorField();
    201         _field = field;
    202     }
    203 
    204     void deleteVectorField()
    205     {
    206         if (_field != NULL) {
    207             delete _field;
    208             _field = NULL;
    209         }
    210     }
    211 
    212     const Volume *getVolume() const
    213     {
    214         return _volume;
    215     }
    216 
    217     int parseSwitches(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
    218     {
    219         if (Rappture::ParseSwitches(interp, _switches, objc, objv, &_sv,
    220                                     SWITCH_DEFAULTS) < 0) {
    221             return TCL_ERROR;
    222         }
    223         return TCL_OK;
    224     }
    225 
    226     Tcl_Command getCommandToken()
    227     {
    228         return _cmdToken;
    229     }
    230 
    231     static float getRelativePosition(FlowPosition *pos);
    232 
    233     static Rappture::SwitchSpec videoSwitches[];
    234 
    235 private:
    236     typedef std::string ParticlesId;
    237     typedef std::string BoxId;
    238     typedef std::tr1::unordered_map<ParticlesId, FlowParticles *> ParticlesHashmap;
    239     typedef std::tr1::unordered_map<BoxId, FlowBox *> BoxHashmap;
    240 
    241     void configure();
    242 
    243     void renderBoxes();
    244 
    245     Tcl_Interp *_interp;
    246     /**
    247      * Name of the flow.  This may differ
    248      * from the name of the command
    249      * associated with the flow, if the
    250      * command was renamed. */
    251     std::string _name;
    252 
    253     /**
    254      * Command associated with the flow.
    255      * When the command is deleted, so is
    256      * the flow. */
    257     Tcl_Command _cmdToken;
    258 
    259     /**
    260      * Uniform rectangular data
    261      * representing the mesh and vector
    262      * field values.  These values are
    263      * kept to regenerate the volume
    264      * associated with the flow. */
    265     Rappture::Unirect3d *_data;
    266 
    267     /**
    268      * The volume associated with the
    269      * flow.  This isn't the same thing as
    270      * a normal volume displayed. */
    271     Volume *_volume;
    272 
    273     /**
    274      * Vector field generated from the
    275      * above volume */
    276     NvVectorField *_field;
    277 
    278     /**
    279      * For each field there can be one or
    280      * more particle injection planes
    281      * where the particles are injected
    282      * into the flow. */
    283     ParticlesHashmap _particlesTable;
    284 
    285     /**
    286      * A table of boxes.  There maybe
    287      * zero or more boxes associated
    288      * with each field. */
    289     BoxHashmap _boxTable;
    290 
    291     FlowValues _sv;
    292 
    293     static Rappture::SwitchSpec _switches[];
    294 };
    295 
    296 extern int GetDataStream(Tcl_Interp *interp, Rappture::Buffer &buf, int nBytes);
    297 
    298 extern int GetBooleanFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
    299                              bool *boolVal);
    300 
    301 extern int GetFloatFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
    302                            float *floatVal);
    303 
    304 extern int GetAxisFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
    305                           int *axisVal);
    306 
    307 extern int GetVolumeFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
    308                             Volume **volume);
     29extern Tcl_AppInitProc FlowCmdInitProc;
     30extern Tcl_ObjCmdProc FlowInstObjCmd;
     31extern Tcl_CmdDeleteProc FlowInstDeleteProc;
    30932
    31033#endif
  • nanovis/branches/1.1/FlowParticles.cpp

    r3567 r4612  
    1616#include "nanovis.h"        // For NMESH
    1717#include "FlowParticles.h"
    18 #include "FlowCmd.h"
     18#include "Flow.h"
    1919#include "Trace.h"
    2020
     
    4848    TRACE("Particles '%s' axis: %d pos: %g rel pos: %g",
    4949          _name.c_str(), _sv.position.axis, _sv.position.value,
    50           FlowCmd::getRelativePosition(&_sv.position));
     50          Flow::getRelativePosition(&_sv.position));
    5151
    52     _renderer->setPos(FlowCmd::getRelativePosition(&_sv.position));
     52    _renderer->setPos(Flow::getRelativePosition(&_sv.position));
    5353    _renderer->setAxis(_sv.position.axis);
    5454    assert(_renderer->active());
     
    5959FlowParticles::configure()
    6060{
    61     _renderer->setPos(FlowCmd::getRelativePosition(&_sv.position));
     61    _renderer->setPos(Flow::getRelativePosition(&_sv.position));
    6262    _renderer->setColor(Vector4f(_sv.color.r,
    6363                                 _sv.color.g,
  • nanovis/branches/1.1/FlowParticles.h

    r3568 r4612  
    1212#define FLOWPARTICLES_H
    1313
     14#include <cassert>
    1415#include <string>
    1516
  • nanovis/branches/1.1/HeightMap.cpp

    r3502 r4612  
    2323
    2424HeightMap::HeightMap() :
    25     _vertexBufferObjectID(0), 
    26     _texcoordBufferObjectID(0), 
    27     _vertexCount(0), 
    28     _contour(0),
    29     _tfPtr(0),
     25    _vertexBufferObjectID(0),
     26    _texcoordBufferObjectID(0),
     27    _vertexCount(0),
     28    _contour(NULL),
     29    _transferFunc(NULL),
    3030    _opacity(0.5f),
    31     _indexBuffer(0),
    32     _indexCount(0), 
    33     _contourColor(1.0f, 0.0f, 0.0f), 
    34     _contourVisible(false), 
     31    _indexBuffer(NULL),
     32    _indexCount(0),
     33    _contourColor(1.0f, 0.0f, 0.0f),
     34    _contourVisible(false),
    3535    _visible(false),
    36     _scale(1.0f, 1.0f, 1.0f), 
     36    _scale(1.0f, 1.0f, 1.0f),
    3737    _centerPoint(0.0f, 0.0f, 0.0f),
    3838    _heights(NULL)
     
    9393        glDisableClientState(GL_NORMAL_ARRAY);
    9494
    95         if (_tfPtr) {
     95        if (_transferFunc) {
    9696            // PUT vertex program here
    9797            //
    9898            //
    9999            _shader->bind();
    100             _shader->setFPTextureParameter("tf", _tfPtr->id());
     100            _shader->setFPTextureParameter("tf", _transferFunc->id());
    101101            _shader->setFPParameter1f("opacity", _opacity);
    102102
    103103            glEnable(GL_TEXTURE_1D);
    104             _tfPtr->getTexture()->activate();
     104            _transferFunc->getTexture()->activate();
    105105 
    106106            glEnableClientState(GL_TEXTURE_COORD_ARRAY);
     
    125125
    126126        glDisableClientState(GL_VERTEX_ARRAY);
    127         if (_tfPtr != NULL) {
    128             _tfPtr->getTexture()->deactivate();
     127        if (_transferFunc != NULL) {
     128            _transferFunc->getTexture()->deactivate();
    129129            glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    130130
     
    384384    }
    385385    ContourLineFilter lineFilter;
    386     //lineFilter.transferFunction(_tfPtr);
     386    //lineFilter.transferFunction(_transferFunc);
    387387    _contour = lineFilter.create(0.0f, 1.0f, 10, map, xNum, yNum);
    388388
     
    398398    Vector3f* vertices = new Vector3f[xNum * yNum];
    399399
    400     Vector3f* dstDataPtr = vertices;
    401     float* srcDataPtr = height;
     400    Vector3f* dstData = vertices;
     401    float* srcData = height;
    402402   
    403403    for (int y = 0; y < yNum; ++y) {
     
    409409
    410410            xCoord = xMin + ((xMax - xMin) * x) / (xNum - 1);
    411             dstDataPtr->set(xCoord, *srcDataPtr, yCoord);
    412 
    413             ++dstDataPtr;
    414             ++srcDataPtr;
     411            dstData->set(xCoord, *srcData, yCoord);
     412
     413            ++dstData;
     414            ++srcData;
    415415        }
    416416    }
     
    422422 */
    423423void
    424 HeightMap::mapToGrid(Grid *gridPtr)
     424HeightMap::mapToGrid(Grid *grid)
    425425{
    426426    int count = _xNum * _yNum;
     
    432432    // this surface's y-values (heights) into the grid's axis coordinates.
    433433
    434     float yScale = 1.0 / (gridPtr->yAxis.max() - gridPtr->yAxis.min());
     434    float yScale = 1.0 / (grid->yAxis.max() - grid->yAxis.min());
    435435    float *p, *q, *pend;
    436436    float *normHeights = new float[count];
    437437    for (p = _heights, pend = p + count, q = normHeights; p < pend; p++, q++) {
    438         *q = (*p - gridPtr->yAxis.min()) * yScale;
     438        *q = (*p - grid->yAxis.min()) * yScale;
    439439    }
    440440    Vector3f *t, *texcoord;
     
    450450    float xMin, xMax, zMin, zMax;
    451451
    452     xScale = 1.0 / (gridPtr->xAxis.max() - gridPtr->xAxis.min());
    453     xMin = (xAxis.min() - gridPtr->xAxis.min()) * xScale;
    454     xMax = (xAxis.max() - gridPtr->xAxis.min()) * xScale;
    455     zScale = 1.0 / (gridPtr->zAxis.max() - gridPtr->zAxis.min());
    456     zMin = (zAxis.min() - gridPtr->zAxis.min()) * zScale;
    457     zMax = (zAxis.max() - gridPtr->zAxis.min()) * zScale;
     452    xScale = 1.0 / (grid->xAxis.max() - grid->xAxis.min());
     453    xMin = (xAxis.min() - grid->xAxis.min()) * xScale;
     454    xMax = (xAxis.max() - grid->xAxis.min()) * xScale;
     455    zScale = 1.0 / (grid->zAxis.max() - grid->zAxis.min());
     456    zMin = (zAxis.min() - grid->zAxis.min()) * zScale;
     457    zMax = (zAxis.max() - grid->zAxis.min()) * zScale;
    458458
    459459    Vector3f* vertices;
     
    477477    }
    478478    ContourLineFilter lineFilter;
    479     //lineFilter.transferFunction(_tfPtr);
     479    //lineFilter.transferFunction(_transferFunc);
    480480    _contour = lineFilter.create(0.0f, 1.0f, 10, vertices, _xNum, _yNum);
    481481   
  • nanovis/branches/1.1/HeightMap.h

    r3502 r4612  
    4949    void setHeight(int xCount, int yCount, vrmath::Vector3f *heights);
    5050#endif
    51     void mapToGrid(Grid *gridPtr);
     51    void mapToGrid(Grid *grid);
    5252
    5353    /**
    5454     *@brief Define a color map for color shading of heightmap
    5555     */
    56     void transferFunction(TransferFunction *tfPtr)
     56    void transferFunction(TransferFunction *transferFunc)
    5757    {
    58         _tfPtr = tfPtr;
     58        _transferFunc = transferFunc;
    5959    }
    6060
     
    6464    TransferFunction *transferFunction()
    6565    {
    66         return _tfPtr;
     66        return _transferFunc;
    6767    }
    6868
     
    128128    int _vertexCount;
    129129    nv::graphics::Geometry *_contour;
    130     TransferFunction *_tfPtr;
     130    TransferFunction *_transferFunc;
    131131    float _opacity;
    132132    NvShader *_shader;
  • nanovis/branches/1.1/Makefile.in

    r4611 r4612  
    111111                ContourLineFilter.o \
    112112                ConvexPolygon.o \
     113                Flow.o \
    113114                FlowBox.o \
    114115                FlowCmd.o \
     
    125126                NvShader.o \
    126127                NvStdVertexShader.o \
    127                 NvVectorField.o \
    128128                NvVolumeShader.o \
    129129                NvZincBlendeReconstructor.o \
     
    174174
    175175ifdef NOTDEF
    176 OBJS +=         NvFlowVisRenderer.o \
    177                 ParticleEmitter.o \
     176OBJS +=         ParticleEmitter.o \
    178177                ParticleSystem.o \
    179178                ParticleSystemFactory.o
     
    274273Chain.o: Chain.cpp Chain.h
    275274CmdProc.o: CmdProc.cpp CmdProc.h
    276 Command.o: Command.cpp nanovis.h $(AUXSRC) CmdProc.h Trace.h PlaneRenderer.h PointSet.h dxReader.h Grid.h HeightMap.h NvCamera.h NvZincBlendeReconstructor.h Unirect.h Volume.h VolumeRenderer.h
     275Command.o: Command.cpp nanovis.h $(AUXSRC) FlowCmd.h CmdProc.h Trace.h PlaneRenderer.h PointSet.h dxReader.h Grid.h HeightMap.h NvCamera.h NvZincBlendeReconstructor.h Unirect.h Volume.h VolumeRenderer.h
    277276ContourLineFilter.o: ContourLineFilter.cpp ContourLineFilter.h
    278277ConvexPolygon.o: ConvexPolygon.cpp ConvexPolygon.h $(VRMATH_DIR)/include/vrmath/Vector4f.h $(VRMATH_DIR)/include/vrmath/Matrix4x4d.h Plane.h
     278Flow.o: Flow.h FlowCmd.h FlowTypes.h FlowBox.h FlowParticles.h Switch.h Trace.h
    279279FlowBox.o: FlowBox.h FlowTypes.h Switch.h Trace.h Volume.h $(VRMATH_DIR)/include/vrmath/Vector3f.h $(VRMATH_DIR)/include/vrmath/Vector4f.h $(VRMATH_DIR)/include/vrmath/Matrix4x4d.h
    280 FlowCmd.o: FlowCmd.cpp FlowCmd.h FlowParticles.h FlowBox.h FlowTypes.h Switch.h Trace.h TransferFunction.h nanovis.h CmdProc.h NvLIC.h Unirect.h Volume.h VelocityArrowsSlice.h $(VRMATH_DIR)/include/vrmath/Vector3f.h
     280FlowCmd.o: FlowCmd.cpp FlowCmd.h FlowParticles.h FlowBox.h FlowTypes.h Command.h Switch.h Trace.h TransferFunction.h nanovis.h CmdProc.h NvLIC.h Unirect.h Volume.h VelocityArrowsSlice.h $(VRMATH_DIR)/include/vrmath/Vector3f.h
    281281FlowParticles.o: FlowParticles.h FlowTypes.h FlowCmd.h Switch.h Trace.h NvParticleRenderer.h Volume.h $(VRMATH_DIR)/include/vrmath/Vector3f.h $(VRMATH_DIR)/include/vrmath/Vector4f.h
    282282GradientFilter.o: GradientFilter.cpp GradientFilter.h
     
    285285NvCamera.o: NvCamera.cpp NvCamera.h config.h $(VRMATH_DIR)/include/vrmath/Matrix4x4d.h
    286286NvColorTableShader.o: NvColorTableShader.cpp NvColorTableShader.h NvShader.h
    287 NvFlowVisRenderer.o: NvFlowVisRenderer.cpp NvFlowVisRenderer.h
    288287NvLIC.o: NvLIC.cpp NvLIC.h
    289288NvParticleAdvectionShader.o: NvParticleAdvectionShader.cpp NvParticleAdvectionShader.h NvShader.h
     
    292291NvShader.o: NvShader.cpp NvShader.h
    293292NvStdVertexShader.o: NvStdVertexShader.cpp NvStdVertexShader.h NvShader.h
    294 NvVectorField.o: NvVectorField.cpp NvVectorField.h NvParticleRenderer.h
    295293NvVolumeShader.o: NvVolumeShader.cpp NvVolumeShader.h NvShader.h
    296294NvZincBlendeReconstructor.o: NvZincBlendeReconstructor.cpp NvZincBlendeReconstructor.h ZincBlendeVolume.h Volume.h $(VRMATH_DIR)/include/vrmath/Vector3f.h
     
    314312Trace.o: Trace.cpp Trace.h
    315313TransferFunction.o: TransferFunction.cpp
    316 Unirect.o: Unirect.cpp Unirect.h Trace.h
     314Unirect.o: Unirect.cpp Unirect.h Command.h Trace.h
    317315VelocityArrowsSlice.o: VelocityArrowsSlice.cpp VelocityArrowsSlice.h
    318316Volume.o: Volume.cpp Volume.h $(AUXSRC)
     
    322320ZincBlendeVolume.o: ZincBlendeVolume.cpp ZincBlendeVolume.h $(AUXSRC)
    323321dxReader.o: dxReader.cpp ReaderCommon.h config.h nanovis.h Unirect.h ZincBlendeVolume.h NvZincBlendeReconstructor.h
    324 nanovis.o: nanovis.cpp nanovis.h $(AUXSRC) FlowCmd.h Grid.h HeightMap.h NvCamera.h NvFlowVisRenderer.h NvLIC.h NvZincBlendeReconstructor.h PerfQuery.h PlaneRenderer.h PointSetRenderer.h PointSet.h Switch.h Trace.h Unirect.h VelocityArrowsSlice.h VolumeInterpolator.h VolumeRenderer.h ZincBlendeVolume.h Axis.h Chain.h
     322nanovis.o: nanovis.cpp nanovis.h $(AUXSRC) Command.h Flow.h Grid.h HeightMap.h NvCamera.h NvLIC.h NvZincBlendeReconstructor.h PerfQuery.h PlaneRenderer.h PointSetRenderer.h PointSet.h Switch.h Trace.h Unirect.h VelocityArrowsSlice.h VolumeInterpolator.h VolumeRenderer.h ZincBlendeVolume.h Axis.h Chain.h
    325323md5.o: md5.h
  • nanovis/branches/1.1/PlaneRenderer.cpp

    r3502 r4612  
    3737
    3838int
    39 PlaneRenderer::addPlane(Texture2D *p, TransferFunction *tfPtr)
     39PlaneRenderer::addPlane(Texture2D *planeTexture, TransferFunction *tf)
    4040{
    4141    int ret = _numPlanes;
    4242
    43     _plane.push_back(p);
    44     _tf.push_back(tfPtr);
     43    _plane.push_back(planeTexture);
     44    _tf.push_back(tf);
    4545
    4646    if (ret == 0)
  • nanovis/branches/1.1/Trace.cpp

    r3559 r4612  
    4545
    4646bool
    47 CheckFBO(GLenum *statusPtr)
     47CheckFBO(GLenum *status)
    4848{
    49     *statusPtr = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
    50     return (*statusPtr == GL_FRAMEBUFFER_COMPLETE_EXT);
     49    *status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
     50    return (*status == GL_FRAMEBUFFER_COMPLETE_EXT);
    5151}
    5252
  • nanovis/branches/1.1/Trace.h

    r3452 r4612  
    3030#define INFO(...)       LogMessage(LOG_INFO, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
    3131
    32 extern bool CheckFBO(GLenum *statusPtr);
     32extern bool CheckFBO(GLenum *status);
    3333extern void PrintFBOStatus(GLenum status, const char *prefix);
    3434extern bool CheckGL(const char *prefix);
  • nanovis/branches/1.1/Unirect.cpp

    r3559 r4612  
    66 */
    77#include <float.h>
     8
    89#include <tcl.h>
    910
     
    1112#include <RpFieldRect3D.h>
    1213
     14#include "Command.h"
    1315#include "Unirect.h"
    1416#include "Trace.h"
    15 
    16 extern int GetFloatFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
    17                            float *valuePtr);
    18 
    19 extern int GetAxisFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, int *indexPtr);
    2017
    2118static inline char *
  • nanovis/branches/1.1/Volume.cpp

    r3567 r4612  
    3838    _height(h),
    3939    _depth(d),
    40     _tfPtr(NULL),
     40    _transferFunc(NULL),
    4141    _ambient(0.6f),
    4242    _diffuse(0.4f),
  • nanovis/branches/1.1/Volume.h

    r3567 r4612  
    277277    TransferFunction *transferFunction()
    278278    {
    279         return _tfPtr;
    280     }
    281 
    282     void transferFunction(TransferFunction *tfPtr)
    283     {
    284         _tfPtr = tfPtr;
     279        return _transferFunc;
     280    }
     281
     282    void transferFunction(TransferFunction *transferFunc)
     283    {
     284        _transferFunc = transferFunc;
    285285    }
    286286
     
    366366     * render this volume.
    367367     */
    368     TransferFunction *_tfPtr;
     368    TransferFunction *_transferFunc;
    369369
    370370    float _ambient;      ///< Ambient material coefficient
  • nanovis/branches/1.1/VolumeInterpolator.cpp

    r3502 r4612  
    125125
    126126void
    127 VolumeInterpolator::addVolume(Volume *refPtr)
     127VolumeInterpolator::addVolume(Volume *volume)
    128128{
    129129    if (_volumes.size() != 0) {
    130         if (_volumes[0]->width() != refPtr->width() ||
    131             _volumes[0]->height() != refPtr->height() ||   
    132             _volumes[0]->depth() != refPtr->depth() ||
    133             _volumes[0]->numComponents() != refPtr->numComponents()) {
     130        if (_volumes[0]->width() != volume->width() ||
     131            _volumes[0]->height() != volume->height() ||   
     132            _volumes[0]->depth() != volume->depth() ||
     133            _volumes[0]->numComponents() != volume->numComponents()) {
    134134            TRACE("The volume should be the same width, height, number of components");
    135135            return;
    136136        }
    137137    } else {
    138         _dataCount = refPtr->width() * refPtr->height() * refPtr->depth();
    139         _numComponents = refPtr->numComponents();
     138        _dataCount = volume->width() * volume->height() * volume->depth();
     139        _numComponents = volume->numComponents();
    140140        _numBytes = _dataCount * _numComponents * sizeof(float);
    141         Vector3f loc = refPtr->location();
     141        Vector3f loc = volume->location();
    142142        _volume = new Volume(loc.x, loc.y, loc.z,
    143                              refPtr->width(),
    144                              refPtr->height(),
    145                              refPtr->depth(),
    146                              refPtr->numComponents(),
    147                              refPtr->data(),
    148                              refPtr->wAxis.min(),
    149                              refPtr->wAxis.max(),
    150                              refPtr->nonZeroMin());
     143                             volume->width(),
     144                             volume->height(),
     145                             volume->depth(),
     146                             volume->numComponents(),
     147                             volume->data(),
     148                             volume->wAxis.min(),
     149                             volume->wAxis.max(),
     150                             volume->nonZeroMin());
    151151
    152152        _volume->numSlices(256-1);
     
    156156        _volume->visible(true);
    157157        _volume->dataEnabled(true);
    158         _volume->ambient(refPtr->ambient());
    159         _volume->diffuse(refPtr->diffuse());
    160         _volume->specularLevel(refPtr->specularLevel());
    161         _volume->specularExponent(refPtr->specularExponent());
    162         _volume->opacityScale(refPtr->opacityScale());
     158        _volume->ambient(volume->ambient());
     159        _volume->diffuse(volume->diffuse());
     160        _volume->specularLevel(volume->specularLevel());
     161        _volume->specularExponent(volume->specularExponent());
     162        _volume->opacityScale(volume->opacityScale());
    163163        _volume->isosurface(0);
    164164        TRACE("VOL : location %f %f %f\n\tid : %s", loc.x, loc.y, loc.z,
    165                refPtr->name());
     165               volume->name());
    166166    }
    167167    _volumes.push_back(_volume);
    168     TRACE("a Volume[%s] is added to VolumeInterpolator", refPtr->name());
     168    TRACE("a Volume[%s] is added to VolumeInterpolator", volume->name());
    169169}
    170170
  • nanovis/branches/1.1/VolumeRenderer.cpp

    r3567 r4612  
    132132    TRACE("start loop %d", volumes.size());
    133133    for (size_t i = 0; i < volumes.size(); i++) {
    134         Volume *volPtr = volumes[i];
     134        Volume *volume = volumes[i];
    135135        polys[i] = NULL;
    136136        actual_slices[i] = 0;
    137137
    138         int n_slices = volPtr->numSlices();
    139         if (volPtr->isosurface()) {
     138        int n_slices = volume->numSlices();
     139        if (volume->isosurface()) {
    140140            // double the number of slices
    141141            n_slices <<= 1;
     
    143143
    144144        //volume start location
    145         Vector3f volPos = volPtr->location();
    146         Vector3f volScaling = volPtr->getPhysicalScaling();
     145        Vector3f volPos = volume->location();
     146        Vector3f volScaling = volume->getPhysicalScaling();
    147147
    148148        TRACE("VOL POS: %g %g %g",
     
    196196        //draw volume bounding box with translation (the correct location in
    197197        //space)
    198         if (volPtr->outline()) {
     198        if (volume->outline()) {
    199199            float olcolor[3];
    200             volPtr->getOutlineColor(olcolor);
     200            volume->getOutlineColor(olcolor);
    201201            drawBoundingBox(x0, y0, z0, x0+1, y0+1, z0+1,
    202202                (double)olcolor[0], (double)olcolor[1], (double)olcolor[2],
     
    222222        size_t n_actual_slices;
    223223
    224         if (volPtr->dataEnabled()) {
     224        if (volume->dataEnabled()) {
    225225            if (z_step == 0.0f)
    226226                n_actual_slices = 1;
     
    244244        // vice versa.
    245245
    246         for (int j = 0; j < volPtr->getCutplaneCount(); j++) {
    247             if (!volPtr->isCutplaneEnabled(j)) {
     246        for (int j = 0; j < volume->getCutplaneCount(); j++) {
     247            if (!volume->isCutplaneEnabled(j)) {
    248248                continue;
    249249            }
    250             float offset = volPtr->getCutplane(j)->offset;
    251             int axis = volPtr->getCutplane(j)->orient;
     250            float offset = volume->getCutplane(j)->offset;
     251            int axis = volume->getCutplane(j)->orient;
    252252
    253253            switch (axis) {
     
    279279
    280280            _cutplaneShader->bind();
    281             _cutplaneShader->setFPTextureParameter("volume", volPtr->textureID());
    282             _cutplaneShader->setFPTextureParameter("tf", volPtr->transferFunction()->id());
     281            _cutplaneShader->setFPTextureParameter("volume", volume->textureID());
     282            _cutplaneShader->setFPTextureParameter("tf", volume->transferFunction()->id());
    283283
    284284            glPushMatrix();
     
    383383
    384384    for (size_t i = 0; i < total_rendered_slices; i++) {
    385         Volume *volPtr = NULL;
     385        Volume *volume = NULL;
    386386
    387387        int volume_index = slices[i].volumeId;
     
    390390        float z_step = z_steps[volume_index];
    391391
    392         volPtr = volumes[volume_index];
    393 
    394         Vector3f volScaling = volPtr->getPhysicalScaling();
     392        volume = volumes[volume_index];
     393
     394        Vector3f volScaling = volume->getPhysicalScaling();
    395395
    396396        glPushMatrix();
     
    398398
    399399        // FIXME: compute view-dependent volume sample distance
    400         double avgSampleDistance = 1.0 / pow(volPtr->width() * volScaling.x *
    401                                              volPtr->height() * volScaling.y *
    402                                              volPtr->depth() * volScaling.z, 1.0/3.0);
     400        double avgSampleDistance = 1.0 / pow(volume->width() * volScaling.x *
     401                                             volume->height() * volScaling.y *
     402                                             volume->depth() * volScaling.z, 1.0/3.0);
    403403        float sampleRatio = z_step / avgSampleDistance;
    404404
    405405#ifdef notdef
    406406        TRACE("shading slice: volume %s addr=%x slice=%d, volume=%d z_step=%g avgSD=%g",
    407               volPtr->name(), volPtr, slice_index, volume_index, z_step, avgSampleDistance);
     407              volume->name(), volume, slice_index, volume_index, z_step, avgSampleDistance);
    408408#endif
    409         activateVolumeShader(volPtr, false, sampleRatio);
     409        activateVolumeShader(volume, false, sampleRatio);
    410410        glPopMatrix();
    411411
     
    493493
    494494void
    495 VolumeRenderer::activateVolumeShader(Volume *volPtr, bool sliceMode,
     495VolumeRenderer::activateVolumeShader(Volume *volume, bool sliceMode,
    496496                                     float sampleRatio)
    497497{
    498498    //vertex shader
    499499    _stdVertexShader->bind();
    500     TransferFunction *tfPtr  = volPtr->transferFunction();
    501     if (volPtr->volumeType() == Volume::CUBIC) {
    502         _regularVolumeShader->bind(tfPtr->id(), volPtr, sliceMode, sampleRatio);
    503     } else if (volPtr->volumeType() == Volume::ZINCBLENDE) {
    504         _zincBlendeShader->bind(tfPtr->id(), volPtr, sliceMode, sampleRatio);
     500    TransferFunction *transferFunc  = volume->transferFunction();
     501    if (volume->volumeType() == Volume::CUBIC) {
     502        _regularVolumeShader->bind(transferFunc->id(), volume, sliceMode, sampleRatio);
     503    } else if (volume->volumeType() == Volume::ZINCBLENDE) {
     504        _zincBlendeShader->bind(transferFunc->id(), volume, sliceMode, sampleRatio);
    505505    }
    506506}
  • nanovis/branches/1.1/VtkReader.cpp

    r3576 r4612  
    342342    lz = (nz - 1) * dz;
    343343
    344     Volume *volPtr = NULL;
     344    Volume *volume = NULL;
    345345    double vmin = DBL_MAX;
    346346    double nzero_min = DBL_MAX;
     
    477477          vmin, vmax, nzero_min);
    478478
    479     volPtr = NanoVis::loadVolume(tag, nx, ny, nz, 4, data,
     479    volume = NanoVis::loadVolume(tag, nx, ny, nz, 4, data,
    480480                                 vmin, vmax, nzero_min);
    481     volPtr->xAxis.setRange(x0, x0 + lx);
    482     volPtr->yAxis.setRange(y0, y0 + ly);
    483     volPtr->zAxis.setRange(z0, z0 + lz);
    484     volPtr->updatePending = true;
     481    volume->xAxis.setRange(x0, x0 + lx);
     482    volume->yAxis.setRange(y0, y0 + ly);
     483    volume->zAxis.setRange(z0, z0 + lz);
     484    volume->updatePending = true;
    485485
    486486    delete [] data;
     
    492492    float dy0 = -0.5*ly/lx;
    493493    float dz0 = -0.5*lz/lx;
    494     if (volPtr) {
    495         volPtr->location(vrmath::Vector3f(dx0, dy0, dz0));
     494    if (volume) {
     495        volume->location(vrmath::Vector3f(dx0, dy0, dz0));
    496496        TRACE("Set volume location to %g %g %g", dx0, dy0, dz0);
    497497    }
    498     return volPtr;
    499 }
     498    return volume;
     499}
  • nanovis/branches/1.1/dxReader.cpp

    r3576 r4612  
    225225        return NULL;
    226226    }
    227     Volume *volPtr = NULL;
     227    Volume *volume = NULL;
    228228    float *data = NULL;
    229229    double vmin = DBL_MAX;
     
    481481          vmin, vmax, nzero_min);
    482482
    483     volPtr = NanoVis::loadVolume(tag, nx, ny, nz, 4, data,
     483    volume = NanoVis::loadVolume(tag, nx, ny, nz, 4, data,
    484484                                 vmin, vmax, nzero_min);
    485     volPtr->xAxis.setRange(x0, x0 + lx);
    486     volPtr->yAxis.setRange(y0, y0 + ly);
    487     volPtr->zAxis.setRange(z0, z0 + lz);
    488     volPtr->updatePending = true;
     485    volume->xAxis.setRange(x0, x0 + lx);
     486    volume->yAxis.setRange(y0, y0 + ly);
     487    volume->zAxis.setRange(z0, z0 + lz);
     488    volume->updatePending = true;
    489489
    490490    // TBD..
    491491#if 0 && defined(USE_POINTSET_RENDERER)
    492492    PointSet *pset = new PointSet();
    493     pset->initialize(volPtr, (float*)data);
     493    pset->initialize(volume, (float*)data);
    494494    pset->setVisible(true);
    495495    NanoVis::pointSet.push_back(pset);
    496496    updateColor(pset);
    497     volPtr->pointsetIndex = NanoVis::pointSet.size() - 1;
     497    volume->pointsetIndex = NanoVis::pointSet.size() - 1;
    498498#endif
    499499    delete [] data;
     
    505505    float dy0 = -0.5*ly/lx;
    506506    float dz0 = -0.5*lz/lx;
    507     if (volPtr) {
    508         volPtr->location(vrmath::Vector3f(dx0, dy0, dz0));
     507    if (volume) {
     508        volume->location(vrmath::Vector3f(dx0, dy0, dz0));
    509509        TRACE("Set volume location to %g %g %g", dx0, dy0, dz0);
    510510    }
    511     return volPtr;
     511    return volume;
    512512}
  • nanovis/branches/1.1/nanovis.cpp

    r4611 r4612  
    5959#include "define.h"
    6060
    61 #include "FlowCmd.h"
     61#include "Command.h"
     62#include "Flow.h"
    6263#include "Grid.h"
    6364#include "HeightMap.h"
    6465#include "NvCamera.h"
    6566#include "NvShader.h"
    66 #include "NvFlowVisRenderer.h"
    6767#include "NvLIC.h"
    6868#include "NvZincBlendeReconstructor.h"
     
    8282using namespace nv::graphics;
    8383using namespace nv::util;
     84using namespace vrmath;
    8485
    8586#define SIZEOF_BMP_HEADER   54
     
    141142float NanoVis::wMin = FLT_MAX;
    142143float NanoVis::wMax = -FLT_MAX;
    143 vrmath::Vector3f NanoVis::sceneMin, NanoVis::sceneMax;
     144Vector3f NanoVis::sceneMin, NanoVis::sceneMax;
    144145
    145146VolumeRenderer *NanoVis::volRenderer = NULL;
    146 #ifdef notdef
    147 NvFlowVisRenderer *NanoVis::flowVisRenderer = NULL;
    148 #endif
    149147VelocityArrowsSlice *NanoVis::velocityArrowsSlice = NULL;
    150148NvLIC *NanoVis::licRenderer = NULL;
     
    167165GLuint NanoVis::_finalDepthRb = 0;
    168166
    169 // in Command.cpp
    170 extern Tcl_Interp *initTcl();
    171 
    172167// Default camera location.
    173168float def_eye_x = 0.0f;
     
    199194        delete legendTexture;
    200195    }
    201 #ifdef notdef
    202     if (flowVisRenderer != NULL) {
    203         TRACE("Deleting flowVisRenderer");
    204         delete flowVisRenderer;
    205     }
    206 #endif
    207196    TRACE("Deleting flows");
    208197    deleteFlows(interp);
     
    570559/** \brief Load a 3D volume
    571560 *
    572  * \param n_component the number of scalars for each space point. All component
     561 * \param name Volume ID
     562 * \param width Number of samples in X direction
     563 * \param height Number of samples in Y direction
     564 * \param depth Number of samples in Z direction
     565 * \param numComponents the number of scalars for each space point. All component
    573566 * scalars for a point are placed consequtively in data array
    574567 * width, height and depth: number of points in each dimension
     568 * \param data Array of floats
     569 * \param vmin Min value of field
     570 * \param vmax Max value of field
     571 * \param nonZeroMin Minimum non-zero value of field
    575572 * \param data pointer to an array of floats.
    576573 */
    577574Volume *
    578575NanoVis::loadVolume(const char *name, int width, int height, int depth,
    579                     int n_component, float *data, double vmin, double vmax,
    580                     double nzero_min)
     576                    int numComponents, float *data, double vmin, double vmax,
     577                    double nonZeroMin)
    581578{
    582579    VolumeHashmap::iterator itr = volumeTable.find(name);
     
    588585    Volume *volume = new Volume(0.f, 0.f, 0.f,
    589586                                width, height, depth,
    590                                 n_component,
    591                                 data, vmin, vmax, nzero_min);
     587                                numComponents,
     588                                data, vmin, vmax, nonZeroMin);
    592589    Volume::updatePending = true;
    593590    volume->name(name);
     
    884881    fonts->setFont("verdana");
    885882
    886 #ifdef notdef
    887     flowVisRenderer = new NvFlowVisRenderer(NMESH, NMESH);
    888 #endif
    889883    velocityArrowsSlice = new VelocityArrowsSlice;
    890 
    891884    licRenderer = new NvLIC(NMESH, NPIX, NPIX, _licAxis, _licSlice);
    892885
     
    936929    initOffscreenBuffer();    //frame buffer object for offscreen rendering
    937930
    938     //create volume renderer and add volumes to it
     931    //create volume renderer
    939932    volRenderer = new VolumeRenderer();
    940933
     
    949942    TRACE("leaving initGL");
    950943}
    951 
    952 #ifdef DO_RLE
    953 char rle[512*512*3];
    954 int rleSize;
    955 
    956 short offsets[512*512*3];
    957 int offsetsSize;
    958 
    959 static void
    960 doRle()
    961 {
    962     int len = NanoVis::winWidth*NanoVis::winHeight*3;
    963     rleSize = 0;
    964     offsetsSize = 0;
    965 
    966     int i = 0;
    967     while (i < len) {
    968         if (NanoVis::screenBuffer[i] == 0) {
    969             int pos = i+1;
    970             while ( (pos < len) && (NanoVis::screenBuffer[pos] == 0)) {
    971                 pos++;
    972             }
    973             offsets[offsetsSize++] = -(pos - i);
    974             i = pos;
    975         }
    976 
    977         else {
    978             int pos;
    979             for (pos = i; (pos < len) && (NanoVis::screenBuffer[pos] != 0); pos++){
    980                 rle[rleSize++] = NanoVis::screenBuffer[pos];
    981             }
    982             offsets[offsetsSize++] = (pos - i);
    983             i = pos;
    984         }
    985 
    986     }
    987 }
    988 #endif
    989944
    990945// used internally to build up the BMP file header
     
    15251480            continue;
    15261481
    1527         vrmath::Vector3f bmin, bmax;
     1482        Vector3f bmin, bmax;
    15281483        volume->getWorldSpaceBounds(bmin, bmax);
    15291484        if (bmin.x > bmax.x)
     
    15571512            continue;
    15581513
    1559         vrmath::Vector3f bmin, bmax;
     1514        Vector3f bmin, bmax;
    15601515        heightMap->getWorldSpaceBounds(bmin, bmax);
    15611516        if (bmin.x > bmax.x)
     
    15821537    }
    15831538
    1584     vrmath::Vector3f flowMin, flowMax;
     1539    Vector3f flowMin, flowMax;
    15851540    getFlowBounds(flowMin, flowMax, onlyVisible);
    15861541    if (flowMin.x < flowMax.x) {
     
    16221577    TRACE("Setting bgcolor to %g %g %g", color[0], color[1], color[2]);
    16231578    glClearColor(color[0], color[1], color[2], 1);
     1579}
     1580
     1581Flow *
     1582NanoVis::getFlow(const char *name)
     1583{
     1584    FlowHashmap::iterator itr = flowTable.find(name);
     1585    if (itr == flowTable.end()) {
     1586        TRACE("Can't find flow '%s'", name);
     1587        return NULL;
     1588    }
     1589    return itr->second;
     1590}
     1591
     1592Flow *
     1593NanoVis::createFlow(Tcl_Interp *interp, const char *name)
     1594{
     1595    FlowHashmap::iterator itr = flowTable.find(name);
     1596    if (itr != flowTable.end()) {
     1597        ERROR("Flow '%s' already exists", name);
     1598        return NULL;
     1599    }
     1600    Flow *flow = new Flow(interp, name);
     1601    flowTable[name] = flow;
     1602    return flow;
     1603}
     1604
     1605/**
     1606 * \brief Delete flow object and hash table entry
     1607 *
     1608 * This is called by the flow command instance delete callback
     1609 */
     1610void
     1611NanoVis::deleteFlow(const char *name)
     1612{
     1613    FlowHashmap::iterator itr = flowTable.find(name);
     1614    if (itr != flowTable.end()) {
     1615        delete itr->second;
     1616        flowTable.erase(itr);
     1617    }
     1618}
     1619
     1620/**
     1621 * \brief Delete all flow object commands
     1622 *
     1623 * This will also delete the flow objects and hash table entries
     1624 */
     1625void
     1626NanoVis::deleteFlows(Tcl_Interp *interp)
     1627{
     1628    FlowHashmap::iterator itr;
     1629    for (itr = flowTable.begin();
     1630         itr != flowTable.end(); ++itr) {
     1631        Tcl_DeleteCommandFromToken(interp, itr->second->getCommandToken());
     1632    }
     1633    flowTable.clear();
     1634}
     1635
     1636bool
     1637NanoVis::mapFlows()
     1638{
     1639    TRACE("Enter");
     1640
     1641    flags &= ~MAP_FLOWS;
     1642
     1643    /*
     1644     * Step 1. Get the overall min and max magnitudes of all the
     1645     *         flow vectors.
     1646     */
     1647    magMin = DBL_MAX, magMax = -DBL_MAX;
     1648
     1649    for (FlowHashmap::iterator itr = flowTable.begin();
     1650         itr != flowTable.end(); ++itr) {
     1651        Flow *flow = itr->second;
     1652        double min, max;
     1653        if (!flow->isDataLoaded()) {
     1654            continue;
     1655        }
     1656        Rappture::Unirect3d *data = flow->data();
     1657        min = data->magMin();
     1658        max = data->magMax();
     1659        if (min < magMin) {
     1660            magMin = min;
     1661        }
     1662        if (max > magMax) {
     1663            magMax = max;
     1664        }
     1665        if (data->xMin() < xMin) {
     1666            xMin = data->xMin();
     1667        }
     1668        if (data->yMin() < yMin) {
     1669            yMin = data->yMin();
     1670        }
     1671        if (data->zMin() < zMin) {
     1672            zMin = data->zMin();
     1673        }
     1674        if (data->xMax() > xMax) {
     1675            xMax = data->xMax();
     1676        }
     1677        if (data->yMax() > yMax) {
     1678            yMax = data->yMax();
     1679        }
     1680        if (data->zMax() > zMax) {
     1681            zMax = data->zMax();
     1682        }
     1683    }
     1684
     1685    TRACE("magMin=%g magMax=%g", NanoVis::magMin, NanoVis::magMax);
     1686
     1687    /*
     1688     * Step 2. Generate the vector field from each data set.
     1689     */
     1690    for (FlowHashmap::iterator itr = flowTable.begin();
     1691         itr != flowTable.end(); ++itr) {
     1692        Flow *flow = itr->second;
     1693        if (!flow->isDataLoaded()) {
     1694            continue; // Flow exists, but no data has been loaded yet.
     1695        }
     1696        if (flow->visible()) {
     1697            flow->initializeParticles();
     1698        }
     1699        if (!flow->scaleVectorField()) {
     1700            return false;
     1701        }
     1702        // FIXME: This doesn't work when there is more than one flow.
     1703        licRenderer->setOffset(flow->getRelativePosition());
     1704        velocityArrowsSlice->slicePos(flow->getRelativePosition());
     1705    }
     1706    advectFlows();
     1707    return true;
     1708}
     1709
     1710void
     1711NanoVis::getFlowBounds(Vector3f& min,
     1712                       Vector3f& max,
     1713                       bool onlyVisible)
     1714{
     1715    TRACE("Enter");
     1716
     1717    min.set(FLT_MAX, FLT_MAX, FLT_MAX);
     1718    max.set(-FLT_MAX, -FLT_MAX, -FLT_MAX);
     1719
     1720    for (FlowHashmap::iterator itr = flowTable.begin();
     1721         itr != flowTable.end(); ++itr) {
     1722        itr->second->getBounds(min, max, onlyVisible);
     1723    }
     1724}
     1725
     1726void
     1727NanoVis::renderFlows()
     1728{
     1729    for (FlowHashmap::iterator itr = flowTable.begin();
     1730         itr != flowTable.end(); ++itr) {
     1731        Flow *flow = itr->second;
     1732        if (flow->isDataLoaded() && flow->visible()) {
     1733            flow->render();
     1734        }
     1735    }
     1736    flags &= ~REDRAW_PENDING;
     1737}
     1738
     1739void
     1740NanoVis::resetFlows()
     1741{
     1742    if (licRenderer->active()) {
     1743        NanoVis::licRenderer->reset();
     1744    }
     1745    for (FlowHashmap::iterator itr = flowTable.begin();
     1746         itr != flowTable.end(); ++itr) {
     1747        Flow *flow = itr->second;
     1748        if (flow->isDataLoaded() && flow->visible()) {
     1749            flow->resetParticles();
     1750        }
     1751    }
     1752}   
     1753
     1754void
     1755NanoVis::advectFlows()
     1756{
     1757    for (FlowHashmap::iterator itr = flowTable.begin();
     1758         itr != flowTable.end(); ++itr) {
     1759        Flow *flow = itr->second;
     1760        if (flow->isDataLoaded() && flow->visible()) {
     1761            flow->advect();
     1762        }
     1763    }
    16241764}
    16251765
     
    16521792    bindOffscreenBuffer();
    16531793
    1654     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear screen
    1655 
    1656     //3D rendering mode
     1794    //clear screen
     1795    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     1796
    16571797    glEnable(GL_DEPTH_TEST);
    16581798    glEnable(GL_COLOR_MATERIAL);
     
    17011841        velocityArrowsSlice->render();
    17021842    }
    1703 #ifdef notdef
    1704     if ((flowVisRenderer != NULL) && (flowVisRenderer->active())) {
    1705         flowVisRenderer->render();
    1706     }
    1707 #endif
    17081843    if (!flowTable.empty()) {
    17091844        renderFlows();
     
    18261961        exitService(90);
    18271962    }
    1828 #ifdef DO_RLE
    1829     doRle();
    1830     int sizes[2] = {  offsets_size*sizeof(offsets[0]), rle_size };
    1831     TRACE("Writing %d,%d", sizes[0], sizes[1]);
    1832     write(1, &sizes, sizeof(sizes));
    1833     write(1, offsets, offsets_size*sizeof(offsets[0]));
    1834     write(1, rle, rle_size);    //unsigned byte
    1835 #else
     1963
    18361964    ppmWrite("nv>image -type image -bytes");
    1837 #endif
     1965
    18381966    TRACE("Leave");
    18391967}
  • nanovis/branches/1.1/nanovis.h

    r4611 r4612  
    5151class PointSetRenderer;
    5252class NvParticleRenderer;
    53 class NvFlowVisRenderer;
    5453class PlaneRenderer;
    5554class VelocityArrowsSlice;
     
    5857class Texture2D;
    5958class HeightMap;
    60 class NvVectorField;
    6159class Grid;
    6260class NvCamera;
    6361class TransferFunction;
    6462class Volume;
    65 class FlowCmd;
     63class Flow;
    6664
    6765class NanoVis
     
    8886    typedef std::tr1::unordered_map<TransferFunctionId, TransferFunction *> TransferFunctionHashmap;
    8987    typedef std::tr1::unordered_map<VolumeId, Volume *> VolumeHashmap;
    90     typedef std::tr1::unordered_map<FlowId, FlowCmd *> FlowHashmap;
     88    typedef std::tr1::unordered_map<FlowId, Flow *> FlowHashmap;
    9189    typedef std::tr1::unordered_map<HeightMapId, HeightMap *> HeightMapHashmap;
    9290
     
    134132
    135133    static Volume *loadVolume(const char *tag, int width, int height, int depth,
    136                               int n, float* data, double vmin, double vmax,
     134                              int numComponents, float *data, double vmin, double vmax,
    137135                              double nonZeroMin);
    138136
    139     static void removeVolume(Volume *volPtr);
     137    static void removeVolume(Volume *volume);
    140138
    141139    static void readScreen()
     
    149147    }
    150148
    151     static FlowCmd *getFlow(const char *name);
    152     static FlowCmd *createFlow(Tcl_Interp *interp, const char *name);
     149    static Flow *getFlow(const char *name);
     150    static Flow *createFlow(Tcl_Interp *interp, const char *name);
    153151    static void deleteFlow(const char *name);
    154152    static void deleteFlows(Tcl_Interp *interp);
     
    190188
    191189    static VolumeRenderer *volRenderer;
    192 #ifdef notdef
    193     static NvFlowVisRenderer *flowVisRenderer;
    194 #endif
    195190    static VelocityArrowsSlice *velocityArrowsSlice;
    196191    static NvLIC *licRenderer;
Note: See TracChangeset for help on using the changeset viewer.