/* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
* Copyright 2008-2014 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_DRIVERS_REX_TERRAIN_ENGINE_SELECTION_INFO
#define OSGEARTH_DRIVERS_REX_TERRAIN_ENGINE_SELECTION_INFO 1

#include "Common"
#include <osgEarth/Profile>
#include <vector>


namespace osgEarth { namespace Drivers { namespace RexTerrainEngine
{
    struct VisParameters
    {
        double _visibilityRange;
        double _visibilityRange2;
        double _fMorphStart;
        double _fMorphEnd;
    };

    /**
     * SelectionInfo is a data structure that holds the LOD distance switching 
     * information for the terrain, to support paging and LOD morphing. 
     * This is calculated once when the terrain is first created.
     */
    class SelectionInfo
    {
    public:
        SelectionInfo() : _numLods(0), _uiFirstLOD(0) { }

        bool initialized(void) const;
        void initialize(unsigned uiFirstLod, unsigned uiMaxLod, const Profile* profile, double mtrf);

        unsigned getNumLODs(void) const { return _numLods; }

        // Morph start ratio
        static double getMorphStartRatio(void) { return _fMorphStartRatio; }

        // LOD at which morphing should start
        static unsigned getLODForMorphing(bool isProjected);

        VisParameters visParameters(unsigned lod) const;
    private:
        unsigned                        _numLods;
        std::pair<unsigned, unsigned>   _uiGridDimensions; 
        std::vector<VisParameters>      _vecVisParams;
        unsigned                        _uiFirstLOD;
        static const double             _fMorphStartRatio; 

        // This is the lod at which morphing should start (used by shader)
        static const unsigned           _uiLODForMorphingRoundEarth;
        
        // This is used to determine _numLods given a fLodFar during initialize
        // initialize. This is the distance beyond which further lods (and 
        // hence VisParameters) are not generated
        static const double             _fLodLowerBound;
    };

} } } // namespace

#endif
