Changeset 64


Ignore:
Timestamp:
Dec 15, 2004, 5:21:19 PM (20 years ago)
Author:
darran
Message:
  • swollen is broken while I investigate lack of bedslope lighting
Location:
Swollen
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • Swollen/include/swwreader.h

    r62 r64  
    5353
    5454typedef std::vector<unsigned int> triangle_list;
     55
    5556
    5657class SWWREADER_EXPORT SWWReader
     
    140141    std::string* _bedslopetexture;
    141142
     143    // optional geodata for bedslope texture map
     144    struct
     145    {
     146        bool hasData;
     147        int xresolution, yresolution;
     148        float xorigin, yorigin;
     149        float xpixel, ypixel;
     150        float rotation;
     151    } _bedslopegeodata;
     152
     153
    142154    // bedslope vertex scale and shift factors (for normalizing to unit cube)
    143155    float _xscale, _yscale, _zscale, _scale;
  • Swollen/swollen/bedslope.cpp

    r62 r64  
    33#include <bedslope.h>
    44
    5 #include <osg/BoundingBox>
    65#include <osg/Texture2D>
    76#include <osg/TexEnv>
     7#include <osgUtil/SmoothingVisitor>
     8
    89
    910#define DEF_BEDSLOPE_COLOUR     145, 122, 59, 255     // R, G, B, Alpha (brown)
     
    2122    // geometry from sww file
    2223    osg::Vec3Array* vertices = _sww->getBedslopeVertexArray().get();
    23     osg::Vec3Array* normals = _sww->getBedslopeNormalArray().get();
     24    //osg::Vec3Array* normals = _sww->getBedslopeNormalArray().get();
    2425
    2526    _geom->setUseDisplayList(true);
    2627    _geom->setVertexArray( vertices );
    2728    _geom->addPrimitiveSet( _sww->getBedslopeIndexArray().get() );
    28     _geom->setNormalArray( normals );
    29     _geom->setNormalBinding( osg::Geometry::BIND_PER_PRIMITIVE );
     29    //_geom->setNormalArray( normals );
     30    //_geom->setNormalBinding( osg::Geometry::BIND_PER_PRIMITIVE );
    3031    _geom->setTexCoordArray( 0, _sww->getBedslopeTextureCoords().get() );
    3132
    32     // geometry bounding box
    33     osg::BoundingBox bbox = _geom->getBound();
     33    osg::UByte4Array* color = new osg::UByte4Array(1);
     34    (*color)[0] = osg::UByte4( 255,255,255,255 );
     35    _geom->setColorArray( color );
     36    _geom->setColorBinding( osg::Geometry::BIND_OVERALL );
     37
     38    // Calculate per-vertex normals
     39    osgUtil::SmoothingVisitor* visitor = new osgUtil::SmoothingVisitor();
     40    visitor->smooth( *_geom );
    3441
    3542    // bedslope texture
     
    3946    texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
    4047    texture->setImage( _sww->getBedslopeTexture() );
    41    
     48
     49    // state
    4250    _stateset = new osg::StateSet;
    43     _stateset->setTextureAttributeAndModes( 0, texture, osg::StateAttribute::ON );
     51    //_stateset->setTextureAttributeAndModes( 0, texture, osg::StateAttribute::ON );
    4452    _stateset->setMode( GL_BLEND, osg::StateAttribute::ON );
    4553    _stateset->setMode( GL_LIGHTING, osg::StateAttribute::ON );
     
    4957    _node->addDrawable(_geom);
    5058    _node->setStateSet(_stateset);
     59
    5160}
    5261
  • Swollen/swollen/main.cpp

    r62 r64  
    5454    viewer.setClearColor(osg::Vec4(DEF_BACKGROUND_COLOUR));
    5555    viewer.getCamera(0)->getRenderSurface()->setWindowRectangle(200,100,800,600);
     56    viewer.getCullSettings().setComputeNearFarMode( osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES );
    5657
    5758
     
    124125    // Lighting
    125126    SpotLight* spotlight = new SpotLight(rootStateSet);
    126     spotlight->setPosition( osg::Vec3(0,0,2) );  // overhead
     127    spotlight->setPosition( osg::Vec3(2,0,2) );  // z is up
    127128    spotlight->setSpotAngle( 45.0 );
    128129
  • Swollen/swollen/spotlight.cpp

    r36 r64  
    2121    _light->setLightNum(num);
    2222    _light->setPosition(osg::Vec4(0,0,0,1));
    23     _light->setAmbient(osg::Vec4(0.5,0.5,0.5,1));
     23    _light->setAmbient(osg::Vec4(0.0,0.0,0.0,1));
    2424    _light->setDiffuse(osg::Vec4(1,1,1,1));
     25    _light->setSpecular(osg::Vec4(1,0,0,1));
    2526    _light->setSpotCutoff(DEF_DEFAULT_ANGLE);
    2627    _light->setSpotExponent(DEF_DEFAULT_EXPONENT);
     
    2930    _source = new osg::LightSource;
    3031    _source->setReferenceFrame( osg::LightSource::RELATIVE_RF );
    31     _source->setLight(_light);
     32    _source->setLight( _light );
    3233    _source->setLocalStateSetModes( osg::StateAttribute::ON );
    3334    _source->setStateSetModes( *rootStateSet, osg::StateAttribute::ON );
     
    4344
    4445    // omit marker cone for now (FIX ME)
    45     // _group->addChild(_marker);
     46    _group->addChild(_marker);
    4647
    4748    setPosition( osg::Vec3(0,0,1) );  // default overhead
  • Swollen/swollen/watersurface.cpp

    r62 r64  
    2121#include <osgUtil/TriStripVisitor>
    2222
     23#define DEF_ALPHA_THRESHOLD 0.01
     24
    2325
    2426// constructor
     
    3638    _node->setStateSet(_stateset);
    3739
    38     _geom->setUseDisplayList( true );
     40    _geom->setUseDisplayList( false );
    3941
    4042    // initial geometry
     
    4850    texture->setImage(osgDB::readImageFile("envmap.jpg"));
    4951    _stateset->setTextureAttributeAndModes( 1, texture, osg::StateAttribute::ON );
    50     _stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
     52    _stateset->setMode( GL_LIGHTING, osg::StateAttribute::ON );
    5153
    5254    // surface transparency
     
    5961    // discard pixels with an alpha value below threshold
    6062    osg::AlphaFunc* alphaFunc = new osg::AlphaFunc;
    61     alphaFunc->setFunction( osg::AlphaFunc::GREATER, _sww->getAlphaMin() );
     63    alphaFunc->setFunction( osg::AlphaFunc::GREATER, DEF_ALPHA_THRESHOLD );
    6264    _stateset->setAttributeAndModes( alphaFunc, osg::StateAttribute::ON );
    6365
  • Swollen/swwreader/Makefile

    r62 r64  
    77
    88OPTIMIZATION     =  -O2
     9#OPTIMIZATION     =  -g
    910
    1011NETCDF_INCLUDE   =  /sw/include
  • Swollen/swwreader/swwreader.cpp

    r62 r64  
    8989    for( iv=1; iv < _npoints; iv++ )
    9090    {
    91       if( _px[iv] < xmin ) xmin = _px[iv];
    92       if( _px[iv] > xmax ) xmax = _px[iv];
    93       if( _py[iv] < ymin ) ymin = _py[iv];
    94       if( _py[iv] > ymax ) ymax = _py[iv];
    95       if( _pz[iv] < zmin ) zmin = _pz[iv];
    96       if( _pz[iv] > zmax ) zmax = _pz[iv];
     91        if( _px[iv] < xmin ) xmin = _px[iv];
     92        if( _px[iv] > xmax ) xmax = _px[iv];
     93        if( _py[iv] < ymin ) ymin = _py[iv];
     94        if( _py[iv] > ymax ) ymax = _py[iv];
     95        if( _pz[iv] < zmin ) zmin = _pz[iv];
     96        if( _pz[iv] > zmax ) zmax = _pz[iv];
    9797    }
    9898
     
    104104    _yscale = 1.0 / yrange;
    105105   
    106     //_zscale = (zmax == 0.0) ? 1.0 : 1.0 / zrange;
    107     //I think this is the right one (OMN) incase of a flat bed that
    108     //isn't necessarily going through z==0
     106    // handle case of a flat bed that doesn't necessarily pass through z=0
    109107    _zscale = (zrange == 0.0) ? 1.0 : 1.0 / zrange;
     108
    110109    _xoffset = xmin;
    111110    _yoffset = ymin;
     
    117116    if( aspect_ratio > 1.0 )
    118117    {
    119       _scale = 1.0 / xrange;
    120       _ycenter /= aspect_ratio;
     118        _scale = 1.0 / xrange;
     119        _ycenter /= aspect_ratio;
    121120    }
    122121    else
    123122    {
    124       _scale = 1.0 / yrange;
    125       _xcenter /= aspect_ratio;
     123        _scale = 1.0 / yrange;
     124        _xcenter /= aspect_ratio;
    126125    }
    127126
     
    133132
    134133
    135     // default texture map
     134    // default texture map without geodata
    136135    _bedslopetexture = new std::string("bedslope.jpg");
     136    _bedslopegeodata.hasData = false;
    137137
    138138
     
    165165    _bedslopevertices = new osg::Vec3Array;
    166166    for (iv=0; iv < _npoints; iv++)
    167       _bedslopevertices->push_back( osg::Vec3( (_px[iv]-_xoffset)*_scale - _xcenter,
    168                                               (_py[iv]-_yoffset)*_scale - _ycenter,
    169                                               (_pz[iv]-_zoffset)*_scale - _zcenter) );
     167        _bedslopevertices->push_back( osg::Vec3( (_px[iv]-_xoffset)*_scale - _xcenter,
     168                                                (_py[iv]-_yoffset)*_scale - _ycenter,
     169                                                (_pz[iv]-_zoffset)*_scale - _zcenter) );
    170170
    171171    // bedslope index array, pvolumes array indexes into x, y and z
    172172    _bedslopeindices = new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES, _nvolumes*_nvertices);
    173173    for (iv=0; iv < _nvolumes*_nvertices; iv++)
    174       (*_bedslopeindices)[iv] = _pvolumes[iv];
     174        (*_bedslopeindices)[iv] = _pvolumes[iv];
    175175
    176176
     
    217217    osg::notify(osg::INFO) << "[SWWReader::setBedslopetexture] filename: " << filename <<  std::endl;
    218218   _bedslopetexture = new std::string(filename);
    219 
    220    // attempt to extract geospatial metadata from image file
    221    GDALDataset  *poDataset;
     219   _bedslopegeodata.hasData = false;
     220
     221   // GDAL Geospatial Image Library
     222   GDALDataset *pGDAL;
    222223   GDALAllRegister();
    223    poDataset = (GDALDataset *) GDALOpen( filename.c_str(), GA_ReadOnly );
    224    if( poDataset == NULL )
     224   pGDAL = (GDALDataset *) GDALOpen( filename.c_str(), GA_ReadOnly );
     225   if( pGDAL == NULL )
    225226      osg::notify(osg::INFO) << "[SWWReader::setBedslopetexture] GDAL unable to open file: " << filename <<  std::endl;
    226227   else
    227228   {
    228       // extract metadata
    229       double adfGeoTransform[6];
    230 
    231       printf( "Driver: %s/%s\n",
    232               poDataset->GetDriver()->GetDescription(),
    233               poDataset->GetDriver()->GetMetadataItem( GDAL_DMD_LONGNAME ) );
    234 
    235       printf( "Size is %dx%dx%d\n",
    236               poDataset->GetRasterXSize(), poDataset->GetRasterYSize(),
    237               poDataset->GetRasterCount() );
    238 
    239       if( poDataset->GetProjectionRef()  != NULL )
    240          printf( "Projection is `%s'\n", poDataset->GetProjectionRef() );
    241 
    242       if( poDataset->GetGeoTransform( adfGeoTransform ) == CE_None )
     229      osg::notify(osg::INFO) << "[SWWReader::setBedslopetexture] GDAL Driver: "
     230                             << pGDAL->GetDriver()->GetDescription() << "/"
     231                             << pGDAL->GetDriver()->GetMetadataItem( GDAL_DMD_LONGNAME )
     232                             << std::endl;
     233
     234      _bedslopegeodata.xresolution = pGDAL->GetRasterXSize();
     235      _bedslopegeodata.yresolution = pGDAL->GetRasterYSize();
     236
     237      // check if image contains geodata
     238      double geodata[6];
     239      if( pGDAL->GetGeoTransform( geodata ) == CE_None )
    243240      {
    244          printf( "Origin = (%.6f,%.6f)\n",
    245                  adfGeoTransform[0], adfGeoTransform[3] );
    246 
    247          printf( "Pixel Size = (%.6f,%.6f)\n",
    248                  adfGeoTransform[1], adfGeoTransform[5] );
     241          _bedslopegeodata.xorigin = geodata[0];
     242          _bedslopegeodata.yorigin = geodata[3];
     243          _bedslopegeodata.rotation = geodata[2];
     244          _bedslopegeodata.xpixel = geodata[1];
     245          _bedslopegeodata.ypixel = geodata[5];
     246          _bedslopegeodata.hasData = true;
     247
     248          osg::notify(osg::INFO) << "[SWWReader::setBedslopetexture] xorigin: " << _bedslopegeodata.xorigin <<  std::endl;
     249          osg::notify(osg::INFO) << "[SWWReader::setBedslopetexture] yorigin: " << _bedslopegeodata.yorigin <<  std::endl;
     250          osg::notify(osg::INFO) << "[SWWReader::setBedslopetexture] xpixel: " << _bedslopegeodata.xpixel <<  std::endl;
     251          osg::notify(osg::INFO) << "[SWWReader::setBedslopetexture] ypixel: " << _bedslopegeodata.ypixel <<  std::endl;
     252          osg::notify(osg::INFO) << "[SWWReader::setBedslopetexture] rotation: " << _bedslopegeodata.rotation <<  std::endl;
    249253      }
    250254   }
Note: See TracChangeset for help on using the changeset viewer.