diff options
Diffstat (limited to 'src')
-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 |
18 files changed, 227 insertions, 228 deletions
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 |