summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CGALEvaluator.cc14
-rw-r--r--src/CGAL_Nef_polyhedron.cc65
-rw-r--r--src/CGAL_Nef_polyhedron.h8
-rw-r--r--src/dxftess-glu.cc28
4 files changed, 53 insertions, 62 deletions
diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc
index 31e5bcf..4bc5fc2 100644
--- a/src/CGALEvaluator.cc
+++ b/src/CGALEvaluator.cc
@@ -46,6 +46,7 @@ void CGALEvaluator::process(CGAL_Nef_polyhedron &target, const CGAL_Nef_polyhedr
if (target.dim != 2 && target.dim != 3) {
assert(false && "Dimension of Nef polyhedron must be 2 or 3");
}
+ assert(target.dim == src.dim);
switch (op) {
case CGE_UNION:
@@ -58,7 +59,7 @@ void CGALEvaluator::process(CGAL_Nef_polyhedron &target, const CGAL_Nef_polyhedr
target -= src;
break;
case CGE_MINKOWSKI:
- target = target.minkowski(src);
+ target.minkowski(src);
break;
case CGE_HULL:
//FIXME: Port convex hull to a binary operator or process it all in the end somehow
@@ -87,7 +88,7 @@ void CGALEvaluator::applyToChildren(const AbstractNode &node, CGALEvaluator::Csg
if (chnode->modinst->tag_background) continue;
assert(isCached(*chnode));
if (first) {
- N = this->cache[chcacheid];
+ N = this->cache[chcacheid].copy();
// If the first child(ren) are empty (e.g. echo) nodes,
// ignore them (reset first flag)
if (N.dim != 0) first = false;
@@ -97,7 +98,8 @@ void CGALEvaluator::applyToChildren(const AbstractNode &node, CGALEvaluator::Csg
chnode->progress_report();
}
}
- this->cache.insert(this->tree.getString(node), N);
+ const std::string &cacheid = this->tree.getString(node);
+ this->cache.insert(cacheid, N);
}
/*
@@ -195,7 +197,8 @@ Response CGALEvaluator::visit(State &state, const TransformNode &node)
node.matrix[2], node.matrix[6], node.matrix[10], node.matrix[14], node.matrix[15]);
N.p3->transform(t);
}
- this->cache.insert(this->tree.getString(node), N);
+ const std::string &cacheid = this->tree.getString(node);
+ this->cache.insert(cacheid, N);
}
addToParent(state, node);
}
@@ -228,7 +231,8 @@ Response CGALEvaluator::visit(State &state, const AbstractPolyNode &node)
node.progress_report();
ps->unlink();
- this->cache.insert(this->tree.getString(node), N);
+ const std::string &cacheid = this->tree.getString(node);
+ this->cache.insert(cacheid, N);
}
catch (...) { // Don't leak the PolySet on ProgressCancelException
ps->unlink();
diff --git a/src/CGAL_Nef_polyhedron.cc b/src/CGAL_Nef_polyhedron.cc
index 09368da..0c8c627 100644
--- a/src/CGAL_Nef_polyhedron.cc
+++ b/src/CGAL_Nef_polyhedron.cc
@@ -5,49 +5,38 @@
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;
- }
+ if (this->dim == 2) (*this->p2) += (*other.p2);
+ else if (this->dim == 3) (*this->p3) += (*other.p3);
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;
- }
+ if (this->dim == 2) (*this->p2) *= (*other.p2);
+ else if (this->dim == 3) (*this->p3) *= (*other.p3);
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;
- }
+ if (this->dim == 2) (*this->p2) -= (*other.p2);
+ else if (this->dim == 3) (*this->p3) -= (*other.p3);
+ return *this;
+}
+
+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 (this->dim == 2) (*this->p2) = minkowski2(*this->p2, *other.p2);
+ else if (this->dim == 3) (*this->p3) = CGAL::minkowski_sum_3(*this->p3, *other.p3);
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();
+ if (this->dim == 2) return this->p2->explorer().number_of_vertices();
+ if (this->dim == 3) return this->p3->number_of_vertices();
return 0;
}
@@ -95,17 +84,13 @@ 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)
+/*!
+ Deep copy
+*/
+CGAL_Nef_polyhedron CGAL_Nef_polyhedron::copy() const
{
- 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;
+ CGAL_Nef_polyhedron copy = *this;
+ if (copy.p2) copy.p2 = new CGAL_Nef_polyhedron2(*copy.p2);
+ else if (copy.p3) copy.p3 = new CGAL_Nef_polyhedron3(*copy.p3);
+ return copy;
}
diff --git a/src/CGAL_Nef_polyhedron.h b/src/CGAL_Nef_polyhedron.h
index 0ab72d7..9cac629 100644
--- a/src/CGAL_Nef_polyhedron.h
+++ b/src/CGAL_Nef_polyhedron.h
@@ -8,20 +8,22 @@
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() : dim(0), p2(0), p3(0) {}
+ CGAL_Nef_polyhedron(CGAL_Nef_polyhedron2 *p) : dim(2), p2(p), p3(0) {}
+ CGAL_Nef_polyhedron(CGAL_Nef_polyhedron3 *p) : dim(3), p2(0), 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);
+ CGAL_Nef_polyhedron copy() const;
int weight() const;
class PolySet *convertToPolyset();
class DxfData *convertToDxfData() const;
int dim;
+ // FIXME: Define ownership of the CGAL objects, e.g. use reference-counted smart pointers
CGAL_Nef_polyhedron2 *p2;
CGAL_Nef_polyhedron3 *p3;
};
diff --git a/src/dxftess-glu.cc b/src/dxftess-glu.cc
index 691872d..3132fe9 100644
--- a/src/dxftess-glu.cc
+++ b/src/dxftess-glu.cc
@@ -193,7 +193,7 @@ static bool point_on_line(double *p1, double *p2, double *p3)
rot: CLOCKWISE rotation around positive Z axis
*/
-void dxf_tesselate(PolySet *ps, DxfData *dxf, double rot, bool up, bool do_triangle_splitting, double h)
+void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, bool up, bool do_triangle_splitting, double h)
{
GLUtesselator *tobj = gluNewTess();
@@ -227,17 +227,17 @@ void dxf_tesselate(PolySet *ps, DxfData *dxf, double rot, bool up, bool do_trian
Grid3d< QPair<int,int> > point_to_path(GRID_COARSE);
- for (int i = 0; i < dxf->paths.count(); i++) {
- if (!dxf->paths[i].is_closed)
+ for (int i = 0; i < dxf.paths.count(); i++) {
+ if (!dxf.paths[i].is_closed)
continue;
gluTessBeginContour(tobj);
- for (int j = 1; j < dxf->paths[i].points.count(); j++) {
- point_to_path.data((*dxf->paths[i].points[j])[0],
- (*dxf->paths[i].points[j])[1],
+ for (int j = 1; j < dxf.paths[i].points.count(); j++) {
+ point_to_path.data((*dxf.paths[i].points[j])[0],
+ (*dxf.paths[i].points[j])[1],
h) = QPair<int,int>(i, j);
vl.append(tess_vdata());
- vl.last().v[0] = (*dxf->paths[i].points[j])[0];
- vl.last().v[1] = (*dxf->paths[i].points[j])[1];
+ vl.last().v[0] = (*dxf.paths[i].points[j])[0];
+ vl.last().v[1] = (*dxf.paths[i].points[j])[1];
vl.last().v[2] = h;
gluTessVertex(tobj, vl.last().v, vl.last().v);
}
@@ -370,19 +370,19 @@ void dxf_tesselate(PolySet *ps, DxfData *dxf, double rot, bool up, bool do_trian
int j2 = point_to_path.data(tess_tri[i].p[2][0], tess_tri[i].p[2][1], tess_tri[i].p[2][2]).second;
if (i0 == i1 && j0 == 1 && j1 == 2)
- dxf->paths[i0].is_inner = !up;
+ dxf.paths[i0].is_inner = !up;
if (i0 == i1 && j0 == 2 && j1 == 1)
- dxf->paths[i0].is_inner = up;
+ dxf.paths[i0].is_inner = up;
if (i1 == i2 && j1 == 1 && j2 == 2)
- dxf->paths[i1].is_inner = !up;
+ dxf.paths[i1].is_inner = !up;
if (i1 == i2 && j1 == 2 && j2 == 1)
- dxf->paths[i1].is_inner = up;
+ dxf.paths[i1].is_inner = up;
if (i2 == i0 && j2 == 1 && j0 == 2)
- dxf->paths[i2].is_inner = !up;
+ dxf.paths[i2].is_inner = !up;
if (i2 == i0 && j2 == 2 && j0 == 1)
- dxf->paths[i2].is_inner = up;
+ dxf.paths[i2].is_inner = up;
}
tess_tri.clear();
contact: Jan Huwald // Impressum