diff options
author | Marius Kintel <marius@kintel.net> | 2011-11-23 15:11:55 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2011-11-23 15:11:55 (GMT) |
commit | 25fa1984dbeed2b294e1f04d833fa5f7bd66fcad (patch) | |
tree | d419950c7fbec37e35d6c1b4c640d181ddf017c6 | |
parent | 1969396b9d1ec34778f9568652b0864f64365a23 (diff) | |
parent | 73092dd4c89829bb0a7fa0a026addd2d54171cbb (diff) |
Merge branch 'hull3'
-rw-r--r-- | RELEASE_NOTES | 1 | ||||
-rw-r--r-- | src/CGALEvaluator.cc | 29 | ||||
-rw-r--r-- | testdata/scad/features/hull3-tests.scad | 34 | ||||
-rw-r--r-- | tests/regression/cgalpngtest/hull3-tests-expected.png | bin | 4408 -> 11978 bytes | |||
-rw-r--r-- | tests/regression/dumptest/hull3-tests-expected.txt | 34 | ||||
-rw-r--r-- | tests/regression/opencsgtest/hull3-tests-expected.png | bin | 4408 -> 12471 bytes | |||
-rw-r--r-- | tests/regression/throwntogethertest/hull3-tests-expected.png | bin | 4408 -> 12471 bytes |
7 files changed, 50 insertions, 48 deletions
diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 2de956d..f25de79 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -3,6 +3,7 @@ OpenSCAD 20xx.yy Features: o The MCAD library is now bundled with OpenSCAD +o hull() Now supports 3D objects o Added import and export of the OFF file format o New import() statement reads the correct file format based on the filename extension (.stl, .dxf and .off is supported) diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index 3646af2..7921b85 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -18,6 +18,7 @@ #include "cgalutils.h" #include <CGAL/assertions_behaviour.h> #include <CGAL/exceptions.h> +#include <CGAL/convex_hull_3.h> #include <string> #include <map> @@ -29,6 +30,7 @@ #include <boost/foreach.hpp> #include <boost/unordered_map.hpp> +#include <boost/bind.hpp> CGAL_Nef_polyhedron CGALEvaluator::evaluateCGALMesh(const AbstractNode &node) { @@ -114,25 +116,40 @@ CGAL_Nef_polyhedron CGALEvaluator::applyHull(const CgaladvNode &node) { CGAL_Nef_polyhedron N; std::list<CGAL_Nef_polyhedron2*> polys; - bool all2d = true; + std::list<CGAL_Polyhedron::Vertex::Point_3> points; + int dim = 0; BOOST_FOREACH(const ChildItem &item, this->visitedchildren[node.index()]) { const AbstractNode *chnode = item.first; const CGAL_Nef_polyhedron &chN = item.second; // FIXME: Don't use deep access to modinst members if (chnode->modinst->tag_background) continue; - if (chN.dim == 2) { + if (dim == 0) { + dim = chN.dim; + } + else if (dim != chN.dim) { + PRINT("WARNING: hull() does not support mixing 2D and 3D objects."); + continue; + } + if (dim == 2) { polys.push_back(chN.p2.get()); } - else if (chN.dim == 3) { - PRINT("WARNING: hull() is not implemented yet for 3D objects!"); - all2d = false; + else if (dim == 3) { + CGAL_Polyhedron P; + chN.p3->convert_to_Polyhedron(P); + std::transform(P.vertices_begin(), P.vertices_end(), std::back_inserter(points), + boost::bind(static_cast<const CGAL_Polyhedron::Vertex::Point_3&(CGAL_Polyhedron::Vertex::*)() const>(&CGAL_Polyhedron::Vertex::point), _1)); } chnode->progress_report(); } - if (all2d) { + if (dim == 2) { N = CGAL_Nef_polyhedron(convexhull2(polys)); } + else if (dim == 3) { + CGAL_Polyhedron P; + CGAL::convex_hull_3(points.begin(), points.end(), P); + N = CGAL_Nef_polyhedron(new CGAL_Nef_polyhedron3(P)); + } return N; } diff --git a/testdata/scad/features/hull3-tests.scad b/testdata/scad/features/hull3-tests.scad index 2bd7d73..12c8a11 100644 --- a/testdata/scad/features/hull3-tests.scad +++ b/testdata/scad/features/hull3-tests.scad @@ -1,27 +1,17 @@ -// 3d not currently implemented -module convex3dSimple() { - hull() { - translate([15,10]) cylinder(r=10); - cylinder(r=10); - } -} - -// 3d not currently implemented -module convex3dHole() { - hull() { - translate([15,10,0]) cylinder(10); - difference() { - cylinder(10); - cylinder(5); - } - } -} - -translate([0,40,0]) convex3dHole(); -translate([40,40,0]) convex3dSimple(); - // Empty hull(); // No children hull() { } +hull() { + cylinder(r=10, h=1); + translate([0,0,10]) cube([5,5,5], center=true); +} + +translate([25,0,0]) hull() { + translate([0,0,10]) cylinder(r=3); + difference() { + cylinder(r=10, h=4, center=true); + cylinder(r=5, h=5, center=true); + } +} diff --git a/tests/regression/cgalpngtest/hull3-tests-expected.png b/tests/regression/cgalpngtest/hull3-tests-expected.png Binary files differindex 50d838c..e34ae89 100644 --- a/tests/regression/cgalpngtest/hull3-tests-expected.png +++ b/tests/regression/cgalpngtest/hull3-tests-expected.png diff --git a/tests/regression/dumptest/hull3-tests-expected.txt b/tests/regression/dumptest/hull3-tests-expected.txt index 831aae2..bde58c9 100644 --- a/tests/regression/dumptest/hull3-tests-expected.txt +++ b/tests/regression/dumptest/hull3-tests-expected.txt @@ -1,26 +1,20 @@ - multmatrix([[1, 0, 0, 0], [0, 1, 0, 40], [0, 0, 1, 0], [0, 0, 0, 1]]) { - group() { - hull() { - multmatrix([[1, 0, 0, 15], [0, 1, 0, 10], [0, 0, 1, 0], [0, 0, 0, 1]]) { - cylinder($fn = 0, $fa = 12, $fs = 1, h = 10, r1 = 1, r2 = 1, center = false); - } - difference() { - cylinder($fn = 0, $fa = 12, $fs = 1, h = 10, r1 = 1, r2 = 1, center = false); - cylinder($fn = 0, $fa = 12, $fs = 1, h = 5, r1 = 1, r2 = 1, center = false); - } - } + hull(); + hull(); + hull() { + cylinder($fn = 0, $fa = 12, $fs = 1, h = 1, r1 = 10, r2 = 10, center = false); + multmatrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 10], [0, 0, 0, 1]]) { + cube(size = [5, 5, 5], center = true); } } - multmatrix([[1, 0, 0, 40], [0, 1, 0, 40], [0, 0, 1, 0], [0, 0, 0, 1]]) { - group() { - hull() { - multmatrix([[1, 0, 0, 15], [0, 1, 0, 10], [0, 0, 1, 0], [0, 0, 0, 1]]) { - cylinder($fn = 0, $fa = 12, $fs = 1, h = 1, r1 = 10, r2 = 10, center = false); - } - cylinder($fn = 0, $fa = 12, $fs = 1, h = 1, r1 = 10, r2 = 10, center = false); + multmatrix([[1, 0, 0, 25], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { + hull() { + multmatrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 10], [0, 0, 0, 1]]) { + cylinder($fn = 0, $fa = 12, $fs = 1, h = 1, r1 = 3, r2 = 3, center = false); + } + difference() { + cylinder($fn = 0, $fa = 12, $fs = 1, h = 4, r1 = 10, r2 = 10, center = true); + cylinder($fn = 0, $fa = 12, $fs = 1, h = 5, r1 = 5, r2 = 5, center = true); } } } - hull(); - hull(); diff --git a/tests/regression/opencsgtest/hull3-tests-expected.png b/tests/regression/opencsgtest/hull3-tests-expected.png Binary files differindex 50d838c..5a363a1 100644 --- a/tests/regression/opencsgtest/hull3-tests-expected.png +++ b/tests/regression/opencsgtest/hull3-tests-expected.png diff --git a/tests/regression/throwntogethertest/hull3-tests-expected.png b/tests/regression/throwntogethertest/hull3-tests-expected.png Binary files differindex 50d838c..5a363a1 100644 --- a/tests/regression/throwntogethertest/hull3-tests-expected.png +++ b/tests/regression/throwntogethertest/hull3-tests-expected.png |