When importing a DXF file which cannot be tessellated by CGAL (e.g. due to self-intersections or duplicate line segments), OpenSCAD fails with the following error message:
CGAL error in dxf_tesselate(): CGAL ERROR: assertion violation!
We should improve that message to something more helpful, so that people can double-check their dxf files.
The necessary context for such an error would be available from e.g. import.cc:225
is there a minimal example DXF that does this?
what would it take to use the GLU tessellator on these instead of the CGAL tessellator? it can deal with self intersections etc right?
I cannot find a minimal example atm. The reason I added this was that someone (BuZz) on IRC had this problem, but he didn't post his file yet.
The GLU tessellator wasn't stable enough - that's the reason we had to rewrite to using CGAL. The GLU tessellator should be able to deal with all geometries, but something failed (not sure what anymore). Also, GLU is known to be buggy under Windows so I usually compile my own GLU from source to avoid using the buggy one which Microsoft ships (this may have changed since I used it though). If we could get CGAL out of that particular subsystem, it would make me happy.
I've also got the same problem I've a very simple dxf I can share that reproduces the problem.
Yes, it would be helpful if you share the dxf.
Sure thing the dxf can be found at http://pastebin.com/UTYzCf30 - it's just two letters 3B done in http://www.dafont.com/hobbiton-brush-hand.font and then trying to follow the instructions on http://repraprip.blogspot.co.uk/2011/05/inkscape-to-openscad-dxf-tutorial.html
use the CGAL triangulation with intersections enabled. attempt to fix…
… issue #159
thank you richardjm
OK, my question is this.
in dxftess-cgal.cc we have this:
typedef CGAL::Constrained_Delaunay_triangulation_2<K, Tds> CDT
according to http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Triangulation_2_ref/Class_Constrained_triangulation_2.html you can give 'tags' to this instantiation to allow intersections. For example:
typedef CGAL::Constrained_Delaunay_triangulation_2<K, Tds, CGAL::Exact_predicates_tag > CDT;
Now when you recompile OpenSCAD with this new code, and try to import richardjm's example here, you get a large number of warnings like this:
WARNING: Duplicate vertex found during Tessellation. Render may be incorrect.
However, you also get a somewhat working import. It doesn't look exactly like you would expect, but it seems to me that it would allow the user to see where the problem was and fix it.
for example with richardjm's sample we can see that the left-hand letter is perfectly fine, it is only in the right hand letter where some issues occur. perhaps through the use of Inkscape the clever user can thus 'fix' their DXF themselves by looking at the mangled output from CGAL's dxf tessellation.
im submitting a pull request which has this new error message:
WARNING: duplicate vertices and/or intersecting lines found during DXF Tessellation. Render may be incorrect.
you can view visuals of the proposed fix behavior here:
and as for the sample letters posted above by richardjm, by opening up that DXF in Inkscape, and scaling it up by a very large amount, the import magically works.
i am guessing this has something to do with the 'Grid' thing. when the DXF has too many points too close together, the 'Grid' stuff in OpenSCAD combines them together and there you get the duplicates and the bad render.
then i must of course ask the question......... what is the purpose of Grid anyways?
but that wont really solve the issue of degenerate DXF, you can have those no matter what the grid size is., because you can always have self intersecting lines and duplicate vertices even without a grid.
The patch also results in some interesting changes to the test suite... some of these tests that used to produce blank images now are producing 'ordinary' looking images.
and some of them are producing 'messy' renders.
Looks like it's generating some "interesting" behaviour :) Glad you've got it reproduced at least.
First of all: Nice catch!
1) Test suite
This patch actually makes the DXF import significantly more robust and will thus support cases which earlier would fail. When merging into master, we should try updating the tests to reflect this new behavior.
Grid is a naive attempt at removing vertices which are close together but not coincident, both to 'repair' modeling errors and to get rid of small details which make the resulting tesselation really large. It should really be refactored, although we might end up having to refactor both polyset and dxfdata at the same time