Polygon difference - weird results from Clipperlib

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

  • Creating contours.
  • Sorts the contours into a tree structure so that all contours held in a particular contour are children of that contour.
  • For each path, perform a pegging operation with all its children using Clipperlib.

The resulting polygon and holes are a donut of the iso-region. These iso-areas can be displayed as a contour map or used for other purposes. Please note that if all I wanted to do was display the outlines, I could stop after the initial sort and display the outlines in order so that the inner display is on top. I really need actual areas.

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

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

image one

This image shows two polygons: the object is highlighted in red, and the children are filled in blue. I want to subtract children from the topic. Notice the small area next to the mouse pointer. What I expect from this fault is the two outer polygons - small next to the mouse pointer and large. I would expect all the “islands” to be holes in the second, large, polygon.

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

image two

enter image description here

In the second image, the tiny polygon near the mouse pointer is “external”, and all 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.

I am doing clipperlib using the red polygon in the first image as an object, and all the children as clips. The clip type is ctDifference (I also tried Xor with the same results - what they should be, considering that all children are within the object). I ask for the return of PolyTree, which has two Childs. I am using the C # library and also tried v6.

At one level, the results that I need are all there - all the “holes” are labeled as such, the problem is that many of these holes come back as children of a tiny outer area in the upper right corner of the image. Am I reading PolyTree incorrectly using ClipperLib incorrectly, or is this result simply incorrect?

In the next note - I noticed that the new ClipperLib (v6) now takes Z values. Now I wonder if there can be a better method than I use to create these iso-areas from a given set of non-standard contour lines?

thanks Matt

EDIT: I loaded the raw data for the polygons in a text file.

here's a link

There is a subject polygon in the file as the first set of vertices, followed by each of these children. Each polygon is represented as X / Y pairs on the same line, with a new line between each polygon.

+3
source share
1 answer

In the second image, the tiny polygon near the mouse pointer is “external”, and all 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.


It seems like an error somewhere, but hard to say without raw data.

In addition, this is not the best place to support Clipper, there is a forum and a place to report suspicious errors in SourceForge . In any case, it is now best to place your source data here (as little as possible, please, continuing to reproduce the problem).

Edit:

Well, I looked at the data, and I don’t understand why you believe ... "all 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); 

Just filter the top levels of the PolyNodes of the PolyTree solution (and the top-level nodes should be "outers") using the code snippet above, this is what I get (the solution is green) ...

enter image description here

From this result, it is not possible that the “tiny polygon next to the mouse pointer” could own other polygons. Having said that, it is obvious that there are still holes in the solution, so there is an error that needs to be fixed.

Edit 2: I found and fixed the error and uploaded Clipper version 6.0.2 to the SourceForge repository . I need to do a little more error checking before I officially upgrade the main Zip package.

Edit 3: Obviously, everything is still not in order.

Edit 4: I think I finally nailed this error (see Patch 420 in the SourceForge repository). Follow there .

+3
source

Source: https://habr.com/ru/post/959195/


All Articles