From b482d9f15b788064b7f9363d59c786664657fd5e Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sat, 4 Jan 2014 18:19:27 -0500 Subject: [PATCH] Bugfix: We didn't cache top-level objects properly --- src/GeometryEvaluator.cc | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/GeometryEvaluator.cc b/src/GeometryEvaluator.cc index cb510fe1..603377c6 100644 --- a/src/GeometryEvaluator.cc +++ b/src/GeometryEvaluator.cc @@ -39,7 +39,6 @@ bool GeometryEvaluator::isCached(const AbstractNode &node) const return GeometryCache::instance()->contains(this->tree.getIdString(node)); } -// FIXME: This doesn't insert into cache. Fix this here or in client code /*! Set allownef to false to force the result to _not_ be a Nef polyhedron */ @@ -47,18 +46,26 @@ shared_ptr GeometryEvaluator::evaluateGeometry(const AbstractNod bool allownef) { if (!isCached(node)) { - Traverser trav(*this, node, Traverser::PRE_AND_POSTFIX); - trav.execute(); - - if (!allownef) { - shared_ptr N = dynamic_pointer_cast(this->root); - if (N) { - if (N->getDimension() == 3) this->root.reset(N->convertToPolyset()); - else this->root.reset(); - GeometryCache::instance()->insert(this->tree.getIdString(node), this->root); - } + shared_ptr N; + if (CGALCache::instance()->contains(this->tree.getIdString(node))) { + N = CGALCache::instance()->get(this->tree.getIdString(node)); } + // If not found in any caches, we need to evaluate the geometry + if (N) { + this->root = N; + } + else { + Traverser trav(*this, node, Traverser::PRE_AND_POSTFIX); + trav.execute(); + + if (!allownef) { + if (shared_ptr N = dynamic_pointer_cast(this->root)) { + this->root.reset(N->convertToPolyset()); + smartCache(node, this->root); + } + } + } return this->root; } return GeometryCache::instance()->get(this->tree.getIdString(node)); @@ -256,9 +263,7 @@ std::vector GeometryEvaluator::collectChildren2D(const // a node is a valid object. If we inserted as we created them, the // cache could have been modified before we reach this point due to a large // sibling object. - if (!isCached(*chnode)) { - GeometryCache::instance()->insert(this->tree.getIdString(*chnode), chgeom); - } + smartCache(*chnode, chgeom); if (chgeom) { if (chgeom->getDimension() == 2) { @@ -274,11 +279,14 @@ std::vector GeometryEvaluator::collectChildren2D(const return children; } +/*! + Since we can generate both Nef and non-Nef geometry, we need to insert it into + the appropriate cache. + This method inserts the geometry into the appropriate cache if it's not already cached. +*/ void GeometryEvaluator::smartCache(const AbstractNode &node, const shared_ptr &geom) { - // Since we can generate both Nef and non-Nef geometry, we need to insert it into - // the appropriate cache shared_ptr N = dynamic_pointer_cast(geom); if (N) { if (!CGALCache::instance()->contains(this->tree.getIdString(node))) {