Changeset 53


Ignore:
Timestamp:
Dec 14, 2004, 1:38:33 PM (20 years ago)
Author:
ole
Message:

Changed alphascaling to be based on hmin, hmiax, alphamin, alphamax which are likely to give better and more intuitive control.

Changed check for division by zero in zrange from zmax ==0 to zrange==0.

Location:
Swollen
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • Swollen/include/swwreader.h

    r48 r53  
    8181    virtual unsigned int getNumberOfTimesteps() {return _ntimesteps;}
    8282
    83     virtual float getAlphaScale() {return _alphascale;}
    84     virtual float getAlphaMax() {return _alphamax;}
    85     virtual float getAlphaThreshold() {return _alphathreshold;}
    86     virtual void setAlphaScale( float value ) {_alphascale = value;}
    87     virtual void setAlphaMax( float value ) {_alphamax = value;}
    88     virtual void setAlphaThreshold( float value ) {_alphathreshold = value;}
     83    virtual float getAlphaMin() {return _alphamin;}   
     84    virtual float getAlphaMax() {return _alphamax;}   
     85    virtual float getHeightMin() {return _heightmin;}       
     86    virtual float getHeightMax() {return _heightmax;}           
    8987
     88    virtual void setAlphaMin( float value ) {_alphamin = value;}   
     89    virtual void setAlphaMax( float value ) {_alphamax = value;}       
     90    virtual void setHeightMin( float value ) {_heightmin = value;}     
     91    virtual void setHeightMax( float value ) {_heightmax = value;}       
     92
     93   
    9094    virtual triangle_list getConnectivity(unsigned int index) {return _connectivity.at(index);}
    9195
     
    146150
    147151    // alpha based culling
    148     float _alphamax, _alphascale, _alphathreshold;
     152    float _alphamax, _alphamin, _heightmax, _heightmin;
    149153
    150154};
  • Swollen/swollen/main.cpp

    r48 r53  
    4040    arguments.getApplicationUsage()->addCommandLineOption("-scale <float>","Vertical scale factor");
    4141    arguments.getApplicationUsage()->addCommandLineOption("-tps <rate>","timesteps per second");
    42     arguments.getApplicationUsage()->addCommandLineOption("-alphascale <float>","physical height to transparency scale factor");
    43     arguments.getApplicationUsage()->addCommandLineOption("-alphathreshold <float>","transparency lower bound 0-1");
     42    arguments.getApplicationUsage()->addCommandLineOption("-hmin <float>","height below which transparency is set to zero");   
     43    arguments.getApplicationUsage()->addCommandLineOption("-hmax <float>","Height above which transparency is set to alphamax");       
     44    arguments.getApplicationUsage()->addCommandLineOption("-alphamin <float>","transparency value at hmin");   
    4445    arguments.getApplicationUsage()->addCommandLineOption("-alphamax <float>","maximum transparency clamp value");
    4546    arguments.getApplicationUsage()->addCommandLineOption("-nosky","omit background sky");
     
    9091
    9192    float tmpfloat;
    92     if( arguments.read("-alphascale",tmpfloat) ) sww->setAlphaScale( tmpfloat );
     93    if( arguments.read("-hmin",tmpfloat) ) sww->setHeightMin( tmpfloat ); 
     94    if( arguments.read("-hmax",tmpfloat) ) sww->setHeightMax( tmpfloat );     
     95    if( arguments.read("-alphamin",tmpfloat) ) sww->setAlphaMin( tmpfloat );   
    9396    if( arguments.read("-alphamax",tmpfloat) ) sww->setAlphaMax( tmpfloat );
    94     if( arguments.read("-alphathreshold",tmpfloat) ) sww->setAlphaThreshold( tmpfloat );
    95 
     97       
    9698
    9799    // root node
  • Swollen/swwreader/swwreader.cpp

    r48 r53  
    118118    _xscale = 1.0 / xrange;
    119119    _yscale = 1.0 / yrange;
    120     _zscale = (zmax == 0.0) ? 1.0 : 1.0 / zrange;
     120   
     121    //_zscale = (zmax == 0.0) ? 1.0 : 1.0 / zrange;
     122    //I think this is the right one (OMN) incase of a flat bed that
     123    //isn't necessarily going through z==0
     124    _zscale = (zrange == 0.0) ? 1.0 : 1.0 / zrange;
    121125    _xoffset = xmin;
    122126    _yoffset = ymin;
     
    138142
    139143    // alpha-scaling defaults
     144    _alphamin = 0.4;       
    140145    _alphamax = 0.9;
    141     _alphascale = 1.0;
    142     _alphathreshold = 0.0;
     146    _heightmin = 1.e-3;
     147    _heightmax = 1.0;   
    143148
    144149
     
    279284
    280285    // stage height above bedslope mapped as alpha value
    281     float alpha, height;
     286    //
     287    // Transparancy alpha is calculated as
     288    //
     289    // alpha = min( a(h-hmin) + alphamin, alphamax),  h >= hmin
     290    // alpha = 0,                                     h < hmin
     291    //
     292    // where a = (alphamax-alphamin)/(hmax-hmin)
     293   
     294    float alpha, height, _alphascale;
     295    _alphascale = (_alphamax - _alphamin) / (_heightmax - _heightmin);
    282296    _stagecolors = new osg::Vec4Array;
    283297    for (iv=0; iv < _npoints; iv++)
    284298    {
    285299        height = _stagevertices->at(iv).z() - _bedslopevertices->at(iv).z();
    286         alpha = height / _alphascale;
    287         if( alpha > _alphamax ) alpha = _alphamax;
     300       
     301        if (height < _heightmin) {
     302          alpha = 0.0;
     303        } else {
     304          alpha = _alphascale*(height - _heightmin) + _alphamin;
     305          if( alpha > _alphamax ) alpha = _alphamax;     
     306        }
    288307        _stagecolors->push_back( osg::Vec4( 1.0, 1.0, 1.0, alpha ) );
    289308    }
Note: See TracChangeset for help on using the changeset viewer.