我正在构建输出对象复杂网格的程序。为了减少面向同一方向的相邻多边形的数量,我决定使用 Boost::Polygon。现在我遇到了麻烦 - 首先,程序不想输出正确的梯形数据,这是在文档中承诺的(或者我可能以错误的方式这样做)。其次,Boost 库在将 polygon_set_data(带孔的多边形集)表示为一组简单的多边形时也会遇到麻烦。我想得到一个可行的解决方案 - 首先我将简单的多边形(没有孔)一起添加到 boost::polygon_set 类型中,之后(假设 Boost 计算了所有操作并且我有几个大多边形)我想得到简单的 boost::多边形数据。
#include "SomeLibrary.h"
#include <boost/polygon/polygon.hpp>
#include <cassert>
using namespace boost::polygon::operators;
using namespace boost::polygon;
using namespace std;
typedef point_data<float> point;
typedef polygon_set_data<float> polygon_set;
typedef polygon_with_holes_data<float> polygon;
typedef pair<point, point> edge;
void FracturePolygon::Dissolve() {
polygon_set BPolygon;
for (auto p : OutMesh.Faces()) { //p is simple polygon data, list of vertices
vector<point> pts;
for (int i = 0; i < p.NumVertices(); i++) {
auto v = InPolygon.MapTo2D(p.Vertex(i)); //i get 2d point data
pts.push_back(point(v.x, v.y)); //now i have boost::point data
}
polygon poly;
set_points(poly, pts.begin(), pts.end()); //i get boost::polygon type
BPolygon += poly; //i add this simple polygon to polygon_set container
}
//now i expect some magic which will give me list of polygons from polygon_set type.
...
}