/* -*-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 OSGEARTH_FEATURES_GEOMETRY_COMPILER_H
#define OSGEARTH_FEATURES_GEOMETRY_COMPILER_H 1
#include
#include
#include
#include
#include
#include
#include
namespace osgEarth
{
/** TODO: refactor into GeometryCompiler::Options */
class OSGEARTH_EXPORT GeometryCompilerOptions
{
public:
/**
* Set the global default values for the options.
*/
static void setDefaults(const GeometryCompilerOptions& defaults);
public:
/**
* Construct new copiler options, optionally deserializing them
*/
GeometryCompilerOptions(const ConfigOptions& conf =ConfigOptions());
public:
/** Maximum span of a generated edge, in degrees. Applicable to geocentric maps only */
optional& maxGranularity() { return _maxGranularity_deg; }
const optional& maxGranularity() const { return _maxGranularity_deg; }
/** Interpolation type to use for geodetic points */
optional& geoInterp() { return _geoInterp; }
const optional& geoInterp() const { return _geoInterp; }
/** Whether to merge geometry from multiple features */
optional& mergeGeometry() { return _mergeGeometry; }
const optional& mergeGeometry() const { return _mergeGeometry; }
/** Expression to evaluate to extract a feature's readable name */
optional& featureName() { return _featureNameExpr; }
const optional& featureName() const { return _featureNameExpr; }
/** Whether to cluster feature geometries together for speed */
optional& clustering() { return _clustering; }
const optional& clustering() const { return _clustering; }
/** Whether to enabled draw-instancing for model substitution */
optional& instancing() { return _instancing; }
const optional& instancing() const { return _instancing; }
/** Whether to ignore the altitude filter (e.g. if you plan to do auto-clamping layer) */
optional& ignoreAltitudeSymbol() { return _ignoreAlt; }
const optional& ignoreAltitudeSymbol() const { return _ignoreAlt; }
//todo: merge this with geoInterp()
optional& resampleMode() { return _resampleMode;}
const optional& resampleMode() const { return _resampleMode;}
optional& resampleMaxLength() { return _resampleMaxLength; }
const optional& resampleMaxLength() const { return _resampleMaxLength;}
/** Whether to generate shader components on compiled geometry */
optional& shaderPolicy() { return _shaderPolicy; }
const optional& shaderPolicy() const { return _shaderPolicy; }
/** Whether to run consolidate equivalent state attributes for better performance. */
optional& optimizeStateSharing() { return _optimizeStateSharing; }
const optional& optimizeStateSharing() const { return _optimizeStateSharing; }
/** Whether to run the optimizer on the resulting group. */
optional& optimize() { return _optimize; }
const optional& optimize() const { return _optimize; }
/** Whether to run the vertex order optimizer on geometry. */
optional& optimizeVertexOrdering() { return _optimizeVertexOrdering; }
const optional& optimizeVertexOrdering() const { return _optimizeVertexOrdering; }
/** Whether to run a geometry validation pass on the resulting group. This is for debugging
purposes and will dump issues to the console. */
optional& validate() { return _validate; }
const optional& validate() const { return _validate; }
/** Maximum size (angle, degrees) of a polygon tile, when breaking up a large polygon for tessellation;
only applies to geocentric maps (detault = 5.0) */
optional& maxPolygonTilingAngle() { return _maxPolyTilingAngle; }
const optional& maxPolygonTilingAngle() const { return _maxPolyTilingAngle; }
/** Whether to use OSG tessellator (default=false) */
optional& useOSGTessellator() { return _useOSGTessellator; }
const optional& useOSGTessellator() const { return _useOSGTessellator; }
public:
Config getConfig() const;
protected:
void fromConfig( const Config& conf );
private:
optional _maxGranularity_deg;
optional _geoInterp;
optional _mergeGeometry;
optional _featureNameExpr;
optional _clustering;
optional _instancing;
optional _resampleMode;
optional _resampleMaxLength;
optional _ignoreAlt;
optional _shaderPolicy;
optional _optimizeStateSharing;
optional _optimize;
optional _optimizeVertexOrdering;
optional _validate;
optional _maxPolyTilingAngle;
optional _useOSGTessellator;
static GeometryCompilerOptions s_defaults;
public:
GeometryCompilerOptions(bool); // internal
};
/**
* Compiles a collection of features against a style.
*/
class OSGEARTH_EXPORT GeometryCompiler
{
public:
/** Constructs a new geometry compiler with default options. */
GeometryCompiler();
/** Constructs a new compiler with preconfigured options. */
GeometryCompiler( const GeometryCompilerOptions& options );
virtual ~GeometryCompiler() { }
/** Access the options read-only */
const GeometryCompilerOptions& options() const { return _options; }
/** Access the options for editing. */
GeometryCompilerOptions& options() { return _options; }
public:
/** Compiles a collection of features into an OSG scene graph. */
osg::Node* compile(
FeatureCursor* input,
const Style& style,
const FilterContext& context);
osg::Node* compile(
Feature* input,
const Style& style,
const FilterContext& context);
osg::Node* compile(
Feature* input,
const FilterContext& context);
osg::Node* compile(
Geometry* geom,
const Style& style,
const FilterContext& context);
osg::Node* compile(
Geometry* geom,
const Style& style);
osg::Node* compile(
Geometry* geom,
const FilterContext& context);
osg::Node* compile(
FeatureList& mungeableInput,
const Style& style,
const FilterContext& context);
protected:
GeometryCompilerOptions _options;
};
} // namespace osgEarth
#endif // OSGEARTH_FEATURES_GEOMETRY_COMPILER_H