From 0a2b7ca0d4d7fb1acda9996d69b25ff6b5495856 Mon Sep 17 00:00:00 2001 From: Don Bright Date: Sat, 14 Dec 2013 17:20:35 -0600 Subject: FIXME leaking polyset by altering functions signatures diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index ec01315..26d3e4c 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -668,16 +668,30 @@ CGAL_Nef_polyhedron CGALEvaluator::evaluateCGALMesh(const PolySet &ps) else // not (this->is2d) { CGAL_Nef_polyhedron3 *N = NULL; + bool plane_error = false; CGAL::Failure_behaviour old_behaviour = CGAL::set_error_behaviour(CGAL::THROW_EXCEPTION); try { - // FIXME: Are we leaking memory for the CGAL_Polyhedron object? - CGAL_Polyhedron *P = createPolyhedronFromPolySet(ps); - if (P) { - N = new CGAL_Nef_polyhedron3(*P); + CGAL_Polyhedron P; + createPolyhedronFromPolySet(ps,P); + N = new CGAL_Nef_polyhedron3(P); + } + catch (const CGAL::Assertion_exception &e) { + if (std::string(e.what()).find("Plane_constructor")!=std::string::npos) { + PRINT("PolySet has nonplanar faces. Attempting alternate construction"); + plane_error=true; + } else { + PRINTB("CGAL error in CGAL_Nef_polyhedron3(): %s", e.what()); } } + if (plane_error) try { + PolySet ps2; + CGAL_Polyhedron P; + tessellate_faces( ps, ps2 ); + createPolyhedronFromPolySet(ps2,P); + N = new CGAL_Nef_polyhedron3(P); + } catch (const CGAL::Assertion_exception &e) { - PRINTB("CGAL error in CGAL_Nef_polyhedron3(): %s", e.what()); + PRINTB("Alternate construction failed. CGAL error in CGAL_Nef_polyhedron3(): %s", e.what()); } CGAL::set_error_behaviour(old_behaviour); return CGAL_Nef_polyhedron(N); diff --git a/src/CGAL_Nef_polyhedron.cc b/src/CGAL_Nef_polyhedron.cc index 440f4ed..2d5bba5 100644 --- a/src/CGAL_Nef_polyhedron.cc +++ b/src/CGAL_Nef_polyhedron.cc @@ -97,11 +97,14 @@ PolySet *CGAL_Nef_polyhedron::convertToPolyset() else if (this->dim == 3) { CGAL::Failure_behaviour old_behaviour = CGAL::set_error_behaviour(CGAL::THROW_EXCEPTION); try { + ps = new PolySet(); CGAL_Polyhedron P; this->p3->convert_to_Polyhedron(P); - ps = createPolySetFromPolyhedron(P); + bool err = createPolySetFromPolyhedron(P, ps); + if (err) delete ps; } catch (const CGAL::Precondition_exception &e) { + delete ps; PRINTB("CGAL error in CGAL_Nef_polyhedron::convertToPolyset(): %s", e.what()); } CGAL::set_error_behaviour(old_behaviour); diff --git a/src/cgalutils.h b/src/cgalutils.h index d25fd4c..50b819a 100644 --- a/src/cgalutils.h +++ b/src/cgalutils.h @@ -2,8 +2,8 @@ #define CGALUTILS_H_ #include -class PolySet *createPolySetFromPolyhedron(const CGAL_Polyhedron &p); -CGAL_Polyhedron *createPolyhedronFromPolySet(const class PolySet &ps); +bool createPolySetFromPolyhedron(const CGAL_Polyhedron &p, class PolySet &ps); +bool createPolyhedronFromPolySet(const class PolySet &ps, class CGAL_Polyhedron &p); CGAL_Iso_cuboid_3 bounding_box( const CGAL_Nef_polyhedron3 &N ); CGAL_Iso_rectangle_2e bounding_box( const CGAL_Nef_polyhedron2 &N ); diff --git a/src/dxftess-cgal.cc b/src/dxftess-cgal.cc index 16eaf9f..a3ebccf 100644 --- a/src/dxftess-cgal.cc +++ b/src/dxftess-cgal.cc @@ -335,3 +335,19 @@ void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, Vector2d scale, bool u dxf.paths[path[2]].is_inner = !up; } } + +void triangulate_polygon( const PolySet::Polygon &pgon, std::vector &triangles ) +{ +} + +/* given a 3d PolySet with 'near planar' faces, triangulate the faces +so CGAL Nef Polyhedron will accept them. */ +void tessellate_3d_faces( PolySet &inps, PolySet &outps ) { + for (size_t i = 0; i < inps.polygons.size(); i++) { + const PolySet::Polygon *pgon = &inps.polygons[i]; + for (size_t j = 0; j < pgon->size(); j++) { + Vector3d v = pgon->at(j); + } + } +} + diff --git a/src/dxftess.h b/src/dxftess.h index f0f27b5..3d96747 100644 --- a/src/dxftess.h +++ b/src/dxftess.h @@ -7,5 +7,6 @@ class DxfData; class PolySet; void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, Vector2d scale, bool up, bool do_triangle_splitting, double h); void dxf_border_to_ps(PolySet *ps, const DxfData &dxf); +void tessellate_3d_faces( PolySet &inps, PolySet &outps ); #endif diff --git a/src/import.cc b/src/import.cc index 3897331..af905fc 100644 --- a/src/import.cc +++ b/src/import.cc @@ -284,7 +284,8 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *) const file >> poly; file.close(); - p = createPolySetFromPolyhedron(poly); + p = new PolySet(); + bool err = createPolySetFromPolyhedron(poly, *p); } #else PRINT("WARNING: OFF import requires CGAL."); diff --git a/src/polyset.h b/src/polyset.h index 6626f79..5c97396 100644 --- a/src/polyset.h +++ b/src/polyset.h @@ -26,7 +26,6 @@ public: void append_vertex(double x, double y, double z = 0.0); void insert_vertex(double x, double y, double z = 0.0); size_t memsize() const; - BoundingBox getBoundingBox() const; #define CSGMODE_DIFFERENCE_FLAG 0x10 -- cgit v0.10.1 From 09d60fd5afd54f1537ff6f5349f6466be8401d01 Mon Sep 17 00:00:00 2001 From: Don Bright Date: Sat, 14 Dec 2013 17:25:40 -0600 Subject: stub of face tessellation function for polyset diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index 26d3e4c..9902f70 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -686,7 +686,7 @@ CGAL_Nef_polyhedron CGALEvaluator::evaluateCGALMesh(const PolySet &ps) if (plane_error) try { PolySet ps2; CGAL_Polyhedron P; - tessellate_faces( ps, ps2 ); + tessellate_3d_faces( ps, ps2 ); createPolyhedronFromPolySet(ps2,P); N = new CGAL_Nef_polyhedron3(P); } diff --git a/src/cgalutils.h b/src/cgalutils.h index 50b819a..0e7fbb5 100644 --- a/src/cgalutils.h +++ b/src/cgalutils.h @@ -3,7 +3,7 @@ #include bool createPolySetFromPolyhedron(const CGAL_Polyhedron &p, class PolySet &ps); -bool createPolyhedronFromPolySet(const class PolySet &ps, class CGAL_Polyhedron &p); +bool createPolyhedronFromPolySet(const class PolySet &ps, CGAL_Polyhedron &p); CGAL_Iso_cuboid_3 bounding_box( const CGAL_Nef_polyhedron3 &N ); CGAL_Iso_rectangle_2e bounding_box( const CGAL_Nef_polyhedron2 &N ); diff --git a/src/dxftess-cgal.cc b/src/dxftess-cgal.cc index a3ebccf..d6f592f 100644 --- a/src/dxftess-cgal.cc +++ b/src/dxftess-cgal.cc @@ -338,11 +338,12 @@ void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, Vector2d scale, bool u void triangulate_polygon( const PolySet::Polygon &pgon, std::vector &triangles ) { + } /* given a 3d PolySet with 'near planar' faces, triangulate the faces so CGAL Nef Polyhedron will accept them. */ -void tessellate_3d_faces( PolySet &inps, PolySet &outps ) { +void tessellate_3d_faces( const PolySet &inps, PolySet &outps ) { for (size_t i = 0; i < inps.polygons.size(); i++) { const PolySet::Polygon *pgon = &inps.polygons[i]; for (size_t j = 0; j < pgon->size(); j++) { diff --git a/src/dxftess.h b/src/dxftess.h index 3d96747..d596f0b 100644 --- a/src/dxftess.h +++ b/src/dxftess.h @@ -7,6 +7,6 @@ class DxfData; class PolySet; void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, Vector2d scale, bool up, bool do_triangle_splitting, double h); void dxf_border_to_ps(PolySet *ps, const DxfData &dxf); -void tessellate_3d_faces( PolySet &inps, PolySet &outps ); +void tessellate_3d_faces( const PolySet &inps, PolySet &outps ); #endif diff --git a/src/import.cc b/src/import.cc index af905fc..f62200b 100644 --- a/src/import.cc +++ b/src/import.cc @@ -285,7 +285,7 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *) const file.close(); p = new PolySet(); - bool err = createPolySetFromPolyhedron(poly, *p); + createPolySetFromPolyhedron(poly, *p); } #else PRINT("WARNING: OFF import requires CGAL."); -- cgit v0.10.1 From 804ec858d9bd832629a2b00ebe689f2d11e4cbe5 Mon Sep 17 00:00:00 2001 From: Don Bright Date: Sat, 14 Dec 2013 21:12:01 -0600 Subject: triangulation of near-planar PolySet faces diff --git a/src/CGAL_Nef_polyhedron.cc b/src/CGAL_Nef_polyhedron.cc index 2d5bba5..8b54eba 100644 --- a/src/CGAL_Nef_polyhedron.cc +++ b/src/CGAL_Nef_polyhedron.cc @@ -100,7 +100,7 @@ PolySet *CGAL_Nef_polyhedron::convertToPolyset() ps = new PolySet(); CGAL_Polyhedron P; this->p3->convert_to_Polyhedron(P); - bool err = createPolySetFromPolyhedron(P, ps); + bool err = createPolySetFromPolyhedron(P, *ps); if (err) delete ps; } catch (const CGAL::Precondition_exception &e) { diff --git a/src/cgalutils.cc b/src/cgalutils.cc index bb46f1c..12e743d 100644 --- a/src/cgalutils.cc +++ b/src/cgalutils.cc @@ -8,10 +8,9 @@ #include -PolySet *createPolySetFromPolyhedron(const CGAL_Polyhedron &p) +bool createPolySetFromPolyhedron(const CGAL_Polyhedron &p, PolySet &ps) { - PolySet *ps = new PolySet(); - + bool err = false; typedef CGAL_Polyhedron::Vertex Vertex; typedef CGAL_Polyhedron::Vertex_const_iterator VCI; typedef CGAL_Polyhedron::Facet_const_iterator FCI; @@ -35,13 +34,13 @@ PolySet *createPolySetFromPolyhedron(const CGAL_Polyhedron &p) double x3 = CGAL::to_double(v3.point().x()); double y3 = CGAL::to_double(v3.point().y()); double z3 = CGAL::to_double(v3.point().z()); - ps->append_poly(); - ps->append_vertex(x1, y1, z1); - ps->append_vertex(x2, y2, z2); - ps->append_vertex(x3, y3, z3); + ps.append_poly(); + ps.append_vertex(x1, y1, z1); + ps.append_vertex(x2, y2, z2); + ps.append_vertex(x3, y3, z3); } while (hc != hc_end); } - return ps; + return err; } #undef GEN_SURFACE_DEBUG @@ -127,22 +126,20 @@ public: } }; -CGAL_Polyhedron *createPolyhedronFromPolySet(const PolySet &ps) +bool createPolyhedronFromPolySet(const PolySet &ps, CGAL_Polyhedron &p) { - CGAL_Polyhedron *P = NULL; + bool err = false; CGAL::Failure_behaviour old_behaviour = CGAL::set_error_behaviour(CGAL::THROW_EXCEPTION); try { - P = new CGAL_Polyhedron; CGAL_Build_PolySet builder(ps); - P->delegate(builder); + p.delegate(builder); } catch (const CGAL::Assertion_exception &e) { PRINTB("CGAL error in CGAL_Build_PolySet: %s", e.what()); - delete P; - P = NULL; + err = true; } CGAL::set_error_behaviour(old_behaviour); - return P; + return err; } CGAL_Iso_cuboid_3 bounding_box( const CGAL_Nef_polyhedron3 &N ) diff --git a/src/cgalutils.h b/src/cgalutils.h index 0e7fbb5..8f7e4dd 100644 --- a/src/cgalutils.h +++ b/src/cgalutils.h @@ -2,8 +2,9 @@ #define CGALUTILS_H_ #include -bool createPolySetFromPolyhedron(const CGAL_Polyhedron &p, class PolySet &ps); -bool createPolyhedronFromPolySet(const class PolySet &ps, CGAL_Polyhedron &p); +#include "polyset.h" +bool createPolySetFromPolyhedron(const CGAL_Polyhedron &p, PolySet &ps); +bool createPolyhedronFromPolySet(const PolySet &ps, CGAL_Polyhedron &p); CGAL_Iso_cuboid_3 bounding_box( const CGAL_Nef_polyhedron3 &N ); CGAL_Iso_rectangle_2e bounding_box( const CGAL_Nef_polyhedron2 &N ); diff --git a/src/dxftess-cgal.cc b/src/dxftess-cgal.cc index d6f592f..6899598 100644 --- a/src/dxftess-cgal.cc +++ b/src/dxftess-cgal.cc @@ -336,19 +336,122 @@ void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, Vector2d scale, bool u } } -void triangulate_polygon( const PolySet::Polygon &pgon, std::vector &triangles ) -{ +typedef enum { XYPLANE, YZPLANE, XZPLANE, NONE } projection_t; + +Vector2d get_projected_point( Vector3d v, projection_t projection ) { + Vector2d v2(0,0); + if (projection==XYPLANE) { v2.x() = v.x(); v2.y() = v.y(); } + else if (projection==XZPLANE) { v2.x() = v.x(); v2.y() = v.z(); } + else if (projection==YZPLANE) { v2.x() = v.y(); v2.y() = v.z(); } + return v2; +} +CGAL_Point_3 cgp( Vector3d v ) { return CGAL_Point_3( v.x(), v.y(), v.z() ); } +/* near-planar polygons in 3d can be projected into 2d, but you have to +be careful. if you project, say, 0,0,0 0,1,0 0,1,1 0,0,1 onto the XY plane +you will not get a polygon, you will get a skinny line thing. */ +projection_t find_good_projection( PolySet::Polygon pgon ) { + // step 1 - find 3 non-collinear points in the input + if (pgon.size()<3) return NONE; + Vector3d v1,v2,v3; + v1 = v2 = v3 = pgon[0]; + for (size_t i=0;i 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 min = std::min(qxy,std::min(qyz,qxz)); + if (min==qxy) return XYPLANE; + else if (min==qyz) return YZPLANE; + return XZPLANE; } -/* given a 3d PolySet with 'near planar' faces, triangulate the faces -so CGAL Nef Polyhedron will accept them. */ +void triangulate_polygon( const PolySet::Polygon &pgon, std::vector &triangles, projection_t projection ) +{ + CDT cdt; + std::vector vhandles; + std::map vertmap; + CGAL::Orientation original_orientation; + std::vector orpgon; + for (size_t i = 0; i < pgon.size(); i++) { + Vector3d v3 = pgon.at(i); + Vector2d v2 = get_projected_point( v3, projection ); + CDTPoint cdtpoint = CDTPoint(v2.x(),v2.y()); + vertmap[ cdtpoint ] = v3; + Vertex_handle vh = cdt.insert( cdtpoint ); + vhandles.push_back(vh); + orpgon.push_back( cdtpoint ); + } + original_orientation = CGAL::orientation_2( orpgon.begin(),orpgon.end() ); + for (size_t i = 0; i < vhandles.size(); i++ ) { + int vindex1 = (i+0); + int vindex2 = (i+1)%vhandles.size(); + cdt.insert_constraint( vhandles[vindex1], vhandles[vindex2] ); + } + std::list list_of_seeds; + CGAL::refine_Delaunay_mesh_2_without_edge_refinement(cdt, + list_of_seeds.begin(), list_of_seeds.end(), DummyCriteria()); + + CDT::Finite_faces_iterator fit; + for( fit=cdt.finite_faces_begin(); fit!=cdt.finite_faces_end(); fit++ ) + { + if(fit->is_in_domain()) { + CDTPoint p1 = cdt.triangle( fit )[0]; + CDTPoint p2 = cdt.triangle( fit )[1]; + CDTPoint p3 = cdt.triangle( fit )[2]; + Vector3d v1 = vertmap[p1]; + Vector3d v2 = vertmap[p2]; + Vector3d v3 = vertmap[p3]; + PolySet::Polygon pgon; + if (CGAL::orientation(p1,p2,p3)==original_orientation) { + pgon.push_back(v1); + pgon.push_back(v2); + pgon.push_back(v3); + } else { + pgon.push_back(v3); + pgon.push_back(v2); + pgon.push_back(v1); + } + triangles.push_back( pgon ); + } + } +} + +/* given a 3d PolySet with 'near planar' faces, triangulate the faces. +See Issue 340... this is so CGAL Nef Polyhedron will accept them. +This code assumes the input polyset has simple polygon faces with no holes. */ void tessellate_3d_faces( const PolySet &inps, PolySet &outps ) { + PRINTB("tess 3d %i",inps.polygons.size()); + PRINTB("%s < input ps",inps.dump()); for (size_t i = 0; i < inps.polygons.size(); i++) { - const PolySet::Polygon *pgon = &inps.polygons[i]; - for (size_t j = 0; j < pgon->size(); j++) { - Vector3d v = pgon->at(j); - } + const PolySet::Polygon pgon = inps.polygons[i]; + if (pgon.size()<3) continue; + std::vector triangles; + projection_t projection = find_good_projection( pgon ); + triangulate_polygon( pgon, triangles, projection ); + for (size_t j=0;j Date: Sat, 14 Dec 2013 21:15:29 -0600 Subject: in polyhedron() replace "triangles" w "faces", but allow backwards compatability by accepting 'triangles' and putting them into 'faces' variable diff --git a/src/primitives.cc b/src/primitives.cc index a587d43..0d557a2 100644 --- a/src/primitives.cc +++ b/src/primitives.cc @@ -103,7 +103,7 @@ public: double fn, fs, fa; primitive_type_e type; int convexity; - Value points, paths, triangles; + Value points, paths, faces; virtual PolySet *evaluate_polyset(class PolySetEvaluator *) const; }; @@ -156,7 +156,7 @@ AbstractNode *PrimitiveModule::instantiate(const Context *ctx, const ModuleInsta args += Assignment("h", NULL), Assignment("r1", NULL), Assignment("r2", NULL), Assignment("center", NULL); break; case POLYHEDRON: - args += Assignment("points", NULL), Assignment("triangles", NULL), Assignment("convexity", NULL); + args += Assignment("points", NULL), Assignment("triangles", NULL), Assignment("convexity", NULL), Assignment("faces", NULL); break; case SQUARE: args += Assignment("size", NULL), Assignment("center", NULL); @@ -235,7 +235,8 @@ AbstractNode *PrimitiveModule::instantiate(const Context *ctx, const ModuleInsta if (type == POLYHEDRON) { node->points = c.lookup_variable("points"); - node->triangles = c.lookup_variable("triangles"); + node->faces = c.lookup_variable("triangles"); + node->faces = c.lookup_variable("faces"); } if (type == SQUARE) { @@ -480,11 +481,11 @@ sphere_next_r2: if (this->type == POLYHEDRON) { p->convexity = this->convexity; - for (size_t i=0; itriangles.toVector().size(); i++) + for (size_t i=0; ifaces.toVector().size(); i++) { p->append_poly(); - for (size_t j=0; jtriangles.toVector()[i].toVector().size(); j++) { - size_t pt = this->triangles.toVector()[i].toVector()[j].toDouble(); + for (size_t j=0; jfaces.toVector()[i].toVector().size(); j++) { + size_t pt = this->faces.toVector()[i].toVector()[j].toDouble(); if (pt < this->points.toVector().size()) { double px, py, pz; if (this->points.toVector()[pt].getVec3(px, py, pz)) @@ -610,7 +611,7 @@ std::string PrimitiveNode::toString() const break; case POLYHEDRON: stream << "(points = " << this->points - << ", triangles = " << this->triangles + << ", faces = " << this->faces << ", convexity = " << this->convexity << ")"; break; case SQUARE: -- cgit v0.10.1 From f12237a9c4b39349da673456e7e309562ed0f75a Mon Sep 17 00:00:00 2001 From: Don Bright Date: Sat, 14 Dec 2013 21:58:22 -0600 Subject: add tests for non-planar bug. add docs to .cc code diff --git a/src/dxftess-cgal.cc b/src/dxftess-cgal.cc index 6899598..ebdcf58 100644 --- a/src/dxftess-cgal.cc +++ b/src/dxftess-cgal.cc @@ -336,8 +336,28 @@ void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, Vector2d scale, bool u } } + +/* Tessellation of 3d PolySet with near-planar polygons. + +We do this by projecting each polygon of the Polyset onto a 2-d plane, +then running a tessellation algorithm on the projected polygon. Then we +project the generated 2d triangles back up into 3d space. + +(in reality as of writing, we dont need to do a back-projection from 2d->3d +because the algorithm we are using doesn't create any new points, and we can +just use a 'map' to associate 3d points to 2d points). + +The code assumes the input polygons are simple, non-intersecting, without +holes, and without duplicate input points. + +For more info, please see github #issue349. This code enables +polyhedron() to use near-planar polygons rather than perfectly planar +polygons. */ + typedef enum { XYPLANE, YZPLANE, XZPLANE, NONE } projection_t; +// this is how we make 3d points appear as though they were 2d points to +//the tessellation algorithm. Vector2d get_projected_point( Vector3d v, projection_t projection ) { Vector2d v2(0,0); if (projection==XYPLANE) { v2.x() = v.x(); v2.y() = v.y(); } @@ -347,9 +367,13 @@ Vector2d get_projected_point( Vector3d v, projection_t projection ) { } CGAL_Point_3 cgp( Vector3d v ) { return CGAL_Point_3( v.x(), v.y(), v.z() ); } -/* near-planar polygons in 3d can be projected into 2d, but you have to -be careful. if you project, say, 0,0,0 0,1,0 0,1,1 0,0,1 onto the XY plane -you will not get a polygon, you will get a skinny line thing. */ + +/* Find a 'good' 2d projection for a given 3d polygon. the XY, YZ, or XZ +plane. This is needed because near-planar polygons in 3d can have 'bad' +projections into 2d. For example if the square 0,0,0 0,1,0 0,1,1 0,0,1 +is projected onto the XY plane you will not get a polygon, you wil get +a skinny line thing. It's better to project that square onto the yz +plane.*/ projection_t find_good_projection( PolySet::Polygon pgon ) { // step 1 - find 3 non-collinear points in the input if (pgon.size()<3) return NONE; @@ -368,8 +392,8 @@ projection_t find_good_projection( PolySet::Polygon pgon ) { // step 2 - find which direction is best for projection. planes use // the equation ax+by+cz+d = 0. a,b, and c determine the direction the // plane is in. we want to find which projection of the 'normal vector' - // would make the smallest shadow if projected onto the given plane. - // 'quadrance' (distance squared) can tell this w/o using sqrt. + // would make the smallest shadow if projected onto the XY, YZ, or XZ + // 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(); @@ -380,6 +404,11 @@ projection_t find_good_projection( PolySet::Polygon pgon ) { 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 +properly oriented. */ void triangulate_polygon( const PolySet::Polygon &pgon, std::vector &triangles, projection_t projection ) { CDT cdt; @@ -431,9 +460,11 @@ void triangulate_polygon( const PolySet::Polygon &pgon, std::vector Date: Sat, 14 Dec 2013 22:15:57 -0600 Subject: fix bug in polyhedron() primitive keyword 'faces' vs 'triangles' diff --git a/src/dxftess-cgal.cc b/src/dxftess-cgal.cc index ebdcf58..e5c62c4 100644 --- a/src/dxftess-cgal.cc +++ b/src/dxftess-cgal.cc @@ -466,8 +466,6 @@ using CGAL's Constrained Delaunay algorithm. This code assumes the input polyset has simple polygon faces with no holes, no self intersections, and no duplicate points. */ void tessellate_3d_faces( const PolySet &inps, PolySet &outps ) { - PRINTB("tess 3d %i",inps.polygons.size()); - PRINTB("%s < input ps",inps.dump()); for (size_t i = 0; i < inps.polygons.size(); i++) { const PolySet::Polygon pgon = inps.polygons[i]; if (pgon.size()<3) continue; @@ -482,9 +480,7 @@ void tessellate_3d_faces( const PolySet &inps, PolySet &outps ) { outps.append_vertex(t[2].x(),t[2].y(),t[2].z()); } } - PRINTB("tess 3d done %i",outps.polygons.size()); - PRINTB("%s < output ps",outps.dump()); } -// End of the Tessellation of PolySet polygons +// End of PolySet face tessellation code diff --git a/src/primitives.cc b/src/primitives.cc index 0d557a2..a76637d 100644 --- a/src/primitives.cc +++ b/src/primitives.cc @@ -235,8 +235,11 @@ AbstractNode *PrimitiveModule::instantiate(const Context *ctx, const ModuleInsta if (type == POLYHEDRON) { node->points = c.lookup_variable("points"); - node->faces = c.lookup_variable("triangles"); node->faces = c.lookup_variable("faces"); + if (node->faces.type() == Value::UNDEFINED) { + // backwards compatable + node->faces = c.lookup_variable("triangles"); + } } if (type == SQUARE) { -- cgit v0.10.1 From 6d0efd62d996e5fbf2b61d54821f8c4c5142ace1 Mon Sep 17 00:00:00 2001 From: Don Bright Date: Sun, 15 Dec 2013 07:47:01 -0600 Subject: improve CGAL nonplanar face error detection. also change dumptests to 'faces' keyword for 'polyhedrnon(). diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index 9902f70..854e9cd 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -677,8 +677,10 @@ CGAL_Nef_polyhedron CGALEvaluator::evaluateCGALMesh(const PolySet &ps) } catch (const CGAL::Assertion_exception &e) { if (std::string(e.what()).find("Plane_constructor")!=std::string::npos) { - PRINT("PolySet has nonplanar faces. Attempting alternate construction"); - plane_error=true; + if (std::string(e.what()).find("has_on")!=std::string::npos) { + PRINT("PolySet has nonplanar faces. Attempting alternate construction"); + plane_error=true; + } } else { PRINTB("CGAL error in CGAL_Nef_polyhedron3(): %s", e.what()); } diff --git a/tests/regression/dumptest/allmodules-expected.csg b/tests/regression/dumptest/allmodules-expected.csg index 42bf4fa..00311d3 100644 --- a/tests/regression/dumptest/allmodules-expected.csg +++ b/tests/regression/dumptest/allmodules-expected.csg @@ -26,7 +26,7 @@ group() { cube(size = [1, 1, 1], center = false); sphere($fn = 0, $fa = 12, $fs = 2, r = 1); cylinder($fn = 0, $fa = 12, $fs = 2, h = 1, r1 = 1, r2 = 1, center = false); - polyhedron(points = undef, triangles = undef, convexity = 1); + polyhedron(points = undef, faces = undef, convexity = 1); square(size = [1, 1], center = false); circle($fn = 0, $fa = 12, $fs = 2, r = 1); polygon(points = undef, paths = undef, convexity = 1); diff --git a/tests/regression/dumptest/example011-expected.csg b/tests/regression/dumptest/example011-expected.csg index 653a6cf..1cd617f 100644 --- a/tests/regression/dumptest/example011-expected.csg +++ b/tests/regression/dumptest/example011-expected.csg @@ -1,3 +1,3 @@ group() { - polyhedron(points = [[10, 0, 0], [0, 10, 0], [-10, 0, 0], [0, -10, 0], [0, 0, 10]], triangles = [[0, 1, 2, 3], [4, 1, 0], [4, 2, 1], [4, 3, 2], [4, 0, 3]], convexity = 1); + polyhedron(points = [[10, 0, 0], [0, 10, 0], [-10, 0, 0], [0, -10, 0], [0, 0, 10]], faces = [[0, 1, 2, 3], [4, 1, 0], [4, 2, 1], [4, 3, 2], [4, 0, 3]], convexity = 1); } diff --git a/tests/regression/dumptest/polyhedron-tests-expected.csg b/tests/regression/dumptest/polyhedron-tests-expected.csg index f59baa2..1bb36d9 100644 --- a/tests/regression/dumptest/polyhedron-tests-expected.csg +++ b/tests/regression/dumptest/polyhedron-tests-expected.csg @@ -1,22 +1,22 @@ group() { group() { - polyhedron(points = [[1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, -1, 0], [0, 0, 1], [0, 0, -1]], triangles = [[0, 4, 2], [0, 2, 5], [0, 3, 4], [0, 5, 3], [1, 2, 4], [1, 5, 2], [1, 4, 3], [1, 3, 5]], convexity = 1); + polyhedron(points = [[1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, -1, 0], [0, 0, 1], [0, 0, -1]], faces = [[0, 4, 2], [0, 2, 5], [0, 3, 4], [0, 5, 3], [1, 2, 4], [1, 5, 2], [1, 4, 3], [1, 3, 5]], convexity = 1); multmatrix([[1, 0, 0, 2], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { - polyhedron(points = [[1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, -1, 0], [0, 0, 1], [0, 0, -1]], triangles = [[0, 4, 2], [0, 2, 5], [0, 3, 4], [0, 5, 3], [1, 2, 4], [1, 5, 2], [1, 3, 4], [1, 3, 5]], convexity = 1); + polyhedron(points = [[1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, -1, 0], [0, 0, 1], [0, 0, -1]], faces = [[0, 4, 2], [0, 2, 5], [0, 3, 4], [0, 5, 3], [1, 2, 4], [1, 5, 2], [1, 3, 4], [1, 3, 5]], convexity = 1); } multmatrix([[1, 0, 0, 4], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { - polyhedron(points = [[1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, -1, 0], [0, 0, 1], [0, 0, -1]], triangles = [[0, 2, 4], [0, 5, 2], [0, 4, 3], [0, 3, 5], [1, 4, 2], [1, 2, 5], [1, 3, 4], [1, 5, 3]], convexity = 1); + polyhedron(points = [[1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, -1, 0], [0, 0, 1], [0, 0, -1]], faces = [[0, 2, 4], [0, 5, 2], [0, 4, 3], [0, 3, 5], [1, 4, 2], [1, 2, 5], [1, 3, 4], [1, 5, 3]], convexity = 1); } } multmatrix([[1, 0, 0, 0], [0, 1, 0, 2], [0, 0, 1, 0], [0, 0, 0, 1]]) { difference() { group() { - polyhedron(points = [[1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, -1, 0], [0, 0, 1], [0, 0, -1]], triangles = [[0, 4, 2], [0, 2, 5], [0, 3, 4], [0, 5, 3], [1, 2, 4], [1, 5, 2], [1, 4, 3], [1, 3, 5]], convexity = 1); + polyhedron(points = [[1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, -1, 0], [0, 0, 1], [0, 0, -1]], faces = [[0, 4, 2], [0, 2, 5], [0, 3, 4], [0, 5, 3], [1, 2, 4], [1, 5, 2], [1, 4, 3], [1, 3, 5]], convexity = 1); multmatrix([[1, 0, 0, 2], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { - polyhedron(points = [[1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, -1, 0], [0, 0, 1], [0, 0, -1]], triangles = [[0, 4, 2], [0, 2, 5], [0, 3, 4], [0, 5, 3], [1, 2, 4], [1, 5, 2], [1, 3, 4], [1, 3, 5]], convexity = 1); + polyhedron(points = [[1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, -1, 0], [0, 0, 1], [0, 0, -1]], faces = [[0, 4, 2], [0, 2, 5], [0, 3, 4], [0, 5, 3], [1, 2, 4], [1, 5, 2], [1, 3, 4], [1, 3, 5]], convexity = 1); } multmatrix([[1, 0, 0, 4], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { - polyhedron(points = [[1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, -1, 0], [0, 0, 1], [0, 0, -1]], triangles = [[0, 2, 4], [0, 5, 2], [0, 4, 3], [0, 3, 5], [1, 4, 2], [1, 2, 5], [1, 3, 4], [1, 5, 3]], convexity = 1); + polyhedron(points = [[1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, -1, 0], [0, 0, 1], [0, 0, -1]], faces = [[0, 2, 4], [0, 5, 2], [0, 4, 3], [0, 3, 5], [1, 4, 2], [1, 2, 5], [1, 3, 4], [1, 5, 3]], convexity = 1); } } multmatrix([[1, 0, 0, 2], [0, 1, 0, 0], [0, 0, 1, 2], [0, 0, 0, 1]]) { -- cgit v0.10.1 From 3296ae4d37c532bec883c83f541da2300d911da2 Mon Sep 17 00:00:00 2001 From: Don Bright Date: Sun, 15 Dec 2013 07:59:53 -0600 Subject: documenation update diff --git a/src/dxftess-cgal.cc b/src/dxftess-cgal.cc index e5c62c4..13c27e5 100644 --- a/src/dxftess-cgal.cc +++ b/src/dxftess-cgal.cc @@ -341,7 +341,8 @@ void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, Vector2d scale, bool u We do this by projecting each polygon of the Polyset onto a 2-d plane, then running a tessellation algorithm on the projected polygon. Then we -project the generated 2d triangles back up into 3d space. +project each of the newly generated 2d 'tiles' (the polygons used for +tessellation, typically triangles) back up into 3d space. (in reality as of writing, we dont need to do a back-projection from 2d->3d because the algorithm we are using doesn't create any new points, and we can -- cgit v0.10.1 From 218760d2f50aa0ee2770b9db75ccf86dc6e361b2 Mon Sep 17 00:00:00 2001 From: Don Bright Date: Sun, 15 Dec 2013 08:02:42 -0600 Subject: restore error checking when creating polyhedron from polyset diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index 854e9cd..3a05b2b 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -672,8 +672,8 @@ CGAL_Nef_polyhedron CGALEvaluator::evaluateCGALMesh(const PolySet &ps) CGAL::Failure_behaviour old_behaviour = CGAL::set_error_behaviour(CGAL::THROW_EXCEPTION); try { CGAL_Polyhedron P; - createPolyhedronFromPolySet(ps,P); - N = new CGAL_Nef_polyhedron3(P); + bool err = createPolyhedronFromPolySet(ps,P); + if (!err) N = new CGAL_Nef_polyhedron3(P); } catch (const CGAL::Assertion_exception &e) { if (std::string(e.what()).find("Plane_constructor")!=std::string::npos) { @@ -689,8 +689,8 @@ CGAL_Nef_polyhedron CGALEvaluator::evaluateCGALMesh(const PolySet &ps) PolySet ps2; CGAL_Polyhedron P; tessellate_3d_faces( ps, ps2 ); - createPolyhedronFromPolySet(ps2,P); - N = new CGAL_Nef_polyhedron3(P); + bool err = createPolyhedronFromPolySet(ps2,P); + if (!err) N = new CGAL_Nef_polyhedron3(P); } catch (const CGAL::Assertion_exception &e) { PRINTB("Alternate construction failed. CGAL error in CGAL_Nef_polyhedron3(): %s", e.what()); -- cgit v0.10.1 From 0bd8531b25410bcb36061c5af7658bce14da9022 Mon Sep 17 00:00:00 2001 From: Don Bright Date: Sun, 15 Dec 2013 08:06:45 -0600 Subject: delete 'new polyset' on failure of creation diff --git a/src/import.cc b/src/import.cc index f62200b..3c2cce1 100644 --- a/src/import.cc +++ b/src/import.cc @@ -285,7 +285,8 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *) const file.close(); p = new PolySet(); - createPolySetFromPolyhedron(poly, *p); + bool err = createPolySetFromPolyhedron(poly, *p); + if (err) delete p; } #else PRINT("WARNING: OFF import requires CGAL."); -- cgit v0.10.1 From 851ce360b42e8f3efdf65227ef6dbc637563b222 Mon Sep 17 00:00:00 2001 From: Don Bright Date: Sun, 15 Dec 2013 08:17:14 -0600 Subject: documentation work diff --git a/src/dxftess-cgal.cc b/src/dxftess-cgal.cc index 13c27e5..85c038f 100644 --- a/src/dxftess-cgal.cc +++ b/src/dxftess-cgal.cc @@ -337,23 +337,32 @@ void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, Vector2d scale, bool u } -/* Tessellation of 3d PolySet with near-planar polygons. +/* Tessellation of 3d PolySet faces -We do this by projecting each polygon of the Polyset onto a 2-d plane, -then running a tessellation algorithm on the projected polygon. Then we -project each of the newly generated 2d 'tiles' (the polygons used for -tessellation, typically triangles) back up into 3d space. +This code is for tessellating the faces of a 3d PolySet, assuming that +the faces are near-planar polygons. + +We do the tessellation by projecting each polygon of the Polyset onto a +2-d plane, then running a 2d tessellation algorithm on the projected 2d +polygon. Then we project each of the newly generated 2d 'tiles' (the +polygons used for tessellation, typically triangles) back up into 3d +space. (in reality as of writing, we dont need to do a back-projection from 2d->3d because the algorithm we are using doesn't create any new points, and we can -just use a 'map' to associate 3d points to 2d points). +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. -For more info, please see github #issue349. This code enables -polyhedron() to use near-planar polygons rather than perfectly planar -polygons. */ +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 +points is not exactly coplanar. "Near-planar" or "Almost planar" polygons +often occur due to rounding issues on, for example, polyhedron() input. +By tessellating the 3d polygon into individual smaller tiles that +are perfectly coplanar (triangles, for example), we can get CGAL to accept +the polyhedron() input. +*/ typedef enum { XYPLANE, YZPLANE, XZPLANE, NONE } projection_t; -- cgit v0.10.1 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 Date: Sun, 15 Dec 2013 08:33:18 -0600 Subject: tab spaces diff --git a/src/dxftess-cgal.cc b/src/dxftess-cgal.cc index 9c4e6fe..a2d3cb3 100644 --- a/src/dxftess-cgal.cc +++ b/src/dxftess-cgal.cc @@ -410,11 +410,11 @@ projection_t find_good_projection( PolySet::Polygon pgon ) { 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; + else if (min==qyz) return YZPLANE; + return XZPLANE; } -/* triangulate the given polygon using CGAL's 2d Constrained Delaunay +/* triangulate the given 3d 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 @@ -449,9 +449,9 @@ bool triangulate_polygon( const PolySet::Polygon &pgon, std::vector()); CDT::Finite_faces_iterator fit; - for( fit=cdt.finite_faces_begin(); fit!=cdt.finite_faces_end(); fit++ ) - { - if(fit->is_in_domain()) { + for( fit=cdt.finite_faces_begin(); fit!=cdt.finite_faces_end(); fit++ ) + { + if(fit->is_in_domain()) { CDTPoint p1 = cdt.triangle( fit )[0]; CDTPoint p2 = cdt.triangle( fit )[1]; CDTPoint p3 = cdt.triangle( fit )[2]; @@ -469,9 +469,9 @@ bool triangulate_polygon( const PolySet::Polygon &pgon, std::vector Date: Sun, 15 Dec 2013 09:00:43 -0600 Subject: minor tweak for clarity diff --git a/src/dxftess-cgal.cc b/src/dxftess-cgal.cc index a2d3cb3..14f1204 100644 --- a/src/dxftess-cgal.cc +++ b/src/dxftess-cgal.cc @@ -418,7 +418,7 @@ projection_t find_good_projection( PolySet::Polygon pgon ) { 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. */ +properly oriented. output is a sequence of 3d triangles. */ bool triangulate_polygon( const PolySet::Polygon &pgon, std::vector &triangles, projection_t projection ) { bool err = false; @@ -491,12 +491,12 @@ void tessellate_3d_faces( const PolySet &inps, PolySet &outps ) { PRINT("WARNING: PolySet has polygon with <3 points"); continue; } - std::vector triangles; projection_t goodproj = find_good_projection( pgon ); if (goodproj==NONE) { PRINT("WARNING: PolySet has degenerate polygon"); continue; } + std::vector triangles; bool err = triangulate_polygon( pgon, triangles, goodproj ); if (!err) for (size_t j=0;j Date: Sun, 15 Dec 2013 16:08:46 -0600 Subject: merging tests diff --git a/tests/regression/cgalpngtest/polyhedron-tests-expected.png b/tests/regression/cgalpngtest/polyhedron-tests-expected.png index 322160d..dd380d3 100644 Binary files a/tests/regression/cgalpngtest/polyhedron-tests-expected.png and b/tests/regression/cgalpngtest/polyhedron-tests-expected.png differ diff --git a/tests/regression/dumptest/polyhedron-tests-expected.csg b/tests/regression/dumptest/polyhedron-tests-expected.csg index dabdf94..a9dc093 100644 --- a/tests/regression/dumptest/polyhedron-tests-expected.csg +++ b/tests/regression/dumptest/polyhedron-tests-expected.csg @@ -8,7 +8,7 @@ group() { polyhedron(points = [[1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, -1, 0], [0, 0, 1], [0, 0, -1]], faces = [[0, 2, 4], [0, 5, 2], [0, 4, 3], [0, 3, 5], [1, 4, 2], [1, 2, 5], [1, 3, 4], [1, 5, 3]], convexity = 1); } multmatrix([[1, 0, 0, 6], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { - polyhedron(points = [[-0.8, -0.8, -0.8], [0, 0, -0.8], [0.8, -0.8, -0.8], [0.8, 0.8, -0.8], [-0.8, 0.8, -0.8], [-0.8, -0.8, 0.8], [0, 0, 0.8], [0.8, -0.8, 0.8], [0.8, 0.8, 0.8], [-0.8, 0.8, 0.8]], triangles = [[0, 1, 2, 3, 4], [5, 6, 1, 0], [6, 7, 2, 1], [7, 8, 3, 2], [8, 9, 4, 3], [9, 5, 0, 4], [9, 8, 7, 6, 5]], convexity = 2); + polyhedron(points = [[-0.8, -0.8, -0.8], [0, 0, -0.8], [0.8, -0.8, -0.8], [0.8, 0.8, -0.8], [-0.8, 0.8, -0.8], [-0.8, -0.8, 0.8], [0, 0, 0.8], [0.8, -0.8, 0.8], [0.8, 0.8, 0.8], [-0.8, 0.8, 0.8]], faces = [[0, 1, 2, 3, 4], [5, 6, 1, 0], [6, 7, 2, 1], [7, 8, 3, 2], [8, 9, 4, 3], [9, 5, 0, 4], [9, 8, 7, 6, 5]], convexity = 2); } } multmatrix([[1, 0, 0, 0], [0, 1, 0, 2], [0, 0, 1, 0], [0, 0, 0, 1]]) { @@ -22,7 +22,7 @@ group() { polyhedron(points = [[1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, -1, 0], [0, 0, 1], [0, 0, -1]], faces = [[0, 2, 4], [0, 5, 2], [0, 4, 3], [0, 3, 5], [1, 4, 2], [1, 2, 5], [1, 3, 4], [1, 5, 3]], convexity = 1); } multmatrix([[1, 0, 0, 6], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { - polyhedron(points = [[-0.8, -0.8, -0.8], [0, 0, -0.8], [0.8, -0.8, -0.8], [0.8, 0.8, -0.8], [-0.8, 0.8, -0.8], [-0.8, -0.8, 0.8], [0, 0, 0.8], [0.8, -0.8, 0.8], [0.8, 0.8, 0.8], [-0.8, 0.8, 0.8]], triangles = [[0, 1, 2, 3, 4], [5, 6, 1, 0], [6, 7, 2, 1], [7, 8, 3, 2], [8, 9, 4, 3], [9, 5, 0, 4], [9, 8, 7, 6, 5]], convexity = 2); + polyhedron(points = [[-0.8, -0.8, -0.8], [0, 0, -0.8], [0.8, -0.8, -0.8], [0.8, 0.8, -0.8], [-0.8, 0.8, -0.8], [-0.8, -0.8, 0.8], [0, 0, 0.8], [0.8, -0.8, 0.8], [0.8, 0.8, 0.8], [-0.8, 0.8, 0.8]], faces = [[0, 1, 2, 3, 4], [5, 6, 1, 0], [6, 7, 2, 1], [7, 8, 3, 2], [8, 9, 4, 3], [9, 5, 0, 4], [9, 8, 7, 6, 5]], convexity = 2); } } multmatrix([[1, 0, 0, 3], [0, 1, 0, 0], [0, 0, 1, 2], [0, 0, 0, 1]]) { diff --git a/tests/regression/opencsgtest/polyhedron-tests-expected.png b/tests/regression/opencsgtest/polyhedron-tests-expected.png index f6665cf..3574372 100644 Binary files a/tests/regression/opencsgtest/polyhedron-tests-expected.png and b/tests/regression/opencsgtest/polyhedron-tests-expected.png differ diff --git a/tests/regression/throwntogethertest/polyhedron-tests-expected.png b/tests/regression/throwntogethertest/polyhedron-tests-expected.png index c293d88..15e083e 100644 Binary files a/tests/regression/throwntogethertest/polyhedron-tests-expected.png and b/tests/regression/throwntogethertest/polyhedron-tests-expected.png differ -- cgit v0.10.1 From 446dc3d36d36ee3786615c6297a141c01ed972c0 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sun, 15 Dec 2013 18:19:05 -0500 Subject: Improved non-planar tests diff --git a/testdata/scad/bugs/nonplanar_polyhedron.scad b/testdata/scad/bugs/nonplanar_polyhedron.scad deleted file mode 100644 index b92d57e..0000000 --- a/testdata/scad/bugs/nonplanar_polyhedron.scad +++ /dev/null @@ -1,131 +0,0 @@ -// test polyhedrons where the facets are not, stritcly speaking, planar, -// but instead "near planar". see issue #349 in github. -polyhedron(points = [[-10., -13.090169943749475, -34.270509831248425], -[-10., -13.090169943749475, 34.270509831248425], -[-10., 13.090169943749475, -34.270509831248425], -[-10., 13.090169943749475, 34.270509831248425], -[-5., -5., -37.3606797749979], [-5., -5., 37.3606797749979], -[-5., 5., -37.3606797749979], [-5., 5., 37.3606797749979], -[-5., -37.3606797749979, -5.], [-5., -37.3606797749979, 5.], -[-5., -21.18033988749895, -31.18033988749895], -[-5., -21.18033988749895, 31.18033988749895], [-5., 37.3606797749979, -5.], -[-5., 37.3606797749979, 5.], [-5., 21.18033988749895, -31.18033988749895], -[-5., 21.18033988749895, 31.18033988749895], [5., -5., -37.3606797749979], -[5., -5., 37.3606797749979], [5., 5., -37.3606797749979], -[5., 5., 37.3606797749979], [5., -37.3606797749979, -5.], -[5., -37.3606797749979, 5.], [5., -21.18033988749895, -31.18033988749895], -[5., -21.18033988749895, 31.18033988749895], [5., 37.3606797749979, -5.], -[5., 37.3606797749979, 5.], [5., 21.18033988749895, -31.18033988749895], -[5., 21.18033988749895, 31.18033988749895], [10., -13.090169943749475, - -34.270509831248425], [10., -13.090169943749475, 34.270509831248425], -[10., 13.090169943749475, -34.270509831248425], -[10., 13.090169943749475, 34.270509831248425], -[-34.270509831248425, -10., -13.090169943749475], -[-34.270509831248425, -10., 13.090169943749475], -[-34.270509831248425, 10., -13.090169943749475], -[-34.270509831248425, 10., 13.090169943749475], -[-29.270509831248425, -18.090169943749473, -16.18033988749895], -[-29.270509831248425, -18.090169943749473, 16.18033988749895], -[-29.270509831248425, 18.090169943749473, -16.18033988749895], -[-29.270509831248425, 18.090169943749473, 16.18033988749895], -[-18.090169943749473, -16.18033988749895, -29.270509831248425], -[-18.090169943749473, -16.18033988749895, 29.270509831248425], -[-18.090169943749473, 16.18033988749895, -29.270509831248425], -[-18.090169943749473, 16.18033988749895, 29.270509831248425], -[-13.090169943749475, -34.270509831248425, -10.], -[-13.090169943749475, -34.270509831248425, 10.], -[-13.090169943749475, -24.270509831248425, -26.18033988749895], -[-13.090169943749475, -24.270509831248425, 26.18033988749895], -[-13.090169943749475, 24.270509831248425, -26.18033988749895], -[-13.090169943749475, 24.270509831248425, 26.18033988749895], -[-13.090169943749475, 34.270509831248425, -10.], -[-13.090169943749475, 34.270509831248425, 10.], -[-26.18033988749895, -13.090169943749475, -24.270509831248425], -[-26.18033988749895, -13.090169943749475, 24.270509831248425], -[-26.18033988749895, 13.090169943749475, -24.270509831248425], -[-26.18033988749895, 13.090169943749475, 24.270509831248425], -[-37.3606797749979, -5., -5.], [-37.3606797749979, -5., 5.], -[-37.3606797749979, 5., -5.], [-37.3606797749979, 5., 5.], -[-16.18033988749895, -29.270509831248425, -18.090169943749473], -[-16.18033988749895, -29.270509831248425, 18.090169943749473], -[-16.18033988749895, 29.270509831248425, -18.090169943749473], -[-16.18033988749895, 29.270509831248425, 18.090169943749473], -[-31.18033988749895, -5., -21.18033988749895], -[-31.18033988749895, -5., 21.18033988749895], -[-31.18033988749895, 5., -21.18033988749895], -[-31.18033988749895, 5., 21.18033988749895], -[-21.18033988749895, -31.18033988749895, -5.], -[-21.18033988749895, -31.18033988749895, 5.], -[-21.18033988749895, 31.18033988749895, -5.], -[-21.18033988749895, 31.18033988749895, 5.], -[-24.270509831248425, -26.18033988749895, -13.090169943749475], -[-24.270509831248425, -26.18033988749895, 13.090169943749475], -[-24.270509831248425, 26.18033988749895, -13.090169943749475], -[-24.270509831248425, 26.18033988749895, 13.090169943749475], -[16.18033988749895, -29.270509831248425, -18.090169943749473], -[16.18033988749895, -29.270509831248425, 18.090169943749473], -[16.18033988749895, 29.270509831248425, -18.090169943749473], -[16.18033988749895, 29.270509831248425, 18.090169943749473], -[24.270509831248425, -26.18033988749895, -13.090169943749475], -[24.270509831248425, -26.18033988749895, 13.090169943749475], -[24.270509831248425, 26.18033988749895, -13.090169943749475], -[24.270509831248425, 26.18033988749895, 13.090169943749475], -[37.3606797749979, -5., -5.], [37.3606797749979, -5., 5.], -[37.3606797749979, 5., -5.], [37.3606797749979, 5., 5.], -[21.18033988749895, -31.18033988749895, -5.], -[21.18033988749895, -31.18033988749895, 5.], -[21.18033988749895, 31.18033988749895, -5.], -[21.18033988749895, 31.18033988749895, 5.], -[13.090169943749475, -34.270509831248425, -10.], -[13.090169943749475, -34.270509831248425, 10.], -[13.090169943749475, -24.270509831248425, -26.18033988749895], -[13.090169943749475, -24.270509831248425, 26.18033988749895], -[13.090169943749475, 24.270509831248425, -26.18033988749895], -[13.090169943749475, 24.270509831248425, 26.18033988749895], -[13.090169943749475, 34.270509831248425, -10.], -[13.090169943749475, 34.270509831248425, 10.], -[26.18033988749895, -13.090169943749475, -24.270509831248425], -[26.18033988749895, -13.090169943749475, 24.270509831248425], -[26.18033988749895, 13.090169943749475, -24.270509831248425], -[26.18033988749895, 13.090169943749475, 24.270509831248425], -[31.18033988749895, -5., -21.18033988749895], -[31.18033988749895, -5., 21.18033988749895], -[31.18033988749895, 5., -21.18033988749895], -[31.18033988749895, 5., 21.18033988749895], -[18.090169943749473, -16.18033988749895, -29.270509831248425], -[18.090169943749473, -16.18033988749895, 29.270509831248425], -[18.090169943749473, 16.18033988749895, -29.270509831248425], -[18.090169943749473, 16.18033988749895, 29.270509831248425], -[29.270509831248425, -18.090169943749473, -16.18033988749895], -[29.270509831248425, -18.090169943749473, 16.18033988749895], -[29.270509831248425, 18.090169943749473, -16.18033988749895], -[29.270509831248425, 18.090169943749473, 16.18033988749895], -[34.270509831248425, -10., -13.090169943749475], -[34.270509831248425, -10., 13.090169943749475], -[34.270509831248425, 10., -13.090169943749475], -[34.270509831248425, 10., 13.090169943749475]],faces = -[[41, 53, 65, 67, 55, 43, 3, 7, 5, 1], [100, 104, 106, 102, 110, 30, 18, 16, - 28, 108], [11, 1, 5, 17, 29, 23], [18, 30, 26, 14, 2, 6], -[33, 37, 73, 69, 68, 72, 36, 32, 56, 57], [91, 90, 82, 114, 118, 86, 87, - 119, 115, 83], [81, 113, 117, 85, 84, 116, 112, 80, 88, 89], -[59, 58, 34, 38, 74, 70, 71, 75, 39, 35], [0, 10, 22, 28, 16, 4], -[15, 27, 31, 19, 7, 3], [64, 52, 40, 0, 4, 6, 2, 42, 54, 66], -[19, 31, 111, 103, 107, 105, 101, 109, 29, 17], [96, 110, 102, 114, 82, 78], -[53, 41, 47, 61, 73, 37], [43, 49, 15, 3], [94, 108, 28, 22], -[23, 29, 109, 95], [2, 14, 48, 42], [36, 72, 60, 46, 40, 52], -[79, 83, 115, 103, 111, 97], [69, 45, 9, 8, 44, 68], -[24, 98, 90, 91, 99, 25], [77, 95, 109, 101, 113, 81], -[42, 48, 62, 74, 38, 54], [40, 46, 10, 0], [97, 111, 31, 27], -[44, 8, 20, 92, 76, 94, 22, 10, 46, 60], [63, 51, 13, 25, 99, 79, 97, 27, - 15, 49], [26, 30, 110, 96], [1, 11, 47, 41], [55, 39, 75, 63, 49, 43], -[80, 112, 100, 108, 94, 76], [48, 14, 26, 96, 78, 98, 24, 12, 50, 62], -[61, 47, 11, 23, 95, 77, 93, 21, 9, 45], [71, 70, 50, 12, 13, 51], -[93, 89, 88, 92, 20, 21], [102, 106, 118, 114], [65, 53, 37, 33], -[74, 62, 50, 70], [77, 81, 89, 93], [101, 105, 117, 113], [66, 54, 38, 34], -[73, 61, 45, 69], [78, 82, 90, 98], [32, 36, 52, 64], [115, 119, 107, 103], -[92, 88, 80, 76], [71, 51, 63, 75], [56, 32, 64, 66, 34, 58], -[107, 119, 87, 85, 117, 105], [35, 39, 55, 67], [112, 116, 104, 100], -[99, 91, 83, 79], [68, 44, 60, 72], [57, 59, 35, 67, 65, 33], -[116, 84, 86, 118, 106, 104], [4, 16, 18, 6], [7, 19, 17, 5], -[12, 24, 25, 13], [9, 21, 20, 8], [56, 58, 59, 57], [85, 87, 86, 84]] -); diff --git a/testdata/scad/features/polyhedron-nonplanar-tests.scad b/testdata/scad/features/polyhedron-nonplanar-tests.scad new file mode 100644 index 0000000..19e76b6 --- /dev/null +++ b/testdata/scad/features/polyhedron-nonplanar-tests.scad @@ -0,0 +1,157 @@ +// Used to cause issue #349 + +// Very slightly non-planar polyhedron +polyhedron(faces=[[3,2,1,0],[7,6,5,4],[0,1,6,7],[1,2,5,6],[2,3,4,5],[3,0,7,4]], +points=[ + [0.0174497,-0.0174524,0.999695], + [1.0173,-0.0174524,0.982243], + [1.0176,0.982395,0.999693], + [0.0177543,0.982395,1.01715], + [0.000304586,0.999848,0.0174497], + [1.00015,0.999848,-0.00000265809], + [0.999848,-0.0000000000000271051,-0.0174524], + [0,0,0]]); + +// Really non-planar polyhedron +translate([2,0,0]) polyhedron(faces=[[3,2,1,0],[7,6,5,4],[0,1,6,7],[1,2,5,6],[2,3,4,5],[3,0,7,4]], +points=[ + [0,0,1], + [1,0.2,1], + [1,1,1], + [0,1,1], + [0,1,0], + [1,1,0], + [1,0,0], + [0,0,0]]); + +// Real-world example: truncated icosidodecahedron +translate([4.5,0.5,0.5]) scale(0.02) polyhedron(points = [ +[-10., -13.090169943749475, -34.270509831248425], +[-10., -13.090169943749475, 34.270509831248425], +[-10., 13.090169943749475, -34.270509831248425], +[-10., 13.090169943749475, 34.270509831248425], +[-5., -5., -37.3606797749979], [-5., -5., 37.3606797749979], +[-5., 5., -37.3606797749979], [-5., 5., 37.3606797749979], +[-5., -37.3606797749979, -5.], [-5., -37.3606797749979, 5.], +[-5., -21.18033988749895, -31.18033988749895], +[-5., -21.18033988749895, 31.18033988749895], [-5., 37.3606797749979, -5.], +[-5., 37.3606797749979, 5.], [-5., 21.18033988749895, -31.18033988749895], +[-5., 21.18033988749895, 31.18033988749895], [5., -5., -37.3606797749979], +[5., -5., 37.3606797749979], [5., 5., -37.3606797749979], +[5., 5., 37.3606797749979], [5., -37.3606797749979, -5.], +[5., -37.3606797749979, 5.], [5., -21.18033988749895, -31.18033988749895], +[5., -21.18033988749895, 31.18033988749895], [5., 37.3606797749979, -5.], +[5., 37.3606797749979, 5.], [5., 21.18033988749895, -31.18033988749895], +[5., 21.18033988749895, 31.18033988749895], [10., -13.090169943749475, + -34.270509831248425], [10., -13.090169943749475, 34.270509831248425], +[10., 13.090169943749475, -34.270509831248425], +[10., 13.090169943749475, 34.270509831248425], +[-34.270509831248425, -10., -13.090169943749475], +[-34.270509831248425, -10., 13.090169943749475], +[-34.270509831248425, 10., -13.090169943749475], +[-34.270509831248425, 10., 13.090169943749475], +[-29.270509831248425, -18.090169943749473, -16.18033988749895], +[-29.270509831248425, -18.090169943749473, 16.18033988749895], +[-29.270509831248425, 18.090169943749473, -16.18033988749895], +[-29.270509831248425, 18.090169943749473, 16.18033988749895], +[-18.090169943749473, -16.18033988749895, -29.270509831248425], +[-18.090169943749473, -16.18033988749895, 29.270509831248425], +[-18.090169943749473, 16.18033988749895, -29.270509831248425], +[-18.090169943749473, 16.18033988749895, 29.270509831248425], +[-13.090169943749475, -34.270509831248425, -10.], +[-13.090169943749475, -34.270509831248425, 10.], +[-13.090169943749475, -24.270509831248425, -26.18033988749895], +[-13.090169943749475, -24.270509831248425, 26.18033988749895], +[-13.090169943749475, 24.270509831248425, -26.18033988749895], +[-13.090169943749475, 24.270509831248425, 26.18033988749895], +[-13.090169943749475, 34.270509831248425, -10.], +[-13.090169943749475, 34.270509831248425, 10.], +[-26.18033988749895, -13.090169943749475, -24.270509831248425], +[-26.18033988749895, -13.090169943749475, 24.270509831248425], +[-26.18033988749895, 13.090169943749475, -24.270509831248425], +[-26.18033988749895, 13.090169943749475, 24.270509831248425], +[-37.3606797749979, -5., -5.], [-37.3606797749979, -5., 5.], +[-37.3606797749979, 5., -5.], [-37.3606797749979, 5., 5.], +[-16.18033988749895, -29.270509831248425, -18.090169943749473], +[-16.18033988749895, -29.270509831248425, 18.090169943749473], +[-16.18033988749895, 29.270509831248425, -18.090169943749473], +[-16.18033988749895, 29.270509831248425, 18.090169943749473], +[-31.18033988749895, -5., -21.18033988749895], +[-31.18033988749895, -5., 21.18033988749895], +[-31.18033988749895, 5., -21.18033988749895], +[-31.18033988749895, 5., 21.18033988749895], +[-21.18033988749895, -31.18033988749895, -5.], +[-21.18033988749895, -31.18033988749895, 5.], +[-21.18033988749895, 31.18033988749895, -5.], +[-21.18033988749895, 31.18033988749895, 5.], +[-24.270509831248425, -26.18033988749895, -13.090169943749475], +[-24.270509831248425, -26.18033988749895, 13.090169943749475], +[-24.270509831248425, 26.18033988749895, -13.090169943749475], +[-24.270509831248425, 26.18033988749895, 13.090169943749475], +[16.18033988749895, -29.270509831248425, -18.090169943749473], +[16.18033988749895, -29.270509831248425, 18.090169943749473], +[16.18033988749895, 29.270509831248425, -18.090169943749473], +[16.18033988749895, 29.270509831248425, 18.090169943749473], +[24.270509831248425, -26.18033988749895, -13.090169943749475], +[24.270509831248425, -26.18033988749895, 13.090169943749475], +[24.270509831248425, 26.18033988749895, -13.090169943749475], +[24.270509831248425, 26.18033988749895, 13.090169943749475], +[37.3606797749979, -5., -5.], [37.3606797749979, -5., 5.], +[37.3606797749979, 5., -5.], [37.3606797749979, 5., 5.], +[21.18033988749895, -31.18033988749895, -5.], +[21.18033988749895, -31.18033988749895, 5.], +[21.18033988749895, 31.18033988749895, -5.], +[21.18033988749895, 31.18033988749895, 5.], +[13.090169943749475, -34.270509831248425, -10.], +[13.090169943749475, -34.270509831248425, 10.], +[13.090169943749475, -24.270509831248425, -26.18033988749895], +[13.090169943749475, -24.270509831248425, 26.18033988749895], +[13.090169943749475, 24.270509831248425, -26.18033988749895], +[13.090169943749475, 24.270509831248425, 26.18033988749895], +[13.090169943749475, 34.270509831248425, -10.], +[13.090169943749475, 34.270509831248425, 10.], +[26.18033988749895, -13.090169943749475, -24.270509831248425], +[26.18033988749895, -13.090169943749475, 24.270509831248425], +[26.18033988749895, 13.090169943749475, -24.270509831248425], +[26.18033988749895, 13.090169943749475, 24.270509831248425], +[31.18033988749895, -5., -21.18033988749895], +[31.18033988749895, -5., 21.18033988749895], +[31.18033988749895, 5., -21.18033988749895], +[31.18033988749895, 5., 21.18033988749895], +[18.090169943749473, -16.18033988749895, -29.270509831248425], +[18.090169943749473, -16.18033988749895, 29.270509831248425], +[18.090169943749473, 16.18033988749895, -29.270509831248425], +[18.090169943749473, 16.18033988749895, 29.270509831248425], +[29.270509831248425, -18.090169943749473, -16.18033988749895], +[29.270509831248425, -18.090169943749473, 16.18033988749895], +[29.270509831248425, 18.090169943749473, -16.18033988749895], +[29.270509831248425, 18.090169943749473, 16.18033988749895], +[34.270509831248425, -10., -13.090169943749475], +[34.270509831248425, -10., 13.090169943749475], +[34.270509831248425, 10., -13.090169943749475], +[34.270509831248425, 10., 13.090169943749475]],faces = +[[41, 53, 65, 67, 55, 43, 3, 7, 5, 1], [100, 104, 106, 102, 110, 30, 18, 16, + 28, 108], [11, 1, 5, 17, 29, 23], [18, 30, 26, 14, 2, 6], +[33, 37, 73, 69, 68, 72, 36, 32, 56, 57], [91, 90, 82, 114, 118, 86, 87, + 119, 115, 83], [81, 113, 117, 85, 84, 116, 112, 80, 88, 89], +[59, 58, 34, 38, 74, 70, 71, 75, 39, 35], [0, 10, 22, 28, 16, 4], +[15, 27, 31, 19, 7, 3], [64, 52, 40, 0, 4, 6, 2, 42, 54, 66], +[19, 31, 111, 103, 107, 105, 101, 109, 29, 17], [96, 110, 102, 114, 82, 78], +[53, 41, 47, 61, 73, 37], [43, 49, 15, 3], [94, 108, 28, 22], +[23, 29, 109, 95], [2, 14, 48, 42], [36, 72, 60, 46, 40, 52], +[79, 83, 115, 103, 111, 97], [69, 45, 9, 8, 44, 68], +[24, 98, 90, 91, 99, 25], [77, 95, 109, 101, 113, 81], +[42, 48, 62, 74, 38, 54], [40, 46, 10, 0], [97, 111, 31, 27], +[44, 8, 20, 92, 76, 94, 22, 10, 46, 60], [63, 51, 13, 25, 99, 79, 97, 27, + 15, 49], [26, 30, 110, 96], [1, 11, 47, 41], [55, 39, 75, 63, 49, 43], +[80, 112, 100, 108, 94, 76], [48, 14, 26, 96, 78, 98, 24, 12, 50, 62], +[61, 47, 11, 23, 95, 77, 93, 21, 9, 45], [71, 70, 50, 12, 13, 51], +[93, 89, 88, 92, 20, 21], [102, 106, 118, 114], [65, 53, 37, 33], +[74, 62, 50, 70], [77, 81, 89, 93], [101, 105, 117, 113], [66, 54, 38, 34], +[73, 61, 45, 69], [78, 82, 90, 98], [32, 36, 52, 64], [115, 119, 107, 103], +[92, 88, 80, 76], [71, 51, 63, 75], [56, 32, 64, 66, 34, 58], +[107, 119, 87, 85, 117, 105], [35, 39, 55, 67], [112, 116, 104, 100], +[99, 91, 83, 79], [68, 44, 60, 72], [57, 59, 35, 67, 65, 33], +[116, 84, 86, 118, 106, 104], [4, 16, 18, 6], [7, 19, 17, 5], +[12, 24, 25, 13], [9, 21, 20, 8], [56, 58, 59, 57], [85, 87, 86, 84]] +); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 20d4dc4..70e56c6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -832,14 +832,12 @@ list(APPEND DUMPTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/escape-test ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/allexpressions.scad ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/allfunctions.scad ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/allmodules.scad - ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/nonplanar_polyhedron.scad ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/stl-cgal-convert_to_Polyhedron-crash.scad) list(APPEND CGALPNGTEST_FILES ${FEATURES_FILES} ${SCAD_DXF_FILES} ${EXAMPLE_FILES}) list(APPEND CGALPNGTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/include-tests.scad ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/use-tests.scad ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/transform-nan-inf-tests.scad - ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/nonplanar_polyhedron.scad ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/stl-cgal-convert_to_Polyhedron-crash.scad ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/localfiles-test.scad ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/localfiles_dir/localfiles-compatibility-test.scad) diff --git a/tests/regression/cgalpngtest/nonplanar_polyhedron-expected.png b/tests/regression/cgalpngtest/nonplanar_polyhedron-expected.png deleted file mode 100644 index 3c69083..0000000 Binary files a/tests/regression/cgalpngtest/nonplanar_polyhedron-expected.png and /dev/null differ diff --git a/tests/regression/cgalpngtest/polyhedron-nonplanar-tests-expected.png b/tests/regression/cgalpngtest/polyhedron-nonplanar-tests-expected.png new file mode 100644 index 0000000..e21c9fc Binary files /dev/null and b/tests/regression/cgalpngtest/polyhedron-nonplanar-tests-expected.png differ diff --git a/tests/regression/dumptest/nonplanar_polyhedron-expected.csg b/tests/regression/dumptest/nonplanar_polyhedron-expected.csg deleted file mode 100644 index a3c1b81..0000000 --- a/tests/regression/dumptest/nonplanar_polyhedron-expected.csg +++ /dev/null @@ -1,3 +0,0 @@ -group() { - polyhedron(points = [[-10, -13.09016994374, -34.27050983124], [-10, -13.09016994374, 34.27050983124], [-10, 13.09016994374, -34.27050983124], [-10, 13.09016994374, 34.27050983124], [-5, -5, -37.36067977499], [-5, -5, 37.36067977499], [-5, 5, -37.36067977499], [-5, 5, 37.36067977499], [-5, -37.36067977499, -5], [-5, -37.36067977499, 5], [-5, -21.18033988749, -31.18033988749], [-5, -21.18033988749, 31.18033988749], [-5, 37.36067977499, -5], [-5, 37.36067977499, 5], [-5, 21.18033988749, -31.18033988749], [-5, 21.18033988749, 31.18033988749], [5, -5, -37.36067977499], [5, -5, 37.36067977499], [5, 5, -37.36067977499], [5, 5, 37.36067977499], [5, -37.36067977499, -5], [5, -37.36067977499, 5], [5, -21.18033988749, -31.18033988749], [5, -21.18033988749, 31.18033988749], [5, 37.36067977499, -5], [5, 37.36067977499, 5], [5, 21.18033988749, -31.18033988749], [5, 21.18033988749, 31.18033988749], [10, -13.09016994374, -34.27050983124], [10, -13.09016994374, 34.27050983124], [10, 13.09016994374, -34.27050983124], [10, 13.09016994374, 34.27050983124], [-34.27050983124, -10, -13.09016994374], [-34.27050983124, -10, 13.09016994374], [-34.27050983124, 10, -13.09016994374], [-34.27050983124, 10, 13.09016994374], [-29.27050983124, -18.09016994374, -16.18033988749], [-29.27050983124, -18.09016994374, 16.18033988749], [-29.27050983124, 18.09016994374, -16.18033988749], [-29.27050983124, 18.09016994374, 16.18033988749], [-18.09016994374, -16.18033988749, -29.27050983124], [-18.09016994374, -16.18033988749, 29.27050983124], [-18.09016994374, 16.18033988749, -29.27050983124], [-18.09016994374, 16.18033988749, 29.27050983124], [-13.09016994374, -34.27050983124, -10], [-13.09016994374, -34.27050983124, 10], [-13.09016994374, -24.27050983124, -26.18033988749], [-13.09016994374, -24.27050983124, 26.18033988749], [-13.09016994374, 24.27050983124, -26.18033988749], [-13.09016994374, 24.27050983124, 26.18033988749], [-13.09016994374, 34.27050983124, -10], [-13.09016994374, 34.27050983124, 10], [-26.18033988749, -13.09016994374, -24.27050983124], [-26.18033988749, -13.09016994374, 24.27050983124], [-26.18033988749, 13.09016994374, -24.27050983124], [-26.18033988749, 13.09016994374, 24.27050983124], [-37.36067977499, -5, -5], [-37.36067977499, -5, 5], [-37.36067977499, 5, -5], [-37.36067977499, 5, 5], [-16.18033988749, -29.27050983124, -18.09016994374], [-16.18033988749, -29.27050983124, 18.09016994374], [-16.18033988749, 29.27050983124, -18.09016994374], [-16.18033988749, 29.27050983124, 18.09016994374], [-31.18033988749, -5, -21.18033988749], [-31.18033988749, -5, 21.18033988749], [-31.18033988749, 5, -21.18033988749], [-31.18033988749, 5, 21.18033988749], [-21.18033988749, -31.18033988749, -5], [-21.18033988749, -31.18033988749, 5], [-21.18033988749, 31.18033988749, -5], [-21.18033988749, 31.18033988749, 5], [-24.27050983124, -26.18033988749, -13.09016994374], [-24.27050983124, -26.18033988749, 13.09016994374], [-24.27050983124, 26.18033988749, -13.09016994374], [-24.27050983124, 26.18033988749, 13.09016994374], [16.18033988749, -29.27050983124, -18.09016994374], [16.18033988749, -29.27050983124, 18.09016994374], [16.18033988749, 29.27050983124, -18.09016994374], [16.18033988749, 29.27050983124, 18.09016994374], [24.27050983124, -26.18033988749, -13.09016994374], [24.27050983124, -26.18033988749, 13.09016994374], [24.27050983124, 26.18033988749, -13.09016994374], [24.27050983124, 26.18033988749, 13.09016994374], [37.36067977499, -5, -5], [37.36067977499, -5, 5], [37.36067977499, 5, -5], [37.36067977499, 5, 5], [21.18033988749, -31.18033988749, -5], [21.18033988749, -31.18033988749, 5], [21.18033988749, 31.18033988749, -5], [21.18033988749, 31.18033988749, 5], [13.09016994374, -34.27050983124, -10], [13.09016994374, -34.27050983124, 10], [13.09016994374, -24.27050983124, -26.18033988749], [13.09016994374, -24.27050983124, 26.18033988749], [13.09016994374, 24.27050983124, -26.18033988749], [13.09016994374, 24.27050983124, 26.18033988749], [13.09016994374, 34.27050983124, -10], [13.09016994374, 34.27050983124, 10], [26.18033988749, -13.09016994374, -24.27050983124], [26.18033988749, -13.09016994374, 24.27050983124], [26.18033988749, 13.09016994374, -24.27050983124], [26.18033988749, 13.09016994374, 24.27050983124], [31.18033988749, -5, -21.18033988749], [31.18033988749, -5, 21.18033988749], [31.18033988749, 5, -21.18033988749], [31.18033988749, 5, 21.18033988749], [18.09016994374, -16.18033988749, -29.27050983124], [18.09016994374, -16.18033988749, 29.27050983124], [18.09016994374, 16.18033988749, -29.27050983124], [18.09016994374, 16.18033988749, 29.27050983124], [29.27050983124, -18.09016994374, -16.18033988749], [29.27050983124, -18.09016994374, 16.18033988749], [29.27050983124, 18.09016994374, -16.18033988749], [29.27050983124, 18.09016994374, 16.18033988749], [34.27050983124, -10, -13.09016994374], [34.27050983124, -10, 13.09016994374], [34.27050983124, 10, -13.09016994374], [34.27050983124, 10, 13.09016994374]], faces = [[41, 53, 65, 67, 55, 43, 3, 7, 5, 1], [100, 104, 106, 102, 110, 30, 18, 16, 28, 108], [11, 1, 5, 17, 29, 23], [18, 30, 26, 14, 2, 6], [33, 37, 73, 69, 68, 72, 36, 32, 56, 57], [91, 90, 82, 114, 118, 86, 87, 119, 115, 83], [81, 113, 117, 85, 84, 116, 112, 80, 88, 89], [59, 58, 34, 38, 74, 70, 71, 75, 39, 35], [0, 10, 22, 28, 16, 4], [15, 27, 31, 19, 7, 3], [64, 52, 40, 0, 4, 6, 2, 42, 54, 66], [19, 31, 111, 103, 107, 105, 101, 109, 29, 17], [96, 110, 102, 114, 82, 78], [53, 41, 47, 61, 73, 37], [43, 49, 15, 3], [94, 108, 28, 22], [23, 29, 109, 95], [2, 14, 48, 42], [36, 72, 60, 46, 40, 52], [79, 83, 115, 103, 111, 97], [69, 45, 9, 8, 44, 68], [24, 98, 90, 91, 99, 25], [77, 95, 109, 101, 113, 81], [42, 48, 62, 74, 38, 54], [40, 46, 10, 0], [97, 111, 31, 27], [44, 8, 20, 92, 76, 94, 22, 10, 46, 60], [63, 51, 13, 25, 99, 79, 97, 27, 15, 49], [26, 30, 110, 96], [1, 11, 47, 41], [55, 39, 75, 63, 49, 43], [80, 112, 100, 108, 94, 76], [48, 14, 26, 96, 78, 98, 24, 12, 50, 62], [61, 47, 11, 23, 95, 77, 93, 21, 9, 45], [71, 70, 50, 12, 13, 51], [93, 89, 88, 92, 20, 21], [102, 106, 118, 114], [65, 53, 37, 33], [74, 62, 50, 70], [77, 81, 89, 93], [101, 105, 117, 113], [66, 54, 38, 34], [73, 61, 45, 69], [78, 82, 90, 98], [32, 36, 52, 64], [115, 119, 107, 103], [92, 88, 80, 76], [71, 51, 63, 75], [56, 32, 64, 66, 34, 58], [107, 119, 87, 85, 117, 105], [35, 39, 55, 67], [112, 116, 104, 100], [99, 91, 83, 79], [68, 44, 60, 72], [57, 59, 35, 67, 65, 33], [116, 84, 86, 118, 106, 104], [4, 16, 18, 6], [7, 19, 17, 5], [12, 24, 25, 13], [9, 21, 20, 8], [56, 58, 59, 57], [85, 87, 86, 84]], convexity = 1); -} diff --git a/tests/regression/dumptest/polyhedron-nonplanar-tests-expected.csg b/tests/regression/dumptest/polyhedron-nonplanar-tests-expected.csg new file mode 100644 index 0000000..1b40e99 --- /dev/null +++ b/tests/regression/dumptest/polyhedron-nonplanar-tests-expected.csg @@ -0,0 +1,11 @@ +group() { + polyhedron(points = [[0.0174497, -0.0174524, 0.999695], [1.0173, -0.0174524, 0.982243], [1.0176, 0.982395, 0.999693], [0.0177543, 0.982395, 1.01715], [0.000304586, 0.999848, 0.0174497], [1.00015, 0.999848, -0.00000265809], [0.999848, 0, -0.0174524], [0, 0, 0]], faces = [[3, 2, 1, 0], [7, 6, 5, 4], [0, 1, 6, 7], [1, 2, 5, 6], [2, 3, 4, 5], [3, 0, 7, 4]], convexity = 1); + multmatrix([[1, 0, 0, 2], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { + polyhedron(points = [[0, 0, 1], [1, 0.2, 1], [1, 1, 1], [0, 1, 1], [0, 1, 0], [1, 1, 0], [1, 0, 0], [0, 0, 0]], faces = [[3, 2, 1, 0], [7, 6, 5, 4], [0, 1, 6, 7], [1, 2, 5, 6], [2, 3, 4, 5], [3, 0, 7, 4]], convexity = 1); + } + multmatrix([[1, 0, 0, 4.5], [0, 1, 0, 0.5], [0, 0, 1, 0.5], [0, 0, 0, 1]]) { + multmatrix([[0.02, 0, 0, 0], [0, 0.02, 0, 0], [0, 0, 0.02, 0], [0, 0, 0, 1]]) { + polyhedron(points = [[-10, -13.09016994374, -34.27050983124], [-10, -13.09016994374, 34.27050983124], [-10, 13.09016994374, -34.27050983124], [-10, 13.09016994374, 34.27050983124], [-5, -5, -37.36067977499], [-5, -5, 37.36067977499], [-5, 5, -37.36067977499], [-5, 5, 37.36067977499], [-5, -37.36067977499, -5], [-5, -37.36067977499, 5], [-5, -21.18033988749, -31.18033988749], [-5, -21.18033988749, 31.18033988749], [-5, 37.36067977499, -5], [-5, 37.36067977499, 5], [-5, 21.18033988749, -31.18033988749], [-5, 21.18033988749, 31.18033988749], [5, -5, -37.36067977499], [5, -5, 37.36067977499], [5, 5, -37.36067977499], [5, 5, 37.36067977499], [5, -37.36067977499, -5], [5, -37.36067977499, 5], [5, -21.18033988749, -31.18033988749], [5, -21.18033988749, 31.18033988749], [5, 37.36067977499, -5], [5, 37.36067977499, 5], [5, 21.18033988749, -31.18033988749], [5, 21.18033988749, 31.18033988749], [10, -13.09016994374, -34.27050983124], [10, -13.09016994374, 34.27050983124], [10, 13.09016994374, -34.27050983124], [10, 13.09016994374, 34.27050983124], [-34.27050983124, -10, -13.09016994374], [-34.27050983124, -10, 13.09016994374], [-34.27050983124, 10, -13.09016994374], [-34.27050983124, 10, 13.09016994374], [-29.27050983124, -18.09016994374, -16.18033988749], [-29.27050983124, -18.09016994374, 16.18033988749], [-29.27050983124, 18.09016994374, -16.18033988749], [-29.27050983124, 18.09016994374, 16.18033988749], [-18.09016994374, -16.18033988749, -29.27050983124], [-18.09016994374, -16.18033988749, 29.27050983124], [-18.09016994374, 16.18033988749, -29.27050983124], [-18.09016994374, 16.18033988749, 29.27050983124], [-13.09016994374, -34.27050983124, -10], [-13.09016994374, -34.27050983124, 10], [-13.09016994374, -24.27050983124, -26.18033988749], [-13.09016994374, -24.27050983124, 26.18033988749], [-13.09016994374, 24.27050983124, -26.18033988749], [-13.09016994374, 24.27050983124, 26.18033988749], [-13.09016994374, 34.27050983124, -10], [-13.09016994374, 34.27050983124, 10], [-26.18033988749, -13.09016994374, -24.27050983124], [-26.18033988749, -13.09016994374, 24.27050983124], [-26.18033988749, 13.09016994374, -24.27050983124], [-26.18033988749, 13.09016994374, 24.27050983124], [-37.36067977499, -5, -5], [-37.36067977499, -5, 5], [-37.36067977499, 5, -5], [-37.36067977499, 5, 5], [-16.18033988749, -29.27050983124, -18.09016994374], [-16.18033988749, -29.27050983124, 18.09016994374], [-16.18033988749, 29.27050983124, -18.09016994374], [-16.18033988749, 29.27050983124, 18.09016994374], [-31.18033988749, -5, -21.18033988749], [-31.18033988749, -5, 21.18033988749], [-31.18033988749, 5, -21.18033988749], [-31.18033988749, 5, 21.18033988749], [-21.18033988749, -31.18033988749, -5], [-21.18033988749, -31.18033988749, 5], [-21.18033988749, 31.18033988749, -5], [-21.18033988749, 31.18033988749, 5], [-24.27050983124, -26.18033988749, -13.09016994374], [-24.27050983124, -26.18033988749, 13.09016994374], [-24.27050983124, 26.18033988749, -13.09016994374], [-24.27050983124, 26.18033988749, 13.09016994374], [16.18033988749, -29.27050983124, -18.09016994374], [16.18033988749, -29.27050983124, 18.09016994374], [16.18033988749, 29.27050983124, -18.09016994374], [16.18033988749, 29.27050983124, 18.09016994374], [24.27050983124, -26.18033988749, -13.09016994374], [24.27050983124, -26.18033988749, 13.09016994374], [24.27050983124, 26.18033988749, -13.09016994374], [24.27050983124, 26.18033988749, 13.09016994374], [37.36067977499, -5, -5], [37.36067977499, -5, 5], [37.36067977499, 5, -5], [37.36067977499, 5, 5], [21.18033988749, -31.18033988749, -5], [21.18033988749, -31.18033988749, 5], [21.18033988749, 31.18033988749, -5], [21.18033988749, 31.18033988749, 5], [13.09016994374, -34.27050983124, -10], [13.09016994374, -34.27050983124, 10], [13.09016994374, -24.27050983124, -26.18033988749], [13.09016994374, -24.27050983124, 26.18033988749], [13.09016994374, 24.27050983124, -26.18033988749], [13.09016994374, 24.27050983124, 26.18033988749], [13.09016994374, 34.27050983124, -10], [13.09016994374, 34.27050983124, 10], [26.18033988749, -13.09016994374, -24.27050983124], [26.18033988749, -13.09016994374, 24.27050983124], [26.18033988749, 13.09016994374, -24.27050983124], [26.18033988749, 13.09016994374, 24.27050983124], [31.18033988749, -5, -21.18033988749], [31.18033988749, -5, 21.18033988749], [31.18033988749, 5, -21.18033988749], [31.18033988749, 5, 21.18033988749], [18.09016994374, -16.18033988749, -29.27050983124], [18.09016994374, -16.18033988749, 29.27050983124], [18.09016994374, 16.18033988749, -29.27050983124], [18.09016994374, 16.18033988749, 29.27050983124], [29.27050983124, -18.09016994374, -16.18033988749], [29.27050983124, -18.09016994374, 16.18033988749], [29.27050983124, 18.09016994374, -16.18033988749], [29.27050983124, 18.09016994374, 16.18033988749], [34.27050983124, -10, -13.09016994374], [34.27050983124, -10, 13.09016994374], [34.27050983124, 10, -13.09016994374], [34.27050983124, 10, 13.09016994374]], faces = [[41, 53, 65, 67, 55, 43, 3, 7, 5, 1], [100, 104, 106, 102, 110, 30, 18, 16, 28, 108], [11, 1, 5, 17, 29, 23], [18, 30, 26, 14, 2, 6], [33, 37, 73, 69, 68, 72, 36, 32, 56, 57], [91, 90, 82, 114, 118, 86, 87, 119, 115, 83], [81, 113, 117, 85, 84, 116, 112, 80, 88, 89], [59, 58, 34, 38, 74, 70, 71, 75, 39, 35], [0, 10, 22, 28, 16, 4], [15, 27, 31, 19, 7, 3], [64, 52, 40, 0, 4, 6, 2, 42, 54, 66], [19, 31, 111, 103, 107, 105, 101, 109, 29, 17], [96, 110, 102, 114, 82, 78], [53, 41, 47, 61, 73, 37], [43, 49, 15, 3], [94, 108, 28, 22], [23, 29, 109, 95], [2, 14, 48, 42], [36, 72, 60, 46, 40, 52], [79, 83, 115, 103, 111, 97], [69, 45, 9, 8, 44, 68], [24, 98, 90, 91, 99, 25], [77, 95, 109, 101, 113, 81], [42, 48, 62, 74, 38, 54], [40, 46, 10, 0], [97, 111, 31, 27], [44, 8, 20, 92, 76, 94, 22, 10, 46, 60], [63, 51, 13, 25, 99, 79, 97, 27, 15, 49], [26, 30, 110, 96], [1, 11, 47, 41], [55, 39, 75, 63, 49, 43], [80, 112, 100, 108, 94, 76], [48, 14, 26, 96, 78, 98, 24, 12, 50, 62], [61, 47, 11, 23, 95, 77, 93, 21, 9, 45], [71, 70, 50, 12, 13, 51], [93, 89, 88, 92, 20, 21], [102, 106, 118, 114], [65, 53, 37, 33], [74, 62, 50, 70], [77, 81, 89, 93], [101, 105, 117, 113], [66, 54, 38, 34], [73, 61, 45, 69], [78, 82, 90, 98], [32, 36, 52, 64], [115, 119, 107, 103], [92, 88, 80, 76], [71, 51, 63, 75], [56, 32, 64, 66, 34, 58], [107, 119, 87, 85, 117, 105], [35, 39, 55, 67], [112, 116, 104, 100], [99, 91, 83, 79], [68, 44, 60, 72], [57, 59, 35, 67, 65, 33], [116, 84, 86, 118, 106, 104], [4, 16, 18, 6], [7, 19, 17, 5], [12, 24, 25, 13], [9, 21, 20, 8], [56, 58, 59, 57], [85, 87, 86, 84]], convexity = 1); + } + } +} diff --git a/tests/regression/opencsgtest/nonplanar_polyhedron-expected.png b/tests/regression/opencsgtest/nonplanar_polyhedron-expected.png deleted file mode 100644 index c81f20a..0000000 Binary files a/tests/regression/opencsgtest/nonplanar_polyhedron-expected.png and /dev/null differ diff --git a/tests/regression/opencsgtest/polyhedron-nonplanar-tests-expected.png b/tests/regression/opencsgtest/polyhedron-nonplanar-tests-expected.png new file mode 100644 index 0000000..26a6791 Binary files /dev/null and b/tests/regression/opencsgtest/polyhedron-nonplanar-tests-expected.png differ diff --git a/tests/regression/throwntogethertest/nonplanar_polyhedron-expected.png b/tests/regression/throwntogethertest/nonplanar_polyhedron-expected.png deleted file mode 100644 index c81f20a..0000000 Binary files a/tests/regression/throwntogethertest/nonplanar_polyhedron-expected.png and /dev/null differ diff --git a/tests/regression/throwntogethertest/polyhedron-nonplanar-tests-expected.png b/tests/regression/throwntogethertest/polyhedron-nonplanar-tests-expected.png new file mode 100644 index 0000000..26a6791 Binary files /dev/null and b/tests/regression/throwntogethertest/polyhedron-nonplanar-tests-expected.png differ -- cgit v0.10.1