summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMolly Lloyd <molly@mapbox.com>2018-01-12 11:46:07 -0800
committerMolly Lloyd <molly@mapbox.com>2018-01-18 18:10:09 -0800
commit41c5c89ecd6859a0d247477afada5e04e6616060 (patch)
tree885be154f37150241e7e19d7b5121d33087a83d6
parentca0f1ed0dca6131ffcfa5b358b34ec6402f47d24 (diff)
downloadqtlocation-mapboxgl-41c5c89ecd6859a0d247477afada5e04e6616060.tar.gz
clean up DEMPyramid
-rw-r--r--src/mbgl/geometry/dem_pyramid.cpp43
-rw-r--r--src/mbgl/geometry/dem_pyramid.hpp3
-rw-r--r--src/mbgl/renderer/buckets/hillshade_bucket.cpp12
-rw-r--r--src/mbgl/tile/raster_dem_tile.hpp3
4 files changed, 26 insertions, 35 deletions
diff --git a/src/mbgl/geometry/dem_pyramid.cpp b/src/mbgl/geometry/dem_pyramid.cpp
index 2674d7a9d8..534ccc9cfd 100644
--- a/src/mbgl/geometry/dem_pyramid.cpp
+++ b/src/mbgl/geometry/dem_pyramid.cpp
@@ -8,13 +8,13 @@ void DEMPyramid::loadFromImage(PremultipliedImage& image){
const int32_t border = std::max<int32_t>(std::ceil(image.size.height / 2), 1);
- Level first(image.size.height, border);
+ level = std::make_unique<Level>(image.size.height, border);
- for (int32_t y = 0; y < first.dim; y++) {
- for (int32_t x = 0; x < first.dim; x++) {
- const int32_t i = y * first.dim + x;
+ for (int32_t y = 0; y < level->dim; y++) {
+ for (int32_t x = 0; x < level->dim; x++) {
+ const int32_t i = y * level->dim + x;
const int32_t j = i * 4;
- first.set(x, y, (image.data[j] * 256 * 256 + image.data[j+1] * 256 + image.data[j+2])/10 - 10000);
+ level->set(x, y, (image.data[j] * 256 * 256 + image.data[j+1] * 256 + image.data[j+2])/10 - 10000);
}
}
@@ -43,19 +43,19 @@ void DEMPyramid::loadFromImage(PremultipliedImage& image){
// first.set( -1, first.dim, first.get(0, first.dim - 1));
// first.set(first.dim, first.dim, first.get(first.dim - 1, first.dim - 1));
- levels.emplace_back(std::move(first));
+
loaded = true;
}
void DEMPyramid::backfillBorder(mbgl::DEMPyramid &borderTileData, int8_t dx, int8_t dy) {
- auto& t = levels.front();
- auto& o = borderTileData.levels.front();
- assert(t.dim == o.dim);
+ auto& t = level;
+ auto& o = borderTileData.level;
+ assert(t->dim == o->dim);
- int32_t _xMin = dx * t.dim;
- int32_t _xMax = dx * t.dim + t.dim;
- int32_t _yMin = dy * t.dim;
- int32_t _yMax = dy * t.dim + t.dim;
+ int32_t _xMin = dx * t->dim;
+ int32_t _xMax = dx * t->dim + t->dim;
+ int32_t _yMin = dy * t->dim;
+ int32_t _yMax = dy * t->dim + t->dim;
if (dx == -1) _xMin = _xMax - 1;
else if (dx == 1) _xMax = _xMin + 1;
@@ -63,18 +63,18 @@ void DEMPyramid::backfillBorder(mbgl::DEMPyramid &borderTileData, int8_t dx, int
if (dy == -1) _yMin = _yMax - 1;
else if (dy == 1) _yMax = _yMin + 1;
- int32_t xMin = util::clamp(_xMin, -t.border, t.dim + t.border);
- int32_t xMax = util::clamp(_xMax, -t.border, t.dim + t.border);
+ int32_t xMin = util::clamp(_xMin, -t->border, t->dim + t->border);
+ int32_t xMax = util::clamp(_xMax, -t->border, t->dim + t->border);
- int32_t yMin = util::clamp(_yMin, -t.border, t.dim + t.border);
- int32_t yMax = util::clamp(_yMax, -t.border, t.dim + t.border);
+ int32_t yMin = util::clamp(_yMin, -t->border, t->dim + t->border);
+ int32_t yMax = util::clamp(_yMax, -t->border, t->dim + t->border);
- int32_t ox = -dx * t.dim;
- int32_t oy = -dy * t.dim;
+ int32_t ox = -dx * t->dim;
+ int32_t oy = -dy * t->dim;
for (int32_t y = yMin; y < yMax; y++) {
for (int32_t x = xMin; x < xMax; x++) {
- t.set(x, y, o.get(x + ox, y + oy));
+ t->set(x, y, o->get(x + ox, y + oy));
}
}
}
@@ -89,7 +89,4 @@ DEMPyramid::Level::Level(int32_t dim_, int32_t border_)
std::memset(image.data.get(), 0, image.bytes());
}
-
-
-
} // namespace mbgl
diff --git a/src/mbgl/geometry/dem_pyramid.hpp b/src/mbgl/geometry/dem_pyramid.hpp
index ba4d5e3ef0..5d3a5cdfde 100644
--- a/src/mbgl/geometry/dem_pyramid.hpp
+++ b/src/mbgl/geometry/dem_pyramid.hpp
@@ -15,6 +15,7 @@ public:
class Level {
public:
Level(int32_t dim, int32_t border);
+ Level(const Level&& level);
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;
@@ -47,7 +48,7 @@ public:
bool isLoaded() {
return loaded;
};
- std::vector<Level> levels;
+ std::unique_ptr<Level> level;
private:
bool loaded = false;
diff --git a/src/mbgl/renderer/buckets/hillshade_bucket.cpp b/src/mbgl/renderer/buckets/hillshade_bucket.cpp
index 09d62b7f78..3c9158a1ec 100644
--- a/src/mbgl/renderer/buckets/hillshade_bucket.cpp
+++ b/src/mbgl/renderer/buckets/hillshade_bucket.cpp
@@ -24,13 +24,9 @@ void HillshadeBucket::upload(gl::Context& context) {
return;
}
- if (!pyramid.levels.empty()) {
- dem = context.createTexture(pyramid.levels.front().image);
- for (size_t l = 1; l < pyramid.levels.size(); l++) {
- auto& image = pyramid.levels[l].image;
- context.updateTexture(*dem, image);
- }
- }
+ dem = context.createTexture(pyramid.level->image);
+ auto& image = pyramid.level->image;
+ context.updateTexture(*dem, image);
if (!segments.empty()) {
vertexBuffer = context.createVertexBuffer(std::move(vertices));
@@ -108,7 +104,7 @@ void HillshadeBucket::setMask(TileMask&& mask_) {
}
bool HillshadeBucket::hasData() const {
- return !pyramid.levels.empty();
+ return pyramid.level->image.valid();
}
} // namespace mbgl
diff --git a/src/mbgl/tile/raster_dem_tile.hpp b/src/mbgl/tile/raster_dem_tile.hpp
index 571c1ca7e9..f208d3e40c 100644
--- a/src/mbgl/tile/raster_dem_tile.hpp
+++ b/src/mbgl/tile/raster_dem_tile.hpp
@@ -15,9 +15,6 @@ enum class DEMTileNeighbors : unsigned char {
// 0b00000000
Empty = 0 << 1,
- // the order of the neighbors in this enum (or rather the order of their flipped bits
- // must stay the same as
-
// 0b00000001
Left = 1 << 0,
// 0b00000010