升压交叉 [英] Boost intersection

查看:240
本文介绍了升压交叉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个boost交叉算法的问题。我不知道我是否有错误或是错误。

I have a problem with boost intersection algorithm. I am not sure if I did an error or it is a bug.

#include <boost/geometry/algorithms/intersection.hpp>
#include <boost/version.hpp>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/ring.hpp>
#include <boost/geometry/geometries/polygon.hpp>
int main()
{
    typedef boost::geometry::model::d2::point_xy<double> BoostPointXY;
    typedef boost::geometry::model::polygon<BoostPointXY> BoostPolygon;

    BoostPolygon polyOne, polyTwo;
    boost::geometry::read_wkt(
            "POLYGON((45, 4), (45, 17), (44, 19), (44, 22), (50, 20), (51.5, 17), (58, 4), (60, 0), (53, 0), (45, 0), (45, 4))",
            polyOne);
    boost::geometry::read_wkt(
            "POLYGON((-10, -5), (0, 25), (43, 25), (45, 20), (50, 20), (60, 0), (5, 0), (5, -5), (-10, -5))", polyTwo);
    std::vector<BoostPolygon> multiPoly;
    boost::geometry::correct(polyOne);
    boost::geometry::correct(polyTwo);
    boost::geometry::intersection(polyOne,polyTwo,multiPoly);
    std::cout << "Size of Multi " << multiPoly.size() << std::endl;
    std::cout << "Using Boost "
              << BOOST_VERSION / 100000     << "."  // major version
              << BOOST_VERSION / 100 % 1000 << "."  // minior version
              << BOOST_VERSION % 100                // patch level
              << std::endl;
}

输出:

Size of Multi 0
Using Boost 1.55.0

但是multiPolygon的大小应该是1还是?当它是一个错误,有人可以用当前提升1.57测试它吗?我现在不能改变我的boost版本。

But the size of the multiPolygon should be 1 or? When it is a bug, can someone test it with the current boost 1.57 ? I can't change my boost version at the moment.

感谢

推荐答案

您的WKT资料无效:

boost::geometry::read_wkt("POLYGON((45  4, 45  17, 44  19, 44  22, 50  20, 51.5  17, 58  4, 60  0, 53  0, 45  0, 45  4))", polyOne);
boost::geometry::read_wkt("POLYGON((-10  -5, 0  25, 43  25, 45  20, 50  20, 60  0, 5  0, 5  -5, -10  -5))", polyTwo);

您的示例刚刚使用了许多无效(?)内圈。

Your sample just used many invalid(?) inner rings.

现在你得到:

Size of Multi 1

>

Live On Coliru < a>

Live On Coliru

#include <boost/geometry.hpp>
#include <boost/geometry/algorithms/intersection.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/ring.hpp>
#include <boost/geometry/io/io.hpp>
#include <fstream>
#include <iostream>

int main() {
    typedef boost::geometry::model::d2::point_xy<double> BoostPointXY;
    typedef boost::geometry::model::polygon<BoostPointXY> BoostPolygon;

    BoostPolygon polyOne, polyTwo;
    boost::geometry::read_wkt("POLYGON((45  4, 45  17, 44  19, 44  22, 50  20, 51.5  17, 58  4, 60  0, 53  0, 45  0, 45  4))", polyOne);
    boost::geometry::read_wkt("POLYGON((-10  -5, 0  25, 43  25, 45  20, 50  20, 60  0, 5  0, 5  -5, -10  -5))", polyTwo);

    boost::geometry::correct(polyOne);
    boost::geometry::correct(polyTwo);

    {
        std::ofstream svg("/tmp/svg.svg");
        boost::geometry::svg_mapper<BoostPointXY> mapper(svg, 400, 400);
        mapper.add(polyOne);
        mapper.add(polyTwo);

        mapper.map(polyOne, "fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(153,204,0);stroke-width:2");
        mapper.map(polyTwo, "fill-opacity:0.5;fill:rgb(204,153,0);stroke:rgb(204,153,0);stroke-width:2");
    }

    std::vector<BoostPolygon> multiPoly;
    boost::geometry::intersection(polyOne,polyTwo,multiPoly);
    std::cout << "Size of Multi " << multiPoly.size() << std::endl;
}

这篇关于升压交叉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆