Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 增强多边形丢弃输入多边形_C++_Boost_Boost Polygon - Fatal编程技术网

C++ 增强多边形丢弃输入多边形

C++ 增强多边形丢弃输入多边形,c++,boost,boost-polygon,C++,Boost,Boost Polygon,我正在尝试使用Boost::Polygon以增量方式构建一组多边形。下面代码中的实时数据集取自我在使用Boost::Polygon的真实系统中发现的病理输入 以下是最低复制代码(您需要在include路径中使用boost开发头): #包括 #包括 #包括 #包括“boost/polygon/polygon.hpp” 使用名称空间std; 使用名称空间boost::polygon; 使用名称空间boost::polygon::操作符; /*从字符串中读取多边形的实用函数。这很难看,但在这个复制案例

我正在尝试使用Boost::Polygon以增量方式构建一组多边形。下面代码中的实时数据集取自我在使用Boost::Polygon的真实系统中发现的病理输入

以下是最低复制代码(您需要在include路径中使用boost开发头):

#包括
#包括
#包括
#包括“boost/polygon/polygon.hpp”
使用名称空间std;
使用名称空间boost::polygon;
使用名称空间boost::polygon::操作符;
/*从字符串中读取多边形的实用函数。这很难看,但在这个复制案例中起作用*/
多边形\数据读取多边形(字符串str)
{
矢量结果;
尺寸指数=0;
while(index!=string::npos)
{
size\u t xend=str.find(“,索引);
大小=str.find(“,xend+1);
float x=atof(str.substr(index,xend-index).c_str());
float y=atof(str.substr(xend+1,yend-xend+1.c_str());
结果。推回(点数据(x,y));
if(yend==string::npos)
打破
指数=yend+1;
}
返回多边形_数据(result.begin(),result.end());
}
/*将多边形集转储到cout的实用函数,对于使用python脚本进行可视化非常有用*/
void dumpPoly(向量多边形集)
{
for(vector::iterator it=polyset.begin();it!=polyset.end();it++)
{
多边形\数据多边形=*it;
对于(多边形数据::迭代器类型jt=poly.begin();jt!=poly.end();jt++)
{
cout来自:

坐标数据类型是所有数据类型和类型的模板参数 由库提供的算法,并期望是完整的。 不支持浮点坐标数据类型 由于 实现浮点健壮性意味着一组不同的 算法和通常针对平台的浮动假设 点表示法

现在一切都有意义了!(这应该是本手册第一页中的一个警告——痛苦——手册)。
#include <iostream>
#include <string>
#include <vector>

#include "boost/polygon/polygon.hpp"

using namespace std;
using namespace boost::polygon;
using namespace boost::polygon::operators;

/* Utility function to read a polygon from a string. This is ugly, but works for the purpose of this repro case */
polygon_data<float> readPoly(string str)
{
    vector<point_data<float> > result;

    size_t index = 0;
    while(index != string::npos)
    {
        size_t xend = str.find(" ", index);
        size_t yend = str.find(" ", xend + 1);

        float x = atof(str.substr(index, xend - index).c_str());
        float y = atof(str.substr(xend + 1, yend - xend + 1).c_str());
        result.push_back(point_data<float>(x, y));

        if(yend == string::npos)
            break;

        index = yend + 1;
    }

    return polygon_data<float>(result.begin(), result.end());
}

/* Utility function to dump a polygon set to cout, useful for visualizing with the python script */
void dumpPoly(vector<polygon_data<float> > polyset)
{
    for(vector<polygon_data<float> >::iterator it = polyset.begin(); it != polyset.end(); it++)
    {
        polygon_data<float> poly = *it;
        for(polygon_data<float>::iterator_type jt = poly.begin(); jt != poly.end(); jt++)
        {
            cout << (*jt).x() << " " << (*jt).y() << " ";
        }
        cout << endl;
    }
}


int main()
{
    std::vector<polygon_data<float> > data;

    // Construct the polygon set
    data += readPoly("-1309.77, 1323.99, -1324, 1309.76, -1324, -1309.76, -1309.77, -1323.99, -1240.23, -1323.99, -1226, -1309.76, -1226, 1309.76, -1240.23, 1323.99");
    data += readPoly("-1323.99, -1309.77, -1309.76, -1324, 1309.76, -1324, 1323.99, -1309.77, 1323.99, -1240.23, 1309.76, -1226, -1309.76, -1226, -1323.99, -1240.23");
    data += readPoly("1323.99, 1309.77, 1309.76, 1324, -1309.76, 1324, -1323.99, 1309.77, -1323.99, 1240.23, -1309.76, 1226, 1309.76, 1226, 1323.99, 1240.23");
    data += readPoly("-544.771, 686.49, -559, 672.261, -559, -544.761, -544.771, -558.99, -475.229, -558.99, -461, -544.761, -461, 672.261, -475.229, 686.49");
    data += readPoly("-558.99, -544.771, -544.761, -559, 672.261, -559, 686.49, -544.771, 686.49, -475.229, 672.261, -461, -544.761, -461, -558.99, -475.229");
    data += readPoly("686.49, 672.271, 672.261, 686.5, -544.761, 686.5, -558.99, 672.271, -558.99, 602.729, -544.761, 588.5, 672.261, 588.5, 686.49, 602.729");
    data += readPoly("-69.8842, -119.057, -49.7607, -119.057, 219.057, 149.76, 219.057, 169.884, 169.884, 219.057, 149.76, 219.057, -119.057, -49.7607, -119.057, -69.8842");
    data += readPoly("672.271, -558.99, 686.5, -544.761, 686.5, 672.261, 672.271, 686.49, 602.729, 686.49, 588.5, 672.261, 588.5, -544.761, 602.729, -558.99");
    data += readPoly("1309.77, -1323.99, 1324, -1309.76, 1324, 1309.76, 1309.77, 1323.99, 1240.23, 1323.99, 1226, 1309.76, 1226, -1309.76, 1240.23, -1323.99");

    /*

    This alternative dataset shows that boost.polygon can handle nested holes, to some extent

    data += readPoly("100 100 100 1900 1900 1900 1900 100");
    data -= readPoly("200 200 200 1800 1800 1800 1800 200");
    data += readPoly("300 300 300 1700 1700 1700 1700 300");
    data -= readPoly("400 400 400 1600 1600 1600 1600 400");
    data += readPoly("500 500 500 1500 1500 1500 1500 500");
    data -= readPoly("600 600 600 1400 1400 1400 1400 600");

    */

    dumpPoly(data);

    return 0;
}
#!/usr/bin/env python 
import matplotlib.pyplot as plt
import sys

lines = sys.stdin.read().split("\n")

for line in lines:
    data = line.split()

    if len(data) == 0:
        continue

    x = []
    y = []
    i = 0
    while i < len(data):
        x.append(float(data[i]))
        y.append(float(data[i+1]))
        i += 2

    plt.fill(x, y)

plt.show()