Changeset 64
- Timestamp:
- Dec 15, 2004, 5:21:19 PM (20 years ago)
- Location:
- Swollen
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
Swollen/include/swwreader.h
r62 r64 53 53 54 54 typedef std::vector<unsigned int> triangle_list; 55 55 56 56 57 class SWWREADER_EXPORT SWWReader … … 140 141 std::string* _bedslopetexture; 141 142 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 142 154 // bedslope vertex scale and shift factors (for normalizing to unit cube) 143 155 float _xscale, _yscale, _zscale, _scale; -
Swollen/swollen/bedslope.cpp
r62 r64 3 3 #include <bedslope.h> 4 4 5 #include <osg/BoundingBox>6 5 #include <osg/Texture2D> 7 6 #include <osg/TexEnv> 7 #include <osgUtil/SmoothingVisitor> 8 8 9 9 10 #define DEF_BEDSLOPE_COLOUR 145, 122, 59, 255 // R, G, B, Alpha (brown) … … 21 22 // geometry from sww file 22 23 osg::Vec3Array* vertices = _sww->getBedslopeVertexArray().get(); 23 osg::Vec3Array* normals = _sww->getBedslopeNormalArray().get();24 //osg::Vec3Array* normals = _sww->getBedslopeNormalArray().get(); 24 25 25 26 _geom->setUseDisplayList(true); 26 27 _geom->setVertexArray( vertices ); 27 28 _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 ); 30 31 _geom->setTexCoordArray( 0, _sww->getBedslopeTextureCoords().get() ); 31 32 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 ); 34 41 35 42 // bedslope texture … … 39 46 texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT); 40 47 texture->setImage( _sww->getBedslopeTexture() ); 41 48 49 // state 42 50 _stateset = new osg::StateSet; 43 _stateset->setTextureAttributeAndModes( 0, texture, osg::StateAttribute::ON );51 //_stateset->setTextureAttributeAndModes( 0, texture, osg::StateAttribute::ON ); 44 52 _stateset->setMode( GL_BLEND, osg::StateAttribute::ON ); 45 53 _stateset->setMode( GL_LIGHTING, osg::StateAttribute::ON ); … … 49 57 _node->addDrawable(_geom); 50 58 _node->setStateSet(_stateset); 59 51 60 } 52 61 -
Swollen/swollen/main.cpp
r62 r64 54 54 viewer.setClearColor(osg::Vec4(DEF_BACKGROUND_COLOUR)); 55 55 viewer.getCamera(0)->getRenderSurface()->setWindowRectangle(200,100,800,600); 56 viewer.getCullSettings().setComputeNearFarMode( osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES ); 56 57 57 58 … … 124 125 // Lighting 125 126 SpotLight* spotlight = new SpotLight(rootStateSet); 126 spotlight->setPosition( osg::Vec3( 0,0,2) ); // overhead127 spotlight->setPosition( osg::Vec3(2,0,2) ); // z is up 127 128 spotlight->setSpotAngle( 45.0 ); 128 129 -
Swollen/swollen/spotlight.cpp
r36 r64 21 21 _light->setLightNum(num); 22 22 _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)); 24 24 _light->setDiffuse(osg::Vec4(1,1,1,1)); 25 _light->setSpecular(osg::Vec4(1,0,0,1)); 25 26 _light->setSpotCutoff(DEF_DEFAULT_ANGLE); 26 27 _light->setSpotExponent(DEF_DEFAULT_EXPONENT); … … 29 30 _source = new osg::LightSource; 30 31 _source->setReferenceFrame( osg::LightSource::RELATIVE_RF ); 31 _source->setLight( _light);32 _source->setLight( _light ); 32 33 _source->setLocalStateSetModes( osg::StateAttribute::ON ); 33 34 _source->setStateSetModes( *rootStateSet, osg::StateAttribute::ON ); … … 43 44 44 45 // omit marker cone for now (FIX ME) 45 //_group->addChild(_marker);46 _group->addChild(_marker); 46 47 47 48 setPosition( osg::Vec3(0,0,1) ); // default overhead -
Swollen/swollen/watersurface.cpp
r62 r64 21 21 #include <osgUtil/TriStripVisitor> 22 22 23 #define DEF_ALPHA_THRESHOLD 0.01 24 23 25 24 26 // constructor … … 36 38 _node->setStateSet(_stateset); 37 39 38 _geom->setUseDisplayList( true );40 _geom->setUseDisplayList( false ); 39 41 40 42 // initial geometry … … 48 50 texture->setImage(osgDB::readImageFile("envmap.jpg")); 49 51 _stateset->setTextureAttributeAndModes( 1, texture, osg::StateAttribute::ON ); 50 _stateset->setMode( GL_LIGHTING, osg::StateAttribute::O FF);52 _stateset->setMode( GL_LIGHTING, osg::StateAttribute::ON ); 51 53 52 54 // surface transparency … … 59 61 // discard pixels with an alpha value below threshold 60 62 osg::AlphaFunc* alphaFunc = new osg::AlphaFunc; 61 alphaFunc->setFunction( osg::AlphaFunc::GREATER, _sww->getAlphaMin());63 alphaFunc->setFunction( osg::AlphaFunc::GREATER, DEF_ALPHA_THRESHOLD ); 62 64 _stateset->setAttributeAndModes( alphaFunc, osg::StateAttribute::ON ); 63 65 -
Swollen/swwreader/Makefile
r62 r64 7 7 8 8 OPTIMIZATION = -O2 9 #OPTIMIZATION = -g 9 10 10 11 NETCDF_INCLUDE = /sw/include -
Swollen/swwreader/swwreader.cpp
r62 r64 89 89 for( iv=1; iv < _npoints; iv++ ) 90 90 { 91 92 93 94 95 96 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]; 97 97 } 98 98 … … 104 104 _yscale = 1.0 / yrange; 105 105 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 109 107 _zscale = (zrange == 0.0) ? 1.0 : 1.0 / zrange; 108 110 109 _xoffset = xmin; 111 110 _yoffset = ymin; … … 117 116 if( aspect_ratio > 1.0 ) 118 117 { 119 120 118 _scale = 1.0 / xrange; 119 _ycenter /= aspect_ratio; 121 120 } 122 121 else 123 122 { 124 125 123 _scale = 1.0 / yrange; 124 _xcenter /= aspect_ratio; 126 125 } 127 126 … … 133 132 134 133 135 // default texture map 134 // default texture map without geodata 136 135 _bedslopetexture = new std::string("bedslope.jpg"); 136 _bedslopegeodata.hasData = false; 137 137 138 138 … … 165 165 _bedslopevertices = new osg::Vec3Array; 166 166 for (iv=0; iv < _npoints; iv++) 167 168 169 167 _bedslopevertices->push_back( osg::Vec3( (_px[iv]-_xoffset)*_scale - _xcenter, 168 (_py[iv]-_yoffset)*_scale - _ycenter, 169 (_pz[iv]-_zoffset)*_scale - _zcenter) ); 170 170 171 171 // bedslope index array, pvolumes array indexes into x, y and z 172 172 _bedslopeindices = new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES, _nvolumes*_nvertices); 173 173 for (iv=0; iv < _nvolumes*_nvertices; iv++) 174 174 (*_bedslopeindices)[iv] = _pvolumes[iv]; 175 175 176 176 … … 217 217 osg::notify(osg::INFO) << "[SWWReader::setBedslopetexture] filename: " << filename << std::endl; 218 218 _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; 222 223 GDALAllRegister(); 223 p oDataset= (GDALDataset *) GDALOpen( filename.c_str(), GA_ReadOnly );224 if( p oDataset== NULL )224 pGDAL = (GDALDataset *) GDALOpen( filename.c_str(), GA_ReadOnly ); 225 if( pGDAL == NULL ) 225 226 osg::notify(osg::INFO) << "[SWWReader::setBedslopetexture] GDAL unable to open file: " << filename << std::endl; 226 227 else 227 228 { 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 ) 243 240 { 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; 249 253 } 250 254 }
Note: See TracChangeset
for help on using the changeset viewer.