diff options
| -rw-r--r-- | openscad.pro | 33 | ||||
| -rw-r--r-- | src/CGALEvaluator.cc | 82 | ||||
| -rw-r--r-- | src/CGALEvaluator.h | 2 | ||||
| -rw-r--r-- | src/CGAL_Nef_polyhedron.cc (renamed from src/cgal.cc) | 67 | ||||
| -rw-r--r-- | src/CGAL_Nef_polyhedron.h | 31 | ||||
| -rw-r--r-- | src/CGAL_Nef_polyhedron_DxfData.cc (renamed from src/nef2dxf.cc) | 23 | ||||
| -rw-r--r-- | src/PolySetCGALEvaluator.cc | 25 | ||||
| -rw-r--r-- | src/cgal.h | 67 | ||||
| -rw-r--r-- | src/cgaladv.cc | 7 | ||||
| -rw-r--r-- | src/cgaladv_minkowski2.cc | 3 | ||||
| -rw-r--r-- | src/cgaladv_minkowski3.cc | 39 | ||||
| -rw-r--r-- | src/cgalfwd.h | 27 | ||||
| -rw-r--r-- | src/cgalrenderer.cc | 11 | ||||
| -rw-r--r-- | src/cgalrenderer.h | 2 | ||||
| -rw-r--r-- | src/dxfdata.h | 4 | ||||
| -rw-r--r-- | src/export.cc | 15 | ||||
| -rw-r--r-- | src/export.h | 6 | ||||
| -rw-r--r-- | src/mainwin.cc | 42 | ||||
| -rw-r--r-- | src/openscad.cc | 2 | ||||
| -rw-r--r-- | tests/CMakeLists.txt | 14 | ||||
| -rw-r--r-- | tests/cgaltest.cc | 2 | 
21 files changed, 256 insertions, 248 deletions
| diff --git a/openscad.pro b/openscad.pro index deda4d0..8e43102 100644 --- a/openscad.pro +++ b/openscad.pro @@ -119,7 +119,6 @@ FORMS   += src/MainWindow.ui \             src/Preferences.ui  HEADERS += src/renderer.h \ -           src/cgalrenderer.h \             src/ThrownTogetherRenderer.h \             src/CGAL_renderer.h \             src/OGL_helper.h \ @@ -127,7 +126,6 @@ HEADERS += src/renderer.h \             src/MainWindow.h \             src/Preferences.h \             src/builtin.h \ -           src/cgal.h \             src/context.h \             src/csgterm.h \             src/dxfdata.h \ @@ -158,9 +156,7 @@ HEADERS += src/renderer.h \             src/traverser.h \             src/nodecache.h \             src/nodedumper.h \ -           src/CGALEvaluator.h \             src/PolySetEvaluator.h \ -           src/PolySetCGALEvaluator.h \             src/CSGTermEvaluator.h \             src/myqhash.h \             src/Tree.h \ @@ -169,8 +165,6 @@ HEADERS += src/renderer.h \  SOURCES += src/openscad.cc \             src/mainwin.cc \ -           src/cgalrenderer.cc \ -           src/cgal.cc \             src/ThrownTogetherRenderer.cc \             src/glview.cc \             src/export.cc \ @@ -187,9 +181,6 @@ 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 \             src/control.cc \             src/render.cc \ @@ -203,19 +194,33 @@ SOURCES += src/openscad.cc \             src/dxfrotextrude.cc \             src/highlighter.cc \             src/printutils.cc \ -           src/nef2dxf.cc \             src/Preferences.cc \             src/progress.cc \             src/editor.cc \             src/traverser.cc \             src/nodedumper.cc \ -           src/CGALEvaluator.cc \ -           src/PolySetEvaluator.cc \ -           src/PolySetCGALEvaluator.cc \             src/CSGTermEvaluator.cc \             src/qhash.cc \             src/Tree.cc \ -	   src/mathc99.cc +	   src/mathc99.cc \ +           src/PolySetEvaluator.cc + +cgal { +HEADERS += src/cgal.h \ +           src/cgalfwd.h \ +           src/CGALEvaluator.h \ +           src/PolySetCGALEvaluator.h \ +           src/cgalrenderer.h \ +           src/CGAL_Nef_polyhedron.h + +SOURCES += src/CGALEvaluator.cc \ +           src/PolySetCGALEvaluator.cc \ +           src/cgalrenderer.cc \ +           src/CGAL_Nef_polyhedron.cc \ +           src/CGAL_Nef_polyhedron_DxfData.cc \ +	   src/cgaladv_convexhull2.cc \ +           src/cgaladv_minkowski2.cc +}  macx {    HEADERS += src/AppleEvents.h \ diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index 22583a7..c67e1f5 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -10,6 +10,7 @@  #include "dxfdata.h"  #include "dxftess.h" +#include "cgal.h"  #include <CGAL/assertions_behaviour.h>  #include <CGAL/exceptions.h> @@ -46,45 +47,25 @@ void CGALEvaluator::process(CGAL_Nef_polyhedron &target, const CGAL_Nef_polyhedr   		assert(false && "Dimension of Nef polyhedron must be 2 or 3");   	} -	if (target.dim == 2) { -		switch (op) { -		case CGE_UNION: -			target.p2 += src.p2; -			break; -		case CGE_INTERSECTION: -			target.p2 *= src.p2; -			break; -		case CGE_DIFFERENCE: -			target.p2 -= src.p2; -			break; -		case CGE_MINKOWSKI: -			target.p2 = minkowski2(target.p2, src.p2); -			break; -		case CGE_HULL: -			//FIXME: Port convex hull to a binary operator or process it all in the end somehow -			// target.p2 = convexhull2(target.p2, src.p2); -			// target.p2 = convexhull2(polys); -			break; -		} -	} -	else if (target.dim == 3) { -		switch (op) { -		case CGE_UNION: -			target.p3 += src.p3; -			break; -		case CGE_INTERSECTION: -			target.p3 *= src.p3; -			break; -		case CGE_DIFFERENCE: -			target.p3 -= src.p3; -			break; -		case CGE_MINKOWSKI: -			target.p3 = minkowski3(target.p3, src.p3); -			break; -		case CGE_HULL: -			// FIXME: Print warning: hull() not supported in 3D -			break; -		} +	switch (op) { +	case CGE_UNION: +		target += src; +		break; +	case CGE_INTERSECTION: +		target *= src; +		break; +	case CGE_DIFFERENCE: +		target -= src; +		break; +	case CGE_MINKOWSKI: +		target = target.minkowski(src); +		break; +	case CGE_HULL: +		//FIXME: Port convex hull to a binary operator or process it all in the end somehow +		// target.p2 = convexhull2(target.p2, src.p2); +		// target.p2 = convexhull2(polys); +		// FIXME: Print warning: hull() not supported in 3D +		break;  	}  } @@ -191,27 +172,28 @@ Response CGALEvaluator::visit(State &state, const TransformNode &node)  					node.matrix[0], node.matrix[4], node.matrix[12],  					node.matrix[1], node.matrix[5], node.matrix[13], node.matrix[15]); -				DxfData dd(N); -				for (int i=0; i < dd.points.size(); i++) { -					CGAL_Kernel2::Point_2 p = CGAL_Kernel2::Point_2(dd.points[i][0], dd.points[i][1]); +				DxfData *dd = N.convertToDxfData(); +				for (int i=0; i < dd->points.size(); i++) { +					CGAL_Kernel2::Point_2 p = CGAL_Kernel2::Point_2(dd->points[i][0], dd->points[i][1]);  					p = t.transform(p); -					dd.points[i][0] = to_double(p.x()); -					dd.points[i][1] = to_double(p.y()); +					dd->points[i][0] = to_double(p.x()); +					dd->points[i][1] = to_double(p.y());  				}  				PolySet ps;  				ps.is2d = true; -				dxf_tesselate(&ps, &dd, 0, true, false, 0); +				dxf_tesselate(&ps, dd, 0, true, false, 0);  				N = evaluateCGALMesh(ps);  				ps.refcount = 0; +				delete dd;  			}  			else if (N.dim == 3) {  				CGAL_Aff_transformation t(  					node.matrix[0], node.matrix[4], node.matrix[ 8], node.matrix[12],  					node.matrix[1], node.matrix[5], node.matrix[ 9], node.matrix[13],  					node.matrix[2], node.matrix[6], node.matrix[10], node.matrix[14], node.matrix[15]); -				N.p3.transform(t); +				N.p3->transform(t);  			}  			this->cache.insert(this->tree.getString(node), N);  		} @@ -574,9 +556,9 @@ CGAL_Nef_polyhedron CGALEvaluator::evaluateCGALMesh(const PolySet &ps)  				}  			} -			CGAL_Nef_polyhedron2 toNef() +			CGAL_Nef_polyhedron2 *toNef()  			{ -				CGAL_Nef_polyhedron2 N; +				CGAL_Nef_polyhedron2 *N = new CGAL_Nef_polyhedron2;  				QHashIterator< int, QList<int> > it(polygons);  				while (it.hasNext()) { @@ -586,7 +568,7 @@ CGAL_Nef_polyhedron CGALEvaluator::evaluateCGALMesh(const PolySet &ps)  						int p = it.value()[j];  						plist.push_back(points[p]);  					} -					N += CGAL_Nef_polyhedron2(plist.begin(), plist.end(), CGAL_Nef_polyhedron2::INCLUDED); +					*N += CGAL_Nef_polyhedron2(plist.begin(), plist.end(), CGAL_Nef_polyhedron2::INCLUDED);  				}  				return N; @@ -642,7 +624,7 @@ CGAL_Nef_polyhedron CGALEvaluator::evaluateCGALMesh(const PolySet &ps)  #if 0  		std::cout << P;  #endif -		CGAL_Nef_polyhedron3 N(P); +		CGAL_Nef_polyhedron3 *N = new CGAL_Nef_polyhedron3(P);  		return CGAL_Nef_polyhedron(N);      }  		catch (CGAL::Assertion_exception e) { diff --git a/src/CGALEvaluator.h b/src/CGALEvaluator.h index 9a1c88c..85d09c4 100644 --- a/src/CGALEvaluator.h +++ b/src/CGALEvaluator.h @@ -4,7 +4,7 @@  #include "myqhash.h"  #include "visitor.h"  #include "Tree.h" -#include "cgal.h" +#include "CGAL_Nef_polyhedron.h"  #include "PolySetCGALEvaluator.h"  #include <string> diff --git a/src/cgal.cc b/src/CGAL_Nef_polyhedron.cc index 190ebd0..09368da 100644 --- a/src/cgal.cc +++ b/src/CGAL_Nef_polyhedron.cc @@ -1,5 +1,55 @@ +#include "CGAL_Nef_polyhedron.h"  #include "cgal.h"  #include "polyset.h" +#include <CGAL/minkowski_sum_3.h> + +CGAL_Nef_polyhedron& CGAL_Nef_polyhedron::operator+=(const CGAL_Nef_polyhedron &other) +{ +	if (other.dim == 2) { +		(*this->p2) += (*other.p2); +		this->dim = 2; +	} +	if (other.dim == 3) { +		(*this->p3) += (*other.p3); +		this->dim = 3; +	} +	return *this; +} + +CGAL_Nef_polyhedron& CGAL_Nef_polyhedron::operator*=(const CGAL_Nef_polyhedron &other) +{ +	if (other.dim == 2) { +		(*this->p2) *= (*other.p2); +		this->dim = 2; +	} +	if (other.dim == 3) { +		(*this->p3) *= (*other.p3); +		this->dim = 3; +	} +	return *this; +} + +CGAL_Nef_polyhedron& CGAL_Nef_polyhedron::operator-=(const CGAL_Nef_polyhedron &other) +{ +	if (other.dim == 2) { +		(*this->p2) -= (*other.p2); +		this->dim = 2; +	} +	if (other.dim == 3) { +		(*this->p3) -= (*other.p3); +		this->dim = 3; +	} +	return *this; +} + +int CGAL_Nef_polyhedron::weight() const +{ +	if (dim == 2) +		return p2->explorer().number_of_vertices(); +	if (dim == 3) +		return p3->number_of_vertices(); +	return 0; +}  /*!  	Creates a new PolySet and initializes it with the data from this polyhedron @@ -11,7 +61,7 @@ PolySet *CGAL_Nef_polyhedron::convertToPolyset()  {  	PolySet *ps = new PolySet();  	CGAL_Polyhedron P; -	this->p3.convert_to_Polyhedron(P); +	this->p3->convert_to_Polyhedron(P);  	typedef CGAL_Polyhedron::Vertex                                 Vertex;  	typedef CGAL_Polyhedron::Vertex_const_iterator                  VCI; @@ -44,3 +94,18 @@ PolySet *CGAL_Nef_polyhedron::convertToPolyset()  	}  	return ps;  } + +extern CGAL_Nef_polyhedron2 minkowski2(const CGAL_Nef_polyhedron2 &a, const CGAL_Nef_polyhedron2 &b); + +CGAL_Nef_polyhedron &CGAL_Nef_polyhedron::minkowski(const CGAL_Nef_polyhedron &other) +{ +	if (other.dim == 2) { +		(*this->p2) = minkowski2(*this->p2, *other.p2); +		this->dim = 2; +	} +	if (other.dim == 3) { +		(*this->p3) = CGAL::minkowski_sum_3(*this->p3, *other.p3); +		this->dim = 3; +	} +	return *this; +} diff --git a/src/CGAL_Nef_polyhedron.h b/src/CGAL_Nef_polyhedron.h new file mode 100644 index 0000000..0ab72d7 --- /dev/null +++ b/src/CGAL_Nef_polyhedron.h @@ -0,0 +1,31 @@ +#ifndef CGAL_NEF_POLYHEDRON_H_ +#define CGAL_NEF_POLYHEDRON_H_ + +#ifdef ENABLE_CGAL + +#include "cgalfwd.h" + +class CGAL_Nef_polyhedron +{ +public: +	CGAL_Nef_polyhedron() : dim(0) {} +	CGAL_Nef_polyhedron(CGAL_Nef_polyhedron2 *p) : dim(2), p2(p) {} +	CGAL_Nef_polyhedron(CGAL_Nef_polyhedron3 *p) : dim(3), p3(p) { } +	~CGAL_Nef_polyhedron() {} + +	CGAL_Nef_polyhedron &operator+=(const CGAL_Nef_polyhedron &other); +	CGAL_Nef_polyhedron &operator*=(const CGAL_Nef_polyhedron &other); +	CGAL_Nef_polyhedron &operator-=(const CGAL_Nef_polyhedron &other); +	CGAL_Nef_polyhedron &minkowski(const CGAL_Nef_polyhedron &other); +	int weight() const; +	class PolySet *convertToPolyset(); +	class DxfData *convertToDxfData() const; + +	int dim; +	CGAL_Nef_polyhedron2 *p2; +	CGAL_Nef_polyhedron3 *p3; +}; + +#endif /* ENABLE_CGAL */ + +#endif diff --git a/src/nef2dxf.cc b/src/CGAL_Nef_polyhedron_DxfData.cc index cbefa9c..4bfb205 100644 --- a/src/nef2dxf.cc +++ b/src/CGAL_Nef_polyhedron_DxfData.cc @@ -26,19 +26,21 @@  #include "dxfdata.h"  #include "grid.h" +#include "CGAL_Nef_polyhedron.h"  #include "cgal.h"  #ifdef ENABLE_CGAL -DxfData::DxfData(const struct CGAL_Nef_polyhedron &N) +DxfData *CGAL_Nef_polyhedron::convertToDxfData() const  { -	assert(N.dim == 2); +	assert(this->dim == 2); +	DxfData *dxfdata = new DxfData();  	Grid2d<int> grid(GRID_COARSE);  	typedef CGAL_Nef_polyhedron2::Explorer Explorer;  	typedef Explorer::Face_const_iterator fci_t;  	typedef Explorer::Halfedge_around_face_const_circulator heafcc_t; -	Explorer E = N.p2.explorer(); +	Explorer E = this->p2->explorer();  	for (fci_t fit = E.faces_begin(), facesend = E.faces_end(); fit != facesend; ++fit)  	{ @@ -52,26 +54,27 @@ DxfData::DxfData(const struct CGAL_Nef_polyhedron &N)  				if (grid.has(x, y)) {  					this_point = grid.align(x, y);  				} else { -					this_point = grid.align(x, y) = points.size(); -					points.append(Vector2d(x, y)); +					this_point = grid.align(x, y) = dxfdata->points.size(); +					dxfdata->points.append(Vector2d(x, y));  				}  				if (first_point < 0) { -					paths.append(Path()); +					dxfdata->paths.append(DxfData::Path());  					first_point = this_point;  				}  				if (this_point != last_point) { -					paths.last().points.append(&points[this_point]); +					dxfdata->paths.last().points.append(&dxfdata->points[this_point]);  					last_point = this_point;  				}  			}  		}  		if (first_point >= 0) { -			paths.last().is_closed = 1; -			paths.last().points.append(&points[first_point]); +			dxfdata->paths.last().is_closed = 1; +			dxfdata->paths.last().points.append(&dxfdata->points[first_point]);  		}  	} -	fixup_path_direction(); +	dxfdata->fixup_path_direction(); +	return dxfdata;  }  #endif // ENABLE_CGAL diff --git a/src/PolySetCGALEvaluator.cc b/src/PolySetCGALEvaluator.cc index a914a62..7e7e528 100644 --- a/src/PolySetCGALEvaluator.cc +++ b/src/PolySetCGALEvaluator.cc @@ -1,4 +1,5 @@  #include "PolySetCGALEvaluator.h" +#include "cgal.h"  #include "polyset.h"  #include "CGALEvaluator.h"  #include "projectionnode.h" @@ -67,8 +68,8 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node, Abstr  		cube->unlink();  		// N.p3 *= CGAL_Nef_polyhedron3(CGAL_Plane(0, 0, 1, 0), CGAL_Nef_polyhedron3::INCLUDED); -		N.p3 *= Ncube.p3; -		if (!N.p3.is_simple()) { +		N *= Ncube; +		if (!N.p3->is_simple()) {  			PRINTF("WARNING: Body of projection(cut = true) isn't valid 2-manifold! Modify your design..");  			goto cant_project_non_simple_polyhedron;  		} @@ -99,7 +100,7 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node, Abstr  	}  	else  	{ -		if (!N.p3.is_simple()) { +		if (!N.p3->is_simple()) {  			PRINTF("WARNING: Body of projection(cut = false) isn't valid 2-manifold! Modify your design..");  			goto cant_project_non_simple_polyhedron;  		} @@ -144,13 +145,13 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node, Abstr  				else  					plist.push_back(p);  			} -			np.p2 += CGAL_Nef_polyhedron2(plist.begin(), plist.end(), -					CGAL_Nef_polyhedron2::INCLUDED); +			(*np.p2) += CGAL_Nef_polyhedron2(plist.begin(), plist.end(), CGAL_Nef_polyhedron2::INCLUDED);  		} -		DxfData dxf(np); -		dxf_tesselate(ps, &dxf, 0, true, false, 0); -		dxf_border_to_ps(ps, &dxf); +		DxfData *dxf = np.convertToDxfData(); +		dxf_tesselate(ps, dxf, 0, true, false, 0); +		dxf_border_to_ps(ps, dxf);  		ps3->unlink(); +		delete dxf;  	}  cant_project_non_simple_polyhedron: @@ -246,10 +247,10 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const DxfLinearExtrudeNode &node,  		N.dim = 2;  		foreach (AbstractNode * v, node.getChildren()) {  			if (v->modinst->tag_background) continue; -			N.p2 += this->cgalevaluator.evaluateCGALMesh(*v).p2; +			N += this->cgalevaluator.evaluateCGALMesh(*v);  		} -		dxf = new DxfData(N); +		dxf = N.convertToDxfData();;  	} else {  		dxf = new DxfData(node.fn, node.fs, node.fa, node.filename, node.layername, node.origin_x, node.origin_y, node.scale);  	} @@ -337,10 +338,10 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const DxfRotateExtrudeNode &node,  		N.dim = 2;  		foreach (AbstractNode * v, node.getChildren()) {  			if (v->modinst->tag_background) continue; -			N.p2 += this->cgalevaluator.evaluateCGALMesh(*v).p2; +			N += this->cgalevaluator.evaluateCGALMesh(*v);  		} -		dxf = new DxfData(N); +		dxf = N.convertToDxfData();  	} else {  		dxf = new DxfData(node.fn, node.fs, node.fa, node.filename, node.layername, node.origin_x, node.origin_y, node.scale);  	} @@ -31,73 +31,6 @@ typedef CGAL::Polyhedron_3<CGAL_Kernel3> CGAL_Polyhedron;  typedef CGAL_Polyhedron::HalfedgeDS CGAL_HDS;  typedef CGAL::Polyhedron_incremental_builder_3<CGAL_HDS> CGAL_Polybuilder; -struct CGAL_Nef_polyhedron -{ -	int dim; -	CGAL_Nef_polyhedron2 p2; -	CGAL_Nef_polyhedron3 p3; - -	CGAL_Nef_polyhedron() { -		dim = 0; -	} - -	CGAL_Nef_polyhedron(const CGAL_Nef_polyhedron2 &p) { -		dim = 2; -		p2 = p; -	} - -	CGAL_Nef_polyhedron(const CGAL_Nef_polyhedron3 &p) { -		dim = 3; -		p3 = p; -	} - -	CGAL_Nef_polyhedron& operator+=(const CGAL_Nef_polyhedron &other) { -		if (other.dim == 2) { -			this->p2 += other.p2; -			this->dim = 2; -		} -		if (other.dim == 3) { -			this->p3 += other.p3; -			this->dim = 3; -		} -		return *this; -	} - -	CGAL_Nef_polyhedron& operator*=(const CGAL_Nef_polyhedron &other) { -		if (other.dim == 2) { -			this->p2 *= other.p2; -			this->dim = 2; -		} -		if (other.dim == 3) { -			this->p3 *= other.p3; -			this->dim = 3; -		} -		return *this; -	} - -	CGAL_Nef_polyhedron& operator-=(const CGAL_Nef_polyhedron &other) { -		if (other.dim == 2) { -			this->p2 -= other.p2; -			this->dim = 2; -		} -		if (other.dim == 3) { -			this->p3 -= other.p3; -			this->dim = 3; -		} -		return *this; -	} - -	int weight() { -		if (dim == 2) -			return p2.explorer().number_of_vertices(); -		if (dim == 3) -			return p3.number_of_vertices(); -		return 0; -	} - -	class PolySet *convertToPolyset(); -}; -  #endif /* ENABLE_CGAL */  #endif diff --git a/src/cgaladv.cc b/src/cgaladv.cc index 6e26713..5b2e5df 100644 --- a/src/cgaladv.cc +++ b/src/cgaladv.cc @@ -29,17 +29,10 @@  #include "context.h"  #include "builtin.h"  #include "printutils.h" -#include "cgal.h"  #include "visitor.h"  #include <sstream>  #include <assert.h> -#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(std::list<CGAL_Nef_polyhedron2> a); -#endif -  enum cgaladv_type_e {  	MINKOWSKI,  	GLIDE, diff --git a/src/cgaladv_minkowski2.cc b/src/cgaladv_minkowski2.cc index b722708..2d64d16 100644 --- a/src/cgaladv_minkowski2.cc +++ b/src/cgaladv_minkowski2.cc @@ -34,7 +34,6 @@  #include <CGAL/minkowski_sum_2.h> -extern CGAL_Nef_polyhedron2 minkowski2(CGAL_Nef_polyhedron2 a, CGAL_Nef_polyhedron2 b);  extern CGAL_Poly2 nef2p2(CGAL_Nef_polyhedron2 p);  //----------------------------------------------------------------------------- @@ -120,7 +119,7 @@ static CGAL_Nef_polyhedron2 p2nef2(CGAL_Poly2 p2) {    return CGAL_Nef_polyhedron2(points.begin(), points.end(), CGAL_Nef_polyhedron2::INCLUDED);  } -CGAL_Nef_polyhedron2 minkowski2(CGAL_Nef_polyhedron2 a, CGAL_Nef_polyhedron2 b) +CGAL_Nef_polyhedron2 minkowski2(const CGAL_Nef_polyhedron2 &a, const CGAL_Nef_polyhedron2 &b)  {  	CGAL_Poly2 ap = nef2p2(a), bp = nef2p2(b); diff --git a/src/cgaladv_minkowski3.cc b/src/cgaladv_minkowski3.cc deleted file mode 100644 index f12ce21..0000000 --- a/src/cgaladv_minkowski3.cc +++ /dev/null @@ -1,39 +0,0 @@ -/* - *  OpenSCAD (www.openscad.org) - *  Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and - *                          Marius Kintel <marius@kintel.net> - * - *  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 <CGAL/minkowski_sum_3.h> - -extern CGAL_Nef_polyhedron3 minkowski3(CGAL_Nef_polyhedron3 a, CGAL_Nef_polyhedron3 b); - -CGAL_Nef_polyhedron3 minkowski3(CGAL_Nef_polyhedron3 a, CGAL_Nef_polyhedron3 b) -{ -	return CGAL::minkowski_sum_3(a, b); -} - -#endif diff --git a/src/cgalfwd.h b/src/cgalfwd.h new file mode 100644 index 0000000..df9b9e2 --- /dev/null +++ b/src/cgalfwd.h @@ -0,0 +1,27 @@ +#ifndef CGALFWD_H_ +#define CGALFWD_H_ + +#ifdef ENABLE_CGAL + +namespace CGAL {  +	class Gmpq; +	template <class T> class Extended_cartesian; +	class HDS_items; +  template <class A, typename Items_, typename Mark_> class Nef_polyhedron_2; +} +typedef CGAL::Gmpq NT; +typedef CGAL::Extended_cartesian<NT> CGAL_Kernel2; +typedef CGAL::Nef_polyhedron_2<CGAL_Kernel2, CGAL::HDS_items, bool> CGAL_Nef_polyhedron2; +	 +namespace CGAL {  +	template <class T> class Cartesian; +	template<class T> struct Default_items; +	class SNC_indexed_items; +	template <typename Kernel_, typename Items_, typename Mark_> class Nef_polyhedron_3; +} +typedef CGAL::Cartesian<NT> CGAL_Kernel3; +typedef CGAL::Nef_polyhedron_3<CGAL_Kernel3, CGAL::SNC_indexed_items, bool> CGAL_Nef_polyhedron3; + +#endif /* ENABLE_CGAL */ + +#endif diff --git a/src/cgalrenderer.cc b/src/cgalrenderer.cc index 7a31747..aa55c57 100644 --- a/src/cgalrenderer.cc +++ b/src/cgalrenderer.cc @@ -29,17 +29,20 @@  #include "CGAL_renderer.h"  #include "dxfdata.h"  #include "dxftess.h" +#include "CGAL_Nef_polyhedron.h" +#include "cgal.h"  #include "Preferences.h"  CGALRenderer::CGALRenderer(const CGAL_Nef_polyhedron &root) : root(root)  {  	if (root.dim == 2) { -		DxfData dd(root); +		DxfData *dd = root.convertToDxfData();  		this->polyhedron = NULL;  		this->polyset = new PolySet();  		this->polyset->is2d = true; -		dxf_tesselate(this->polyset, &dd, 0, true, false, 0); +		dxf_tesselate(this->polyset, dd, 0, true, false, 0); +		delete dd;  	}  	else if (root.dim == 3) {  		this->polyset = NULL; @@ -54,7 +57,7 @@ CGALRenderer::CGALRenderer(const CGAL_Nef_polyhedron &root) : root(root)  															 Preferences::inst()->color(Preferences::CGAL_FACE_FRONT_COLOR).green(),  															 Preferences::inst()->color(Preferences::CGAL_FACE_FRONT_COLOR).blue()); -		CGAL::OGL::Nef3_Converter<CGAL_Nef_polyhedron3>::convert_to_OGLPolyhedron(this->root.p3, this->polyhedron); +		CGAL::OGL::Nef3_Converter<CGAL_Nef_polyhedron3>::convert_to_OGLPolyhedron(*this->root.p3, this->polyhedron);  		this->polyhedron->init();  	}  } @@ -86,7 +89,7 @@ void CGALRenderer::draw(bool showfaces, bool showedges) const  		typedef Explorer::Face_const_iterator fci_t;  		typedef Explorer::Halfedge_around_face_const_circulator heafcc_t;  		typedef Explorer::Point Point; -		Explorer E = this->root.p2.explorer(); +		Explorer E = this->root.p2->explorer();  		// Draw 2D edges  		glDisable(GL_DEPTH_TEST); diff --git a/src/cgalrenderer.h b/src/cgalrenderer.h index b3c1638..4e8039a 100644 --- a/src/cgalrenderer.h +++ b/src/cgalrenderer.h @@ -2,7 +2,7 @@  #define CGALRENDERER_H_  #include "renderer.h" -#include "cgal.h" +#include "CGAL_Nef_polyhedron.h"  class CGALRenderer : public Renderer  { diff --git a/src/dxfdata.h b/src/dxfdata.h index e71a740..a513edf 100644 --- a/src/dxfdata.h +++ b/src/dxfdata.h @@ -37,13 +37,9 @@ public:  	DxfData();  	DxfData(double fn, double fs, double fa, QString filename, QString layername = QString(), double xorigin = 0.0, double yorigin = 0.0, double scale = 1.0); -#ifdef ENABLE_CGAL -	DxfData(const struct CGAL_Nef_polyhedron &N); -#endif  	Vector2d *addPoint(double x, double y); -private:  	void fixup_path_direction();  }; diff --git a/src/export.cc b/src/export.cc index e46a14f..17a14c8 100644 --- a/src/export.cc +++ b/src/export.cc @@ -24,6 +24,7 @@   *   */ +#include "export.h"  #include "printutils.h"  #include "polyset.h"  #include "dxfdata.h" @@ -34,6 +35,7 @@  #include <errno.h>  #ifdef ENABLE_CGAL +#include "CGAL_Nef_polyhedron.h"  #include "cgal.h"  /*! @@ -43,7 +45,7 @@  void export_stl(CGAL_Nef_polyhedron *root_N, QTextStream &output, QProgressDialog *pd)  {  	CGAL_Polyhedron P; -	root_N->p3.convert_to_Polyhedron(P); +	root_N->p3->convert_to_Polyhedron(P);  	typedef CGAL_Polyhedron::Vertex                                 Vertex;  	typedef CGAL_Polyhedron::Vertex_const_iterator                  VCI; @@ -131,12 +133,12 @@ void export_dxf(CGAL_Nef_polyhedron *root_N, QTextStream &output, QProgressDialo  				 << "  2\n"  				 << "ENTITIES\n"; -	DxfData dd(*root_N); -	for (int i=0; i<dd.paths.size(); i++) +	DxfData *dd =root_N->convertToDxfData(); +	for (int i=0; i<dd->paths.size(); i++)  	{ -		for (int j=1; j<dd.paths[i].points.size(); j++) { -			const Vector2d &p1 = *dd.paths[i].points[j-1]; -			const Vector2d &p2 = *dd.paths[i].points[j]; +		for (int j=1; j<dd->paths[i].points.size(); j++) { +			const Vector2d &p1 = *dd->paths[i].points[j-1]; +			const Vector2d &p2 = *dd->paths[i].points[j];  			double x1 = p1[0];  			double y1 = p1[1];  			double x2 = p2[0]; @@ -173,6 +175,7 @@ void export_dxf(CGAL_Nef_polyhedron *root_N, QTextStream &output, QProgressDialo  	output << "  0\n"  				 <<"EOF\n"; +	delete dd;  	setlocale(LC_NUMERIC, "");      // Set default locale  } diff --git a/src/export.h b/src/export.h index d35246c..0298611 100644 --- a/src/export.h +++ b/src/export.h @@ -2,9 +2,9 @@  #define EXPORT_H_  #ifdef ENABLE_CGAL -#include "cgal.h" -void cgal_nef3_to_polyset(PolySet *ps, CGAL_Nef_polyhedron *root_N); -void export_stl(class CGAL_Nef_polyhedron *root_N, class QTextStream &output, class QProgressDialog *pd); + +void cgal_nef3_to_polyset(class PolySet *ps, class CGAL_Nef_polyhedron *root_N); +void export_stl(CGAL_Nef_polyhedron *root_N, class QTextStream &output, class QProgressDialog *pd);  void export_off(CGAL_Nef_polyhedron *root_N, class QTextStream &output, QProgressDialog *pd);  void export_dxf(CGAL_Nef_polyhedron *root_N, class QTextStream &output, QProgressDialog *pd);  #endif diff --git a/src/mainwin.cc b/src/mainwin.cc index 89d17c5..4faed34 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -46,8 +46,6 @@  #ifdef USE_PROGRESSWIDGET  #include "ProgressWidget.h"  #endif -#include "CGALEvaluator.h" -#include "PolySetCGALEvaluator.h"  #include "ThrownTogetherRenderer.h"  #include <QMenu> @@ -84,7 +82,11 @@ using namespace boost::lambda;  #ifdef ENABLE_CGAL +#include "CGALEvaluator.h" +#include "PolySetCGALEvaluator.h"  #include "cgalrenderer.h" +#include "CGAL_Nef_polyhedron.h" +#include "cgal.h"  #endif // ENABLE_CGAL @@ -1232,41 +1234,41 @@ void MainWindow::actionRenderCGAL()  		if (this->root_N->dim == 2) {  			PRINTF("   Top level object is a 2D object:");  			QApplication::processEvents(); -			PRINTF("   Empty:      %6s", this->root_N->p2.is_empty() ? "yes" : "no"); +			PRINTF("   Empty:      %6s", this->root_N->p2->is_empty() ? "yes" : "no");  			QApplication::processEvents(); -			PRINTF("   Plane:      %6s", this->root_N->p2.is_plane() ? "yes" : "no"); +			PRINTF("   Plane:      %6s", this->root_N->p2->is_plane() ? "yes" : "no");  			QApplication::processEvents(); -			PRINTF("   Vertices:   %6d", (int)this->root_N->p2.explorer().number_of_vertices()); +			PRINTF("   Vertices:   %6d", (int)this->root_N->p2->explorer().number_of_vertices());  			QApplication::processEvents(); -			PRINTF("   Halfedges:  %6d", (int)this->root_N->p2.explorer().number_of_halfedges()); +			PRINTF("   Halfedges:  %6d", (int)this->root_N->p2->explorer().number_of_halfedges());  			QApplication::processEvents(); -			PRINTF("   Edges:      %6d", (int)this->root_N->p2.explorer().number_of_edges()); +			PRINTF("   Edges:      %6d", (int)this->root_N->p2->explorer().number_of_edges());  			QApplication::processEvents(); -			PRINTF("   Faces:      %6d", (int)this->root_N->p2.explorer().number_of_faces()); +			PRINTF("   Faces:      %6d", (int)this->root_N->p2->explorer().number_of_faces());  			QApplication::processEvents(); -			PRINTF("   FaceCycles: %6d", (int)this->root_N->p2.explorer().number_of_face_cycles()); +			PRINTF("   FaceCycles: %6d", (int)this->root_N->p2->explorer().number_of_face_cycles());  			QApplication::processEvents(); -			PRINTF("   ConnComp:   %6d", (int)this->root_N->p2.explorer().number_of_connected_components()); +			PRINTF("   ConnComp:   %6d", (int)this->root_N->p2->explorer().number_of_connected_components());  			QApplication::processEvents();  		}  		if (this->root_N->dim == 3) {  			PRINTF("   Top level object is a 3D object:"); -			PRINTF("   Simple:     %6s", this->root_N->p3.is_simple() ? "yes" : "no"); +			PRINTF("   Simple:     %6s", this->root_N->p3->is_simple() ? "yes" : "no");  			QApplication::processEvents(); -			PRINTF("   Valid:      %6s", this->root_N->p3.is_valid() ? "yes" : "no"); +			PRINTF("   Valid:      %6s", this->root_N->p3->is_valid() ? "yes" : "no");  			QApplication::processEvents(); -			PRINTF("   Vertices:   %6d", (int)this->root_N->p3.number_of_vertices()); +			PRINTF("   Vertices:   %6d", (int)this->root_N->p3->number_of_vertices());  			QApplication::processEvents(); -			PRINTF("   Halfedges:  %6d", (int)this->root_N->p3.number_of_halfedges()); +			PRINTF("   Halfedges:  %6d", (int)this->root_N->p3->number_of_halfedges());  			QApplication::processEvents(); -			PRINTF("   Edges:      %6d", (int)this->root_N->p3.number_of_edges()); +			PRINTF("   Edges:      %6d", (int)this->root_N->p3->number_of_edges());  			QApplication::processEvents(); -			PRINTF("   Halffacets: %6d", (int)this->root_N->p3.number_of_halffacets()); +			PRINTF("   Halffacets: %6d", (int)this->root_N->p3->number_of_halffacets());  			QApplication::processEvents(); -			PRINTF("   Facets:     %6d", (int)this->root_N->p3.number_of_facets()); +			PRINTF("   Facets:     %6d", (int)this->root_N->p3->number_of_facets());  			QApplication::processEvents(); -			PRINTF("   Volumes:    %6d", (int)this->root_N->p3.number_of_volumes()); +			PRINTF("   Volumes:    %6d", (int)this->root_N->p3->number_of_volumes());  			QApplication::processEvents();  		} @@ -1367,7 +1369,7 @@ void MainWindow::actionExportSTLorOFF(bool)  		return;  	} -	if (!this->root_N->p3.is_simple()) { +	if (!this->root_N->p3->is_simple()) {  		PRINT("Object isn't a valid 2-manifold! Modify your design..");  		clearCurrentOutput();  		return; @@ -1386,7 +1388,7 @@ void MainWindow::actionExportSTLorOFF(bool)  	QProgressDialog *pd = new QProgressDialog(  			stl_mode ? "Exporting object to STL file..." : "Exporting object to OFF file...", -			QString(), 0, this->root_N->p3.number_of_facets() + 1); +			QString(), 0, this->root_N->p3->number_of_facets() + 1);  	pd->setValue(0);  	pd->setAutoClose(false);  	pd->show(); diff --git a/src/openscad.cc b/src/openscad.cc index a948c5a..a13528e 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -41,7 +41,7 @@  #include <vector>  #ifdef ENABLE_CGAL -#include "cgal.h" +#include "CGAL_Nef_polyhedron.h"  #include <CGAL/assertions_behaviour.h>  #endif diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ae5c496..088871c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -139,9 +139,10 @@ include_directories(${CGAL_INCLUDE_DIRS})  #  # cgaltest  # -add_executable(cgaltest cgaltest.cc ../src/cgal.cc ../src/CSGTermEvaluator.cc ../src/CGALEvaluator.cc -                        ../src/PolySetCGALEvaluator.cc ../src/qhash.cc ../src/nef2dxf.cc -                        ../src/cgaladv_minkowski2.cc ../src/cgaladv_minkowski3.cc ${COMMON_SOURCES}) +add_executable(cgaltest cgaltest.cc ../src/CGAL_Nef_polyhedron.cc ../src/CSGTermEvaluator.cc +                        ../src/CGALEvaluator.cc ../src/PolySetCGALEvaluator.cc ../src/qhash.cc +                        ../src/CGAL_Nef_polyhedron_DxfData.cc ../src/cgaladv_minkowski2.cc +                        ${COMMON_SOURCES})  set_target_properties(cgaltest PROPERTIES COMPILE_FLAGS "-DENABLE_CGAL ${CGAL_CXX_FLAGS_INIT}")  target_link_libraries(cgaltest ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES} ${QT_LIBRARIES} ${OPENGL_LIBRARY}) @@ -149,9 +150,10 @@ target_link_libraries(cgaltest ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES} ${QT_  # opencsgtest  #  add_executable(opencsgtest opencsgtest.cc OffscreenView.cc OffscreenContext.mm -                           ../src/OpenCSGRenderer.cc ../src/ThrownTogetherRenderer.cc ../src/CSGTermEvaluator.cc ../src/cgal.cc ../src/CGALEvaluator.cc -                           ../src/PolySetCGALEvaluator.cc ../src/qhash.cc ../src/nef2dxf.cc -                           ../src/cgaladv_minkowski2.cc ../src/cgaladv_minkowski3.cc +                           ../src/OpenCSGRenderer.cc ../src/ThrownTogetherRenderer.cc +                           ../src/CSGTermEvaluator.cc ../src/CGAL_Nef_polyhedron.cc +                           ../src/CGALEvaluator.cc ../src/PolySetCGALEvaluator.cc ../src/qhash.cc +                           ../src/CGAL_Nef_polyhedron_DxfData.cc ../src/cgaladv_minkowski2.cc                             ${COMMON_SOURCES})  set_target_properties(opencsgtest PROPERTIES COMPILE_FLAGS "-DENABLE_OPENCSG -DENABLE_CGAL ${CGAL_CXX_FLAGS_INIT}")  target_link_libraries(opencsgtest ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES} ${QT_LIBRARIES} ${OPENCSG_LIBRARY} ${GLEW_LIBRARY} ${COCOA_LIBRARY} ${OPENGL_LIBRARY}) diff --git a/tests/cgaltest.cc b/tests/cgaltest.cc index df03a43..9d4ef5d 100644 --- a/tests/cgaltest.cc +++ b/tests/cgaltest.cc @@ -32,6 +32,7 @@  #include "export.h"  #include "builtin.h"  #include "Tree.h" +#include "CGAL_Nef_polyhedron.h"  #include "CGALEvaluator.h"  #include "PolySetCGALEvaluator.h" @@ -42,6 +43,7 @@  #include <QTextStream>  #include <getopt.h>  #include <iostream> +#include <assert.h>  QString commandline_commands;  const char *make_command = NULL; | 
