osgEarth 2.1.1
Public Member Functions | Protected Attributes

osgEarth::Features::AltitudeFilter Class Reference

Inheritance diagram for osgEarth::Features::AltitudeFilter:
Collaboration diagram for osgEarth::Features::AltitudeFilter:

List of all members.

Public Member Functions

 AltitudeFilter ()
void setPropertiesFromStyle (const Style &style)
void setMaxResolution (double value)
double getMaxResolution () const
virtual FilterContext push (FeatureList &input, FilterContext &cx)

Protected Attributes

osg::ref_ptr< const
AltitudeSymbol
_altitude
double _maxRes
std::string _maxZAttr
std::string _minZAttr
std::string _terrainZAttr

Detailed Description

Feature filter that will clamp incoming feature geometry to an elevation model.

Definition at line 34 of file AltitudeFilter.


Constructor & Destructor Documentation

AltitudeFilter::AltitudeFilter ( )

Constructs a new clamping filter

Definition at line 31 of file AltitudeFilter.cpp.

                               :
_maxRes ( 0.0f )
{
    //NOP
}

Member Function Documentation

double osgEarth::Features::AltitudeFilter::getMaxResolution ( ) const [inline]

Definition at line 47 of file AltitudeFilter.

{ return _maxRes; }
FilterContext AltitudeFilter::push ( FeatureList input,
FilterContext cx 
) [virtual]

Implements osgEarth::Features::FeatureFilter.

Definition at line 48 of file AltitudeFilter.cpp.

{
    const Session* session = cx.getSession();
    if ( !session ) {
        OE_WARN << LC << "No session - session is required for elevation clamping" << std::endl;
        return cx;
    }

    // the map against which we'll be doing elevation clamping
    MapFrame mapf = session->createMapFrame( Map::ELEVATION_LAYERS );

    const SpatialReference* mapSRS     = mapf.getProfile()->getSRS();
    const SpatialReference* featureSRS = cx.profile()->getSRS();

    // establish an elevation query interface based on the features' SRS.
    ElevationQuery eq( mapf );

    NumericExpression scaleExpr;
    if ( _altitude.valid() && _altitude->verticalScale().isSet() )
        scaleExpr = *_altitude->verticalScale();

    NumericExpression offsetExpr;
    if ( _altitude.valid() && _altitude->verticalOffset().isSet() )
        offsetExpr = *_altitude->verticalOffset();

    bool clamp =
        _altitude->clamping() != AltitudeSymbol::CLAMP_NONE;

    // whether to record a "minimum terrain" value
    bool collectHATs =
        _altitude->clamping() == AltitudeSymbol::CLAMP_RELATIVE_TO_TERRAIN ||
        _altitude->clamping() == AltitudeSymbol::CLAMP_ABSOLUTE;

    for( FeatureList::iterator i = features.begin(); i != features.end(); ++i )
    {
        Feature* feature = i->get();
        double maxGeomZ     = -DBL_MAX;
        double minGeomZ     =  DBL_MAX;
        double maxTerrainZ  = -DBL_MAX;
        double minTerrainZ  =  DBL_MAX;
        double minHAT       =  DBL_MAX;
        double maxHAT       = -DBL_MAX;

        double scaleZ = 1.0;
        if ( _altitude.valid() && _altitude->verticalScale().isSet() )
            scaleZ = feature->eval( scaleExpr );

        double offsetZ = 0.0;
        if ( _altitude.valid() && _altitude->verticalOffset().isSet() )
            offsetZ = feature->eval( offsetExpr );
        
        GeometryIterator gi( feature->getGeometry() );
        while( gi.hasMore() )
        {
            Geometry* geom = gi.next();

            // clamps the entire array to the terrain using the specified resolution.
            if ( clamp )
            {
                if ( collectHATs )
                {
                    std::vector<double> elevations;
                    elevations.reserve( geom->size() );
                    eq.getElevations( geom->asVector(), featureSRS, elevations, _maxRes );
                    for( unsigned i=0; i<geom->size(); ++i )
                    {
                        double z = (*geom)[i].z() * scaleZ + offsetZ;
                        double hat =
                            _altitude->clamping() == AltitudeSymbol::CLAMP_ABSOLUTE ? z - elevations[i] :
                            z;

                        if ( hat > maxHAT )
                            maxHAT = hat;
                        if ( hat < minHAT )
                            minHAT = hat;

                        double elev = elevations[i];
                        if ( elev > maxTerrainZ )
                            maxTerrainZ = elev;
                        if ( elev < minTerrainZ )
                            minTerrainZ = elev;

                        (*geom)[i].z() =
                            _altitude->clamping() == AltitudeSymbol::CLAMP_ABSOLUTE ? z :
                            z + elevations[i];
                    }
                }
                else
                {
                    eq.getElevations( geom->asVector(), featureSRS, true, _maxRes );
                }
            }

            for( Geometry::iterator i = geom->begin(); i != geom->end(); ++i )
            {
                if ( !collectHATs )
                {
                    i->z() *= scaleZ;
                    i->z() += offsetZ;
                }

                if ( i->z() > maxGeomZ )
                    maxGeomZ = i->z();
                if ( i->z() < minGeomZ )
                    minGeomZ = i->z();
            }
        }

        if ( minHAT != DBL_MAX )
        {
            feature->set( "__min_hat", minHAT );
            feature->set( "__max_hat", maxHAT );
        }

        if ( minGeomZ != DBL_MAX )
        {
            feature->set( "__min_geom_z", minGeomZ );
            feature->set( "__max_geom_z", maxGeomZ );
        }

        if ( minTerrainZ != DBL_MAX )
        {
            feature->set( "__min_terrain_z", minTerrainZ );
            feature->set( "__max_terrain_z", maxTerrainZ );
        }
    }

    return cx;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void osgEarth::Features::AltitudeFilter::setMaxResolution ( double  value) [inline]

Maximum terrain resolution to consider when clamping

Definition at line 46 of file AltitudeFilter.

{ _maxRes = value; }

Here is the caller graph for this function:

void AltitudeFilter::setPropertiesFromStyle ( const Style style)

Shortcut to set any properties that are represented in a style.

Definition at line 38 of file AltitudeFilter.cpp.

{
    _altitude = style.get<AltitudeSymbol>();
    if ( _altitude )
    {
        setMaxResolution( *_altitude->clampingResolution() );
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 53 of file AltitudeFilter.

Definition at line 54 of file AltitudeFilter.

Definition at line 55 of file AltitudeFilter.

Definition at line 55 of file AltitudeFilter.

Definition at line 55 of file AltitudeFilter.


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