Boost基本操作
Boost中的多边形交并比
BBox是存放最大点和最小点的包围框。
double isOverlapped(BBox2D &bbox_a, const BBox2D &bbox_b)
{
double area_intersect = 0.0, area_union = 0.0;
// validity check
if (!bbox_a.IsValid() || !bbox_b.IsValid()) return 0.0;
// intersect operation between two kind of boundary
typedef boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double>, false> polygon;
// add boundary point to polygon counterclock wise
polygon poly_src, poly_tgt;
std::vector<boost::geometry::model::d2::point_xy<double>> points;
points.emplace_back(boost::geometry::model::d2::point_xy<double>(bbox_a.min.x, bbox_a.min.y));
points.emplace_back(boost::geometry::model::d2::point_xy<double>(bbox_a.max.x, bbox_a.min.y));
points.emplace_back(boost::geometry::model::d2::point_xy<double>(bbox_a.max.x, bbox_a.max.y));
points.emplace_back(boost::geometry::model::d2::point_xy<double>(bbox_a.min.x, bbox_a.max.y));
boost::geometry::assign_points(poly_src, points);
std::cout << boost::geometry::area(poly_src) << std::endl;
points.clear();
// for the tgt bbox boundary
points.emplace_back(boost::geometry::model::d2::point_xy<double>(bbox_b.min.x, bbox_b.min.y));
points.emplace_back(boost::geometry::model::d2::point_xy<double>(bbox_b.max.x, bbox_b.min.y));
points.emplace_back(boost::geometry::model::d2::point_xy<double>(bbox_b.max.x, bbox_b.max.y));
points.emplace_back(boost::geometry::model::d2::point_xy<double>(bbox_b.min.x, bbox_b.max.y));
boost::geometry::assign_points(poly_tgt, points);
std::cout << boost::geometry::area(poly_tgt) << std::endl;
std::deque<polygon> poly_output_intersect, poly_output_union;
boost::geometry::intersection(poly_src, poly_tgt, poly_output_intersect);
if (poly_output_intersect.empty()) return 0.0;
boost::geometry::union_(poly_src, poly_tgt, poly_output_union);
for (auto p : poly_output_intersect)
{
area_intersect += boost::geometry::area(p);
}
for (auto p : poly_output_union)
{
area_union += boost::geometry::area(p);
}
std::cout << area_intersect << ", " << area_union << ", " << area_intersect / area_union << std::endl;
return area_union > 0.01 ? area_intersect / area_union : 0.0;
}
Boost中文件系统API
total_size = boost::filesystem::file_size("文件路径");
float file_size = 0.f, disk_available_size = 0.f;
file_size = total_size / 1073741824.f;
std::cout << "Current file size is " << file_size << " GB." << std::endl;
// get the setting destination dir and the root dir path of the out put path
boost::filesystem::path p = output_path;
boost::filesystem::space_info s = boost::filesystem::space(p.root_path());
disk_available_size = s.available / 1073741824.f;
std::cout << "Current root dir disk capacity is " << s.capacity / 1073741824.f << " GB." << std::endl;
std::cout << "Current root dir disk available is " << s.available / 1073741824.f << " GB." << std::endl;
还有其他很多api等待后续挖掘。