MarkerSymbol 5.78 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 147 148 149 150 151 152 153 154 155 156
/* -*-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 OSGEARTHSYMBOLOGY_MARKER_SYMBOL_H
#define OSGEARTHSYMBOLOGY_MARKER_SYMBOL_H 1

#include <climits>

#include <osgEarth/Common>
#include <osgEarthSymbology/Symbol>
#include <osgEarthSymbology/Expression>
#include <osg/Vec3f>

namespace osgEarth { namespace Symbology
{
    class InstanceSymbol;

    /**
     * The MarkerSymbol describes replacement of geometry with "markers". A marker
     * it another object like a 3D model (node) or an image.
     */
    class OSGEARTHSYMBOLOGY_EXPORT MarkerSymbol : public Symbol
    {
    public:
        /**
         * Controls the placements of models.
         */
        enum Placement
        {
            /** Places one model instance at the centroid of the feature. */
            PLACEMENT_CENTROID,

            /** Places a model instance at each feature point. */
            PLACEMENT_VERTEX,

            /** Places model instances at regular intervals within/along the feature geometry,
                according to density. */
            PLACEMENT_INTERVAL,

            /** Scatters model instances randomly within/along feature, according to density. */
            PLACEMENT_RANDOM
        };

        // note: these are similar to the values in osgText::Text::AlignmentType
        enum Alignment {
            ALIGN_LEFT_TOP,
            ALIGN_LEFT_CENTER,
            ALIGN_LEFT_BOTTOM,

            ALIGN_CENTER_TOP,
            ALIGN_CENTER_CENTER,
            ALIGN_CENTER_BOTTOM,

            ALIGN_RIGHT_TOP,
            ALIGN_RIGHT_CENTER,
            ALIGN_RIGHT_BOTTOM,
        };

    public:
        META_Object(osgEarthSymbology, MarkerSymbol);

        MarkerSymbol(const MarkerSymbol& rhs,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
        MarkerSymbol( const Config& conf =Config() );


        /** Since MarkerSymbol is deprecated, this conveneince function will convert to an InstanceSymbol */
        class InstanceSymbol* convertToInstanceSymbol() const;

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

        /** URI of the model to use for substitution. */
        optional<StringExpression>& url() { return _url; }
        const optional<StringExpression>& url() const { return _url; }     

        /** Name of the resource library to use with this symbol (optional) */
        optional<StringExpression>& library() { return _library; }
        const optional<StringExpression>& library() const { return _library; }   

        /** How to map feature geometry to model placement. (default is PLACEMENT_CENTROID) */
        optional<Placement>& placement() { return _placement; }
        const optional<Placement>& placement() const { return _placement; }

        /** For PLACEMENT_RANDOM/INTERVAL, the scattering density in instances per sqkm */
        optional<float>& density() { return _density; }
        const optional<float>& density() const { return _density; }

        /** Model instance scale factor */
        optional<NumericExpression>& scale() { return _scale; }
        const optional<NumericExpression>& scale() const { return _scale; }

        /** Orientation in HPR degrees */
        optional<osg::Vec3f>& orientation() { return _orientation; }
        const optional<osg::Vec3f>& orientation() const { return _orientation; }

        /** Seeding value for the randomizer */
        optional<unsigned>& randomSeed() { return _randomSeed; }
        const optional<unsigned>& randomSeed() const { return _randomSeed; }

        /** Hint as to whether the marker is an icon vs. a 3D model */
        optional<bool>& isModel() { return _isModelHint; }
        const optional<bool>& isModel() const { return _isModelHint; }

        /** Alignment of the marker relative to center pixels */
        optional<Alignment>& alignment() { return _alignment; }
        const optional<Alignment>& alignment() const { return _alignment; }
        
    public: // non-serialized properties (for programmatic use only)

        /** Explicit image to use for 2D icon placemet */
        void setImage( osg::Image* image ) { _image = image; }
        osg::Image* getImage( unsigned maxSize =INT_MAX ) const;

        /** Explicit model to use for model placement */
        void setModel( osg::Node* node ) { _node = node; }
        osg::Node* getModel() const { return _node.get(); }

    public:
        virtual Config getConfig() const;
        virtual void mergeConfig( const Config& conf );
        static void parseSLD(const Config& c, class Style& style);

    protected:
        optional<StringExpression>   _url;
        optional<StringExpression>   _library;
        optional<NumericExpression>  _scale;
        optional<Placement>          _placement;
        optional<osg::Vec3f>         _orientation;
        optional<float>              _density;
        optional<unsigned>           _randomSeed;
        optional<bool>               _isModelHint;
        optional<Alignment>         _alignment;

        osg::ref_ptr<osg::Node>      _node;
        mutable osg::ref_ptr<osg::Image> _image;
    };

} } // namespace osgEarth::Symbology

#endif // OSGEARTHSYMBOLOGY_MARKER_SYMBOL_H