osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarthDrivers/engine_osgterrain/StreamingTile

Go to the documentation of this file.
00001 /* -*-c++-*- */
00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
00003 * Copyright 2008-2010 Pelican Mapping
00004 * http://osgearth.org
00005 *
00006 * osgEarth is free software; you can redistribute it and/or modify
00007 * it under the terms of the GNU Lesser General Public License as published by
00008 * the Free Software Foundation; either version 2 of the License, or
00009 * (at your option) any later version.
00010 *
00011 * This program is distributed in the hope that it will be useful,
00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 * GNU Lesser General Public License for more details.
00015 *
00016 * You should have received a copy of the GNU Lesser General Public License
00017 * along with this program.  If not, see <http://www.gnu.org/licenses/>
00018 */
00019 #ifndef OSGEARTH_ENGINE_OSGTERRAIN_STREAMING_TILE
00020 #define OSGEARTH_ENGINE_OSGTERRAIN_STREAMING_TILE 1
00021 
00022 #include "Tile"
00023 #include <osgEarth/TaskService>
00024 
00025 class TileFactory;
00026 class StreamingTerrain;
00027 
00028 using namespace osgEarth;
00029 
00030 //------------------------------------------------------------------------
00031 
00032 class StreamingTile : public Tile
00033 {
00034 public:
00035     // Please refer the StreamingTerrain::refreshFamily() method for more info on this structure.
00036     struct Relative
00037     {
00038         int getImageLOD(unsigned int layerID)
00039         {
00040             LayerIDtoLODMap::iterator itr = imageLODs.find(layerID);
00041             if (itr != imageLODs.end()) return itr->second;
00042             return -1;
00043         }
00044         
00045         typedef std::map<unsigned int, int> LayerIDtoLODMap;
00046 
00047         bool               expected;
00048         int                elevLOD;
00049         LayerIDtoLODMap    imageLODs;
00050         osgTerrain::TileID tileID;
00051 
00052         enum Direction {
00053             PARENT =0,
00054             WEST   =1,
00055             NORTH  =2,
00056             EAST   =3,
00057             SOUTH  =4
00058         };
00059 
00060         Relative() { }
00061     };
00062 
00063 public:
00064     StreamingTile( const TileKey& key, GeoLocator* keyLocator, bool quickReleaseGLObjects );
00065 
00066     virtual const char* libraryName() const { return "osgEarth"; }
00067     virtual const char* className() const { return "StreamingTile"; }
00068 
00069     // Updates and services this tile's image request tasks
00070     void servicePendingImageRequests( const MapFrame& mapf, int stamp );
00071 
00072     // Updates and services this tile's heightfield request tasks
00073     void servicePendingElevationRequests( const MapFrame& mapf, int stamp, bool tileTableLocked );
00074 
00075     // returns TRUE if the tile was modified as a result of a completed request.
00076     bool serviceCompletedRequests( const MapFrame& mapf, bool tileTableLocked );
00077 
00079     void setHasElevationHint( bool hasElevation );
00080 
00082     bool isElevationLayerUpToDate() const { return _elevationLayerUpToDate; }
00083 
00085     int getElevationLOD() const { return _elevationLOD; }
00086     void setElevationLOD( int lod );
00087 
00089     class StreamingTerrain* getStreamingTerrain();
00090     const class StreamingTerrain* getStreamingTerrain() const;
00091 
00092     // updates one image layer
00093     void updateImagery( ImageLayer* layer, const MapFrame& mapf, OSGTileFactory* factory );
00094 
00095     // are we using a task service for tile generation?
00096     bool getUseTileGenRequest() const { return _useTileGenRequest; }
00097 
00098     // gets this tile's relatives
00099     Relative* getFamily() { return _family; }
00100 
00101     // marks a request to regenerate the tile based on the specified change(s).
00102     void queueTileUpdate( TileUpdate::Action action, int index =-1 );
00103     
00104     void applyImmediateTileUpdate( TileUpdate::Action action, int index =-1 );
00105 
00106     // marks any pending or running requests for cancelation, and returns true if they
00107     // are all canceled.
00108     virtual bool cancelActiveTasks(); //override
00109 
00110     void resetElevationRequests( const MapFrame& mapf );
00111 
00112 protected:
00113 
00114     ~StreamingTile();
00115 
00116 private:
00117 
00118     bool _requestsInstalled;
00119     bool _hasElevation;
00120     bool _elevationLayerDirty;
00121     bool _colorLayersDirty;
00122     bool _elevationLayerRequested;
00123     bool _elevationLayerUpToDate;
00124     int  _elevationLOD;
00125     bool _useTileGenRequest;
00126     bool _sequentialImagery;
00127 
00128     typedef std::queue<TileUpdate> TileUpdateQueue;
00129     TileUpdateQueue _tileUpdates;
00130 
00131     TaskRequestList _requests;
00132     osg::ref_ptr<TaskRequest> _elevRequest;
00133     osg::ref_ptr<TaskRequest> _elevPlaceholderRequest;
00134     osg::ref_ptr<TaskRequest> _tileGenRequest;
00135 
00136     Relative _family[5];
00137 
00139     void installRequests( const MapFrame& mapf, int stamp );
00140     bool readyForNewElevation();
00141     bool readyForNewImagery(osgEarth::ImageLayer* layer, int currentLOD);
00142 };
00143 
00144 
00145 #endif // OSGEARTH_ENGINE_OSGTERRAIN_STREAMING_TILE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines