From 9faf543680190e91f54ef2f26c6a619a88ae1e19 Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Wed, 4 Mar 2015 13:37:03 -0800 Subject: [PATCH] refs #928: bookmarking working build of refactor --- .../{geometry.hpp => pbf_geometry.hpp} | 12 +- src/mbgl/map/geometry_tile.cpp | 36 +++- src/mbgl/map/geometry_tile.hpp | 56 +++--- src/mbgl/map/tile_parser.cpp | 28 +-- src/mbgl/map/tile_parser.hpp | 9 +- src/mbgl/map/vector_tile.cpp | 180 ++++++++++-------- src/mbgl/map/vector_tile.hpp | 48 ++--- src/mbgl/renderer/fill_bucket.cpp | 28 +-- src/mbgl/renderer/fill_bucket.hpp | 4 +- src/mbgl/renderer/line_bucket.cpp | 31 +-- src/mbgl/renderer/line_bucket.hpp | 5 +- src/mbgl/renderer/symbol_bucket.cpp | 29 ++- src/mbgl/renderer/symbol_bucket.hpp | 10 +- 13 files changed, 233 insertions(+), 243 deletions(-) rename src/mbgl/geometry/{geometry.hpp => pbf_geometry.hpp} (83%) diff --git a/src/mbgl/geometry/geometry.hpp b/src/mbgl/geometry/pbf_geometry.hpp similarity index 83% rename from src/mbgl/geometry/geometry.hpp rename to src/mbgl/geometry/pbf_geometry.hpp index 484d17b36da..46380e6fecd 100644 --- a/src/mbgl/geometry/geometry.hpp +++ b/src/mbgl/geometry/pbf_geometry.hpp @@ -1,5 +1,5 @@ -#ifndef MBGL_GEOMETRY_GEOMETRY -#define MBGL_GEOMETRY_GEOMETRY +#ifndef MBGL_GEOMETRY_PBF_GEOMETRY +#define MBGL_GEOMETRY_PBF_GEOMETRY #include #include @@ -8,10 +8,10 @@ namespace mbgl { -class Geometry : private util::noncopyable { +class PBFGeometry : private util::noncopyable { public: - inline explicit Geometry(pbf& data); + inline explicit PBFGeometry(pbf& data); enum command : uint8_t { end = 0, @@ -30,14 +30,14 @@ class Geometry : private util::noncopyable { int32_t ox, oy; }; -Geometry::Geometry(pbf& data_) +PBFGeometry::PBFGeometry(pbf& data_) : data(data_), cmd(1), length(0), x(0), y(0), ox(0), oy(0) {} -Geometry::command Geometry::next(int32_t &rx, int32_t &ry) { +PBFGeometry::command PBFGeometry::next(int32_t &rx, int32_t &ry) { if (data.data < data.end) { if (length == 0) { uint32_t cmd_length = static_cast(data.varint()); diff --git a/src/mbgl/map/geometry_tile.cpp b/src/mbgl/map/geometry_tile.cpp index 53272b10c6b..b337cd7c954 100644 --- a/src/mbgl/map/geometry_tile.cpp +++ b/src/mbgl/map/geometry_tile.cpp @@ -15,15 +15,39 @@ std::ostream& mbgl::operator<<(std::ostream& os, const GeometryFeatureType& type } } +GeometryTileFeature::GeometryTileFeature() {} + +Geometry GeometryTileFeature::nextGeometry() { + Geometry result; + result.set(); + return result; +} + +std::ostream& mbgl::operator<<(std::ostream& os, const GeometryTileFeature& feature) { + os << "Feature(" << feature.id << "): " << feature.type << std::endl; + for (const auto& prop : feature.properties) { + os << " - " << prop.first << ": " << prop.second << std::endl; + } + return os; +} + +GeometryFilteredTileLayer::GeometryFilteredTileLayer(const GeometryTileLayer& layer_, const FilterExpression& filterExpression_) + : layer(layer_), + filterExpression(filterExpression_) {} + +GeometryTileFeature GeometryFilteredTileLayer::nextMatchingFeature() { + GeometryTileFeature result; + result.type = GeometryFeatureType::Unknown; + return result; +} + +GeometryTileFeature GeometryTileLayer::nextFeature() { + return GeometryTileFeature(); +} + GeometryTile& GeometryTile::operator=(GeometryTile&& other) { if (this != &other) { layers.swap(other.layers); } return *this; } - -template -GeometryFilteredTileLayer::iterator::iterator(const GeometryFilteredTileLayer& parent_) - : parent(parent_) { - operator++(); -} diff --git a/src/mbgl/map/geometry_tile.hpp b/src/mbgl/map/geometry_tile.hpp index 6ca2b0eb569..7d8698d13e8 100644 --- a/src/mbgl/map/geometry_tile.hpp +++ b/src/mbgl/map/geometry_tile.hpp @@ -5,18 +5,19 @@ #include #include #include +#include +#include #include #include #include #include +#include #include #include namespace mbgl { -class GeometryTileLayer; - enum class GeometryFeatureType { Unknown = 0, Point = 1, @@ -24,58 +25,54 @@ enum class GeometryFeatureType { Polygon = 3 }; +typedef Coordinate GeometryPoint; +typedef std::vector GeometryLine; +typedef std::vector GeometryPolygon; + +using Geometry = mapbox::util::variant; + std::ostream& operator<<(std::ostream&, const GeometryFeatureType& type); -template +class GeometryTileLayer; + class GeometryTileFeature { +public: + GeometryTileFeature(); + + virtual Geometry nextGeometry(); + public: uint64_t id = 0; GeometryFeatureType type = GeometryFeatureType::Unknown; std::map properties; - T geometries; }; -template -std::ostream& operator<<(std::ostream&, const GeometryTileFeature& feature); +std::ostream& operator<<(std::ostream&, const GeometryTileFeature& feature); template class GeometryTileTagExtractor { public: GeometryTileTagExtractor(const GeometryTileLayer&); - void setTags(const T&); - virtual mapbox::util::optional getValue(const std::string &key) const; + inline void setTags(const T& tags_) { tags = tags_; } + mapbox::util::optional getValue(const std::string &key) const; + inline void setType(GeometryFeatureType type_) { type = type_; } - GeometryFeatureType getType() const { return type; } + inline GeometryFeatureType getType() const { return type; } protected: - const GeometryTileLayer &layer; + const GeometryTileLayer& layer; + T tags; GeometryFeatureType type = GeometryFeatureType::Unknown; }; - -template class GeometryFilteredTileLayer { -public: - class iterator { - public: - iterator(const GeometryFilteredTileLayer&); - virtual void operator++(); - virtual bool operator!=(const iterator& other) const; - virtual const T& operator*() const; - - protected: - const GeometryFilteredTileLayer& parent; - bool valid = false; - }; - public: GeometryFilteredTileLayer(const GeometryTileLayer&, const FilterExpression&); - iterator begin() const; - iterator end() const; + virtual GeometryTileFeature nextMatchingFeature(); -public: +protected: const GeometryTileLayer& layer; const FilterExpression& filterExpression; }; @@ -83,6 +80,9 @@ class GeometryFilteredTileLayer { std::ostream& operator<<(std::ostream&, const PositionedGlyph&); class GeometryTileLayer { +public: + virtual GeometryTileFeature nextFeature(); + public: std::string name; uint32_t extent = 4096; diff --git a/src/mbgl/map/tile_parser.cpp b/src/mbgl/map/tile_parser.cpp index 43e754978bb..de9c5a82e0b 100644 --- a/src/mbgl/map/tile_parser.cpp +++ b/src/mbgl/map/tile_parser.cpp @@ -189,7 +189,7 @@ std::unique_ptr TileParser::createBucket(const StyleBucket &bucketDesc) auto layer_it = vectorTile.layers.find(bucketDesc.source_layer); if (layer_it != vectorTile.layers.end()) { - const VectorTileLayer &layer = layer_it->second; + const GeometryTileLayer &layer = layer_it->second; if (bucketDesc.type == StyleLayerType::Fill) { return createFillBucket(layer, bucketDesc); } else if (bucketDesc.type == StyleLayerType::Line) { @@ -213,24 +213,24 @@ std::unique_ptr TileParser::createBucket(const StyleBucket &bucketDesc) } template -void TileParser::addBucketGeometries(Bucket& bucket, const VectorTileLayer& layer, const FilterExpression &filter) { - FilteredVectorTileLayer filtered_layer(layer, filter); - for (pbf feature : filtered_layer) { +void TileParser::addBucketGeometries(Bucket& bucket, const GeometryTileLayer& layer, const FilterExpression &filter) { + GeometryFilteredTileLayer filtered_layer(layer, filter); + GeometryTileFeature feature = filtered_layer.nextMatchingFeature(); + while (feature.type != GeometryFeatureType::Unknown) { if (obsolete()) return; - while (feature.next(4)) { // geometry - pbf geometry_pbf = feature.message(); - if (geometry_pbf) { - bucket->addGeometry(geometry_pbf); - } else if (debug::tileParseWarnings) { - fprintf(stderr, "[WARNING] geometry is empty\n"); - } + Geometry geometry = feature.nextGeometry(); + while (!geometry.is()) { + bucket->addGeometry(geometry); + geometry = feature.nextGeometry(); } + + feature = filtered_layer.nextMatchingFeature(); } } -std::unique_ptr TileParser::createFillBucket(const VectorTileLayer &layer, +std::unique_ptr TileParser::createFillBucket(const GeometryTileLayer &layer, const StyleBucket &bucket_desc) { auto fill = parseStyleLayoutFill(bucket_desc, tile.id.z); auto bucket = util::make_unique(std::move(fill), @@ -241,7 +241,7 @@ std::unique_ptr TileParser::createFillBucket(const VectorTileLayer &laye return obsolete() ? nullptr : std::move(bucket); } -std::unique_ptr TileParser::createLineBucket(const VectorTileLayer &layer, +std::unique_ptr TileParser::createLineBucket(const GeometryTileLayer &layer, const StyleBucket &bucket_desc) { auto line = parseStyleLayoutLine(bucket_desc, tile.id.z); auto bucket = util::make_unique(std::move(line), @@ -252,7 +252,7 @@ std::unique_ptr TileParser::createLineBucket(const VectorTileLayer &laye return obsolete() ? nullptr : std::move(bucket); } -std::unique_ptr TileParser::createSymbolBucket(const VectorTileLayer &layer, +std::unique_ptr TileParser::createSymbolBucket(const GeometryTileLayer &layer, const StyleBucket &bucket_desc) { auto symbol = parseStyleLayoutSymbol(bucket_desc, tile.id.z); auto bucket = util::make_unique(std::move(symbol), *collision); diff --git a/src/mbgl/map/tile_parser.hpp b/src/mbgl/map/tile_parser.hpp index 228557846c6..841ae1749c1 100644 --- a/src/mbgl/map/tile_parser.hpp +++ b/src/mbgl/map/tile_parser.hpp @@ -1,6 +1,7 @@ #ifndef MBGL_MAP_TILE_PARSER #define MBGL_MAP_TILE_PARSER +#include #include #include #include @@ -52,11 +53,11 @@ class TileParser : private util::noncopyable void parseStyleLayers(util::ptr group); std::unique_ptr createBucket(const StyleBucket& bucketDesc); - std::unique_ptr createFillBucket(const VectorTileLayer& layer, const StyleBucket& bucketDesc); - std::unique_ptr createLineBucket(const VectorTileLayer& layer, const StyleBucket& bucketDesc); - std::unique_ptr createSymbolBucket(const VectorTileLayer& layer, const StyleBucket& bucketDesc); + std::unique_ptr createFillBucket(const GeometryTileLayer& layer, const StyleBucket& bucketDesc); + std::unique_ptr createLineBucket(const GeometryTileLayer& layer, const StyleBucket& bucketDesc); + std::unique_ptr createSymbolBucket(const GeometryTileLayer& layer, const StyleBucket& bucketDesc); - template void addBucketGeometries(Bucket& bucket, const VectorTileLayer& layer, const FilterExpression& filter); + template void addBucketGeometries(Bucket& bucket, const GeometryTileLayer& layer, const FilterExpression& filter); private: const VectorTile vectorTile; diff --git a/src/mbgl/map/vector_tile.cpp b/src/mbgl/map/vector_tile.cpp index af0c2ac07b1..89f20a75423 100644 --- a/src/mbgl/map/vector_tile.cpp +++ b/src/mbgl/map/vector_tile.cpp @@ -1,17 +1,19 @@ #include +#include #include +#include #include using namespace mbgl; -VectorTileFeature::VectorTileFeature(pbf feature, const VectorTileLayer& layer) { - while (feature.next()) { - if (feature.tag == 1) { // id - id = feature.varint(); - } else if (feature.tag == 2) { // tags +VectorTileFeature::VectorTileFeature(pbf feature_pbf, const GeometryTileLayer& layer) { + while (feature_pbf.next()) { + if (feature_pbf.tag == 1) { // id + id = feature_pbf.varint(); + } else if (feature_pbf.tag == 2) { // tags // tags are packed varints. They should have an even length. - pbf tags = feature.message(); + pbf tags = feature_pbf.message(); while (tags) { uint32_t tag_key = tags.varint(); @@ -30,22 +32,64 @@ VectorTileFeature::VectorTileFeature(pbf feature, const VectorTileLayer& layer) throw std::runtime_error("uneven number of feature tag ids"); } } - } else if (feature.tag == 3) { // type - type = (GeometryFeatureType)feature.varint(); - } else if (feature.tag == 4) { // geometry - geometries = feature.message(); + } else if (feature_pbf.tag == 3) { // type + type = (GeometryFeatureType)feature_pbf.varint(); + } else if (feature_pbf.tag == 4) { // geometry + geometry_pbf = feature_pbf.message(); } else { - feature.skip(); + feature_pbf.skip(); } } } -std::ostream& mbgl::operator<<(std::ostream& os, const GeometryTileFeature& feature) { - os << "Feature(" << feature.id << "): " << feature.type << std::endl; - for (const auto& prop : feature.properties) { - os << " - " << prop.first << ": " << prop.second << std::endl; +Geometry VectorTileFeature::nextGeometry() { + pbf current_geometry_pbf = geometry_pbf.message(); + PBFGeometry current_geometry(current_geometry_pbf); + int32_t x, y; + Geometry result; + result.set(); + + if (multigeometry || geometry_pbf.next(4)) { + if (type == GeometryFeatureType::Point) { + current_geometry.next(x, y); + GeometryPoint point(x, y); + result.set(point); + } else if (type == GeometryFeatureType::LineString) { + GeometryLine line; + PBFGeometry::command cmd; + while ((cmd = current_geometry.next(x, y)) != PBFGeometry::end) { + if (cmd == PBFGeometry::move_to) { + multigeometry = true; + result.set(line); + break; + } else { + line.emplace_back(x, y); + } + } + if (!multigeometry) { + result.set(line); + } + } else if (type == GeometryFeatureType::Polygon) { + GeometryPolygon polygon; + PBFGeometry::command cmd; + while ((cmd = current_geometry.next(x, y)) != PBFGeometry::end) { + if (cmd == PBFGeometry::move_to) { + multigeometry = true; + result.set(polygon); + break; + } else { +// polygon.emplace_back(x, y); + } + } + if (!multigeometry) { + result.set(polygon); + } + } else { + throw std::runtime_error("unrecognized geometry type"); + } } - return os; + + return std::move(result); } VectorTile::VectorTile(pbf tile) { @@ -59,51 +103,34 @@ VectorTile::VectorTile(pbf tile) { } } -VectorTileLayer::VectorTileLayer(pbf layer) : layer_pbf(layer) { - while (layer.next()) { - if (layer.tag == 1) { // name - name = layer.string(); - } else if (layer.tag == 3) { // keys - keys.emplace_back(layer.string()); +VectorTileLayer::VectorTileLayer(pbf layer) : feature_pbf(layer) { + while (feature_pbf.next()) { + if (feature_pbf.tag == 1) { // name + name = feature_pbf.string(); + } else if (feature_pbf.tag == 3) { // keys + keys.emplace_back(feature_pbf.string()); key_index.emplace(keys.back(), keys.size() - 1); - } else if (layer.tag == 4) { // values - values.emplace_back(std::move(parseValue(layer.message()))); - } else if (layer.tag == 5) { // extent - extent = layer.varint(); + } else if (feature_pbf.tag == 4) { // values + values.emplace_back(std::move(parseValue(feature_pbf.message()))); + } else if (feature_pbf.tag == 5) { // extent + extent = feature_pbf.varint(); } else { - layer.skip(); + feature_pbf.skip(); } } } FilteredVectorTileLayer::FilteredVectorTileLayer(const VectorTileLayer& layer_, const FilterExpression& filterExpression_) - : GeometryFilteredTileLayer(layer_, filterExpression_) {} - -FilteredVectorTileLayer::iterator FilteredVectorTileLayer::begin() const { - const VectorTileLayer *layer_ = static_cast(&layer); - - return FilteredVectorTileLayer::iterator(*this, layer_->layer_pbf); -} - -FilteredVectorTileLayer::iterator FilteredVectorTileLayer::end() const { - const VectorTileLayer *layer_ = static_cast(&layer); - - return FilteredVectorTileLayer::iterator(*this, pbf(layer_->layer_pbf.end, 0)); + : GeometryFilteredTileLayer(layer_, filterExpression_) { + feature_pbf = layer_.feature_pbf; } -FilteredVectorTileLayer::iterator::iterator(const FilteredVectorTileLayer& parent_, const pbf& data_pbf_) - : GeometryFilteredTileLayer::iterator(parent_), - feature_pbf(pbf()), - data_pbf(data_pbf_) {} - -VectorTileTagExtractor::VectorTileTagExtractor(const VectorTileLayer& layer_) - : GeometryTileTagExtractor(layer_) {} - -void VectorTileTagExtractor::setTags(const pbf& pbf) { - tags_pbf = pbf; -} +template <> +GeometryTileTagExtractor::GeometryTileTagExtractor(const GeometryTileLayer& layer_) + : layer(layer_) {} -mapbox::util::optional VectorTileTagExtractor::getValue(const std::string& key) const { +template <> +mapbox::util::optional GeometryTileTagExtractor::getValue(const std::string& key) const { if (key == "$type") { return Value(uint64_t(type)); } @@ -116,7 +143,7 @@ mapbox::util::optional VectorTileTagExtractor::getValue(const std::string // Now loop through all the key/value pair tags. // tags are packed varints. They should have an even length. - pbf tags_pbf_ = tags_pbf; + pbf tags_pbf_ = tags; uint32_t tag_key, tag_val; while (tags_pbf_) { tag_key = tags_pbf_.varint(); @@ -142,43 +169,40 @@ mapbox::util::optional VectorTileTagExtractor::getValue(const std::string return value; } -template bool mbgl::evaluate(const FilterExpression&, const VectorTileTagExtractor&); +template bool mbgl::evaluate(const FilterExpression&, const GeometryTileTagExtractor&); -void FilteredVectorTileLayer::iterator::operator++() { - valid = false; +GeometryTileFeature FilteredVectorTileLayer::nextMatchingFeature() { + GeometryTileFeature result; - const FilterExpression &expression = parent.filterExpression; + if (feature_pbf.next(2)) { + pbf current_feature_pbf = feature_pbf.message(); - while (data_pbf.next(2)) { // feature - feature_pbf = data_pbf.message(); - pbf feature_pbf_ = feature_pbf; + GeometryTileTagExtractor extractor(layer); - GeometryTileTagExtractor extractor(parent.layer); - - // Retrieve the basic information - while (feature_pbf_.next()) { - if (feature_pbf_.tag == 2) { // tags - extractor.setTags(feature_pbf.message()); - } else if (feature_pbf_.tag == 3) { // geometry type - extractor.setType(GeometryFeatureType(feature_pbf_.varint())); + while (current_feature_pbf.next()) { + if (current_feature_pbf.tag == 2) { // tags + extractor.setTags(current_feature_pbf); + } else if (current_feature_pbf.tag == 3) { // geometry type + extractor.setType(GeometryFeatureType(current_feature_pbf.varint())); } else { - feature_pbf_.skip(); + current_feature_pbf.skip(); } } - if (evaluate(expression, extractor)) { - valid = true; - return; // data loop - } else { - valid = false; + if (evaluate(filterExpression, extractor)) { + result = VectorTileFeature(current_feature_pbf.message(), layer); } } -} -bool FilteredVectorTileLayer::iterator::operator!=(const iterator& other) const { - return !(data_pbf.data == other.data_pbf.data && data_pbf.end == other.data_pbf.end && valid == other.valid); + return std::move(result); } -const pbf& FilteredVectorTileLayer::iterator:: operator*() const { - return feature_pbf; +GeometryTileFeature VectorTileLayer::nextFeature() { + GeometryTileFeature result; + + if (feature_pbf.next(2)) { + result = VectorTileFeature(feature_pbf.message(), *this); + } + + return std::move(result); } diff --git a/src/mbgl/map/vector_tile.hpp b/src/mbgl/map/vector_tile.hpp index bfa9e086abd..f83eebb1edd 100644 --- a/src/mbgl/map/vector_tile.hpp +++ b/src/mbgl/map/vector_tile.hpp @@ -2,6 +2,7 @@ #define MBGL_MAP_VECTOR_TILE #include +#include #include #include @@ -9,54 +10,37 @@ namespace mbgl { class VectorTileLayer; -class VectorTileFeature : public GeometryTileFeature { +class VectorTileFeature : public GeometryTileFeature { public: - VectorTileFeature(pbf, const VectorTileLayer&); + VectorTileFeature(pbf, const GeometryTileLayer&); + + Geometry nextGeometry(); private: - const pbf feature_pbf; + pbf geometry_pbf; + bool multigeometry = false; }; -std::ostream& operator<<(std::ostream&, const GeometryTileFeature&); - -class VectorTileTagExtractor : public GeometryTileTagExtractor { +class FilteredVectorTileLayer : public GeometryFilteredTileLayer { public: - VectorTileTagExtractor(const VectorTileLayer&); + FilteredVectorTileLayer(const VectorTileLayer&, const FilterExpression&); - void setTags(const pbf&); - mapbox::util::optional getValue(const std::string &key) const; + GeometryTileFeature nextMatchingFeature(); private: - pbf tags_pbf; -}; - -class FilteredVectorTileLayer : public GeometryFilteredTileLayer { -public: - class iterator : public GeometryFilteredTileLayer::iterator { - public: - iterator(const FilteredVectorTileLayer&, const pbf&); - void operator++(); - bool operator!=(const iterator& other) const; - const pbf& operator*() const; - - private: - pbf feature_pbf; - pbf data_pbf; - }; + pbf feature_pbf; -public: - FilteredVectorTileLayer(const VectorTileLayer&, const FilterExpression&); - - iterator begin() const; - iterator end() const; }; class VectorTileLayer : public GeometryTileLayer { + friend class FilteredVectorTileLayer; public: VectorTileLayer(pbf); -public: - const pbf layer_pbf; + GeometryTileFeature nextFeature(); + +private: + pbf feature_pbf; }; class VectorTile : public GeometryTile { diff --git a/src/mbgl/renderer/fill_bucket.cpp b/src/mbgl/renderer/fill_bucket.cpp index fca4ee31350..8796424c7af 100644 --- a/src/mbgl/renderer/fill_bucket.cpp +++ b/src/mbgl/renderer/fill_bucket.cpp @@ -1,17 +1,12 @@ #include #include #include -#include - #include #include #include -#include #include - #include - #include struct geometry_too_long_exception : std::exception {}; @@ -69,24 +64,13 @@ FillBucket::~FillBucket() { } } -void FillBucket::addGeometry(pbf& geom) { - Geometry::command cmd; - - Coordinate coord; - Geometry geometry(geom); - int32_t x, y; - while ((cmd = geometry.next(x, y)) != Geometry::end) { - if (cmd == Geometry::move_to) { - if (line.size()) { - clipper.AddPath(line, ClipperLib::ptSubject, true); - line.clear(); - hasVertices = true; - } - } - line.emplace_back(x, y); - } +void FillBucket::addGeometry(const Geometry& fill) { + const GeometryPolygon& polygon = fill.get(); - if (line.size()) { + for (auto line_it = polygon.begin(); line_it != polygon.end(); line_it++) { + for (auto point_it = line_it->begin(); point_it != line_it->end(); point_it++) { + line.emplace_back(point_it->x, point_it->y); + } clipper.AddPath(line, ClipperLib::ptSubject, true); line.clear(); hasVertices = true; diff --git a/src/mbgl/renderer/fill_bucket.hpp b/src/mbgl/renderer/fill_bucket.hpp index 0e3f38cd500..b2b56852e99 100644 --- a/src/mbgl/renderer/fill_bucket.hpp +++ b/src/mbgl/renderer/fill_bucket.hpp @@ -2,6 +2,7 @@ #define MBGL_RENDERER_FILLBUCKET #include +#include #include #include #include @@ -27,7 +28,6 @@ class BucketDescription; class OutlineShader; class PlainShader; class PatternShader; -struct pbf; class FillBucket : public Bucket { @@ -48,7 +48,7 @@ class FillBucket : public Bucket { virtual void render(Painter& painter, util::ptr layer_desc, const Tile::ID& id, const mat4 &matrix); virtual bool hasData() const; - void addGeometry(pbf& data); + void addGeometry(const Geometry& fill); void tessellate(); void drawElements(PlainShader& shader); diff --git a/src/mbgl/renderer/line_bucket.cpp b/src/mbgl/renderer/line_bucket.cpp index e181ac77b4e..d14b86f2dc0 100644 --- a/src/mbgl/renderer/line_bucket.cpp +++ b/src/mbgl/renderer/line_bucket.cpp @@ -1,12 +1,9 @@ #include -#include -#include +#include #include #include #include -#include - #include #include #include @@ -37,28 +34,6 @@ LineBucket::~LineBucket() { // Do not remove. header file only contains forward definitions to unique pointers. } - -void LineBucket::addGeometry(pbf& geom) { - std::vector line; - Geometry::command cmd; - - Coordinate coord; - Geometry geometry(geom); - int32_t x, y; - while ((cmd = geometry.next(x, y)) != Geometry::end) { - if (cmd == Geometry::move_to) { - if (!line.empty()) { - addGeometry(line); - line.clear(); - } - } - line.emplace_back(x, y); - } - if (line.size()) { - addGeometry(line); - } -} - struct TriangleElement { TriangleElement(uint16_t a_, uint16_t b_, uint16_t c_) : a(a_), b(b_), c(c_) {} uint16_t a, b, c; @@ -66,7 +41,9 @@ struct TriangleElement { typedef uint16_t PointElement; -void LineBucket::addGeometry(const std::vector& vertices) { +void LineBucket::addGeometry(const Geometry &line) { + const GeometryLine& vertices = line.get(); + auto &layout = *styleLayout; // TODO: use roundLimit // const float roundLimit = geometry.round_limit; diff --git a/src/mbgl/renderer/line_bucket.hpp b/src/mbgl/renderer/line_bucket.hpp index 3f022ce0ef7..7bbb495edd9 100644 --- a/src/mbgl/renderer/line_bucket.hpp +++ b/src/mbgl/renderer/line_bucket.hpp @@ -2,6 +2,7 @@ #define MBGL_RENDERER_LINEBUCKET #include +#include #include #include #include @@ -20,7 +21,6 @@ class LineShader; class LinejoinShader; class LineSDFShader; class LinepatternShader; -struct pbf; class LineBucket : public Bucket { typedef ElementGroup<3> triangle_group_type; @@ -36,8 +36,7 @@ class LineBucket : public Bucket { virtual void render(Painter& painter, util::ptr layer_desc, const Tile::ID& id, const mat4 &matrix); virtual bool hasData() const; - void addGeometry(pbf& data); - void addGeometry(const std::vector& line); + void addGeometry(const Geometry& line); bool hasPoints() const; diff --git a/src/mbgl/renderer/symbol_bucket.cpp b/src/mbgl/renderer/symbol_bucket.cpp index 25eecfc622f..0380c2e1ad6 100644 --- a/src/mbgl/renderer/symbol_bucket.cpp +++ b/src/mbgl/renderer/symbol_bucket.cpp @@ -1,10 +1,10 @@ -#include #include +#include +#include #include #include #include #include -#include #include #include #include @@ -47,7 +47,7 @@ void SymbolBucket::addGlyphsToAtlas(uint64_t tileid, const std::string stackname glyphAtlas.addGlyphs(tileid, text, stackname, fontStack,face); } -std::vector SymbolBucket::processFeatures(const VectorTileLayer &layer, +std::vector SymbolBucket::processFeatures(const GeometryTileLayer &layer, const FilterExpression &filter, GlyphStore &glyphStore, const Sprite &sprite) { @@ -64,9 +64,9 @@ std::vector SymbolBucket::processFeatures(const VectorTileLayer & // Determine and load glyph ranges std::set ranges; - FilteredVectorTileLayer filtered_layer(layer, filter); - for (const pbf &feature_pbf : filtered_layer) { - const VectorTileFeature feature{feature_pbf, layer}; + GeometryFilteredTileLayer filtered_layer(layer, filter); + GeometryTileFeature feature = filtered_layer.nextMatchingFeature(); + while (feature.type != GeometryFeatureType::Unknown) { SymbolFeature ft; @@ -97,22 +97,21 @@ std::vector SymbolBucket::processFeatures(const VectorTileLayer & auto &multiline = ft.geometry; - // Decode line - Geometry::command cmd; - pbf geom(feature.geometry); - Geometry geometry(geom); + Geometry geometry = feature.nextGeometry(); + const GeometryLine& line = geometry.get(); bool first = true; - int32_t x, y; - while ((cmd = geometry.next(x, y)) != Geometry::end) { - if (first || cmd == Geometry::move_to) { + for (auto point_it = line.begin(); point_it != line.end(); point_it++) { + if (first) { multiline.emplace_back(); first = false; } - multiline.back().emplace_back(x, y); + multiline.back().emplace_back(point_it->x, point_it->y); } features.push_back(std::move(ft)); } + + feature = filtered_layer.nextMatchingFeature(); } if (layout.placement == PlacementType::Line) { @@ -125,7 +124,7 @@ std::vector SymbolBucket::processFeatures(const VectorTileLayer & return features; } -void SymbolBucket::addFeatures(const VectorTileLayer &layer, const FilterExpression &filter, +void SymbolBucket::addFeatures(const GeometryTileLayer &layer, const FilterExpression &filter, const Tile::ID &id, SpriteAtlas &spriteAtlas, Sprite &sprite, GlyphAtlas & glyphAtlas, GlyphStore &glyphStore) { auto &layout = *styleLayout; diff --git a/src/mbgl/renderer/symbol_bucket.hpp b/src/mbgl/renderer/symbol_bucket.hpp index 8ad420cde03..a97ad0bf55c 100644 --- a/src/mbgl/renderer/symbol_bucket.hpp +++ b/src/mbgl/renderer/symbol_bucket.hpp @@ -2,11 +2,11 @@ #define MBGL_RENDERER_SYMBOLBUCKET #include +#include #include #include #include #include -#include #include #include #include @@ -63,7 +63,7 @@ class SymbolBucket : public Bucket { virtual bool hasTextData() const; virtual bool hasIconData() const; - void addFeatures(const VectorTileLayer &layer, const FilterExpression &filter, + void addFeatures(const GeometryTileLayer &layer, const FilterExpression &filter, const Tile::ID &id, SpriteAtlas &spriteAtlas, Sprite &sprite, GlyphAtlas &glyphAtlas, GlyphStore &glyphStore); @@ -76,11 +76,9 @@ class SymbolBucket : public Bucket { private: - std::vector processFeatures(const VectorTileLayer &layer, const FilterExpression &filter, GlyphStore &glyphStore, const Sprite &sprite); - - - void addFeature(const std::vector &line, const Shaping &shaping, const GlyphPositions &face, const Rect &image); + std::vector processFeatures(const GeometryTileLayer &layer, const FilterExpression &filter, GlyphStore &glyphStore, const Sprite &sprite); + void addFeature(const GeometryLine &line, const Shaping &shaping, const GlyphPositions &face, const Rect &image); // Adds placed items to the buffer. template