osgEarth 2.1.1
Public Member Functions | Protected Member Functions | Protected Attributes

osgEarth::CacheSeed Class Reference

Collaboration diagram for osgEarth::CacheSeed:

List of all members.

Public Member Functions

 CacheSeed ()
void setMinLevel (const unsigned int &minLevel)
const unsigned int getMinLevel () const
void setMaxLevel (const unsigned int &maxLevel)
const unsigned int getMaxLevel () const
const BoundsgetBounds () const
void setBounds (const Bounds &bounds)
void setBounds (const double &minLon, const double &minLat, const double &maxLon, const double &maxLat)
void setProgressCallback (osgEarth::ProgressCallback *progress)
void seed (Map *map)

Protected Member Functions

void processKey (const MapFrame &mapf, const TileKey &key) const
void cacheTile (const MapFrame &mapf, const TileKey &key) const

Protected Attributes

unsigned int _minLevel
unsigned int _maxLevel
Bounds _bounds
osg::ref_ptr< ProgressCallback_progress

Detailed Description

Utility class for seeding a cache

Definition at line 33 of file CacheSeed.


Constructor & Destructor Documentation

osgEarth::CacheSeed::CacheSeed ( ) [inline]

Definition at line 36 of file CacheSeed.

                   :
          _minLevel(0),
          _maxLevel(12),
          _bounds(-180, -90, 180, 90) { }

Member Function Documentation

void CacheSeed::cacheTile ( const MapFrame mapf,
const TileKey key 
) const [protected]

Definition at line 189 of file CacheSeed.cpp.

{
    for( ImageLayerVector::const_iterator i = mapf.imageLayers().begin(); i != mapf.imageLayers().end(); i++ )
    {
        ImageLayer* layer = i->get();
        if ( layer->isKeyValid( key ) )
        {
            GeoImage image = layer->createImage( key );
        }
    }

    if ( mapf.elevationLayers().size() > 0 )
    {
        osg::ref_ptr<osg::HeightField> hf;
        mapf.getHeightField( key, false, hf );
    }
}

Here is the call graph for this function:

const Bounds& osgEarth::CacheSeed::getBounds ( ) const [inline]

Gets the bounds to seed in

Definition at line 64 of file CacheSeed.

{ return _bounds; }
const unsigned int osgEarth::CacheSeed::getMaxLevel ( ) const [inline]

Gets the maximum level to cache to.

Definition at line 59 of file CacheSeed.

{return _maxLevel;}
const unsigned int osgEarth::CacheSeed::getMinLevel ( ) const [inline]

Gets the minimum level to cache to.

Definition at line 49 of file CacheSeed.

{return _minLevel;}
void CacheSeed::processKey ( const MapFrame mapf,
const TileKey key 
) const [protected]

Definition at line 149 of file CacheSeed.cpp.

{
    unsigned int x, y, lod;
    key.getTileXY(x, y);
    lod = key.getLevelOfDetail();

//      osg::ref_ptr<osgEarth::VersionedTerrain> terrain = new osgEarth::VersionedTerrain( map, engine );

    if ( _minLevel <= lod && _maxLevel >= lod )
    {
//        OE_NOTICE << "Caching tile = " << key.str() << std::endl; //<< lod << " (" << x << ", " << y << ") " << std::endl;
        if ( _progress.valid() && _progress->reportProgress(0, 0, "Caching tile: " + key.str()) )
            return; // Task has been cancelled by user

        cacheTile( mapf, key );
  //      bool validData;
                //osg::ref_ptr<osg::Node> node = engine->createTile( map, terrain.get(), key, true, false, false, validData );        
    }

    if (lod <= _maxLevel)
    {
        TileKey k0 = key.createChildKey(0);
        TileKey k1 = key.createChildKey(1);
        TileKey k2 = key.createChildKey(2);
        TileKey k3 = key.createChildKey(3);        

        //Check to see if the bounds intersects ANY of the tile's children.  If it does, then process all of the children
        //for this level
        if (_bounds.intersects( k0.getExtent().bounds() ) || _bounds.intersects(k1.getExtent().bounds()) ||
            _bounds.intersects( k2.getExtent().bounds() ) || _bounds.intersects(k3.getExtent().bounds()) )
        {
            processKey(mapf, k0);
            processKey(mapf, k1);
            processKey(mapf, k2);
            processKey(mapf, k3);
        }
    }
}

Here is the call graph for this function:

void CacheSeed::seed ( Map map)

Performs the seed operation

Definition at line 28 of file CacheSeed.cpp.

{
    //Threading::ScopedReadLock lock( map->getMapDataMutex() );

    if ( !map->getMapOptions().cache().isSet() )
    //if (!map->getCache())
    {
        OE_WARN << "Warning:  Map does not have a cache defined, please define a cache." << std::endl;
        return;
    }

//    osg::ref_ptr<MapEngine> engine = new MapEngine(); //map->createMapEngine();

    std::vector<TileKey> keys;
    map->getProfile()->getRootKeys(keys);

    //Set the default bounds to the entire profile if the user didn't override the bounds
    if (_bounds.xMin() == 0 && _bounds.yMin() == 0 &&
        _bounds.xMax() == 0 && _bounds.yMax() == 0)
    {
        const GeoExtent& mapEx =  map->getProfile()->getExtent();
        _bounds = Bounds( mapEx.xMin(), mapEx.yMin(), mapEx.xMax(), mapEx.yMax() );
    }


    bool hasCaches = false;
    int src_min_level = INT_MAX;
    unsigned int src_max_level = 0;

    MapFrame mapf( map, Map::TERRAIN_LAYERS, "CacheSeed::seed" );

    //Assumes the the TileSource will perform the caching for us when we call createImage
    for( ImageLayerVector::const_iterator i = mapf.imageLayers().begin(); i != mapf.imageLayers().end(); i++ )
    {
                ImageLayer* layer = i->get();
        TileSource* src = i->get()->getTileSource();
        const ImageLayerOptions& opt = layer->getImageLayerOptions();

        if ( opt.cacheOnly() == true )
        {
            OE_WARN << "Warning:  Cannot seed b/c Layer \"" << layer->getName() << "\" is cache only." << std::endl;
            return;
        }
        else if (!src)
        {
            OE_WARN << "Warning: Layer \"" << layer->getName() << "\" could not create TileSource." << std::endl;
        }
        else if ( !src->supportsPersistentCaching() )
        {
            OE_WARN << "Warning: Layer \"" << layer->getName() << "\" does not support seeding." << std::endl;
        }
        else if ( !layer->getCache() )
        {
            OE_NOTICE << "Notice: Layer \"" << layer->getName() << "\" has no persistent cache defined; skipping." << std::endl;
        }
        else
        {
            hasCaches = true;

                        if (opt.minLevel().isSet() && opt.minLevel().get() < src_min_level)
                src_min_level = opt.minLevel().get();
                        if (opt.maxLevel().isSet() && opt.maxLevel().get() > src_max_level)
                src_max_level = opt.maxLevel().get();
        }
    }

    for( ElevationLayerVector::const_iterator i = mapf.elevationLayers().begin(); i != mapf.elevationLayers().end(); i++ )
    {
                ElevationLayer* layer = i->get();
        TileSource* src = i->get()->getTileSource();
        const ElevationLayerOptions& opt = layer->getElevationLayerOptions();

        if ( opt.cacheOnly().get())
        {
            OE_WARN << "Warning:  Cannot seed b/c Layer \"" << layer->getName() << "\" is cache only." << std::endl;
            return;
        }
        else if (!src)
        {
            OE_WARN << "Warning: Layer \"" << layer->getName() << "\" could not create TileSource." << std::endl;
        }
        else if ( !src->supportsPersistentCaching() )
        {
            OE_WARN << "Warning: Layer \"" << layer->getName() << "\" does not support seeding." << std::endl;
        }
        else if ( !layer->getCache() )
        {
            OE_NOTICE << "Notice: Layer \"" << src->getName() << "\" has no persistent cache defined; skipping." << std::endl;
        }
        else
        {
            hasCaches = true;

                        if (opt.minLevel().isSet() && opt.minLevel().get() < src_min_level)
                src_min_level = opt.minLevel().get();
                        if (opt.maxLevel().isSet() && opt.maxLevel().get() > src_max_level)
                src_max_level = opt.maxLevel().get();
                }
    }

    if (!hasCaches)
    {
        OE_NOTICE << "There are either no caches defined in the map, or no sources to cache. Exiting." << std::endl;
        return;
    }

    if ( src_max_level > 0 && src_max_level < _maxLevel )
    {
        _maxLevel = src_max_level;
    }

    OE_NOTICE << "Maximum cache level will be " << _maxLevel << std::endl;

    for (unsigned int i = 0; i < keys.size(); ++i)
    {
        processKey( mapf, keys[i] );
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void osgEarth::CacheSeed::setBounds ( const double &  minLon,
const double &  minLat,
const double &  maxLon,
const double &  maxLat 
) [inline]

Sets the bounds to seed in

Definition at line 74 of file CacheSeed.

{ _bounds = Bounds(minLon, minLat, maxLon, maxLat); }
void osgEarth::CacheSeed::setBounds ( const Bounds bounds) [inline]

Sets the bounds to seed in

Definition at line 69 of file CacheSeed.

{ _bounds = bounds; }

Here is the caller graph for this function:

void osgEarth::CacheSeed::setMaxLevel ( const unsigned int &  maxLevel) [inline]

Sets the maximum level to seed to

Definition at line 54 of file CacheSeed.

{_maxLevel = maxLevel;}

Here is the caller graph for this function:

void osgEarth::CacheSeed::setMinLevel ( const unsigned int &  minLevel) [inline]

Sets the minimum level to seed to

Definition at line 44 of file CacheSeed.

{_minLevel = minLevel;}

Here is the caller graph for this function:

void osgEarth::CacheSeed::setProgressCallback ( osgEarth::ProgressCallback progress) [inline]

Set progress callback for reporting which tiles are seeded

Definition at line 79 of file CacheSeed.

{ _progress = progress? progress : new ProgressCallback; }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 89 of file CacheSeed.

unsigned int osgEarth::CacheSeed::_maxLevel [protected]

Definition at line 88 of file CacheSeed.

unsigned int osgEarth::CacheSeed::_minLevel [protected]

Definition at line 87 of file CacheSeed.

Definition at line 90 of file CacheSeed.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines