#pragma once

#include "AftrConfig.h"
#ifdef AFTR_CONFIG_USE_GDAL

#include "MGLGridECEF.h"

namespace Aftr
{
class MGLGridECEFElevation : public MGLGridECEF
{
public:
   /// Offset is typically the center LLA point for the terrain...
   /// Most commonly used c'tor
   static MGLGridECEFElevation* New( WO* parentWO, const VectorD& upperLeft, const VectorD& lowerRight,
      unsigned int granularity, const VectorD& offset, const VectorD& scale,
      const std::string& elevationData, float exageration, bool useColors, int numSplits );


   /// Offset is typically the center LLA point for the terrain...
   MGLGridECEFElevation( WO* parentWO, bool clip, const VectorD& upperLeft, const VectorD& lowerRight,
      unsigned int granularity, const VectorD& offset, const VectorD& scale, const std::string& elevationData, float exageration );

   //Creates a ModelDataShared* that is immediately returned. The caller owns this pointer, it is no longer managed by makeVBO(...).
   ModelDataShared* makeModelDataShared( int splits );
   
   /// Offset is typically the center LLA point for the terrain...
   MGLGridECEFElevation( WO* parentWO, const VectorD& upperLeft, const VectorD& lowerRight,
      unsigned int granularity, const VectorD& scale, const std::string& elevationData, float exageration );

   virtual ~MGLGridECEFElevation() {}
   //virtual void defineVertices();
   //virtual void defineTextureCoords();
   virtual void defineTextureCoordsClipped();
   virtual void defineColors();
  // virtual void render( const Camera& cam );
   virtual void setScale( const Vector& scale );

   float oceanHeight = 0;

   virtual bool overTerrainLLA( const VectorD& lla ) const noexcept;
   virtual double getElevationAtLLA( const VectorD& lla ) const noexcept;
protected:

   MGLGridECEFElevation( WO* parentWO );

   virtual void onCreate( const VectorD& upperLeft, const VectorD& lowerRight,
      unsigned int granularity, const VectorD& offset, const VectorD& scale,
      const std::string& elevationData, float exageration, bool useColors, int numSplits );

   void createNewResolutionTerrain( const VectorD& upperLeft, const VectorD& lowerRight, const std::string& elevationData );
   void createFullResolutionTerrain( const VectorD& upperLeft, const VectorD& lowerRight, const std::string& elevationData );
   void createSubSampledTerrain( const VectorD& upperLeft, const VectorD& lowerRight, unsigned int granularity, const std::string& elevationData );

   float maxHeight = -std::numeric_limits<float>::max();
   float minHeight = std::numeric_limits<float>::max();

   float averageHeight = 0;
   float standardDeviationHeight = 0;
};
}

#endif

