diff options
author | Chris Loer <chris.loer@gmail.com> | 2017-11-09 13:24:43 -0800 |
---|---|---|
committer | Chris Loer <chris.loer@mapbox.com> | 2017-11-17 10:05:15 -0800 |
commit | 77bfb47fdabbd257272a01bef591d73e8c53c9c7 (patch) | |
tree | 253edfab06524d0626e992e6d31c6c4bba7cbe1f | |
parent | c0cb210ddca1901a956cd68e9142b7fb04183248 (diff) | |
download | qtlocation-mapboxgl-77bfb47fdabbd257272a01bef591d73e8c53c9c7.tar.gz |
[core] Update queryRenderedFeatures to use global CollisionIndex.
-rw-r--r-- | src/mbgl/annotation/render_annotation_source.cpp | 5 | ||||
-rw-r--r-- | src/mbgl/annotation/render_annotation_source.hpp | 3 | ||||
-rw-r--r-- | src/mbgl/geometry/feature_index.cpp | 26 | ||||
-rw-r--r-- | src/mbgl/geometry/feature_index.hpp | 39 | ||||
-rw-r--r-- | src/mbgl/renderer/render_source.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_geojson_source.cpp | 5 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_geojson_source.hpp | 3 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_image_source.cpp | 3 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_image_source.hpp | 3 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_raster_source.cpp | 3 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_raster_source.hpp | 3 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_vector_source.cpp | 5 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_vector_source.hpp | 3 | ||||
-rw-r--r-- | src/mbgl/renderer/tile_pyramid.cpp | 6 | ||||
-rw-r--r-- | src/mbgl/renderer/tile_pyramid.hpp | 3 | ||||
-rw-r--r-- | src/mbgl/tile/tile.cpp | 3 | ||||
-rw-r--r-- | src/mbgl/tile/tile.hpp | 5 |
17 files changed, 84 insertions, 38 deletions
diff --git a/src/mbgl/annotation/render_annotation_source.cpp b/src/mbgl/annotation/render_annotation_source.cpp index ba80be0da0..a0b69af8d5 100644 --- a/src/mbgl/annotation/render_annotation_source.cpp +++ b/src/mbgl/annotation/render_annotation_source.cpp @@ -63,8 +63,9 @@ std::unordered_map<std::string, std::vector<Feature>> RenderAnnotationSource::queryRenderedFeatures(const ScreenLineString& geometry, const TransformState& transformState, const std::vector<const RenderLayer*>& layers, - const RenderedQueryOptions& options) const { - return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options); + const RenderedQueryOptions& options, + const CollisionIndex& collisionIndex) const { + return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options, collisionIndex); } std::vector<Feature> RenderAnnotationSource::querySourceFeatures(const SourceQueryOptions&) const { diff --git a/src/mbgl/annotation/render_annotation_source.hpp b/src/mbgl/annotation/render_annotation_source.hpp index 6209c943f1..aa2578d4e3 100644 --- a/src/mbgl/annotation/render_annotation_source.hpp +++ b/src/mbgl/annotation/render_annotation_source.hpp @@ -27,7 +27,8 @@ public: queryRenderedFeatures(const ScreenLineString& geometry, const TransformState& transformState, const std::vector<const RenderLayer*>& layers, - const RenderedQueryOptions& options) const final; + const RenderedQueryOptions& options, + const CollisionIndex& collisionIndex) const final; std::vector<Feature> querySourceFeatures(const SourceQueryOptions&) const final; diff --git a/src/mbgl/geometry/feature_index.cpp b/src/mbgl/geometry/feature_index.cpp index f7dbbfb8b3..e610e5ba5f 100644 --- a/src/mbgl/geometry/feature_index.cpp +++ b/src/mbgl/geometry/feature_index.cpp @@ -2,7 +2,7 @@ #include <mbgl/renderer/render_layer.hpp> #include <mbgl/renderer/query.hpp> #include <mbgl/renderer/layers/render_symbol_layer.hpp> -#include <mbgl/text/collision_tile.hpp> +#include <mbgl/text/collision_index.hpp> #include <mbgl/util/constants.hpp> #include <mbgl/util/math.hpp> #include <mbgl/math/minmax.hpp> @@ -26,8 +26,9 @@ void FeatureIndex::insert(const GeometryCollection& geometries, const std::string& sourceLayerName, const std::string& bucketName) { for (const auto& ring : geometries) { - grid.insert(IndexedSubfeature { index, sourceLayerName, bucketName, sortIndex++ }, - mapbox::geometry::envelope(ring)); + auto envelope = mapbox::geometry::envelope(ring); + grid.insert(IndexedSubfeature(index, sourceLayerName, bucketName, sortIndex++), + {convertPoint<float>(envelope.min), convertPoint<float>(envelope.max)}); } } @@ -47,9 +48,10 @@ void FeatureIndex::query( const double scale, const RenderedQueryOptions& queryOptions, const GeometryTileData& geometryTileData, - const CanonicalTileID& tileID, + const UnwrappedTileID& tileID, + const std::string& sourceID, const std::vector<const RenderLayer*>& layers, - const CollisionTile* collisionTile, + const CollisionIndex& collisionIndex, const float additionalQueryRadius) const { // Determine query radius @@ -58,7 +60,8 @@ void FeatureIndex::query( // Query the grid index mapbox::geometry::box<int16_t> box = mapbox::geometry::envelope(queryGeometry); - std::vector<IndexedSubfeature> features = grid.query({ box.min - additionalRadius, box.max + additionalRadius }); + std::vector<IndexedSubfeature> features = grid.query({ convertPoint<float>(box.min - additionalRadius), + convertPoint<float>(box.max + additionalRadius) }); std::sort(features.begin(), features.end(), topDown); @@ -69,18 +72,13 @@ void FeatureIndex::query( if (indexedFeature.sortIndex == previousSortIndex) continue; previousSortIndex = indexedFeature.sortIndex; - addFeature(result, indexedFeature, queryGeometry, queryOptions, geometryTileData, tileID, layers, bearing, pixelsToTileUnits); + addFeature(result, indexedFeature, queryGeometry, queryOptions, geometryTileData, tileID.canonical, layers, bearing, pixelsToTileUnits); } - // Query symbol features, if they've been placed. - if (!collisionTile) { - return; - } - - std::vector<IndexedSubfeature> symbolFeatures = collisionTile->queryRenderedSymbols(queryGeometry, scale); + std::vector<IndexedSubfeature> symbolFeatures = collisionIndex.queryRenderedSymbols(queryGeometry, tileID, sourceID); std::sort(symbolFeatures.begin(), symbolFeatures.end(), topDownSymbols); for (const auto& symbolFeature : symbolFeatures) { - addFeature(result, symbolFeature, queryGeometry, queryOptions, geometryTileData, tileID, layers, bearing, pixelsToTileUnits); + addFeature(result, symbolFeature, queryGeometry, queryOptions, geometryTileData, tileID.canonical, layers, bearing, pixelsToTileUnits); } } diff --git a/src/mbgl/geometry/feature_index.hpp b/src/mbgl/geometry/feature_index.hpp index 2ae7da33df..07dc1b1558 100644 --- a/src/mbgl/geometry/feature_index.hpp +++ b/src/mbgl/geometry/feature_index.hpp @@ -2,6 +2,7 @@ #include <mbgl/style/types.hpp> #include <mbgl/tile/geometry_tile_data.hpp> +#include <mbgl/tile/tile_id.hpp> #include <mbgl/util/grid_index.hpp> #include <mbgl/util/feature.hpp> @@ -14,16 +15,43 @@ namespace mbgl { class RenderedQueryOptions; class RenderLayer; -class CollisionTile; -class CanonicalTileID; +class CollisionIndex; class IndexedSubfeature { public: IndexedSubfeature() = delete; - std::size_t index; + IndexedSubfeature(std::size_t index_, std::string sourceLayerName_, std::string bucketName_, size_t sortIndex_) + : index(index_) + , sourceLayerName(std::move(sourceLayerName_)) + , bucketName(std::move(bucketName_)) + , sortIndex(sortIndex_) + , z(0) + , x(0) + , y(0) + {} + + IndexedSubfeature(std::size_t index_, std::string sourceLayerName_, std::string bucketName_, size_t sortIndex_, + std::string sourceID_, uint8_t z_, uint32_t x_, uint32_t y_) + : index(index_) + , sourceLayerName(std::move(sourceLayerName_)) + , bucketName(std::move(bucketName_)) + , sortIndex(std::move(sortIndex_)) + , sourceID(std::move(sourceID_)) + , z(z_) + , x(x_) + , y(y_) + {} + + size_t index; std::string sourceLayerName; std::string bucketName; size_t sortIndex; + + // Only used for symbol features + std::string sourceID; + uint8_t z; + uint32_t x; + uint32_t y; }; class FeatureIndex { @@ -40,9 +68,10 @@ public: const double scale, const RenderedQueryOptions& options, const GeometryTileData&, - const CanonicalTileID&, + const UnwrappedTileID&, + const std::string&, const std::vector<const RenderLayer*>&, - const CollisionTile*, + const CollisionIndex&, const float additionalQueryRadius) const; static optional<GeometryCoordinates> translateQueryGeometry( diff --git a/src/mbgl/renderer/render_source.hpp b/src/mbgl/renderer/render_source.hpp index 8293923ff6..8c84af4f1e 100644 --- a/src/mbgl/renderer/render_source.hpp +++ b/src/mbgl/renderer/render_source.hpp @@ -24,6 +24,7 @@ class SourceQueryOptions; class Tile; class RenderSourceObserver; class TileParameters; +class CollisionIndex; class RenderSource : protected TileObserver { public: @@ -63,7 +64,8 @@ public: queryRenderedFeatures(const ScreenLineString& geometry, const TransformState& transformState, const std::vector<const RenderLayer*>& layers, - const RenderedQueryOptions& options) const = 0; + const RenderedQueryOptions& options, + const CollisionIndex& collisionIndex) const = 0; virtual std::vector<Feature> querySourceFeatures(const SourceQueryOptions&) const = 0; diff --git a/src/mbgl/renderer/sources/render_geojson_source.cpp b/src/mbgl/renderer/sources/render_geojson_source.cpp index 504db78ea3..d07cfcdc41 100644 --- a/src/mbgl/renderer/sources/render_geojson_source.cpp +++ b/src/mbgl/renderer/sources/render_geojson_source.cpp @@ -84,8 +84,9 @@ std::unordered_map<std::string, std::vector<Feature>> RenderGeoJSONSource::queryRenderedFeatures(const ScreenLineString& geometry, const TransformState& transformState, const std::vector<const RenderLayer*>& layers, - const RenderedQueryOptions& options) const { - return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options); + const RenderedQueryOptions& options, + const CollisionIndex& collisionIndex) const { + return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options, collisionIndex); } std::vector<Feature> RenderGeoJSONSource::querySourceFeatures(const SourceQueryOptions& options) const { diff --git a/src/mbgl/renderer/sources/render_geojson_source.hpp b/src/mbgl/renderer/sources/render_geojson_source.hpp index b2e06c68d4..55166ea901 100644 --- a/src/mbgl/renderer/sources/render_geojson_source.hpp +++ b/src/mbgl/renderer/sources/render_geojson_source.hpp @@ -31,7 +31,8 @@ public: queryRenderedFeatures(const ScreenLineString& geometry, const TransformState& transformState, const std::vector<const RenderLayer*>& layers, - const RenderedQueryOptions& options) const final; + const RenderedQueryOptions& options, + const CollisionIndex&) const final; std::vector<Feature> querySourceFeatures(const SourceQueryOptions&) const final; diff --git a/src/mbgl/renderer/sources/render_image_source.cpp b/src/mbgl/renderer/sources/render_image_source.cpp index 9140e01711..b5c42584e0 100644 --- a/src/mbgl/renderer/sources/render_image_source.cpp +++ b/src/mbgl/renderer/sources/render_image_source.cpp @@ -84,7 +84,8 @@ std::unordered_map<std::string, std::vector<Feature>> RenderImageSource::queryRenderedFeatures(const ScreenLineString&, const TransformState&, const std::vector<const RenderLayer*>&, - const RenderedQueryOptions&) const { + const RenderedQueryOptions&, + const CollisionIndex&) const { return std::unordered_map<std::string, std::vector<Feature>> {}; } diff --git a/src/mbgl/renderer/sources/render_image_source.hpp b/src/mbgl/renderer/sources/render_image_source.hpp index 8d80838c3b..72cf4cea61 100644 --- a/src/mbgl/renderer/sources/render_image_source.hpp +++ b/src/mbgl/renderer/sources/render_image_source.hpp @@ -32,7 +32,8 @@ public: queryRenderedFeatures(const ScreenLineString& geometry, const TransformState& transformState, const std::vector<const RenderLayer*>& layers, - const RenderedQueryOptions& options) const final; + const RenderedQueryOptions& options, + const CollisionIndex& collisionIndex) const final; std::vector<Feature> querySourceFeatures(const SourceQueryOptions&) const final; diff --git a/src/mbgl/renderer/sources/render_raster_source.cpp b/src/mbgl/renderer/sources/render_raster_source.cpp index bcd719365d..f11f9b7aed 100644 --- a/src/mbgl/renderer/sources/render_raster_source.cpp +++ b/src/mbgl/renderer/sources/render_raster_source.cpp @@ -74,7 +74,8 @@ std::unordered_map<std::string, std::vector<Feature>> RenderRasterSource::queryRenderedFeatures(const ScreenLineString&, const TransformState&, const std::vector<const RenderLayer*>&, - const RenderedQueryOptions&) const { + const RenderedQueryOptions&, + const CollisionIndex& ) const { return std::unordered_map<std::string, std::vector<Feature>> {}; } diff --git a/src/mbgl/renderer/sources/render_raster_source.hpp b/src/mbgl/renderer/sources/render_raster_source.hpp index e1bf5798ff..25041fde43 100644 --- a/src/mbgl/renderer/sources/render_raster_source.hpp +++ b/src/mbgl/renderer/sources/render_raster_source.hpp @@ -27,7 +27,8 @@ public: queryRenderedFeatures(const ScreenLineString& geometry, const TransformState& transformState, const std::vector<const RenderLayer*>& layers, - const RenderedQueryOptions& options) const final; + const RenderedQueryOptions& options, + const CollisionIndex& collisionIndex) const final; std::vector<Feature> querySourceFeatures(const SourceQueryOptions&) const final; diff --git a/src/mbgl/renderer/sources/render_vector_source.cpp b/src/mbgl/renderer/sources/render_vector_source.cpp index ca3071c6b0..49f8fdff2c 100644 --- a/src/mbgl/renderer/sources/render_vector_source.cpp +++ b/src/mbgl/renderer/sources/render_vector_source.cpp @@ -77,8 +77,9 @@ std::unordered_map<std::string, std::vector<Feature>> RenderVectorSource::queryRenderedFeatures(const ScreenLineString& geometry, const TransformState& transformState, const std::vector<const RenderLayer*>& layers, - const RenderedQueryOptions& options) const { - return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options); + const RenderedQueryOptions& options, + const CollisionIndex& collisionIndex) const { + return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options, collisionIndex); } std::vector<Feature> RenderVectorSource::querySourceFeatures(const SourceQueryOptions& options) const { diff --git a/src/mbgl/renderer/sources/render_vector_source.hpp b/src/mbgl/renderer/sources/render_vector_source.hpp index ac319a167e..4a992e854f 100644 --- a/src/mbgl/renderer/sources/render_vector_source.hpp +++ b/src/mbgl/renderer/sources/render_vector_source.hpp @@ -27,7 +27,8 @@ public: queryRenderedFeatures(const ScreenLineString& geometry, const TransformState& transformState, const std::vector<const RenderLayer*>& layers, - const RenderedQueryOptions& options) const final; + const RenderedQueryOptions& options, + const CollisionIndex& collisionIndex) const final; std::vector<Feature> querySourceFeatures(const SourceQueryOptions&) const final; diff --git a/src/mbgl/renderer/tile_pyramid.cpp b/src/mbgl/renderer/tile_pyramid.cpp index f3ee787442..fae16c9ce6 100644 --- a/src/mbgl/renderer/tile_pyramid.cpp +++ b/src/mbgl/renderer/tile_pyramid.cpp @@ -208,7 +208,8 @@ void TilePyramid::update(const std::vector<Immutable<style::Layer::Impl>>& layer std::unordered_map<std::string, std::vector<Feature>> TilePyramid::queryRenderedFeatures(const ScreenLineString& geometry, const TransformState& transformState, const std::vector<const RenderLayer*>& layers, - const RenderedQueryOptions& options) const { + const RenderedQueryOptions& options, + const CollisionIndex& collisionIndex) const { std::unordered_map<std::string, std::vector<Feature>> result; if (renderTiles.empty() || geometry.empty()) { return result; @@ -251,7 +252,8 @@ std::unordered_map<std::string, std::vector<Feature>> TilePyramid::queryRendered tileSpaceQueryGeometry, transformState, layers, - options); + options, + collisionIndex); } return result; diff --git a/src/mbgl/renderer/tile_pyramid.hpp b/src/mbgl/renderer/tile_pyramid.hpp index ac4572b103..feab8a838c 100644 --- a/src/mbgl/renderer/tile_pyramid.hpp +++ b/src/mbgl/renderer/tile_pyramid.hpp @@ -51,7 +51,8 @@ public: queryRenderedFeatures(const ScreenLineString& geometry, const TransformState& transformState, const std::vector<const RenderLayer*>&, - const RenderedQueryOptions& options) const; + const RenderedQueryOptions& options, + const CollisionIndex& collisionIndex) const; std::vector<Feature> querySourceFeatures(const SourceQueryOptions&) const; diff --git a/src/mbgl/tile/tile.cpp b/src/mbgl/tile/tile.cpp index f36a472e72..85899a98cb 100644 --- a/src/mbgl/tile/tile.cpp +++ b/src/mbgl/tile/tile.cpp @@ -34,7 +34,8 @@ void Tile::queryRenderedFeatures( const GeometryCoordinates&, const TransformState&, const std::vector<const RenderLayer*>&, - const RenderedQueryOptions&) {} + const RenderedQueryOptions&, + const CollisionIndex&) {} void Tile::querySourceFeatures( std::vector<Feature>&, diff --git a/src/mbgl/tile/tile.hpp b/src/mbgl/tile/tile.hpp index 65a497aaae..b4b50b93ee 100644 --- a/src/mbgl/tile/tile.hpp +++ b/src/mbgl/tile/tile.hpp @@ -27,6 +27,8 @@ class RenderLayer; class RenderedQueryOptions; class SourceQueryOptions; +class CollisionIndex; + namespace gl { class Context; } // namespace gl @@ -55,7 +57,8 @@ public: const GeometryCoordinates& queryGeometry, const TransformState&, const std::vector<const RenderLayer*>&, - const RenderedQueryOptions& options); + const RenderedQueryOptions& options, + const CollisionIndex&); virtual void querySourceFeatures( std::vector<Feature>& result, |