Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Improve error message on invalid DXF imports #159

Closed
kintel opened this Issue · 11 comments

3 participants

@kintel
Owner

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!
Expr: false
File: /usr/local/include/CGAL/Constrained_triangulation_2.h

We should improve that message to something more helpful, so that people can double-check their dxf files.

See dxftess-cgal.cc:170
The necessary context for such an error would be available from e.g. import.cc:225

@donbright
Collaborator
  1. is there a minimal example DXF that does this?

  2. what would it take to use the GLU tessellator on these instead of the CGAL tessellator? it can deal with self intersections etc right?

@kintel
Owner
  1. 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.

  2. 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.

@richardjm

I've also got the same problem I've a very simple dxf I can share that reproduces the problem.

@kintel
Owner

Yes, it would be helpful if you share the dxf.

@richardjm

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

@donbright
Collaborator

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.
@donbright donbright referenced this issue
Closed

Issue159 #184

@donbright
Collaborator

you can view visuals of the proposed fix behavior here:

http://cakebaby.wikia.com/wiki/Cakebaby_Wiki/richardjmbug

@donbright
Collaborator

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.

@donbright
Collaborator

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.

http://cakebaby.wikia.com/wiki/OpenSCAD_linux_x86_64_software-rasterizer_scdh_test_report

and some of them are producing 'messy' renders.

@richardjm

Looks like it's generating some "interesting" behaviour :) Glad you've got it reproduced at least.

@kintel
Owner

First of all: Nice catch!

Two things:

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.

2) grid

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

@kintel kintel closed this
@donbright donbright referenced this issue
Merged

Issue159 #255

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.