Changeset 45


Ignore:
Timestamp:
Dec 13, 2004, 1:17:13 AM (20 years ago)
Author:
darran
Message:

Major changes as per Robert's suggestions

  • removed all culling from swwreader
  • DrawElements? for primitive set improves speed
  • per vertex alpha (vec4 color)

Also,

  • initial view angle slightly above plane
Location:
Swollen
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • Swollen/INSTALL

    r6 r45  
    77   OpenSceneGraph, OpenThreads, and Producer
    88            - http://openscenegraph.sourceforge.net
    9             - available as a bundle, OSG_OP_OT-0.9.7-3
    10             - this itself has 3rd party dependencies available
    11               as a downloadable bundle
     9            - available as a bundle, OSG_OP_OT-0.9.8
     10            - OpenSceneGraph has 3rd party dependencies, these are
     11              available as a downloadable .zip for Windows.
    1212            - ensure you can run the examples that come with OSG
    1313              prior to building the viewer
     
    3939                    /lib
    4040                    /include
     41                 /3rdParty (Windows only)
    4142
    4243   NETCDF_DIR :  root of NetCDF binary package with needed subdirs
     
    4748
    4849
    49 3) For Visual Studio .NET,
    50 
    51     (i) Open the solution in visualstudio subdir.
    52    (ii) Open Menu Tools|Options|Projects|VC++Directories and add a
    53         path to $(NETCDF_DIR)/bin and $(OSG_ROOT)/bin.
    54   (iii) Build the solution
     503) Compilation
    5551
    5652
    57 4) For Mac OSX
     53   WINDOWS
    5854
    59     Run make in swwreader and swollen directories.
     55      (i) Open the solution in visualstudio subdir.
     56     (ii) Open Menu Tools|Options|Projects|VC++Directories and add a
     57          path to $(NETCDF_DIR)/bin and $(OSG_ROOT)/bin.
     58     (iii) Build the solution
    6059
    6160
    62 5) For Linux
     61   Mac OSX
    6362
    64     Makefiles not yet written
     63          Run make in top-level OSG_ROOT directory.
    6564
     65
     66   Linux
     67
     68          Makefiles not yet written
     69
     70
     71
     724) The binary swollen (swollen.exe on Windows) lives in the distribution's
     73   bin directory.  Test the build with any of the sample datasets in the
     74   distribution's data subdirectory, e.g.,
     75         "cd bin; ./swollen ../data/laminar.sww"
     76
     77
     78
  • Swollen/include/swwreader.h

    r44 r45  
    6666    virtual osg::ref_ptr<osg::Vec3Array> getBedslopeVertexArray() {return _bedslopevertices;}
    6767    virtual osg::ref_ptr<osg::Vec3Array> getBedslopeNormalArray() {return _bedslopenormals;}
    68     virtual osg::ref_ptr<osg::UIntArray> getBedslopeIndexArray() {return _bedslopeindices;}
     68    virtual osg::ref_ptr<osg::DrawElementsUShort> getBedslopeIndexArray() {return _bedslopeindices;}
    6969    virtual osg::ref_ptr<osg::Vec3Array> getBedslopeCentroidArray() {return _bedslopecentroids;}
     70    virtual osg::ref_ptr<osg::Vec2Array> getBedslopeTextureCoords() {return _bedslopetexcoords;}
    7071
    7172    // stage
    7273    virtual osg::ref_ptr<osg::Vec3Array> getStageVertexArray(unsigned int index);
    73     virtual osg::ref_ptr<osg::UIntArray> getStageIndexArray() {return _stageindices;}
    7474    virtual osg::ref_ptr<osg::Vec3Array> getStageVertexNormalArray() {return _stagevertexnormals;}
    75     virtual osg::ref_ptr<osg::Vec3Array> getStagePrimitiveNormalArray() {return _stageprimitivenormals;}
    7675    virtual osg::ref_ptr<osg::Vec3Array> getStageCentroidsArray() {return _stagecentroids;}
    7776    virtual osg::ref_ptr<osg::Vec4Array> getStageColorArray() {return _stagecolors;}
     
    8180    virtual size_t getNumberOfVertices() {return _npoints;}
    8281    virtual unsigned int getNumberOfTimesteps() {return _ntimesteps;}
    83     virtual int getNumberOfBedslopeIndices() {return _bedslopeindices->size();}
    84     virtual int getNumberOfStageIndices() {return _stageindices->size();}
     82    //virtual int getNumberOfBedslopeIndices() {return _bedslopeindices->size();}
     83    //virtual int getNumberOfStageIndices() {return _stageindices->size();}
    8584
    8685    // stage culling
     
    122121    osg::ref_ptr<osg::Vec3Array> _bedslopevertices;
    123122    osg::ref_ptr<osg::Vec3Array> _bedslopenormals;
    124     osg::ref_ptr<osg::UIntArray> _bedslopeindices;
     123    osg::ref_ptr<osg::DrawElementsUShort> _bedslopeindices;
    125124    osg::ref_ptr<osg::Vec3Array> _bedslopecentroids;
     125    osg::ref_ptr<osg::Vec2Array> _bedslopetexcoords;
    126126
    127127    // geometry that changes per timestep
    128128    osg::ref_ptr<osg::Vec3Array> _stagevertices;
    129129    osg::ref_ptr<osg::Vec3Array> _stageprimitivenormals;
    130     osg::ref_ptr<osg::UIntArray> _stageindices;
    131130    osg::ref_ptr<osg::Vec3Array> _stagevertexnormals;
    132131    osg::ref_ptr<osg::Vec3Array> _stagecentroids;
     
    134133
    135134    // bedslope vertex scale and shift factors (for normalizing to unit cube)
    136     float _xscale, _yscale, _zscale;
     135    float _xscale, _yscale, _zscale, _scale;
    137136    float _xoffset, _yoffset, _zoffset;
    138137    float _xcenter, _ycenter, _zcenter;
  • Swollen/swollen/bedslope.cpp

    r44 r45  
    1616{
    1717
     18    // persistent
     19    _sww = sww;
     20
    1821    // bedslope geometry as triangles with shared vertices
    1922    _geom = new osg::Geometry;
    2023
    2124    // geometry from sww file
    22     osg::Vec3Array* vertices = sww->getBedslopeVertexArray().get();
    23     osg::UIntArray* indices = sww->getBedslopeIndexArray().get();
    24     osg::Vec3Array* normals = sww->getBedslopeNormalArray().get();
    25     unsigned int nindices = sww->getNumberOfBedslopeIndices();
     25    osg::Vec3Array* vertices = _sww->getBedslopeVertexArray().get();
     26    osg::Vec3Array* normals = _sww->getBedslopeNormalArray().get();
    2627
    2728    _geom->setUseDisplayList(true);
    2829    _geom->setVertexArray( vertices );
    29     _geom->setVertexIndices( indices );
    30     _geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, nindices ));
     30    _geom->addPrimitiveSet( _sww->getBedslopeIndexArray().get() );
    3131    _geom->setNormalArray( normals );
    3232    _geom->setNormalBinding( osg::Geometry::BIND_PER_PRIMITIVE );
    33 
     33    _geom->setTexCoordArray( 0, _sww->getBedslopeTextureCoords().get() );
    3434
    3535    // geometry bounding box
    3636    osg::BoundingBox bbox = _geom->getBound();
    37 
    38     // bedslope texture coords scaled to range [0,1]
    39     osg::Vec2Array* texcoords = new osg::Vec2Array;
    40     osg::Vec3 v;
    41     float xrange = bbox.xMax() - bbox.xMin();
    42     float yrange = bbox.yMax() - bbox.yMin();
    43     for( unsigned int i=0; i < vertices->size(); i++ )
    44     {
    45         v = vertices->at(i);
    46         texcoords->push_back( osg::Vec2( (v.x()-bbox.xMin())/xrange, (v.y()-bbox.yMin())/yrange) );
    47     }
    48     _geom->setTexCoordArray( 0, texcoords );
    49     _geom->setTexCoordIndices( 0, indices );
    5037
    5138    // bedslope texture
     
    5542    texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
    5643    texture->setImage(osgDB::readImageFile("bedslope.jpg"));
    57 
    58 
    59     // bedslope colour
    60     //osg::UByte4Array* colors = new osg::UByte4Array; 
    61     //colors->push_back(osg::UByte4(DEF_BEDSLOPE_COLOUR));
    62     //_geom->setColorArray(colors);
    63     //_geom->setColorBinding(osg::Geometry::BIND_OVERALL);
    64 
    65     // material properties
    66     _material = new osg::Material;
    67     _material->setDiffuse(osg::Material::FRONT, osg::Vec4(DEF_BEDSLOPE_COLOUR));
    68     _material->setSpecular(osg::Material::FRONT, osg::Vec4(1,0,0,1));
    69     _material->setShininess(osg::Material::FRONT, 128);
    70 
    7144   
    7245    _stateset = new osg::StateSet;
     
    7447    _stateset->setMode( GL_BLEND, osg::StateAttribute::ON );
    7548    _stateset->setMode( GL_LIGHTING, osg::StateAttribute::ON );
    76     _stateset->setAttribute(_material);
    77 
    78 
    79 
    8049
    8150    _node = new osg::Geode;
  • Swollen/swollen/bedslope.h

    r6 r45  
    1616#include <SWWReader.h>
    1717#include <osg/Geode>
    18 #include <osg/Material>
    1918#include <osg/StateAttribute>
    2019
     
    3635    osg::Geometry* _geom;
    3736    osg::StateSet* _stateset;
    38     osg::Material* _material;
    3937    virtual ~BedSlope(){;}
    4038
  • Swollen/swollen/main.cpp

    r43 r45  
    3636    // set up the usage document, in case we need to print out how to use this program.
    3737    arguments.getApplicationUsage()->setDescription(arguments.getApplicationName());
    38     arguments.getApplicationUsage()->setCommandLineUsage("swwviewer [options] swwfile ...");
     38    arguments.getApplicationUsage()->setCommandLineUsage("swollen [options] swwfile ...");
    3939    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
    4040    arguments.getApplicationUsage()->addCommandLineOption("-scale <s>","Vertical scale factor");
     41    arguments.getApplicationUsage()->addCommandLineOption("-tps <rate>","timesteps per second");
    4142
    4243    // construct the viewer.
     
    4647    viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
    4748    viewer.setClearColor(osg::Vec4(DEF_BACKGROUND_COLOUR));
    48     //viewer.getCamera(0)->getRenderSurface()->setWindowRectangle(550,100,640,480);
     49    viewer.getCamera(0)->getRenderSurface()->setWindowRectangle(200,100,800,600);
    4950
    5051
     
    7374    if (sww->isValid() == false)
    7475    {
    75         std::cout << "Could not load " << swwfile << " ... quitting" << std::endl;
     76        std::cout << "Unable to load " << swwfile << " ... is this really an .sww file?" << std::endl;
    7677        return 1;
    7778    }
     
    8586
    8687
    87 
    8888    // root node
    8989    osg::Group* rootnode = new osg::Group;
     
    105105    HeadsUpDisplay* hud = new HeadsUpDisplay();
    106106    hud->setTitle("pyVolution SWW Viewer");
     107
    107108
    108109    // Lighting
     
    110111    spotlight->setPosition( osg::Vec3(0,0,2) );  // overhead
    111112    spotlight->setSpotAngle( 45.0 );
     113
    112114
    113115    // scenegraph hierarchy
     
    143145    KeyboardEventHandler* event_handler = new KeyboardEventHandler(sww->getNumberOfTimesteps(), tps);
    144146    viewer.getEventHandlerList().push_front(event_handler);
     147
    145148 
    146149    // create the windows and run the threads.
     
    148151
    149152
    150     // Initial camera position
     153    // initial camera position
    151154    viewer.getTrackball()->setNode( rootnode );
    152155    viewer.getTrackball()->setAutoComputeHomePosition(false);
    153156    viewer.getTrackball()->setHomePosition(
    154         osg::Vec3d(0,-4,0),  // camera location
     157        osg::Vec3d(0,-4,1),    // camera location
    155158        osg::Vec3d(0,0,0),     // camera target
    156159        osg::Vec3d(0,0,1) );   // camera up vector
  • Swollen/swollen/watersurface.cpp

    r44 r45  
    3434    _geom = new osg::Geometry;
    3535    _stateset = new osg::StateSet;
    36     _material = new osg::Material;
    3736    _zoffset = DEF_ZOFFSET;
    3837
     
    4140    _node->addDrawable(_geom);
    4241    _node->setStateSet(_stateset);
    43     //_stateset->setAttribute(_material);
    4442
    4543    _geom->setUseDisplayList(true);
     
    4745    // initial geometry
    4846    setTimeStep(0);
    49 
    50     //_material->setDiffuse(osg::Material::FRONT, osg::Vec4(DEF_WATER_COLOUR));
    51     //_material->setSpecular(osg::Material::FRONT, osg::Vec4(1,1,1,1));
    52     //_material->setTransparency(osg::Material::FRONT_AND_BACK, DEF_WATER_TRANSPARENCY);
    53     //_material->setShininess(osg::Material::FRONT, 128);
    5447
    5548    // environment map
     
    5952    texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
    6053    texture->setImage(osgDB::readImageFile("envmap.jpg"));
    61     //_stateset->setTextureAttributeAndModes( 1, texture, osg::StateAttribute::ON );
     54    _stateset->setTextureAttributeAndModes( 1, texture, osg::StateAttribute::ON );
    6255    _stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
    6356
    6457    // surface transparency
    65     //osg::BlendFunc* osgBlendFunc = new osg::BlendFunc();
    66     //osgBlendFunc->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
    67     //_stateset->setAttribute(osgBlendFunc);
    68     //_stateset->setMode(GL_BLEND, osg::StateAttribute::ON);
     58    osg::BlendFunc* osgBlendFunc = new osg::BlendFunc();
     59    osgBlendFunc->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
     60    _stateset->setAttribute(osgBlendFunc);
     61    _stateset->setMode(GL_BLEND, osg::StateAttribute::ON);
    6962
    7063    osg::AlphaFunc* alphaFunc = new osg::AlphaFunc;
     
    8376    texenv->setMode( osg::TexEnv::DECAL );
    8477    texenv->setColor( osg::Vec4(0.6f,0.6f,0.6f,0.2f) );
    85     //_stateset->setTextureAttributeAndModes( 1, texgen, osg::StateAttribute::ON );
    86     //_stateset->setTextureAttribute( 1, texenv );
     78    _stateset->setTextureAttributeAndModes( 1, texgen, osg::StateAttribute::ON );
     79    _stateset->setTextureAttribute( 1, texenv );
    8780}
    8881
     
    10396    // local reference to raw height field data
    10497    osg::ref_ptr<osg::Vec3Array> vertices = _sww->getStageVertexArray(ts);
    105     osg::ref_ptr<osg::UIntArray> indices = _sww->getStageIndexArray();
    106     osg::ref_ptr<osg::Vec3Array> normals = _sww->getStagePrimitiveNormalArray();
    10798    osg::ref_ptr<osg::Vec3Array> vertexnormals = _sww->getStageVertexNormalArray();
    10899    osg::ref_ptr<osg::Vec4Array> colors = _sww->getStageColorArray();
     
    118109    // geometry
    119110    _geom->setVertexArray( vertices.get() );
    120     _geom->setVertexIndices( indices.get() );
    121     _geom->addPrimitiveSet( new osg::DrawArrays(
    122            osg::PrimitiveSet::TRIANGLES, 0, _sww->getNumberOfStageIndices() ) );
     111    _geom->addPrimitiveSet( _sww->getBedslopeIndexArray().get() );
    123112
    124113    // per vertex colors (using only alpha)
    125114    _geom->setColorArray( colors.get() );
    126     _geom->setColorIndices( colorindices );
    127115    _geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
    128116
    129117    // normals
    130118    _geom->setNormalArray( vertexnormals.get() );
    131     _geom->setNormalIndices( indices.get() );
    132119    _geom->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
    133120
  • Swollen/swollen/watersurface.h

    r13 r45  
    1515#include <SWWReader.h>
    1616#include <osg/Geode>
    17 #include <osg/Material>
    1817#include <osg/StateAttribute>
    1918
     
    3837    osg::Geometry* _geom;
    3938    osg::StateSet* _stateset;
    40     osg::Material* _material;
    4139    virtual ~WaterSurface();
    4240    float _zoffset;
  • Swollen/swwreader/swwreader.cpp

    r44 r45  
    121121    xrange = xmax - xmin;
    122122    yrange = ymax - ymin;
     123    zrange = zmax - zmin;
    123124    aspect_ratio = xrange/yrange;
     125    _xscale = 1.0 / xrange;
     126    _yscale = 1.0 / yrange;
     127    _zscale = (zmax == 0.0) ? 1.0 : 1.0 / zrange;
     128    _xoffset = xmin;
     129    _yoffset = ymin;
     130    _zoffset = zmin;
     131    _xcenter = 0.5;
     132    _ycenter = 0.5;
     133    _zcenter = 0.0;
     134
    124135    if( aspect_ratio > 1.0 )
    125136    {
    126             _xscale = 1.0 / xrange;
    127             _xoffset = xmin;
    128             _xcenter = 0.5;
    129 
    130             _yscale = _xscale;
    131             _yoffset = ymin;
    132             _ycenter = 0.5 / aspect_ratio;
    133 
    134             _zscale = _xscale;
    135             _zoffset = zmin;
    136             _zcenter = 0.0;
     137      _scale = 1.0 / xrange;
     138      _ycenter /= aspect_ratio;
    137139    }
    138140    else
    139141    {
    140             _yscale = 1.0 / yrange;
    141             _yoffset = ymin;
    142             _ycenter = 0.5;
    143 
    144             _xscale = _yscale;
    145             _xoffset = xmin;
    146             _xcenter = 0.5 / aspect_ratio;
    147 
    148             _zscale = _yscale;
    149             _zoffset = zmin;
    150             _zcenter = 0.0;
     142      _scale = 1.0 / yrange;
     143      _xcenter /= aspect_ratio;
    151144    }
    152145
     
    180173    }
    181174
    182     // load bedslope vertex array, shifting and scaling vertices to unit cube
     175    // bedslope vertex array, shifting and scaling vertices to unit cube
    183176    // centred about the origin
    184177    _bedslopevertices = new osg::Vec3Array;
    185178    for (iv=0; iv < _npoints; iv++)
    186       _bedslopevertices->push_back( osg::Vec3( (_px[iv]-_xoffset)*_xscale - _xcenter,
    187                                                (_py[iv]-_yoffset)*_yscale - _ycenter,
    188                                                (_pz[iv]-_zoffset)*_zscale - _zcenter) );
    189 
    190     // load bedslope index array, pvolumes array indexes into x, y and z
    191     _bedslopeindices = new osg::UIntArray;
     179      _bedslopevertices->push_back( osg::Vec3( (_px[iv]-_xoffset)*_scale - _xcenter,
     180                                               (_py[iv]-_yoffset)*_scale - _ycenter,
     181                                               (_pz[iv]-_zoffset)*_scale - _zcenter) );
     182
     183    // bedslope index array, pvolumes array indexes into x, y and z
     184    _bedslopeindices = new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES, _nvolumes*_nvertices);
    192185    for (iv=0; iv < _nvolumes*_nvertices; iv++)
    193         _bedslopeindices->push_back( _pvolumes[iv] );
     186      (*_bedslopeindices)[iv] = _pvolumes[iv];
     187
     188
     189    // bedslope texture coords based on (x,y) locations scaled by extents into range [0,1]
     190    _bedslopetexcoords = new osg::Vec2Array;
     191    for( iv=0; iv < _npoints; iv++ )
     192      _bedslopetexcoords->push_back( osg::Vec2( (_px[iv]-_xoffset)*_xscale, (_py[iv]-_yoffset)*_yscale ) );
     193
     194
    194195
    195196    // calculate bedslope primitive normal and centroid arrays
     
    246247    _stagevertices = new osg::Vec3Array;
    247248    for (iv=0; iv < _npoints; iv++)
    248         _stagevertices->push_back( osg::Vec3(
    249                                              (_px[iv]-_xoffset)*_xscale - _xcenter,
    250                                              (_py[iv]-_yoffset)*_yscale - _ycenter,
    251                                              (_pstage[iv]-_zoffset)*_zscale - _zcenter) );
    252 
    253     // stage index and per primitive normal and centroid arrays
     249        _stagevertices->push_back( osg::Vec3( (_px[iv]-_xoffset)*_scale - _xcenter,
     250                                              (_py[iv]-_yoffset)*_scale - _ycenter,
     251                                              (_pstage[iv]-_zoffset)*_scale - _zcenter) );
     252
     253
     254    // stage index, per primitive normal and centroid arrays
    254255    _stageprimitivenormals = new osg::Vec3Array;
    255256    _stagecentroids = new osg::Vec3Array;
    256     _stageindices = new osg::UIntArray;
    257     _stagecolors = new osg::Vec4Array;
    258257    osg::Vec3 v1b, v2b, v3b;
    259258    osg::Vec3 v1s, v2s, v3s;
    260259    osg::Vec3 side1, side2, nrm;
    261260    unsigned int v1index, v2index, v3index;
    262     osg::ref_ptr<osg::UIntArray> culledlist = new osg::UIntArray;
    263     std::vector<triangle_list> stageconnectivity = std::vector<triangle_list>(_npoints);
    264261
    265262    // over all stage triangles
    266     unsigned int nonculled = 0;
    267     float alphamin = 1.0;
    268     float alphamax = 0.0;
    269263    for (iv=0; iv < _nvolumes; iv++){
    270264
     
    280274        v3b = _bedslopevertices->at(v3index);
    281275
    282         // shallow water depth culling test
    283         if( (_cullsetting == CULLALL || _cullsetting == CULLNEARZERO) &&
    284             ((v1s.z()+v2s.z()+v3s.z())/3.0 - _bedslopecentroids->at(iv).z()) < _cullnearzero )
    285         {
    286             culledlist->push_back( iv );
    287             continue;
    288         }
    289 
    290         // steep bedslope culling test
    291         if( _cullsetting == CULLALL || _cullsetting == CULLSTEEPANGLE )
    292         {
    293             if( _bedslopenormals->at(iv) * osg::Vec3f(0,0,1) < _cullsteepangle )
    294             {
    295                 culledlist->push_back( iv );
    296                 continue;
    297             }
    298         }
    299 
    300         // pass through, current triangle is visible (not culled)
    301         _stageindices->push_back( v1index );
    302         _stageindices->push_back( v2index );
    303         _stageindices->push_back( v3index );
    304 
    305         // alpha value based on stage-bedslope height difference
    306         float alpha1 = ( v1s.z()-v1b.z() )*10.0;
    307         float alpha2 = ( v2s.z()-v2b.z() )*10.0;
    308         float alpha3 = ( v3s.z()-v3b.z() )*10.0;
    309         alphamax = MAX( alphamax, alpha1 );
    310         alphamax = MAX( alphamax, alpha2 );
    311         alphamax = MAX( alphamax, alpha3 );
    312         alphamin = MIN( alphamin, alpha1 );
    313         alphamin = MIN( alphamin, alpha2 );
    314         alphamin = MIN( alphamin, alpha3 );
    315 
    316         osg::Vec4 color1, color2, color3;
    317         color1.set( alpha1,alpha1,alpha1, 1.0 );
    318         color2.set( alpha2,alpha2,alpha2, 1.0 );
    319         color3.set( alpha3,alpha3,alpha3, 1.0 );
    320         //color1.set( alpha1,alpha1,alpha1, alpha1 );
    321         //color2.set( alpha2,alpha2,alpha2, alpha2 );
    322         //color3.set( alpha3,alpha3,alpha3, alpha3 );
    323         _stagecolors->push_back( color1 );
    324         _stagecolors->push_back( color2 );
    325         _stagecolors->push_back( color3 );
    326 
    327276        // current triangle primitive normal
    328277        side1 = v2s - v1s;
     
    331280        nrm.normalize();
    332281
    333         // stage triangle connectivity, a list (indexed by vertex number)
    334         // of lists (indices of non-culled triangles sharing this vertex)
    335         stageconnectivity.at(v1index).push_back(nonculled);
    336         stageconnectivity.at(v2index).push_back(nonculled);
    337         stageconnectivity.at(v3index).push_back(nonculled);
    338 
    339         // store centroid and primitive normal (both needed to visualize vectors)
     282        // store centroid and primitive normal
    340283        _stagecentroids->push_back( (v1s+v2s+v3s)/3.0 );
    341284        _stageprimitivenormals->push_back( nrm );
    342285
    343         // non-culled triangle count
    344         nonculled++;
    345 
    346     }
    347 
    348     std::cout << "index: " << index << "    AlphaMax: " << alphamax << std::endl;
    349     std::cout << "index: " << index << "    AlphaMin: " << alphamin << std::endl;
    350 
    351     // per-vertex normals
     286    }
     287
     288
     289    float alpha;
     290    _stagecolors = new osg::Vec4Array;
     291    for (iv=0; iv < _npoints; iv++)
     292    {
     293      // FIXME: needs to be scaled appropriately
     294        alpha = ( _stagevertices->at(iv).z() - _bedslopevertices->at(iv).z() ) * 100.0;
     295        _stagecolors->push_back( osg::Vec4( 1.0, 1.0, 1.0, alpha ) );
     296    }
     297
     298
     299    // per-vertex normals calculated as average of primitive normals
     300    // from contributing triangles
    352301    _stagevertexnormals = new osg::Vec3Array;
    353302    int num_shared_triangles, triangle_index;
     
    355304    {
    356305        nrm.set(0,0,0);
    357         num_shared_triangles = stageconnectivity.at(iv).size();
     306        num_shared_triangles = _connectivity.at(iv).size();
    358307        for (int i=0; i<num_shared_triangles; i++ )
    359308        {
    360             triangle_index = stageconnectivity.at(iv).at(i);
    361 
    362             // summing of contributing primitive normals
     309            triangle_index = _connectivity.at(iv).at(i);
    363310            nrm += _stageprimitivenormals->at(triangle_index);
    364311        }
    365312
    366         // FIXME: Length of this list has to match vertex list length.
    367         // We have vertices and normals that aren't being referenced.
    368         if( 1 || num_shared_triangles )  // avoid vertices belonging only to culled triangles
    369         {
    370             nrm = nrm / num_shared_triangles;  // average
    371             nrm.normalize();
    372             _stagevertexnormals->push_back(nrm);
    373         }
     313        nrm = nrm / num_shared_triangles;  // average
     314        nrm.normalize();
     315        _stagevertexnormals->push_back(nrm);
    374316    }
    375317
Note: See TracChangeset for help on using the changeset viewer.