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

Legend:

Unmodified
Added
Removed
  • 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.