void TileModel::generateElevationTexture() { osg::Image* image = 0L; osg::HeightField* hf = _elevationData.getHeightField(); if ( hf ) { ImageToHeightFieldConverter conv; image = conv.convert( hf, 32 ); } else { // no heightfield; create one and initialize it to zero. image = new osg::Image(); image->allocateImage(32, 32, 1, GL_LUMINANCE, GL_FLOAT); ImageUtils::PixelWriter write(image); for(int s=0; s<image->s(); ++s) for(int t=0; t<image->t(); ++t) write(osg::Vec4(0,0,0,0), s, t); } _elevationTexture = new osg::Texture2D( image ); _elevationTexture->setInternalFormat(GL_LUMINANCE32F_ARB); _elevationTexture->setSourceFormat(GL_LUMINANCE); _elevationTexture->setFilter( osg::Texture::MAG_FILTER, osg::Texture::LINEAR ); _elevationTexture->setFilter( osg::Texture::MIN_FILTER, osg::Texture::LINEAR ); _elevationTexture->setWrap ( osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE ); _elevationTexture->setWrap ( osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE ); _elevationTexture->setResizeNonPowerOfTwoHint( false ); _elevationTexture->setMaxAnisotropy( 1.0f ); }
void Cache::setHeightField( const TileKey& key, const CacheSpec& spec, const osg::HeightField* hf) { ImageToHeightFieldConverter conv; //Take a reference to the returned image so it gets deleted properly osg::ref_ptr<osg::Image> image = conv.convert(hf); setImage( key, spec, image.get() ); }
osg::HeightField* TileSource::createHeightField(const TileKey& key, ProgressCallback* progress) { //osg::ref_ptr<osg::Image> image = createImage(key, dbOptions, progress); osg::ref_ptr<osg::Image> image = createImage(key, progress); osg::HeightField* hf = 0; if (image.valid()) { ImageToHeightFieldConverter conv; hf = conv.convert( image.get() ); } return hf; }
bool Cache::getHeightField( const TileKey& key, const CacheSpec& spec, osg::ref_ptr<const osg::HeightField>& out_hf ) { //Try to get an image from the cache osg::ref_ptr<const osg::Image> image; if ( getImage( key, spec, image ) ) { OE_DEBUG << LC << "Read cached heightfield " << std::endl; ImageToHeightFieldConverter conv; out_hf = conv.convert(image.get()); return out_hf.valid(); } else return false; }
osg::HeightField* WCS11Source::createHeightField(const TileKey& key, ProgressCallback* progress) { osg::HeightField* field = NULL; osg::ref_ptr<osg::Image> image = createImage( key, progress ); if ( image.valid() ) { ImageToHeightFieldConverter conv; conv.setRemoveNoDataValues( true ); field = conv.convert( image.get() ); } return field; }
bool TileSource::storeHeightField(const TileKey& key, osg::HeightField* hf, ProgressCallback* progress) { if ( _status != STATUS_OK || hf == 0L ) return 0L; ImageToHeightFieldConverter conv; osg::ref_ptr<osg::Image> image = conv.convert(hf, 32); if (image.valid()) { return storeImage(key, image.get(), progress); } return false; }
/** override */ osg::HeightField* createHeightField( const TileKey& key, ProgressCallback* progress) { osg::Image* image = createImage(key, progress); if (!image) { OE_INFO << "[osgEarth::WMS] Failed to read heightfield from " << createURI(key) << std::endl; } float scaleFactor = 1; //Scale the heightfield to meters if ( _options.elevationUnit() == "ft") { scaleFactor = 0.3048; } ImageToHeightFieldConverter conv; return conv.convert( image, scaleFactor ); }
void TerrainTileModelFactory::addElevation(TerrainTileModel* model, const Map* map, const TileKey& key, const CreateTileModelFilter& filter, unsigned border, ProgressCallback* progress) { // make an elevation layer. OE_START_TIMER(fetch_elevation); if (!filter.empty() && !filter.elevation().isSetTo(true)) return; const osgEarth::ElevationInterpolation& interp = map->getMapOptions().elevationInterpolation().get(); // Request a heightfield from the map. osg::ref_ptr<osg::HeightField> mainHF; osg::ref_ptr<NormalMap> normalMap; bool hfOK = getOrCreateHeightField(map, key, SAMPLE_FIRST_VALID, interp, border, mainHF, normalMap, progress) && mainHF.valid(); if (hfOK == false && key.getLOD() == _options.firstLOD().get()) { OE_DEBUG << LC << "No HF at key " << key.str() << ", making placeholder" << std::endl; mainHF = new osg::HeightField(); mainHF->allocate(1, 1); mainHF->setHeight(0, 0, 0.0f); hfOK = true; } if (hfOK && mainHF.valid()) { osg::ref_ptr<TerrainTileElevationModel> layerModel = new TerrainTileElevationModel(); layerModel->setHeightField( mainHF.get() ); // pre-calculate the min/max heights: for( unsigned col = 0; col < mainHF->getNumColumns(); ++col ) { for( unsigned row = 0; row < mainHF->getNumRows(); ++row ) { float h = mainHF->getHeight(col, row); if ( h > layerModel->getMaxHeight() ) layerModel->setMaxHeight( h ); if ( h < layerModel->getMinHeight() ) layerModel->setMinHeight( h ); } } // needed for normal map generation model->heightFields().setNeighbor(0, 0, mainHF.get()); // convert the heightfield to a 1-channel 32-bit fp image: ImageToHeightFieldConverter conv; osg::Image* hfImage = conv.convertToR32F(mainHF.get()); if ( hfImage ) { // Made an image, so store this as a texture with no matrix. osg::Texture* texture = createElevationTexture( hfImage ); layerModel->setTexture( texture ); model->elevationModel() = layerModel.get(); } if (normalMap.valid()) { TerrainTileImageLayerModel* layerModel = new TerrainTileImageLayerModel(); layerModel->setName( "oe_normal_map" ); // Made an image, so store this as a texture with no matrix. osg::Texture* texture = createNormalTexture(normalMap.get()); layerModel->setTexture( texture ); model->normalModel() = layerModel; } } if (progress) progress->stats()["fetch_elevation_time"] += OE_STOP_TIMER(fetch_elevation); }