/* osgEarth
 * Copyright 2015 Pelican Mapping
 * MIT License
 */
#ifndef OSGEARTH_SPLAT_BIOME_H
#define OSGEARTH_SPLAT_BIOME_H 1

#include "Export"
#include "SplatCatalog"
#include <osgEarth/GeoData>
#include <vector>

namespace osgEarth { namespace Splat
{
    /**
     * Defines a set of geospatial extents under which to apply a particular
     * procedural catalog.
     */
    class OSGEARTHSPLAT_EXPORT BiomeRegion
    {
    public: // types        
        struct Region
        {
            GeoExtent extent;
            double    zmin, zmin2;
            double    zmax, zmax2;
            double    meanRadius2;
            osg::Polytope tope;
        };

    public:
        /** Construct an empty biome. */
        BiomeRegion();

        /** Get the list of bounding boxes enclosing this biome. */
        std::vector<Region>& getRegions() { return _regions; }
        const std::vector<Region>& getRegions() const { return _regions; }

        /** Name of this biome. */
        optional<std::string>& name() { return _name; }
        const optional<std::string>& name() const { return _name; }

        /** URI of the catalog mapped to this biome */
        optional<URI>& catalogURI() { return _catalogURI; }
        const optional<URI>& catalogURI() const { return _catalogURI; }

        /** The catalog to apply for this biome. */
        void setCatalog(SplatCatalog* catalog) { _catalog = catalog; }
        SplatCatalog* getCatalog() const { return _catalog.get(); }


    public:
        /** Serialize this biome's primitive members. */
        Config getConfig() const;

        bool configure(const Config& conf);

    protected:

        optional<std::string>      _name;
        optional<URI>              _catalogURI;
        std::vector<Region>        _regions;
        osg::ref_ptr<SplatCatalog> _catalog;
    };

    typedef std::vector<BiomeRegion> BiomeRegionVector;

} } // namespace osgEarth::Splat

#endif // OSGEARTH_SPLAT_BIOME_H
