summaryrefslogtreecommitdiff
path: root/src/mbgl/geometry/dem_pyramid.hpp
blob: d115f191c0b65ac17320eff2c0fe58d774fe75e6 (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
#pragma once

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

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

namespace mbgl {

class DEMPyramid {
public:
    class Level {
    public:
        Level(int32_t width, int32_t height, size_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;
        }

        void resample(Level& target);

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

    public:
        const int32_t width;
        const int32_t height;
        const int32_t border;
        const int32_t stride;
        PremultipliedImage image;
    };


    void buildLevels();

    std::vector<Level> levels;


};

} // namespace mbgl