Changeset 95


Ignore:
Timestamp:
Jun 3, 2005, 1:08:42 PM (19 years ago)
Author:
darran
Message:
  • correct texture coordinates for georeferenced bedslope images
Location:
Swollen
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • Swollen/doc/contract2_hours.txt

    r90 r95  
    33------------------
    44
     52 June, Thursday (2 hours)
     6- bedslope texture only used when specified
     7- almost finished image query of .sww global attributes
    58
    6931 May, Tuesday (3 hours)
  • Swollen/swollen/bedslope.cpp

    r92 r95  
    4848                osg::Texture2D* texture = new osg::Texture2D;
    4949                texture->setDataVariance( osg::Object::DYNAMIC );
    50                 texture->setWrap( osg::Texture::WRAP_S, osg::Texture::REPEAT );
    51                 texture->setWrap( osg::Texture::WRAP_T, osg::Texture::REPEAT );
     50                texture->setWrap( osg::Texture::WRAP_S, osg::Texture::CLAMP );
     51                texture->setWrap( osg::Texture::WRAP_T, osg::Texture::CLAMP );
    5252                texture->setImage( _sww->getBedslopeTexture() );
    5353
  • Swollen/swwreader/swwreader.cpp

    r92 r95  
    44    Reader of SWW files from within OpenSceneGraph.
    55
    6     copyright (C) 2004 Geoscience Australia
     6    copyright (C) 2004-2005 Geoscience Australia
    77*/
    88
     
    7575
    7676        // sww file can optionally contain bedslope texture image filename
    77         size_t attlen;
    78         if( nc_inq_attlen(_ncid, NC_GLOBAL, "institution", &attlen) != NC_ENOTATT )
     77        size_t attlen; // length of text attribute (if it exists)
     78        if( nc_inq_attlen(_ncid, NC_GLOBAL, "bedslope_image", &attlen) != NC_ENOTATT )
    7979        {
    80                 std::string filename;
    81                 int nc_get_att_text(_ncid, NC_GLOBAL, "institution", char filename);
    82                 setBedslopeTexture( std::string filename );
     80        char* filename;
     81        if( (filename = (char*) malloc(attlen+1)) != NULL){
     82            int status;
     83                status = nc_get_att_text(_ncid, NC_GLOBAL, "bedslope_image", filename);
     84            if( status == NC_NOERR )
     85            {
     86                filename[attlen] = '\0';  // ensure string is terminated, not a requirement for netcdf attributes
     87                osg::notify(osg::INFO) << "[SWWReader] embedded image filename: " << filename <<  std::endl;
     88                        setBedslopeTexture( std::string(filename) );
     89            }
     90        free( filename );
     91        }
    8392        }
    8493
     
    99108    for( iv=1; iv < _npoints; iv++ )
    100109    {
    101         if( _px[iv] < xmin ) xmin = _px[iv];
    102         if( _px[iv] > xmax ) xmax = _px[iv];
    103         if( _py[iv] < ymin ) ymin = _py[iv];
    104         if( _py[iv] > ymax ) ymax = _py[iv];
    105         if( _pz[iv] < zmin ) zmin = _pz[iv];
    106         if( _pz[iv] > zmax ) zmax = _pz[iv];
     110            if( _px[iv] < xmin ) xmin = _px[iv];
     111            if( _px[iv] > xmax ) xmax = _px[iv];
     112            if( _py[iv] < ymin ) ymin = _py[iv];
     113            if( _py[iv] > ymax ) ymax = _py[iv];
     114            if( _pz[iv] < zmin ) zmin = _pz[iv];
     115            if( _pz[iv] > zmax ) zmax = _pz[iv];
    107116    }
    108117
     
    238247      _bedslopegeodata.xresolution = pGDAL->GetRasterXSize();
    239248      _bedslopegeodata.yresolution = pGDAL->GetRasterYSize();
     249          osg::notify(osg::INFO) << "[SWWReader::setBedslopetexture] xresolution: " <<
     250          _bedslopegeodata.xresolution <<  std::endl;
     251          osg::notify(osg::INFO) << "[SWWReader::setBedslopetexture] yresolution: " <<
     252          _bedslopegeodata.yresolution <<  std::endl;
    240253
    241254      // check if image contains geodata
     
    271284osg::ref_ptr<osg::Vec2Array> SWWReader::getBedslopeTextureCoords()
    272285{
    273 
    274    // bedslope texture coords based on (x,y) locations scaled by extents into range [0,1]
    275286   _bedslopetexcoords = new osg::Vec2Array;
    276    for( unsigned int iv=0; iv < _npoints; iv++ )
    277       _bedslopetexcoords->push_back( osg::Vec2( (_px[iv]-_xoffset)*_xscale, (_py[iv]-_yoffset)*_yscale ) );
     287    if( _bedslopegeodata.hasData )  // georeferenced bedslope texture
     288    {
     289        float xorigin = _bedslopegeodata.xorigin;
     290        float yorigin = _bedslopegeodata.yorigin;
     291        float xrange = _bedslopegeodata.xpixel * _bedslopegeodata.xresolution;
     292        float yrange = _bedslopegeodata.ypixel * _bedslopegeodata.yresolution;
     293        for( unsigned int iv=0; iv < _npoints; iv++ )
     294            _bedslopetexcoords->push_back( osg::Vec2( (_px[iv] - xorigin)/xrange, (_py[iv] - yorigin)/yrange ) );           }
     295    else
     296    {
     297        // decal'd using (x,y) locations scaled by extents into range [0,1]
     298        for( unsigned int iv=0; iv < _npoints; iv++ )
     299            _bedslopetexcoords->push_back( osg::Vec2( (_px[iv]-_xoffset)*_xscale, (_py[iv]-_yoffset)*_yscale ) );
     300    }
    278301
    279302   return _bedslopetexcoords;
Note: See TracChangeset for help on using the changeset viewer.