Changeset 48


Ignore:
Timestamp:
Dec 13, 2004, 11:42:36 PM (20 years ago)
Author:
darran
Message:
  • added alpha-related command line params
  • added -nosky flag
Location:
Swollen
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • Swollen/INSTALL

    r45 r48  
    551) The pyVolution Visualizer has several dependencies.
    66
    7    OpenSceneGraph, OpenThreads, and Producer
     7   OpenThreads, Producer, OpenSceneGraph:
    88            - http://openscenegraph.sourceforge.net
    9             - available as a bundle, OSG_OP_OT-0.9.8
     9            - available as a bundle, OSG_OP_OT-0.9.8, that contains
     10              OpenThreads, (Open)Producer and OpenSceneGraph as
     11              subdirectories. 
    1012            - OpenSceneGraph has 3rd party dependencies, these are
    11               available as a downloadable .zip for Windows.
     13              available as a downloadable .zip for Windows.  Extracted
     14              .zip directory (3rdParty) lives alongside other three
     15              subdirectories.
     16            - Build "release" versions in above order
    1217            - ensure you can run the examples that come with OSG
    13               prior to building the viewer
     18              prior to building the viewer (these live in the
     19              OpenSceneGraph/bin directory on Windows).
    1420
    1521   NetCDF   - a self-describing binary file format I/O library
     
    4551
    4652   CPPUNIT :  root of c++ unit testing framework with needed subdirs
    47               /lib and /include
     53              /lib and /include (optional)
    4854
    4955
     
    5359   WINDOWS
    5460
    55       (i) Open the solution in visualstudio subdir.
     61      (i) Within VisualStudio, Open the solution in Swollen visualstudio subdirectory
    5662     (ii) Open Menu Tools|Options|Projects|VC++Directories and add a
    5763          path to $(NETCDF_DIR)/bin and $(OSG_ROOT)/bin.
  • Swollen/doc/contract2_hours.txt

    r46 r48  
    33------------------
    44
     5
     614 December, Monday (6 hours)
     7- visit to GA, swollen now compiling on-site under Windows/Visual Studio .NET
     8- added command line params for tweaking transparency (see "swollen -help")
    59
    61012 December, Saturday (4 hours)
  • Swollen/doc/contract2_priorities.txt

    r43 r48  
    2929  from camera) [1]
    3030- z-scaling to emphasize vertical details (via -scale command line parameter) [1]
    31 
     31- Optional height-dependent semi-transparent water surface [0]
     32- added -nosky command-line option to appease those who want a plain background [?]
     33- Duncan and Ole able to compile Swollen from source under Windows/Visual Studio .NET [?]
    3234
    3335
     
    3840  (e.g. stage, speed, ..) [4]
    3941- Output coordinates defining camera position [?]
    40 - Interactive positioning of light(s) [?]
    41 
     42- Ability to handle scenes with a resolution of 500,000+ triangles [3]
    4243
    4344
     
    4950- Problems with Duncan's, Chris' and Stephen Roberts' machines at GA: Swollen won't render semi transparency.
    5051  Swwviewer works fine.
    51 
    52 
    5352
    5453
     
    6463
    6564
    66 
    67 
    6865--------------------------------------------------
    6966
     
    7269- Scene augmentation with OSG models [2]       
    7370- Optional contour lines of water surface [1]
    74 - Optional height-dependent semi-transparent water surface [0]
     71
    7572       
    76 
    7773FUNCTIONALITY:
    7874
     
    8682- Ability to show earthquakes [0]
    8783- Concept of 'buildings' and shaking them [0]
    88 
    89 
     84- Interactive positioning of light(s) [?]
     85- key binding 'h' for home camera position [?]
     86- key binding 't' for top camera position [?]
     87- user feedback should differentiate between "sww file not found" and
     88  "sww file couldn't read" [?]
     89- add -version command line flag synced with Subversion revision number (useful for debugging) [?]
    9090
    9191
     
    9393
    9494- Scene optimization via geometry and texture level-of-detail (LOD) [3]
    95 - Ability to handle scenes with a resolution of 500,000+ triangles [3]
    9695- Separate thread for loading a ring buffer of stage data [1]
    9796
     
    109108- Revisit use of culling steep epsilon [3]     
    110109- SWW netcdf meta information [0]
    111 
    112 
  • Swollen/include/swwreader.h

    r45 r48  
    8080    virtual size_t getNumberOfVertices() {return _npoints;}
    8181    virtual unsigned int getNumberOfTimesteps() {return _ntimesteps;}
    82     //virtual int getNumberOfBedslopeIndices() {return _bedslopeindices->size();}
    83     //virtual int getNumberOfStageIndices() {return _stageindices->size();}
    8482
    85     // stage culling
    86     virtual void toggleCullSetting();
    87     virtual float getCullNearZero() {return _cullnearzero;}
    88     virtual float getCullSteepAngle() {return _cullsteepangle;}
    89     virtual void setCullNearZero( float value ) {_cullnearzero = value; }
    90     virtual void setCullSteepAngle( float value ) {_cullsteepangle = value; }
     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;}
    9189
    9290    virtual triangle_list getConnectivity(unsigned int index) {return _connectivity.at(index);}
     
    147145    std::vector<triangle_list> _connectivity;
    148146
    149     // stage culling
    150     float _cullnearzero;
    151     float _cullsteepangle;
    152     enum cullstate { CULLALL, CULLNEARZERO, CULLSTEEPANGLE, CULLNONE };
    153     cullstate _cullsetting;
     147    // alpha based culling
     148    float _alphamax, _alphascale, _alphathreshold;
    154149
    155150};
  • Swollen/swollen/keyboardeventhandler.cpp

    r13 r48  
    1414  _prevtime = 0;
    1515  _togglewireframe = false;
    16   _togglecullsetting = false;
    1716}
    1817
     
    7675                          handled = true;
    7776                          break;
    78 
    79                 case 'c':
    80                   _togglecullsetting = true;
    81                   handled = true;
    82                   break;
    8377                }
    8478
     
    125119
    126120
    127 bool KeyboardEventHandler::toggleCullSetting()
    128 {
    129         if( _togglecullsetting )
    130         {
    131                 _togglecullsetting = false;
    132                 return true;
    133         }
    134         return false;
    135 }
    136 
  • Swollen/swollen/keyboardeventhandler.h

    r13 r48  
    2323        virtual bool timestepChanged();
    2424        virtual bool toggleWireframe();
    25         virtual bool toggleCullSetting();
    2625        virtual int getTimestep(){return (unsigned int) _timestep;}
    2726        virtual void setTime(float time);
     
    3029        int _direction, _timestep, _ntimesteps;
    3130        float _tps, _prevtime, _tpsorig;
    32         bool _paused, _timestepchanged, _togglewireframe, _togglecullsetting;
     31        bool _paused, _timestepchanged, _togglewireframe;
    3332};
    3433
  • Swollen/swollen/main.cpp

    r45 r48  
    3737    arguments.getApplicationUsage()->setDescription(arguments.getApplicationName());
    3838    arguments.getApplicationUsage()->setCommandLineUsage("swollen [options] swwfile ...");
    39     arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
    40     arguments.getApplicationUsage()->addCommandLineOption("-scale <s>","Vertical scale factor");
     39    arguments.getApplicationUsage()->addCommandLineOption("-help","Display this information");
     40    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");
     44    arguments.getApplicationUsage()->addCommandLineOption("-alphamax <float>","maximum transparency clamp value");
     45    arguments.getApplicationUsage()->addCommandLineOption("-nosky","omit background sky");
    4246
    4347    // construct the viewer.
     
    5458
    5559    // if user request help write it out to cout.
    56     if (arguments.read("-h") || arguments.read("--help"))
     60    if( arguments.read("-help") )
    5761    {
    5862        arguments.getApplicationUsage()->write(std::cout);
     
    6165
    6266
    63     // load sww file specified as final argument on command line (static
     67    // load sww file specified as final argument on command line (static bedslope
    6468    // geometry only, per timestep height field geometry is done in loop below)
    6569    int lastarg = arguments.argc()-1;
     
    7983
    8084
    81     // default arguments
     85    // default arguments and command line parameters
    8286    float tps;
    8387    if( !arguments.read("-tps",tps) || tps <= 0.0 ) tps = DEF_TPS;
     
    8589    if( !arguments.read("-scale",vscale) ) vscale = 1.0;
    8690
     91    float tmpfloat;
     92    if( arguments.read("-alphascale",tmpfloat) ) sww->setAlphaScale( tmpfloat );
     93    if( arguments.read("-alphamax",tmpfloat) ) sww->setAlphaMax( tmpfloat );
     94    if( arguments.read("-alphathreshold",tmpfloat) ) sww->setAlphaThreshold( tmpfloat );
     95
    8796
    8897    // root node
     
    91100    // transform
    92101    osg::PositionAttitudeTransform* model = new osg::PositionAttitudeTransform;
    93     model->setName("model_transform");
     102    model->setName("position_attitude_transform");
    94103
    95104    // enscapsulates OpenGL state
     
    122131
    123132
    124     // FIXME: should be reasonable default and adjustable
     133    // allow vertical scaling from command line parameter
    125134    model->setScale( osg::Vec3(1.0, 1.0, vscale) );
    126135
    127     // sky
    128     rootnode->addChild( createSky(10.0, "sky_small.jpg") );
     136    // surrounding sky sphere
     137    if( !arguments.read("-nosky") )
     138      rootnode->addChild( createSky(10.0, "sky_small.jpg") );
    129139
    130140
     
    153163    // initial camera position
    154164    viewer.getTrackball()->setNode( rootnode );
    155     viewer.getTrackball()->setAutoComputeHomePosition(false);
     165    viewer.getTrackball()->setAutoComputeHomePosition( false );
    156166    viewer.getTrackball()->setHomePosition(
    157         osg::Vec3d(0,-4,1),    // camera location
     167        osg::Vec3d(0,-3,2),    // camera location
    158168        osg::Vec3d(0,0,0),     // camera target
    159169        osg::Vec3d(0,0,1) );   // camera up vector
     
    182192        if( event_handler->toggleWireframe() )
    183193            water->toggleWireframe();
    184         if( event_handler->toggleCullSetting() )
    185         {
    186             sww->toggleCullSetting();
    187                 water->setTimeStep(timestep);  // forced reload
    188         }
    189194
    190195
  • Swollen/swollen/watersurface.cpp

    r45 r48  
    2222
    2323
    24 #define DEF_WATER_COLOUR        0, 0, 0.5, 1        // R, G, B, Alpha (blue)
    25 #define DEF_WATER_TRANSPARENCY  0.1                 // 0=opaque, 1=transparent
    26 #define DEF_ZOFFSET             0.01
    27 
    2824// constructor
    2925WaterSurface::WaterSurface(SWWReader* sww)
     
    3430    _geom = new osg::Geometry;
    3531    _stateset = new osg::StateSet;
    36     _zoffset = DEF_ZOFFSET;
    3732
    3833    // construct local scenegraph hierarchy
     
    6257
    6358    osg::AlphaFunc* alphaFunc = new osg::AlphaFunc;
    64     //alphaFunc->setFunction(osg::AlphaFunc::GEQUAL,0.1f);
    65     alphaFunc->setFunction(osg::AlphaFunc::ALWAYS);
     59    alphaFunc->setFunction( osg::AlphaFunc::GEQUAL, _sww->getAlphaThreshold() );
    6660    _stateset->setAttributeAndModes( alphaFunc, osg::StateAttribute::ON );
    67 
    6861    _stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
    69 
    7062
    7163    // automatically generate texture coords
     
    9284    // delete if exists
    9385    if( _geom->getNumPrimitiveSets() )
    94       _geom->removePrimitiveSet(0);  // reference counting actually does the delete
     86      _geom->removePrimitiveSet(0);  // reference counting does actual delete
    9587
    9688    // local reference to raw height field data
     
    9991    osg::ref_ptr<osg::Vec4Array> colors = _sww->getStageColorArray();
    10092
    101     // vertical (z) offset to eliminate potential zbuffer problems with bedslope
    102     osg::UIntArray* colorindices = new osg::UIntArray(vertices.get()->size());
    103     for( unsigned int iv=0; iv < vertices.get()->size(); iv++ )
    104     {
    105         vertices.get()->at(iv) += osg::Vec3f( 0.0, 0.0, _zoffset );
    106         colorindices->at(iv) = iv;
    107     }
    108 
    10993    // geometry
    11094    _geom->setVertexArray( vertices.get() );
    11195    _geom->addPrimitiveSet( _sww->getBedslopeIndexArray().get() );
    11296
    113     // per vertex colors (using only alpha)
     97    // per vertex colors (we only modulate the alpha for transparency)
    11498    _geom->setColorArray( colors.get() );
    11599    _geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
  • Swollen/swollen/watersurface.h

    r45 r48  
    1818
    1919
    20 
    2120class WaterSurface
    2221{
     
    2827    virtual void setTimeStep( unsigned int ts );
    2928    virtual void toggleWireframe();
    30     virtual void setOffset( float amount ){ _zoffset = amount; }
    31     virtual float getOffset(){ return _zoffset; }
    3229
    3330protected:
     
    3835    osg::StateSet* _stateset;
    3936    virtual ~WaterSurface();
    40     float _zoffset;
    4137
    4238};
  • Swollen/swwreader/swwreader.cpp

    r45 r48  
    3535#include <stdio.h>
    3636
    37 #define DEF_CULLNEARZERO    0.001
    38 #define DEF_CULLSTEEPANGLE  0.9
    39 #define DEF_CULLSTART       CULLNONE
    40 
    41 #define MIN(a, b) (a < b ? a : b)
    42 #define MAX(a, b) (a > b ? a : b)
    43 
    4437
    4538// only constructor, requires netcdf file
     
    144137    }
    145138
     139    // alpha-scaling defaults
     140    _alphamax = 0.9;
     141    _alphascale = 1.0;
     142    _alphathreshold = 0.0;
     143
     144
    146145    osg::notify(osg::INFO) << "[SWWReader] xmin: " << xmin <<  std::endl;
    147146    osg::notify(osg::INFO) << "[SWWReader] xmax: " << xmax <<  std::endl;
     
    155154
    156155
    157     // culling defaults
    158     _cullsetting = DEF_CULLSTART;
    159     _cullnearzero = DEF_CULLNEARZERO;
    160     _cullsteepangle = DEF_CULLSTEEPANGLE;
    161 
    162156    // compute triangle connectivity, a list (indexed by vertex number)
    163157    // of lists (indices of triangles sharing this vertex)
     
    191185    for( iv=0; iv < _npoints; iv++ )
    192186      _bedslopetexcoords->push_back( osg::Vec2( (_px[iv]-_xoffset)*_xscale, (_py[iv]-_yoffset)*_yscale ) );
    193 
    194187
    195188
     
    251244                                              (_pstage[iv]-_zoffset)*_scale - _zcenter) );
    252245
    253 
    254246    // stage index, per primitive normal and centroid arrays
    255247    _stageprimitivenormals = new osg::Vec3Array;
     
    261253
    262254    // over all stage triangles
    263     for (iv=0; iv < _nvolumes; iv++){
    264 
     255    for (iv=0; iv < _nvolumes; iv++)
     256    {
    265257        v1index = _pvolumes[3*iv+0];
    266258        v2index = _pvolumes[3*iv+1];
     
    283275        _stagecentroids->push_back( (v1s+v2s+v3s)/3.0 );
    284276        _stageprimitivenormals->push_back( nrm );
    285 
    286     }
    287 
    288 
    289     float alpha;
     277    }
     278
     279
     280    // stage height above bedslope mapped as alpha value
     281    float alpha, height;
    290282    _stagecolors = new osg::Vec4Array;
    291283    for (iv=0; iv < _npoints; iv++)
    292284    {
    293       // FIXME: needs to be scaled appropriately
    294         alpha = ( _stagevertices->at(iv).z() - _bedslopevertices->at(iv).z() ) * 100.0;
     285        height = _stagevertices->at(iv).z() - _bedslopevertices->at(iv).z();
     286        alpha = height / _alphascale;
     287        if( alpha > _alphamax ) alpha = _alphamax;
    295288        _stagecolors->push_back( osg::Vec4( 1.0, 1.0, 1.0, alpha ) );
    296289    }
     
    321314
    322315
    323 void SWWReader::toggleCullSetting()
    324 {
    325 
    326   switch( _cullsetting )
    327     {
    328 
    329     case CULLALL:
    330       _cullsetting = CULLNEARZERO;
    331       osg::notify(osg::INFO) << "[SWWReader::toggleCullSetting] CULLNEARZERO" <<  std::endl;
    332       break;
    333 
    334     case CULLNEARZERO:
    335       _cullsetting = CULLSTEEPANGLE;
    336       osg::notify(osg::INFO) << "[SWWReader::toggleCullSetting] CULLSTEEPANGLE" <<  std::endl;
    337       break;
    338 
    339     case CULLSTEEPANGLE:
    340       _cullsetting = CULLNONE;
    341       osg::notify(osg::INFO) << "[SWWReader::toggleCullSetting] CULLNONE" <<  std::endl;
    342       break;
    343 
    344     case CULLNONE:
    345       _cullsetting = CULLALL;
    346       osg::notify(osg::INFO) << "[SWWReader::toggleCullSetting] CULLALL" <<  std::endl;
    347       break;
    348 
    349     }
    350 }
    351 
    352 
    353316
    354317bool SWWReader::_statusHasError()
Note: See TracChangeset for help on using the changeset viewer.