/* -*-c++-*- */ /* osgEarth - Geospatial SDK for OpenSceneGraph * Copyright 2020 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 */ #ifndef OSGEARTHFEATURES_FEATURE_MODEL_SOURCE_H #define OSGEARTHFEATURES_FEATURE_MODEL_SOURCE_H 1 #include #include #include #include #include #include #include #include #include #include #include namespace osgEarth { class OSGEARTH_EXPORT FeatureModelOptions { public: //properties OE_OPTION_LAYER(StyleSheet, styleSheet); /** Maximum span of a generated edge, in degrees. For geocentric maps only */ optional& maxGranularity() { return _maxGranularity_deg; } const optional& maxGranularity() const { return _maxGranularity_deg; } /** Whether to explicity set/clear GL lighting on the result */ optional& enableLighting() { return _lit; } const optional& enableLighting() const { return _lit; } /** Information that controls paging and tiling of the dataset */ optional& layout() { return _layout; } const optional& layout() const { return _layout; } optional& clusterCulling() { return _clusterCulling; } const optional& clusterCulling() const { return _clusterCulling; } /** Expression that will assign a node name to geometry built from each feature. Note; this may disable various scene graph optimizations. */ optional& featureName() { return _featureNameExpr; } const optional& featureName() const { return _featureNameExpr; } /** Whether to index feature data for use with the global ObjectIndex (default = yes) for the purposes of search, picking, etc. */ optional& featureIndexing() { return _featureIndexing; } const optional& featureIndexing() const { return _featureIndexing; } /** Whether to activate backface culling (default = yes) */ optional& backfaceCulling() { return _backfaceCulling; } const optional& backfaceCulling() const { return _backfaceCulling; } /** Whether to activate alpha blending (default = yes) */ optional& alphaBlending() { return _alphaBlending; } const optional& alphaBlending() const { return _alphaBlending; } /** Fading properties */ optional& fading() { return _fading; } const optional& fading() const { return _fading; } /** Whether to enable caching of actual OSG nodes. default = false. */ optional& nodeCaching() { return _nodeCaching; } const optional& nodeCaching() const { return _nodeCaching; } /** Debug: whether to enable a session-wide resource cache (default=true) */ optional& sessionWideResourceCache() { return _sessionWideResourceCache; } const optional& sessionWideResourceCache() const { return _sessionWideResourceCache; } /** Options feature filters */ OE_OPTION_VECTOR(ConfigOptions, filters); public: FeatureModelOptions(const ConfigOptions& co =ConfigOptions()); void fromConfig(const Config& conf); Config getConfig() const; protected: optional _layout; optional _featureNameExpr; optional _lit; optional _maxGranularity_deg; optional _clusterCulling; optional _backfaceCulling; optional _alphaBlending; optional _fading; optional _featureIndexing; optional _sessionWideResourceCache; optional _nodeCaching; }; /** * Interface for a class that can create a Node from a set of features and * a style definition. You will provide this to a FeatureModeGraph when * creating a feature node in a driver. */ class OSGEARTH_EXPORT FeatureNodeFactory : public osg::Referenced { public: /** * Render (or update) a list of features into a node according to the specified * style. */ virtual bool createOrUpdateNode( FeatureCursor* cursor, const Style& style, const FilterContext& context, osg::ref_ptr& node, const Query& query) { // for backwards compatibility with old API return createOrUpdateNode(cursor, style, context, node); } virtual bool createOrUpdateNode( FeatureCursor* cursor, const Style& style, const FilterContext& context, osg::ref_ptr& node) { return false; } /** * Creates a group that will contain all the geometry corresponding to a * given style. The subclass has the option of overriding this in order to create * a custom implementation. */ virtual osg::Group* getOrCreateStyleGroup( const Style& style, Session* session ); }; /** * A Feature node factory that invokes the GeometryCompiler. */ class OSGEARTH_EXPORT GeomFeatureNodeFactory : public FeatureNodeFactory { public: GeomFeatureNodeFactory( const GeometryCompilerOptions& options); bool createOrUpdateNode( FeatureCursor* features, const Style& style, const FilterContext& context, osg::ref_ptr& node, const Query& query); public: GeometryCompilerOptions _options; }; #if 0 /** * A ModelSource that renders Feature data from a FeatureSource. * @deprecated */ class OSGEARTH_EXPORT FeatureModelSource : public ModelSource { public: /** * Constructs a new feature model source with the provided options. */ FeatureModelSource( const FeatureModelSourceOptions& options =FeatureModelSourceOptions() ); /** * Sets a new read options. */ void setReadOptions(const osgDB::Options* readOptions); protected: // ModelSource virtual Status initialize(const osgDB::Options* readOptions); virtual osg::Node* createNodeImplementation( const Map* map, ProgressCallback* progress ); public: /** * Abstract - the implementation class must define a feature node factory object * that will actually bulid feature geometry. */ virtual FeatureNodeFactory* createFeatureNodeFactory() =0; public: // properties: /** Sets a feature source. */ void setFeatureSource( FeatureSource* source ); /** The underlying feature source. */ FeatureSource* getFeatureSource() { return _features.get(); } /** The options with which this source was created */ virtual const FeatureModelSourceOptions& getFeatureModelOptions() const { return _options; } public: // META_Object specialization: virtual osg::Object* cloneType() const { return 0; } // cloneType() not appropriate virtual osg::Object* clone(const osg::CopyOp&) const { return 0; } // clone() not appropriate virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast(obj)!=NULL; } virtual const char* className() const { return "FeatureModelSource"; } virtual const char* libraryName() const { return "osgEarth"; } protected: /** DTOR is protected to prevent this object from being allocated on the stack */ virtual ~FeatureModelSource() { } osg::ref_ptr _features; osg::observer_ptr _map; const FeatureModelSourceOptions _options; osg::ref_ptr _factory; osg::ref_ptr _readOptions; }; #endif } // namespace osgEarth #endif // OSGEARTHFEATURES_FEATURE_SOURCE_H