C++ 使用boost::geometry::buffer函数

C++ 使用boost::geometry::buffer函数,c++,boost,boost-geometry,C++,Boost,Boost Geometry,这是我第一次使用boost库,所以我对它感到非常不舒服,我可能做错了什么。我在使用boost::geometry::buffer()函数时遇到一些问题 这是我的密码: #include <vector> #include <boost\geometry.hpp> #include <boost\geometry\geometries\register\point.hpp> struct PNT_2D { double x, y; }; BOOST_G

这是我第一次使用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;
}
  • 您提供的代码是缓冲一个框。对于具有多边形的缓冲区, 您(当前)需要将缓冲区与策略一起使用(请参阅 (这里有一个例子)
  • 如果您这样做,并提供策略,结果应该是一个多多边形
  • 您的示例有效地使用了一个框,因此这可能是一个选项 也但是,您的输入几何体应该符合长方体的概念

您好,谢谢您的回答,我已经用新代码和新错误更新了问题。答案在消息中:“要禁用此警告,请使用-D_SCL_SECURE_NO_WARNINGS”。我猜,事实上我已经以这种方式解决了问题,但我对此感到不舒服,只是想知道是否还有其他警告。
'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.