discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

#4340: Removing holes from 2D objects

NM
Nick Moore
Thu, Sep 8, 2022 12:04 AM

https://github.com/openscad/openscad/issues/4340

G'day all!

Thanks for writing OpenSCAD!  I've been doing heaps of stuff in it over the last couple of years and really enjoying the way it works a lot more than more conventional CAD software.

I recently had an idea for which I need to automatically remove all the 'holes' from an arbitrary 2D shape (mostly text) before extrusion.  I've posted sketchy implementations of a couple of possible approaches to this problem at issue #4340.

I'm happy to polish this work up and turn it into a PR if there's more general interest, but was hoping for some feedback on which approach sounds appropriate, or whether I'm missing some easier way.

cheers,

-----Nick

https://github.com/openscad/openscad/issues/4340 G'day all! Thanks for writing OpenSCAD! I've been doing heaps of stuff in it over the last couple of years and really enjoying the way it works a lot more than more conventional CAD software. I recently had an idea for which I need to automatically remove all the 'holes' from an arbitrary 2D shape (mostly text) before extrusion. I've posted sketchy implementations of a couple of possible approaches to this problem at issue #4340. I'm happy to polish this work up and turn it into a PR if there's more general interest, but was hoping for some feedback on which approach sounds appropriate, or whether I'm missing some easier way. cheers, -----Nick
CA
Carsten Arnholm
Thu, Sep 8, 2022 6:24 AM

On 08.09.2022 02:04, Nick Moore wrote:

I recently had an idea for which I need to automatically
remove all the 'holes' from an arbitrary 2D shape (mostly text)
before extrusion.

That is an operation that can be fully automated. It is called
'fill2d' in AngelCAD:

'fill2d is a 2-dimensional boolean operation that removes internal holes
in in 2d shapes, but leaves a possibly concave outer contour intact.'

Carsten Arnholm

On 08.09.2022 02:04, Nick Moore wrote: > I recently had an idea for which I need to automatically > remove all the 'holes' from an arbitrary 2D shape (mostly text) > before extrusion. That is an operation that can be fully automated. It is called 'fill2d' in AngelCAD: 'fill2d is a 2-dimensional boolean operation that removes internal holes in in 2d shapes, but leaves a possibly concave outer contour intact.' Carsten Arnholm
TP
Torsten Paul
Thu, Sep 8, 2022 7:49 PM

On 08.09.22 02:04, Nick Moore wrote:

I'm happy to polish this work up and turn it into a PR if
there's more general interest, but was hoping for some
feedback on which approach sounds appropriate, or whether
I'm missing some easier way.

I've seen this discussed before and I think there's no
general solution with the currently available features.

So a PR implementing this would be great. I would suggest
to separate this from offset() though. A dedicated fill()
seems like a good choice.

This would not trivially cover the mentioned "expand only
the outer outline" but that sounds like a tricky thing
that may need to be looked at separately.

Feel free to join the IRC channel if you are interested
in some more interactive discussion.

ciao,
Torsten.

On 08.09.22 02:04, Nick Moore wrote: > I'm happy to polish this work up and turn it into a PR if > there's more general interest, but was hoping for some > feedback on which approach sounds appropriate, or whether > I'm missing some easier way. I've seen this discussed before and I think there's no general solution with the currently available features. So a PR implementing this would be great. I would suggest to separate this from offset() though. A dedicated fill() seems like a good choice. This would not trivially cover the mentioned "expand only the outer outline" but that sounds like a tricky thing that may need to be looked at separately. Feel free to join the IRC channel if you are interested in some more interactive discussion. ciao, Torsten.
JB
Jordan Brown
Thu, Sep 8, 2022 8:23 PM

On 9/8/2022 12:49 PM, Torsten Paul wrote:

This would not trivially cover the mentioned "expand only
the outer outline" but that sounds like a tricky thing
that may need to be looked at separately.

Isn't that

module offset_outside(d) {
    difference() {
        offset(d) fill() children();
        difference() {
            fill() children();
            children();
        }
    }
}

?

On 9/8/2022 12:49 PM, Torsten Paul wrote: > This would not trivially cover the mentioned "expand only > the outer outline" but that sounds like a tricky thing > that may need to be looked at separately. Isn't that module offset_outside(d) {     difference() {         offset(d) fill() children();         difference() {             fill() children();             children();         }     } } ?
NM
Nick Moore
Thu, Sep 8, 2022 9:52 PM

On Fri, 9 Sep 2022, at 05:49, Torsten Paul wrote:

So a PR implementing this would be great. I would suggest
to separate this from offset() though. A dedicated fill()
seems like a good choice.

OK, great!  I'll clean up the first, simplest implementation and change it's name to fill(), get CI working and send in a PR in the next few days.

I was a bit worried about adding new builtin names which is why I was messing with offset() parameters but I guess that's just how it is :-).  It's conceptually simpler, and as Jordan points out, you can do the inside/outside offset thing by combining differences.

Is there a logical operation for fill() on a 3D shape?  I guess if you were unioning lots of objects (or even just two convex objects) you might end up with a little "air bubble" between them and so it could be handy to be have a way to eliminate this.

-----Nick

On Fri, 9 Sep 2022, at 05:49, Torsten Paul wrote: > > So a PR implementing this would be great. I would suggest > to separate this from offset() though. A dedicated fill() > seems like a good choice. OK, great! I'll clean up the first, simplest implementation and change it's name to fill(), get CI working and send in a PR in the next few days. I was a bit worried about adding new builtin names which is why I was messing with offset() parameters but I guess that's just how it is :-). It's conceptually simpler, and as Jordan points out, you can do the inside/outside offset thing by combining differences. Is there a logical operation for fill() on a 3D shape? I guess if you were unioning lots of objects (or even just two convex objects) you might end up with a little "air bubble" between them and so it could be handy to be have a way to eliminate this. -----Nick
TP
Torsten Paul
Thu, Sep 8, 2022 10:12 PM

On 08.09.22 23:52, Nick Moore wrote:

OK, great!  I'll clean up the first, simplest implementation
and change it's name to fill(), get CI working and send in a
PR in the next few days.

It would be nice if you could add a simple test case, but we
can look at that once the PR is created.

https://github.com/openscad/openscad/blob/master/doc/testing.txt
Example: https://github.com/openscad/openscad/pull/4041/files

I was a bit worried about adding new builtin names

While there's always some potential for issues, a new builtin
on it's own is usually not a problem as scripts using that
name would just override this with their own and by definition
can't miss the builtin one that not existed at time of writing.

It's conceptually simpler, and as Jordan points out, you can
do the inside/outside offset thing by combining differences.

If that code works for the general case, even better.

Is there a logical operation for fill() on a 3D shape?

As opposed to the 2d version, I never missed that so far, but
I suppose there could be cases where it would be useful.

ciao,
Torsten.

On 08.09.22 23:52, Nick Moore wrote: > OK, great! I'll clean up the first, simplest implementation > and change it's name to fill(), get CI working and send in a > PR in the next few days. It would be nice if you could add a simple test case, but we can look at that once the PR is created. https://github.com/openscad/openscad/blob/master/doc/testing.txt Example: https://github.com/openscad/openscad/pull/4041/files > I was a bit worried about adding new builtin names While there's always some potential for issues, a new builtin on it's own is usually not a problem as scripts using that name would just override this with their own and by definition can't miss the builtin one that not existed at time of writing. > It's conceptually simpler, and as Jordan points out, you can > do the inside/outside offset thing by combining differences. If that code works for the general case, even better. > Is there a logical operation for fill() on a 3D shape? As opposed to the 2d version, I never missed that so far, but I suppose there could be cases where it would be useful. ciao, Torsten.
NM
Nick Moore
Fri, Sep 9, 2022 7:45 AM

On Fri, 9 Sep 2022, at 08:12, Torsten Paul wrote:

On 08.09.22 23:52, Nick Moore wrote:

OK, great!  I'll clean up the first, simplest implementation
and change it's name to fill(), get CI working and send in a
PR in the next few days.

It would be nice if you could add a simple test case, but we
can look at that once the PR is created.

No worries, I created https://github.com/openscad/openscad/pull/4348 and just copied the hull tests for now, I'll think up some more interesting test cases over the weekend.

If someone can review my C++ for not being utterly stupid that'd be great, there's no compiler warnings but it's been a very long time since I wrote C++ in anger and I can't totally remember how memory management works.

-----N

On Fri, 9 Sep 2022, at 08:12, Torsten Paul wrote: > On 08.09.22 23:52, Nick Moore wrote: >> OK, great! I'll clean up the first, simplest implementation >> and change it's name to fill(), get CI working and send in a >> PR in the next few days. > > It would be nice if you could add a simple test case, but we > can look at that once the PR is created. No worries, I created https://github.com/openscad/openscad/pull/4348 and just copied the hull tests for now, I'll think up some more interesting test cases over the weekend. If someone can review my C++ for not being utterly stupid that'd be great, there's no compiler warnings but it's been a very long time since I wrote C++ in anger and I can't totally remember how memory management works. -----N
RW
Rogier Wolff
Fri, Sep 9, 2022 8:41 AM

On Fri, Sep 09, 2022 at 12:12:17AM +0200, Torsten Paul wrote:

I was a bit worried about adding new builtin names

While there's always some potential for issues, a new builtin
on it's own is usually not a problem as scripts using that
name would just override this with their own and by definition
can't miss the builtin one that not existed at time of writing.

Issues arise when you have a library that does use the builtin and a
"main program" that uses a module of the same name. Or reverse.

Roger. 

--
** R.E.Wolff@BitWizard.nl ** https://www.BitWizard.nl/ ** +31-15-2049110 **
**    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233    **
f equals m times a. When your f is steady, and your m is going down
your a is going up.  -- Chris Hadfield about flying up the space shuttle.

On Fri, Sep 09, 2022 at 12:12:17AM +0200, Torsten Paul wrote: > > I was a bit worried about adding new builtin names > > While there's always some potential for issues, a new builtin > on it's own is usually not a problem as scripts using that > name would just override this with their own and by definition > can't miss the builtin one that not existed at time of writing. Issues arise when you have a library that does use the builtin and a "main program" that uses a module of the same name. Or reverse. Roger. -- ** R.E.Wolff@BitWizard.nl ** https://www.BitWizard.nl/ ** +31-15-2049110 ** ** Delftechpark 11 2628 XJ Delft, The Netherlands. KVK: 27239233 ** f equals m times a. When your f is steady, and your m is going down your a is going up. -- Chris Hadfield about flying up the space shuttle.