Changeset 3935 for trunk


Ignore:
Timestamp:
Sep 18, 2013 2:51:50 AM (11 years ago)
Author:
ldelgass
Message:

First pass at loading VTK vector data for flows in nanovis

Location:
trunk/packages/vizservers/nanovis
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/nanovis/Doxyfile.in

    r3597 r3935  
    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
     601EXCLUDE                = @srcdir@/bak @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
  • trunk/packages/vizservers/nanovis/Flow.cpp

    r3630 r3935  
    4141    _interp(interp),
    4242    _name(name),
    43     _data(NULL),
    4443    _volume(NULL)
    4544{
     
    5958    Rappture::FreeSwitches(_switches, &_sv, 0);
    6059
    61     if (_data != NULL) {
    62         delete _data;
    63     }
    6460    if (_volume != NULL) {
    6561        NanoVis::removeVolume(_volume);
     
    9187    if (isDataLoaded()) {
    9288        BBox bbox;
    93         data()->getBounds(bbox.min, bbox.max);
     89        _volume->getBounds(bbox.min, bbox.max);
    9490        allBounds.extend(bbox);
    9591    }
     
    115111    switch (position->axis) {
    116112    case AXIS_X: 
    117         return (position->value - _data->xMin()) /
    118             (_data->xMax() - _data->xMin());
     113        return (position->value - _volume->xAxis.min()) /
     114            (_volume->xAxis.max() - _volume->xAxis.min());
    119115    case AXIS_Y: 
    120         return (position->value - _data->yMin()) /
    121             (_data->yMax() - _data->yMin());
     116        return (position->value - _volume->yAxis.min()) /
     117            (_volume->yAxis.max() - _volume->yAxis.min());
    122118    case AXIS_Z: 
    123         return (position->value - _data->zMin()) /
    124             (_data->zMax() - _data->zMin());
     119        return (position->value - _volume->zAxis.min()) /
     120            (_volume->zAxis.max() - _volume->zAxis.min());
    125121    }
    126122    return 0.0;
     
    303299Flow::scaleVectorField()
    304300{
    305     float *vdata = getScaledVector();
    306     if (_volume != NULL) {
    307         TRACE("Updating existing volume: %s", _volume->name());
    308         _volume->setData(vdata, magMin, magMax, 0);
    309     } else {
    310         _volume = makeVolume(vdata);
    311         if (_volume == NULL) {
    312             return false;
    313         }
    314     }
    315     delete [] vdata;
     301    if (_volume == NULL) {
     302        return false;
     303    }
     304
    316305    // FIXME: LIC and arrows should be per-flow
    317306    if (NanoVis::licRenderer != NULL) {
     
    346335
    347336float *
    348 Flow::getScaledVector()
    349 {
    350     assert(_data->nComponents() == 3);
    351     size_t n = _data->nValues() / _data->nComponents() * 4;
     337Flow::getScaledVector(Rappture::Unirect3d *unirect)
     338{
     339    assert(unirect->nComponents() == 3);
     340    size_t n = unirect->nValues() / unirect->nComponents() * 4;
    352341    float *data = new float[n];
    353342    memset(data, 0, sizeof(float) * n);
    354343    float *dest = data;
    355     const float *values = _data->values();
    356     for (size_t iz = 0; iz < _data->zNum(); iz++) {
    357         for (size_t iy = 0; iy < _data->yNum(); iy++) {
    358             for (size_t ix = 0; ix < _data->xNum(); ix++) {
     344    const float *values = unirect->values();
     345    for (size_t iz = 0; iz < unirect->zNum(); iz++) {
     346        for (size_t iy = 0; iy < unirect->yNum(); iy++) {
     347            for (size_t ix = 0; ix < unirect->xNum(); ix++) {
    359348                double vx, vy, vz, vm;
    360349                vx = values[0];
     
    362351                vz = values[2];
    363352                vm = sqrt(vx*vx + vy*vy + vz*vz);
    364                 dest[0] = vm / magMax;
    365                 dest[1] = vx /(2.0 * magMax) + 0.5;
    366                 dest[2] = vy /(2.0 * magMax) + 0.5;
    367                 dest[3] = vz /(2.0 * magMax) + 0.5;
     353                dest[0] = vm / unirect->magMax();
     354                dest[1] = vx /(2.0 * unirect->magMax()) + 0.5;
     355                dest[2] = vy /(2.0 * unirect->magMax()) + 0.5;
     356                dest[3] = vz /(2.0 * unirect->magMax()) + 0.5;
    368357                values += 3;
    369358                dest += 4;
     
    375364
    376365Volume *
    377 Flow::makeVolume(float *data)
     366Flow::makeVolume(Rappture::Unirect3d *unirect, float *data)
    378367{
    379368    Volume *volume =
    380369        NanoVis::loadVolume(_name.c_str(),
    381                             _data->xNum(),
    382                             _data->yNum(),
    383                             _data->zNum(),
     370                            unirect->xNum(),
     371                            unirect->yNum(),
     372                            unirect->zNum(),
    384373                            4, data,
    385                             magMin, magMax, 0);
    386     volume->xAxis.setRange(_data->xMin(), _data->xMax());
    387     volume->yAxis.setRange(_data->yMin(), _data->yMax());
    388     volume->zAxis.setRange(_data->zMin(), _data->zMax());
    389 
    390     TRACE("mag=%g %g", magMin, magMax);
    391 
    392     volume->disableCutplane(0);
    393     volume->disableCutplane(1);
    394     volume->disableCutplane(2);
     374                            unirect->magMin(),
     375                            unirect->magMax(),
     376                            0);
     377    volume->xAxis.setRange(unirect->xMin(), unirect->xMax());
     378    volume->yAxis.setRange(unirect->yMin(), unirect->yMax());
     379    volume->zAxis.setRange(unirect->zMin(), unirect->zMax());
     380
     381    TRACE("mag=%g %g", unirect->magMin(), unirect->magMax());
     382
     383    return volume;
     384}
     385
     386void
     387Flow::initVolume()
     388{
     389    _volume->disableCutplane(0);
     390    _volume->disableCutplane(1);
     391    _volume->disableCutplane(2);
    395392
    396393    /* Initialize the volume with the previously configured values. */
    397     volume->transferFunction(_sv.transferFunction);
    398     volume->dataEnabled(_sv.showVolume);
    399     volume->twoSidedLighting(_sv.twoSidedLighting);
    400     volume->outline(_sv.showOutline);
    401     volume->opacityScale(_sv.opacity);
    402     volume->ambient(_sv.ambient);
    403     volume->diffuse(_sv.diffuse);
    404     volume->specularLevel(_sv.specular);
    405     volume->specularExponent(_sv.specularExp);
     394    _volume->transferFunction(_sv.transferFunction);
     395    _volume->dataEnabled(_sv.showVolume);
     396    _volume->twoSidedLighting(_sv.twoSidedLighting);
     397    _volume->outline(_sv.showOutline);
     398    _volume->opacityScale(_sv.opacity);
     399    _volume->ambient(_sv.ambient);
     400    _volume->diffuse(_sv.diffuse);
     401    _volume->specularLevel(_sv.specular);
     402    _volume->specularExponent(_sv.specularExp);
    406403
    407404    Volume::updatePending = true;
    408     return volume;
    409 }
     405}
  • trunk/packages/vizservers/nanovis/Flow.h

    r3630 r3935  
    8383    void getBoxNames(std::vector<std::string>& names);
    8484
    85     bool scaleVectorField();
    86 
    8785    bool visible()
    8886    {
     
    9795    bool isDataLoaded()
    9896    {
    99         return (_data != NULL);
    100     }
    101 
    102     Rappture::Unirect3d *data()
    103     {
    104         return _data;
    105     }
    106 
    107     void data(Rappture::Unirect3d *data)
    108     {
    109         if (_data != NULL) {
    110             delete _data;
    111         }
    112         _data = data;
     97        return (_volume != NULL);
     98    }
     99
     100    void getVectorRange(double range[])
     101    {
     102        range[0] = _volume->wAxis.min();
     103        range[1] = _volume->wAxis.max();
     104    }
     105
     106    void data(Rappture::Unirect3d *unirect)
     107    {
     108        float *vdata = getScaledVector(unirect);
     109        _volume = makeVolume(unirect, vdata);
     110        delete [] vdata;
     111        initVolume();
     112        scaleVectorField();
     113        delete unirect;
     114    }
     115
     116    void data(Volume *volume)
     117    {
     118        _volume = volume;
     119        initVolume();
     120        scaleVectorField();
    113121    }
    114122
     
    198206    typedef std::tr1::unordered_map<BoxId, FlowBox *> BoxHashmap;
    199207
    200     float *getScaledVector();
    201 
    202     Volume *makeVolume(float *data);
     208    void initVolume();
     209
     210    bool scaleVectorField();
     211
     212    float *getScaledVector(Rappture::Unirect3d *unirect);
     213
     214    Volume *makeVolume(Rappture::Unirect3d *unirect, float *data);
    203215
    204216    void renderBoxes();
     
    219231
    220232    /**
    221      * Uniform rectangular data
    222      * representing the mesh and vector
    223      * field values.  These values are
    224      * kept to regenerate the volume
    225      * associated with the flow. */
    226     Rappture::Unirect3d *_data;
    227 
    228     /**
    229233     * The volume associated with the
    230234     * flow.  This isn't the same thing as
  • trunk/packages/vizservers/nanovis/FlowCmd.cpp

    r3630 r3935  
    3030#include "Command.h"
    3131#include "PPMWriter.h"
     32#ifdef USE_VTK
     33#include "VtkDataSetReader.h"
     34#endif
     35#include "VtkReader.h"
    3236#include "FlowCmd.h"
    3337#include "FlowTypes.h"
     
    243247    size_t length = buf.size();
    244248
    245     Rappture::Unirect3d *dataPtr;
    246     dataPtr = new Rappture::Unirect3d(nComponents);
     249    Rappture::Unirect3d *unirect = NULL;
     250    Volume *volume = NULL;
    247251
    248252    Flow *flow = (Flow *)clientData;
    249253    if ((length > 4) && (strncmp(bytes, "<DX>", 4) == 0)) {
    250         if (!dataPtr->importDx(result, nComponents, length - 4, bytes + 4)) {
     254        unirect = new Rappture::Unirect3d(nComponents);
     255        if (!unirect->importDx(result, nComponents, length - 4, bytes + 4)) {
    251256            Tcl_AppendResult(interp, result.remark(), (char *)NULL);
    252             delete dataPtr;
     257            delete unirect;
    253258            return TCL_ERROR;
    254259        }
    255260    } else if ((length > 10) && (strncmp(bytes, "unirect3d ", 10) == 0)) {
    256         if (dataPtr->parseBuffer(interp, buf) != TCL_OK) {
    257             delete dataPtr;
     261        unirect = new Rappture::Unirect3d(nComponents);
     262        if (unirect->parseBuffer(interp, buf) != TCL_OK) {
     263            delete unirect;
    258264            return TCL_ERROR;
    259265        }
    260266    } else if ((length > 10) && (strncmp(bytes, "unirect2d ", 10) == 0)) {
     267        unirect = new Rappture::Unirect3d(nComponents);
    261268        Rappture::Unirect2d *u2dPtr;
    262269        u2dPtr = new Rappture::Unirect2d(nComponents);
     
    265272            return TCL_ERROR;
    266273        }
    267         dataPtr->convert(u2dPtr);
     274        unirect->convert(u2dPtr);
    268275        delete u2dPtr;
    269 #if 0
    270276    } else if ((length > 14) && (strncmp(bytes, "# vtk DataFile", 14) == 0)) {
    271277        TRACE("VTK loading...");
     
    277283        }
    278284        Rappture::Outcome context;
    279         volume = load_vtk_volume_stream(context, tag, fdata);
     285#ifdef USE_VTK
     286        volume = load_vtk_volume_stream(context, flow->name(), bytes, length);
     287#else
     288        std::stringstream fdata;
     289        fdata.write(bytes, nBytes);
     290        volume = load_vtk_volume_stream(context, flow->name(), fdata);
     291#endif
    280292        if (volume == NULL) {
    281293            Tcl_AppendResult(interp, context.remark(), (char*)NULL);
    282294            return TCL_ERROR;
    283295        }
    284 #endif
    285296    } else {
    286297        TRACE("header is %.14s", buf.bytes());
    287         if (!dataPtr->importDx(result, nComponents, length, bytes)) {
     298        if (!unirect->importDx(result, nComponents, length, bytes)) {
    288299            Tcl_AppendResult(interp, result.remark(), (char *)NULL);
    289             delete dataPtr;
    290             return TCL_ERROR;
    291         }
    292     }
    293     if (dataPtr->nValues() == 0) {
    294         delete dataPtr;
     300            delete unirect;
     301            return TCL_ERROR;
     302        }
     303    }
     304    if (unirect != NULL && unirect->nValues() == 0) {
     305        delete unirect;
    295306        Tcl_AppendResult(interp, "no data found in stream", (char *)NULL);
    296307        return TCL_ERROR;
    297308    }
     309#if 0
    298310    TRACE("nx = %d ny = %d nz = %d",
    299           dataPtr->xNum(), dataPtr->yNum(), dataPtr->zNum());
     311          unirect->xNum(), unirect->yNum(), unirect->zNum());
    300312    TRACE("x0 = %lg y0 = %lg z0 = %lg",
    301           dataPtr->xMin(), dataPtr->yMin(), dataPtr->zMin());
     313          unirect->xMin(), unirect->yMin(), unirect->zMin());
    302314    TRACE("lx = %lg ly = %lg lz = %lg",
    303           dataPtr->xMax() - dataPtr->xMin(),
    304           dataPtr->yMax() - dataPtr->yMin(),
    305           dataPtr->zMax() - dataPtr->zMin());
     315          unirect->xMax() - unirect->xMin(),
     316          unirect->yMax() - unirect->yMin(),
     317          unirect->zMax() - unirect->zMin());
    306318    TRACE("dx = %lg dy = %lg dz = %lg",
    307           dataPtr->xNum() > 1 ? (dataPtr->xMax() - dataPtr->xMin())/(dataPtr->xNum()-1) : 0,
    308           dataPtr->yNum() > 1 ? (dataPtr->yMax() - dataPtr->yMin())/(dataPtr->yNum()-1) : 0,
    309           dataPtr->zNum() > 1 ? (dataPtr->zMax() - dataPtr->zMin())/(dataPtr->zNum()-1) : 0);
     319          unirect->xNum() > 1 ? (unirect->xMax() - unirect->xMin())/(unirect->xNum()-1) : 0,
     320          unirect->yNum() > 1 ? (unirect->yMax() - unirect->yMin())/(unirect->yNum()-1) : 0,
     321          unirect->zNum() > 1 ? (unirect->zMax() - unirect->zMin())/(unirect->zNum()-1) : 0);
    310322    TRACE("magMin = %lg magMax = %lg",
    311           dataPtr->magMin(), dataPtr->magMax());
    312     flow->data(dataPtr);
     323          unirect->magMin(), unirect->magMax());
     324#endif
     325    if (unirect != NULL) {
     326        flow->data(unirect);
     327    } else {
     328        flow->data(volume);
     329    }
     330    double range[2];
     331    flow->getVectorRange(range);
    313332    {
    314333        char info[1024];
    315334        int length =
    316335            sprintf(info, "nv>data tag %s min %g max %g\n",
    317                     flow->name(), dataPtr->magMin(), dataPtr->magMax());
     336                    flow->name(), range[0], range[1]);
    318337#ifdef USE_THREADS
    319338        queueResponse(info, (size_t)length, Response::VOLATILE);
     
    840859    }
    841860    if (Flow::updatePending) {
    842         NanoVis::mapFlows();
     861        NanoVis::setFlowRanges();
    843862    }
    844863    NanoVis::renderLegend(tf, Flow::magMin, Flow::magMax, w, h, label);
     
    965984    NanoVis::resetFlows();
    966985    if (Flow::updatePending) {
    967         NanoVis::mapFlows();
     986        NanoVis::setFlowRanges();
    968987    }
    969988    for (int i = 0; i < nSteps; i++) {
     
    9971016    assert(NanoVis::licRenderer != NULL);
    9981017    if (Flow::updatePending) {
    999         NanoVis::mapFlows();
     1018        NanoVis::setFlowRanges();
    10001019    }
    10011020    NanoVis::licRenderer->convolve();
  • trunk/packages/vizservers/nanovis/Grid.cpp

    r3916 r3935  
    2020
    2121#define NUMDIGITS       6
    22 #define GRID_TICK       0.05
     22#define TICK_LENGTH     0.05
     23#define LABEL_OFFSET    0.06
     24#define TITLE_OFFSET    0.2
    2325
    2426Grid::Grid() :
     
    5557    glEnable(GL_DEPTH_TEST);
    5658    glDisable(GL_TEXTURE_2D);
     59#ifdef notdef
    5760    glEnable(GL_BLEND);
    58 #ifdef notdef
    5961    glEnable(GL_LINE_SMOOTH);
     62#else
     63    glDisable(GL_BLEND);
    6064#endif
    6165
     
    7377    {
    7478        glVertex3f(0.0f, 0.0f, 0.0f);
    75         glVertex3f(1.0f + GRID_TICK, 0.0f, 0.0f);
     79        glVertex3f(1.0f + TICK_LENGTH/xAxis.range(), 0.0f, 0.0f);
    7680        glVertex3f(0.0f, 0.0f, 0.0f);
    77         glVertex3f(0.0f, 1.0f + GRID_TICK, 0.0f);
     81        glVertex3f(0.0f, 1.0f + TICK_LENGTH/yAxis.range(), 0.0f);
    7882        glVertex3f(0.0f, 0.0f, 0.0f);
    79         glVertex3f(0.0f, 0.0f, 1.0f + GRID_TICK);
     83        glVertex3f(0.0f, 0.0f, 1.0f + TICK_LENGTH/zAxis.range());
    8084    }
    8185    glEnd();
     
    96100            glVertex3f(x, 1.0f, 0.0f);
    97101            glVertex3f(x, 0.0f, 0.0f);
    98             glVertex3f(x, 0.0f, 1.0f + GRID_TICK);
     102            glVertex3f(x, 0.0f, 1.0f + TICK_LENGTH/zAxis.range());
    99103        }
    100104        for (result = yAxis.firstMajor(iter); result; result = iter.next()) {
     
    102106            y = yAxis.map(iter.getValue());
    103107            glVertex3f(0.0f, y, 0.0f);
    104             glVertex3f(1.0f + GRID_TICK, y, 0.0f);
     108            glVertex3f(1.0f + TICK_LENGTH/xAxis.range(), y, 0.0f);
    105109            glVertex3f(0.0f, y, 0.0f);
    106110            glVertex3f(0.0f, y, 1.0f);
     
    112116            glVertex3f(0.0f, 1.0f, z);
    113117            glVertex3f(0.0f, 0.0f, z);
    114             glVertex3f(1.0f + GRID_TICK, 0.0f, z);
     118            glVertex3f(1.0f + TICK_LENGTH/xAxis.range(), 0.0f, z);
    115119        }
    116120    }
     
    163167        glGetDoublev(GL_PROJECTION_MATRIX, prjm);
    164168        glGetIntegerv(GL_VIEWPORT, viewport);
    165        
     169
    166170        _font->begin();
    167         if (gluProject(1.2, 0.0, 0.0, mv, prjm, viewport, &wx, &wy, &wz) &&
     171        if (gluProject(1.0 + TITLE_OFFSET/xAxis.range(), 0.0, 0.0, mv, prjm, viewport, &wx, &wy, &wz) &&
    168172            wz >= 0.0 && wz <= 1.0) {
    169173            glLoadIdentity();
     
    176180        }
    177181       
    178         if (gluProject(0.0, 1.2, 0.0, mv, prjm, viewport, &wx, &wy, &wz) &&
     182        if (gluProject(0.0, 1.0 + TITLE_OFFSET/yAxis.range(), 0.0, mv, prjm, viewport, &wx, &wy, &wz) &&
    179183            wz >= 0.0 && wz <= 1.0) {
    180184            glLoadIdentity();
     
    187191        }
    188192       
    189         if (gluProject(0.0, 0.0, 1.2, mv, prjm, viewport, &wx, &wy, &wz) &&
     193        if (gluProject(0.0, 0.0, 1.0 + TITLE_OFFSET/zAxis.range(), mv, prjm, viewport, &wx, &wy, &wz) &&
    190194            wz >= 0.0 && wz <= 1.0) {
    191195            glLoadIdentity();
     
    203207            float x;
    204208            x = xAxis.map(iter.getValue());
    205             if (gluProject(x, 0.0f, 1.06f, mv, prjm, viewport, &wx, &wy, &wz) &&
     209            if (gluProject(x, 0.0f, 1.0 + LABEL_OFFSET/zAxis.range(), mv, prjm, viewport, &wx, &wy, &wz) &&
    206210                wz >= 0.0 && wz <= 1.0) {
    207211                char buff[20];
     
    215219            float y;
    216220            y = yAxis.map(iter.getValue());
    217             if (gluProject(1.06f, y, 0.0f, mv, prjm, viewport, &wx, &wy, &wz) &&
     221            if (gluProject(1.0 + LABEL_OFFSET/xAxis.range(), y, 0.0f, mv, prjm, viewport, &wx, &wy, &wz) &&
    218222                wz >= 0.0 && wz <= 1.0) {
    219223                char buff[20];
     
    224228            }
    225229        }
    226         for (result = zAxis.firstMajor(iter); result; result = iter.next()) {
     230        for (result = zAxis.firstMajor(iter) + LABEL_OFFSET/xAxis.range(); result; result = iter.next()) {
    227231            float z;
    228232            z = zAxis.map(iter.getValue());
    229             if (gluProject(1.06f, 0.0f, z, mv, prjm, viewport, &wx, &wy, &wz) &&
     233            if (gluProject(1.0 + LABEL_OFFSET/xAxis.range(), 0.0f, z, mv, prjm, viewport, &wx, &wy, &wz) &&
    230234                wz >= 0.0 && wz <= 1.0) {
    231235                char buff[20];
  • trunk/packages/vizservers/nanovis/ReaderCommon.cpp

    r3611 r3935  
    6464
    6565/**
     66 * \brief Normalize data to [0,1] based on vmin,vmax range
     67 *
     68 * Data outside of given range is clamped, and NaNs are set to
     69 * -1 in the output
     70 *
     71 * \param data Float array of unnormalized data, will be normalized on return
     72 * \param count Number of elts in array
     73 * \param stride Stride between values in data array
     74 * \param vmin Minimum value in data array
     75 * \param vmax Maximum value in data array
     76 */
     77void
     78nv::normalizeVector(float *data, int count, double vmin, double vmax)
     79{
     80    for (int p = 0; p < count; p++) {
     81        int i = p * 4;
     82        data[i  ] = data[i]/vmax;
     83        data[i+1] = data[i+1]/(2.0 * vmax) + 0.5;
     84        data[i+2] = data[i+2]/(2.0 * vmax) + 0.5;
     85        data[i+3] = data[i+3]/(2.0 * vmax) + 0.5;
     86    }
     87}
     88
     89/**
    6690 * \brief Compute Sobel filtered gradients for a 3D volume
    6791 *
  • trunk/packages/vizservers/nanovis/ReaderCommon.h

    r3613 r3935  
    1515normalizeScalar(float *data, int count, int stride, double min, double max);
    1616
     17extern void
     18normalizeVector(float *data, int count, double min, double max);
     19
    1720extern float *
    1821computeGradient(float *data,
  • trunk/packages/vizservers/nanovis/Unirect.cpp

    r3611 r3935  
    88
    99#include <tcl.h>
    10 
    11 #include <RpField1D.h>
    12 #include <RpFieldRect3D.h>
    1310
    1411#include "Command.h"
     
    634631}
    635632
    636 bool
    637 Rappture::Unirect3d::resample(Rappture::Outcome &result, size_t nSamples)
    638 {
    639     Rappture::Mesh1D xgrid(_xMin, _xMax, _xNum);
    640     Rappture::Mesh1D ygrid(_yMin, _yMax, _yNum);
    641     Rappture::Mesh1D zgrid(_zMin, _zMax, _zNum);
    642     Rappture::FieldRect3D xfield(xgrid, ygrid, zgrid);
    643     Rappture::FieldRect3D yfield(xgrid, ygrid, zgrid);
    644     Rappture::FieldRect3D zfield(xgrid, ygrid, zgrid);
    645 
    646     size_t i, j;
    647     for (i = 0, j = 0; i < _nValues; i += _nComponents, j++) {
    648         double vx, vy, vz;
    649 
    650         vx = _values[i];
    651         vy = _values[i+1];
    652         vz = _values[i+2];
    653        
    654         xfield.define(j, vx);
    655         yfield.define(j, vy);
    656         zfield.define(j, vz);
    657     }
    658     // Figure out a good mesh spacing
    659     double dx, dy, dz;
    660     double lx, ly, lz;
    661     lx = xfield.rangeMax(Rappture::xaxis) - xfield.rangeMin(Rappture::xaxis);
    662     ly = xfield.rangeMax(Rappture::yaxis) - xfield.rangeMin(Rappture::yaxis);
    663     lz = xfield.rangeMax(Rappture::zaxis) - xfield.rangeMin(Rappture::zaxis);
    664 
    665     double dmin;
    666     dmin = pow((lx*ly*lz)/((nSamples-1)*(nSamples-1)*(nSamples-1)), 0.333);
    667 
    668     /* Recompute new number of points for each axis. */
    669     _xNum = (size_t)ceil(lx/dmin);
    670     _yNum = (size_t)ceil(ly/dmin);
    671     _zNum = (size_t)ceil(lz/dmin);
    672 
    673 #ifndef HAVE_NPOT_TEXTURES
    674     // must be an even power of 2 for older cards
    675     _xNum = (int)pow(2.0, ceil(log10((double)_xNum)/log10(2.0)));
    676     _yNum = (int)pow(2.0, ceil(log10((double)_yNum)/log10(2.0)));
    677     _zNum = (int)pow(2.0, ceil(log10((double)_zNum)/log10(2.0)));
    678 #endif
    679 
    680     dx = lx/(double)(_xNum-1);
    681     dy = ly/(double)(_yNum-1);
    682     dz = lz/(double)(_zNum-1);
    683 
    684     TRACE("lx:%lf ly:%lf lz:%lf dmin:%lf dx:%lf dy:%lf dz:%lf", lx, ly, lz, dmin, dx, dy, dz);
    685 
    686     size_t n = _nComponents * _xNum * _yNum * _zNum;
    687     _values = (float *)realloc(_values, sizeof(float) * n);
    688     memset(_values, 0, sizeof(float) * n);
    689 
    690     // Generate the uniformly sampled rectangle that we need for a volume
    691     float *destPtr = _values;
    692     for (size_t i = 0; i < _zNum; i++) {
    693         double z;
    694 
    695         z = _zMin + (i * dx);
    696         for (size_t j = 0; j < _yNum; j++) {
    697             double y;
    698                
    699             y = _yMin + (j * dy);
    700             for (size_t k = 0; k < _xNum; k++) {
    701                 double x;
    702 
    703                 x = _xMin + (k * dz);
    704                 destPtr[0] = xfield.value(x, y, z);
    705                 destPtr[1] = yfield.value(x, y, z);
    706                 destPtr[2] = zfield.value(x, y, z);
    707             }
    708         }
    709     }
    710     _nValues = _xNum * _yNum * _zNum * _nComponents;
    711     return true;
    712 }
    713 
    714633void
    715634Rappture::Unirect3d::getVectorRange()
  • trunk/packages/vizservers/nanovis/Unirect.h

    r3630 r3935  
    229229    bool convert(Unirect2d *dataPtr);
    230230
    231     bool resample(Rappture::Outcome &context, size_t nSamples = 30);
    232 
    233231    bool isInitialized()
    234232    {
     
    247245    float _zValueMin, _zValueMax;
    248246    double _magMin, _magMax;                /* Range of magnitudes of vector
    249                                          * data. */
     247                                             * data. */
    250248    char *_xUnits;
    251249    char *_yUnits;
  • trunk/packages/vizservers/nanovis/Volume.cpp

    r3883 r3935  
    3131double Volume::valueMax = 1.0;
    3232
    33 Volume::Volume(int w, int h, int d,
    34                int n, float *data,
    35                double v0, double v1, double nonZeroMin) :
     33Volume::Volume(int width, int height, int depth,
     34               int numComponents, float *data,
     35               double vmin, double vmax, double nonZeroMin) :
    3636    _id(0),
    37     _width(w),
    38     _height(h),
    39     _depth(d),
     37    _width(width),
     38    _height(height),
     39    _depth(depth),
    4040    _transferFunc(NULL),
    4141    _ambient(0.6f),
     
    4646    _opacityScale(0.5f),
    4747    _data(NULL),
    48     _numComponents(n),
     48    _numComponents(numComponents),
    4949    _nonZeroMin(nonZeroMin),
    5050    _cutplanesVisible(true),
     
    6363    _outlineColor[0] = _outlineColor[1] = _outlineColor[2] = 1.0f;
    6464
    65     _tex = new Texture3D(_width, _height, _depth, GL_FLOAT, GL_LINEAR, n);
     65    _tex = new Texture3D(_width, _height, _depth, GL_FLOAT, GL_LINEAR, _numComponents);
    6666    int fcount = _width * _height * _depth * _numComponents;
    6767    _data = new float[fcount];
     
    7171    _id = _tex->id();
    7272
    73     wAxis.setRange(v0, v1);
     73    wAxis.setRange(vmin, vmax);
    7474
    7575    //Add cut planes. We create 3 default cut planes facing x, y, z directions.
     
    9191}
    9292
    93 void Volume::setData(float *data, double v0, double v1, double nonZeroMin)
     93void Volume::setData(float *data, double vmin, double vmax, double nonZeroMin)
    9494{
    9595    int fcount = _width * _height * _depth * _numComponents;
    9696    memcpy(_data, data, fcount * sizeof(float));
    9797    _tex->update(_data);
    98     wAxis.setRange(v0, v1);
     98    wAxis.setRange(vmin, vmax);
    9999    _nonZeroMin = nonZeroMin;
    100100    updatePending = true;
  • trunk/packages/vizservers/nanovis/Volume.h

    r3883 r3935  
    125125    }
    126126
    127     void setData(float *data, double v0, double v1, double nonZeroMin);
     127    void setData(float *data, double vmin, double vmax, double nonZeroMin);
    128128
    129129    const float *data() const
  • trunk/packages/vizservers/nanovis/VtkDataSetReader.cpp

    r3870 r3935  
    1111#include <vtkDataSet.h>
    1212#include <vtkImageData.h>
     13#include <vtkPointData.h>
     14#include <vtkDataArray.h>
    1315#include <vtkDataSetReader.h>
    1416#include <vtkCharArray.h>
     
    104106    memset(data, 0, npts * 4);
    105107
     108    bool isVectorData = (resampledDataSet->GetPointData()->GetVectors() != NULL);
     109
    106110    int ix = 0;
    107111    int iy = 0;
     
    109113    for (int p = 0; p < npts; p++) {
    110114        int nindex = p * 4;
    111         double val = resampledDataSet->GetScalarComponentAsDouble(ix, iy, iz, 0);
    112         data[nindex] = (float)val;
    113         if (val < vmin) {
     115        double val;
     116        if (isVectorData) {
     117            double vec[3];
     118            int loc[3];
     119            loc[0] = ix; loc[1] = iy; loc[2] = iz;
     120            vtkIdType idx = resampledDataSet->ComputePointId(loc);
     121            resampledDataSet->GetPointData()->GetVectors()->GetTuple(idx, vec);
     122            val = sqrt(vec[0]*vec[0] + vec[1]*vec[1] * vec[2]*vec[2]);
     123            data[nindex] = (float)val;
     124            data[nindex+1] = (float)vec[0];
     125            data[nindex+2] = (float)vec[1];
     126            data[nindex+3] = (float)vec[2];
     127        } else {
     128            val = resampledDataSet->GetScalarComponentAsDouble(ix, iy, iz, 0);
     129            data[nindex] = (float)val;
     130        }
     131         if (val < vmin) {
    114132            vmin = val;
    115133        } else if (val > vmax) {
     
    129147    }
    130148
    131     // scale all values [0-1], -1 => out of bounds
    132     normalizeScalar(data, npts, 4, vmin, vmax);
    133     computeSimpleGradient(data, nx, ny, nz,
    134                           dx, dy, dz);
     149    if (isVectorData) {
     150        // Normalize magnitude [0,1] and vector components [0,1]
     151        normalizeVector(data, npts, vmin, vmax);
     152    } else {
     153        // scale all values [0-1], -1 => out of bounds
     154        normalizeScalar(data, npts, 4, vmin, vmax);
     155        computeSimpleGradient(data, nx, ny, nz,
     156                              dx, dy, dz);
     157    }
    135158
    136159    TRACE("nx = %i ny = %i nz = %i", nx, ny, nz);
  • trunk/packages/vizservers/nanovis/ZincBlendeVolume.cpp

    r3630 r3935  
    2424using namespace vrmath;
    2525
    26 ZincBlendeVolume::ZincBlendeVolume(int w, int h, int d, int n,
     26ZincBlendeVolume::ZincBlendeVolume(int width, int height, int depth,
     27                                   int numComponents,
    2728                                   float *dataVolumeA, float *dataVolumeB,
    28                                    double v0, double v1, double non_zeromin,
     29                                   double vmin, double vmax, double nonZeroMin,
    2930                                   const Vector3f& cellSz) :
    30     Volume(w, h, d, n, dataVolumeA, v0, v1, non_zeromin),
     31    Volume(width, height, depth, numComponents, dataVolumeA, vmin, vmax, nonZeroMin),
    3132    cellSize(cellSz)
    3233{
     
    3435    _volumeType = ZINCBLENDE;
    3536
    36     //store member tex initialize in Volume() as zincblende_tex[0]
     37    //store member tex initialize in Volume() as zincblendeTex[0]
    3738    assert(_tex);
    3839    zincblendeTex[0] = _tex;
    3940
    4041    //now add another tex as zincblende_tex[1]
    41     Texture3D *secondTex = new Texture3D(w, h, d, GL_FLOAT, GL_LINEAR, n);
     42    Texture3D *secondTex = new Texture3D(width, height, depth, GL_FLOAT, GL_LINEAR, numComponents);
    4243    assert(secondTex);
    4344    secondTex->initialize(dataVolumeB);
  • trunk/packages/vizservers/nanovis/ZincBlendeVolume.h

    r3630 r3935  
    2323    ZincBlendeVolume(int width, int height, int depth, int numComponents,
    2424                     float *dataVolumeA, float *dataVolumeB,
    25                      double vmin, double vmax, double non_zeromin,
     25                     double vmin, double vmax, double nonZeroMin,
    2626                     const vrmath::Vector3f& cellSize);
    2727
  • trunk/packages/vizservers/nanovis/nanovis.cpp

    r3900 r3935  
    619619}
    620620
     621/**
     622 * \brief Called when new volumes are added to update ranges
     623 */
    621624void
    622625NanoVis::setVolumeRanges()
     
    644647}
    645648
     649/**
     650 * \brief Called when new heightmaps are added to update ranges
     651 */
    646652void
    647653NanoVis::setHeightmapRanges()
     
    676682NanoVis::collectBounds(bool onlyVisible)
    677683{
    678     if (Flow::updatePending) {
    679         mapFlows();
    680     }
    681 
    682684    sceneBounds.makeEmpty();
    683685
     
    706708    }
    707709
    708     {
     710    for (FlowHashmap::iterator itr = flowTable.begin();
     711         itr != flowTable.end(); ++itr) {
     712        Flow *flow = itr->second;
     713
    709714        BBox bbox;
    710         getFlowBounds(bbox.min, bbox.max, onlyVisible);
     715        flow->getBounds(bbox.min, bbox.max, onlyVisible);
    711716        sceneBounds.extend(bbox);
    712717    }
     
    812817}
    813818
     819/**
     820 * \brief Called when new flows are added to update ranges
     821 */
    814822bool
    815 NanoVis::mapFlows()
     823NanoVis::setFlowRanges()
    816824{
    817825    TRACE("Enter");
     
    827835         itr != flowTable.end(); ++itr) {
    828836        Flow *flow = itr->second;
    829         double min, max;
    830837        if (!flow->isDataLoaded()) {
    831838            continue;
    832839        }
    833         Rappture::Unirect3d *data = flow->data();
    834         min = data->magMin();
    835         max = data->magMax();
    836         if (min < Flow::magMin) {
    837             Flow::magMin = min;
     840        double range[2];
     841        flow->getVectorRange(range);
     842        if (range[0] < Flow::magMin) {
     843            Flow::magMin = range[0];
    838844        }
    839         if (max > Flow::magMax) {
    840             Flow::magMax = max;
     845        if (range[1] > Flow::magMax) {
     846            Flow::magMax = range[1];
    841847        }
    842848    }
     
    856862            flow->initializeParticles();
    857863        }
    858         if (!flow->scaleVectorField()) {
    859             return false;
    860         }
    861864    }
    862865
    863866    Flow::updatePending = false;
    864867    return true;
    865 }
    866 
    867 void
    868 NanoVis::getFlowBounds(Vector3f& min,
    869                        Vector3f& max,
    870                        bool onlyVisible)
    871 {
    872     TRACE("Enter");
    873 
    874     BBox allBounds;
    875     for (FlowHashmap::iterator itr = flowTable.begin();
    876          itr != flowTable.end(); ++itr) {
    877         BBox bbox;
    878         itr->second->getBounds(bbox.min, bbox.max, onlyVisible);
    879         allBounds.extend(bbox);
    880     }
    881 
    882     min = allBounds.min;
    883     max = allBounds.max;
    884868}
    885869
     
    928912
    929913    if (Flow::updatePending) {
    930         mapFlows();
     914        setFlowRanges();
    931915    }
    932916    if (HeightMap::updatePending) {
  • trunk/packages/vizservers/nanovis/nanovis.h

    r3630 r3935  
    123123    static void setVolumeRanges();
    124124    static void setHeightmapRanges();
    125     static bool mapFlows();
     125    static bool setFlowRanges();
    126126
    127127    static Flow *getFlow(const char *name);
     
    129129    static void deleteFlows(Tcl_Interp *interp);
    130130    static void deleteFlow(const char *name);
    131     static void getFlowBounds(vrmath::Vector3f& min,
    132                               vrmath::Vector3f& max,
    133                               bool onlyVisible = false);
     131
    134132    static void renderFlows();
    135133    static void resetFlows();
  • trunk/packages/vizservers/nanovis/util/Fonts.cpp

    r3559 r3935  
    9393    glLoadIdentity();
    9494
     95#if 0
     96    glDisable(GL_BLEND);
     97    glEnable(GL_DEPTH_TEST);
     98#else
    9599    glEnable(GL_BLEND);
    96100    glDisable(GL_DEPTH_TEST);
     101#endif
    97102}
    98103
     
    223228            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    224229            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
     230            glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    225231            glBindTexture(GL_TEXTURE_2D, 0);
    226232
Note: See TracChangeset for help on using the changeset viewer.