Changeset 105


Ignore:
Timestamp:
Jun 10, 2005, 8:28:56 PM (19 years ago)
Author:
darran
Message:
  • reintroduction of 'c' steep culling
  • distro20050610 release
Location:
Swollen
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • Swollen/distros/windistro.py

    r96 r105  
    3737# sample sww file for testing
    3838localtestdir = localrootdir + os.sep + 'tests'
    39 localfiles.append(localtestdir + os.sep + 'cylinders2.sww')
    40 localfiles.append(localtestdir + os.sep + 'cylinders2.tif')
     39localfiles.append(localtestdir + os.sep + 'cylinders.sww')
     40localfiles.append(localtestdir + os.sep + 'cylinders.tif')
    4141
    4242
  • Swollen/include/swwreader.h

    r103 r105  
    8787    virtual unsigned int getNumberOfTimesteps() {return _ntimesteps;}
    8888
    89     virtual float getAlphaMin() {return _alphamin;}   
    90     virtual float getAlphaMax() {return _alphamax;}   
    91     virtual float getHeightMin() {return _heightmin;}       
    92     virtual float getHeightMax() {return _heightmax;}           
     89    virtual float getAlphaMin() {return _alphamin;}
     90    virtual float getAlphaMax() {return _alphamax;}
     91    virtual float getHeightMin() {return _heightmin;}
     92    virtual float getHeightMax() {return _heightmax;}
     93    virtual float getCullAngle() {return _cullangle;}
    9394
    94     virtual void setAlphaMin( float value ) {_alphamin = value;}   
    95     virtual void setAlphaMax( float value ) {_alphamax = value;}       
    96     virtual void setHeightMin( float value ) {_heightmin = value;}     
    97     virtual void setHeightMax( float value ) {_heightmax = value;}       
     95    virtual void setAlphaMin( float value ) {_alphamin = value;}
     96    virtual void setAlphaMax( float value ) {_alphamax = value;}
     97    virtual void setHeightMin( float value ) {_heightmin = value;}
     98    virtual void setHeightMax( float value ) {_heightmax = value;}
     99
     100    virtual void setCullAngle( float value ) {_cullangle = value;}
     101    virtual void toggleCulling() {_culling = _culling ? false : true;}
    98102   
    99103    virtual triangle_list getConnectivity(unsigned int index) {return _connectivity.at(index);}
     
    145149    struct
    146150    {
    147         bool hasData;
    148         int xresolution, yresolution;
    149         float xorigin, yorigin;
    150         float xpixel, ypixel;
    151         float rotation;
     151        bool hasData;
     152        int xresolution, yresolution;
     153        float xorigin, yorigin;
     154        float xpixel, ypixel;
     155        float rotation;
    152156    } _bedslopegeodata;
    153157
     
    174178    float _alphamax, _alphamin, _heightmax, _heightmin;
    175179
     180    // cull triangles with steepness angle above this value
     181    float _cullangle;
     182    bool _culling;
     183
    176184};
    177185
  • Swollen/swollen/main.cpp

    r104 r105  
    4747    arguments.getApplicationUsage()->addCommandLineOption("-lightpos <float>,<float>,<float>","x,y,z of bedslope directional light (z is up, default is overhead)");
    4848    arguments.getApplicationUsage()->addCommandLineOption("-nosky","Omit background sky");
     49    arguments.getApplicationUsage()->addCommandLineOption("-cullangle <float angle 0-90>","Cull triangles steeper than this value");
    4950    arguments.getApplicationUsage()->addCommandLineOption("-texture <file>","Image to use for bedslope topography");
    5051    arguments.getApplicationUsage()->addCommandLineOption("-version","Revision number and creation (not compile) date");
     
    104105    if( arguments.read("-alphamin",tmpfloat) ) sww->setAlphaMin( tmpfloat );   
    105106    if( arguments.read("-alphamax",tmpfloat) ) sww->setAlphaMax( tmpfloat );
     107    if( arguments.read("-cullangle",tmpfloat) ) sww->setCullAngle( tmpfloat );
    106108
    107109    std::string bedslopetexture;
     
    202204        viewer.sync();
    203205
     206
    204207        // current time
    205208        double time = viewer.getFrameStamp()->getReferenceTime();
     
    219222
    220223        if( event_handler->toggleCulling() )
    221             std::cout << "toggle culling" << std::endl;
    222 
     224        {
     225            sww->toggleCulling();
     226            water->setTimeStep(timestep);  // refresh
     227        }
    223228
    224229        // update the scene by traversing with the update visitor
  • Swollen/swollen/watersurface.cpp

    r104 r105  
    6767
    6868    osg::TexEnv* texenv = new osg::TexEnv;
    69     //texenv->setMode( osg::TexEnv::DECAL );
    70     texenv->setMode( osg::TexEnv::BLEND );
     69    texenv->setMode( osg::TexEnv::DECAL );
     70    //texenv->setMode( osg::TexEnv::BLEND );
    7171    texenv->setColor( osg::Vec4(0.6f,0.6f,0.6f,0.2f) );
    7272    _stateset->setTextureAttributeAndModes( 1, texgen, osg::StateAttribute::ON );
  • Swollen/swwreader/swwreader.cpp

    r104 r105  
    2121#include <stdio.h>
    2222#include <gdal_priv.h>
     23
     24
     25// compile time defaults
     26#define DEFAULT_CULLANGLE 85.0
     27#define DEFAULT_ALPHAMIN 0.8
     28#define DEFAULT_ALPHAMAX 1.0
     29#define DEFAULT_HEIGHTMIN 0.0
     30#define DEFAULT_HEIGHTMAX 1.0
     31#define DEFAULT_BEDSLOPEOFFSET 0.0
     32#define DEFAULT_CULLONSTART false
    2333
    2434
     
    108118    }
    109119
     120
     121    // alpha-scaling defaults, can be overridden after construction by command line parameters
     122    _alphamin = DEFAULT_ALPHAMIN;
     123    _alphamax = DEFAULT_ALPHAMAX;
     124    _heightmin = DEFAULT_HEIGHTMIN;
     125    _heightmax = DEFAULT_HEIGHTMAX;
     126
     127    // steepness culling default, can be overridden after construction by command line parameter
     128    _cullangle = DEFAULT_CULLANGLE;
     129    _culling = DEFAULT_CULLONSTART;
    110130
    111131    // loop index
     
    191211        _bedslopevertices->push_back( osg::Vec3( (_px[iv]-_xoffset)*_scale - _xcenter,
    192212                                                 (_py[iv]-_yoffset)*_scale - _ycenter,
    193                                                  (_pz[iv]-_zoffset)*_scale - _zcenter - 0.00) );
     213                                                 (_pz[iv]-_zoffset)*_scale - _zcenter - DEFAULT_BEDSLOPEOFFSET) );
    194214
    195215    // bedslope index array, pvolumes array indexes into x, y and z
     
    330350    osg::ref_ptr<osg::IntArray> steeptri = new osg::IntArray;
    331351
    332     // alpha-scaling defaults
    333     _alphamin = 0.8;
    334     _alphamax = 1.0;
    335     _heightmin = 0.00;
    336     _heightmax = 1.0;
    337 
    338352    // stage heights from netcdf file (x and y are same as bedslope)
    339353    int status = nc_get_vars_float (_ncid, _stageid, start, count, stride, _pstage);
     
    354368    unsigned int v1index, v2index, v3index;
    355369
     370    // cullangle given in degrees, test is against dot product
     371    float cullthreshold = cos(osg::DegreesToRadians(_cullangle));
     372
    356373    // over all stage triangles
    357374    for (iv=0; iv < _nvolumes; iv++)
     
    378395        _stageprimitivenormals->push_back( nrm );
    379396
    380         // identify steep triangles
    381         if( fabs(nrm * osg::Vec3f(0,0,1)) < 0.4 )
    382         {
     397        // identify steep triangles, store index
     398        if( fabs(nrm * osg::Vec3f(0,0,1)) < cullthreshold )
    383399            steeptri->push_back( iv );
    384         }
    385     }
    386 
    387 
    388     int seed = 5;
    389     srand(seed);
    390     float r, g, b;
     400    }
    391401
    392402    // stage height above bedslope mapped as alpha value
     
    399409    for (iv=0; iv < _npoints; iv++)
    400410    {
     411        // water height above corresponding bedslope
    401412        height = _stagevertices->at(iv).z() - _bedslopevertices->at(iv).z();
    402413       
    403414        if (height < _heightmin)
    404         {
    405415            alpha = 0.0;
    406         }
    407416        else
    408417        {
    409                 alpha = alphascale * (height - _heightmin) + _alphamin;
     418            alpha = alphascale * (height - _heightmin) + _alphamin;
    410419                if( alpha > _alphamax )
    411                     alpha = _alphamax;   
     420                alpha = _alphamax;
    412421        }
    413422
    414         r = ((float) rand())/RAND_MAX;
    415         g = ((float) rand())/RAND_MAX;
    416         b = ((float) rand())/RAND_MAX;
    417         //alpha = ((float) rand())/RAND_MAX;
    418         alpha = 0.9;
    419         _stagecolors->push_back( osg::Vec4( r, g, b, alpha ) );
    420     }
    421 
    422     for (iv=0; iv < steeptri->size() ; iv++)
    423     {
    424         int tri = steeptri->at(iv);
    425         v1index = _pvolumes[3*tri+0];
    426         v2index = _pvolumes[3*tri+1];
    427         v3index = _pvolumes[3*tri+2];
    428 
    429         r = ((float) rand())/RAND_MAX;
    430         g = ((float) rand())/RAND_MAX;
    431         b = ((float) rand())/RAND_MAX;
    432 
    433         std::cout << tri << std::endl;
    434 
    435         // FIXME: needs to be an overwrite rather than a push
    436         //_stagecolors->push_back( osg::Vec4( 1, 1, 1, alpha ) );
    437     }
    438 
    439 
     423        _stagecolors->push_back( osg::Vec4( 1.0, 1.0, 1.0, alpha ) );
     424    }
     425
     426        // steep triangle vertices should have alpha=0, overwrite such vertex colours
     427    if( _culling )
     428    {
     429        for (iv=0; iv < steeptri->size() ; iv++)
     430        {
     431            int tri = steeptri->at(iv);
     432            v1index = _pvolumes[3*tri+0];
     433            v2index = _pvolumes[3*tri+1];
     434            v3index = _pvolumes[3*tri+2];
     435
     436            _stagecolors->at(v1index) = osg::Vec4( 1, 1, 1, 0 );
     437            _stagecolors->at(v2index) = osg::Vec4( 1, 1, 1, 0 );
     438            _stagecolors->at(v3index) = osg::Vec4( 1, 1, 1, 0 );
     439        }
     440    }
    440441
    441442    // per-vertex normals calculated as average of primitive normals
Note: See TracChangeset for help on using the changeset viewer.