discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Bad Polyhedron Faces

LM
Leonard Martin Struttmann
Sat, Nov 23, 2024 1:39 PM

I’d like to discuss a potential feature request.

Viewing polyhedra using Thrown Together shows mis-ordered faces in pink.
For simple polyhedra it is relatively easy to track down the “bad” faces
and correct them.

However, for large, complicated polyhedra this is much more difficult.

Obviously, during Preview, OpenSCAD can determine if a face is
mis-ordered.  Could we have an optional Feature such that OpenSCAD throws a
warning when a mis-ordered face is encountered AND identifies the index of
the mis-ordered face?

Thanks

Len

I’d like to discuss a potential feature request. Viewing polyhedra using Thrown Together shows mis-ordered faces in pink. For simple polyhedra it is relatively easy to track down the “bad” faces and correct them. However, for large, complicated polyhedra this is much more difficult. Obviously, during Preview, OpenSCAD can determine if a face is mis-ordered. Could we have an optional Feature such that OpenSCAD throws a warning when a mis-ordered face is encountered AND identifies the index of the mis-ordered face? Thanks Len
LM
Leonard Martin Struttmann
Sat, Nov 23, 2024 1:42 PM

Never mind.  Reading the docs more closely I see that ALL faces have a pink
side.  Please ignore the previous email.

On Sat, Nov 23, 2024 at 7:39 AM Leonard Martin Struttmann <
lenstruttmann@gmail.com> wrote:

I’d like to discuss a potential feature request.

Viewing polyhedra using Thrown Together shows mis-ordered faces in pink.
For simple polyhedra it is relatively easy to track down the “bad” faces
and correct them.

However, for large, complicated polyhedra this is much more difficult.

Obviously, during Preview, OpenSCAD can determine if a face is
mis-ordered.  Could we have an optional Feature such that OpenSCAD throws a
warning when a mis-ordered face is encountered AND identifies the index of
the mis-ordered face?

Thanks

Len

Never mind. Reading the docs more closely I see that ALL faces have a pink side. Please ignore the previous email. On Sat, Nov 23, 2024 at 7:39 AM Leonard Martin Struttmann < lenstruttmann@gmail.com> wrote: > I’d like to discuss a potential feature request. > > Viewing polyhedra using Thrown Together shows mis-ordered faces in pink. > For simple polyhedra it is relatively easy to track down the “bad” faces > and correct them. > > However, for large, complicated polyhedra this is much more difficult. > > Obviously, during Preview, OpenSCAD can determine if a face is > mis-ordered. Could we have an optional Feature such that OpenSCAD throws a > warning when a mis-ordered face is encountered AND identifies the index of > the mis-ordered face? > > Thanks > > Len > >
TP
Torsten Paul
Sat, Nov 23, 2024 4:42 PM

On 23.11.24 14:39, Leonard Martin Struttmann via Discuss wrote:

Obviously, during Preview, OpenSCAD can determine if a face is mis-
ordered.

Wrong (unfortunately). The user can see this is the case due to
what the graphics card draws. OpenSCAD has no knowledge of that
fact whatsoever.

ciao,
Torsten.

On 23.11.24 14:39, Leonard Martin Struttmann via Discuss wrote: > Obviously, during Preview, OpenSCAD can determine if a face is mis- > ordered. Wrong (unfortunately). The user can see this is the case due to what the graphics card draws. OpenSCAD has no knowledge of that fact whatsoever. ciao, Torsten.
TP
Torsten Paul
Sat, Nov 23, 2024 4:49 PM

On 23.11.24 14:42, Leonard Martin Struttmann via Discuss wrote:

Never mind.  Reading the docs more closely I see that ALL faces have a
pink side.  Please ignore the previous email.

Haha, too late. But all what's said so far means it's not just easily
done with the currently available information. There might be ways of
helping a bit even if a full analysis is very difficult.

So maybe it would be possible to collect ideas somewhere even though
it might take a while to get something actually into OpenSCAD.

First idea: It might be possible to determine the offending face when
clicking on the pink-ish color similar to how the "jump-to-source"
works. That would not scale well to huge polyhedrons, but could maybe
help with manual debugging smaller ones.

ciao,
Torsten.

On 23.11.24 14:42, Leonard Martin Struttmann via Discuss wrote: > Never mind.  Reading the docs more closely I see that ALL faces have a > pink side.  Please ignore the previous email. Haha, too late. But all what's said so far means it's not just easily done with the currently available information. There might be ways of helping a bit even if a full analysis is very difficult. So maybe it would be possible to collect ideas somewhere even though it might take a while to get something actually into OpenSCAD. First idea: It might be possible to determine the offending face when clicking on the pink-ish color similar to how the "jump-to-source" works. That would not scale well to huge polyhedrons, but could maybe help with manual debugging smaller ones. ciao, Torsten.
AM
Adrian Mariano
Sat, Nov 23, 2024 4:59 PM

If you're just looking for a solution and your polyhedron isn't too big,
you can use the BOSL2 function, vnf_validate() which identifies any faults
in your polyhedron.  On large polyhedra the run time may be prohibitive.

On Sat, Nov 23, 2024 at 8:39 AM Leonard Martin Struttmann via Discuss <
discuss@lists.openscad.org> wrote:

I’d like to discuss a potential feature request.

Viewing polyhedra using Thrown Together shows mis-ordered faces in pink.
For simple polyhedra it is relatively easy to track down the “bad” faces
and correct them.

However, for large, complicated polyhedra this is much more difficult.

Obviously, during Preview, OpenSCAD can determine if a face is
mis-ordered.  Could we have an optional Feature such that OpenSCAD throws a
warning when a mis-ordered face is encountered AND identifies the index of
the mis-ordered face?

Thanks

Len


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

If you're just looking for a solution and your polyhedron isn't too big, you can use the BOSL2 function, vnf_validate() which identifies any faults in your polyhedron. On large polyhedra the run time may be prohibitive. On Sat, Nov 23, 2024 at 8:39 AM Leonard Martin Struttmann via Discuss < discuss@lists.openscad.org> wrote: > I’d like to discuss a potential feature request. > > Viewing polyhedra using Thrown Together shows mis-ordered faces in pink. > For simple polyhedra it is relatively easy to track down the “bad” faces > and correct them. > > However, for large, complicated polyhedra this is much more difficult. > > Obviously, during Preview, OpenSCAD can determine if a face is > mis-ordered. Could we have an optional Feature such that OpenSCAD throws a > warning when a mis-ordered face is encountered AND identifies the index of > the mis-ordered face? > > Thanks > > Len > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
BC
Bob Carlson
Sat, Nov 23, 2024 5:55 PM

I have looked at the documentation when I saw Thrown Together mentioned, but I could not find anything useful. What is Thrown Together anyway?

-Bob

On Nov 23, 2024, at 09:59, Adrian Mariano via Discuss discuss@lists.openscad.org wrote:

If you're just looking for a solution and your polyhedron isn't too big, you can use the BOSL2 function, vnf_validate() which identifies any faults in your polyhedron.  On large polyhedra the run time may be prohibitive.

On Sat, Nov 23, 2024 at 8:39 AM Leonard Martin Struttmann via Discuss <discuss@lists.openscad.org mailto:discuss@lists.openscad.org> wrote:

I’d like to discuss a potential feature request.

Viewing polyhedra using Thrown Together shows mis-ordered faces in pink.  For simple polyhedra it is relatively easy to track down the “bad” faces and correct them.

However, for large, complicated polyhedra this is much more difficult.

Obviously, during Preview, OpenSCAD can determine if a face is mis-ordered.  Could we have an optional Feature such that OpenSCAD throws a warning when a mis-ordered face is encountered AND identifies the index of the mis-ordered face?

Thanks

Len


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org mailto:discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

I have looked at the documentation when I saw Thrown Together mentioned, but I could not find anything useful. What is Thrown Together anyway? -Bob > On Nov 23, 2024, at 09:59, Adrian Mariano via Discuss <discuss@lists.openscad.org> wrote: > > If you're just looking for a solution and your polyhedron isn't too big, you can use the BOSL2 function, vnf_validate() which identifies any faults in your polyhedron. On large polyhedra the run time may be prohibitive. > > On Sat, Nov 23, 2024 at 8:39 AM Leonard Martin Struttmann via Discuss <discuss@lists.openscad.org <mailto:discuss@lists.openscad.org>> wrote: >> I’d like to discuss a potential feature request. >> >> Viewing polyhedra using Thrown Together shows mis-ordered faces in pink. For simple polyhedra it is relatively easy to track down the “bad” faces and correct them. >> >> However, for large, complicated polyhedra this is much more difficult. >> >> Obviously, during Preview, OpenSCAD can determine if a face is mis-ordered. Could we have an optional Feature such that OpenSCAD throws a warning when a mis-ordered face is encountered AND identifies the index of the mis-ordered face? >> >> Thanks >> >> Len >> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org <mailto:discuss-leave@lists.openscad.org> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org
JB
Jordan Brown
Sat, Nov 23, 2024 6:27 PM

On 11/23/2024 5:42 AM, Leonard Martin Struttmann via Discuss wrote:

Never mind.  Reading the docs more closely I see that ALL faces have a
pink side.  Please ignore the previous email.

Right.  The previewer actually doesn't know which face is toward the
camera; it paints one side yellow and the other side purple, and the
graphics subsystem figures out what is in front of what.

It is possible to detect face-twist and face-connection problems.  In
a proper polyhedron, each edge belongs to exactly two faces, and is
traversed in opposite order on the two faces. Consider a cube in its
default orientation.  The edge that runs along the Z axis, the one where
X and Y are zero, is connected to the front face, where clockwise is
"up", and is connected to the left face, where clockwise is "down".  If
a particular edge is traversed only once, there's a hole.  If it's
traversed three or more times, the polyhedron is not manifold.  If it's
traversed twice in the same direction, the faces are inconsistently wound.

That check is relatively straightforward to implement in C++, but
painful to implement in OpenSCAD.  (For n being the number of edges,
it's O(n) in C++, and I think it can be done in O(n log n) in OpenSCAD. 
The problem is that you can't populate an array in arbitrary order in
OpenSCAD.)

That check will let you ensure that the polyhedron is consistent, that
the faces are all wound in the same direction.  It won't tell you
whether they are all wound clockwise-from-the-outside.  Ref, e.g.,
https://xkcd.com/2403/ .

However, there's also a way to detect that.  The formula for the volume
of a polyhedron https://en.wikipedia.org/wiki/Polyhedron#Volume will
naturally produce a positive number if the faces are wound one way, and
a negative number if the faces are wound the other way.  Again for n
being the number of edges, I believe that's O(n).

So, net, while it's a nuisance to do in OpenSCAD-language, it's not
awful to do the appropriate checks in C++.  Not free, and maybe not
worth doing on every polyhedron construction, but not awful.  (After
all, once you learn how to build the polyhedron correctly, re-checking
it is a waste of time)

If we wanted it to, OpenSCAD could even correct an inside-out
polyhedron, or could attempt to correct an inconsistently-wound
polyhedron.  (Can't correct a Klein bottle, though.)  But that would
require running the check on every polyhedron, which seems like an
unreasonable processing expense.

On 11/23/2024 5:42 AM, Leonard Martin Struttmann via Discuss wrote: > Never mind.  Reading the docs more closely I see that ALL faces have a > pink side.  Please ignore the previous email. Right.  The previewer actually doesn't know which face is toward the camera; it paints one side yellow and the other side purple, and the graphics subsystem figures out what is in front of what. It *is* possible to detect face-twist and face-connection problems.  In a proper polyhedron, each edge belongs to exactly two faces, and is traversed in opposite order on the two faces. Consider a cube in its default orientation.  The edge that runs along the Z axis, the one where X and Y are zero, is connected to the front face, where clockwise is "up", and is connected to the left face, where clockwise is "down".  If a particular edge is traversed only once, there's a hole.  If it's traversed three or more times, the polyhedron is not manifold.  If it's traversed twice in the same direction, the faces are inconsistently wound. That check is relatively straightforward to implement in C++, but painful to implement in OpenSCAD.  (For n being the number of edges, it's O(n) in C++, and I think it can be done in O(n log n) in OpenSCAD.  The problem is that you can't populate an array in arbitrary order in OpenSCAD.) That check will let you ensure that the polyhedron is consistent, that the faces are all wound in the same direction.  It won't tell you whether they are all wound clockwise-from-the-outside.  Ref, e.g., https://xkcd.com/2403/ . However, there's also a way to detect that.  The formula for the volume of a polyhedron <https://en.wikipedia.org/wiki/Polyhedron#Volume> will naturally produce a positive number if the faces are wound one way, and a negative number if the faces are wound the other way.  Again for n being the number of edges, I believe that's O(n). So, net, while it's a nuisance to do in OpenSCAD-language, it's not awful to do the appropriate checks in C++.  Not free, and maybe not worth doing on every polyhedron construction, but not awful.  (After all, once you learn how to build the polyhedron correctly, re-checking it is a waste of time) If we wanted it to, OpenSCAD could even correct an inside-out polyhedron, or could attempt to correct an inconsistently-wound polyhedron.  (Can't correct a Klein bottle, though.)  But that would require running the check on every polyhedron, which seems like an unreasonable processing expense.
JB
Jordan Brown
Sat, Nov 23, 2024 7:03 PM

On 11/23/2024 10:27 AM, Jordan Brown via Discuss wrote:

It is possible to detect face-twist and face-connection problems.

Let me back that off a little.

You can detect those problems if:

  • you're looking at a polyhedron() call, and
  • the polyhedron uses the same entry in the points array for shared
    vertexes, and
  • the polyhedron uses different entries in the points array for
    vertexes that just happen to be in the same place.

Consider the case of two cubes that touch along an edge:

cube(10);
translate([10,10,0]) cube(10);

If you represented this as a single polyhedron, that shared edge needs
to be represented twice, with one cube connecting two of the points and
the other cube connecting the other two points.

This restriction also impacts import() of an STL, and is worse there
because an STL has only coordinates, no indexes.  Two identical sets of
coordinates are necessarily the same "point".  The
two-cubes-sharing-an-edge case can't be turned into "every edge
traversed twice".

There might be a more general rule that every edge must be traversed an
even number of times, half in one direction and half in the other
direction.  I'm not sure.

On 11/23/2024 10:27 AM, Jordan Brown via Discuss wrote: > It *is* possible to detect face-twist and face-connection problems. Let me back that off a little. You can detect those problems if: * you're looking at a polyhedron() call, and * the polyhedron uses the same entry in the points array for shared vertexes, and * the polyhedron uses *different* entries in the points array for vertexes that just happen to be in the same place. Consider the case of two cubes that touch along an edge: cube(10); translate([10,10,0]) cube(10); If you represented this as a single polyhedron, that shared edge needs to be represented twice, with one cube connecting two of the points and the other cube connecting the other two points. This restriction also impacts import() of an STL, and is worse there because an STL has only coordinates, no indexes.  Two identical sets of coordinates are necessarily the same "point".  The two-cubes-sharing-an-edge case can't be turned into "every edge traversed twice". There might be a more general rule that every edge must be traversed an even number of times, half in one direction and half in the other direction.  I'm not sure.
LM
Leonard Martin Struttmann
Sat, Nov 23, 2024 9:31 PM

Wow!  Thanks for all of this info about checks.  I am currently writing
some Python code to help me check a polyhedron that was generated by a
program other than OpenSCAD.

Len

On Sat, Nov 23, 2024 at 1:03 PM Jordan Brown via Discuss <
discuss@lists.openscad.org> wrote:

On 11/23/2024 10:27 AM, Jordan Brown via Discuss wrote:

It is possible to detect face-twist and face-connection problems.

Let me back that off a little.

You can detect those problems if:

- you're looking at a polyhedron() call, and
- the polyhedron uses the same entry in the points array for shared
vertexes, and
- the polyhedron uses *different* entries in the points array for
vertexes that just happen to be in the same place.

Consider the case of two cubes that touch along an edge:

cube(10);
translate([10,10,0]) cube(10);

If you represented this as a single polyhedron, that shared edge needs to
be represented twice, with one cube connecting two of the points and the
other cube connecting the other two points.

This restriction also impacts import() of an STL, and is worse there
because an STL has only coordinates, no indexes.  Two identical sets of
coordinates are necessarily the same "point".  The
two-cubes-sharing-an-edge case can't be turned into "every edge traversed
twice".

There might be a more general rule that every edge must be traversed an
even number of times, half in one direction and half in the other
direction.  I'm not sure.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Wow! Thanks for all of this info about checks. I am currently writing some Python code to help me check a polyhedron that was generated by a program other than OpenSCAD. Len On Sat, Nov 23, 2024 at 1:03 PM Jordan Brown via Discuss < discuss@lists.openscad.org> wrote: > On 11/23/2024 10:27 AM, Jordan Brown via Discuss wrote: > > It *is* possible to detect face-twist and face-connection problems. > > > Let me back that off a little. > > You can detect those problems if: > > - you're looking at a polyhedron() call, and > - the polyhedron uses the same entry in the points array for shared > vertexes, and > - the polyhedron uses *different* entries in the points array for > vertexes that just happen to be in the same place. > > Consider the case of two cubes that touch along an edge: > > cube(10); > translate([10,10,0]) cube(10); > > If you represented this as a single polyhedron, that shared edge needs to > be represented twice, with one cube connecting two of the points and the > other cube connecting the other two points. > > > This restriction also impacts import() of an STL, and is worse there > because an STL has only coordinates, no indexes. Two identical sets of > coordinates are necessarily the same "point". The > two-cubes-sharing-an-edge case can't be turned into "every edge traversed > twice". > > > There might be a more general rule that every edge must be traversed an > even number of times, half in one direction and half in the other > direction. I'm not sure. > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
JB
Jon Bondy
Sat, Nov 23, 2024 9:53 PM

Carsten Arnholm has written some fairly comprehensive checking
programs.  Maybe check with him before you re-invent the wheel, unless
you like that sort of thing.

On 11/23/2024 4:31 PM, Leonard Martin Struttmann via Discuss wrote:

Wow! Thanks for all of this info about checks.  I am currently writing
some Python code to help me check a polyhedron that was generated by a
program other than OpenSCAD.

Len

--
This email has been checked for viruses by AVG antivirus software.
www.avg.com

Carsten Arnholm has written some fairly comprehensive checking programs.  Maybe check with him before you re-invent the wheel, unless you like that sort of thing. On 11/23/2024 4:31 PM, Leonard Martin Struttmann via Discuss wrote: > Wow! Thanks for all of this info about checks.  I am currently writing > some Python code to help me check a polyhedron that was generated by a > program other than OpenSCAD. > > Len > -- This email has been checked for viruses by AVG antivirus software. www.avg.com