|
osgEarth 2.1.1
|
Inheritance diagram for osgEarth::Features::AltitudeFilter:
Collaboration diagram for osgEarth::Features::AltitudeFilter: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 |
Feature filter that will clamp incoming feature geometry to an elevation model.
Definition at line 34 of file AltitudeFilter.
| AltitudeFilter::AltitudeFilter | ( | ) |
Constructs a new clamping filter
Definition at line 31 of file AltitudeFilter.cpp.
: _maxRes ( 0.0f ) { //NOP }
| 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:osg::ref_ptr<const AltitudeSymbol> osgEarth::Features::AltitudeFilter::_altitude [protected] |
Definition at line 53 of file AltitudeFilter.
double osgEarth::Features::AltitudeFilter::_maxRes [protected] |
Definition at line 54 of file AltitudeFilter.
std::string osgEarth::Features::AltitudeFilter::_maxZAttr [protected] |
Definition at line 55 of file AltitudeFilter.
std::string osgEarth::Features::AltitudeFilter::_minZAttr [protected] |
Definition at line 55 of file AltitudeFilter.
std::string osgEarth::Features::AltitudeFilter::_terrainZAttr [protected] |
Definition at line 55 of file AltitudeFilter.
1.7.3