Planar Holes Finder : a script for 2D workflows!  1-20  21-27

Next
 From:  mkdm
8646.1 
Hi Michael and everyone!

I put my hand on keyboard again and I coded a bunch of JS code that I hope will be very helpful for many people :)

With this work I tried to solve a long-standing problem that almost daily I meet during my 2D workflow session involving Moi and Affinity Designer.

The problem is that I often need to select in Moi all the closed curves that can be considered "holes" of a given closed curve.
And I always had to do this operation manually.
A very tedious task!

So, I have written this "PlanarHolesFinder" script.

Get it at : http://take.ms/BhYv0
Unzip the file and copy it into the "scripts" folder of your Moi installation.

This is the very first 0.1 version but I must say that I'm already very satisfied with it and with its performance on my 7700K :)

To show you some stuff to evaluate I made two tests with two Moi 3dm files, containing only planar curves laying on the TOP plane.

In both files I replicated a "block" composed of 9 planar curves for a total of 179 control points.

1) Scene 1
400 "blocks" for a total of 3600 planar curves and an total of 286400 control points

Total elaboration time : about 6 secs

2) Scene 2
1600 "blocks" for a total of 14400 planar curves and an total of 2577600 control points

Total elaboration time : about 23 secs

The script is totally not optimized but IMHO the performance are already good.

I have in mind some kind of optimization but I have to make some test.

**************************************************************************
**************************************************************************
The script is very easy to use :

1) Select first the PLANAR CLOSED curve that should be the "container" of the holes
2) Select all the other curves that we can consider "candidate holes"
3) Run the script!

At the end of the elaboration, if the script found some "holes", all the "holes" will be automatically selected.
Also the original "container" curve will be selected.

N.B. :

THE SCRIPT IS A LITTLE BIT LIMITED FOR THE MOMENT BECAUSE ONLY THE PROJECTION ON THE TOP PLANE IS TAKEN INTO ACCOUNT.

But anyway the script is capable to recognize as "holes" also NON-Planar curves.

//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////

This is the DEMO video of the scene 1 : http://take.ms/gCbyh

This is the DEMO video of the scene 2 : http://take.ms/YETKu

This is the scene 1 screenshot :



This is the scene 2 screenshot :








Ciao a tutti! (Hello everyone!)

- Marco (mkdm)
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  mkdm
8646.2 
Hi everyone!

...last demo video for Non-planar curves !

Watch it at : http://take.ms/6HpTD

This is the 3dm file : http://take.ms/piqKM

This is the screenshot :





Ciao!

- Marco (mkdm)
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Karsten (KMRQUS)
8646.3 In reply to 8646.2 
Hello Marco,

very interesting script. Maybe it can be pimped to a lasso selection.

Have a nice day
Karsten
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  mkdm
8646.4 In reply to 8646.3 
Hi Kartseen.

@You "...very interesting script. Maybe it can be pimped to a lasso selection..."

Yes! While writing this script I thought so too :)

Lasso selection...the "missed" thing! LOL :)

As I said this is the very first 0.1 version of the script but if you want to share your skill with me and us,
please feel free to get this script and improve it with your experimentation and ideas !

I'm not "jealous" about my scripts/commands :)

I have in mind some optimization and or improvements for this script but it could be very interesting
if you want to share what you are thinking about this script.

As a final note I can tell you that "PlanarHolesFinder" will be also very very useful in bundle with the other script that I hope to complete soon,
that is "FilterCurveByLenght".

You will see.

It's another very interesting commands very useful for 2D workflows.

Stay tuned.

We'll catch up.

Ciao!

- Marco (mkdm)
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  mkdm
8646.5 
Hi everyone.

P.S LOL! LOL!

I think I made a big "mathematical" error in my very first post :)

I have reported a wrong number of total control points.

This is the correct values :

In both files I replicated a "block" composed of 9 planar curves for a total of 179 control points.

1) Scene 1
400 "blocks" for a total of 3600 planar curves and an total of 71600 control points (NOT 286400)

Total elaboration time : about 6 secs THIS WAS ALREADY CORRECT

2) Scene 2
1600 "blocks" for a total of 14400 planar curves and an total of 286400 control points (NOT 2577600)

Total elaboration time : about 23 secs THIS WAS ALREADY CORRECT

Ciao!

- Marco (mkdm)
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  mkdm
8646.6 
Hi!

Hmm...I think I should rename this script.

...maybe "PlanarHolesFinder" is not the correct name...

- Marco (mkdm)
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  mkdm
8646.7 
Hi Michael.

WOW!!

I've just found out that my knowledge of Moi is very weak! LOL LOL :)

I discovered that this sentence was totally wrong :

"THE SCRIPT IS A LITTLE BIT LIMITED FOR THE MOMENT BECAUSE ONLY THE PROJECTION ON THE TOP PLANE IS TAKEN INTO ACCOUNT."

Please watch this video : http://take.ms/AF6Rq

IT WORKS ALSO FROM THE OTHER VIEWS!!!

But...if I rotate the "container" curve to a given angle, one of the possible "holes" is not taken into account...

This it the 3dm file : http://take.ms/3Ryb1



Evidently I don't know very well the internal mechanism of "Project" command :)

Could you help me about this point ?

Thanks a lot.

I repeat...I think I should rename the script :)

Ciao!

- Marco (mkdm)
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
8646.8 In reply to 8646.7 
Hi Marco, did you say you were using "closest point" mode for the projection? That mode works by calculating the closest point from a location on the curve to the surface and so it's not dependent on a single direction. It doesn't work too well with curvy surfaces when the curve isn't right near the surface though.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  mkdm
8646.9 In reply to 8646.8 
Yes Michael!

I'm using "closest point" method because I thought it was the easiest one.

For this very first version of the script I wanted to minimize the "inputs" so I've used the most simplified version of "Project" :

code:
		factory = moi.command.createFactory('project');
		factory.setInput(0, projectInput);
		factory.setInput(1, projectTarget);
		factory.setInput(2, 'closestpt');
		
		projectResult = factory.calculate();


But...I didn't understand very well this part of the sentence :

@You : "It doesn't work too well with curvy surfaces when the curve isn't right near the surface though."

Thanks.

- Marco (mkdm)
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  mkdm
8646.10 
Hi everyone.

I'm working on a tweaked version of the script to make it more friendly for a strict "Lasso" selection...

It will be sufficient to draw the "Lasso" and select it. Then fire the script.

And...voilá!

I have to add the code that should automatically remove the "lasso" at the end of execution if something has been found.

N.B. Keep in mind the same considerations of my previous posts. It uses the "project" command with "closes pt".
Then all the previous considerations can be applied also to this "modified" implementation I'm working on for the "Lasso"

For the moment this is a demo video : http://take.ms/9x0Yx

This is a screenshot :




Ciao!

- Marco (mkdm)
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Mik (MIKULAS)
8646.11 In reply to 8646.10 
Excellent script Marco!
Lasso selection for closed curves is perfetto!

Thanks a lot, I missed this command quite often. Maybe it would useful to combine this script with "SelectInetrescted" script which works as a lasso selection for solids, then "Lasso selection" script could be universal.

Ciao
Mik
Attachments:

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  mkdm
8646.12 In reply to 8646.11 
Ciao Mik!

Thanks a lot for your appreciation! Thanks!

Your idea to combine this script with your "SelectInetrescted" it's a great idea!

I hope soon, maybe tonight, to release the 0.2 version of "PlanarHolesFinder" and also the special modified version "LassoSelCurves"
and the in the next days I will study "SelectInetrescted" to see what can I do to combine both!

It could be a great thing having these kind of scripts combined, but also in the case it will be too complex,
with the very fast workflow of Moi's shortcut we can always fire commands/scripts at the speed of light :)

My intention is to create a little set of very specialized script especially dedicated to 2D Workflows,
and "PlanarHolesFinder"/"LassoSelCurves" are just the first,
but...at the moment it's best for me not make too many plans :)

Stay tuned!


Ciao!

Marco (mkdm)
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
8646.13 In reply to 8646.9 
Hi Marco,

> But...I didn't understand very well this part of the sentence :
>
> @You : "It doesn't work too well with curvy surfaces when the curve isn't right near the surface though."

If you have a curvy surface instead of a flat surface, this type of projection down by surface normal will make the projected result squish together or expand and the Solids++ routine for this function doesn't deal very well with that, it tends to produce a curve with little zig-zags in it. If the curve is pretty close to a wavy surface it can work ok though.

But I need to make a new implementation for it at some point here since it can give bad results.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  mkdm
8646.14 In reply to 8646.13 
Hi Michael.

Ok. Understood.

@You : "...If you have a curvy surface instead of a flat surface..."
But...the problem is that I never have Non-flat surface.
The surface that I use with as the target for "Project" is always flat, but there are some situation where it fails anyway.

Strange thing...

You can watch again my previous post and the video posted at (http://moi3d.com/forum/index.php?webtag=MOI&msg=8646.7)

This is the video : http://take.ms/AF6Rq

As you can see at position 01:58 I use the Circle as reference to find holes in it.
The circle if is simply rotated but is FLAT.
And as you can see the blue curve is not considered "hole". Is not "captured" by the "Project" command.


I stay tuned.

Thanks.

- Marco (mkdm)
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  mkdm
8646.15 In reply to 8646.13 
...maybe I should switch to "Direction" mode for the "Project" command.

But I wanted to use "ClosestPt" because it's more easy and requires less interaction with the user, less inputs from him.

I think if I switch to "Direction" for "Project", if I want to keep the code simple at least for this first upcoming official release of the script,
my command will work only for Top Plane.

Instead using "ClosestPt" I've seen that it works also for all standard planes (right, left....)

I don't know.

Also I'm writing this script to be placed in "Scripts" folder, non in "Commands" because I don't want for it any UI.
Just fire a shortcut and run it, both Lasso and "FindHoles" variants.

What do you think ?

Thanks.

- Marco (mkdm)
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
8646.16 In reply to 8646.14 
Hi Marco, yes it sounds like the "closest point" mode for project isn't reliable enough for you, the direction mode should work better. Or another possibility could be the steps that I mentioned earlier - determine if any curves intersect the outer boundary (use the "intersect" factory from the Construct > Curve > Isect command and see if it generates any result), remove those then send the rest to planarsrf to generate loops. Use the hole loops to identify the curves they came from by seeing if any start/end points match between the curve segments and the hole edges.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  mkdm
8646.17 In reply to 8646.16 
Hi Michael.

Thanks a lot for the suggestion.

But...I think that the method you mentioned is not right for me.

Because this part of the sentence " if any start/end points match between the curve segments and the hole edges" it's too restrictive.
I could have more than one curve that shares the same start/end point but with different shapes.

For example :



Furthermore also this part of the sentence is not what I want to do : "...remove those then send the rest to planarsrf to generate loops."

Because I want to use my script to find not only "totally enclosed curves" but also "partially enclosed", that is the curves that intersect the boundary of
the "container".


I really don't know.

Maybe for the moment I can continue to use "Project" with "ClosestPt" and for the moment not to take into account the rare cases where it fails .

Or I can decide to witch to "Direction" mode and for the moment restrict the scope of my scripts to "TOP plane only", that also was the original idea.

I don't know.

Have you got a final suggestion to give me about these considerations ?

Thanks a lot :)

Marco (mkdm)
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
8646.18 In reply to 8646.17 
Hi Marco, my suggestion for the shared point case you show there would be to not consider that to be a hole, that will be malformed geometry if you try to actually create a hole like that where a hole boundary intersects with the outer boundary. Boundaries should not be self intersecting and outer/inner boundaries should not intersect with each other. If they do then there become areas of a trimmed surface where the inside and outside regions of the surface are not well defined.

For the other part you mention:

> Furthermore also this part of the sentence is not what I want to do : "...remove those then send the rest to planarsrf to generate loops."
>
> Because I want to use my script to find not only "totally enclosed curves" but also "partially enclosed", that is the curves
> that intersect the boundary of the "container".

Ok, then instead of removing the intersected curves from consideration just put them also into the "captured" list but don't send them over to planarsrf.

But another problem is it sounds like you're not just looking for "holes" anymore, to make a "hole" it has to be a closed curve.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
8646.19 In reply to 8646.17 
Hi Marco, also for direction I think you should be able to automatically figure out a projection direction by getting the bounding box of your containment curve and then seeing which direction has a zero extent.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  mkdm
8646.20 In reply to 8646.18 
@You : "...But another problem is it sounds like you're not just looking for "holes" anymore, to make a "hole" it has to be a closed curve..."

You're right Michael :)

The fact is that I wanted initially to start a script for "2D workflows" not for "solids" or "solids boolean" stuff.

My script does this main things :

1) Capture all curves that can be considered "holes" of another flat curve.
I know that this part of the sentence was not very clear.
When Is said "Hole" I wanted to say : closed curves that, when projected, are totally enclosed into the "planar surface" created using the"container" curve.

2) During my coding I also wanted to add capabilities to capture also other situations.
So, now I'm coding my script to be fired in 3 different ways :

A) Capture all "totally enclosed" in "container curve"
B) Capture all "partially enclosed" in "container curve", that is the curves that when projected they intersect the boundary of the "container"
3) Capture both of them

But...during the coding and also during the various experiments and tests popped into my mind that the scripts also could works with
other planes, not only TOP plane, and I started to face with the problem of "Direction" vs "ClosestPt."


Now I try to switch to "Direction" mode and leave the script with the minimum interaction with the user,
assuming that the direction in forced to TOP plane.

Later, when the first official version of the script will be tested by other users, I will try to make it more complex.


I'm also writing the variant for a quick "Lasso" selection !

Thanks for all your help :)

I think I need some suggestion for using the "Project" factory with "Direction", but I want first to try.

We'll catch up!

Ciao!

Marco (mkdm)
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All

 

 
Show messages:  1-20  21-27