使用 boost::geometry::buffer 函数
Posted
技术标签:
【中文标题】使用 boost::geometry::buffer 函数【英文标题】:using boost::geometry::buffer function 【发布时间】:2019-03-08 15:40:25 【问题描述】:这是我第一次使用 boost 库,所以我对此感到很不舒服,而且我可能做错了什么。我在使用 boost::geometry::buffer() 函数时遇到了一些问题。
这是我的代码:
#include <vector>
#include <boost\geometry.hpp>
#include <boost\geometry\geometries\register\point.hpp>
struct PNT_2D
double x, y;
;
BOOST_GEOMETRY_REGISTER_POINT_2D(PNT_2D, double, boost::geometry::cs::cartesian, x, y);
typedef boost::geometry::model::polygon<PNT_2D, false> BoostPolygon;
typedef std::vector<PNT_2D> StlPolygon;
int main(int argc, char * argv[])
int nStaph;
BoostPolygon polygon;
BoostPolygon off_polygon;
PNT_2D p2dPunto;
StlPolygon stlPolygon;
stlPolygon.resize(5);
stlPolygon[0].x = stlPolygon[0].y = stlPolygon[4].x = stlPolygon[4].y = 0.0;
stlPolygon[1].x = 25.0; stlPolygon[1].y = 0.0;
stlPolygon[2].x = 25.0; stlPolygon[2].y = 25.0;
stlPolygon[3].x = 0.0; stlPolygon[3].y = 25.0;
boost::geometry::append(polygon, stlPolygon);
boost::geometry::buffer(polygon, off_polygon, 1);
stlPolygon = off_polygon.outer();
for (auto punto = stlPolygon.begin(); punto != stlPolygon.end(); punto++)
std::cout << "(" << punto->x << ", " << punto->y << ")" << std::endl;
编译时出现以下错误:
'int boost::mpl::assertion_failed<false>(boost::mpl::assert<false>::type)': impossibile convertire l'argomento 1 da 'boost::mpl::failed ************(__thiscall boost::geometry::nyi::not_implemented_error<boost::geometry::info::POLYGON,boost::geometry::info::POLYGON,void>::THIS_OPERATION_IS_NOT_OR_NOT_YET_IMPLEMENTED::* ***********)(boost::mpl::assert_::types<Term1,Term2,Term3,boost::mpl::na>)' a 'boost::mpl::assert<false>::type'
我错过了什么?
编辑
我已通过以下方式更新了我的代码:
//////////////////////// DEFINITIONS
typedef BG::model::polygon<PNT_2D, false> BoostPolygon;
typedef BG::model::multi_polygon<BoostPolygon> BoostMultiPolygon;
typedef SB::distance_symmetric<double> DistanceStrategy;
typedef SB::end_round EndStrategy;
typedef SB::join_round JoinStrategy;
typedef SB::point_circle PointStrategy;
typedef SB::side_straight SideStrategy;
typedef std::vector<PNT_2D> StlPolygon;
/////////////////////////////////////////////////////////////
///////////////////////// CODE
BoostMultiPolygon off_polygon;
BoostPolygon polygon;
DistanceStrategy distance_strategy(1.0);
EndStrategy end_strategy;
JoinStrategy join_strategy;
PointStrategy point_strategy;
PNT_2D p2dPunto;
SideStrategy side_strategy;
StlPolygon stlPolygon;
p2dPunto.x = p2dPunto.y = 0.0;
boost::geometry::append(polygon, p2dPunto);
p2dPunto.x = 25.0; p2dPunto.y = 0.0;
boost::geometry::append(polygon, p2dPunto);
p2dPunto.x = 25.0; p2dPunto.y = 25.0;
boost::geometry::append(polygon, p2dPunto);
p2dPunto.x = 0.0; p2dPunto.y = 25.0;
boost::geometry::append(polygon, p2dPunto);
p2dPunto.x = 0.0; p2dPunto.y = 0.0;
boost::geometry::append(polygon, p2dPunto);
boost::geometry::buffer(polygon, off_polygon, distance_strategy, side_strategy, join_strategy, end_strategy, point_strategy);
for (auto poligono = off_polygon.begin(); poligono != off_polygon.end(); poligono++)
for (auto punto = poligono->outer().begin(); punto != poligono->outer().end(); punto++)
std::cout << "(" << punto->x << ", " << punto->y << ")" << std::endl;
std::cin >> nStaph;
return EXIT_SUCCESS;
现在我遇到了这个错误:
'std::copy::_Unchecked_iterators::_Deprecate': Call to 'std::copy' with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
Not in the main project, but in xutility.
【问题讨论】:
【参考方案1】: 您提供的代码是缓冲一个盒子。对于带有多边形的缓冲区, 您(当前)需要使用带有策略的缓冲区(请参阅doc 有一个例子) 如果您这样做并提供策略,则结果应该是多面体 您的样本有效地使用了一个盒子,所以这可能是一个选项 也。但是你的输入几何应该满足盒子的概念【讨论】:
您好,感谢您的回答,我已经用新代码和新错误更新了问题。 答案在消息中:“要禁用此警告,请使用 -D_SCL_SECURE_NO_WARNINGS”。 我猜的,其实我是这样解决的,但是心里不舒服,就是想知道有没有别的办法。以上是关于使用 boost::geometry::buffer 函数的主要内容,如果未能解决你的问题,请参考以下文章
在使用加载数据流步骤的猪中,使用(使用 PigStorage)和不使用它有啥区别?
Qt静态编译时使用OpenSSL有三种方式(不使用,动态使用,静态使用,默认是动态使用)