osgEarth 2.1.1

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

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_DIAMOND_H
00020 #define OSGEARTH_DROAM_ENGINE_DIAMOND_H 1
00021 
00022 #include "Common"
00023 #include "AMRGeometry"
00024 #include <osgEarth/Revisioning>
00025 #include <osgEarth/TileKey>
00026 #include <osgEarth/TaskService>
00027 #include <osg/Geometry>
00028 
00029 class MeshManager;
00030 
00031 // ancestor incidies (counter-clockwise from the bottom)
00032 enum DiamondAncestor {
00033     QUADTREE = 0, // bottom of the diamond (also the quadtree ancestor)
00034     PARENT_R = 1, // right parent
00035     GDPARENT = 2, // top of the diamond
00036     PARENT_L = 3  // left parent
00037 };
00038 
00039 enum DiamondStatus {
00040     ACTIVE   = 0, // diamond is active in the mesh
00041     INACTIVE = 1  // diamond is idle or has been flagged for deletion
00042 };
00043 
00044 // diamond's orientation. 0 is "up".
00045 typedef unsigned short Orientation;
00046 
00047 struct RevisionedStateSet : public osgEarth::Revisioned<osg::StateSet>
00048 {
00049 };
00050 
00057 struct Diamond : osg::Referenced
00058 {
00059     Diamond( MeshManager* mesh, const osgEarth::TileKey& key, Level level, const std::string& name ="" );
00060     ~Diamond();
00061 
00062     void activate();                    // call after the diamond is entirely initialized.
00063 
00064     osgEarth::TileKey _key;             // tile key corresponding to this diamond (geom diamonds only)
00065     std::string _name;                  // name of this diamond (for debugging only-- remove later)
00066     Level _level;                       // subdivision level
00067     Orientation _orientation;           // orientation of the diamond
00068     DiamondStatus _status;              // whether this diamond is active or has been removed
00069     MeshManager* _mesh;                 // the mesh under which this diamond exists
00070     osg::ref_ptr<Diamond> _a[4];        // 4 ancestors (use Ancestor enum as indicies)
00071     osg::ref_ptr<Diamond> _c[4];        // immediate children (clockwise from bottom-right)
00072     unsigned short _childValence;       // number of slots for children (always 4, except 3 at level 0)
00073     bool _isSplit;                      // is this diamond split? (i.e. can it create children?)
00074     bool _hasGeometry;                  // whether this is a geometry diamond (i.e. odd-numbered level)
00075     NodeIndex _vi;                      // index of this diamond's vertex/normal in the master vbos
00076     TravNumber _lastCullFrame;          // frame number of last cull pass
00077     bool _drawableDirty;                // marks this diamond's primitive set as needing a refresh.
00078     bool _queuedForSplit;               // whether this diamond is in the split queue.
00079     bool _queuedForMerge;               // whether this diamond is in the merge queue.
00080     bool _queuedForImage;               // whether this diamond is in the image queue.
00081     bool _bsComputed;                   // whether _bs has been computed yet
00082     bool _imageRequested;               // whether the texture image has been submitted to the task service
00083     osg::ref_ptr<RevisionedStateSet> _stateSet; // stateset for this diamond level
00084     osg::ref_ptr<AMRDrawable> _amrDrawable;     // primitive draw list
00085     Diamond* _targetStateSetOwner;      // Diamond that owns the stateset we ultimately want to use
00086     Diamond* _currentStateSetOwner;     // Diamond that owns the stateset we are currently using
00087     osgEarth::Revision _targetStateSetRevision;   // Revision of the stateset we are rendering with
00088     bool _hasFinalImage;                // whether the final texture has been loaded into the stateset.
00089     
00090     osg::BoundingSphere _visibleBound;  // this diamond's visible extent (for drawing)
00091     const osg::BoundingSphere& visibleBound() const;
00092 
00093     osg::BoundingSphere _extendedBound; // this diamond's extended extent (for split/merge determination)  
00094     const osg::BoundingSphere& extendedBound() const;
00095 
00096     osg::ref_ptr<osgEarth::TaskRequest> _imageRequest;
00097 
00098 
00099 
00101     void dump();
00102 
00104     void setCoord( double x, double y, double z ) { setCoord( osg::Vec3d(x,y,z) ); }
00105     void setCoord( const osg::Vec3d& coord );
00106 
00108     Diamond* getOrCreateNeighbor( ChildIndex c );
00109 
00111     Diamond* getNeighbor( ChildIndex c );
00112 
00114     Diamond* getOrCreateChild( ChildIndex c );
00115 
00117     void removeChild( ChildIndex c );
00118 
00121     ChildIndex getIndexOfChild( Diamond* child );
00122 
00124     ChildIndex getIndexOfChildEdgeStartingAt( NodeIndex vi );
00125 
00127     void seed( Level maxLevel );
00128 
00130     void split();
00131 
00133     void merge();
00134 
00136     bool hasChildren() const;
00137 
00139     bool hasAllChildren() const;
00140 
00142     void computeBound();
00143 
00145     unsigned int cull( osgUtil::CullVisitor* cv );
00146 
00148     void setChild( ChildIndex index, Diamond* child );
00149 
00151     void refreshDrawable();
00152 
00154     void dirty();
00155 
00157     inline Diamond* q(ChildIndex c) {
00158         ChildIndex c2 = c == 0 || c == 2 ? 1 : 3;
00159         return _c[c].valid() ? _c[c]->_c[c2].get() : 0L;
00160     }
00161 
00162     //const osg::Vec3f& vert() const; // { return _mesh->v(_vi); }
00163     //const osg::Vec3d& coord() const;
00164     //const osg::Vec3f& normal() const;
00165     //const osg::Vec3d& geoCoord() const;
00166     const MeshNode& node() const;
00167 
00168     //void releaseGLObjects();
00169 };
00170 
00171 #endif // OSGEARTH_DROAM_ENGINE_DIAMOND_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines