osgEarth 2.1.1

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

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_ENGINE_NODE_H
00020 #define OSGEARTH_ENGINE_OSGTERRAIN_ENGINE_NODE_H 1
00021 
00022 #include <osgEarth/TerrainEngineNode>
00023 #include <osgEarth/TextureCompositor>
00024 #include <osgEarth/Map>
00025 #include <osgEarth/Revisioning>
00026 #include <osgEarth/TaskService>
00027 
00028 #include "OSGTerrainOptions"
00029 #include "OSGTileFactory"
00030 #include "KeyNodeFactory"
00031 #include "TileBuilder"
00032 
00033 #include <osg/Geode>
00034 #include <osg/NodeCallback>
00035 
00036 using namespace osgEarth;
00037 
00038 class OSGTerrainEngineNode : public TerrainEngineNode
00039 {
00040 public:
00041     OSGTerrainEngineNode();
00042     OSGTerrainEngineNode( const OSGTerrainEngineNode& rhs, const osg::CopyOp& op =osg::CopyOp::DEEP_COPY_ALL );
00043     META_Node(osgEarth,OSGTerrainEngineNode);
00044     ~OSGTerrainEngineNode();
00045 
00046 public:
00047     osg::Node* createNode(const TileKey& key);
00048 
00049 public: // TerrainEngineNode overrides    
00050     virtual void preInitialize( const Map* map, const TerrainOptions& options );
00051     virtual void postInitialize( const Map* map, const TerrainOptions& options );
00052     virtual void validateTerrainOptions( TerrainOptions& options );
00053     virtual const TerrainOptions& getTerrainOptions() const { return _terrainOptions; }
00054     virtual void traverse( osg::NodeVisitor& );
00055     virtual osg::BoundingSphere computeBound() const;
00056 
00057 public: // MapCallback adapter functions
00058     void onMapInfoEstablished( const MapInfo& mapInfo ); // not virtual!
00059     void onMapModelChanged( const MapModelChange& change ); // not virtual!
00060 
00061     UID getUID() const;
00062     OSGTileFactory* getTileFactory() const { return _tileFactory.get(); }
00063     class Terrain* getTerrain() const { return _terrain; }
00064 
00065 public: // statics    
00066     static void registerEngine( OSGTerrainEngineNode* engineNode );
00067     static void unregisterEngine( UID uid );
00068     static void getEngineByUID( UID uid, osg::ref_ptr<OSGTerrainEngineNode>& output );
00069 
00070 private:
00071     void init();
00072     void syncMapModel();
00073 
00074     void addImageLayer( ImageLayer* layer );
00075     void addElevationLayer( ElevationLayer* layer );
00076 
00077     void removeImageLayer( ImageLayer* layerRemoved );
00078     void removeElevationLayer( ElevationLayer* layerRemoved );
00079 
00080     void moveImageLayer( unsigned int oldIndex, unsigned int newIndex );
00081     void moveElevationLayer( unsigned int oldIndex, unsigned int newIndex );
00082     
00083     void updateElevation( Tile* tile );
00084     void installShaders();
00085     void updateTextureCombining();
00086 
00087 private:
00088     osg::ref_ptr<OSGTileFactory>         _tileFactory;
00089     //class CustomTerrain* _terrain;
00090     class Terrain*               _terrain;
00091     UID                                  _uid;
00092     osgEarth::Drivers::OSGTerrainOptions _terrainOptions;
00093     Revision                             _shaderLibRev;
00094     osg::ref_ptr<TaskServiceManager>     _taskServiceMgr;
00095 
00096     // store a separate map frame for each of the traversal threads
00097     MapFrame* _update_mapf; // map frame for the main/update traversal thread
00098     MapFrame* _cull_mapf;   // map frame for the cull traversal thread
00099 
00100     osg::ref_ptr<TaskService>    _tileService;
00101     osg::ref_ptr<KeyNodeFactory> _keyNodeFactory;
00102     osg::ref_ptr<TileBuilder>    _tileBuilder;
00103 
00104     osg::Timer _timer;
00105     unsigned   _tileCount;
00106     double     _tileCreationTime;
00107     bool       _isStreaming;
00108 };
00109 
00110 #endif // OSGEARTH_ENGINE_OSGTERRAIN_ENGINE_NODE_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines