Changeset 111


Ignore:
Timestamp:
Jun 21, 2005, 2:21:44 PM (19 years ago)
Author:
darran
Message:
  • refactoring to facilitate storing state
  • segfaulting at the moment ...
Location:
Swollen
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • Swollen/include/swwreader.h

    r107 r111  
    7171    virtual osg::ref_ptr<osg::Vec2Array> getBedslopeTextureCoords();
    7272
    73     virtual bool hasBedslopeTexture() {return (_bedslopetexture != NULL);}
     73    virtual bool hasBedslopeTexture() {return (_state.bedslopetexturefilename != NULL);}
    7474    virtual void setBedslopeTexture( std::string filename );
    7575    virtual osg::Image* getBedslopeTexture();
     
    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;}
    93     virtual float getCullAngle() {return _cullangle;}
     89    virtual float getAlphaMin() {return _state.alphamin;}
     90    virtual float getAlphaMax() {return _state.alphamax;}
     91    virtual float getHeightMin() {return _state.heightmin;}
     92    virtual float getHeightMax() {return _state.heightmax;}
     93    virtual float getCullAngle() {return _state.cullangle;}
    9494
    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;}
     95    virtual void setAlphaMin( float value ) {_state.alphamin = value;}
     96    virtual void setAlphaMax( float value ) {_state.alphamax = value;}
     97    virtual void setHeightMin( float value ) {_state.heightmin = value;}
     98    virtual void setHeightMax( float value ) {_state.heightmax = value;}
    9999
    100     virtual void setCullAngle( float value ) {_cullangle = value;}
    101     virtual void toggleCulling() {_culling = _culling ? false : true;}
     100    virtual void setCullAngle( float value ) {_state.cullangle = value;}
     101    virtual void toggleCulling() {_state.culling = _state.culling ? false : true;}
     102    virtual bool getCulling() {return _state.culling;}
     103    virtual void setCulling(bool value) {_state.culling = value;}
    102104   
    103105    virtual triangle_list getConnectivity(unsigned int index) {return _connectivity.at(index);}
    104106
    105     const std::string getSwollenDir() {return *_swollendir;}
    106     virtual void setSwollenDir(const std::string path) {_swollendir = new std::string(path);}
     107    const std::string getSwollenDir() {return *(_state.swollendirectory);}
     108    virtual void setSwollenDir(const std::string path) {_state.swollendirectory = new std::string(path);}
    107109
    108110
     
    111113    virtual ~SWWReader();
    112114
    113     std::string* _filename;
    114     std::string* _swollendir;
    115    
     115
     116    // state contains all the info needed to serialize
     117    struct
     118    {
     119          float alphamax;  // define alpha (transparency) function
     120          float alphamin;
     121          float heightmax;
     122          float heightmin;
     123
     124          float cullangle;  // cull triangles with steepness angle above this value
     125          bool culling;   // culling is on or off
     126
     127          std::string* swwfilename;
     128          std::string* bedslopetexturefilename;
     129          std::string* swollendirectory;
     130
     131    } _state;
     132
     133
    116134    // constructor determines SWW validity (netcdf + proper structure)
    117135    bool _valid;
     
    147165    osg::ref_ptr<osg::Vec4Array> _stagecolors;
    148166
    149     // optional bedslope texture map
    150     std::string* _bedslopetexture;
    151 
    152167    // optional geodata for bedslope texture map
    153168    struct
     
    179194    std::vector<triangle_list> _connectivity;
    180195
    181     // define alpha (transparency) function
    182     float _alphamax, _alphamin, _heightmax, _heightmin;
    183 
    184     // cull triangles with steepness angle above this value
    185     float _cullangle;
    186     bool _culling;
    187 
    188196};
    189197
  • Swollen/swollen/hud.cpp

    r33 r111  
    4747    _time->setText("t = 0.0");
    4848
     49    // recording mode text
     50    _record = new osgText::Text;
     51    _record->setFont(font);
     52    _record->setColor(osg::Vec4(DEF_HUD_COLOUR) );
     53    _record->setCharacterSize(30);
     54    _record->setPosition(osg::Vec3(600,20,0));
     55    _record->setFontResolution(40,40);
     56    _record->setText("");
     57
     58
    4959    // state
    5060    osg::StateSet *state = _projection->getOrCreateStateSet();
     
    6070    textnode->addDrawable( _title );
    6171    textnode->addDrawable( _time );
     72    textnode->addDrawable( _record );
    6273    xfm->addChild( textnode );
    6374    _projection->addChild( xfm );
     
    8495}
    8596
     97
     98void HeadsUpDisplay::setRecordingMode( char *s )
     99{
     100    _record->setText(s);
     101}
     102
  • Swollen/swollen/hud.h

    r6 r111  
    2525    virtual void setTime(float t);
    2626    virtual void setTitle(char *s);
     27    virtual void setRecordingMode(char *s);
    2728    virtual osg::Projection* get(){ return _projection; }
    2829
     
    3031
    3132    osg::Projection* _projection;
    32         osgText::Text* _title;
    33         osgText::Text* _time;
     33    osgText::Text* _title;
     34    osgText::Text* _time;
     35    osgText::Text* _record;
    3436    virtual ~HeadsUpDisplay();
    3537
  • Swollen/swollen/keyboardeventhandler.cpp

    r104 r111  
    1515    _togglewireframe = false;
    1616    _toggleculling = false;
     17
    1718}
    1819
     
    8384
    8485
     86            case '1':
     87                _togglerecording = true;
     88                handled = true;
     89                break;
     90
     91            case '2':
     92                _recordingplayback = true;
     93                handled = true;
     94                break;
     95
     96            case '3':
     97                _recordingsave = true;
     98                handled = true;
     99                break;
     100
    85101            }
    86102
     
    138154
    139155
     156bool KeyboardEventHandler::toggleRecording()
     157{
     158    if( _togglerecording )
     159    {
     160        _togglerecording = false;
     161        return true;
     162    }
     163    return false;
     164}
  • Swollen/swollen/keyboardeventhandler.h

    r104 r111  
    2424    virtual bool toggleWireframe();
    2525    virtual bool toggleCulling();
     26    virtual bool toggleRecording();
    2627    virtual int getTimestep(){return (unsigned int) _timestep;}
    2728    virtual void setTime(float time);
     
    3132    float _tps, _prevtime, _tpsorig;
    3233    bool _paused, _timestepchanged, _togglewireframe, _toggleculling;
     34    bool _togglerecording, _recordingplayback, _recordingsave;
    3335};
    3436
  • Swollen/swollen/main.cpp

    r106 r111  
    184184   }
    185185
     186
    186187   // register additional event handler
    187188   KeyboardEventHandler* event_handler = new KeyboardEventHandler(sww->getNumberOfTimesteps(), tps);
     
    205206
    206207
     208   // animation mode is off to start
     209   bool recordingmode = false;
     210
     211
    207212   unsigned int timestep = 0;
    208213   while( !viewer.done() )
     
    235240      }
    236241
     242      /*
     243        Finite State Machine for animation
     244     
     245        0 1 1 begin storing view/orientation/cull settings
     246        0 2 2 if exists, store current settings, commence playback of saved animation path
     247        0 3 0 save animation to disk
     248
     249        1 1 0 stop storing settings
     250        1 2 2 stop storing settings and commence playback
     251        1 3 1 save animation, keep recording
     252
     253        2 2 0 stop playback, return to saved settings
     254        2 1 2 no effect
     255        2 3 2 save animation, continue playing back
     256
     257        header comprised of original command line arguments
     258
     259        state comprised of:
     260           frame
     261           elapsedtime
     262           position
     263           orientation
     264           timestep
     265           cullsteep
     266           wireframe
     267 
     268      */
     269
     270
     271      if( event_handler->toggleRecording() )
     272      {
     273         switch( recordingmode )
     274         {
     275            case false :
     276               recordingmode = true;
     277               hud->setRecordingMode("recording");
     278               break;
     279            case true :
     280               recordingmode = false;
     281               hud->setRecordingMode("");
     282               break;
     283         }
     284
     285      }
     286
     287
    237288      // update the scene by traversing with the update visitor
    238289      viewer.update();
  • Swollen/swollen/version.cpp

    r107 r111  
    1 const char* version() { const char* s = "Revision: 105:106M"; return s; }
     1const char* version() { const char* s = "Revision: 110M"; return s; }
  • Swollen/swollen/watersurface.cpp

    r106 r111  
    7373    _stateset->setTextureAttributeAndModes( 1, texgen, osg::StateAttribute::ON );
    7474    _stateset->setTextureAttribute( 1, texenv );
     75
     76    // default is filled watersurface
     77    _wireframe = false;
     78
    7579}
    7680
     
    114118void WaterSurface::toggleWireframe()
    115119{
     120   if( _wireframe )
     121      _wireframe = false;
     122   else
     123      _wireframe = true;
     124
     125   setWireframe(_wireframe);
     126}
     127
     128
     129void WaterSurface::setWireframe(bool value)
     130{
    116131    osg::PolygonMode* polyModeObj =
    117132        dynamic_cast<osg::PolygonMode*>(_stateset->getAttribute(osg::StateAttribute::POLYGONMODE));
     
    123138    }
    124139
    125     switch( polyModeObj->getMode(osg::PolygonMode::FRONT_AND_BACK) )
     140    switch( value )
    126141    {
    127    
    128       case osg::PolygonMode::FILL : polyModeObj->setMode(osg::PolygonMode::FRONT_AND_BACK,
    129                                                          osg::PolygonMode::LINE); break;
    130       case osg::PolygonMode::LINE : polyModeObj->setMode(osg::PolygonMode::FRONT_AND_BACK,
    131                                                          osg::PolygonMode::FILL); break;
    132       case osg::PolygonMode::POINT : break;
     142       case true :
     143          polyModeObj->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE);
     144          break;
     145
     146       case false :
     147         polyModeObj->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::FILL);
     148         break;
    133149    }
    134150}
  • Swollen/swollen/watersurface.h

    r48 r111  
    2727    virtual void setTimeStep( unsigned int ts );
    2828    virtual void toggleWireframe();
     29    virtual bool getWireframe(){ return _wireframe; };
     30    virtual void setWireframe(bool wireframe);
    2931
    3032protected:
     
    3537    osg::StateSet* _stateset;
    3638    virtual ~WaterSurface();
    37 
     39    bool _wireframe;
    3840};
    3941
  • Swollen/swwreader/swwreader.cpp

    r107 r111  
    4040
    4141   // netcdf filename
    42    _filename = new std::string(filename);
     42   _state.swwfilename = new std::string(filename);
    4343
    4444   // netcdf open
    45    _status.push_back( nc_open(_filename->c_str(), NC_NOWRITE, &_ncid) );
     45   _status.push_back( nc_open(filename.c_str(), NC_NOWRITE, &_ncid) );
    4646   if (this->_statusHasError()) return;
    4747
     
    131131
    132132   // alpha-scaling defaults, can be overridden after construction by command line parameters
    133    _alphamin = DEFAULT_ALPHAMIN;
    134    _alphamax = DEFAULT_ALPHAMAX;
    135    _heightmin = DEFAULT_HEIGHTMIN;
    136    _heightmax = DEFAULT_HEIGHTMAX;
     133   _state.alphamin = DEFAULT_ALPHAMIN;
     134   _state.alphamax = DEFAULT_ALPHAMAX;
     135   _state.heightmin = DEFAULT_HEIGHTMIN;
     136   _state.heightmax = DEFAULT_HEIGHTMAX;
    137137
    138138   // steepness culling default, can be overridden after construction by command line parameter
    139    _cullangle = DEFAULT_CULLANGLE;
    140    _culling = DEFAULT_CULLONSTART;
     139   _state.cullangle = DEFAULT_CULLANGLE;
     140   _state.culling = DEFAULT_CULLONSTART;
    141141
    142142   // loop index
     
    270270   _valid = true;
    271271
     272   std::cout << _state.alphamin << std::endl;
     273   std::cout << _state.alphamax << std::endl;
     274   std::cout << _state.heightmin << std::endl;
     275   std::cout << _state.heightmax << std::endl;
     276   std::cout << _state.cullangle << std::endl;
     277   std::cout << _state.culling << std::endl;
     278
     279   std::cout << *_state.swwfilename << std::endl;
     280   std::cout << *_state.bedslopetexturefilename << std::endl;
     281
    272282}
    273283
     
    285295{
    286296   osg::notify(osg::INFO) << "[SWWReader::setBedslopetexture] filename: " << filename <<  std::endl;
    287    _bedslopetexture = new std::string(filename);
     297   _state.bedslopetexturefilename = new std::string(filename);
    288298   _bedslopegeodata.hasData = false;
    289299
     
    311321      {
    312322         _bedslopegeodata.xorigin = geodata[0];
    313         _bedslopegeodata.yorigin = geodata[3];
    314         _bedslopegeodata.rotation = geodata[2];
    315         _bedslopegeodata.xpixel = geodata[1];
    316         _bedslopegeodata.ypixel = geodata[5];
    317         _bedslopegeodata.hasData = true;
    318 
    319         osg::notify(osg::INFO) << "[SWWReader::setBedslopetexture] xorigin: " << _bedslopegeodata.xorigin <<  std::endl;
    320         osg::notify(osg::INFO) << "[SWWReader::setBedslopetexture] yorigin: " << _bedslopegeodata.yorigin <<  std::endl;
    321         osg::notify(osg::INFO) << "[SWWReader::setBedslopetexture] xpixel: " << _bedslopegeodata.xpixel <<  std::endl;
    322         osg::notify(osg::INFO) << "[SWWReader::setBedslopetexture] ypixel: " << _bedslopegeodata.ypixel <<  std::endl;
    323         osg::notify(osg::INFO) << "[SWWReader::setBedslopetexture] rotation: " << _bedslopegeodata.rotation <<  std::endl;
     323        _bedslopegeodata.yorigin = geodata[3];
     324        _bedslopegeodata.rotation = geodata[2];
     325        _bedslopegeodata.xpixel = geodata[1];
     326        _bedslopegeodata.ypixel = geodata[5];
     327        _bedslopegeodata.hasData = true;
     328
     329        osg::notify(osg::INFO) << "[SWWReader::setBedslopetexture] xorigin: " << _bedslopegeodata.xorigin <<  std::endl;
     330        osg::notify(osg::INFO) << "[SWWReader::setBedslopetexture] yorigin: " << _bedslopegeodata.yorigin <<  std::endl;
     331        osg::notify(osg::INFO) << "[SWWReader::setBedslopetexture] xpixel: " << _bedslopegeodata.xpixel <<  std::endl;
     332        osg::notify(osg::INFO) << "[SWWReader::setBedslopetexture] ypixel: " << _bedslopegeodata.ypixel <<  std::endl;
     333        osg::notify(osg::INFO) << "[SWWReader::setBedslopetexture] rotation: " << _bedslopegeodata.rotation <<  std::endl;
    324334      }
    325335   }
     
    330340osg::Image* SWWReader::getBedslopeTexture()
    331341{
    332    return osgDB::readImageFile( _bedslopetexture->c_str() );
     342   return osgDB::readImageFile( _state.bedslopetexturefilename->c_str() );
    333343}
    334344
     
    350360   else
    351361   {
    352       // decal'd using (x,y) locations scaled by extents into range [0,1]
     362      // decaled using (x,y) locations scaled by extents into range [0,1]
    353363      for( unsigned int iv=0; iv < _npoints; iv++ )
    354364         _bedslopetexcoords->push_back( osg::Vec2( (_px[iv]-_xoffset)*_xscale, (_py[iv]-_yoffset)*_yscale ) );
     
    391401
    392402   // cullangle given in degrees, test is against dot product
    393    float cullthreshold = cos(osg::DegreesToRadians(_cullangle));
     403   float cullthreshold = cos(osg::DegreesToRadians(_state.cullangle));
    394404
    395405   // over all stage triangles
     
    427437   // where a = (alphamax-alphamin)/(hmax-hmin)
    428438   float alpha, height, alphascale;
    429    alphascale = (_alphamax - _alphamin) / (_heightmax - _heightmin);
     439   alphascale = (_state.alphamax - _state.alphamin) / (_state.heightmax - _state.heightmin);
    430440   _stagecolors = new osg::Vec4Array;
    431441   for (iv=0; iv < _npoints; iv++)
     
    434444      height = _stagevertices->at(iv).z() - _bedslopevertices->at(iv).z();
    435445       
    436       if (height < _heightmin)
     446      if (height < _state.heightmin)
    437447         alpha = 0.0;
    438448      else
    439449      {
    440          alpha = alphascale * (height - _heightmin) + _alphamin;
    441          if( alpha > _alphamax )
    442             alpha = _alphamax;
     450         alpha = alphascale * (height - _state.heightmin) + _state.alphamin;
     451         if( alpha > _state.alphamax )
     452            alpha = _state.alphamax;
    443453      }
    444454
     
    447457
    448458   // steep triangle vertices should have alpha=0, overwrite such vertex colours
    449    if( _culling )
     459   if( _state.culling )
    450460   {
    451461      for (iv=0; iv < steeptri->size() ; iv++)
Note: See TracChangeset for help on using the changeset viewer.