Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #928 from mapbox/928-refactor-vend-geometry
Browse files Browse the repository at this point in the history
refactor VectorTile to vend geometry
  • Loading branch information
incanus committed Mar 10, 2015
2 parents f82de98 + 062d33c commit cc7371e
Show file tree
Hide file tree
Showing 16 changed files with 263 additions and 443 deletions.
77 changes: 0 additions & 77 deletions src/mbgl/geometry/geometry.hpp

This file was deleted.

1 change: 0 additions & 1 deletion src/mbgl/geometry/glyph_atlas.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <mbgl/geometry/glyph_atlas.hpp>
#include <mbgl/map/vector_tile.hpp>

#include <mbgl/platform/gl.hpp>
#include <mbgl/platform/platform.hpp>
Expand Down
16 changes: 16 additions & 0 deletions src/mbgl/map/geometry_tile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <mbgl/map/geometry_tile.hpp>
#include <mbgl/style/filter_expression_private.hpp>

namespace mbgl {

mapbox::util::optional<Value> GeometryTileFeatureExtractor::getValue(const std::string& key) const {
if (key == "$type") {
return Value(uint64_t(feature.getType()));
}

return feature.getValue(key);
}

template bool evaluate(const FilterExpression&, const GeometryTileFeatureExtractor&);

}
62 changes: 62 additions & 0 deletions src/mbgl/map/geometry_tile.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#ifndef MBGL_MAP_GEOMETRY_TILE
#define MBGL_MAP_GEOMETRY_TILE

#include <mbgl/style/filter_expression.hpp>
#include <mbgl/style/value.hpp>
#include <mbgl/text/glyph.hpp>
#include <mbgl/util/optional.hpp>
#include <mbgl/util/ptr.hpp>
#include <mbgl/util/variant.hpp>
#include <mbgl/util/vec.hpp>
#include <mbgl/util/noncopyable.hpp>

#include <cstdint>
#include <map>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <vector>

namespace mbgl {

enum class FeatureType : uint8_t {
Unknown = 0,
Point = 1,
LineString = 2,
Polygon = 3
};

typedef std::vector<std::vector<Coordinate>> GeometryCollection;

class GeometryTileFeature : public mbgl::util::noncopyable {
public:
virtual FeatureType getType() const = 0;
virtual mapbox::util::optional<Value> getValue(const std::string& key) const = 0;
virtual GeometryCollection getGeometries() const = 0;
};

class GeometryTileLayer : public mbgl::util::noncopyable {
public:
virtual std::size_t featureCount() const = 0;
virtual util::ptr<const GeometryTileFeature> feature(std::size_t i) const = 0;
};

class GeometryTile : public mbgl::util::noncopyable {
public:
virtual util::ptr<const GeometryTileLayer> getLayer(const std::string&) const = 0;
};

class GeometryTileFeatureExtractor {
public:
GeometryTileFeatureExtractor(const GeometryTileFeature& feature_)
: feature(feature_) {}

mapbox::util::optional<Value> getValue(const std::string& key) const;

private:
const GeometryTileFeature& feature;
};

}

#endif
43 changes: 20 additions & 23 deletions src/mbgl/map/tile_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,14 @@ std::unique_ptr<Bucket> TileParser::createBucket(const StyleBucket &bucketDesc)
if (tile.id.z >= std::ceil(bucketDesc.max_zoom)) return nullptr;
if (bucketDesc.visibility == mbgl::VisibilityType::None) return nullptr;

auto layer_it = vectorTile.layers.find(bucketDesc.source_layer);
if (layer_it != vectorTile.layers.end()) {
const VectorTileLayer &layer = layer_it->second;
auto layer = vectorTile.getLayer(bucketDesc.source_layer);
if (layer) {
if (bucketDesc.type == StyleLayerType::Fill) {
return createFillBucket(layer, bucketDesc);
return createFillBucket(*layer, bucketDesc);
} else if (bucketDesc.type == StyleLayerType::Line) {
return createLineBucket(layer, bucketDesc);
return createLineBucket(*layer, bucketDesc);
} else if (bucketDesc.type == StyleLayerType::Symbol) {
return createSymbolBucket(layer, bucketDesc);
return createSymbolBucket(*layer, bucketDesc);
} else if (bucketDesc.type == StyleLayerType::Raster) {
return nullptr;
} else {
Expand All @@ -213,25 +212,23 @@ std::unique_ptr<Bucket> TileParser::createBucket(const StyleBucket &bucketDesc)
}

template <class Bucket>
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) {
for (std::size_t i = 0; i < layer.featureCount(); i++) {
auto feature = layer.feature(i);

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");
}
}
GeometryTileFeatureExtractor extractor(*feature);
if (!evaluate(filter, extractor))
continue;

bucket->addGeometry(feature->getGeometries());
}
}

std::unique_ptr<Bucket> TileParser::createFillBucket(const VectorTileLayer &layer,
const StyleBucket &bucket_desc) {
std::unique_ptr<Bucket> TileParser::createFillBucket(const GeometryTileLayer& layer,
const StyleBucket& bucket_desc) {
auto fill = parseStyleLayoutFill(bucket_desc, tile.id.z);
auto bucket = util::make_unique<FillBucket>(std::move(fill),
tile.fillVertexBuffer,
Expand All @@ -241,8 +238,8 @@ std::unique_ptr<Bucket> TileParser::createFillBucket(const VectorTileLayer &laye
return obsolete() ? nullptr : std::move(bucket);
}

std::unique_ptr<Bucket> TileParser::createLineBucket(const VectorTileLayer &layer,
const StyleBucket &bucket_desc) {
std::unique_ptr<Bucket> TileParser::createLineBucket(const GeometryTileLayer& layer,
const StyleBucket& bucket_desc) {
auto line = parseStyleLayoutLine(bucket_desc, tile.id.z);
auto bucket = util::make_unique<LineBucket>(std::move(line),
tile.lineVertexBuffer,
Expand All @@ -252,8 +249,8 @@ std::unique_ptr<Bucket> TileParser::createLineBucket(const VectorTileLayer &laye
return obsolete() ? nullptr : std::move(bucket);
}

std::unique_ptr<Bucket> TileParser::createSymbolBucket(const VectorTileLayer &layer,
const StyleBucket &bucket_desc) {
std::unique_ptr<Bucket> TileParser::createSymbolBucket(const GeometryTileLayer& layer,
const StyleBucket& bucket_desc) {
auto symbol = parseStyleLayoutSymbol(bucket_desc, tile.id.z);
auto bucket = util::make_unique<SymbolBucket>(std::move(symbol), *collision);
bucket->addFeatures(
Expand Down
12 changes: 7 additions & 5 deletions src/mbgl/map/tile_parser.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef MBGL_MAP_TILE_PARSER
#define MBGL_MAP_TILE_PARSER

#include <mbgl/map/geometry_tile.hpp>
#include <mbgl/map/vector_tile.hpp>
#include <mbgl/style/filter_expression.hpp>
#include <mbgl/style/class_properties.hpp>
Expand Down Expand Up @@ -51,12 +52,13 @@ class TileParser : private util::noncopyable
bool obsolete() const;
void parseStyleLayers(util::ptr<const StyleLayerGroup> group);

std::unique_ptr<Bucket> createBucket(const StyleBucket& bucketDesc);
std::unique_ptr<Bucket> createFillBucket(const VectorTileLayer& layer, const StyleBucket& bucketDesc);
std::unique_ptr<Bucket> createLineBucket(const VectorTileLayer& layer, const StyleBucket& bucketDesc);
std::unique_ptr<Bucket> createSymbolBucket(const VectorTileLayer& layer, const StyleBucket& bucketDesc);
std::unique_ptr<Bucket> createBucket(const StyleBucket&);
std::unique_ptr<Bucket> createFillBucket(const GeometryTileLayer&, const StyleBucket&);
std::unique_ptr<Bucket> createLineBucket(const GeometryTileLayer&, const StyleBucket&);
std::unique_ptr<Bucket> createSymbolBucket(const GeometryTileLayer&, const StyleBucket&);

template <class Bucket> void addBucketGeometries(Bucket& bucket, const VectorTileLayer& layer, const FilterExpression& filter);
template <class Bucket>
void addBucketGeometries(Bucket&, const GeometryTileLayer&, const FilterExpression&);

private:
const VectorTile vectorTile;
Expand Down
Loading

0 comments on commit cc7371e

Please sign in to comment.