Changeset 13


Ignore:
Timestamp:
Nov 2, 2004, 11:20:45 PM (19 years ago)
Author:
darran
Message:
  • culling 'c' now loops through CULLNONE, CULLNEARZERO, CULLSTEEPANGLE, CULLALL
  • scaling of datasets now done in swwreader by scaling vertices on load
  • method in watersurface for adjustable zoffset from bedslope
  • need state machine for current mode and adjustment bindings
Location:
Swollen
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • Swollen/include/swwreader.h

    r6 r13  
    8383
    8484    // stage culling
    85     virtual void toggleCullNearZero() {_cullnearzero = _cullnearzero ? false : true;}
    86     virtual bool getCullNearZero() {return _cullnearzero;}
    87     virtual float getCullNearZeroValue() {return _cullnearzerovalue;}
    88     virtual void toggleCullSteepAngle() {_cullsteepangle = _cullsteepangle ? false : true;}
    89     virtual bool getCullSteepAngle() {return _cullsteepangle;}
    90     virtual float getCullSteepAngleValue() {return _cullsteepanglevalue;}
     85    virtual void toggleCullSetting();
     86    virtual float getCullNearZero() {return _cullnearzero;}
     87    virtual float getCullSteepAngle() {return _cullsteepangle;}
     88    virtual void setCullNearZero( float value ) {_cullnearzero = value; }
     89    virtual void setCullSteepAngle( float value ) {_cullsteepangle = value; }
    9190
    9291    virtual triangle_list getConnectivity(unsigned int index) {return _connectivity.at(index);}
     
    131130    osg::ref_ptr<osg::Vec3Array> _stagecentroids;
    132131
     132    // bedslope vertex scale and shift factors (for normalizing to unit cube)
     133    float _xscale, _yscale, _zscale;
     134    float _xoffset, _yoffset, _zoffset;
    133135
    134136    // stack of return values from netcdf function calls
     
    143145
    144146    // stage culling
    145     bool _cullnearzero;
    146     float _cullnearzerovalue;
    147     bool _cullsteepangle;
    148     float _cullsteepanglevalue;
     147    float _cullnearzero;
     148    float _cullsteepangle;
     149    enum cullstate { CULLALL, CULLNEARZERO, CULLSTEEPANGLE, CULLNONE };
     150    cullstate _cullsetting;
    149151
    150152};
  • Swollen/swollen/keyboardeventhandler.cpp

    r9 r13  
    1414  _prevtime = 0;
    1515  _togglewireframe = false;
    16   _togglecullnearzero = false;
     16  _togglecullsetting = false;
    1717}
    1818
     
    7373
    7474                        case 'w':
    75                 _togglewireframe = true;
    76                                 handled = true;
    77                                 break;
     75                          _togglewireframe = true;
     76                          handled = true;
     77                          break;
    7878
    79             case 'c':
    80                 _togglecullnearzero = true;
    81                                 handled = true;
    82                                 break;
     79                case 'c':
     80                  _togglecullsetting = true;
     81                  handled = true;
     82                  break;
    8383                }
    8484
     
    125125
    126126
    127 bool KeyboardEventHandler::toggleCullNearZero()
     127bool KeyboardEventHandler::toggleCullSetting()
    128128{
    129         if( _togglecullnearzero )
     129        if( _togglecullsetting )
    130130        {
    131                 _togglecullnearzero = false;
     131                _togglecullsetting = false;
    132132                return true;
    133133        }
  • Swollen/swollen/keyboardeventhandler.h

    r9 r13  
    2323        virtual bool timestepChanged();
    2424        virtual bool toggleWireframe();
    25         virtual bool toggleCullNearZero();
     25        virtual bool toggleCullSetting();
    2626        virtual int getTimestep(){return (unsigned int) _timestep;}
    2727        virtual void setTime(float time);
     
    3030        int _direction, _timestep, _ntimesteps;
    3131        float _tps, _prevtime, _tpsorig;
    32         bool _paused, _timestepchanged, _togglewireframe, _togglecullnearzero;
     32        bool _paused, _timestepchanged, _togglewireframe, _togglecullsetting;
    3333};
    3434
  • Swollen/swollen/main.cpp

    r12 r13  
    114114
    115115
    116     // center model in x and y
     116    // center model in x and y (now done in swwreader)
     117    /*
    117118    osg::BoundingBox bbox = bedslope->getBound();
    118119    float scale = 1.0/bbox.radius();
    119     model->setScale( osg::Vec3(scale,scale,scale) );
    120120    model->setPosition( -bbox.center()*scale );
    121 
     121    */
     122
     123    // FIXME: should be reasonable default and adjustable
     124    model->setScale( osg::Vec3(1.0, 1.0, 0.2) );
    122125
    123126    // sky
     
    156159
    157160
     161    unsigned int timestep = 0;
    158162    while( !viewer.done() )
    159163    {
     
    163167        // current time
    164168        double time = viewer.getFrameStamp()->getReferenceTime();
    165 
    166         // events
    167         if( event_handler->toggleWireframe() )
    168             water->toggleWireframe();
    169         if( event_handler->toggleCullNearZero() )
    170             sww->toggleCullNearZero();
    171169
    172170        // advance sww frame?
     
    174172        if( event_handler->timestepChanged() )
    175173        {
    176             unsigned int timestep = event_handler->getTimestep();
     174            timestep = event_handler->getTimestep();
    177175            water->setTimeStep(timestep);
    178176            hud->setTime( sww->getTime(timestep) );
    179177        }
     178
     179        // events
     180        if( event_handler->toggleWireframe() )
     181            water->toggleWireframe();
     182        if( event_handler->toggleCullSetting() )
     183          {
     184            sww->toggleCullSetting();
     185            water->setTimeStep(timestep);  // forced reload
     186          }
     187
    180188
    181189        // update the scene by traversing with the update visitor
  • Swollen/swollen/watersurface.cpp

    r11 r13  
    1919
    2020
    21 #define DEF_WATER_COLOUR        0, 0, 0.5, 1            // R, G, B, Alpha (blue)
    22 #define DEF_WATER_TRANSPARENCY  0.1                   // 0=opaque, 1=transparent
    23 
     21#define DEF_WATER_COLOUR        0, 0, 0.5, 1        // R, G, B, Alpha (blue)
     22#define DEF_WATER_TRANSPARENCY  0.1                 // 0=opaque, 1=transparent
     23#define DEF_ZOFFSET             0.01
    2424
    2525// constructor
     
    3232    _stateset = new osg::StateSet;
    3333    _material = new osg::Material;
     34    _zoffset = DEF_ZOFFSET;
    3435
    3536    // construct local scenegraph hierarchy
     
    9899
    99100
    100     // vertical (z) offset to eliminate zbuffer problems
     101    // vertical (z) offset to eliminate potential zbuffer problems with bedslope
    101102    for( unsigned int iv=0; iv < vertices.get()->size(); iv++ )
    102       vertices.get()->at(iv) += osg::Vec3f( 0.0, 0.0, 0.0 );
     103      vertices.get()->at(iv) += osg::Vec3f( 0.0, 0.0, _zoffset );
    103104
    104105    _geom->setVertexArray( vertices.get() );
  • Swollen/swollen/watersurface.h

    r6 r13  
    2929    virtual void setTimeStep( unsigned int ts );
    3030    virtual void toggleWireframe();
     31    virtual void setOffset( float amount ){ _zoffset = amount; }
     32    virtual float getOffset(){ return _zoffset; }
    3133
    3234protected:
     
    3840    osg::Material* _material;
    3941    virtual ~WaterSurface();
     42    float _zoffset;
    4043
    4144};
  • Swollen/swwreader/swwreader.cpp

    r8 r13  
    3535#include <stdio.h>
    3636
     37#define DEF_CULLNEARZERO    0.001
     38#define DEF_CULLSTEEPANGLE  0.9
     39#define DEF_CULLSTART       CULLNONE
     40
     41
    3742// only constructor, requires netcdf file
    3843SWWReader::SWWReader(const std::string& filename)
     
    6166    _status.push_back( nc_inq_dimlen(_ncid, _ntimestepsid, &_ntimesteps) );
    6267    if (this->_statusHasError()) return;
    63 
    64     // debug info
    65     osg::notify(osg::INFO) << "[SWWReader]" <<  std::endl;
    66     osg::notify(osg::INFO) << "    nvolumes: " << _nvolumes <<  std::endl;
    67     osg::notify(osg::INFO) << "    nvertices: " << _nvertices << std::endl;
    68     osg::notify(osg::INFO) << "    npoints: " << _npoints << std::endl;
    69     osg::notify(osg::INFO) << "    ntimesteps: " << _ntimesteps << std::endl;
    70 
    7168
    7269    // variable ids
     
    10198    unsigned int v1index, v2index, v3index;
    10299
     100    // bedslope extents and resultant scale factors
     101    float xmin, xmax, xrange;
     102    float ymin, ymax, yrange;
     103    float zmin, zmax, zrange;
     104    xmin = _px[0];
     105    xmax = _px[0];
     106    ymin = _py[0];
     107    ymax = _py[0];
     108    zmin = _pz[0];
     109    zmax = _pz[0];
     110    for( iv=1; iv < _npoints; iv++ )
     111    {
     112      if( _px[iv] < xmin ) xmin = _px[iv];
     113      if( _px[iv] > xmax ) xmax = _px[iv];
     114      if( _py[iv] < ymin ) ymin = _py[iv];
     115      if( _py[iv] > ymax ) ymax = _py[iv];
     116      if( _pz[iv] < zmin ) zmin = _pz[iv];
     117      if( _pz[iv] > zmax ) zmax = _pz[iv];
     118    }
     119    _xscale = 1.0/(xmax - xmin);  _xoffset = xmin;
     120    _yscale = 1.0/(ymax - ymin);  _yoffset = ymin;
     121    _zscale = (zmax==zmin) ? 1.0 : 1.0/(zmax - zmin);  _zoffset = zmin;
     122    std::cout << "xmin: " << xmin << std::endl;
     123    std::cout << "xmax: " << xmax << std::endl;
     124    std::cout << "ymin: " << ymin << std::endl;
     125    std::cout << "ymax: " << ymax << std::endl;
     126    std::cout << "zmin: " << zmin << std::endl;
     127    std::cout << "zmax: " << zmax << std::endl;
     128    std::cout << "xscale: " << _xscale << std::endl;
     129    std::cout << "yscale: " << _yscale << std::endl;
     130    std::cout << "zscale: " << _zscale << std::endl;
     131
     132
    103133    // culling defaults
    104     _cullnearzero = true;
    105     _cullnearzerovalue = 0.001;
    106     _cullsteepangle = true;
    107     _cullsteepanglevalue = 0.9;
     134    _cullsetting = DEF_CULLSTART;
     135    _cullnearzero = DEF_CULLNEARZERO;
     136    _cullsteepangle = DEF_CULLSTEEPANGLE;
    108137
    109138    // compute triangle connectivity, a list (indexed by vertex number)
     
    120149    }
    121150
    122     // load bedslope vertex array
     151    // load bedslope vertex array, shifting and scaling vertices to unit cube
     152    // centred about the origin
    123153    _bedslopevertices = new osg::Vec3Array;
    124154    for (iv=0; iv < _npoints; iv++)
    125         _bedslopevertices->push_back( osg::Vec3(_px[iv], _py[iv], _pz[iv]) );
     155      _bedslopevertices->push_back( osg::Vec3( (_px[iv]-_xoffset)*_xscale - 0.5,
     156                                               (_py[iv]-_yoffset)*_yscale - 0.5,
     157                                               (_pz[iv]-_zoffset)*_zscale - 0.5) );
    126158
    127159    // load bedslope index array, pvolumes array indexes into x, y and z
     
    180212    int status = nc_get_vars_float (_ncid, _stageid, start, count, stride, _pstage);
    181213
    182     // load stage vertex array
     214    // load stage vertex array, scaling and shifting vertices to lie in the unit cube
    183215    _stagevertices = new osg::Vec3Array;
    184216    for (iv=0; iv < _npoints; iv++)
    185         _stagevertices->push_back( osg::Vec3(_px[iv], _py[iv], _pstage[iv]) );
     217        _stagevertices->push_back( osg::Vec3(
     218                                             (_px[iv]-_xoffset)*_xscale - 0.5,
     219                                             (_py[iv]-_yoffset)*_yscale - 0.5,
     220                                             (_pstage[iv]-_zoffset)*_zscale - 0.5) );
    186221
    187222    // stage index and per primitive normal and centroid arrays
     
    212247
    213248        // shallow water depth culling test
    214         if( _cullnearzero && ((v1s.z()+v2s.z()+v3s.z())/3.0 - _bedslopecentroids->at(iv).z()) < _cullnearzerovalue )
     249        if( (_cullsetting == CULLALL || _cullsetting == CULLNEARZERO) &&
     250            ((v1s.z()+v2s.z()+v3s.z())/3.0 - _bedslopecentroids->at(iv).z()) < _cullnearzero )
    215251        {
    216252            culledlist->push_back( iv );
     
    219255
    220256        // steep bedslope culling test
    221         if( _cullsteepangle )
    222         {
    223             if( _bedslopenormals->at(iv) * osg::Vec3f(0,0,1) < _cullsteepanglevalue )
     257        if( _cullsetting == CULLALL || _cullsetting == CULLSTEEPANGLE )
     258        {
     259            if( _bedslopenormals->at(iv) * osg::Vec3f(0,0,1) < _cullsteepangle )
    224260            {
    225261                culledlist->push_back( iv );
     
    283319
    284320
     321
     322void SWWReader::toggleCullSetting()
     323{
     324
     325  switch( _cullsetting )
     326    {
     327
     328    case CULLALL:
     329      _cullsetting = CULLNEARZERO;
     330      osg::notify(osg::INFO) << "[SWWReader::toggleCullSetting] CULLNEARZERO" <<  std::endl;
     331      break;
     332
     333    case CULLNEARZERO:
     334      _cullsetting = CULLSTEEPANGLE;
     335      osg::notify(osg::INFO) << "[SWWReader::toggleCullSetting] CULLSTEEPANGLE" <<  std::endl;
     336      break;
     337
     338    case CULLSTEEPANGLE:
     339      _cullsetting = CULLNONE;
     340      osg::notify(osg::INFO) << "[SWWReader::toggleCullSetting] CULLNONE" <<  std::endl;
     341      break;
     342
     343    case CULLNONE:
     344      _cullsetting = CULLALL;
     345      osg::notify(osg::INFO) << "[SWWReader::toggleCullSetting] CULLALL" <<  std::endl;
     346      break;
     347
     348    }
     349}
     350
     351
     352
    285353bool SWWReader::_statusHasError()
    286354{
Note: See TracChangeset for help on using the changeset viewer.