| 18 | namespace generator |
| 19 | { |
| 20 | class SrtmTile |
| 21 | { |
| 22 | public: |
| 23 | SrtmTile() : m_valid(false) {} |
| 24 | SrtmTile(SrtmTile && rhs); |
| 25 | |
| 26 | void Init(std::string const & dir, ms::LatLon const & coord); |
| 27 | |
| 28 | inline bool IsValid() const { return m_valid; } |
| 29 | /// @return Height in meters at |coord| or kInvalidAltitude. |
| 30 | /// @{ |
| 31 | /// Nearest serialized height. |
| 32 | geometry::Altitude GetHeight(ms::LatLon const & coord) const; |
| 33 | /// Triangle interpolation. |
| 34 | double GetTriangleHeight(ms::LatLon const & coord) const; |
| 35 | /// Bilinear interpolation. |
| 36 | double GetBilinearHeight(ms::LatLon const & coord) const; |
| 37 | |
| 38 | geometry::Altitude GetAltitude(ms::LatLon const & coord) const |
| 39 | { |
| 40 | return static_cast<geometry::Altitude>(std::round(GetBilinearHeight(coord))); |
| 41 | } |
| 42 | /// @} |
| 43 | |
| 44 | using LatLonKey = std::pair<int32_t, int32_t>; |
| 45 | static LatLonKey GetKey(ms::LatLon const & coord); |
| 46 | |
| 47 | static std::string GetBase(ms::LatLon const & coord); |
| 48 | static std::string GetPath(std::string const & dir, std::string const & base); |
| 49 | |
| 50 | /// Used in unit tests only to prepare mock tile. |
| 51 | geometry::Altitude * DataForTests(size_t & sz); |
| 52 | |
| 53 | private: |
| 54 | static ms::LatLon GetCoordInSeconds(ms::LatLon const & coord); |
| 55 | geometry::Altitude GetHeightRC(size_t row, size_t col) const; |
| 56 | |
| 57 | inline geometry::Altitude const * Data() const { return reinterpret_cast<geometry::Altitude const *>(m_data.data()); } |
| 58 | |
| 59 | inline size_t Size() const { return m_data.size() / sizeof(geometry::Altitude); } |
| 60 | void Invalidate(); |
| 61 | |
| 62 | std::vector<uint8_t> m_data; |
| 63 | bool m_valid; |
| 64 | |
| 65 | DISALLOW_COPY(SrtmTile); |
| 66 | }; |
| 67 | |
| 68 | class SrtmTileManager |
| 69 | { |