[core] Remove dead code
- CollisionTile - FrameHistory - PlacementConfig
This commit is contained in:
@@ -168,8 +168,6 @@ set(MBGL_CORE_FILES
|
||||
src/mbgl/renderer/cross_faded_property_evaluator.cpp
|
||||
src/mbgl/renderer/cross_faded_property_evaluator.hpp
|
||||
src/mbgl/renderer/data_driven_property_evaluator.hpp
|
||||
src/mbgl/renderer/frame_history.cpp
|
||||
src/mbgl/renderer/frame_history.hpp
|
||||
src/mbgl/renderer/group_by_layout.cpp
|
||||
src/mbgl/renderer/group_by_layout.hpp
|
||||
src/mbgl/renderer/image_atlas.cpp
|
||||
@@ -531,8 +529,6 @@ set(MBGL_CORE_FILES
|
||||
src/mbgl/text/check_max_angle.hpp
|
||||
src/mbgl/text/collision_feature.cpp
|
||||
src/mbgl/text/collision_feature.hpp
|
||||
src/mbgl/text/collision_tile.cpp
|
||||
src/mbgl/text/collision_tile.hpp
|
||||
src/mbgl/text/collision_index.cpp
|
||||
src/mbgl/text/collision_index.hpp
|
||||
src/mbgl/text/cross_tile_symbol_index.cpp
|
||||
@@ -549,7 +545,6 @@ set(MBGL_CORE_FILES
|
||||
src/mbgl/text/glyph_pbf.cpp
|
||||
src/mbgl/text/glyph_pbf.hpp
|
||||
src/mbgl/text/glyph_range.hpp
|
||||
src/mbgl/text/placement_config.hpp
|
||||
src/mbgl/text/placement.cpp
|
||||
src/mbgl/text/placement.hpp
|
||||
src/mbgl/text/quads.cpp
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
#include <mbgl/renderer/frame_history.hpp>
|
||||
#include <mbgl/math/minmax.hpp>
|
||||
#include <mbgl/gl/context.hpp>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
FrameHistory::FrameHistory() {
|
||||
changeOpacities.fill(0);
|
||||
opacities.fill(0);
|
||||
}
|
||||
|
||||
void FrameHistory::record(const TimePoint& now, float zoom, const Duration& duration) {
|
||||
|
||||
int16_t zoomIndex = std::floor(zoom * 10.0);
|
||||
|
||||
if (firstFrame) {
|
||||
changeTimes.fill(now);
|
||||
|
||||
for (int16_t z = 0; z <= zoomIndex; z++) {
|
||||
opacities.data[z] = 255u;
|
||||
}
|
||||
firstFrame = false;
|
||||
}
|
||||
|
||||
if (zoomIndex < previousZoomIndex) {
|
||||
for (int16_t z = zoomIndex + 1; z <= previousZoomIndex; z++) {
|
||||
changeTimes[z] = now;
|
||||
changeOpacities[z] = opacities.data[z];
|
||||
}
|
||||
} else {
|
||||
for (int16_t z = zoomIndex; z > previousZoomIndex; z--) {
|
||||
changeTimes[z] = now;
|
||||
changeOpacities[z] = opacities.data[z];
|
||||
}
|
||||
}
|
||||
|
||||
for (int16_t z = 0; z <= 255; z++) {
|
||||
const std::chrono::duration<float> timeDiff = now - changeTimes[z];
|
||||
const int32_t opacityChange = (duration == Milliseconds(0) ? 1 : (timeDiff / duration)) * 255;
|
||||
const uint8_t opacity = z <= zoomIndex
|
||||
? util::min(255, changeOpacities[z] + opacityChange)
|
||||
: util::max(0, changeOpacities[z] - opacityChange);
|
||||
if (opacities.data[z] != opacity) {
|
||||
opacities.data[z] = opacity;
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (zoomIndex != previousZoomIndex) {
|
||||
previousZoomIndex = zoomIndex;
|
||||
previousTime = now;
|
||||
}
|
||||
|
||||
time = now;
|
||||
}
|
||||
|
||||
bool FrameHistory::needsAnimation(const Duration& duration) const {
|
||||
return (time - previousTime) < duration;
|
||||
}
|
||||
|
||||
void FrameHistory::upload(gl::Context& context, uint32_t unit) {
|
||||
if (!texture) {
|
||||
texture = context.createTexture(opacities, unit);
|
||||
} else if (dirty) {
|
||||
context.updateTexture(*texture, opacities, unit);
|
||||
}
|
||||
dirty = false;
|
||||
}
|
||||
|
||||
void FrameHistory::bind(gl::Context& context, uint32_t unit) {
|
||||
upload(context, unit);
|
||||
context.bindTexture(*texture, unit);
|
||||
}
|
||||
|
||||
bool FrameHistory::isVisible(const float zoom) const {
|
||||
return opacities.data[std::floor(zoom * 10)] != 0;
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
@@ -1,41 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
|
||||
#include <mbgl/util/platform.hpp>
|
||||
#include <mbgl/gl/texture.hpp>
|
||||
#include <mbgl/util/chrono.hpp>
|
||||
#include <mbgl/util/image.hpp>
|
||||
#include <mbgl/util/optional.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
namespace gl {
|
||||
class Context;
|
||||
} // namespace gl
|
||||
|
||||
class FrameHistory {
|
||||
public:
|
||||
FrameHistory();
|
||||
void record(const TimePoint&, float zoom, const Duration&);
|
||||
|
||||
bool needsAnimation(const Duration&) const;
|
||||
void bind(gl::Context&, uint32_t);
|
||||
void upload(gl::Context&, uint32_t);
|
||||
bool isVisible(const float zoom) const;
|
||||
|
||||
private:
|
||||
std::array<TimePoint, 256> changeTimes;
|
||||
std::array<uint8_t, 256> changeOpacities;
|
||||
AlphaImage opacities{ { 256, 1 } };
|
||||
|
||||
int16_t previousZoomIndex = 0;
|
||||
TimePoint previousTime;
|
||||
TimePoint time;
|
||||
bool firstFrame = true;
|
||||
bool dirty = true;
|
||||
|
||||
mbgl::optional<gl::Texture> texture;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <mbgl/renderer/property_evaluation_parameters.hpp>
|
||||
#include <mbgl/renderer/render_tile.hpp>
|
||||
#include <mbgl/renderer/paint_parameters.hpp>
|
||||
#include <mbgl/renderer/frame_history.hpp>
|
||||
#include <mbgl/text/glyph_atlas.hpp>
|
||||
#include <mbgl/programs/programs.hpp>
|
||||
#include <mbgl/programs/symbol_program.hpp>
|
||||
@@ -81,8 +80,6 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) {
|
||||
|
||||
const auto& layout = bucket.layout;
|
||||
|
||||
parameters.frameHistory.bind(parameters.context, 1);
|
||||
|
||||
auto draw = [&] (auto& program,
|
||||
auto&& uniformValues,
|
||||
const auto& buffers,
|
||||
|
||||
@@ -12,7 +12,6 @@ PaintParameters::PaintParameters(gl::Context& context_,
|
||||
const UpdateParameters& updateParameters,
|
||||
const EvaluatedLight& evaluatedLight_,
|
||||
RenderStaticData& staticData_,
|
||||
FrameHistory& frameHistory_,
|
||||
ImageManager& imageManager_,
|
||||
LineAtlas& lineAtlas_)
|
||||
: context(context_),
|
||||
@@ -20,7 +19,6 @@ PaintParameters::PaintParameters(gl::Context& context_,
|
||||
state(updateParameters.transformState),
|
||||
evaluatedLight(evaluatedLight_),
|
||||
staticData(staticData_),
|
||||
frameHistory(frameHistory_),
|
||||
imageManager(imageManager_),
|
||||
lineAtlas(lineAtlas_),
|
||||
mapMode(updateParameters.mode),
|
||||
|
||||
@@ -17,7 +17,6 @@ namespace mbgl {
|
||||
class RendererBackend;
|
||||
class UpdateParameters;
|
||||
class RenderStaticData;
|
||||
class FrameHistory;
|
||||
class Programs;
|
||||
class TransformState;
|
||||
class ImageManager;
|
||||
@@ -33,7 +32,6 @@ public:
|
||||
const UpdateParameters&,
|
||||
const EvaluatedLight&,
|
||||
RenderStaticData&,
|
||||
FrameHistory&,
|
||||
ImageManager&,
|
||||
LineAtlas&);
|
||||
|
||||
@@ -44,7 +42,6 @@ public:
|
||||
const EvaluatedLight& evaluatedLight;
|
||||
|
||||
RenderStaticData& staticData;
|
||||
FrameHistory& frameHistory;
|
||||
ImageManager& imageManager;
|
||||
LineAtlas& lineAtlas;
|
||||
|
||||
|
||||
@@ -255,7 +255,6 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
|
||||
updateParameters,
|
||||
renderLight.getEvaluated(),
|
||||
*staticData,
|
||||
frameHistory,
|
||||
*imageManager,
|
||||
*lineAtlas
|
||||
};
|
||||
@@ -368,9 +367,6 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
|
||||
order.emplace_back(RenderItem { *layer, source });
|
||||
}
|
||||
|
||||
frameHistory.record(parameters.timePoint,
|
||||
parameters.state.getZoom(),
|
||||
parameters.mapMode == MapMode::Continuous ? util::DEFAULT_TRANSITION_DURATION : Milliseconds(0));
|
||||
bool symbolBucketsChanged = false;
|
||||
if (parameters.mapMode == MapMode::Still) {
|
||||
// TODO: Think about right way for symbol index to handle still rendering
|
||||
@@ -418,8 +414,7 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
|
||||
|
||||
parameters.imageManager.upload(parameters.context, 0);
|
||||
parameters.lineAtlas.upload(parameters.context, 0);
|
||||
parameters.frameHistory.upload(parameters.context, 0);
|
||||
|
||||
|
||||
// Update all clipping IDs + upload buckets.
|
||||
for (const auto& entry : renderSources) {
|
||||
if (entry.second->isEnabled()) {
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <mbgl/renderer/renderer.hpp>
|
||||
#include <mbgl/renderer/render_source_observer.hpp>
|
||||
#include <mbgl/renderer/render_light.hpp>
|
||||
#include <mbgl/renderer/frame_history.hpp>
|
||||
#include <mbgl/style/image.hpp>
|
||||
#include <mbgl/style/source.hpp>
|
||||
#include <mbgl/style/layer.hpp>
|
||||
@@ -93,7 +92,6 @@ private:
|
||||
};
|
||||
|
||||
RenderState renderState = RenderState::Never;
|
||||
FrameHistory frameHistory;
|
||||
ZoomHistory zoomHistory;
|
||||
TransformState transformState;
|
||||
|
||||
|
||||
@@ -1,267 +0,0 @@
|
||||
#include <mbgl/text/collision_tile.hpp>
|
||||
#include <mbgl/geometry/feature_index.hpp>
|
||||
#include <mbgl/math/log2.hpp>
|
||||
#include <mbgl/util/constants.hpp>
|
||||
#include <mbgl/util/math.hpp>
|
||||
#include <mbgl/math/minmax.hpp>
|
||||
#include <mbgl/util/intersection_tests.hpp>
|
||||
|
||||
#include <mapbox/geometry/envelope.hpp>
|
||||
#include <mapbox/geometry/multi_point.hpp>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
CollisionTile::CollisionTile(PlacementConfig config_) : config(std::move(config_)) {
|
||||
// Compute the transformation matrix.
|
||||
const float angle_sin = std::sin(config.angle);
|
||||
const float angle_cos = std::cos(config.angle);
|
||||
rotationMatrix = { { angle_cos, -angle_sin, angle_sin, angle_cos } };
|
||||
reverseRotationMatrix = { { angle_cos, angle_sin, -angle_sin, angle_cos } };
|
||||
|
||||
perspectiveRatio =
|
||||
1.0f +
|
||||
0.5f * (util::division(config.cameraToTileDistance, config.cameraToCenterDistance, 1.0f) -
|
||||
1.0f);
|
||||
|
||||
minScale /= perspectiveRatio;
|
||||
maxScale /= perspectiveRatio;
|
||||
|
||||
// We can only approximate here based on the y position of the tile
|
||||
// The shaders calculate a more accurate "incidence_stretch"
|
||||
// at render time to calculate an effective scale for collision
|
||||
// purposes, but we still want to use the yStretch approximation
|
||||
// here because we can't adjust the aspect ratio of the collision
|
||||
// boxes at render time.
|
||||
yStretch = util::max(
|
||||
1.0f, util::division(config.cameraToTileDistance,
|
||||
config.cameraToCenterDistance * std::cos(config.pitch), 1.0f));
|
||||
}
|
||||
|
||||
float CollisionTile::findPlacementScale(const Point<float>& anchor, const CollisionBox& box, const float boxMaxScale, const Point<float>& blockingAnchor, const CollisionBox& blocking) {
|
||||
float minPlacementScale = minScale;
|
||||
|
||||
// Find the lowest scale at which the two boxes can fit side by side without overlapping.
|
||||
// Original algorithm:
|
||||
|
||||
const float s1 = util::division(blocking.x1 - box.x2, anchor.x - blockingAnchor.x,
|
||||
1.0f); // scale at which new box is to the left of old box
|
||||
const float s2 = util::division(blocking.x2 - box.x1, anchor.x - blockingAnchor.x,
|
||||
1.0f); // scale at which new box is to the right of old box
|
||||
const float s3 = util::division((blocking.y1 - box.y2) * yStretch, anchor.y - blockingAnchor.y,
|
||||
1.0f); // scale at which new box is to the top of old box
|
||||
const float s4 = util::division((blocking.y2 - box.y1) * yStretch, anchor.y - blockingAnchor.y,
|
||||
1.0f); // scale at which new box is to the bottom of old box
|
||||
|
||||
float collisionFreeScale = util::min(util::max(s1, s2), util::max(s3, s4));
|
||||
|
||||
if (collisionFreeScale > blocking.maxScale) {
|
||||
// After a box's maxScale the label has shrunk enough that the box is no longer needed to cover it,
|
||||
// so unblock the new box at the scale that the old box disappears.
|
||||
collisionFreeScale = blocking.maxScale;
|
||||
}
|
||||
|
||||
if (collisionFreeScale > boxMaxScale) {
|
||||
// If the box can only be shown after it is visible, then the box can never be shown.
|
||||
// But the label can be shown after this box is not visible.
|
||||
collisionFreeScale = boxMaxScale;
|
||||
}
|
||||
|
||||
if (collisionFreeScale > minPlacementScale &&
|
||||
collisionFreeScale >= blocking.placementScale) {
|
||||
// If this collision occurs at a lower scale than previously found collisions
|
||||
// and the collision occurs while the other label is visible
|
||||
|
||||
// this this is the lowest scale at which the label won't collide with anything
|
||||
minPlacementScale = collisionFreeScale;
|
||||
}
|
||||
|
||||
return minPlacementScale;
|
||||
}
|
||||
|
||||
float CollisionTile::placeFeature(const CollisionFeature& feature, bool allowOverlap, bool avoidEdges) {
|
||||
static const float infinity = std::numeric_limits<float>::infinity();
|
||||
static const std::array<CollisionBox, 4> edges {{
|
||||
// left
|
||||
CollisionBox(Point<float>(0, 0), { 0, 0 }, 0, -infinity, 0, infinity, infinity),
|
||||
// right
|
||||
CollisionBox(Point<float>(util::EXTENT, 0), { 0, 0 }, 0, -infinity, 0, infinity, infinity),
|
||||
// top
|
||||
CollisionBox(Point<float>(0, 0), { 0, 0 }, -infinity, 0, infinity, 0, infinity),
|
||||
// bottom
|
||||
CollisionBox(Point<float>(0, util::EXTENT), { 0, 0 }, -infinity, 0, infinity, 0, infinity)
|
||||
}};
|
||||
|
||||
float minPlacementScale = minScale;
|
||||
|
||||
for (auto& box : feature.boxes) {
|
||||
const auto anchor = util::matrixMultiply(rotationMatrix, box.anchor);
|
||||
|
||||
const float boxMaxScale = box.adjustedMaxScale(rotationMatrix, yStretch);
|
||||
|
||||
if (!allowOverlap) {
|
||||
for (auto it = tree.qbegin(bgi::intersects(getTreeBox(anchor, box))); it != tree.qend(); ++it) {
|
||||
const CollisionBox& blocking = std::get<1>(*it);
|
||||
Point<float> blockingAnchor = util::matrixMultiply(rotationMatrix, blocking.anchor);
|
||||
|
||||
minPlacementScale = util::max(minPlacementScale, findPlacementScale(anchor, box, boxMaxScale, blockingAnchor, blocking));
|
||||
if (minPlacementScale >= maxScale) return minPlacementScale;
|
||||
}
|
||||
}
|
||||
|
||||
if (avoidEdges) {
|
||||
const Point<float> rtl = util::matrixMultiply(reverseRotationMatrix, { box.x1, box.y1 });
|
||||
const Point<float> rtr = util::matrixMultiply(reverseRotationMatrix, { box.x2, box.y1 });
|
||||
const Point<float> rbl = util::matrixMultiply(reverseRotationMatrix, { box.x1, box.y2 });
|
||||
const Point<float> rbr = util::matrixMultiply(reverseRotationMatrix, { box.x2, box.y2 });
|
||||
CollisionBox rotatedBox(box.anchor,
|
||||
box.offset,
|
||||
util::min(rtl.x, rtr.x, rbl.x, rbr.x),
|
||||
util::min(rtl.y, rtr.y, rbl.y, rbr.y),
|
||||
util::max(rtl.x, rtr.x, rbl.x, rbr.x),
|
||||
util::max(rtl.y, rtr.y, rbl.y, rbr.y),
|
||||
boxMaxScale);
|
||||
|
||||
for (auto& blocking : edges) {
|
||||
minPlacementScale = util::max(minPlacementScale, findPlacementScale(box.anchor, rotatedBox, boxMaxScale, blocking.anchor, blocking));
|
||||
if (minPlacementScale >= maxScale) return minPlacementScale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return minPlacementScale;
|
||||
}
|
||||
|
||||
void CollisionTile::insertFeature(CollisionFeature& feature, float minPlacementScale, bool ignorePlacement) {
|
||||
for (auto& box : feature.boxes) {
|
||||
box.placementScale = minPlacementScale;
|
||||
}
|
||||
|
||||
if (minPlacementScale < maxScale) {
|
||||
std::vector<CollisionTreeBox> treeBoxes;
|
||||
for (auto& box : feature.boxes) {
|
||||
CollisionBox adjustedBox = box;
|
||||
box.maxScale = box.adjustedMaxScale(rotationMatrix, yStretch);
|
||||
treeBoxes.emplace_back(getTreeBox(util::matrixMultiply(rotationMatrix, box.anchor), box), std::move(adjustedBox), feature.indexedFeature);
|
||||
}
|
||||
if (ignorePlacement) {
|
||||
ignoredTree.insert(treeBoxes.begin(), treeBoxes.end());
|
||||
} else {
|
||||
tree.insert(treeBoxes.begin(), treeBoxes.end());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// +---------------------------+ As you zoom, the size of the symbol changes
|
||||
// |(x1,y1) | | relative to the tile e.g. when zooming in,
|
||||
// | | | the symbol gets smaller relative to the tile.
|
||||
// | (x1',y1') v |
|
||||
// | +-------+-------+ | The boxes inserted into the tree represents
|
||||
// | | | | | the bounds at the integer zoom level (where
|
||||
// | | | | | the symbol is biggest relative to the tile).
|
||||
// | | | | |
|
||||
// |---->+-------+-------+<----| This happens because placement is updated
|
||||
// | | |(xa,ya)| | once every new integer zoom level e.g.
|
||||
// | | | | | std::floor(oldZoom) != std::floor(newZoom).
|
||||
// | | | | |
|
||||
// | +-------+-------+ | Thus, they don't represent the exact bounds
|
||||
// | ^ (x2',y2') | of the symbol at the current zoom level. For
|
||||
// | | | calculating the bounds at current zoom level
|
||||
// | | (x2,y2)| we must unscale the box using its center as
|
||||
// +---------------------------+ transform origin.
|
||||
Box CollisionTile::getTreeBox(const Point<float>& anchor, const CollisionBox& box, const float scale) {
|
||||
assert(box.x1 <= box.x2 && box.y1 <= box.y2);
|
||||
return Box{
|
||||
// When the 'perspectiveRatio' is high, we're effectively underzooming
|
||||
// the tile because it's in the distance.
|
||||
// In order to detect collisions that only happen while underzoomed,
|
||||
// we have to query a larger portion of the grid.
|
||||
// This extra work is offset by having a lower 'maxScale' bound
|
||||
// Note that this adjustment ONLY affects the bounding boxes
|
||||
// in the grid. It doesn't affect the boxes used for the
|
||||
// minPlacementScale calculations.
|
||||
CollisionPoint{
|
||||
anchor.x + box.x1 / scale * perspectiveRatio,
|
||||
anchor.y + box.y1 / scale * yStretch * perspectiveRatio,
|
||||
},
|
||||
CollisionPoint{
|
||||
anchor.x + box.x2 / scale * perspectiveRatio,
|
||||
anchor.y + box.y2 / scale * yStretch * perspectiveRatio
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
std::vector<IndexedSubfeature> CollisionTile::queryRenderedSymbols(const GeometryCoordinates& queryGeometry, float scale) const {
|
||||
std::vector<IndexedSubfeature> result;
|
||||
if (queryGeometry.empty() || (tree.empty() && ignoredTree.empty())) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Generate a rotated geometry out of the original query geometry.
|
||||
// Scale has already been handled by the prior conversions.
|
||||
GeometryCoordinates polygon;
|
||||
for (const auto& point : queryGeometry) {
|
||||
auto rotated = util::matrixMultiply(rotationMatrix, convertPoint<float>(point));
|
||||
polygon.push_back(convertPoint<int16_t>(rotated));
|
||||
}
|
||||
|
||||
// Predicate for ruling out already seen features.
|
||||
std::unordered_map<std::string, std::unordered_set<std::size_t>> sourceLayerFeatures;
|
||||
auto seenFeature = [&] (const CollisionTreeBox& treeBox) -> bool {
|
||||
const IndexedSubfeature& feature = std::get<2>(treeBox);
|
||||
const auto& seenFeatures = sourceLayerFeatures[feature.sourceLayerName];
|
||||
return seenFeatures.find(feature.index) == seenFeatures.end();
|
||||
};
|
||||
|
||||
// "perspectiveRatio" is a tile-based approximation of how much larger symbols will
|
||||
// be in the distance. It won't line up exactly with the actually rendered symbols
|
||||
// Being exact would require running the collision detection logic in symbol_sdf.vertex
|
||||
// in the CPU
|
||||
const float perspectiveScale = scale / perspectiveRatio;
|
||||
|
||||
// Account for the rounding done when updating symbol shader variables.
|
||||
const float roundedScale = std::pow(2.0f, std::ceil(util::log2(perspectiveScale) * 10.0f) / 10.0f);
|
||||
|
||||
// Check if feature is rendered (collision free) at current scale.
|
||||
auto visibleAtScale = [&] (const CollisionTreeBox& treeBox) -> bool {
|
||||
const CollisionBox& box = std::get<1>(treeBox);
|
||||
return roundedScale >= box.placementScale && roundedScale <= box.adjustedMaxScale(rotationMatrix, yStretch);
|
||||
};
|
||||
|
||||
// Check if query polygon intersects with the feature box at current scale.
|
||||
auto intersectsAtScale = [&] (const CollisionTreeBox& treeBox) -> bool {
|
||||
const CollisionBox& collisionBox = std::get<1>(treeBox);
|
||||
const auto anchor = util::matrixMultiply(rotationMatrix, collisionBox.anchor);
|
||||
|
||||
const int16_t x1 = anchor.x + (collisionBox.x1 / perspectiveScale);
|
||||
const int16_t y1 = anchor.y + (collisionBox.y1 / perspectiveScale) * yStretch;
|
||||
const int16_t x2 = anchor.x + (collisionBox.x2 / perspectiveScale);
|
||||
const int16_t y2 = anchor.y + (collisionBox.y2 / perspectiveScale) * yStretch;
|
||||
auto bbox = GeometryCoordinates {
|
||||
{ x1, y1 }, { x2, y1 }, { x2, y2 }, { x1, y2 }
|
||||
};
|
||||
return util::polygonIntersectsPolygon(polygon, bbox);
|
||||
};
|
||||
|
||||
auto predicates = bgi::satisfies(seenFeature)
|
||||
&& bgi::satisfies(visibleAtScale)
|
||||
&& bgi::satisfies(intersectsAtScale);
|
||||
|
||||
auto queryTree = [&](const auto& tree_) {
|
||||
for (auto it = tree_.qbegin(predicates); it != tree_.qend(); ++it) {
|
||||
const IndexedSubfeature& feature = std::get<2>(*it);
|
||||
auto& seenFeatures = sourceLayerFeatures[feature.sourceLayerName];
|
||||
seenFeatures.insert(feature.index);
|
||||
result.push_back(feature);
|
||||
}
|
||||
};
|
||||
|
||||
queryTree(tree);
|
||||
queryTree(ignoredTree);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
@@ -1,71 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/text/collision_feature.hpp>
|
||||
#include <mbgl/text/placement_config.hpp>
|
||||
#include <mbgl/tile/geometry_tile_data.hpp>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#pragma GCC diagnostic ignored "-Wshadow"
|
||||
#ifdef __clang__
|
||||
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
|
||||
#endif
|
||||
#pragma GCC diagnostic ignored "-Wpragmas"
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-register"
|
||||
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
|
||||
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
|
||||
#ifndef __clang__
|
||||
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||
#pragma GCC diagnostic ignored "-Wmisleading-indentation"
|
||||
#endif
|
||||
#include <boost/geometry.hpp>
|
||||
#include <boost/geometry/geometries/point.hpp>
|
||||
#include <boost/geometry/geometries/box.hpp>
|
||||
#include <boost/geometry/index/rtree.hpp>
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
namespace bg = boost::geometry;
|
||||
namespace bgm = bg::model;
|
||||
namespace bgi = bg::index;
|
||||
using CollisionPoint = bgm::point<float, 2, bg::cs::cartesian>;
|
||||
using Box = bgm::box<CollisionPoint>;
|
||||
using CollisionTreeBox = std::tuple<Box, CollisionBox, IndexedSubfeature>;
|
||||
using Tree = bgi::rtree<CollisionTreeBox, bgi::linear<16, 4>>;
|
||||
|
||||
class IndexedSubfeature;
|
||||
|
||||
class CollisionTile {
|
||||
public:
|
||||
explicit CollisionTile(PlacementConfig);
|
||||
|
||||
float placeFeature(const CollisionFeature&, bool allowOverlap, bool avoidEdges);
|
||||
void insertFeature(CollisionFeature&, float minPlacementScale, bool ignorePlacement);
|
||||
|
||||
std::vector<IndexedSubfeature> queryRenderedSymbols(const GeometryCoordinates&, float scale) const;
|
||||
|
||||
const PlacementConfig config;
|
||||
|
||||
float minScale = 0.5f;
|
||||
float maxScale = 2.0f;
|
||||
float yStretch;
|
||||
|
||||
std::array<float, 4> rotationMatrix;
|
||||
std::array<float, 4> reverseRotationMatrix;
|
||||
|
||||
private:
|
||||
float findPlacementScale(
|
||||
const Point<float>& anchor, const CollisionBox& box, const float boxMaxScale,
|
||||
const Point<float>& blockingAnchor, const CollisionBox& blocking);
|
||||
Box getTreeBox(const Point<float>& anchor, const CollisionBox& box, const float scale = 1.0);
|
||||
|
||||
Tree tree;
|
||||
Tree ignoredTree;
|
||||
|
||||
float perspectiveRatio;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
@@ -1,33 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/constants.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class PlacementConfig {
|
||||
public:
|
||||
PlacementConfig(float angle_ = 0, float pitch_ = 0, float cameraToCenterDistance_ = 0, float cameraToTileDistance_ = 0, bool debug_ = false)
|
||||
: angle(angle_), pitch(pitch_), cameraToCenterDistance(cameraToCenterDistance_), cameraToTileDistance(cameraToTileDistance_), debug(debug_) {
|
||||
}
|
||||
|
||||
bool operator==(const PlacementConfig& rhs) const {
|
||||
return angle == rhs.angle &&
|
||||
pitch == rhs.pitch &&
|
||||
debug == rhs.debug &&
|
||||
((pitch * util::RAD2DEG < 25) ||
|
||||
(cameraToCenterDistance == rhs.cameraToCenterDistance && cameraToTileDistance == rhs.cameraToTileDistance));
|
||||
}
|
||||
|
||||
bool operator!=(const PlacementConfig& rhs) const {
|
||||
return !operator==(rhs);
|
||||
}
|
||||
|
||||
public:
|
||||
float angle;
|
||||
float pitch;
|
||||
float cameraToCenterDistance;
|
||||
float cameraToTileDistance;
|
||||
bool debug;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
Reference in New Issue
Block a user