示例#1
0
Registry::Registry() :
osg::Referenced     ( true ),
_gdal_registered    ( false ),
_numGdalMutexGets   ( 0 ),
_uidGen             ( 0 ),
_caps               ( 0L ),
_defaultFont        ( 0L ),
_terrainEngineDriver( "mp" )
{
    // set up GDAL and OGR.
    OGRRegisterAll();
    GDALAllRegister();

    // global initialization for CURL (not thread safe)
    HTTPClient::globalInit();

    // generates the basic shader code for the terrain engine and model layers.
    _shaderLib = new ShaderFactory();

    // thread pool for general use
    _taskServiceManager = new TaskServiceManager();

    // optimizes sharing of state attributes and state sets for
    // performance boost
    _stateSetCache = new StateSetCache();

    // activate KMZ support
    osgDB::Registry::instance()->addArchiveExtension  ( "kmz" );
    osgDB::Registry::instance()->addFileExtensionAlias( "kmz", "kml" );

    osgDB::Registry::instance()->addMimeTypeExtensionMapping( "application/vnd.google-earth.kml+xml", "kml" );
    osgDB::Registry::instance()->addMimeTypeExtensionMapping( "application/vnd.google-earth.kmz",     "kmz" );
    osgDB::Registry::instance()->addMimeTypeExtensionMapping( "text/plain",                           "osgb" );
    osgDB::Registry::instance()->addMimeTypeExtensionMapping( "text/xml",                             "osgb" );
    osgDB::Registry::instance()->addMimeTypeExtensionMapping( "application/json",                     "osgb" );
    osgDB::Registry::instance()->addMimeTypeExtensionMapping( "text/json",                            "osgb" );
    osgDB::Registry::instance()->addMimeTypeExtensionMapping( "text/x-json",                          "osgb" );
    osgDB::Registry::instance()->addMimeTypeExtensionMapping( "image/jpg",                            "jpg" );
    
    // pre-load OSG's ZIP plugin so that we can use it in URIs
    std::string zipLib = osgDB::Registry::instance()->createLibraryNameForExtension( "zip" );
    if ( !zipLib.empty() )
        osgDB::Registry::instance()->loadLibrary( zipLib );    

    // set up our default r/w options to NOT cache archives!
    _defaultOptions = new osgDB::Options();
    _defaultOptions->setObjectCacheHint( osgDB::Options::CACHE_NONE );
    //_defaultOptions->setObjectCacheHint( (osgDB::Options::CacheHintOptions)
    //    ((int)_defaultOptions->getObjectCacheHint() & ~osgDB::Options::CACHE_ARCHIVES) );

    // see if there's a cache in the envvar
    const char* cachePath = ::getenv("OSGEARTH_CACHE_PATH");
    if ( cachePath )
    {
        FileSystemCacheOptions options;
        options.rootPath() = std::string(cachePath);

        osg::ref_ptr<Cache> cache = CacheFactory::create(options);
        if ( cache->isOK() )
        {
            setCache( cache.get() );
            OE_INFO << LC << "CACHE PATH set from environment variable: \"" << cachePath << "\"" << std::endl;
        }
        else
        {
            OE_WARN << LC << "FAILED to initialize cache from env.var." << std::endl;
        }
    }

    // activate cache-only mode from the environment
    if ( ::getenv("OSGEARTH_CACHE_ONLY") )
    {
        setOverrideCachePolicy( CachePolicy::CACHE_ONLY );
        OE_INFO << LC << "CACHE-ONLY MODE set from environment variable" << std::endl;
    }

    // activate no-cache mode from the environment
    else if ( ::getenv("OSGEARTH_NO_CACHE") )
    {
        setOverrideCachePolicy( CachePolicy::NO_CACHE );
        OE_INFO << LC << "NO-CACHE MODE set from environment variable" << std::endl;
    }

    const char* teStr = ::getenv("OSGEARTH_TERRAIN_ENGINE");
    if ( teStr )
    {
        _terrainEngineDriver = std::string(teStr);
    }

    // load a default font
    const char* envFont = ::getenv("OSGEARTH_DEFAULT_FONT");
    if ( envFont )
    {
        _defaultFont = osgText::readFontFile( std::string(envFont) );
    }
    if ( !_defaultFont.valid() )
    {
#ifdef WIN32
        _defaultFont = osgText::readFontFile("arial.ttf");
#endif
    }

    // register the system stock Units.
    Units::registerAll( this );
}
Registry::Registry() :
osg::Referenced  ( true ),
_gdal_registered ( false ),
_numGdalMutexGets( 0 ),
_uidGen          ( 0 ),
_caps            ( 0L ),
_defaultFont     ( 0L )
{
    // set up GDAL and OGR.
    OGRRegisterAll();
    GDALAllRegister();

    _shaderLib = new ShaderFactory();
    _taskServiceManager = new TaskServiceManager();

    // activate KMZ support
    osgDB::Registry::instance()->addFileExtensionAlias( "kmz", "kml" );
    osgDB::Registry::instance()->addArchiveExtension  ( "kmz" );    

#if OSG_MIN_VERSION_REQUIRED(3,0,0)
    osgDB::Registry::instance()->addMimeTypeExtensionMapping( "application/vnd.google-earth.kml+xml", "kml" );
    osgDB::Registry::instance()->addMimeTypeExtensionMapping( "application/vnd.google-earth.kmz",     "kmz" );
    //osgDB::Registry::instance()->addMimeTypeExtensionMapping( "text/xml",                             "xml" );
    //osgDB::Registry::instance()->addMimeTypeExtensionMapping( "application/json",                     "json" );
    //osgDB::Registry::instance()->addMimeTypeExtensionMapping( "text/json",                            "json" );
    //osgDB::Registry::instance()->addMimeTypeExtensionMapping( "text/x-json",                          "json" );
    osgDB::Registry::instance()->addMimeTypeExtensionMapping( "text/plain",                           "osgb" );
    osgDB::Registry::instance()->addMimeTypeExtensionMapping( "text/xml",                             "osgb" );
    osgDB::Registry::instance()->addMimeTypeExtensionMapping( "application/json",                     "osgb" );
    osgDB::Registry::instance()->addMimeTypeExtensionMapping( "text/json",                            "osgb" );
    osgDB::Registry::instance()->addMimeTypeExtensionMapping( "text/x-json",                          "osgb" );
#endif
    
    // pre-load OSG's ZIP plugin so that we can use it in URIs
    std::string zipLib = osgDB::Registry::instance()->createLibraryNameForExtension( "zip" );
    if ( !zipLib.empty() )
        osgDB::Registry::instance()->loadLibrary( zipLib );    

    // set up our default r/w options to NOT cache archives!
    _defaultOptions = new osgDB::Options();
    _defaultOptions->setObjectCacheHint( osgDB::Options::CACHE_NONE );
    //_defaultOptions->setObjectCacheHint( (osgDB::Options::CacheHintOptions)
    //    ((int)_defaultOptions->getObjectCacheHint() & ~osgDB::Options::CACHE_ARCHIVES) );

    // see if there's a cache in the envvar
    const char* cachePath = ::getenv("OSGEARTH_CACHE_PATH");
    if ( cachePath )
    {
        FileSystemCacheOptions options;
        options.rootPath() = std::string(cachePath);

        osg::ref_ptr<Cache> cache = CacheFactory::create(options);
        if ( cache->isOK() )
        {
            setCache( cache.get() );
            OE_INFO << LC << "CACHE PATH set from environment variable: \"" << cachePath << "\"" << std::endl;
        }
        else
        {
            OE_WARN << LC << "FAILED to initialize cache from env.var." << std::endl;
        }
    }

    // activate cache-only mode from the environment
    if ( ::getenv("OSGEARTH_CACHE_ONLY") )
    {
        _defaultCachePolicy = CachePolicy::CACHE_ONLY;
        OE_INFO << LC << "CACHE-ONLY MODE set from environment variable" << std::endl;
    }

    // activate no-cache mode from the environment
    else if ( ::getenv("OSGEARTH_NO_CACHE") )
    {
        _defaultCachePolicy = CachePolicy::NO_CACHE;
        OE_INFO << LC << "NO-CACHE MODE set from environment variable" << std::endl;
    }

    // load a default font

    const char* envFont = ::getenv("OSGEARTH_DEFAULT_FONT");
    if ( envFont )
    {
        _defaultFont = osgText::readFontFile( std::string(envFont) );
    }
    if ( !_defaultFont.valid() )
    {
#ifdef WIN32
        _defaultFont = osgText::readFontFile("arial.ttf");
#endif
    }
}
示例#3
0
void GlobePlugin::setupMap()
{
  QSettings settings;
  QString cacheDirectory = settings.value( "cache/directory", QgsApplication::qgisSettingsDirPath() + "cache" ).toString();

#if OSGEARTH_VERSION_GREATER_OR_EQUAL( 2, 2, 0 )
  FileSystemCacheOptions cacheOptions;
  cacheOptions.rootPath() = cacheDirectory.toStdString();
#else
  TMSCacheOptions cacheOptions;
  cacheOptions.setPath( cacheDirectory.toStdString() );
#endif

  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 );
  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;
  //terrainOptions.lodFallOff() = 6.0;
  nodeOptions.setTerrainOptions( terrainOptions );

  // The MapNode will render the Map object in the scene graph.
  mMapNode = new osgEarth::MapNode( map, nodeOptions );

  if ( settings.value( "/Plugin-Globe/baseLayerEnabled", true ).toBool() )
  {
    setBaseMap( settings.value( "/Plugin-Globe/baseLayerURL", "http://readymap.org/readymap/tiles/1.0.0/7/" ).toString() );
  }

  mRootNode = new osg::Group();
  mRootNode->addChild( mMapNode );

  // Add layers to the map
  imageLayersChanged();
  elevationLayersChanged();

  // model placement utils
#ifdef HAVE_OSGEARTH_ELEVATION_QUERY
#else
  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();
      QgsFeatureIterator fit = layer->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( QgsAttributeList() ) ); //TODO: select only visible features
      QgsFeature feature;
      while ( fit.nextFeature( feature ) )
      {
        QgsPoint point = feature.geometry()->asPoint();
        placeNode( model, point.y(), point.x() );
      }
    }
  }
#endif

}