From f570b7fd2558d73f8446681be10bc82fa1c283e6 Mon Sep 17 00:00:00 2001 From: Don Bright Date: Sun, 15 Dec 2013 08:28:36 -0600 Subject: add some error checking diff --git a/src/dxftess-cgal.cc b/src/dxftess-cgal.cc index 85c038f..9c4e6fe 100644 --- a/src/dxftess-cgal.cc +++ b/src/dxftess-cgal.cc @@ -353,7 +353,7 @@ because the algorithm we are using doesn't create any new points, and we can just use a 'map' to associate 3d points with 2d points). The code assumes the input polygons are simple, non-intersecting, without -holes, and without duplicate input points. +holes, without duplicate input points, and with proper orientation. The purpose of this code is originally to fix github issue 349. Our CGAL kernel does not accept polygons for Nef_Polyhedron_3 if each of the @@ -406,26 +406,29 @@ projection_t find_good_projection( PolySet::Polygon pgon ) { // plane. 'quadrance' (distance squared) can tell this w/o using sqrt. CGAL::Plane_3 pl( cgp(v1), cgp(v2), cgp(v3) ); NT3 qxy = pl.a()*pl.a()+pl.b()*pl.b(); - NT3 qyz = pl.b()*pl.b()+pl.c()*pl.c(); - NT3 qxz = pl.c()*pl.c()+pl.a()*pl.a(); + NT3 qyz = pl.b()*pl.b()+pl.c()*pl.c(); + NT3 qxz = pl.c()*pl.c()+pl.a()*pl.a(); NT3 min = std::min(qxy,std::min(qyz,qxz)); if (min==qxy) return XYPLANE; else if (min==qyz) return YZPLANE; return XZPLANE; } -/* triangulate the given polygon using CGAL's Constrained Delaunay -algorithm. project the polygon's points using the given projection -before performing the triangulation. this code assumes input polygon is -simple, no holes, no self-intersections, no duplicate points, and +/* triangulate the given polygon using CGAL's 2d Constrained Delaunay +algorithm. Project the polygon's points into 2d using the given projection +before performing the triangulation. This code assumes input polygon is +simple, no holes, no self-intersections, no duplicate points, and is properly oriented. */ -void triangulate_polygon( const PolySet::Polygon &pgon, std::vector &triangles, projection_t projection ) +bool triangulate_polygon( const PolySet::Polygon &pgon, std::vector &triangles, projection_t projection ) { + bool err = false; + CGAL::Failure_behaviour old_behaviour = CGAL::set_error_behaviour(CGAL::THROW_EXCEPTION); + try { CDT cdt; std::vector vhandles; std::map vertmap; CGAL::Orientation original_orientation; - std::vector orpgon; + std::vector orienpgon; for (size_t i = 0; i < pgon.size(); i++) { Vector3d v3 = pgon.at(i); Vector2d v2 = get_projected_point( v3, projection ); @@ -433,9 +436,9 @@ void triangulate_polygon( const PolySet::Polygon &pgon, std::vector triangles; - projection_t projection = find_good_projection( pgon ); - triangulate_polygon( pgon, triangles, projection ); - for (size_t j=0;j