From afd4a6adb8dd0e67918688b45460730b7147ba12 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Fri, 15 Nov 2013 18:30:56 -0500 Subject: [PATCH] Handle CgaladvNodes --- src/GeometryEvaluator.cc | 67 ++++++++++++++++++++++++++++++++++------ src/GeometryEvaluator.h | 1 + 2 files changed, 59 insertions(+), 9 deletions(-) diff --git a/src/GeometryEvaluator.cc b/src/GeometryEvaluator.cc index afa7283b..6452bc2c 100644 --- a/src/GeometryEvaluator.cc +++ b/src/GeometryEvaluator.cc @@ -9,6 +9,7 @@ #include "linearextrudenode.h" #include "rotateextrudenode.h" #include "csgnode.h" +#include "cgaladvnode.h" #include "clipper-utils.h" #include "CGALEvaluator.h" #include "CGALCache.h" @@ -157,29 +158,51 @@ void GeometryEvaluator::addToParent(const State &state, } /*! - Fallback: If we don't know how to handle a node, send it to CGAL - */ + Custom nodes are handled here => implicit union +*/ Response GeometryEvaluator::visit(State &state, const AbstractNode &node) { if (state.isPrefix() && isCached(node)) return PruneTraversal; if (state.isPostfix()) { - shared_ptr geom; + shared_ptr geom; if (!isCached(node)) { - CGAL_Nef_polyhedron N = this->cgalevaluator->evaluateCGALMesh(node); - CGALCache::instance()->insert(this->tree.getIdString(node), N); - - PolySet *ps = NULL; - if (!N.isNull()) ps = N.convertToPolyset(); - geom.reset(ps); + const Geometry *geometry = applyToChildren2D(node, OPENSCAD_UNION); + const Polygon2d *polygons = dynamic_cast(geometry); + assert(polygons); + geom.reset(geometry); } else { geom = GeometryCache::instance()->get(this->tree.getIdString(node)); } addToParent(state, node, geom); + // FIXME: if 3d node, CGAL? } return ContinueTraversal; } +/* + FIXME: Where do we handle nodes which should be sent to CGAL? + + if (state.isPrefix() && isCached(node)) return PruneTraversal; + if (state.isPostfix()) { + shared_ptr geom; + if (!isCached(node)) { + CGAL_Nef_polyhedron N = this->cgalevaluator->evaluateCGALMesh(node); + CGALCache::instance()->insert(this->tree.getIdString(node), N); + + PolySet *ps = NULL; + if (!N.isNull()) ps = N.convertToPolyset(); + geom.reset(ps); + } + else { + geom = GeometryCache::instance()->get(this->tree.getIdString(node)); + } + addToParent(state, node, geom); + } + return ContinueTraversal; +*/ + + /*! Leaf nodes can create their own geometry, so let them do that */ @@ -476,3 +499,29 @@ Response GeometryEvaluator::visit(State &state, const AbstractPolyNode &node) return ContinueTraversal; } +Response GeometryEvaluator::visit(State &state, const CgaladvNode &node) +{ + if (state.isPrefix() && isCached(node)) return PruneTraversal; + if (state.isPostfix()) { + shared_ptr geom; + if (!isCached(node)) { + // if (node.type == RESIZE) { + // const Geometry *geometry = applyToChildren2D(node, OPENSCAD_UNION); + // // FIXME: find size and transform + // } + // else { + CGAL_Nef_polyhedron N = this->cgalevaluator->evaluateCGALMesh(node); + CGALCache::instance()->insert(this->tree.getIdString(node), N); + PolySet *ps = N.isNull() ? NULL : N.convertToPolyset(); + geom.reset(ps); +// } + // FIXME: handle 3D + } + else { + geom = GeometryCache::instance()->get(this->tree.getIdString(node)); + } + addToParent(state, node, geom); + } + return ContinueTraversal; +} + diff --git a/src/GeometryEvaluator.h b/src/GeometryEvaluator.h index 0397530b..39710dcb 100644 --- a/src/GeometryEvaluator.h +++ b/src/GeometryEvaluator.h @@ -25,6 +25,7 @@ public: virtual Response visit(State &state, const LeafNode &node); virtual Response visit(State &state, const TransformNode &node); virtual Response visit(State &state, const CsgNode &node); + virtual Response visit(State &state, const CgaladvNode &node); const Tree &getTree() const { return this->tree; }