From f04c235f2f0480fce04e55812e3b7611db34577b Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sat, 25 Dec 2010 23:46:07 +0100 Subject: Added section for proposed language changes for 'V2.0' diff --git a/doc/TODO.txt b/doc/TODO.txt index 63afb03..a053b58 100644 --- a/doc/TODO.txt +++ b/doc/TODO.txt @@ -169,6 +169,11 @@ o Grammar - import_*() -> *_import() (consistent prefix vs. postfix) - linear_extrude()/rotate_extrude(): Cumbersome names? -> (extrude, revolve, lathe, sweep ?) +IDEAS FOR LANGUAGE CHANGES +-------------------------- +o More strict checking of module parameters to make e.g. this fail: + module test(a,b) { a=1; b=2; echo(a,b,c); } test(c=3); + CODE ---- -- cgit v0.10.1 From 592ca6abadcb6443629be4407b973279a891278c Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sat, 25 Dec 2010 23:55:28 +0100 Subject: Output LWPOLYLINE objects instead of LINE for DXF export. Patch submitted by Lars Kruse diff --git a/src/export.cc b/src/export.cc index 40b16d5..2b474f6 100644 --- a/src/export.cc +++ b/src/export.cc @@ -166,6 +166,20 @@ void export_dxf(CGAL_Nef_polyhedron *root_N, QString filename, QProgressDialog * } setlocale(LC_NUMERIC, "C"); // Ensure radix is . (not ,) in output + + // Some importers (e.g. QCAD) needs a HEADER section specifying AutoCAD 2000 as + // the file format for LWPOLYLINE entities to work + fprintf(f, " 0\n" + "SECTION\n" + " 2\n" + "HEADER\n" + " 9\n" + "$ACADVER\n" + " 1\n" + "AC1015\n" + " 0\n" + "ENDSEC\n"); + // Some importers (e.g. Inkscape) needs a BLOCKS section to be present fprintf(f, " 0\n" "SECTION\n" @@ -182,26 +196,29 @@ void export_dxf(CGAL_Nef_polyhedron *root_N, QString filename, QProgressDialog * DxfData dd(*root_N); for (int i=0; ix; - double y1 = p1->y; - double x2 = p2->x; - double y2 = p2->y; - fprintf(f, " 0\n"); - fprintf(f, "LINE\n"); - // Some importers (e.g. Inkscape) needs a layer to be specified - fprintf(f, " 8\n"); - fprintf(f, "0\n"); + if (dd.paths[i].points.size() < 2) + // not a valid polygon + continue; + // Use the LWPOLYLINE class - this makes it easier to handle complete + // objects (as paths) in Inkscape. + fprintf(f, " 0\n"); + fprintf(f, "LWPOLYLINE\n"); + // Some importers (e.g. Inkscape) need a layer to be specified + fprintf(f, " 8\n"); + fprintf(f, "0\n"); + // number of vertices + fprintf(f, " 90\n"); + fprintf(f, "%d\n", dd.paths[i].points.size()); + // polygon flag (closed, ...) + fprintf(f, " 70\n"); + fprintf(f, "%d\n", dd.paths[i].is_closed ? 1 : 0); + // add all points + for (int j=0; jx); fprintf(f, " 20\n"); - fprintf(f, "%f\n", y1); - fprintf(f, " 21\n"); - fprintf(f, "%f\n", y2); + fprintf(f, "%f\n", p->y); } } -- cgit v0.10.1 From 9aa7b944590eadd6bd05ad2a8e5331f06ec17079 Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Fri, 8 Apr 2011 22:19:06 +0100 Subject: WIP adding support for convex hull operations. diff --git a/src/cgaladv.cc b/src/cgaladv.cc index bf2e85a..3e53569 100644 --- a/src/cgaladv.cc +++ b/src/cgaladv.cc @@ -30,6 +30,7 @@ #include "builtin.h" #include "printutils.h" #include "cgal.h" +#include #ifdef ENABLE_CGAL extern CGAL_Nef_polyhedron3 minkowski3(CGAL_Nef_polyhedron3 a, CGAL_Nef_polyhedron3 b); @@ -39,7 +40,8 @@ extern CGAL_Nef_polyhedron2 minkowski2(CGAL_Nef_polyhedron2 a, CGAL_Nef_polyhedr enum cgaladv_type_e { MINKOWSKI, GLIDE, - SUBDIV + SUBDIV, + HULL }; class CgaladvModule : public AbstractModule @@ -103,6 +105,10 @@ AbstractNode *CgaladvModule::evaluate(const Context *ctx, const ModuleInstantiat level = c.lookup_variable("level", true); } + if (type == HULL) { + convexity = c.lookup_variable("convexity", true); + } + node->convexity = (int)convexity.num; node->path = path; node->subdiv_type = subdiv_type.text; @@ -125,6 +131,7 @@ void register_builtin_cgaladv() builtin_modules["minkowski"] = new CgaladvModule(MINKOWSKI); builtin_modules["glide"] = new CgaladvModule(GLIDE); builtin_modules["subdiv"] = new CgaladvModule(SUBDIV); + builtin_modules["hull"] = new CgaladvModule(HULL); } #ifdef ENABLE_CGAL @@ -174,6 +181,29 @@ CGAL_Nef_polyhedron CgaladvNode::render_cgal_nef_polyhedron() const PRINT("WARNING: subdiv() is not implemented yet!"); } + if (type == HULL) + { + bool first = true; + foreach(AbstractNode * v, children) { + if (v->modinst->tag_background) + continue; + if (first) { + N = v->render_cgal_nef_polyhedron(); + if (N.dim != 0) + first = false; + } else { + CGAL_Nef_polyhedron tmp = v->render_cgal_nef_polyhedron(); + if (N.dim == 3 && tmp.dim == 3) { + + } + if (N.dim == 2 && tmp.dim == 2) { + + } + } + v->progress_report(); + } + } + cgal_nef_cache.insert(cache_id, new cgal_nef_cache_entry(N), N.weight()); print_messages_pop(); progress_report(); -- cgit v0.10.1 From fe5d7359644ca26098a1cb070f0deba416b60598 Mon Sep 17 00:00:00 2001 From: Len Trigg Date: Sat, 9 Apr 2011 07:39:14 +0100 Subject: 2d Minkowski mostly working When the 2d minkowski was enabled the nef2p2 was bailing out too early. I added a simple p2nef2 based on what projection.cc was doing, and applied it to the outer_boundary of the polygon_with_holes_2. It now seems to work for simple scad code such as: minkowski() { translate([25,0,0]) square(20); circle(r=3); } diff --git a/src/cgaladv_minkowski2.cc b/src/cgaladv_minkowski2.cc index 6a4b31c..d03943c 100644 --- a/src/cgaladv_minkowski2.cc +++ b/src/cgaladv_minkowski2.cc @@ -31,7 +31,7 @@ #include "grid.h" #include "cgal.h" -#if 0 +#if 1 #include #include @@ -42,6 +42,44 @@ struct K2 : public CGAL::Exact_predicates_exact_constructions_kernel {}; typedef CGAL::Polygon_2 Poly2; typedef CGAL::Polygon_with_holes_2 Poly2h; +//----------------------------------------------------------------------------- +// Pretty-print a CGAL polygon. +// +template +void print_polygon (const CGAL::Polygon_2& P) +{ + typename CGAL::Polygon_2::Vertex_const_iterator vit; + + std::cout << "[ " << P.size() << " vertices:"; + for (vit = P.vertices_begin(); vit != P.vertices_end(); ++vit) + std::cout << " (" << *vit << ')'; + std::cout << " ]" << std::endl; +} + +//----------------------------------------------------------------------------- +// Pretty-print a polygon with holes. +// +template +void print_polygon_with_holes (const CGAL::Polygon_with_holes_2& pwh) { + if (! pwh.is_unbounded()) { + std::cout << "{ Outer boundary = "; + print_polygon (pwh.outer_boundary()); + } else + std::cout << "{ Unbounded polygon." << std::endl; + + typename CGAL::Polygon_with_holes_2::Hole_const_iterator hit; + unsigned int k = 1; + + std::cout << " " << pwh.number_of_holes() << " holes:" << std::endl; + for (hit = pwh.holes_begin(); hit != pwh.holes_end(); ++hit, ++k) { + std::cout << " Hole #" << k << " = "; + print_polygon (*hit); + } + std::cout << " }" << std::endl; + + return; +} + static Poly2 nef2p2(CGAL_Nef_polyhedron2 p) { std::list points; @@ -54,16 +92,23 @@ static Poly2 nef2p2(CGAL_Nef_polyhedron2 p) for (fci_t fit = E.faces_begin(), fend = E.faces_end(); fit != fend; ++fit) { - if (fit != E.faces_begin()) { + std::cout << "face " << ((E.mark(fit))? "is part of polygon" : "is not part of polygon") << std::endl; + if (!E.mark(fit)) { + continue; + } + //if (fit != E.faces_begin()) { + if (points.size() != 0) { PRINT("WARNING: minkowski() is not implemented for 2d objects with holes!"); - break; + break; } heafcc_t fcirc(E.halfedge(fit)), fend(fcirc); CGAL_For_all(fcirc, fend) { + //std::cout << "fcirc,fend " << std::endl; if (E.is_standard(E.target(fcirc))) { Explorer::Point ep = E.point(E.target(fcirc)); double x = to_double(ep.x()), y = to_double(ep.y()); + std::cout << "point " << ep << std::endl; grid.align(x, y); points.push_back(K2::Point_2(x, y)); } @@ -72,15 +117,36 @@ static Poly2 nef2p2(CGAL_Nef_polyhedron2 p) return Poly2(points.begin(), points.end()); } +static CGAL_Nef_polyhedron2 p2nef2(Poly2 p2) { + std::list points; + for (int j = 0; j < p2.size(); j++) { + double x = to_double(p2[j].x()); + double y = to_double(p2[j].y()); + CGAL_Nef_polyhedron2::Point p = CGAL_Nef_polyhedron2::Point(x, y); + points.push_back(p); + } + return CGAL_Nef_polyhedron2(points.begin(), points.end(), CGAL_Nef_polyhedron2::INCLUDED); +} CGAL_Nef_polyhedron2 minkowski2(CGAL_Nef_polyhedron2 a, CGAL_Nef_polyhedron2 b) { Poly2 ap = nef2p2(a), bp = nef2p2(b); - Poly2h x = minkowski_sum_2(ap, bp); - /** FIXME **/ - - PRINT("WARNING: minkowski() is not implemented yet for 2d objects!"); - return CGAL_Nef_polyhedron2(); + std::cout << "ap = "; print_polygon(ap); + std::cout << "bp = "; print_polygon(bp); + + if (ap.size() == 0) { + PRINT("WARNING: minkowski() could not get any points from object 1!"); + return CGAL_Nef_polyhedron2(); + } else if (bp.size() == 0) { + PRINT("WARNING: minkowski() could not get any points from object 2!"); + return CGAL_Nef_polyhedron2(); + } else { + Poly2h x = minkowski_sum_2(ap, bp); + std::cout << "result = "; print_polygon_with_holes(x); + + // Make a CGAL_Nef_polyhedron2 out of just the boundary for starters + return p2nef2(x.outer_boundary()); + } } #else -- cgit v0.10.1 From 9cc441025cda17a494259b1ae2cafc5b48c14a12 Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Sat, 9 Apr 2011 10:27:50 +0100 Subject: Basic implementation of convex hull for 2d polyhedra. The code was provided to me by Len Trigg via email. diff --git a/openscad.pro b/openscad.pro index 5b3a398..eecae9a 100644 --- a/openscad.pro +++ b/openscad.pro @@ -161,6 +161,7 @@ SOURCES += src/openscad.cc \ src/primitives.cc \ src/projection.cc \ src/cgaladv.cc \ + src/cgaladv_convexhull2.cc \ src/cgaladv_minkowski3.cc \ src/cgaladv_minkowski2.cc \ src/surface.cc \ @@ -180,7 +181,7 @@ SOURCES += src/openscad.cc \ src/Preferences.cc \ src/progress.cc \ src/editor.cc \ - src/mathc99.cc + src/mathc99.cc macx { HEADERS += src/AppleEvents.h \ @@ -198,4 +199,3 @@ INSTALLS += examples libraries.path = /usr/local/share/openscad/libraries/ libraries.files = libraries/* INSTALLS += libraries - diff --git a/src/cgal.h b/src/cgal.h index 6cbb251..f9161cc 100644 --- a/src/cgal.h +++ b/src/cgal.h @@ -10,6 +10,9 @@ #include #include #include +#include +#include +#include typedef CGAL::Extended_cartesian CGAL_Kernel2; typedef CGAL::Nef_polyhedron_2 CGAL_Nef_polyhedron2; @@ -24,6 +27,9 @@ typedef CGAL_Nef_polyhedron3::Aff_transformation_3 CGAL_Aff_transformation; typedef CGAL_Nef_polyhedron3::Vector_3 CGAL_Vector; typedef CGAL_Nef_polyhedron3::Plane_3 CGAL_Plane; typedef CGAL_Nef_polyhedron3::Point_3 CGAL_Point; +typedef CGAL::Exact_predicates_exact_constructions_kernel CGAL_ExactKernel2; +typedef CGAL::Polygon_2 CGAL_Poly2; +typedef CGAL::Polygon_with_holes_2 CGAL_Poly2h; struct CGAL_Nef_polyhedron { diff --git a/src/cgaladv.cc b/src/cgaladv.cc index 3e53569..48f14c7 100644 --- a/src/cgaladv.cc +++ b/src/cgaladv.cc @@ -30,11 +30,11 @@ #include "builtin.h" #include "printutils.h" #include "cgal.h" -#include #ifdef ENABLE_CGAL extern CGAL_Nef_polyhedron3 minkowski3(CGAL_Nef_polyhedron3 a, CGAL_Nef_polyhedron3 b); extern CGAL_Nef_polyhedron2 minkowski2(CGAL_Nef_polyhedron2 a, CGAL_Nef_polyhedron2 b); +extern CGAL_Nef_polyhedron2 convexhull2(CGAL_Nef_polyhedron2 a, CGAL_Nef_polyhedron2 b); #endif enum cgaladv_type_e { @@ -197,7 +197,7 @@ CGAL_Nef_polyhedron CgaladvNode::render_cgal_nef_polyhedron() const } if (N.dim == 2 && tmp.dim == 2) { - + N.p2 = convexhull2(N.p2, tmp.p2); } } v->progress_report(); diff --git a/src/cgaladv_convexhull2.cc b/src/cgaladv_convexhull2.cc new file mode 100644 index 0000000..9505e44 --- /dev/null +++ b/src/cgaladv_convexhull2.cc @@ -0,0 +1,59 @@ +/* + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf and + * Marius Kintel + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * As a special exception, you have permission to link this program + * with the CGAL library and distribute executables, as long as you + * follow the requirements of the GNU GPL in regard to all of the + * software in the executable aside from CGAL. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifdef ENABLE_CGAL + +#include "cgal.h" +#include + +extern CGAL_Nef_polyhedron2 convexhull2(CGAL_Nef_polyhedron2 a, CGAL_Nef_polyhedron2 b); +extern CGAL_Poly2 nef2p2(CGAL_Nef_polyhedron2 p); + +static std::list p2points(CGAL_Poly2 p2) +{ + std::list points; + for (int j = 0; j < p2.size(); j++) { + double x = to_double(p2[j].x()), y = to_double(p2[j].y()); + CGAL_Nef_polyhedron2::Point p = + CGAL_Nef_polyhedron2::Point(x, y); + points.push_back(p); + } + return points; +} + +CGAL_Nef_polyhedron2 convexhull2(CGAL_Nef_polyhedron2 a, CGAL_Nef_polyhedron2 b) +{ + CGAL_Poly2 ap = nef2p2(a); + std::list points = p2points(ap), result; + + CGAL::convex_hull_2(points.begin(), points.end(), + std::back_inserter(result)); + std::cout << result.size() << " points on the convex hull" << std::endl; + return CGAL_Nef_polyhedron2(result.begin(), + result.end(), CGAL_Nef_polyhedron2::INCLUDED); +} + +#endif diff --git a/src/cgaladv_minkowski2.cc b/src/cgaladv_minkowski2.cc index d03943c..116139f 100644 --- a/src/cgaladv_minkowski2.cc +++ b/src/cgaladv_minkowski2.cc @@ -33,14 +33,10 @@ #if 1 -#include #include extern CGAL_Nef_polyhedron2 minkowski2(CGAL_Nef_polyhedron2 a, CGAL_Nef_polyhedron2 b); - -struct K2 : public CGAL::Exact_predicates_exact_constructions_kernel {}; -typedef CGAL::Polygon_2 Poly2; -typedef CGAL::Polygon_with_holes_2 Poly2h; +extern CGAL_Poly2 nef2p2(CGAL_Nef_polyhedron2 p); //----------------------------------------------------------------------------- // Pretty-print a CGAL polygon. @@ -80,9 +76,9 @@ void print_polygon_with_holes (const CGAL::Polygon_with_holes_2 points; + std::list points; Grid2d grid(GRID_COARSE); typedef CGAL_Nef_polyhedron2::Explorer Explorer; @@ -110,14 +106,14 @@ static Poly2 nef2p2(CGAL_Nef_polyhedron2 p) double x = to_double(ep.x()), y = to_double(ep.y()); std::cout << "point " << ep << std::endl; grid.align(x, y); - points.push_back(K2::Point_2(x, y)); + points.push_back(CGAL_ExactKernel2::Point_2(x, y)); } } } - return Poly2(points.begin(), points.end()); + return CGAL_Poly2(points.begin(), points.end()); } -static CGAL_Nef_polyhedron2 p2nef2(Poly2 p2) { +static CGAL_Nef_polyhedron2 p2nef2(CGAL_Poly2 p2) { std::list points; for (int j = 0; j < p2.size(); j++) { double x = to_double(p2[j].x()); @@ -130,7 +126,7 @@ static CGAL_Nef_polyhedron2 p2nef2(Poly2 p2) { CGAL_Nef_polyhedron2 minkowski2(CGAL_Nef_polyhedron2 a, CGAL_Nef_polyhedron2 b) { - Poly2 ap = nef2p2(a), bp = nef2p2(b); + CGAL_Poly2 ap = nef2p2(a), bp = nef2p2(b); std::cout << "ap = "; print_polygon(ap); std::cout << "bp = "; print_polygon(bp); @@ -141,7 +137,7 @@ CGAL_Nef_polyhedron2 minkowski2(CGAL_Nef_polyhedron2 a, CGAL_Nef_polyhedron2 b) PRINT("WARNING: minkowski() could not get any points from object 2!"); return CGAL_Nef_polyhedron2(); } else { - Poly2h x = minkowski_sum_2(ap, bp); + CGAL_Poly2h x = minkowski_sum_2(ap, bp); std::cout << "result = "; print_polygon_with_holes(x); // Make a CGAL_Nef_polyhedron2 out of just the boundary for starters -- cgit v0.10.1 From 5ef540054cc4a548a78eb78318e527f0e283ece8 Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Sat, 9 Apr 2011 17:52:12 +0100 Subject: Added test script for convex hull. diff --git a/testdata/scad/convex_hull.scad b/testdata/scad/convex_hull.scad new file mode 100644 index 0000000..7db6817 --- /dev/null +++ b/testdata/scad/convex_hull.scad @@ -0,0 +1,8 @@ +hull() { + union() { + translate([15,10,0]) + circle(10); + circle(10); + } + square(2); +} -- cgit v0.10.1 From 5d5c745fdecd2580b5254cc1fd758bdc31ff88ba Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Sat, 9 Apr 2011 17:53:19 +0100 Subject: Slight improvement. You no longer need an arbitary shape in the script for it to work. See changes in testdata/scad/convex_hull.scad The square(2) was never rendered it was just there because the hull is calculated when it itterates onto the second child. I also removed the unneeded parameter. diff --git a/src/cgaladv.cc b/src/cgaladv.cc index 48f14c7..45a3bdd 100644 --- a/src/cgaladv.cc +++ b/src/cgaladv.cc @@ -34,7 +34,7 @@ #ifdef ENABLE_CGAL extern CGAL_Nef_polyhedron3 minkowski3(CGAL_Nef_polyhedron3 a, CGAL_Nef_polyhedron3 b); extern CGAL_Nef_polyhedron2 minkowski2(CGAL_Nef_polyhedron2 a, CGAL_Nef_polyhedron2 b); -extern CGAL_Nef_polyhedron2 convexhull2(CGAL_Nef_polyhedron2 a, CGAL_Nef_polyhedron2 b); +extern CGAL_Nef_polyhedron2 convexhull2(CGAL_Nef_polyhedron2 a); #endif enum cgaladv_type_e { @@ -183,24 +183,19 @@ CGAL_Nef_polyhedron CgaladvNode::render_cgal_nef_polyhedron() const if (type == HULL) { - bool first = true; + foreach(AbstractNode * v, children) { - if (v->modinst->tag_background) - continue; - if (first) { - N = v->render_cgal_nef_polyhedron(); - if (N.dim != 0) - first = false; - } else { - CGAL_Nef_polyhedron tmp = v->render_cgal_nef_polyhedron(); - if (N.dim == 3 && tmp.dim == 3) { - - } - if (N.dim == 2 && tmp.dim == 2) { - N.p2 = convexhull2(N.p2, tmp.p2); - } - } - v->progress_report(); + if (v->modinst->tag_background) + continue; + N = v->render_cgal_nef_polyhedron(); + if (N.dim == 3) { + + } + if (N.dim == 2) { + N.p2 = convexhull2(N.p2); + } + v->progress_report(); + break; } } diff --git a/src/cgaladv_convexhull2.cc b/src/cgaladv_convexhull2.cc index 9505e44..1914954 100644 --- a/src/cgaladv_convexhull2.cc +++ b/src/cgaladv_convexhull2.cc @@ -29,7 +29,7 @@ #include "cgal.h" #include -extern CGAL_Nef_polyhedron2 convexhull2(CGAL_Nef_polyhedron2 a, CGAL_Nef_polyhedron2 b); +extern CGAL_Nef_polyhedron2 convexhull2(CGAL_Nef_polyhedron2 a); extern CGAL_Poly2 nef2p2(CGAL_Nef_polyhedron2 p); static std::list p2points(CGAL_Poly2 p2) @@ -44,7 +44,7 @@ static std::list p2points(CGAL_Poly2 p2) return points; } -CGAL_Nef_polyhedron2 convexhull2(CGAL_Nef_polyhedron2 a, CGAL_Nef_polyhedron2 b) +CGAL_Nef_polyhedron2 convexhull2(CGAL_Nef_polyhedron2 a) { CGAL_Poly2 ap = nef2p2(a); std::list points = p2points(ap), result; diff --git a/testdata/scad/convex_hull.scad b/testdata/scad/convex_hull.scad index 7db6817..0f6c073 100644 --- a/testdata/scad/convex_hull.scad +++ b/testdata/scad/convex_hull.scad @@ -4,5 +4,4 @@ hull() { circle(10); circle(10); } - square(2); } -- cgit v0.10.1 From ded6d3b1b45c965ec5da81befe1b0d2c7ae31209 Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Sat, 9 Apr 2011 20:27:08 +0100 Subject: Convex hull now works properly with multiple children that do not neccecerily need to be touching. diff --git a/src/cgaladv.cc b/src/cgaladv.cc index 45a3bdd..6301cd3 100644 --- a/src/cgaladv.cc +++ b/src/cgaladv.cc @@ -34,7 +34,7 @@ #ifdef ENABLE_CGAL extern CGAL_Nef_polyhedron3 minkowski3(CGAL_Nef_polyhedron3 a, CGAL_Nef_polyhedron3 b); extern CGAL_Nef_polyhedron2 minkowski2(CGAL_Nef_polyhedron2 a, CGAL_Nef_polyhedron2 b); -extern CGAL_Nef_polyhedron2 convexhull2(CGAL_Nef_polyhedron2 a); +extern CGAL_Nef_polyhedron2 convexhull2(std::list a); #endif enum cgaladv_type_e { @@ -184,19 +184,24 @@ CGAL_Nef_polyhedron CgaladvNode::render_cgal_nef_polyhedron() const if (type == HULL) { + std::list polys; + bool all2d = true; foreach(AbstractNode * v, children) { if (v->modinst->tag_background) continue; N = v->render_cgal_nef_polyhedron(); if (N.dim == 3) { - + //polys.push_back(tmp.p3); + all2d=false; } if (N.dim == 2) { - N.p2 = convexhull2(N.p2); + polys.push_back(N.p2); } v->progress_report(); - break; } + + if(all2d) + N.p2 = convexhull2(polys); } cgal_nef_cache.insert(cache_id, new cgal_nef_cache_entry(N), N.weight()); diff --git a/src/cgaladv_convexhull2.cc b/src/cgaladv_convexhull2.cc index 1914954..e1e466d 100644 --- a/src/cgaladv_convexhull2.cc +++ b/src/cgaladv_convexhull2.cc @@ -29,31 +29,27 @@ #include "cgal.h" #include -extern CGAL_Nef_polyhedron2 convexhull2(CGAL_Nef_polyhedron2 a); +extern CGAL_Nef_polyhedron2 convexhull2(std::list a); extern CGAL_Poly2 nef2p2(CGAL_Nef_polyhedron2 p); -static std::list p2points(CGAL_Poly2 p2) +CGAL_Nef_polyhedron2 convexhull2(std::list a) { - std::list points; - for (int j = 0; j < p2.size(); j++) { - double x = to_double(p2[j].x()), y = to_double(p2[j].y()); - CGAL_Nef_polyhedron2::Point p = - CGAL_Nef_polyhedron2::Point(x, y); - points.push_back(p); + std::list points; + + std::list::iterator i; + for(i=a.begin(); i!=a.end(); i++) { + CGAL_Poly2 ap=nef2p2(*i); + for (int j=0;j points = p2points(ap), result; - - CGAL::convex_hull_2(points.begin(), points.end(), - std::back_inserter(result)); - std::cout << result.size() << " points on the convex hull" << std::endl; - return CGAL_Nef_polyhedron2(result.begin(), - result.end(), CGAL_Nef_polyhedron2::INCLUDED); + std::list result; + CGAL::convex_hull_2(points.begin(),points.end(),std::back_inserter(result)); + + return CGAL_Nef_polyhedron2(result.begin(),result.end(),CGAL_Nef_polyhedron2::INCLUDED); } #endif -- cgit v0.10.1 From cdc4574a9c1d6be012eab8e49b55e4472a71d563 Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Sun, 10 Apr 2011 10:10:42 +0100 Subject: Updated test, you no longer need to union the ojects passed to hull. diff --git a/testdata/scad/convex_hull.scad b/testdata/scad/convex_hull.scad index 0f6c073..8255417 100644 --- a/testdata/scad/convex_hull.scad +++ b/testdata/scad/convex_hull.scad @@ -1,7 +1,5 @@ hull() { - union() { translate([15,10,0]) circle(10); circle(10); - } } -- cgit v0.10.1 From 5739d33cd5c801d47b6d6e4b753811b13639bfbd Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sun, 10 Apr 2011 17:41:32 +0200 Subject: Bugfix: Handling of input-file was not working diff --git a/src/openscad.cc b/src/openscad.cc index bc1d845..aa0188c 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -144,15 +144,21 @@ int main(int argc, char **argv) ("o", po::value(), "off-file") ("x", po::value(), "dxf-file") ("d", po::value(), "deps-file") - ("m", po::value(), "make file") - ("D", po::value >(), "var=val") - ; + ("m", po::value(), "makefile") + ("D", po::value >(), "var=val"); + + po::options_description hidden("Hidden options"); + hidden.add_options() + ("input-file", po::value< vector >(), "input file"); po::positional_options_description p; p.add("input-file", -1); + po::options_description all_options; + all_options.add(desc).add(hidden); + po::variables_map vm; - po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm); + po::store(po::command_line_parser(argc, argv).options(all_options).positional(p).run(), vm); // po::notify(vm); if (vm.count("help")) help(argv[0]); @@ -348,7 +354,7 @@ int main(int argc, char **argv) new MainWindow(qfilename); vector inputFiles; if (vm.count("input-file")) { - inputFiles = vm["input-files"].as >(); + inputFiles = vm["input-file"].as >(); for (vector::const_iterator i = inputFiles.begin()+1; i != inputFiles.end(); i++) { new MainWindow(QFileInfo(original_path, i->c_str()).absoluteFilePath()); } -- cgit v0.10.1 From 0c1b1f4e2243696cbec0427c41182c5529a6c55f Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sun, 10 Apr 2011 17:41:54 +0200 Subject: Removed excessive debug output diff --git a/src/cgaladv_minkowski2.cc b/src/cgaladv_minkowski2.cc index d03943c..fb8dd4b 100644 --- a/src/cgaladv_minkowski2.cc +++ b/src/cgaladv_minkowski2.cc @@ -31,8 +31,6 @@ #include "grid.h" #include "cgal.h" -#if 1 - #include #include @@ -62,9 +60,9 @@ void print_polygon (const CGAL::Polygon_2& P) template void print_polygon_with_holes (const CGAL::Polygon_with_holes_2& pwh) { if (! pwh.is_unbounded()) { - std::cout << "{ Outer boundary = "; - print_polygon (pwh.outer_boundary()); - } else + std::cout << "{ Outer boundary = "; + print_polygon (pwh.outer_boundary()); + } else std::cout << "{ Unbounded polygon." << std::endl; typename CGAL::Polygon_with_holes_2::Hole_const_iterator hit; @@ -92,23 +90,20 @@ static Poly2 nef2p2(CGAL_Nef_polyhedron2 p) for (fci_t fit = E.faces_begin(), fend = E.faces_end(); fit != fend; ++fit) { - std::cout << "face " << ((E.mark(fit))? "is part of polygon" : "is not part of polygon") << std::endl; - if (!E.mark(fit)) { - continue; - } + if (!E.mark(fit)) { + continue; + } //if (fit != E.faces_begin()) { if (points.size() != 0) { PRINT("WARNING: minkowski() is not implemented for 2d objects with holes!"); - break; + break; } heafcc_t fcirc(E.halfedge(fit)), fend(fcirc); CGAL_For_all(fcirc, fend) { - //std::cout << "fcirc,fend " << std::endl; if (E.is_standard(E.target(fcirc))) { Explorer::Point ep = E.point(E.target(fcirc)); double x = to_double(ep.x()), y = to_double(ep.y()); - std::cout << "point " << ep << std::endl; grid.align(x, y); points.push_back(K2::Point_2(x, y)); } @@ -117,9 +112,10 @@ static Poly2 nef2p2(CGAL_Nef_polyhedron2 p) return Poly2(points.begin(), points.end()); } + static CGAL_Nef_polyhedron2 p2nef2(Poly2 p2) { std::list points; - for (int j = 0; j < p2.size(); j++) { + for (size_t j = 0; j < p2.size(); j++) { double x = to_double(p2[j].x()); double y = to_double(p2[j].y()); CGAL_Nef_polyhedron2::Point p = CGAL_Nef_polyhedron2::Point(x, y); @@ -131,33 +127,20 @@ static CGAL_Nef_polyhedron2 p2nef2(Poly2 p2) { CGAL_Nef_polyhedron2 minkowski2(CGAL_Nef_polyhedron2 a, CGAL_Nef_polyhedron2 b) { Poly2 ap = nef2p2(a), bp = nef2p2(b); - std::cout << "ap = "; print_polygon(ap); - std::cout << "bp = "; print_polygon(bp); - - if (ap.size() == 0) { - PRINT("WARNING: minkowski() could not get any points from object 1!"); - return CGAL_Nef_polyhedron2(); - } else if (bp.size() == 0) { - PRINT("WARNING: minkowski() could not get any points from object 2!"); - return CGAL_Nef_polyhedron2(); - } else { - Poly2h x = minkowski_sum_2(ap, bp); - std::cout << "result = "; print_polygon_with_holes(x); - - // Make a CGAL_Nef_polyhedron2 out of just the boundary for starters - return p2nef2(x.outer_boundary()); - } -} -#else - -CGAL_Nef_polyhedron2 minkowski2(CGAL_Nef_polyhedron2, CGAL_Nef_polyhedron2) -{ - PRINT("WARNING: minkowski() is not implemented yet for 2d objects!"); - return CGAL_Nef_polyhedron2(); + if (ap.size() == 0) { + PRINT("WARNING: minkowski() could not get any points from object 1!"); + return CGAL_Nef_polyhedron2(); + } else if (bp.size() == 0) { + PRINT("WARNING: minkowski() could not get any points from object 2!"); + return CGAL_Nef_polyhedron2(); + } else { + Poly2h x = minkowski_sum_2(ap, bp); + + // Make a CGAL_Nef_polyhedron2 out of just the boundary for starters + return p2nef2(x.outer_boundary()); + } } #endif -#endif - -- cgit v0.10.1 From 06cc8b1d585e03d47dfb20014c5281c43d806f1b Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Mon, 11 Apr 2011 01:47:06 +0200 Subject: indentation diff --git a/src/cgaladv.cc b/src/cgaladv.cc index 6301cd3..0dc70ad 100644 --- a/src/cgaladv.cc +++ b/src/cgaladv.cc @@ -183,25 +183,24 @@ CGAL_Nef_polyhedron CgaladvNode::render_cgal_nef_polyhedron() const if (type == HULL) { - - std::list polys; - bool all2d = true; - foreach(AbstractNode * v, children) { - if (v->modinst->tag_background) + std::list polys; + bool all2d = true; + foreach(AbstractNode * v, children) { + if (v->modinst->tag_background) continue; - N = v->render_cgal_nef_polyhedron(); - if (N.dim == 3) { + N = v->render_cgal_nef_polyhedron(); + if (N.dim == 3) { //polys.push_back(tmp.p3); all2d=false; - } - if (N.dim == 2) { + } + if (N.dim == 2) { polys.push_back(N.p2); + } + v->progress_report(); } - v->progress_report(); - } - if(all2d) - N.p2 = convexhull2(polys); + if (all2d) + N.p2 = convexhull2(polys); } cgal_nef_cache.insert(cache_id, new cgal_nef_cache_entry(N), N.weight()); diff --git a/src/cgaladv_convexhull2.cc b/src/cgaladv_convexhull2.cc index e1e466d..448dd4b 100644 --- a/src/cgaladv_convexhull2.cc +++ b/src/cgaladv_convexhull2.cc @@ -34,22 +34,22 @@ extern CGAL_Poly2 nef2p2(CGAL_Nef_polyhedron2 p); CGAL_Nef_polyhedron2 convexhull2(std::list a) { - std::list points; + std::list points; - std::list::iterator i; - for(i=a.begin(); i!=a.end(); i++) { - CGAL_Poly2 ap=nef2p2(*i); - for (int j=0;j::iterator i; + for (i=a.begin(); i!=a.end(); i++) { + CGAL_Poly2 ap=nef2p2(*i); + for (size_t j=0;j result; - CGAL::convex_hull_2(points.begin(),points.end(),std::back_inserter(result)); + std::list result; + CGAL::convex_hull_2(points.begin(),points.end(),std::back_inserter(result)); - return CGAL_Nef_polyhedron2(result.begin(),result.end(),CGAL_Nef_polyhedron2::INCLUDED); + return CGAL_Nef_polyhedron2(result.begin(),result.end(),CGAL_Nef_polyhedron2::INCLUDED); } #endif -- cgit v0.10.1 From 3fbadddeacdf708875df0fe4a2c5d410a263ca51 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Mon, 11 Apr 2011 01:48:09 +0200 Subject: Added warning about missing 3D version of hull() diff --git a/src/cgaladv.cc b/src/cgaladv.cc index 0dc70ad..66cefa9 100644 --- a/src/cgaladv.cc +++ b/src/cgaladv.cc @@ -191,6 +191,7 @@ CGAL_Nef_polyhedron CgaladvNode::render_cgal_nef_polyhedron() const N = v->render_cgal_nef_polyhedron(); if (N.dim == 3) { //polys.push_back(tmp.p3); + PRINT("WARNING: hull() is not implemented yet for 3D objects!"); all2d=false; } if (N.dim == 2) { -- cgit v0.10.1 From b6e9179e4888bd52b2881275011e071b59fe1df9 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Mon, 11 Apr 2011 01:51:16 +0200 Subject: misc. fixes: Now supports hull() in OpenCSG mode, dump supports hull(), convexity not needed for hull() diff --git a/src/cgaladv.cc b/src/cgaladv.cc index 66cefa9..dd797fd 100644 --- a/src/cgaladv.cc +++ b/src/cgaladv.cc @@ -105,10 +105,6 @@ AbstractNode *CgaladvModule::evaluate(const Context *ctx, const ModuleInstantiat level = c.lookup_variable("level", true); } - if (type == HULL) { - convexity = c.lookup_variable("convexity", true); - } - node->convexity = (int)convexity.num; node->path = path; node->subdiv_type = subdiv_type.text; @@ -222,6 +218,9 @@ CSGTerm *CgaladvNode::render_csg_term(double m[20], QVector *highlight if (type == SUBDIV) return render_csg_term_from_nef(m, highlights, background, "subdiv", this->convexity); + if (type == HULL) + return render_csg_term_from_nef(m, highlights, background, "hull", this->convexity); + return NULL; } @@ -229,7 +228,7 @@ CSGTerm *CgaladvNode::render_csg_term(double m[20], QVector *highlight CSGTerm *CgaladvNode::render_csg_term(double m[20], QVector *highlights, QVector *background) const { - PRINT("WARNING: Found minkowski(), glide() or subdiv() statement but compiled without CGAL support!"); + PRINT("WARNING: Found minkowski(), glide(), subdiv() or hull() statement but compiled without CGAL support!"); return NULL; } @@ -247,6 +246,8 @@ QString CgaladvNode::dump(QString indent) const } if (type == SUBDIV) text.sprintf("subdiv(level = %d, convexity = %d) {\n", this->level, this->convexity); + if (type == HULL) + text.sprintf("hull() {\n"); foreach (AbstractNode *v, this->children) text += v->dump(indent + QString("\t")); text += indent + "}\n"; -- cgit v0.10.1 From 46c3ef4ed427ec2b4dcbd089936ff0f30c9b7d30 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Mon, 11 Apr 2011 01:52:26 +0200 Subject: Added hull() and 2D minkowski diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 3cfb955..9995180 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -1,8 +1,9 @@ OpenSCAD 2011.XX ================ -o Added rands() function -o Added sign() function +o Added hull() for convex hulls +o minkowski() now supports 2D objects +o Added functions: rands(), sign() o Now supports escaping of the following characters in strings: \n, \t, \r, \\, \" o Support nested includes o Improved parsing of numbers -- cgit v0.10.1 From a3cfe9e6d76f41cbd13711d1bc3843afe3d14f2d Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Tue, 12 Apr 2011 17:48:57 +0200 Subject: Added note about 2D only for hull() diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 9995180..352fa67 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -1,7 +1,7 @@ OpenSCAD 2011.XX ================ -o Added hull() for convex hulls +o Added hull() for convex hulls (2D object only) o minkowski() now supports 2D objects o Added functions: rands(), sign() o Now supports escaping of the following characters in strings: \n, \t, \r, \\, \" -- cgit v0.10.1 From 4853111f828fbbb9445fbf9d72f1e2c73930611f Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Tue, 12 Apr 2011 20:43:57 +0200 Subject: Added bug diff --git a/doc/TODO.txt b/doc/TODO.txt index cca4a2a..88257cb 100644 --- a/doc/TODO.txt +++ b/doc/TODO.txt @@ -104,7 +104,7 @@ o Editor wishlist - C-c/C-v should work on the focused widget, not always in the editor o Computation - - Run CGAL rendering in a backgroud thread + - Run CGAL rendering in a background thread - Enable viewing/editing while rendering - Progress: Call progresswidget more often to avoid app hanging for multiple seconds (i.e. make cancel button more responsive) @@ -167,6 +167,8 @@ o Misc - Add 'lines' object type for non-solid 2d drawings - Is there a reason why modules like echo, empty if, empty for loop returns an empty AbstractNode instead of being ignored? + - Bug: Using the background operator (%) on the only object in a scene triggers a + CSG error: No top level object found o Grammar - dim->name -> dim->label - A random(seed) function -- cgit v0.10.1 From df5b74216918aecb768463bf7c9ec0e26fbd4525 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Tue, 12 Apr 2011 21:51:45 +0200 Subject: bugfix: Pass short options to boost program_options diff --git a/src/openscad.cc b/src/openscad.cc index aa0188c..4b6cc1b 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -140,12 +140,12 @@ int main(int argc, char **argv) desc.add_options() ("help,h", "help message") ("version,v", "print the version") - ("s", po::value(), "stl-file") - ("o", po::value(), "off-file") - ("x", po::value(), "dxf-file") - ("d", po::value(), "deps-file") - ("m", po::value(), "makefile") - ("D", po::value >(), "var=val"); + (",s", po::value(), "stl-file") + (",o", po::value(), "off-file") + (",x", po::value(), "dxf-file") + (",d", po::value(), "deps-file") + (",m", po::value(), "makefile") + (",D", po::value >(), "var=val"); po::options_description hidden("Hidden options"); hidden.add_options() -- cgit v0.10.1 From 0545f0ef8100d1efc588e8fb97ae75d9dee8ca8f Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Tue, 12 Apr 2011 22:37:36 +0200 Subject: Run some tests diff --git a/doc/release-checklist.txt b/doc/release-checklist.txt index d0e1174..419b899 100644 --- a/doc/release-checklist.txt +++ b/doc/release-checklist.txt @@ -21,6 +21,8 @@ o build binaries - release-linux.sh Windows: FIXME 32 vs. 64 bit +o FIXME: Run some tests + o Set back version: release-linux.sh, publish-macosx.sh, FIXME: Windows o Upload -- cgit v0.10.1 From c8dd96b76f672d5f99ceb63db2155447bbaa868b Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Tue, 12 Apr 2011 22:37:49 +0200 Subject: Must specify both long and short options diff --git a/src/openscad.cc b/src/openscad.cc index 4b6cc1b..bf22246 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -140,12 +140,12 @@ int main(int argc, char **argv) desc.add_options() ("help,h", "help message") ("version,v", "print the version") - (",s", po::value(), "stl-file") - (",o", po::value(), "off-file") - (",x", po::value(), "dxf-file") - (",d", po::value(), "deps-file") - (",m", po::value(), "makefile") - (",D", po::value >(), "var=val"); + ("s,s", po::value(), "stl-file") + ("o,o", po::value(), "off-file") + ("x,x", po::value(), "dxf-file") + ("d,d", po::value(), "deps-file") + ("m,m", po::value(), "makefile") + ("D,D", po::value >(), "var=val"); po::options_description hidden("Hidden options"); hidden.add_options() -- cgit v0.10.1