1/* -*-c++-*- */
2/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
3 * Copyright 2015 Pelican Mapping
4 * http://osgearth.org
5 *
6 * osgEarth is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program.  If not, see <http://www.gnu.org/licenses/>
18 */
19#ifndef OSGEARTH_DRIVER_FEATURE_STENCIL_MODEL_OPTIONS
20#define OSGEARTH_DRIVER_FEATURE_STENCIL_MODEL_OPTIONS 1
21
22#include <osgEarth/Common>
23#include <osgEarthFeatures/FeatureModelSource>
24
25namespace osgEarth { namespace Drivers
26{
27    using namespace osgEarth;
28    using namespace osgEarth::Features;
29
30    class FeatureStencilModelOptions : public FeatureModelSourceOptions // NO EXPORT; header only
31    {
32    public: // properties
33
34        optional<double>& extrusionDistance() { return _extrusionDistance; }
35        const optional<double>& extrusionDistance() const { return _extrusionDistance; }
36
37        optional<double>& densificationThreshold() { return _densificationThreshold; }
38        const optional<double>& densificationThreshold() const { return _densificationThreshold; }
39
40        optional<bool>& inverted() { return _inverted; }
41        const optional<bool>& inverted() const { return _inverted; }
42
43        optional<bool>& mask() { return _mask; }
44        const optional<bool>& mask() const { return _mask; }
45
46        optional<bool>& showVolumes() { return _showVolumes; }
47        const optional<bool>& showVolumes() const { return _showVolumes; }
48
49    public:
50        FeatureStencilModelOptions( const ConfigOptions& options =ConfigOptions() ) : FeatureModelSourceOptions( options ),
51            _extrusionDistance( 300000 ),
52            _densificationThreshold( 1000000 ),
53            _inverted( false ),
54            _mask( false ),
55            _showVolumes( false )
56        {
57            setDriver( "feature_stencil" );
58            fromConfig( _conf );
59        }
60
61        virtual ~FeatureStencilModelOptions() { }
62
63    public:
64        Config getConfig() const {
65            Config conf = FeatureModelSourceOptions::getConfig();
66            conf.updateIfSet( "extrusion_distance", _extrusionDistance );
67            conf.updateIfSet( "densification_threshold", _densificationThreshold );
68            conf.updateIfSet( "inverted", _inverted );
69            conf.updateIfSet( "mask", _mask );
70            conf.updateIfSet( "showVolumes", _showVolumes );
71            return conf;
72        }
73
74    protected:
75        void mergeConfig( const Config& conf ) {
76            FeatureModelSourceOptions::mergeConfig( conf );
77            fromConfig( conf );
78        }
79
80    private:
81        void fromConfig( const Config& conf ) {
82            conf.getIfSet( "extrusion_distance", _extrusionDistance );
83            conf.getIfSet( "densification_threshold", _densificationThreshold );
84            conf.getIfSet( "inverted", _inverted );
85            conf.getIfSet( "mask", _mask );
86            conf.getIfSet( "show_volumes", _showVolumes );
87
88            //special: you can also set mask=true by naming the config:
89            if ( !_mask.isSet() && conf.key() == "mask_model" )
90                _mask = true;
91        }
92
93        optional<double> _extrusionDistance, _densificationThreshold;
94        optional<bool> _inverted, _mask, _showVolumes;
95    };
96
97} } // namespace osgEarth::Drivers
98
99#endif // OSGEARTH_DRIVER_FEATURE_STENCIL_MODEL_OPTIONS
100
101