Added support for 3D object in the hull() module

stl_dim
Marius Kintel 2011-11-23 16:11:48 +01:00
parent 077a914ac6
commit 73092dd4c8
7 changed files with 52 additions and 50 deletions

View File

@ -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)

View File

@ -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;
}

View File

@ -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);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -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, 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);
}
}
}
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);
}
}
}
hull();
hull();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 12 KiB