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

Commit

Permalink
refs #928: bookmarking working build of refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
incanus committed Mar 4, 2015
1 parent 1725704 commit 9faf543
Show file tree
Hide file tree
Showing 13 changed files with 233 additions and 243 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef MBGL_GEOMETRY_GEOMETRY
#define MBGL_GEOMETRY_GEOMETRY
#ifndef MBGL_GEOMETRY_PBF_GEOMETRY
#define MBGL_GEOMETRY_PBF_GEOMETRY

#include <mbgl/util/pbf.hpp>
#include <mbgl/util/noncopyable.hpp>
Expand All @@ -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,
Expand All @@ -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<uint32_t>(data.varint());
Expand Down
36 changes: 30 additions & 6 deletions src/mbgl/map/geometry_tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,39 @@ std::ostream& mbgl::operator<<(std::ostream& os, const GeometryFeatureType& type
}
}

GeometryTileFeature::GeometryTileFeature() {}

Geometry GeometryTileFeature::nextGeometry() {
Geometry result;
result.set<std::false_type>();
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 <typename T>
GeometryFilteredTileLayer<T>::iterator::iterator(const GeometryFilteredTileLayer<T>& parent_)
: parent(parent_) {
operator++();
}
56 changes: 28 additions & 28 deletions src/mbgl/map/geometry_tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,84 +5,84 @@
#include <mbgl/style/value.hpp>
#include <mbgl/text/glyph.hpp>
#include <mbgl/util/optional.hpp>
#include <mbgl/util/variant.hpp>
#include <mbgl/util/vec.hpp>

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

namespace mbgl {

class GeometryTileLayer;

enum class GeometryFeatureType {
Unknown = 0,
Point = 1,
LineString = 2,
Polygon = 3
};

typedef Coordinate GeometryPoint;
typedef std::vector<GeometryPoint> GeometryLine;
typedef std::vector<GeometryLine> GeometryPolygon;

using Geometry = mapbox::util::variant<std::false_type, GeometryPoint, GeometryLine, GeometryPolygon>;

std::ostream& operator<<(std::ostream&, const GeometryFeatureType& type);

template <typename T>
class GeometryTileLayer;

class GeometryTileFeature {
public:
GeometryTileFeature();

virtual Geometry nextGeometry();

public:
uint64_t id = 0;
GeometryFeatureType type = GeometryFeatureType::Unknown;
std::map<std::string, Value> properties;
T geometries;
};

template <typename T>
std::ostream& operator<<(std::ostream&, const GeometryTileFeature<T>& feature);
std::ostream& operator<<(std::ostream&, const GeometryTileFeature& feature);

template <typename T>
class GeometryTileTagExtractor {
public:
GeometryTileTagExtractor(const GeometryTileLayer&);

void setTags(const T&);
virtual mapbox::util::optional<Value> getValue(const std::string &key) const;
inline void setTags(const T& tags_) { tags = tags_; }
mapbox::util::optional<Value> 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 <typename T>
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;
};

std::ostream& operator<<(std::ostream&, const PositionedGlyph&);

class GeometryTileLayer {
public:
virtual GeometryTileFeature nextFeature();

public:
std::string name;
uint32_t extent = 4096;
Expand Down
28 changes: 14 additions & 14 deletions src/mbgl/map/tile_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ std::unique_ptr<Bucket> 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) {
Expand All @@ -213,24 +213,24 @@ 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) {
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<std::false_type>()) {
bucket->addGeometry(geometry);
geometry = feature.nextGeometry();
}

feature = filtered_layer.nextMatchingFeature();
}
}

std::unique_ptr<Bucket> TileParser::createFillBucket(const VectorTileLayer &layer,
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),
Expand All @@ -241,7 +241,7 @@ std::unique_ptr<Bucket> TileParser::createFillBucket(const VectorTileLayer &laye
return obsolete() ? nullptr : std::move(bucket);
}

std::unique_ptr<Bucket> TileParser::createLineBucket(const VectorTileLayer &layer,
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),
Expand All @@ -252,7 +252,7 @@ std::unique_ptr<Bucket> TileParser::createLineBucket(const VectorTileLayer &laye
return obsolete() ? nullptr : std::move(bucket);
}

std::unique_ptr<Bucket> TileParser::createSymbolBucket(const VectorTileLayer &layer,
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);
Expand Down
9 changes: 5 additions & 4 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 @@ -52,11 +53,11 @@ class TileParser : private util::noncopyable
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> createFillBucket(const GeometryTileLayer& layer, const StyleBucket& bucketDesc);
std::unique_ptr<Bucket> createLineBucket(const GeometryTileLayer& layer, const StyleBucket& bucketDesc);
std::unique_ptr<Bucket> createSymbolBucket(const GeometryTileLayer& layer, const StyleBucket& bucketDesc);

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

private:
const VectorTile vectorTile;
Expand Down
Loading

0 comments on commit 9faf543

Please sign in to comment.