多边形差异-Clipperlib的奇怪结果 [英] Polygon difference - strange results from Clipperlib

查看:279
本文介绍了多边形差异-Clipperlib的奇怪结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从一组轮廓创建等面积多边形(圆环").这是过程:

I am trying to create iso-area polygons ("donuts") from a set of contours. This is the process:

  1. 生成轮廓.
  2. 将轮廓排序为树形结构,这样,在特定轮廓内保存的所有轮廓都是该轮廓的子级.
  3. 对于每个轮廓,请使用Clipperlib对所有轮廓执行不同的操作.

所得的多边形和孔构成等面积甜甜圈".然后可以将这些等面积线渲染为等高线图,或用于其他目的.请注意,如果我只想渲染轮廓,则可以在初始排序后停止并按顺序渲染轮廓,以便最里面的渲染位于顶部.我确实需要实际区域.

The resulting polygon(s) and holes constitute the iso-area "donut". These iso-areas can then be rendered as a contour map, or used for other purposes. Note that if all I wanted to do was render the contours, I could stop after the initial sort and render the contours in order, such that inner-most render on top. I do require the actual areas.

首先-Clipperlib是一个很棒的库,我很乐意为此花钱-谢谢安格斯!

First up - Clipperlib is a fantastic library, and one that I would be very happy to pay good money for - thanks Angus!

我的问题是,在某些情况下,我可能会从差异操作中得到一些奇怪的结果-我怀疑这可能是我的用户错误,因此我将说明问题:

My issue is that I seem to get some strange results from the difference operation in certain situations - I suspect this may be user error on my part, so I will illustrate the problem:

此图像显示两个多边形-主题以红色勾勒出轮廓,子代以蓝色填充.我希望从这个主题中减去孩子们.请注意鼠标指针附近的小区域.我从此差异中期望得到的是两个外部多边形-靠近鼠标指针的小多边形和较大的多边形.我还希望所有的岛"都是第二个较大的多边形内的孔.

This image shows two polygons - the subject is outlined in red, and the children are filled in blue. I wish to subtract the children from the subject. Note the small area near the mouse-pointer. What I would expect from this diff is two outer polygons - the small one near the mouse pointer and the large one. I would further expect all of the "islands" to be holes within the second, large, polygon.

我实际上得到的是两个外部部件(如预期的那样),每个外部部件都带有子级(孔):

What I actually get is two outers (as expected), with children (holes) associated with each:

在第二个图像中,鼠标指针附近的小多边形是外部",而所有其他填充的多边形都是属于它的孔".请注意,我在两个图像中都显示了这两种解决方案的轮廓-仅关注填充的多边形.

In the second image, the tiny polygon near the mouse pointer is the "outer", and all of the other filled polygons are "holes" belonging to it. Note that I show the outlines of both solutions in both images - just focus on the filled polygons.

我正在执行clipperlib,使用第一个图像中的红色多边形作为主题,并将所有子代用作剪辑.剪辑类型是ctDifference(我也尝试过Xor,其结果相同-鉴于所有子项都在主题之内,所以它们应该是相同的). 我要回PolyTree,它有两个孩子.我正在使用c#库,并且还尝试了v6.

I am executing clipperlib using the red polygon in the first image as the subject, and all of the children as clips. Clip type is ctDifference (I have also tried Xor with the same results - which they should be, given that all children are within the subject). I am requesting a PolyTree back, which has two Childs. I am using the c# library, and have also tried v6.

在一个层次上,我需要的结果就全部存在了-所有的孔"都被指定为这样,问题是这些孔中的许多都是作为位于顶部右上角的微小外部区域的子级返回的.图像.我是不正确地阅读了PolyTree,还是错误地使用了ClipperLib,还是这个结果是错误的?

On one level, the results that I need are all there - all of the "holes" are designated such, the problem is that many of these holes are returned as children of the tiny outer area at the top-right of the image. Am I reading the PolyTree incorrectly, using ClipperLib incorrectly, or is this result simply wrong?

进一步说明-我注意到新的ClipperLib(v6)现在接受Z值.我现在想知道是否有比从给定的无序轮廓线集合生成这些等值线更好的方法?

On a further note - I noticed that the new ClipperLib (v6) now accepts Z values. I'm wondering now if there may be a better method than I am using for generating these iso-areas from a given collection of un-ordered contour lines?

谢谢, 马特

我已经将多边形的原始数据上传到了文本文件中.

I have uploaded the raw data for the polygons in a text file.

此处是链接

该文件将主题多边形作为第一组顶点,然后是每个子级.每个多边形在单行上表示为X/Y对,每个多边形之间有换行符.

The file has the subject polygon as the first set of vertices, followed by each of the children. Each polygon is represented as X/Y pairs on a single row, with a newline between each polygon.

推荐答案

在第二个图像中,鼠标指针附近的小多边形是外部",所有其他填充的多边形是属于它的孔".请注意,我在两个图像中都显示了这两种解决方案的轮廓-仅关注填充的多边形.

In the second image, the tiny polygon near the mouse pointer is the "outer", and all of the other filled polygons are "holes" belonging to it. Note that I show the outlines of both solutions in both images - just focus on the filled polygons.


这听起来像是在某个地方有错误,但是如果没有原始数据就很难分辨.


This sounds like there's a bug somewhere but it's hard to tell without the raw data.

此外,这也不是Clipper支持的最佳场所,这里有一个讨论论坛,并在

Also, this isn't the best place for Clipper support, there is a discussion forum and a place to report suspected bugs at SourceForge. Anyhow, it's probably best now to post your raw data here (as little as possible please while still reproducing the problem).

好的,我查看了数据,但我不明白您为什么相信……所有其他填充的多边形都是属于它的"孔"".

OK, I've had a look at the data and I don't understand why you believe ... "all of the other filled polygons are "holes" belonging to it".

      PolyTree solutiontree = new PolyTree();
      cpr.Execute(ClipType.ctDifference, solutiontree, 
          PolyFillType.pftNonZero, PolyFillType.pftNonZero);
      solution = new Polygons(solutiontree.ChildCount);
      foreach (PolyNode pn in solutiontree.Childs)
        solution.Add(pn.Contour);

只需使用上面的代码片段过滤解决方案PolyTree的顶级PolyNode(并且顶级节点必须为外部"),这就是我得到的(解决方案为绿色阴影)...

Just filtering the top level PolyNodes of the solution PolyTree (and top level nodes must be 'outers') using the code snippet above, this is what I get (the solution is shaded green) ...

从这个结果中不可能得出靠近鼠标指针的微小多边形"可以拥有其他多边形的信息. 话虽如此,解决方案中显然仍然存在漏洞,因此存在需要修复的错误.

There's no way from this result that "the tiny polygon near the mouse pointer" can own the other polygons. Having said that, there are evidently still holes in the solution so there's a bug somewhere that needs fixing.

我已经找到并修复了该错误,并将Clipper 6.0.2版本上传到了

Edit 2: I've found and fixed the bug and uploaded Clipper version 6.0.2 to the SourceForge repository. I'll need to do a bit more error checking before I formally update the main Zip package.

修改3: 显然还是不对.

我想我终于找到了这个错误(请参阅SourceForge存储库中的420版). 跟进.

Edit 4: I think I've finally nailed this bug (see revision 420 in SourceForge repository). Follow up there.

这篇关于多边形差异-Clipperlib的奇怪结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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