void GlobePlugin::elevationLayersChanged() { if ( mIsGlobeRunning ) { QgsDebugMsg( "elevationLayersChanged: Globe Running, executing" ); osg::ref_ptr<Map> map = mMapNode->getMap(); if ( map->getNumElevationLayers() > 1 ) { mOsgViewer->getDatabasePager()->clear(); } // Remove elevation layers ElevationLayerVector list; map->getElevationLayers( list ); for ( ElevationLayerVector::iterator i = list.begin(); i != list.end(); ++i ) { map->removeElevationLayer( *i ); } // Add elevation layers QSettings settings; QString cacheDirectory = settings.value( "cache/directory", QgsApplication::qgisSettingsDirPath() + "cache" ).toString(); QTableWidget* table = mSettingsDialog->elevationDatasources(); for ( int i = 0; i < table->rowCount(); ++i ) { QString type = table->item( i, 0 )->text(); //bool cache = table->item( i, 1 )->checkState(); QString uri = table->item( i, 2 )->text(); ElevationLayer* layer = 0; if ( "Raster" == type ) { GDALOptions options; options.url() = uri.toStdString(); layer = new osgEarth::ElevationLayer( uri.toStdString(), options ); } else if ( "TMS" == type ) { TMSOptions options; options.url() = uri.toStdString(); layer = new osgEarth::ElevationLayer( uri.toStdString(), options ); } map->addElevationLayer( layer ); //if ( !cache || type == "Worldwind" ) layer->setCache( 0 ); //no tms cache for worldwind (use worldwind_cache) } #if OSGEARTH_VERSION_GREATER_OR_EQUAL( 2, 5, 0 ) double scale = QgsProject::instance()->readDoubleEntry( "Globe-Plugin", "/verticalScale", 1 ); setVerticalScale( scale ); #endif } else { QgsDebugMsg( "layersChanged: Globe NOT running, skipping" ); return; } }
/** * Makes a simple projected MapNode that contains a basemap of the world */ MapNode* makeMiniMapNode( ) { MapOptions mapOpt; mapOpt.coordSysType() = MapOptions::CSTYPE_PROJECTED; mapOpt.profile() = ProfileOptions("plate-carre"); Map* map = new Map( mapOpt ); GDALOptions basemapOpt; basemapOpt.url() = "../data/world.tif"; map->addImageLayer( new ImageLayer( ImageLayerOptions("basemap", basemapOpt) ) ); // That's it, the map is ready; now create a MapNode to render the Map: MapNodeOptions mapNodeOptions; mapNodeOptions.enableLighting() = false; return new MapNode( map, mapNodeOptions ); }
void GlobePlugin::layersChanged() { if ( mIsGlobeRunning ) { QgsDebugMsg( "layersChanged: Globe Running, executing" ); osg::ref_ptr<Map> map = mMapNode->getMap(); if ( map->getNumImageLayers() > 1 || map->getNumElevationLayers() > 1 ) { viewer.getDatabasePager()->clear(); } // Remove elevation layers ElevationLayerVector list; map->getElevationLayers( list ); for ( ElevationLayerVector::iterator i = list.begin(); i != list.end(); i++ ) { map->removeElevationLayer( *i ); } // Add elevation layers QSettings settings; QString cacheDirectory = settings.value( "cache/directory", QgsApplication::qgisSettingsDirPath() + "cache" ).toString(); QTableWidget* table = mSettingsDialog.elevationDatasources(); for ( int i = 0; i < table->rowCount(); ++i ) { QString type = table->item( i, 0 )->text(); bool cache = table->item( i, 1 )->checkState(); QString uri = table->item( i, 2 )->text(); ElevationLayer* layer = 0; if ( "Raster" == type ) { GDALOptions options; options.url() = uri.toStdString(); layer = new osgEarth::ElevationLayer( uri.toStdString(), options ); } else if ( "Worldwind" == type ) { WorldWindOptions options; options.elevationCachePath() = cacheDirectory.toStdString() + "/globe/worldwind_srtm"; layer = new osgEarth::ElevationLayer( "WorldWind bil", options ); TerrainEngineNode* terrainEngineNode = mMapNode->getTerrainEngine(); terrainEngineNode->setVerticalScale( 2 ); terrainEngineNode->setElevationSamplingRatio( 0.25 ); } else if ( "TMS" == type ) { TMSOptions options; options.url() = uri.toStdString(); layer = new osgEarth::ElevationLayer( uri.toStdString(), options ); } map->addElevationLayer( layer ); if ( !cache || type == "Worldwind" ) layer->setCache( 0 ); //no tms cache for worldwind (use worldwind_cache) } //remove QGIS layer if ( mQgisMapLayer ) { QgsDebugMsg( "removeMapLayer" ); map->removeImageLayer( mQgisMapLayer ); } //add QGIS layer QgsDebugMsg( "addMapLayer" ); mTileSource = new QgsOsgEarthTileSource( mQGisIface ); mTileSource->initialize( "", 0 ); ImageLayerOptions options( "QGIS" ); mQgisMapLayer = new ImageLayer( options, mTileSource ); map->addImageLayer( mQgisMapLayer ); mQgisMapLayer->setCache( 0 ); //disable caching } else { QgsDebugMsg( "layersChanged: Globe NOT running, skipping" ); return; } }
void GlobePlugin::setupMap() { QSettings settings; QString cacheDirectory = settings.value( "cache/directory", QgsApplication::qgisSettingsDirPath() + "cache" ).toString(); TMSCacheOptions cacheOptions; cacheOptions.setPath( cacheDirectory.toStdString() ); MapOptions mapOptions; mapOptions.cache() = cacheOptions; osgEarth::Map *map = new osgEarth::Map( mapOptions ); //Default image layer GDALOptions driverOptions; driverOptions.url() = QDir::cleanPath( QgsApplication::pkgDataPath() + "/globe/world.tif" ).toStdString(); ImageLayerOptions layerOptions( "world", driverOptions ); layerOptions.cacheEnabled() = false; map->addImageLayer( new osgEarth::ImageLayer( layerOptions ) ); MapNodeOptions nodeOptions; //nodeOptions.proxySettings() = //nodeOptions.enableLighting() = false; //LoadingPolicy loadingPolicy( LoadingPolicy::MODE_SEQUENTIAL ); TerrainOptions terrainOptions; //terrainOptions.loadingPolicy() = loadingPolicy; terrainOptions.compositingTechnique() = TerrainOptions::COMPOSITING_MULTITEXTURE_FFP; nodeOptions.setTerrainOptions( terrainOptions ); // The MapNode will render the Map object in the scene graph. mMapNode = new osgEarth::MapNode( map, nodeOptions ); //prefill cache if ( !QFile::exists( cacheDirectory + "/worldwind_srtm" ) ) { copyFolder( QgsApplication::pkgDataPath() + "/globe/data/worldwind_srtm", cacheDirectory + "/globe/worldwind_srtm" ); } mRootNode = new osg::Group(); mRootNode->addChild( mMapNode ); // Add layers to the map layersChanged(); // model placement utils mElevationManager = new osgEarth::Util::ElevationManager( mMapNode->getMap() ); mElevationManager->setTechnique( osgEarth::Util::ElevationManager::TECHNIQUE_GEOMETRIC ); mElevationManager->setMaxTilesToCache( 50 ); mObjectPlacer = new osgEarth::Util::ObjectPlacer( mMapNode ); // place 3D model on point layer if ( mSettingsDialog.modelLayer() && !mSettingsDialog.modelPath().isEmpty() ) { osg::Node* model = osgDB::readNodeFile( mSettingsDialog.modelPath().toStdString() ); if ( model ) { QgsVectorLayer* layer = mSettingsDialog.modelLayer(); QgsAttributeList fetchAttributes; layer->select( fetchAttributes ); //TODO: select only visible features QgsFeature feature; while ( layer->nextFeature( feature ) ) { QgsPoint point = feature.geometry()->asPoint(); placeNode( model, point.y(), point.x() ); } } } }
osg::Image* createImage( const TileKey& key, ProgressCallback* progress) { osg::Timer_t start = osg::Timer::instance()->tick(); std::vector< std::string > files; _index->getFiles( key.getExtent(), files ); osg::Timer_t end = osg::Timer::instance()->tick(); OE_DEBUG << "Got " << files.size() << " files in " << osg::Timer::instance()->delta_m( start, end) << " ms" << std::endl; // The result image osg::Image* result = 0; for (unsigned int i = 0; i < files.size(); i++) { osg::ref_ptr< TileSource> source; { //Try to get the TileSource from the cache TileSourceCache::Record record; if (_tileSourceCache.get( files[i], record )) { source = record.value().get(); } else { // Couldn't get it from the cache so open it. GDALOptions opt; opt.url() = files[i]; //Just force it to render so we don't have to worry about falling back opt.maxDataLevelOverride() = 23; //Disable the l2 cache so that we don't run out of RAM so easily. opt.L2CacheSize() = 0; start = osg::Timer::instance()->tick(); source = osgEarth::TileSourceFactory::create( opt ); Status compStatus = source->open(); if (compStatus.isOK()) { _tileSourceCache.insert( files[i], source.get() ); } else { OE_WARN << "Failed to open " << files[i] << std::endl; } end = osg::Timer::instance()->tick(); //OE_NOTICE << "init took " << osg::Timer::instance()->delta_m( start, end) << "ms" << std::endl; } } start = osg::Timer::instance()->tick(); osg::ref_ptr< osg::Image > image = source->createImage( key); end = osg::Timer::instance()->tick(); OE_DEBUG << "createImage " << osg::Timer::instance()->delta_m( start, end) << "ms" << std::endl; if (image) { if (!result) { // Initialize the result result = new osg::Image( *image.get() ); } else { // Composite the new image with the result ImageUtils::mix( result, image.get(), 1.0); } } else { OE_DEBUG << "Failed to create image for " << files[i] << std::endl; } } return result; }
// // NOTE: run this sample from the repo/tests directory. // int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc,argv); osgViewer::Viewer viewer(arguments); s_viewer = &viewer; // Start by creating the map: s_mapNode = MapNode::load(arguments); if ( !s_mapNode ) { Map* map = new Map(); // Start with a basemap imagery layer; we'll be using the GDAL driver // to load a local GeoTIFF file: GDALOptions basemapOpt; basemapOpt.url() = "../data/world.tif"; map->addImageLayer( new ImageLayer( ImageLayerOptions("basemap", basemapOpt) ) ); // That's it, the map is ready; now create a MapNode to render the Map: MapNodeOptions mapNodeOptions; mapNodeOptions.enableLighting() = false; s_mapNode = new MapNode( map, mapNodeOptions ); } s_mapNode->setNodeMask( 0x01 ); // Define a style for the feature data. Since we are going to render the // vectors as lines, configure the line symbolizer: StyleSheet* styleSheet = buildStyleSheet( Color::Yellow, 2.0f ); s_source = new FeatureListSource(); LineString* line = new LineString(); line->push_back( osg::Vec3d(-60, 20, 0) ); line->push_back( osg::Vec3d(-120, 20, 0) ); line->push_back( osg::Vec3d(-120, 60, 0) ); line->push_back( osg::Vec3d(-60, 60, 0) ); Feature *feature = new Feature(line, s_mapNode->getMapSRS(), Style(), s_fid++); s_source->insertFeature( feature ); s_activeFeature = feature; s_root = new osg::Group; s_root->addChild( s_mapNode.get() ); Session* session = new Session(s_mapNode->getMap(), styleSheet, s_source.get()); FeatureModelGraph* graph = new FeatureModelGraph( session, FeatureModelSourceOptions(), new GeomFeatureNodeFactory() ); graph->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); graph->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); s_root->addChild( graph ); //Setup the controls ControlCanvas* canvas = ControlCanvas::get( &viewer ); s_root->addChild( canvas ); Grid *toolbar = createToolBar( ); canvas->addControl( toolbar ); canvas->setNodeMask( 0x1 << 1 ); int col = 0; LabelControl* addVerts = new LabelControl("Add Verts"); toolbar->setControl(col++, 0, addVerts ); addVerts->addEventHandler( new AddVertsModeHandler( graph )); LabelControl* edit = new LabelControl("Edit"); toolbar->setControl(col++, 0, edit ); edit->addEventHandler(new EditModeHandler( graph )); unsigned int row = 0; Grid *styleBar = createToolBar( ); styleBar->setPosition(0, 50); canvas->addControl( styleBar ); //Make a list of styles styleBar->setControl(0, row++, new LabelControl("Styles") ); unsigned int numStyles = 8; for (unsigned int i = 0; i < numStyles; ++i) { float w = 50; osg::Vec4 color = randomColor(); float widths[3] = {2, 4, 8}; unsigned int r = row++; for (unsigned int j = 0; j < 3; j++) { Control* l = new Control(); l->setBackColor( color ); l->addEventHandler(new ChangeStyleHandler(graph, buildStyleSheet( color, widths[j] ) )); l->setSize(w,5 * widths[j]); styleBar->setControl(j, r, l); } } viewer.setSceneData( s_root.get() ); viewer.setCameraManipulator( new EarthManipulator() ); if ( s_mapNode ) viewer.getCamera()->addCullCallback( new osgEarth::Util::AutoClipPlaneCullCallback(s_mapNode) ); // add some stock OSG handlers: viewer.addEventHandler(new osgViewer::StatsHandler()); viewer.addEventHandler(new osgViewer::WindowSizeHandler()); viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet())); return viewer.run(); }
// // NOTE: run this sample from the repo/tests directory. // int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc,argv); if ( arguments.read("--help") ) return usage( argv[0] ); bool useRaster = arguments.read("--rasterize"); bool useOverlay = arguments.read("--overlay"); bool useStencil = arguments.read("--stencil"); bool useMem = arguments.read("--mem"); bool useLabels = arguments.read("--labels"); if ( useStencil ) osg::DisplaySettings::instance()->setMinimumNumStencilBits( 8 ); osgViewer::Viewer viewer(arguments); // Start by creating the map: Map* map = new Map(); // Start with a basemap imagery layer; we'll be using the GDAL driver // to load a local GeoTIFF file: GDALOptions basemapOpt; basemapOpt.url() = "../data/world.tif"; map->addImageLayer( new ImageLayer( ImageLayerOptions("basemap", basemapOpt) ) ); // Next we add a feature layer. OGRFeatureOptions featureOptions; if ( !useMem ) { // Configures the feature driver to load the vectors from a shapefile: featureOptions.url() = "../data/world.shp"; } else { // the --mem options tells us to just make an in-memory geometry: Ring* line = new Ring(); line->push_back( osg::Vec3d(-60, 20, 0) ); line->push_back( osg::Vec3d(-120, 20, 0) ); line->push_back( osg::Vec3d(-120, 60, 0) ); line->push_back( osg::Vec3d(-60, 60, 0) ); featureOptions.geometry() = line; } // Define a style for the feature data. Since we are going to render the // vectors as lines, configure the line symbolizer: Style style; LineSymbol* ls = style.getOrCreateSymbol<LineSymbol>(); ls->stroke()->color() = Color::Yellow; ls->stroke()->width() = 2.0f; // That's it, the map is ready; now create a MapNode to render the Map: MapNodeOptions mapNodeOptions; mapNodeOptions.enableLighting() = false; MapNode* mapNode = new MapNode( map, mapNodeOptions ); osg::Group* root = new osg::Group(); root->addChild( mapNode ); viewer.setSceneData( root ); viewer.setCameraManipulator( new EarthManipulator() ); // Process cmdline args MapNodeHelper().parse(mapNode, arguments, &viewer, root, new LabelControl("Features Demo")); if (useStencil) { FeatureStencilModelOptions stencilOptions; stencilOptions.featureOptions() = featureOptions; stencilOptions.styles() = new StyleSheet(); stencilOptions.styles()->addStyle( style ); stencilOptions.enableLighting() = false; stencilOptions.depthTestEnabled() = false; ls->stroke()->width() = 0.1f; map->addModelLayer( new ModelLayer("my features", stencilOptions) ); } else if (useRaster) { AGGLiteOptions rasterOptions; rasterOptions.featureOptions() = featureOptions; rasterOptions.styles() = new StyleSheet(); rasterOptions.styles()->addStyle( style ); map->addImageLayer( new ImageLayer("my features", rasterOptions) ); } else //if (useGeom || useOverlay) { FeatureGeomModelOptions geomOptions; geomOptions.featureOptions() = featureOptions; geomOptions.styles() = new StyleSheet(); geomOptions.styles()->addStyle( style ); geomOptions.enableLighting() = false; ModelLayerOptions layerOptions( "my features", geomOptions ); map->addModelLayer( new ModelLayer(layerOptions) ); } if ( useLabels ) { // set up symbology for drawing labels. We're pulling the label // text from the name attribute, and its draw priority from the // population attribute. Style labelStyle; TextSymbol* text = labelStyle.getOrCreateSymbol<TextSymbol>(); text->content() = StringExpression( "[cntry_name]" ); text->priority() = NumericExpression( "[pop_cntry]" ); text->removeDuplicateLabels() = true; text->size() = 16.0f; text->alignment() = TextSymbol::ALIGN_CENTER_CENTER; text->fill()->color() = Color::White; text->halo()->color() = Color::DarkGray; // and configure a model layer: FeatureGeomModelOptions geomOptions; geomOptions.featureOptions() = featureOptions; geomOptions.styles() = new StyleSheet(); geomOptions.styles()->addStyle( labelStyle ); map->addModelLayer( new ModelLayer("labels", geomOptions) ); } if ( !useStencil ) viewer.getCamera()->addCullCallback( new osgEarth::Util::AutoClipPlaneCullCallback(mapNode) ); // add some stock OSG handlers: viewer.addEventHandler(new osgViewer::StatsHandler()); viewer.addEventHandler(new osgViewer::WindowSizeHandler()); viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet())); return viewer.run(); }
// // NOTE: run this sample from the repo/tests directory. // int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc,argv); bool useRaster = arguments.read("--rasterize"); bool useOverlay = arguments.read("--overlay"); bool useStencil = arguments.read("--stencil"); bool useMem = arguments.read("--mem"); bool useLabels = arguments.read("--labels"); osgViewer::Viewer viewer(arguments); // Start by creating the map: Map* map = new Map(); // Start with a basemap imagery layer; we'll be using the GDAL driver // to load a local GeoTIFF file: GDALOptions basemapOpt; basemapOpt.url() = "../data/world.tif"; map->addImageLayer( new ImageLayer( ImageLayerOptions("basemap", basemapOpt) ) ); // Next we add a feature layer. First configure a feature driver to // load the vectors from a shapefile: OGRFeatureOptions featureOpt; if ( !useMem ) { featureOpt.url() = "../data/usa.shp"; } else { Ring* line = new Ring(); line->push_back( osg::Vec3d(-60, 20, 0) ); line->push_back( osg::Vec3d(-120, 20, 0) ); line->push_back( osg::Vec3d(-120, 60, 0) ); line->push_back( osg::Vec3d(-60, 60, 0) ); featureOpt.geometry() = line; } // Define a style for the feature data. Since we are going to render the // vectors as lines, configure the line symbolizer: Style style; LineSymbol* ls = style.getOrCreateSymbol<LineSymbol>(); ls->stroke()->color() = osg::Vec4f( 1,1,0,1 ); // yellow ls->stroke()->width() = 2.0f; // Add some text labels. if ( useLabels ) { TextSymbol* text = style.getOrCreateSymbol<TextSymbol>(); text->provider() = "overlay"; text->content() = StringExpression( "[name]" ); text->priority() = NumericExpression( "[area]" ); text->removeDuplicateLabels() = true; text->size() = 16.0f; text->fill()->color() = Color::White; text->halo()->color() = Color::DarkGray; } // That's it, the map is ready; now create a MapNode to render the Map: MapNodeOptions mapNodeOptions; mapNodeOptions.enableLighting() = false; MapNode* mapNode = new MapNode( map, mapNodeOptions ); // Now we'll choose the AGG-Lite driver to render the features. By the way, the // feature data is actually polygons, so we override that to treat it as lines. // We apply the feature driver and set the style as well. if (useStencil) { FeatureStencilModelOptions worldOpt; worldOpt.featureOptions() = featureOpt; worldOpt.geometryTypeOverride() = Geometry::TYPE_LINESTRING; worldOpt.styles() = new StyleSheet(); worldOpt.styles()->addStyle( style ); worldOpt.enableLighting() = false; worldOpt.depthTestEnabled() = false; map->addModelLayer( new ModelLayer( "my features", worldOpt ) ); } else if (useRaster) { AGGLiteOptions worldOpt; worldOpt.featureOptions() = featureOpt; worldOpt.geometryTypeOverride() = Geometry::TYPE_LINESTRING; worldOpt.styles() = new StyleSheet(); worldOpt.styles()->addStyle( style ); map->addImageLayer( new ImageLayer( ImageLayerOptions("world", worldOpt) ) ); } else //if (useGeom || useOverlay) { FeatureGeomModelOptions worldOpt; worldOpt.featureOptions() = featureOpt; worldOpt.geometryTypeOverride() = Geometry::TYPE_LINESTRING; worldOpt.styles() = new StyleSheet(); worldOpt.styles()->addStyle( style ); worldOpt.enableLighting() = false; worldOpt.depthTestEnabled() = false; ModelLayerOptions options( "my features", worldOpt ); options.overlay() = useOverlay; map->addModelLayer( new ModelLayer(options) ); } viewer.setSceneData( mapNode ); viewer.setCameraManipulator( new EarthManipulator() ); if ( !useStencil && !useOverlay ) viewer.addEventHandler( new osgEarth::Util::AutoClipPlaneHandler ); // add some stock OSG handlers: viewer.addEventHandler(new osgViewer::StatsHandler()); viewer.addEventHandler(new osgViewer::WindowSizeHandler()); viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet())); return viewer.run(); }
// // NOTE: run this sample from the repo/tests directory. // int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc,argv); osgViewer::Viewer viewer(arguments); s_viewer = &viewer; // Start by creating the map: s_mapNode = MapNode::load(arguments); if ( !s_mapNode ) { Map* map = new Map(); // Start with a basemap imagery layer; we'll be using the GDAL driver // to load a local GeoTIFF file: GDALOptions basemapOpt; basemapOpt.url() = "../data/world.tif"; map->addImageLayer( new ImageLayer( ImageLayerOptions("basemap", basemapOpt) ) ); // That's it, the map is ready; now create a MapNode to render the Map: MapNodeOptions mapNodeOptions; mapNodeOptions.enableLighting() = false; s_mapNode = new MapNode( map, mapNodeOptions ); } s_mapNode->setNodeMask( 0x01 ); // Define a style for the feature data. Style style = buildStyle( Color::Yellow, 2.0f ); //LineString* line = new LineString(); Geometry* geom = GeometryUtils::geometryFromWKT("POLYGON((191.026667 87.63333,114.75 78,89.5 77.333336,81.833336 75.333336,70.683334 74.5,70.916664 73.666664,68.666664 73.666664,66.291664 71.505,57.65 71.166664,58 73.9,48.616665 73,49.198334 71.43,49.5 70.5,43.266666 68.666664,32.083332 71.5,32.083332 74,35 74,35 81,32 81,32 90,191.026667 87.63333))"); OE_NOTICE << "Geometry " << GeometryUtils::geometryToWKT(geom) << std::endl; Feature* feature = new Feature(geom, s_mapNode->getMapSRS(), Style(), s_fid++); s_featureNode = new FeatureNode( s_mapNode, feature ); s_featureNode->setStyle( style ); s_editorsRoot = new osg::Group; s_root = new osg::Group; s_root->addChild( s_mapNode.get() ); s_root->addChild( s_featureNode.get() ); s_root->addChild( s_editorsRoot.get() ); //Setup the controls ControlCanvas* canvas = ControlCanvas::getOrCreate( &viewer ); s_root->addChild( canvas ); Grid *toolbar = createToolBar( ); canvas->addControl( toolbar ); canvas->setNodeMask( 0x1 << 1 ); int col = 0; LabelControl* addVerts = new LabelControl("Add Verts"); toolbar->setControl(col++, 0, addVerts ); addVerts->addEventHandler( new AddVertsModeHandler()); LabelControl* edit = new LabelControl("Edit"); toolbar->setControl(col++, 0, edit ); edit->addEventHandler(new EditModeHandler()); unsigned int row = 0; Grid *styleBar = createToolBar( ); styleBar->setPosition(0, 50); canvas->addControl( styleBar ); //Make a list of styles styleBar->setControl(0, row++, new LabelControl("Styles") ); unsigned int numStyles = 8; for (unsigned int i = 0; i < numStyles; ++i) { float w = 50; osg::Vec4 color = randomColor(); float widths[3] = {2, 4, 8}; unsigned int r = row++; for (unsigned int j = 0; j < 3; j++) { Control* l = new Control(); l->setBackColor( color ); l->addEventHandler(new ChangeStyleHandler(buildStyle( color, widths[j] ) )); l->setSize(w,5 * widths[j]); styleBar->setControl(j, r, l); } } viewer.setSceneData( s_root.get() ); viewer.setCameraManipulator( new EarthManipulator() ); if ( s_mapNode ) viewer.getCamera()->addCullCallback( new osgEarth::Util::AutoClipPlaneCullCallback(s_mapNode) ); // add some stock OSG handlers: viewer.addEventHandler(new osgViewer::StatsHandler()); viewer.addEventHandler(new osgViewer::WindowSizeHandler()); viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet())); return viewer.run(); }
void TileIndexBuilder::build(const std::string& indexFilename, const osgEarth::SpatialReference* srs) { expandFilenames(); if (!srs) { srs = osgEarth::SpatialReference::create("wgs84"); } osg::ref_ptr< osgEarth::Util::TileIndex > index = osgEarth::Util::TileIndex::create( indexFilename, srs ); _indexFilename = indexFilename; std::string indexDir = getFilePath( _indexFilename ); unsigned int total = _expandedFilenames.size(); for (unsigned int i = 0; i < _expandedFilenames.size(); i++) { std::string filename = _expandedFilenames[ i ]; GDALOptions opt; opt.url() = filename; osg::ref_ptr< ImageLayer > layer = new ImageLayer( ImageLayerOptions("", opt) ); bool ok = false; if ( layer.valid() ) { osg::ref_ptr< TileSource > source = layer->getTileSource(); if (source.valid()) { for (DataExtentList::iterator itr = source->getDataExtents().begin(); itr != source->getDataExtents().end(); ++itr) { // We want the filename as it is relative to the index file std::string relative = getPathRelative( indexDir, filename ); index->add( relative, *itr); ok = true; } } } if (_progress.valid()) { std::stringstream buf; if (ok) { buf << "Processed "; } else { buf << "Skipped "; } buf << filename; _progress->reportProgress( (double)i+1, (double)total, buf.str() ); } } osg::Timer_t end = osg::Timer::instance()->tick(); }