bugs: export/import hollow stl models bug

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

bugs: export/import hollow stl models bug

clothbot
Hi Clifford and Marius,

I think I've narrowed in on some symptoms of these STL-related import/export bugs a bit more:

1. Grab http://github.com/clothbot/eda/blob/master/openscad/tests/Makefile.STL

2. Set the OPENSCAD path

3. Run "make test_diff_import_stl.stl"

4. Open the intermediate "test_diff_import_stl.scad" file in a graphical OpenSCAD session.

Rotate the model around until you can see the diff'd out corner of the imported hollow cube.

STL Export Bug:
        - The internal hollow volume facets appear to be winding loops the wrong direction.
        - The F5-Compile looks like empty/infinite space
        - F6-Compile&Render is a solid cube

STL Import Bug:
        - Use http://github.com/clothbot/eda/blob/master/openscad/tests/test_hollow_cube.fixed.winding.stl
                - The F5-Compile looks more correct (not empty/infinite space)
                - F6-Compile&Render is still a solid cube.
        - Use http://github.com/clothbot/eda/blob/master/openscad/tests/test_hollow_cube.fixed.meshlab.stl
                - The F5-Compile looks the same as the fixed.winding.stl so also fixing the face normals via meshlab doesn't improve things.
                - F6-Compile&Render is still a solid cube.

Andrew.

--

"The future is already here.  It's just not very evenly distributed" -- William Gibson

Me: http://clothbot.com/wiki/




Reply | Threaded
Open this post in threaded view
|

Re: bugs: export/import hollow stl models bug

kintel
Administrator
Andrew,

After looking at this, I think I know why this happens, although not how to fix it:

OpenSCAD imports an STL file into a single CGAL::Polyhedron_3 object.
This object stores the STL file as a single 2-manifold surface. Volumes with holes are,
if I understand the docs correctly, not supported. What exactly happens with not supported
surfaces is unknown and perhaps arbitrary, which you have discovered.

To fix this, I think we need to do smth. like this:
o Detect separate sub-volumes in a loaded model.
o If any of the sub-volumes are defined "inside-out" or lies wholly within another positive volume, we can convert this to a   CSG difference.

Clifford: Any insight into this based on your CGAL experience?

~/= Marius

--
We are Elektropeople for a better living.


Reply | Threaded
Open this post in threaded view
|

Re: bugs: export/import hollow stl models bug

clothbot
Hi Marius,

Just spotted one possible place to fix the null face export issues.

Line 120 of src/export.cc: Look for cases where vs1, vs2 and vs3 fall on the same line, not just the same point.

Andrew.


On 2010-07-02, at 4:32 PM, Marius Kintel wrote:

> Andrew,
>
> After looking at this, I think I know why this happens, although not how to fix it:
>
> OpenSCAD imports an STL file into a single CGAL::Polyhedron_3 object.
> This object stores the STL file as a single 2-manifold surface. Volumes with holes are,
> if I understand the docs correctly, not supported. What exactly happens with not supported
> surfaces is unknown and perhaps arbitrary, which you have discovered.
>
> To fix this, I think we need to do smth. like this:
> o Detect separate sub-volumes in a loaded model.
> o If any of the sub-volumes are defined "inside-out" or lies wholly within another positive volume, we can convert this to a   CSG difference.
>
> Clifford: Any insight into this based on your CGAL experience?
>
> ~/= Marius
>
> --
> We are Elektropeople for a better living.
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad

--

"The future is already here.  It's just not very evenly distributed" -- William Gibson

Me: http://clothbot.com/wiki/




Reply | Threaded
Open this post in threaded view
|

Re: bugs: export/import hollow stl models bug

kintel
Administrator
On Jul 2, 2010, at 23:35 PM, Andrew Plumb wrote:
> Just spotted one possible place to fix the null face export issues.
>
> Line 120 of src/export.cc: Look for cases where vs1, vs2 and vs3 fall on the same line, not just the same point.

If we just ignore such triangles, the resulting mesh wouldn't be continuous. This will cause interesting problems later on.
The correct way to do this (without modifying vertices) would be to do an edge swap on the longest of the colinear edges instead.

~/= Marius

--
We are Elektropeople for a better living.





Reply | Threaded
Open this post in threaded view
|

throw warning+coords on stl export null and same-line faces (was Re: bugs: export/import hollow stl models bug)

clothbot
On 2010-07-02, at 6:26 PM, Marius Kintel wrote:

> On Jul 2, 2010, at 23:35 PM, Andrew Plumb wrote:
>> Just spotted one possible place to fix the null face export issues.
>>
>> Line 120 of src/export.cc: Look for cases where vs1, vs2 and vs3 fall on the same line, not just the same point.
>
> If we just ignore such triangles, the resulting mesh wouldn't be continuous. This will cause interesting problems later on.
> The correct way to do this (without modifying vertices) would be to do an edge swap on the longest of the colinear edges instead.


For the time being, could you add some code to throw warnings+coordinates when null and same-line degenerate faces are detected  at stl export time?  That might open up some options to fix things either within the OpenSCAD model code or by post-processing the resulting STL.

Andrew.

--

"The future is already here.  It's just not very evenly distributed" -- William Gibson

Me: http://clothbot.com/wiki/




Reply | Threaded
Open this post in threaded view
|

Re: bugs: export/import hollow stl models bug

clothbot
In reply to this post by kintel
Hey Marius,

Section 28.2 of the CGAL User and Reference Manual (v3.6.1) mentions CGAL::convex_decomposition_3(Nef_polyhedron_3& N) which looks like it could be of use at export and/or import STL time to preserve inner hollow space geometry.

I'm trying it out at the export_stl stage first to see if it splits geometry into sub-volumes like I think it might.  I have it compiling (but not working yet) with the following two changes:

--snip--
Index: cgal.h
===================================================================
--- cgal.h (revision 566)
+++ cgal.h (working copy)
@@ -10,6 +10,7 @@
 #include <CGAL/Polyhedron_3.h>
 #include <CGAL/Nef_polyhedron_3.h>
 #include <CGAL/IO/Polyhedron_iostream.h>
+#include <CGAL/convex_decomposition_3.h>
 
 typedef CGAL::Extended_cartesian<CGAL::Gmpq> CGAL_Kernel2;
 typedef CGAL::Nef_polyhedron_2<CGAL_Kernel2> CGAL_Nef_polyhedron2;
Index: export.cc
===================================================================
--- export.cc (revision 566)
+++ export.cc (working copy)
@@ -75,6 +75,7 @@
  */
 void export_stl(CGAL_Nef_polyhedron *root_N, QString filename, QProgressDialog *pd)
 {
+ CGAL::convex_decomposition_3(root_N->p3);
  CGAL_Polyhedron P;
  root_N->p3.convert_to_Polyhedron(P);
 
--end-snip--

More needs to be tweaked to get the export code working, most likely using Volume_const_iterator along similar lines to
CGAL-3.6/examples/Convex_decomposition_3.

I'll try prodding at the code more this evening, but all the better if you figure it out sooner!

Andrew.


On 2010-07-02, at 4:32 PM, Marius Kintel wrote:

> Andrew,
>
> After looking at this, I think I know why this happens, although not how to fix it:
>
> OpenSCAD imports an STL file into a single CGAL::Polyhedron_3 object.
> This object stores the STL file as a single 2-manifold surface. Volumes with holes are,
> if I understand the docs correctly, not supported. What exactly happens with not supported
> surfaces is unknown and perhaps arbitrary, which you have discovered.
>
> To fix this, I think we need to do smth. like this:
> o Detect separate sub-volumes in a loaded model.
> o If any of the sub-volumes are defined "inside-out" or lies wholly within another positive volume, we can convert this to a   CSG difference.
>
> Clifford: Any insight into this based on your CGAL experience?
>
> ~/= Marius
>
> --
> We are Elektropeople for a better living.
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad

--

"The future is already here.  It's just not very evenly distributed" -- William Gibson

Me: http://clothbot.com/wiki/




Reply | Threaded
Open this post in threaded view
|

Re: bugs: export/import hollow stl models bug

kintel
Administrator
On Jul 6, 2010, at 22:22 PM, Andrew Plumb wrote:
>
> Section 28.2 of the CGAL User and Reference Manual (v3.6.1) mentions CGAL::convex_decomposition_3(Nef_polyhedron_3& N) which looks like it could be of use at export and/or import STL time to preserve inner hollow space geometry.
>

Hi,

This might be a small step in the right direction, but I don't think this will get us where we want to be in the end.

As a showstopper example, think about a 3D model of a hollow U-shaped capped pipe. Neither the outer or the inner (hole) geometry is convex, and such a convex decomposer would split the model into arbitrary convex components.

What we want to do in the end is to check whether any of the subparts are wholly contained within another part. If so, we could perform a normal CSG operation on these and thus succesively build a CGAL-conformant Nef polyhedron.
Since the model is going to be arbitrary decomposed, the whole inner/outer test is going to fail in the end and we're back where we started.

..unless I've missed some key aspect of this decomposition algorithm that is.

I appreciate you trying to figure this out though, so please keep hacking!

~/= Marius

--
We are Elektropeople for a better living