1
我想通過在循環中添加boost::geometry::model::polygon
來創建boost::geometry::model::multi_polygon
。我已經瀏覽了boost的例子和文檔,但他們不清楚如何去做。這裏是我的代碼有Boost :: geometry如何將多邊形添加到multi_polygon中
typedef boost::geometry::model::d2::point_xy<double> point_xy;
typedef boost::geometry::model::polygon<point_xy> polygon_type;
typedef boost::geometry::model::multi_polygon<polygon_type> multi_polygon_type;
// Calculate centroid
multi_polygon_type polygons;
Q_FOREACH(QGraphicsItem* graphicsItem, allItemsInScene)
{
// Make a polygon for each graphics item
polygon_type poly;
// Find bounding box surrounding item and create boost compatible points from it
QRectF boundingBox = graphicsItem->boundingRect();
std::vector<point_xy> pointList; // Store points in vector so we can assign them to a polygon
point_xy topLeft(boundingBox.topLeft().x(), boundingBox.topLeft().y());
pointList.push_back(topLeft);
point_xy topRight(boundingBox.topRight().x(), boundingBox.topRight().y());
pointList.push_back(topRight);
point_xy bottomRight(boundingBox.bottomRight().x(), boundingBox.bottomRight().y());
pointList.push_back(bottomRight);
point_xy bottomLeft(boundingBox.bottomLeft().x(), boundingBox.bottomLeft().y());
pointList.push_back(bottomLeft);
// assign points to polygon
boost::geometry::assign_points(poly, pointList);
// Add polygon to multi-polygon
boost::geometry::append(polygons, poly); // DOESN'T WORK
}
爲什麼不自足的樣本......? – sehe