Full Version: A possible script for finding "holes" of a planar closed curve

From: mkdm [#1]
 24 Oct 2017

Hi Michael.

Working on my 2D workflow involving Moi and Affinity Designer I often need to select all the closed curve in Moi
that can be considered as "holes" of a given closed curve.
And I have to do this operation manually. Very tedious.

I don't remember if someone has already written something like that but if not,
I thought of writing this new command : "FindHoles".

But before I do, I want to post this pseudo code and ask if do you think it's a good way or not.
For what I've simulated it should be.

For a better understanding of what I want to do you can also check this brief video : http://take.ms/HJ6Zj

Anyway, this is the pseudo code :


1) CURRENT LIMITATION : All the curves must be planar and must lay on the TOP plane

2) I first select the curve for which I want to find possible "HOLES"

3) I then select the set of all the other curves that I consider "candidate holes"

4) I run this "FindHoles" command that perform these tasks :

Step A) I assign the first selected curve, at index 0 of selected curves, to the variable "IN_CURVE"
Step B) If "IN_CURVE" is not CLOSED then I exit

Step C) I assign all other selected curves, starting from index 1 of selected curves, to the variable "CAND_HOLES"
Step D) If "CAND_HOLES" is EMPTY then I exit

Step E) I perform the "Planar" command on "IN_CURVE"
I call the resulting surface "PLAN_IN_CURVE"

Step F) I enter this loop that should find all "holes" of "IN_CURVE"
This is the pseudo code of the loop :

***** LOOP START *****

For each "ELEMENT" in "CAND_HOLES"

Step 1) I perform the "Project" command

Step 2) "Object to Project" = "ELEMENT"

Step 3) "Projection Target" = "PLAN_IN_CURVE" with : TOP as selected projection plane, "Closest pt" as projection options

Step 4) I get the possible resulting curve and call it "PROJ_RES"

Step 5) If I get no "PROJ_RES" then "ELEMENT" is NOT a "hole" of "IN_CURVE"

Step 6) If "PROJ_RES" is an OPEN curve then "ELEMENT" is NOT a "hole" of "IN_CURVE"

Step 7) If "PROJ_RES" is a CLOSED curve then "ELEMENT" IS a "hole" of IN_CURVE and I add it to the resulting array "FOUND_HOLES"

Step 8) Next (For each)

***** LOOP END *****

At the end I deselect everything and I select all the curves in "FOUND_HOLES"

What do you think ?

Thanks a lot.

Marco (mkdm)


From: Michael Gibson [#2]
 24 Oct 2017

Hi Marco, it sounds like that might work but I haven't analyzed what you've got there in detail yet.

The Construct > Planar command does do this type of hole detection as part of how it functions, so maybe another possible way could be to just send all the curves through PlanarSrf, then in the breps that were generated from that get the brep face and on the face call getLoops() - if a face has more than one loop all the loops after the first one are holes, the first loop is the outer boundary. So for every hole you detected there you'd need to identify the original curve it came from, maybe scanning through your curves and seeing if they have the same start/end points would work. For segmented curves like a square with 4 segments in it that will have 4 separate edges in the loop.

- Michael


From: mkdm [#3]
 24 Oct 2017

Hi Michael.

Thanks a lot for the prompt reply!

Well...I too have considered a solution like the one you told me but for what I've simulated manually it seem not to work and also
maybe it's a little bit more complex than the solution I have though.

For example, using my example scene if I select all curves and apply a single PlananrSfr I get no useful resulting surfaces.
I mean that I can't get the main surface with the holes inside, but only many separated surfaces from each input curve.

Please check this brief video if you can : http://take.ms/QtaWo

Here you can get the example scene file : http://take.ms/uO3Eu

Thanks for your support :)


From: Michael Gibson [#4]
 24 Oct 2017

Hi Marco, yeah you're right, it turns out for a case with some of the curves intersecting each other like you've got there it won't make nested holes. So for that method to work you'd need to detect curves that intersect with your outer boundary and remove those from what you give to PlanarSrf. With the intersected curves removed you could probably use PlanarSrf to detect whether a curve is either inside or outside the outline though, if your other method doesn't work out.

- Michael


From: mkdm [#5]
 24 Oct 2017

Hi Michael.

Thanks a lot for your suggestion.

All in all is almost like the method I thought :)

Ok. I'm going to code a bunch of JS code for a first rough version of the script.

I think that it could be very useful for many use cases.

We'll catch up.


Marco (mkdm)


Reply to All

Back to thread list | Login

© 2018 Project Beehive Forum