Changeset 111
- Timestamp:
- Jun 21, 2005, 2:21:44 PM (19 years ago)
- Location:
- Swollen
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
Swollen/include/swwreader.h
r107 r111 71 71 virtual osg::ref_ptr<osg::Vec2Array> getBedslopeTextureCoords(); 72 72 73 virtual bool hasBedslopeTexture() {return (_ bedslopetexture != NULL);}73 virtual bool hasBedslopeTexture() {return (_state.bedslopetexturefilename != NULL);} 74 74 virtual void setBedslopeTexture( std::string filename ); 75 75 virtual osg::Image* getBedslopeTexture(); … … 87 87 virtual unsigned int getNumberOfTimesteps() {return _ntimesteps;} 88 88 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;} 94 94 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;} 99 99 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;} 102 104 103 105 virtual triangle_list getConnectivity(unsigned int index) {return _connectivity.at(index);} 104 106 105 const std::string getSwollenDir() {return * _swollendir;}106 virtual void setSwollenDir(const std::string path) {_s wollendir= 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);} 107 109 108 110 … … 111 113 virtual ~SWWReader(); 112 114 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 116 134 // constructor determines SWW validity (netcdf + proper structure) 117 135 bool _valid; … … 147 165 osg::ref_ptr<osg::Vec4Array> _stagecolors; 148 166 149 // optional bedslope texture map150 std::string* _bedslopetexture;151 152 167 // optional geodata for bedslope texture map 153 168 struct … … 179 194 std::vector<triangle_list> _connectivity; 180 195 181 // define alpha (transparency) function182 float _alphamax, _alphamin, _heightmax, _heightmin;183 184 // cull triangles with steepness angle above this value185 float _cullangle;186 bool _culling;187 188 196 }; 189 197 -
Swollen/swollen/hud.cpp
r33 r111 47 47 _time->setText("t = 0.0"); 48 48 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 49 59 // state 50 60 osg::StateSet *state = _projection->getOrCreateStateSet(); … … 60 70 textnode->addDrawable( _title ); 61 71 textnode->addDrawable( _time ); 72 textnode->addDrawable( _record ); 62 73 xfm->addChild( textnode ); 63 74 _projection->addChild( xfm ); … … 84 95 } 85 96 97 98 void HeadsUpDisplay::setRecordingMode( char *s ) 99 { 100 _record->setText(s); 101 } 102 -
Swollen/swollen/hud.h
r6 r111 25 25 virtual void setTime(float t); 26 26 virtual void setTitle(char *s); 27 virtual void setRecordingMode(char *s); 27 28 virtual osg::Projection* get(){ return _projection; } 28 29 … … 30 31 31 32 osg::Projection* _projection; 32 osgText::Text* _title; 33 osgText::Text* _time; 33 osgText::Text* _title; 34 osgText::Text* _time; 35 osgText::Text* _record; 34 36 virtual ~HeadsUpDisplay(); 35 37 -
Swollen/swollen/keyboardeventhandler.cpp
r104 r111 15 15 _togglewireframe = false; 16 16 _toggleculling = false; 17 17 18 } 18 19 … … 83 84 84 85 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 85 101 } 86 102 … … 138 154 139 155 156 bool KeyboardEventHandler::toggleRecording() 157 { 158 if( _togglerecording ) 159 { 160 _togglerecording = false; 161 return true; 162 } 163 return false; 164 } -
Swollen/swollen/keyboardeventhandler.h
r104 r111 24 24 virtual bool toggleWireframe(); 25 25 virtual bool toggleCulling(); 26 virtual bool toggleRecording(); 26 27 virtual int getTimestep(){return (unsigned int) _timestep;} 27 28 virtual void setTime(float time); … … 31 32 float _tps, _prevtime, _tpsorig; 32 33 bool _paused, _timestepchanged, _togglewireframe, _toggleculling; 34 bool _togglerecording, _recordingplayback, _recordingsave; 33 35 }; 34 36 -
Swollen/swollen/main.cpp
r106 r111 184 184 } 185 185 186 186 187 // register additional event handler 187 188 KeyboardEventHandler* event_handler = new KeyboardEventHandler(sww->getNumberOfTimesteps(), tps); … … 205 206 206 207 208 // animation mode is off to start 209 bool recordingmode = false; 210 211 207 212 unsigned int timestep = 0; 208 213 while( !viewer.done() ) … … 235 240 } 236 241 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 237 288 // update the scene by traversing with the update visitor 238 289 viewer.update(); -
Swollen/swollen/version.cpp
r107 r111 1 const char* version() { const char* s = "Revision: 1 05:106M"; return s; }1 const char* version() { const char* s = "Revision: 110M"; return s; } -
Swollen/swollen/watersurface.cpp
r106 r111 73 73 _stateset->setTextureAttributeAndModes( 1, texgen, osg::StateAttribute::ON ); 74 74 _stateset->setTextureAttribute( 1, texenv ); 75 76 // default is filled watersurface 77 _wireframe = false; 78 75 79 } 76 80 … … 114 118 void WaterSurface::toggleWireframe() 115 119 { 120 if( _wireframe ) 121 _wireframe = false; 122 else 123 _wireframe = true; 124 125 setWireframe(_wireframe); 126 } 127 128 129 void WaterSurface::setWireframe(bool value) 130 { 116 131 osg::PolygonMode* polyModeObj = 117 132 dynamic_cast<osg::PolygonMode*>(_stateset->getAttribute(osg::StateAttribute::POLYGONMODE)); … … 123 138 } 124 139 125 switch( polyModeObj->getMode(osg::PolygonMode::FRONT_AND_BACK))140 switch( value ) 126 141 { 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; 133 149 } 134 150 } -
Swollen/swollen/watersurface.h
r48 r111 27 27 virtual void setTimeStep( unsigned int ts ); 28 28 virtual void toggleWireframe(); 29 virtual bool getWireframe(){ return _wireframe; }; 30 virtual void setWireframe(bool wireframe); 29 31 30 32 protected: … … 35 37 osg::StateSet* _stateset; 36 38 virtual ~WaterSurface(); 37 39 bool _wireframe; 38 40 }; 39 41 -
Swollen/swwreader/swwreader.cpp
r107 r111 40 40 41 41 // netcdf filename 42 _ filename = new std::string(filename);42 _state.swwfilename = new std::string(filename); 43 43 44 44 // 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) ); 46 46 if (this->_statusHasError()) return; 47 47 … … 131 131 132 132 // 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; 137 137 138 138 // 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; 141 141 142 142 // loop index … … 270 270 _valid = true; 271 271 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 272 282 } 273 283 … … 285 295 { 286 296 osg::notify(osg::INFO) << "[SWWReader::setBedslopetexture] filename: " << filename << std::endl; 287 _ bedslopetexture = new std::string(filename);297 _state.bedslopetexturefilename = new std::string(filename); 288 298 _bedslopegeodata.hasData = false; 289 299 … … 311 321 { 312 322 _bedslopegeodata.xorigin = geodata[0]; 313 314 315 316 317 318 319 320 321 322 323 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; 324 334 } 325 335 } … … 330 340 osg::Image* SWWReader::getBedslopeTexture() 331 341 { 332 return osgDB::readImageFile( _ bedslopetexture->c_str() );342 return osgDB::readImageFile( _state.bedslopetexturefilename->c_str() ); 333 343 } 334 344 … … 350 360 else 351 361 { 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] 353 363 for( unsigned int iv=0; iv < _npoints; iv++ ) 354 364 _bedslopetexcoords->push_back( osg::Vec2( (_px[iv]-_xoffset)*_xscale, (_py[iv]-_yoffset)*_yscale ) ); … … 391 401 392 402 // cullangle given in degrees, test is against dot product 393 float cullthreshold = cos(osg::DegreesToRadians(_ cullangle));403 float cullthreshold = cos(osg::DegreesToRadians(_state.cullangle)); 394 404 395 405 // over all stage triangles … … 427 437 // where a = (alphamax-alphamin)/(hmax-hmin) 428 438 float alpha, height, alphascale; 429 alphascale = (_ alphamax - _alphamin) / (_heightmax - _heightmin);439 alphascale = (_state.alphamax - _state.alphamin) / (_state.heightmax - _state.heightmin); 430 440 _stagecolors = new osg::Vec4Array; 431 441 for (iv=0; iv < _npoints; iv++) … … 434 444 height = _stagevertices->at(iv).z() - _bedslopevertices->at(iv).z(); 435 445 436 if (height < _ heightmin)446 if (height < _state.heightmin) 437 447 alpha = 0.0; 438 448 else 439 449 { 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; 443 453 } 444 454 … … 447 457 448 458 // steep triangle vertices should have alpha=0, overwrite such vertex colours 449 if( _ culling )459 if( _state.culling ) 450 460 { 451 461 for (iv=0; iv < steeptri->size() ; iv++)
Note: See TracChangeset
for help on using the changeset viewer.