我試圖在我的一個項目上使用boost::geometry
的rtree DS,但我發現很難瀏覽文檔。某些方法記錄不完善,我找不到足夠的例子。現在我正在嘗試構建一個示例程序,以便我可以進一步構建它。在幾何圖形中使用boost rtree查找結果點
因此,在下面的例子中,我有一個點和一個盒子,我需要找到那個盒子裏面的所有點。我想問的另一件事是,我找不到packing algorithm
構造函數或方法,所以如何使用它。這是我做了什麼至今 -
#include <iostream>
#include <vector>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/register/point.hpp>
#include <boost/geometry/geometries/register/box.hpp>
#include <boost/geometry/index/rtree.hpp>
namespace bg = boost::geometry;
namespace bgi = boost::geometry::index;
struct my_point
{
float x, y;
my_point(float _x, float _y) : x(_x), y(_y) {}
};
struct my_box
{
my_point ll, ur;
my_box(float x1, float y1, float x2, float y2) : ll(x1,y1), ur(x2,y2) {}
};
// Register the point type
BOOST_GEOMETRY_REGISTER_POINT_2D(my_point, float, cs::cartesian, x, y)
// Register the box type, also notifying that it is based on "my_point"
BOOST_GEOMETRY_REGISTER_BOX(my_box, my_point, ll, ur)
int main()
{
std::vector<std::pair<my_point, int>> pts;
pts.emplace_back(std::make_pair(my_point(2,2), 5));
pts.emplace_back(std::make_pair(my_point(3,3), 1));
pts.emplace_back(std::make_pair(my_point(4,5), 3));
pts.emplace_back(std::make_pair(my_point(4,4), 12));
pts.emplace_back(std::make_pair(my_point(1,2), 50));
// ....
bgi::rtree<std::pair<my_point, int>, bgi::dynamic_rstar> rT(bgi::dynamic_rstar(pts.size()));
rT.insert(pts.begin(), pts.end());
my_box box1(1,1,4,4);
// how to retrieve all points or their .second inside this box?
return 0;
}