SimpleOceanOptions 6.18 KB
Newer Older
xuebingbing's avatar
xuebingbing committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
/* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
 * Copyright 2015 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 <http://www.gnu.org/licenses/>
 */
#ifndef OSGEARTH_DRIVER_SIMPLE_OCEAN
#define OSGEARTH_DRIVER_SIMPLE_OCEAN 1

#include <osgEarthUtil/Ocean>
#include <osgEarth/MapNode>
#include <osgEarth/ImageLayer>
#include <osgEarth/URI>
#include <osgEarth/Registry>
#include <osgEarthSymbology/Color>

namespace osgEarth { namespace Drivers { namespace SimpleOcean
{
    using namespace osgEarth;
    using namespace osgEarth::Util;

    /**
     * Options for controlling the ocean surface node.
     * (header-only)
     */
    class SimpleOceanOptions : public OceanOptions
    {
    public:
        /** Nominal sea level in meters (relative to ellipsoid/geoid); default is zero. */
        optional<float>& seaLevel() { return _seaLevel; }
        const optional<float>& seaLevel() const { return _seaLevel; }

        /** Elevation offset (relative to seaLevel) at which ocean surface goes to min transparency.
         *  Not available when using a mask layer. */
        optional<float>& lowFeatherOffset() { return _lowFeatherOffset; }
        const optional<float>& lowFeatherOffset() const { return _lowFeatherOffset; }

        /** Elevation offset (relative to seaLevel) at which ocean surface goes to full transparency.
         *  Not available when using a mask layer. */
        optional<float>& highFeatherOffset() { return _highFeatherOffset; }
        const optional<float>& highFeatherOffset() const { return _highFeatherOffset; }

        /** Maximum LOD to subdivide ocean surface */
        optional<unsigned>& maxLOD() { return _maxLOD; }
        const optional<unsigned>& maxLOD() const { return _maxLOD; }

        /** Color of the ocean surface (before texturing) */
        optional<Color>& baseColor() { return _baseColor; }
        const optional<Color>& baseColor() const { return _baseColor; }

        /** Maximum visibile range of the ocean (at which is starts fading in) */
        optional<float>& maxRange() { return _maxRange; }
        const optional<float>& maxRange() const { return _maxRange; }

        /** Range over which ocean fades into view (starting at maxRange) */
        optional<float>& fadeRange() { return _fadeRange; }
        const optional<float>& fadeRange() const { return _fadeRange; }

        /** URI of the texture to blend and animate into the ocean surface. */
        optional<URI>& textureURI() { return _textureURI; }
        const optional<URI>& textureURI() const { return _textureURI; }

        /** Image layer configuration for an optional "ocean mask" layer.
         *  This is an image layer that encodes areas of land versus ocean in the
         *  alpha channel of the image. The mapping is: [0...1] => [land...ocean] */
        optional<ImageLayerOptions>& maskLayer() { return _maskLayerOptions; }
        const optional<ImageLayerOptions>& maskLayer() const { return _maskLayerOptions; }

    public:
        SimpleOceanOptions( const ConfigOptions& conf =ConfigOptions() )
            : OceanOptions      ( conf ),
              _seaLevel         ( 0.0f ),
              _lowFeatherOffset ( -100.0f ),
              _highFeatherOffset( -10.0f ),
              _maxRange         ( 1000000.0f ),
              _fadeRange        ( 125000.0f ),
              _maxLOD           ( 20 ),
              _baseColor        ( osg::Vec4(0.2, 0.3, 0.5, 0.8) )
        {
            mergeConfig( _conf );
        }

        /** dtor */
        virtual ~SimpleOceanOptions() { }

    public:
        Config getConfig() const {
            Config conf = OceanOptions::newConfig();
            conf.updateIfSet("sea_level",           _seaLevel );
            conf.updateIfSet("high_feather_offset", _highFeatherOffset );
            conf.updateIfSet("low_feather_offset",  _lowFeatherOffset );
            conf.updateIfSet("max_range",           _maxRange );
            conf.updateIfSet("fade_range",          _fadeRange );
            conf.updateIfSet("max_lod",             _maxLOD );
            conf.updateIfSet("base_color",          _baseColor );
            conf.updateIfSet("texture_url",         _textureURI );
            conf.updateObjIfSet("mask_layer",       _maskLayerOptions );
            return conf;
        }

    protected:
        void mergeConfig( const Config& conf ) {
            OceanOptions::mergeConfig( conf );
            fromConfig( conf );
        }

    private:
        void fromConfig( const Config& conf ) {
            conf.getIfSet("sea_level",           _seaLevel );
            conf.getIfSet("high_feather_offset", _highFeatherOffset );
            conf.getIfSet("low_feather_offset",  _lowFeatherOffset );
            conf.getIfSet("max_range",           _maxRange );
            conf.getIfSet("fade_range",          _fadeRange );
            conf.getIfSet("max_lod",             _maxLOD );
            conf.getIfSet("base_color",          _baseColor );
            conf.getIfSet("texture_url",         _textureURI );
            conf.getObjIfSet("mask_layer",       _maskLayerOptions );
        }

    private:
        optional<float>             _seaLevel;
        optional<float>             _lowFeatherOffset;
        optional<float>             _highFeatherOffset;
        optional<float>             _maxRange;
        optional<float>             _fadeRange;
        optional<unsigned>          _maxLOD;
        optional<Color>             _baseColor;
        optional<URI>               _textureURI;
        optional<ImageLayerOptions> _maskLayerOptions;
    };

} } } // namespace osgEarth::Drivers::SimpleOcean

#endif // OSGEARTH_DRIVER_SIMPLE_OCEAN