/* -*-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 OSGEARTHSYMBOLOGY_SKIN_RESOURCE_H #define OSGEARTHSYMBOLOGY_SKIN_RESOURCE_H 1 #include #include #include #include #include #include namespace osgEarth { namespace Util { /** * A resource that points to a "skin", which is a Texture image paired with * a collection of metadata that describes its suitability for use in a scene. */ class OSGEARTH_EXPORT SkinResource : public Resource { public: /** Constructs a new skin resource. */ SkinResource( const Config& conf =Config() ); /** dtor */ virtual ~SkinResource() { } /** * Creates a new StateSet containing a Texture based on this Skin. */ osg::StateSet* createStateSet( const osgDB::Options* dbOptions ) const; /** * Creates an image for this SkinResource. */ osg::ref_ptr createImage( const osgDB::Options* options ) const; osg::Texture* createTexture(const osgDB::Options* readOptions) const; osg::Texture* createTexture(osg::Image* image) const; /** * A key string that can uniquely identify this object for the purposes * of creating its state set (e.g., for a cache) */ std::string getUniqueID() const; public: /** inline image (not serializable) */ osg::ref_ptr& image() { return _image; } const osg::ref_ptr& image() const { return _image; } /** Source location of the actual texture image. */ optional& imageURI() { return _imageURI; } const optional& imageURI() const { return _imageURI; } /** Real-world width of the image, in meters */ optional& imageWidth() { return _imageWidth; } const optional& imageWidth() const { return _imageWidth; } /** Real-world height of the image, in meters */ optional& imageHeight() { return _imageHeight; } const optional& imageHeight() const { return _imageHeight; } /** Minimum acceptable real-world object height (meters) for which this image would make an appropriate texture */ optional& minObjectHeight() { return _minObjHeight; } const optional& minObjectHeight() const { return _minObjHeight; } /** Maximum acceptable real-world object height (meters) for which this image would make an appropriate texture */ optional& maxObjectHeight() { return _maxObjHeight; } const optional& maxObjectHeight() const { return _maxObjHeight; } /** Whether this image is suitable for use as a vertically repeating texture */ optional& isTiled() { return _isTiled; } const optional& isTiled() const { return _isTiled; } /** Image offset within a source atlas (S dimension [0..1]) */ optional& imageBiasS() { return _imageBiasS; } const optional& imageBiasS() const { return _imageBiasS; } /** Image offset (pixels) within a source atlas (T dimension [0..1]) */ optional& imageBiasT() { return _imageBiasT; } const optional& imageBiasT() const { return _imageBiasT; } /** Image layer index within a source atlas (R dimension) */ optional& imageLayer() { return _imageLayer; } const optional& imageLayer() const { return _imageLayer; } /** Image scalke factor within a source atlas (S dimension) */ optional& imageScaleS() { return _imageScaleS; } const optional& imageScaleS() const { return _imageScaleS; } /** Image scalke factor within a source atlas (T dimension) */ optional& imageScaleT() { return _imageScaleT; } const optional& imageScaleT() const { return _imageScaleT; } /** GL texture application mode */ optional& texEnvMode() { return _texEnvMode; } const optional& texEnvMode() const { return _texEnvMode; } /** The maximum allowable size of a texture (in either dimension) that uses this image. */ optional maxTextureSpan() { return _maxTexSpan; } const optional maxTextureSpan() const { return _maxTexSpan; } /** Whether this image is suitable for texture atlasing */ optional& atlasHint() { return _atlasHint; } const optional& atlasHint() const { return _atlasHint; } /** Options string to pass in when reading the image */ optional& readOptions() { return _readOptions; } const optional& readOptions() const { return _readOptions; } public: // serialization methods virtual Config getConfig() const; void mergeConfig( const Config& conf ); protected: osg::StateSet* createStateSet( osg::Image* image ) const; protected: optional _name; optional _imageURI; optional _imageWidth; optional _imageHeight; optional _minObjHeight; optional _maxObjHeight; optional _isTiled; optional _texEnvMode; optional _maxTexSpan; optional _imageBiasS; optional _imageBiasT; optional _imageLayer; optional _imageScaleS; optional _imageScaleT; optional _atlasHint; optional _readOptions; osg::ref_ptr _image; }; /** * Query object that you can use to search for applicable Skin resources from the * ResourceLibrary. */ class OSGEARTH_EXPORT SkinSymbol : public TaggableWithConfig { public: META_Object(osgEarth, SkinSymbol); SkinSymbol(const SkinSymbol& rhs,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); SkinSymbol( const Config& conf =Config() ); /** dtor */ virtual ~SkinSymbol() { } public: // query parameters /** Name of the resource library to use with this symbol. */ optional& library() { return _library; } const optional& library() const { return _library; } /** Object height in meters (must fall in the skin's min/max object height range to be accepted) */ optional& objectHeight() { return _objHeight; } const optional& objectHeight() const { return _objHeight; } /** Minimum acceptable real-world object height for which this image would make an appropriate texture */ optional& minObjectHeight() { return _minObjHeight; } const optional& minObjectHeight() const { return _minObjHeight; } /** Maximum acceptable real-world object height for which this image would make an appropriate texture */ optional& maxObjectHeight() { return _maxObjHeight; } const optional& maxObjectHeight() const { return _maxObjHeight; } /** Whether this image is suitable for use as a vertically repeating texture */ optional& isTiled() { return _isTiled; } const optional& isTiled() const { return _isTiled; } /** Random number seed value (for picking a candidate) */ optional& randomSeed() { return _randomSeed; } const optional& randomSeed() const { return _randomSeed; } /** Name of a specific skin in the catalog */ optional& name() { return _name; } const optional& name() const { return _name; } public: void mergeConfig(const Config& conf); Config getConfig() const; static void parseSLD(const Config& c, class Style& style); protected: optional _library; optional _objHeight; optional _minObjHeight; optional _maxObjHeight; optional _isTiled; optional _randomSeed; optional _name; }; typedef std::vector< osg::ref_ptr > SkinResourceVector; } } #endif // OSGEARTHSYMBOLOGY_SKIN_RESOURCE_H