osgEarth 2.1.1
|
Public Member Functions | |
FeatureTileSource (const TileSourceOptions &options=TileSourceOptions()) | |
virtual void | initialize (const std::string &referenceURI, const Profile *overrideProfile=NULL) |
virtual osg::Image * | createImage (const TileKey &key, ProgressCallback *progress) |
FeatureSource * | getFeatureSource () |
void | setFeatureSource (FeatureSource *source) |
virtual osg::Object * | cloneType () const |
virtual osg::Object * | clone (const osg::CopyOp &) const |
virtual bool | isSameKindAs (const osg::Object *obj) const |
virtual const char * | className () const |
virtual const char * | libraryName () const |
Protected Member Functions | |
virtual osg::Referenced * | createBuildData () |
virtual bool | renderFeaturesForStyle (const Style &style, const FeatureList &features, osg::Referenced *buildData, const GeoExtent &imageExtent, osg::Image *out_image) |
virtual bool | preProcess (osg::Image *image, osg::Referenced *buildData) |
virtual bool | postProcess (osg::Image *image, osg::Referenced *buildData) |
virtual | ~FeatureTileSource () |
bool | queryAndRenderFeaturesForStyle (const Style &style, const Query &query, osg::Referenced *data, const GeoExtent &imageExtent, osg::Image *out_image) |
Protected Attributes | |
osg::ref_ptr< FeatureSource > | _features |
const FeatureTileSourceOptions | _options |
osg::ref_ptr< const osgEarth::Map > | _map |
bool | _initialized |
A TileSource that renders Feature data from a FeatureSource. An implementation of this base class will render image or heightfield tiles from feature data.
Definition at line 78 of file FeatureTileSource.
FeatureTileSource::FeatureTileSource | ( | const TileSourceOptions & | options = TileSourceOptions() | ) |
Constructs a new feature tile source with the provided options.
Definition at line 86 of file FeatureTileSource.cpp.
: TileSource( options ), _options( options.getConfig() ), _initialized( false ) { if ( _options.featureSource().valid() ) { _features = _options.featureSource().get(); } else if ( _options.featureOptions().isSet() ) { _features = FeatureSourceFactory::create( _options.featureOptions().value() ); if ( !_features.valid() ) { OE_WARN << LC << "Failed to create FeatureSource from options" << std::endl; } } }
virtual osgEarth::Features::FeatureTileSource::~FeatureTileSource | ( | ) | [inline, protected, virtual] |
DTOR is protected to prevent this object from being allocated on the stack
Definition at line 157 of file FeatureTileSource.
{ }
virtual const char* osgEarth::Features::FeatureTileSource::className | ( | ) | const [inline, virtual] |
Reimplemented from osgEarth::TileSource.
Definition at line 151 of file FeatureTileSource.
{ return "FeatureTileSource"; }
virtual osg::Object* osgEarth::Features::FeatureTileSource::clone | ( | const osg::CopyOp & | ) | const [inline, virtual] |
Reimplemented from osgEarth::TileSource.
Definition at line 149 of file FeatureTileSource.
{ return 0; } // clone() not appropriate
virtual osg::Object* osgEarth::Features::FeatureTileSource::cloneType | ( | ) | const [inline, virtual] |
Reimplemented from osgEarth::TileSource.
Definition at line 148 of file FeatureTileSource.
{ return 0; } // cloneType() not appropriate
virtual osg::Referenced* osgEarth::Features::FeatureTileSource::createBuildData | ( | ) | [inline, protected, virtual] |
Creates an implementation-specific data object to be passed to buildNodeForStyle
Reimplemented in AGGLiteRasterizerTileSource.
Definition at line 105 of file FeatureTileSource.
{ return NULL; }
osg::Image * FeatureTileSource::createImage | ( | const TileKey & | key, |
ProgressCallback * | progress | ||
) | [virtual] |
Creates an image for the given TileKey. The returned object is new and is the responsibility of the caller.
Implements osgEarth::TileSource.
Definition at line 155 of file FeatureTileSource.cpp.
{ if ( !_features.valid() || !_features->getFeatureProfile() ) return 0L; // style data const StyleSheet* styles = _options.styles(); // implementation-specific data osg::ref_ptr<osg::Referenced> buildData = createBuildData(); // allocate the image. osg::ref_ptr<osg::Image> image = new osg::Image(); image->allocateImage( getPixelsPerTile(), getPixelsPerTile(), 1, GL_RGBA, GL_UNSIGNED_BYTE ); preProcess( image.get(), buildData.get() ); // figure out if and how to style the geometry. if ( _features->hasEmbeddedStyles() ) { // Each feature has its own embedded style data, so use that: osg::ref_ptr<FeatureCursor> cursor = _features->createFeatureCursor( Query() ); while( cursor->hasMore() ) { Feature* feature = cursor->nextFeature(); if ( feature ) { FeatureList list; list.push_back( feature ); renderFeaturesForStyle( *feature->style(), list, buildData.get(), key.getExtent(), image.get() ); } } } else if ( styles ) { if ( styles->selectors().size() > 0 ) { for( StyleSelectorList::const_iterator i = styles->selectors().begin(); i != styles->selectors().end(); ++i ) { const StyleSelector& sel = *i; const Style* style = styles->getStyle( sel.getSelectedStyleName() ); queryAndRenderFeaturesForStyle( *style, sel.query().value(), buildData.get(), key.getExtent(), image.get() ); } } else { const Style* style = styles->getDefaultStyle(); queryAndRenderFeaturesForStyle( *style, Query(), buildData.get(), key.getExtent(), image.get() ); } } else { queryAndRenderFeaturesForStyle( Style(), Query(), buildData.get(), key.getExtent(), image.get() ); } // final tile processing after all styles are done postProcess( image.get(), buildData.get() ); return image.release(); }
FeatureSource* osgEarth::Features::FeatureTileSource::getFeatureSource | ( | ) | [inline] |
The underlying feature source.
Definition at line 95 of file FeatureTileSource.
{ return _features.get(); }
void FeatureTileSource::initialize | ( | const std::string & | referenceURI, |
const Profile * | overrideProfile = NULL |
||
) | [virtual] |
Initialize the TileSource. The profile should be computed and set here using setProfile()
Implements osgEarth::TileSource.
Definition at line 106 of file FeatureTileSource.cpp.
{ if (overrideProfile) { //If we were given a profile, take it on. setProfile(overrideProfile); } else { //Assume it is global-geodetic setProfile( osgEarth::Registry::instance()->getGlobalGeodeticProfile() ); } if ( _features.valid() ) { _features->initialize( referenceURI ); #if 0 // removed this as it was screwing up the rasterizer (agglite plugin).. not sure there's any reason to do this anyway if (_features->getFeatureProfile()) { setProfile( Profile::create(_features->getFeatureProfile()->getSRS(), _features->getFeatureProfile()->getExtent().xMin(), _features->getFeatureProfile()->getExtent().yMin(), _features->getFeatureProfile()->getExtent().xMax(), _features->getFeatureProfile()->getExtent().yMax())); } #endif } else { OE_WARN << LC << "No FeatureSource provided; nothing will be rendered (" << getName() << ")" << std::endl; } _initialized = true; }
virtual bool osgEarth::Features::FeatureTileSource::isSameKindAs | ( | const osg::Object * | obj | ) | const [inline, virtual] |
Reimplemented from osgEarth::TileSource.
Definition at line 150 of file FeatureTileSource.
{ return dynamic_cast<const FeatureTileSource*>(obj)!=NULL; }
virtual const char* osgEarth::Features::FeatureTileSource::libraryName | ( | ) | const [inline, virtual] |
Reimplemented from osgEarth::TileSource.
Definition at line 152 of file FeatureTileSource.
{ return "osgEarthFeatures"; }
virtual bool osgEarth::Features::FeatureTileSource::postProcess | ( | osg::Image * | image, |
osg::Referenced * | buildData | ||
) | [inline, protected, virtual] |
Optional implementation hook to post-process an image tile after all calls to renderFeaturesForStyle() are complete.
Reimplemented in AGGLiteRasterizerTileSource.
Definition at line 141 of file FeatureTileSource.
{ return true; }
virtual bool osgEarth::Features::FeatureTileSource::preProcess | ( | osg::Image * | image, |
osg::Referenced * | buildData | ||
) | [inline, protected, virtual] |
Optional implementation hook to pre-process an image tile before any calls to renderFeaturesForStyle().
Reimplemented in AGGLiteRasterizerTileSource.
Definition at line 133 of file FeatureTileSource.
{ return true; }
bool FeatureTileSource::queryAndRenderFeaturesForStyle | ( | const Style & | style, |
const Query & | query, | ||
osg::Referenced * | data, | ||
const GeoExtent & | imageExtent, | ||
osg::Image * | out_image | ||
) | [protected] |
Definition at line 220 of file FeatureTileSource.cpp.
{ // first we need the overall extent of the layer: const GeoExtent& featuresExtent = getFeatureSource()->getFeatureProfile()->getExtent(); // convert them both to WGS84, intersect the extents, and convert back. GeoExtent featuresExtentWGS84 = featuresExtent.transform( featuresExtent.getSRS()->getGeographicSRS() ); GeoExtent imageExtentWGS84 = imageExtent.transform( featuresExtent.getSRS()->getGeographicSRS() ); GeoExtent queryExtentWGS84 = featuresExtentWGS84.intersectionSameSRS( imageExtentWGS84.bounds() ); if ( queryExtentWGS84.isValid() ) { GeoExtent queryExtent = queryExtentWGS84.transform( featuresExtent.getSRS() ); // incorporate the image extent into the feature query for this style: Query localQuery = query; localQuery.bounds() = query.bounds().isSet()? query.bounds()->unionWith( queryExtent.bounds() ) : queryExtent.bounds(); // query the feature source: osg::ref_ptr<FeatureCursor> cursor = _features->createFeatureCursor( localQuery ); // now copy the resulting feature set into a list, converting the data // types along the way if a geometry override is in place: FeatureList cellFeatures; while( cursor->hasMore() ) { Feature* feature = cursor->nextFeature(); Geometry* geom = feature->getGeometry(); if ( geom ) { // apply a type override if requested: if (_options.geometryTypeOverride().isSet() && _options.geometryTypeOverride() != geom->getComponentType() ) { geom = geom->cloneAs( _options.geometryTypeOverride().value() ); if ( geom ) feature->setGeometry( geom ); } } if ( geom ) { cellFeatures.push_back( feature ); } } //OE_NOTICE // << "Rendering " // << cellFeatures.size() // << " features in (" // << queryExtent.toString() << ")" // << std::endl; return renderFeaturesForStyle( style, cellFeatures, data, imageExtent, out_image ); } else { return false; } }
virtual bool osgEarth::Features::FeatureTileSource::renderFeaturesForStyle | ( | const Style & | style, |
const FeatureList & | features, | ||
osg::Referenced * | buildData, | ||
const GeoExtent & | imageExtent, | ||
osg::Image * | out_image | ||
) | [inline, protected, virtual] |
Creates OSG graph(s) representing the specified feature list.
style | Styling information for the feature geometry |
features | Features to render |
buildData | Implementation-specific build data (from createBuildData) |
out_image | Pre-allocated image to which the implementation would render. |
Reimplemented in AGGLiteRasterizerTileSource.
Definition at line 122 of file FeatureTileSource.
{ return false; }
void FeatureTileSource::setFeatureSource | ( | FeatureSource * | source | ) |
Sets the source from which to read feature data. It is only legal to call this method before this TileSource has been initialized by the map engine. Afterwards it will have no effect.
Definition at line 142 of file FeatureTileSource.cpp.
{ if ( !_initialized ) { _features = source; } else { OE_WARN << LC << "Illegal: cannot set FeatureSource after intitialization ( " << getName() << ")" << std::endl; } }
osg::ref_ptr<FeatureSource> osgEarth::Features::FeatureTileSource::_features [protected] |
Definition at line 159 of file FeatureTileSource.
bool osgEarth::Features::FeatureTileSource::_initialized [protected] |
Definition at line 163 of file FeatureTileSource.
osg::ref_ptr<const osgEarth::Map> osgEarth::Features::FeatureTileSource::_map [protected] |
Definition at line 162 of file FeatureTileSource.
const FeatureTileSourceOptions osgEarth::Features::FeatureTileSource::_options [protected] |
Reimplemented from osgEarth::TileSource.
Reimplemented in AGGLiteRasterizerTileSource.
Definition at line 160 of file FeatureTileSource.