TerrainTile.h 2.75 KB
Newer Older
Andreas Bircher's avatar
Andreas Bircher committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#ifndef TERRAINTILE_H
#define TERRAINTILE_H

#include "QGCLoggingCategory.h"

#include <QGeoCoordinate>

#define TERRAIN_TILE_SIZE 90

Q_DECLARE_LOGGING_CATEGORY(TerrainTileLog)

class TerrainTile
{
public:
    TerrainTile();
    ~TerrainTile();

    /**
    * Constructor from json doc with elevation data (either from file or web)
    *
Andreas Bircher's avatar
Andreas Bircher committed
21
    * @param document
Andreas Bircher's avatar
Andreas Bircher committed
22
    */
Andreas Bircher's avatar
Andreas Bircher committed
23
    TerrainTile(QJsonDocument document);
Andreas Bircher's avatar
Andreas Bircher committed
24 25 26 27 28 29 30

    /**
    * Check for whether a coordinate lies within this tile
    *
    * @param coordinate
    * @return true if within
    */
Andreas Bircher's avatar
Andreas Bircher committed
31
    bool isIn(const QGeoCoordinate& coordinate) const;
Andreas Bircher's avatar
Andreas Bircher committed
32 33 34 35 36 37

    /**
    * Check whether valid data is loaded
    *
    * @return true if data is valid
    */
Andreas Bircher's avatar
Andreas Bircher committed
38
    bool isValid(void) const { return _isValid; }
Andreas Bircher's avatar
Andreas Bircher committed
39 40 41 42 43 44 45

    /**
    * Evaluates the elevation at the given coordinate
    *
    * @param coordinate
    * @return elevation
    */
Andreas Bircher's avatar
Andreas Bircher committed
46
    float elevation(const QGeoCoordinate& coordinate) const;
Andreas Bircher's avatar
Andreas Bircher committed
47 48 49 50 51 52

    /**
    * Accessor for the minimum elevation of the tile
    *
    * @return minimum elevation
    */
Andreas Bircher's avatar
Andreas Bircher committed
53
    float minElevation(void) const { return _minElevation; }
Andreas Bircher's avatar
Andreas Bircher committed
54 55 56 57 58 59

    /**
    * Accessor for the maximum elevation of the tile
    *
    * @return maximum elevation
    */
Andreas Bircher's avatar
Andreas Bircher committed
60
    float maxElevation(void) const { return _maxElevation; }
Andreas Bircher's avatar
Andreas Bircher committed
61 62 63 64 65 66

    /**
    * Accessor for the average elevation of the tile
    *
    * @return average elevation
    */
Andreas Bircher's avatar
Andreas Bircher committed
67 68 69 70 71 72 73
    float avgElevation(void) const { return _avgElevation; }

    /// tile grid size in lat and lon
    static const int    _gridSize = TERRAIN_TILE_SIZE;

    /// grid spacing in degree
    static const float  _srtm1Increment = 1.0 / (60.0 * 60.0);
Andreas Bircher's avatar
Andreas Bircher committed
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

private:
    QGeoCoordinate      _southWest;                                     /// South west corner of the tile
    QGeoCoordinate      _northEast;                                     /// North east corner of the tile

    float               _minElevation;                                  /// Minimum elevation in tile
    float               _maxElevation;                                  /// Maximum elevation in tile
    float               _avgElevation;                                  /// Average elevation of the tile

    float               _data[TERRAIN_TILE_SIZE][TERRAIN_TILE_SIZE];    /// elevation data
    bool                _isValid;                                       /// data loaded is valid

    // Json keys
    static const char*  _jsonStatusKey;
    static const char*  _jsonDataKey;
    static const char*  _jsonBoundsKey;
    static const char*  _jsonSouthWestKey;
    static const char*  _jsonNorthEastKey;
    static const char*  _jsonStatsKey;
    static const char*  _jsonMaxElevationKey;
    static const char*  _jsonMinElevationKey;
    static const char*  _jsonAvgElevationKey;
    static const char*  _jsonCarpetKey;
};

#endif // TERRAINTILE_H