summaryrefslogtreecommitdiff
path: root/src/mbgl/geometry/dem_data.hpp
blob: e59fbfedf2655f71cb775fa883bf2fd6fddb25f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma once

#include <mbgl/math/clamp.hpp>
#include <mbgl/util/image.hpp>

#include <memory>
#include <array>
#include <cassert>
#include <vector>

namespace mbgl {

class DEMData {
public:
    class Level {
    public:
        Level(int32_t dim, int32_t border);

        void set(const int32_t x, const int32_t y, const int32_t value) {
            reinterpret_cast<int32_t*>(image.data.get())[idx(x, y)] = value + 65536;
        }

        int32_t get(const int32_t x, const int32_t y) const {
            return reinterpret_cast<const int32_t*>(image.data.get())[idx(x, y)] - 65536;
        }

        const PremultipliedImage* getImage() {
            return &image;
        }


    private:
        size_t idx(const int32_t x, const int32_t y) const {
            assert(x >= -border);
            assert(x < dim + border);
            assert(y >= -border);
            assert(y < dim + border);
            return (y + border) * stride + (x + border);
        }

    public:
        const int32_t dim;
        const int32_t border;
        const int32_t stride;
        PremultipliedImage image;
    };
    
    DEMData(const PremultipliedImage& image);
    void backfillBorder(const DEMData& borderTileData, int8_t dx, int8_t dy);
    bool isLoaded() const {
        return loaded;
    }
    Level level;
    private:
        bool loaded = false;

};

} // namespace mbgl