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

Commit

Permalink
refs #352: catalog (hardcoded: POI) features on tile parse
Browse files Browse the repository at this point in the history
  • Loading branch information
incanus committed Nov 25, 2015
1 parent f782f5e commit 139b9e7
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/mbgl/annotation/point_annotation_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
// Make Boost Geometry aware of our LatLng type
BOOST_GEOMETRY_REGISTER_POINT_2D(mbgl::LatLng, double, boost::geometry::cs::cartesian, longitude, latitude)
BOOST_GEOMETRY_REGISTER_BOX(mbgl::LatLngBounds, mbgl::LatLng, sw, ne)
// FIXME like Collision/Feature

namespace mbgl {

Expand Down
47 changes: 47 additions & 0 deletions src/mbgl/map/tile_worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,53 @@ void TileWorker::parseLayer(const StyleLayer& layer, const GeometryTile& geometr
// We cannot parse this bucket yet. Instead, we're saving it for later.
pending.emplace_back(layer, std::move(bucket));
} else {

// catalog features for interactivity
//
// if (layer.interactive) { ...
//
// also, we don't get here for raster buckets, since they don't have layers

if (!partialParse && layer.id.substr(0, 3) == "poi" && bucket->hasData()) {
result.featureTree.clear();
for (std::size_t i = 0; i < geometryLayer->featureCount(); i++) {
const auto feature = geometryLayer->getFeature(i);
const auto geometries = feature->getGeometries();
for (std::size_t j = 0; j < geometries.size(); j++) {
FeatureBox featureBox {{ 4096 + 64, 4096 + 64 }, { -64, -64 }};
const auto geometry = geometries.at(j);
for (std::size_t k = 0; k < geometry.size(); k++) {
const auto point = geometry.at(k);
const auto min = featureBox.min_corner();
const auto max = featureBox.max_corner();
if (point.x < min.get<0>()) {
featureBox.min_corner().set<0>(point.x);
}
if (point.y < min.get<1>()) {
featureBox.min_corner().set<1>(point.y);
}
if (point.x > max.get<0>()) {
featureBox.max_corner().set<0>(point.x);
}
if (point.y > max.get<1>()) {
featureBox.max_corner().set<1>(point.y);
}
std::string name = "(unknown)";
const auto maybe_name = feature->getValue("name_en");
if (maybe_name.get().is<std::string>()) {
name = maybe_name.get().get<std::string>();
}
name = layer.id + " - " + name;
result.featureTree.insert(std::make_pair(featureBox, layer.id + name));
// printf("added %s\n", name.c_str());
}
}
}
if (result.featureTree.size()) {
// printf("feature tree for %i,%i,%i [%s] has %lu members\n", id.z, id.x, id.y, layer.id.c_str(), result.featureTree.size());
}
}

insertBucket(layer.bucketName(), std::move(bucket));
}
}
Expand Down
30 changes: 30 additions & 0 deletions src/mbgl/map/tile_worker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <mapbox/variant.hpp>

#include <mbgl/map/tile_data.hpp>
#include <mbgl/map/geometry_tile.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/ptr.hpp>
#include <mbgl/text/placement_config.hpp>
Expand All @@ -14,6 +16,25 @@
#include <list>
#include <unordered_map>

#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"
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#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 {

class CollisionTile;
Expand All @@ -22,12 +43,21 @@ class Style;
class Bucket;
class StyleLayer;

namespace FeatureBG = boost::geometry;
namespace FeatureBGM = FeatureBG::model;
namespace FeatureBGI = FeatureBG::index;
typedef FeatureBGM::point<int16_t, 2, FeatureBG::cs::cartesian> FeaturePoint;
typedef FeatureBGM::box<FeaturePoint> FeatureBox;
typedef std::pair<FeatureBox, std::string> Feature;
typedef FeatureBGI::rtree<Feature, FeatureBGI::linear<16, 4>> FeatureTree;

// We're using this class to shuttle the resulting buckets from the worker thread to the MapContext
// thread. This class is movable-only because the vector contains movable-only value elements.
class TileParseResultBuckets {
public:
TileData::State state = TileData::State::invalid;
std::unordered_map<std::string, std::unique_ptr<Bucket>> buckets;
FeatureTree featureTree;
};

using TileParseResult = mapbox::util::variant<TileParseResultBuckets, // success
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/text/collision_tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ float CollisionTile::placeFeature(const CollisionFeature &feature) {
const auto anchor = box.anchor.matMul(rotationMatrix);

std::vector<CollisionTreeBox> blockingBoxes;
tree.query(bgi::intersects(getTreeBox(anchor, box)), std::back_inserter(blockingBoxes));
tree.query(CollisionBGI::intersects(getTreeBox(anchor, box)), std::back_inserter(blockingBoxes));

for (auto& blockingTreeBox : blockingBoxes) {
const auto& blocking = std::get<1>(blockingTreeBox);
Expand Down
14 changes: 7 additions & 7 deletions src/mbgl/text/collision_tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@

namespace mbgl {

namespace bg = boost::geometry;
namespace bgm = bg::model;
namespace bgi = bg::index;
typedef bgm::point<float, 2, bg::cs::cartesian> CollisionPoint;
typedef bgm::box<CollisionPoint> Box;
namespace CollisionBG = boost::geometry;
namespace CollisionBGM = CollisionBG::model;
namespace CollisionBGI = CollisionBG::index;
typedef CollisionBGM::point<float, 2, CollisionBG::cs::cartesian> CollisionPoint;
typedef CollisionBGM::box<CollisionPoint> Box;
typedef std::pair<Box, CollisionBox> CollisionTreeBox;
typedef bgi::rtree<CollisionTreeBox, bgi::linear<16, 4>> Tree;
typedef CollisionBGI::rtree<CollisionTreeBox, CollisionBGI::linear<16, 4>> CollisionTree;

class CollisionTile {
public:
Expand All @@ -49,7 +49,7 @@ class CollisionTile {
private:
Box getTreeBox(const vec2<float>& anchor, const CollisionBox& box);

Tree tree;
CollisionTree tree;
std::array<float, 4> rotationMatrix;
};

Expand Down

0 comments on commit 139b9e7

Please sign in to comment.