osgEarth 2.1.1
Public Member Functions | Static Public Member Functions | Protected Attributes

osgEarth::Features::FeatureGridder Class Reference

Inheritance diagram for osgEarth::Features::FeatureGridder:
Collaboration diagram for osgEarth::Features::FeatureGridder:

List of all members.

Public Member Functions

 FeatureGridder (const Bounds &bounds, const GriddingPolicy &policy)
int getNumCells () const
bool getCellBounds (int i, Bounds &output) const
bool cullFeatureListToCell (int i, FeatureList &features) const
virtual ~FeatureGridder ()

Static Public Member Functions

static bool isSupported ()

Protected Attributes

Bounds _inputBounds
GriddingPolicy _policy
int _cellsX
int _cellsY
std::list< void * > _geosGeoms

Detailed Description

Given a list of features, this will grid them up and return one grid cell at a time. For each grid cell, it will crop the feature geometry to the cell boundary.

Definition at line 88 of file FeatureGridder.


Constructor & Destructor Documentation

FeatureGridder::FeatureGridder ( const Bounds bounds,
const GriddingPolicy policy 
)

Definition at line 87 of file FeatureGridder.cpp.

                                                              :
_inputBounds( inputBounds ),
_policy( policy )
{
    if ( _policy.enabled() ) //_policy.cellSize().isSet() && *_policy.cellSize() > 0.0 )
    {
        _cellsX = (int)::ceil(_inputBounds.width() / *_policy.cellSize() );
        _cellsY = (int)::ceil(_inputBounds.height() / *_policy.cellSize() );
    }
    else
    {
        _cellsX = 1;
        _cellsY = 1;
    }

    _cellsX = osg::clampAbove( _cellsX, 1 );
    _cellsY = osg::clampAbove( _cellsY, 1 );

#ifndef OSGEARTH_HAVE_GEOS

    if ( _policy.cullingTechnique().isSetTo( GriddingPolicy::CULL_BY_CROPPING ) )
    {
        OE_WARN 
            << "Warning: Gridding policy 'cull by cropping' requires GEOS. Falling back on 'cull by centroid'." 
            << std::endl;

        _policy.cullingTechnique() = GriddingPolicy::CULL_BY_CENTROID;
    }

#endif // !OSGEARTH_HAVE_GEOS
}

Here is the call graph for this function:

FeatureGridder::~FeatureGridder ( ) [virtual]

Definition at line 120 of file FeatureGridder.cpp.

{
    //nop
}

Member Function Documentation

bool FeatureGridder::cullFeatureListToCell ( int  i,
FeatureList features 
) const

Definition at line 151 of file FeatureGridder.cpp.

{
    bool success = true;
    int inCount = features.size();

    Bounds b;
    if ( getCellBounds( i, b ) )
    {
        if ( _policy.cullingTechnique() == GriddingPolicy::CULL_BY_CENTROID )
        {
            for( FeatureList::iterator f_i = features.begin(); f_i != features.end();  )
            {
                bool keepFeature = false;

                Feature* feature = f_i->get();
                Symbology::Geometry* featureGeom = feature->getGeometry();
                if ( featureGeom )
                {
                    osg::Vec3d centroid = featureGeom->getBounds().center();
                    if ( b.contains( centroid.x(), centroid.y() ) )
                    {
                        keepFeature = true;
                    }
                }

                if ( keepFeature )
                    ++f_i;
                else
                    f_i = features.erase( f_i );
            }
        }

        else // CULL_BY_CROPPING (requires GEOS)
        {

#ifdef OSGEARTH_HAVE_GEOS

            // create the intersection polygon:
            osg::ref_ptr<Symbology::Polygon> poly = new Symbology::Polygon( 4 );
            poly->push_back( osg::Vec3d( b.xMin(), b.yMin(), 0 ));
            poly->push_back( osg::Vec3d( b.xMax(), b.yMin(), 0 ));
            poly->push_back( osg::Vec3d( b.xMax(), b.yMax(), 0 ));
            poly->push_back( osg::Vec3d( b.xMin(), b.yMax(), 0 ));

            for( FeatureList::iterator f_i = features.begin(); f_i != features.end();  )
            {
                bool keepFeature = false;

                Feature* feature = f_i->get();
                Symbology::Geometry* featureGeom = feature->getGeometry();
                if ( featureGeom )
                {
                    osg::ref_ptr<Symbology::Geometry> croppedGeometry;
                    if ( featureGeom->crop( poly.get(), croppedGeometry ) )
                    {
                        feature->setGeometry( croppedGeometry.get() );
                        keepFeature = true;
                    }                   
                }

                if ( keepFeature )
                    ++f_i;
                else
                    f_i = features.erase( f_i );
            }  

#endif // OSGEARTH_HAVE_GEOS

        }

    }

    OE_INFO << LC
            << "Grid cell " << i << ": bounds="
            << b.xMin() << "," << b.yMin() << " => " << b.xMax() << "," << b.yMax()
            << "; in=" << inCount << "; out=" << features.size()
            << std::endl;

    return success;
}

Here is the call graph for this function:

bool FeatureGridder::getCellBounds ( int  i,
Bounds output 
) const

Definition at line 132 of file FeatureGridder.cpp.

{
    if ( i >= 0 && i < (_cellsX*_cellsY) )
    {
        int x = i % _cellsX;
        int y = i / _cellsX;

        double xmin = _inputBounds.xMin() + _policy.cellSize().value()  * (double)x;
        double ymin = _inputBounds.yMin() + _policy.cellSize().value() * (double)y;
        double xmax = osg::clampBelow( _inputBounds.xMin() + *_policy.cellSize() * (double)(x+1), _inputBounds.xMax() );
        double ymax = osg::clampBelow( _inputBounds.yMin() + *_policy.cellSize() * (double)(y+1), _inputBounds.yMax() );

        output = Bounds( xmin, ymin, xmax, ymax );
        return true;
    }
    return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int FeatureGridder::getNumCells ( ) const

Definition at line 126 of file FeatureGridder.cpp.

{
    return _cellsX * _cellsY;
}
static bool osgEarth::Features::FeatureGridder::isSupported ( ) [static]

Member Data Documentation

Definition at line 108 of file FeatureGridder.

Definition at line 108 of file FeatureGridder.

std::list<void*> osgEarth::Features::FeatureGridder::_geosGeoms [protected]

Definition at line 109 of file FeatureGridder.

Definition at line 106 of file FeatureGridder.

Definition at line 107 of file FeatureGridder.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines