gpt4 book ai didi

c++ - 来自 Voronoi 的 Delaunay boost : missing triangle with non-integral point coordinates

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:33:54 25 4
gpt4 key购买 nike

遵循这两个资源:

我用 boost 写了一个 Delaunay 三角剖分。如果点坐标是完整的(我生成了几个随机测试并且我没有观察到错误),它工作正常。但是,如果这些点不是整数,我会发现许多不正确的三角剖分缺少边缘或错误的边缘。

例如这张图片是用四舍五入的值构建的并且是正确的(见下面的代码)

enter image description here

但是这个图像是用原始值构建的并且是不正确的(见下面的代码)

enter image description here

这段代码重现了这两个例子(没有显示)。

#include <boost/polygon/voronoi.hpp>
using boost::polygon::voronoi_builder;
using boost::polygon::voronoi_diagram;

struct Point
{
double a;
double b;
Point(double x, double y) : a(x), b(y) {}
};

namespace boost
{
namespace polygon
{
template <>
struct geometry_concept<Point>
{
typedef point_concept type;
};

template <>
struct point_traits<Point>
{
typedef double coordinate_type;

static inline coordinate_type get(const Point& point, orientation_2d orient)
{
return (orient == HORIZONTAL) ? point.a : point.b;
}
};
} // polygon
} // boost

int main()
{

std::vector<double> xx = {8.45619987, 9.96573889, 0.26574428, 7.63918524, 8.15187618, 0.09100718};
std::vector<double> yy = {9.2452883, 7.0843455, 0.4811701, 3.1193826, 5.1336435, 5.5368374};

// std::vector<double> xx = {8, 10, 0, 8, 8, 0};
// std::vector<double> yy = {9, 7, 0, 3, 5, 6};

std::vector<Point> points;

for (int i = 0 ; i < xx.size() ; i++)
{
points.push_back(Point(xx[i], yy[i]));
}

// Construction of the Voronoi Diagram.
voronoi_diagram<double> vd;
construct_voronoi(points.begin(), points.end(), &vd);

for (const auto& vertex: vd.vertices())
{
std::vector<Point> triangle;
auto edge = vertex.incident_edge();
do
{
auto cell = edge->cell();
assert(cell->contains_point());

triangle.push_back(points[cell->source_index()]);
if (triangle.size() == 3)
{
// process output triangles
std::cout << "Got triangle: (" << triangle[0].a << " " << triangle[0].b << ") (" << triangle[1].a << " " << triangle[1].b << ") (" << triangle[2].a << " " << triangle[2].b << ")" << std::endl;
triangle.erase(triangle.begin() + 1);
}

edge = edge->rot_next();
} while (edge != vertex.incident_edge());
}

return 0;
}

最佳答案

It works fine if the points coordinates are not decimal

在试用了您的示例之后,我突然意识到您并不是说“当坐标不是小数时”。你的意思是“整体”。差别很大。

Documentation: Point Concept

The coordinate type is expected to be integral

Floating point coordinate types are not supported by all the algorithms and generally not suitable for use with the library at present.

关于c++ - 来自 Voronoi 的 Delaunay boost : missing triangle with non-integral point coordinates,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50657847/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com