/usr/include/osgEarthUtil/SpatialData is in libosgearth-dev 2.9.0+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | /* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
* Copyright 2016 Pelican Mapping
* http://osgearth.org
*
* osgEarth is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#ifndef OSGEARTHUTIL_SPATIAL_DATA
#define OSGEARTHUTIL_SPATIAL_DATA
#include <osgEarthUtil/Common>
#include <osgEarth/GeoData>
#include <osg/observer_ptr>
#include <osg/Geode>
#include <osg/Plane>
#include <osg/LOD>
#include <map>
namespace osgEarth { namespace Util
{
using namespace osgEarth;
class GeoObject;
//typedef std::vector< osg::ref_ptr<GeoObject> > GeoObjectVector;
typedef std::pair< float, osg::ref_ptr<GeoObject> > GeoObjectPair;
typedef std::multimap< float, osg::ref_ptr<GeoObject> > GeoObjectCollection;
/**
* A group corresponding to a specific geospatial cell.
*/
class OSGEARTHUTIL_EXPORT GeoCell : public osg::LOD
{
public:
GeoCell(
const GeoExtent& extent,
float maxRange,
unsigned maxOjbects,
unsigned splitDim,
float splitRangeFactor,
unsigned depth );
/** dtor */
virtual ~GeoCell() { }
/** Adds an object to this geocell graph. */
virtual bool insertObject( GeoObject* object );
/** Removes an object from this geocell graph. */
bool removeObject( GeoObject* object );
/** Re-index an object withing the geocell graph based on a new position. */
bool reindexObject( GeoObject* object );
/** The number of rows and columns into which this cell will split */
unsigned getSplitDimension() const { return _splitDim; }
/** The maximum number of objects this cell can hold before splitting */
unsigned getMaxObjects() const { return _maxObjects; }
/** Child cells have a maximum LOD range of this cell's max range times this factor. */
float getSplitRangeFactor() const { return _splitRangeFactor; }
/** the extent of this cell */
const GeoExtent& getExtent() const { return _extent; }
/** gets the frame number of the last time this cell passed cull */
unsigned getLastCullFrame() const { return _frameStamp; }
public: // osg::LOD overrides
virtual osg::BoundingSphere computeBound() const;
virtual void traverse( osg::NodeVisitor& nv );
protected:
GeoExtent _extent;
unsigned _splitDim;
unsigned _maxObjects; // maximum # of objects to render in this cell before splitting.
unsigned _minObjects; // minimum # of objects to drop below before pulling up
float _maxRange; // maximum visibility range of this cell.
float _splitRangeFactor; // child range = cell range * factor
unsigned _count; // # of objects in this cell (including all children)
unsigned _depth;
unsigned _frameStamp; // last fram this cell was visited by CULL
void split();
void merge();
void adjustCount( int delta );
void generateBoundaries();
void generateBoundaryGeometry();
std::vector<osg::Vec3d> _boundaryPoints;
// priority-order collection of objects
GeoObjectCollection _objects;
osg::ref_ptr<osg::Geode> _clusterGeode;
osg::ref_ptr<osg::Geode> _boundaryGeode;
osg::Vec4Array* _boundaryColor;
friend class GeoCellVisitor;
};
class OSGEARTHUTIL_EXPORT GeoGraph : public GeoCell
{
public:
GeoGraph(
const GeoExtent& extent,
float maxRange,
unsigned maxObjects =500,
unsigned splitDim =2,
float splitRangeFactor =0.5f,
unsigned rootWidth =2,
unsigned rootHeight =2 );
/** dtor */
virtual ~GeoGraph() { }
bool insertObject( GeoObject* object );
private:
unsigned _rootWidth, _rootHeight;
};
class GeoCellVisitor : public osg::NodeVisitor
{
public:
GeoCellVisitor() : osg::NodeVisitor( osg::NodeVisitor::TRAVERSE_ALL_CHILDREN ) { }
virtual ~GeoCellVisitor() { }
virtual void operator()( const GeoCell* cell, const GeoObjectCollection& objects ) =0;
void apply( osg::LOD& node ) {
const GeoCell* cell = static_cast<const GeoCell*>(&node);
if ( cell->_depth > 0 )
this->operator()( cell, cell->_objects );
traverse( node );
}
};
/**
* Base class for an object indexed by a GeoCell hierarchy.
*/
class OSGEARTHUTIL_EXPORT GeoObject : public osg::Referenced
{
public:
/**
* Outputs the location (for spatial indexing), which must be in the same
* SRS as the GeoGraph.
*/
virtual bool getLocation( osg::Vec3d& output ) const =0;
/** The priority of the object relative to other objects */
virtual float getPriority() const { return 0.0; }
/** Gets the node to render for this object. */
virtual osg::Node* getNode() const =0;
/** The cell currently holding this object. */
GeoCell* getGeoCell() const { return _cell.get(); }
protected:
GeoObject();
virtual ~GeoObject() { }
osg::observer_ptr<GeoCell> _cell;
float _priority;
friend class GeoCell;
};
} } // namespace osgEarth::Util
#endif // OSGEARTHUTIL_SPATIAL_DATA
|