osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarthDrivers/engine_droam/MeshManager

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_DROAM_ENGINE_MESH_MANAGER_H
00020 #define OSGEARTH_DROAM_ENGINE_MESH_MANAGER_H 1
00021 
00022 #include "Common"
00023 #include "Diamond"
00024 #include "Manifold"
00025 #include "AMRGeometry"
00026 #include <osgEarth/Map>
00027 #include <osgEarth/TaskService>
00028 #include <osg/Geode>
00029 #include <osg/Geometry>
00030 #include <queue>
00031 #include <deque>
00032 #include <list>
00033 #include <set>
00034 
00035 using namespace osgEarth;
00036 
00037 
00038 typedef std::queue< osg::ref_ptr<Diamond> > DiamondQueue;
00039 
00040 struct DiamondJob {
00041     DiamondJob( Diamond* d, float priority ) : _d(d), _priority(priority) { }
00042     bool operator < ( const DiamondJob& rhs ) const { return _priority < rhs._priority; }
00043     osg::ref_ptr<Diamond> _d;
00044     float _priority;
00045 };
00046 
00047 typedef std::queue<DiamondJob> DiamondJobQueue;
00048 typedef std::deque<DiamondJob> DiamondJobQDeque;
00049 typedef std::priority_queue<
00050     DiamondJob, 
00051     DiamondJobQDeque, 
00052     std::less<DiamondJobQDeque::value_type> > DiamondPriorityQueue;
00053 
00054 struct DiamondJobComparator {
00055     bool operator()( const DiamondJob& lhs, const DiamondJob& rhs ) {
00056         return lhs._priority < rhs._priority; }
00057 };
00058 
00059 typedef std::set<DiamondJob,DiamondJobComparator> DiamondJobOrderedSet;
00060 typedef std::list<DiamondJob> DiamondJobList;
00061 
00062 struct CullSettings 
00063 {
00064     CullSettings() : _maxRange( 2.0f ), _maxDeviation( 0.0 ) { }
00065     float _maxRange;
00066     float _maxDeviation;
00067 };
00068 
00069 class MeshManager : public osg::Referenced
00070 {
00071 public:
00073     MeshManager( Manifold* manifold, Map* map );
00074 
00075 public:
00077     NodeIndex addNode( const osg::Vec3d& manifoldCoord );
00078     NodeIndex addNode( const MeshNode& node );
00079 
00081     void removeNode( NodeIndex index );
00082 
00084     void queueForRefresh( Diamond* d );
00085 
00087     void queueForSplit( Diamond* d, float priority );
00088 
00090     void queueForMerge( Diamond* d, float priority );
00091 
00093     void queueForImage( Diamond* d, float priority );
00094 
00096     void update();
00097 
00099     inline const MeshNode& node( NodeIndex i ) { return _nodes[i]; }
00100     //inline const osg::Vec3f& vert( NodeIndex i ) { return _nodes[i]._vertex; }
00101     //inline const osg::Vec3d& coord( NodeIndex i ) { return _nodes[i]._manifoldCoord; }
00102     //inline const osg::Vec3f& normal( NodeIndex i ) { return _nodes[i]._normal; }
00103     //inline const osg::Vec3d& geoCoord( NodeIndex i ) { return _nodes[i]._geodeticCoord; }
00104 
00105 public:
00106     osg::ref_ptr<Manifold> _manifold;
00107     osg::ref_ptr<Map>      _map;
00108 
00109     DiamondQueue         _dirtyQueue;        // queue for primitive set refresh jobs
00110     DiamondPriorityQueue _splitQueue;        // queue for diamond split jobs
00111     DiamondPriorityQueue _mergeQueue;        // queue for diamond merge jobs
00112     DiamondJobList       _imageQueue;        // queue for texture loading jobs
00113 
00114     std::vector<MeshNode> _nodes;
00115     std::queue<NodeIndex> _freeList;
00116 
00117     // the minimum level that contains renderable geometry (i.e. the level of the 
00118     // first quadtree ancestor that will render its quadtree decendants).
00119     Level _minGeomLevel;
00120 
00121     // The minimum splittable level. This is the lowest level at which diamonds may be split
00122     // or merged. Only diamonds above this level may be removed.
00123     Level _minActiveLevel;
00124 
00125     // cannot split beyond this level.
00126     Level _maxActiveLevel;
00127 
00128     CullSettings _cullSettings;
00129     int _maxJobsPerFrame;
00130 
00131     osg::ref_ptr<TaskService> _imageService;  // service to load textures.
00132 
00133     osg::ref_ptr<osg::Geode>    _amrGeode;    // geode that hold the AMRGeometry
00134     osg::ref_ptr<AMRGeometry>   _amrGeom;     // virtual geometry node
00135     AMRDrawableList             _amrDrawList; // culling result
00136 };
00137 
00138 #endif // OSGEARTH_DROAM_ENGINE_MESH_MANAGER_H
00139 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines