diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CGALRenderer.cc | 17 | ||||
-rw-r--r-- | src/CGALRenderer.h | 13 | ||||
-rw-r--r-- | src/PolySetCGALRenderer.h | 1 | ||||
-rw-r--r-- | src/Tree.h | 2 | ||||
-rw-r--r-- | src/grid.h | 2 | ||||
-rw-r--r-- | src/myqhash.h | 9 | ||||
-rw-r--r-- | src/qhash.cc | 19 |
7 files changed, 44 insertions, 19 deletions
diff --git a/src/CGALRenderer.cc b/src/CGALRenderer.cc index 67529b3..3fd0d7b 100644 --- a/src/CGALRenderer.cc +++ b/src/CGALRenderer.cc @@ -1,7 +1,6 @@ #include "CGALRenderer.h" #include "visitor.h" #include "state.h" -#include "nodecache.h" #include "module.h" // FIXME: Temporarily for ModuleInstantiation #include "printutils.h" @@ -29,12 +28,12 @@ CGAL_Nef_polyhedron CGALRenderer::renderCGALMesh(const AbstractNode &node) render.execute(); assert(isCached(node)); } - return this->cache[this->dumpcache[node]]; + return this->cache[this->tree.getString(node)]; } bool CGALRenderer::isCached(const AbstractNode &node) const { - return this->cache.contains(this->dumpcache[node]); + return this->cache.contains(this->tree.getString(node)); } /*! @@ -94,7 +93,7 @@ void CGALRenderer::applyToChildren(const AbstractNode &node, CGALRenderer::CsgOp iter != this->visitedchildren[node.index()].end(); iter++) { const AbstractNode *chnode = iter->first; - const QString &chcacheid = iter->second; + const string &chcacheid = iter->second; // FIXME: Don't use deep access to modinst members if (chnode->modinst->tag_background) continue; assert(isCached(*chnode)); @@ -109,7 +108,7 @@ void CGALRenderer::applyToChildren(const AbstractNode &node, CGALRenderer::CsgOp chnode->progress_report(); } } - this->cache.insert(this->dumpcache[node], N); + this->cache.insert(this->tree.getString(node), N); } /* @@ -172,7 +171,7 @@ Response CGALRenderer::visit(const State &state, const TransformNode &node) applyToChildren(node, UNION); // Then apply transform - CGAL_Nef_polyhedron N = this->cache[this->dumpcache[node]]; + CGAL_Nef_polyhedron N = this->cache[this->tree.getString(node)]; assert(N.dim >= 2 && N.dim <= 3); if (N.dim == 2) { // Unfortunately CGAL provides no transform method for CGAL_Nef_polyhedron2 @@ -205,7 +204,7 @@ Response CGALRenderer::visit(const State &state, const TransformNode &node) node.m[2], node.m[6], node.m[10], node.m[14], node.m[15]); N.p3.transform(t); } - this->cache.insert(cacheid, N); + this->cache.insert(this->tree.getString(node), N); } addToParent(state, node); } @@ -237,7 +236,7 @@ Response CGALRenderer::visit(const State &state, const AbstractPolyNode &node) node.progress_report(); ps->unlink(); - this->cache.insert(this->dumpcache[node], N); + this->cache.insert(this->tree.getString(node), N); } catch (...) { // Don't leak the PolySet on ProgressCancelException ps->unlink(); @@ -258,7 +257,7 @@ void CGALRenderer::addToParent(const State &state, const AbstractNode &node) assert(state.isPostfix()); this->visitedchildren.erase(node.index()); if (state.parent()) { - this->visitedchildren[state.parent()->index()].push_back(std::make_pair(&node, this->dumpcache[node])); + this->visitedchildren[state.parent()->index()].push_back(std::make_pair(&node, this->tree.getString(node))); } } diff --git a/src/CGALRenderer.h b/src/CGALRenderer.h index 0492c86..11abaa3 100644 --- a/src/CGALRenderer.h +++ b/src/CGALRenderer.h @@ -1,11 +1,13 @@ #ifndef CGALRENDERER_H_ #define CGALRENDERER_H_ +#include "myqhash.h" + #include <string> #include <map> #include <list> #include "visitor.h" -#include "nodecache.h" +#include "Tree.h" #include "cgal.h" #ifdef ENABLE_CGAL @@ -23,7 +25,7 @@ class CGALRenderer : public Visitor public: enum CsgOp {UNION, INTERSECTION, DIFFERENCE, MINKOWSKI}; // FIXME: If a cache is not given, we need to fix this ourselves - CGALRenderer(QHash<QString, CGAL_Nef_polyhedron> &cache, const NodeCache<string> &dumpcache) : cache(cache), dumpcache(dumpcache) {} + CGALRenderer(QHash<string, CGAL_Nef_polyhedron> &cache, const Tree &tree) : cache(cache), tree(tree) {} virtual ~CGALRenderer() {} virtual Response visit(const State &state, const AbstractNode &node); @@ -38,16 +40,15 @@ public: private: void addToParent(const State &state, const AbstractNode &node); bool isCached(const AbstractNode &node) const; - QString mk_cache_id(const AbstractNode &node) const; void process(CGAL_Nef_polyhedron &target, const CGAL_Nef_polyhedron &src, CGALRenderer::CsgOp op); void applyToChildren(const AbstractNode &node, CGALRenderer::CsgOp op); string currindent; - typedef list<pair<const AbstractNode *, QString> > ChildList; + typedef list<pair<const AbstractNode *, string> > ChildList; map<int, ChildList> visitedchildren; - QHash<QString, CGAL_Nef_polyhedron> &cache; - const NodeCache<string> &dumpcache; + QHash<string, CGAL_Nef_polyhedron> &cache; + const Tree &tree; }; #endif diff --git a/src/PolySetCGALRenderer.h b/src/PolySetCGALRenderer.h index fb708ed..ef71a57 100644 --- a/src/PolySetCGALRenderer.h +++ b/src/PolySetCGALRenderer.h @@ -2,7 +2,6 @@ #define POLYSETCGALRENDERER_H_ #include "PolySetRenderer.h" -#include <QHash> #include "CGALRenderer.h" /*! @@ -2,7 +2,6 @@ #define TREE_H_ #include "nodecache.h" -//#include "cgal.h" using std::string; @@ -19,7 +18,6 @@ public: // FIXME: Really return a reference? const string &getString(const AbstractNode &node) const; -// CGAL_Nef_polyhedron getCGALMesh(const AbstractNode &node) const; private: const AbstractNode *root_node; @@ -1,10 +1,10 @@ #ifndef GRID_H_ #define GRID_H_ +#include <QHash> #include <math.h> #include <stdint.h> #include <stdlib.h> -#include <QHash> const double GRID_COARSE = 0.001; const double GRID_FINE = 0.000001; diff --git a/src/myqhash.h b/src/myqhash.h new file mode 100644 index 0000000..13eba09 --- /dev/null +++ b/src/myqhash.h @@ -0,0 +1,9 @@ +#ifndef OPENSCAD_QHASH_H_ +#define OPENSCAD_QHASH_H_ + +#include <qglobal.h> +#include <string> +extern uint qHash(const std::string &); +#include <QHash> + +#endif diff --git a/src/qhash.cc b/src/qhash.cc new file mode 100644 index 0000000..cec9adf --- /dev/null +++ b/src/qhash.cc @@ -0,0 +1,19 @@ +#include "myqhash.h" + +static uint hash(const uchar *p, int n) +{ + uint h = 0; + uint g; + + while (n--) { + h = (h << 4) + *p++; + if ((g = (h & 0xf0000000)) != 0) + h ^= g >> 23; + h &= ~g; + } + return h; +} + +uint qHash(const std::string &str) { + return hash(reinterpret_cast<const uchar *>(str.c_str()), str.length()); +} |