使用给定一组点的voroni近似将空间分割为多边形区域

问题描述 投票:1回答:2

我试图将空间划分为一组多边形,其中每个多边形大约是一组输入点之一的voroni单元。

我试图将Boost :: Voroni用于此目的,但是使用这个库的输出很复杂,需要花费很多额外的努力才能得到我想要的东西。

我想知道是否有人知道从BOOST :: voroni图中得到我想要的最好的方法,或者如果有人知道一个更简单的库而不是直接找到我正在寻找的东西?

这里有一些代码显示了我想要做的事情,

voronoi_diagram< float > vd;
construct_voronoi( gridPointPos.begin(), gridPointPos.end(), &vd );

int index = 0;
for (voronoi_diagram<float>::const_cell_iterator it = vd.cells().begin();
    it != vd.cells().end(); ++it, ++index ) {

    // if the voroni cell has infinite edges,
        // then clip them to a finite length

    // extract the voroni vertices of this cell

    // create a boost polygon from the extracted edges
} 

因为boost对于我的需求来说过于笼统和复杂,我更喜欢一个只执行所有这些操作的库或算法,只返回多个多边形集。我有什么选择?

c++ boost voronoi boost-polygon
2个回答
0
投票

您可以在PHP中尝试我的bowyer-Watson增量算法实现delaunay三角测量,它也可以找到voronoi图。您可以在codeplex.com(http://voronoi.codeplex.com/)下载。


0
投票

我有同样的问题,但我真的找不到任何重量轻到我的口味。所以我创建了自己的C实现(单个头文件),请参阅https://github.com/JCash/voronoi

给定一个点数组,以及一些draw_triangle函数:

    jcv_diagram diagram;
    memset(&diagram, 0, sizeof(jcv_diagram));
    jcv_diagram_generate(count, (const jcv_point*)points, width, height, &diagram );

    const jcv_site* sites = jcv_diagram_get_sites( &diagram );
    for( int i = 0; i < diagram.numsites; ++i )
    {
        const jcv_site* site = &sites[i];

        unsigned char color_tri[3] = { 127, 127, 127 };
        const jcv_graphedge* e = site->edges;
        while( e )
        {
            draw_triangle( &site->p, &e->pos[0], &e->pos[1], image, width, height, 3, color_tri);
            e = e->next;
        }
    }

    jcv_diagram_free( &diagram );
© www.soinside.com 2019 - 2024. All rights reserved.