diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CGALEvaluator.cc | 49 | ||||
-rw-r--r-- | src/CGALEvaluator.h | 3 | ||||
-rw-r--r-- | src/cgaladv_convexhull2.cc | 9 |
3 files changed, 46 insertions, 15 deletions
diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index a63d271..0d46cd9 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -63,12 +63,6 @@ void CGALEvaluator::process(CGAL_Nef_polyhedron &target, const CGAL_Nef_polyhedr case CGE_MINKOWSKI: 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; } } @@ -100,6 +94,40 @@ void CGALEvaluator::applyToChildren(const AbstractNode &node, CGALEvaluator::Csg this->cache.insert(cacheid, N); } +extern CGAL_Nef_polyhedron2 *convexhull2(std::list<CGAL_Nef_polyhedron2*> a); + +void CGALEvaluator::applyHull(const CgaladvNode &node) +{ + if (this->visitedchildren[node.index()].size() > 0) { + std::list<CGAL_Nef_polyhedron2*> polys; + bool all2d = true; + for (ChildList::const_iterator iter = this->visitedchildren[node.index()].begin(); + iter != this->visitedchildren[node.index()].end(); + iter++) { + const AbstractNode *chnode = iter->first; + const string &chcacheid = iter->second; + // FIXME: Don't use deep access to modinst members + if (chnode->modinst->tag_background) continue; + assert(isCached(*chnode)); + const CGAL_Nef_polyhedron &ch = this->cache[chcacheid]; + if (ch.dim == 2) { + polys.push_back(ch.p2); + } + else if (ch.dim == 3) { + PRINT("WARNING: hull() is not implemented yet for 3D objects!"); + all2d = false; + } + chnode->progress_report(); + } + + if (all2d) { + CGAL_Nef_polyhedron N(convexhull2(polys)); + const std::string &cacheid = this->tree.getString(node); + this->cache.insert(cacheid, N); + } + } +} + /* Typical visitor behavior: o In prefix: Check if we're cached -> prune @@ -246,17 +274,20 @@ Response CGALEvaluator::visit(State &state, const CgaladvNode &node) switch (node.type) { case MINKOWSKI: op = CGE_MINKOWSKI; + applyToChildren(node, op); break; case GLIDE: + PRINT("WARNING: glide() is not implemented yet!"); + return PruneTraversal; + break; case SUBDIV: - // FIXME: Not implemented + PRINT("WARNING: subdiv() is not implemented yet!"); return PruneTraversal; break; case HULL: - op = CGE_HULL; + applyHull(node); break; } - applyToChildren(node, op); } addToParent(state, node); } diff --git a/src/CGALEvaluator.h b/src/CGALEvaluator.h index a985065..2453c25 100644 --- a/src/CGALEvaluator.h +++ b/src/CGALEvaluator.h @@ -19,7 +19,7 @@ using std::pair; class CGALEvaluator : public Visitor { public: - enum CsgOp {CGE_UNION, CGE_INTERSECTION, CGE_DIFFERENCE, CGE_MINKOWSKI, CGE_HULL}; + enum CsgOp {CGE_UNION, CGE_INTERSECTION, CGE_DIFFERENCE, CGE_MINKOWSKI}; // FIXME: If a cache is not given, we need to fix this ourselves CGALEvaluator(QHash<string, CGAL_Nef_polyhedron> &cache, const Tree &tree) : cache(cache), tree(tree), psevaluator(*this) {} virtual ~CGALEvaluator() {} @@ -41,6 +41,7 @@ private: bool isCached(const AbstractNode &node) const; void process(CGAL_Nef_polyhedron &target, const CGAL_Nef_polyhedron &src, CGALEvaluator::CsgOp op); void applyToChildren(const AbstractNode &node, CGALEvaluator::CsgOp op); + void applyHull(const CgaladvNode &node); string currindent; typedef list<pair<const AbstractNode *, string> > ChildList; diff --git a/src/cgaladv_convexhull2.cc b/src/cgaladv_convexhull2.cc index 448dd4b..492df3c 100644 --- a/src/cgaladv_convexhull2.cc +++ b/src/cgaladv_convexhull2.cc @@ -29,16 +29,15 @@ #include "cgal.h" #include <CGAL/convex_hull_2.h> -extern CGAL_Nef_polyhedron2 convexhull2(std::list<CGAL_Nef_polyhedron2> a); extern CGAL_Poly2 nef2p2(CGAL_Nef_polyhedron2 p); -CGAL_Nef_polyhedron2 convexhull2(std::list<CGAL_Nef_polyhedron2> a) +CGAL_Nef_polyhedron2 *convexhull2(std::list<CGAL_Nef_polyhedron2*> a) { std::list<CGAL_Nef_polyhedron2::Point> points; - std::list<CGAL_Nef_polyhedron2>::iterator i; + std::list<CGAL_Nef_polyhedron2*>::iterator i; for (i=a.begin(); i!=a.end(); i++) { - CGAL_Poly2 ap=nef2p2(*i); + CGAL_Poly2 ap=nef2p2(**i); for (size_t j=0;j<ap.size();j++) { double x=to_double(ap[j].x()),y=to_double(ap[j].y()); CGAL_Nef_polyhedron2::Point p=CGAL_Nef_polyhedron2::Point(x,y); @@ -49,7 +48,7 @@ CGAL_Nef_polyhedron2 convexhull2(std::list<CGAL_Nef_polyhedron2> a) std::list<CGAL_Nef_polyhedron2::Point> result; CGAL::convex_hull_2(points.begin(),points.end(),std::back_inserter(result)); - return CGAL_Nef_polyhedron2(result.begin(),result.end(),CGAL_Nef_polyhedron2::INCLUDED); + return new CGAL_Nef_polyhedron2(result.begin(),result.end(),CGAL_Nef_polyhedron2::INCLUDED); } #endif |