From e68773df5093caff423ab4c9869f9a591dbade6f Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sat, 3 Dec 2011 01:21:44 +0100 Subject: Upgraded OpenCSG to 1.3.2 diff --git a/scripts/macosx-build-dependencies.sh b/scripts/macosx-build-dependencies.sh index 32b15cd..e69d594 100755 --- a/scripts/macosx-build-dependencies.sh +++ b/scripts/macosx-build-dependencies.sh @@ -185,10 +185,10 @@ build_opencsg() version=$1 echo "Building OpenCSG" $version "..." cd $BASEDIR/src + rm -rf OpenCSG-$version curl -O http://www.opencsg.org/OpenCSG-$version.tar.gz tar xzf OpenCSG-$version.tar.gz cd OpenCSG-$version - patch -p1 < $OPENSCADDIR/patches/OpenCSG-$version-FBO.patch patch -p1 < $OPENSCADDIR/patches/OpenCSG-$version-MacOSX-port.patch MACOSX_DEPLOY_DIR=$DEPLOYDIR qmake -r CONFIG+="x86 x86_64" make install @@ -202,4 +202,4 @@ build_boost 1.47.0 # NB! For CGAL, also update the actual download URL in the function build_cgal 3.9 build_glew 1.7.0 -build_opencsg 1.3.0 +build_opencsg 1.3.2 -- cgit v0.10.1 From 1e2e2f6944636ea26259688d46c67da57094d947 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sat, 3 Dec 2011 01:24:49 +0100 Subject: update 3rd party version numbers diff --git a/README b/README index 85baf16..a818bf3 100644 --- a/README +++ b/README @@ -43,25 +43,25 @@ development. Other versions may or may not work as well.. * GMP (5.0.x): http://www.gmplib.org/ -* MPFR (3.0.x): +* MPFR (3.x): http://www.mpfr.org/ * boost (1.35 - 1.47) http://www.boost.org/ -* cmake (2.6.x, required by CGAL) +* cmake (2.6 - 2.8, required by CGAL and the test framework) http://www.cmake.org/ -* OpenCSG (1.3.0): +* OpenCSG (1.3.2): http://www.opencsg.org/ -* GLEW (1.5.x, 1.6.x, also bundled with OpenCSG) +* GLEW (1.5 ->) http://glew.sourceforge.net/ * Eigen2 (2.0.13->) http://eigen.tuxfamily.org/ -* GCC C++ Compiler (4.2, 4.3.1): +* GCC C++ Compiler (4.2 ->): http://gcc.gnu.org/ * Bison (2.4): -- cgit v0.10.1 From faf4a6485143a9b0d1bbc45ddb32ac1bcd111946 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sun, 4 Dec 2011 22:20:19 +0100 Subject: Killed some warnings diff --git a/src/OpenCSGRenderer.cc b/src/OpenCSGRenderer.cc index 5d6b0da..a1aafc5 100644 --- a/src/OpenCSGRenderer.cc +++ b/src/OpenCSGRenderer.cc @@ -56,7 +56,7 @@ OpenCSGRenderer::OpenCSGRenderer(CSGChain *root_chain, CSGChain *highlights_chai { } -void OpenCSGRenderer::draw(bool showfaces, bool showedges) const +void OpenCSGRenderer::draw(bool /*showfaces*/, bool showedges) const { if (this->root_chain) { GLint *shaderinfo = this->shaderinfo; diff --git a/src/ThrownTogetherRenderer.cc b/src/ThrownTogetherRenderer.cc index 336c4c7..3ab13ea 100644 --- a/src/ThrownTogetherRenderer.cc +++ b/src/ThrownTogetherRenderer.cc @@ -40,7 +40,7 @@ ThrownTogetherRenderer::ThrownTogetherRenderer(CSGChain *root_chain, { } -void ThrownTogetherRenderer::draw(bool showfaces, bool showedges) const +void ThrownTogetherRenderer::draw(bool /*showfaces*/, bool showedges) const { if (this->root_chain) { glEnable(GL_CULL_FACE); diff --git a/src/expr.cc b/src/expr.cc index 7e1a25b..66a0d11 100644 --- a/src/expr.cc +++ b/src/expr.cc @@ -86,7 +86,7 @@ Value Expression::evaluate(const Context *context) const return *v1.vec[i]; } if (v1.type == Value::STRING && v2.type == Value::NUMBER) { - int i = (int)(v2.num); + int i = int(v2.num); if (i >= 0 && i < v1.text.size()) return Value(v1.text.substr(i, 1)); } diff --git a/src/glview.cc b/src/glview.cc index 8454cd6..bc287b5 100644 --- a/src/glview.cc +++ b/src/glview.cc @@ -535,7 +535,6 @@ void GLView::mouseMoveEvent(QMouseEvent *event) double dx = (this_mouse.x()-last_mouse.x()) * 0.7; double dy = (this_mouse.y()-last_mouse.y()) * 0.7; if (mouse_drag_active) { - int i = event->buttons(); if (event->buttons() & Qt::LeftButton #ifdef Q_WS_MAC && !(event->modifiers() & Qt::MetaModifier) diff --git a/src/mainwin.cc b/src/mainwin.cc index 22fb82c..29c84b0 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -849,11 +849,11 @@ void MainWindow::compileCSG(bool procevents) } if (root_chain->polysets.size() > 1000) { - PRINTF("WARNING: Normalized tree has %d elements!", root_chain->polysets.size()); + PRINTF("WARNING: Normalized tree has %d elements!", int(root_chain->polysets.size())); PRINTF("WARNING: OpenCSG rendering has been disabled."); } else { - PRINTF("Normalized CSG tree has %d elements", root_chain->polysets.size()); + PRINTF("Normalized CSG tree has %d elements", int(root_chain->polysets.size())); this->opencsgRenderer = new OpenCSGRenderer(this->root_chain, this->highlights_chain, this->background_chain, diff --git a/src/primitives.cc b/src/primitives.cc index b18a816..67e19c3 100644 --- a/src/primitives.cc +++ b/src/primitives.cc @@ -505,7 +505,7 @@ sphere_next_r2: for (size_t i=0; ipoints.vec.size(); i++) { double x,y; if (!this->points.vec[i]->getv2(x, y)) { - PRINTF("ERROR: Unable to convert point at index %d to a vec2 of numbers", i); + PRINTF("ERROR: Unable to convert point at index %d to a vec2 of numbers", int(i)); delete p; return NULL; } -- cgit v0.10.1 From d392ee33f6eb57d2d08a7a7703fb9118aa82698c Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Mon, 5 Dec 2011 23:57:42 +0100 Subject: Commented out yee_compare diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 624346b..29f8b25 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -296,9 +296,8 @@ target_link_libraries(echotest tests-nocgal tests-core ${QT_LIBRARIES} ${OPENGL_ # # Yangli Hector Yee's PerceptualDiff code -# - -add_executable(yee_compare yee_compare.cpp lodepng.cpp) +# FIXME: Disabled since we use ImageMagick now. Eventually remove this and the files. +# add_executable(yee_compare yee_compare.cpp lodepng.cpp) # # dumptest -- cgit v0.10.1 From 65a5aa23bfd78718972082f82eb7366d01a968a6 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Tue, 6 Dec 2011 01:16:54 +0100 Subject: Refactoring: Use shared_ptr instead of our own shared pointer implementation for CSGTerm diff --git a/src/CSGTermEvaluator.cc b/src/CSGTermEvaluator.cc index 0c7bca7..1aedfec 100644 --- a/src/CSGTermEvaluator.cc +++ b/src/CSGTermEvaluator.cc @@ -18,6 +18,7 @@ #include #include #include +#include /*! \class CSGTermEvaluator @@ -26,9 +27,9 @@ with OpenCSG. */ -CSGTerm *CSGTermEvaluator::evaluateCSGTerm(const AbstractNode &node, - std::vector &highlights, - std::vector &background) +shared_ptr CSGTermEvaluator::evaluateCSGTerm(const AbstractNode &node, + std::vector > &highlights, + std::vector > &background) { Traverser evaluate(*this, node, Traverser::PRE_AND_POSTFIX); evaluate.execute(); @@ -39,31 +40,28 @@ CSGTerm *CSGTermEvaluator::evaluateCSGTerm(const AbstractNode &node, void CSGTermEvaluator::applyToChildren(const AbstractNode &node, CSGTermEvaluator::CsgOp op) { - CSGTerm *t1 = NULL; - for (ChildList::const_iterator iter = this->visitedchildren[node.index()].begin(); - iter != this->visitedchildren[node.index()].end(); - iter++) { - const AbstractNode *chnode = *iter; - CSGTerm *t2 = this->stored_term[chnode->index()]; + shared_ptr t1; + BOOST_FOREACH(const AbstractNode *chnode, this->visitedchildren[node.index()]) { + shared_ptr t2(this->stored_term[chnode->index()]); this->stored_term.erase(chnode->index()); if (t2 && !t1) { t1 = t2; } else if (t2 && t1) { if (op == CSGT_UNION) { - t1 = new CSGTerm(CSGTerm::TYPE_UNION, t1, t2); + t1.reset(new CSGTerm(CSGTerm::TYPE_UNION, t1, t2)); } else if (op == CSGT_DIFFERENCE) { - t1 = new CSGTerm(CSGTerm::TYPE_DIFFERENCE, t1, t2); + t1.reset(new CSGTerm(CSGTerm::TYPE_DIFFERENCE, t1, t2)); } else if (op == CSGT_INTERSECTION) { - t1 = new CSGTerm(CSGTerm::TYPE_INTERSECTION, t1, t2); + t1.reset(new CSGTerm(CSGTerm::TYPE_INTERSECTION, t1, t2)); } } } if (t1 && node.modinst->tag_highlight) { - this->highlights.push_back(t1->link()); + this->highlights.push_back(t1); } if (t1 && node.modinst->tag_background) { this->background.push_back(t1); - t1 = NULL; // don't propagate background tagged nodes + t1.reset(); // don't propagate background tagged nodes } this->stored_term[node.index()] = t1; } @@ -86,21 +84,22 @@ Response CSGTermEvaluator::visit(State &state, const AbstractIntersectionNode &n return ContinueTraversal; } -static CSGTerm *evaluate_csg_term_from_ps(const State &state, - std::vector &highlights, - std::vector &background, +static shared_ptr evaluate_csg_term_from_ps(const State &state, + std::vector > &highlights, + std::vector > &background, const shared_ptr &ps, const ModuleInstantiation *modinst, const AbstractNode &node) { std::stringstream stream; stream << node.name() << node.index(); - CSGTerm *t = new CSGTerm(ps, state.matrix(), state.color(), stream.str()); - if (modinst->tag_highlight) - highlights.push_back(t->link()); + shared_ptr t(new CSGTerm(ps, state.matrix(), state.color(), stream.str())); + if (modinst->tag_highlight) { + highlights.push_back(t); + } if (modinst->tag_background) { background.push_back(t); - return NULL; + t.reset(); } return t; } @@ -108,7 +107,7 @@ static CSGTerm *evaluate_csg_term_from_ps(const State &state, Response CSGTermEvaluator::visit(State &state, const AbstractPolyNode &node) { if (state.isPostfix()) { - CSGTerm *t1 = NULL; + shared_ptr t1; if (this->psevaluator) { shared_ptr ps = this->psevaluator->getPolySet(node, true); if (ps) { @@ -173,7 +172,7 @@ Response CSGTermEvaluator::visit(State &state, const ColorNode &node) Response CSGTermEvaluator::visit(State &state, const RenderNode &node) { if (state.isPostfix()) { - CSGTerm *t1 = NULL; + shared_ptr t1; shared_ptr ps; if (this->psevaluator) { ps = this->psevaluator->getPolySet(node, true); @@ -191,7 +190,7 @@ Response CSGTermEvaluator::visit(State &state, const RenderNode &node) Response CSGTermEvaluator::visit(State &state, const CgaladvNode &node) { if (state.isPostfix()) { - CSGTerm *t1 = NULL; + shared_ptr t1; // FIXME: Calling evaluator directly since we're not a PolyNode. Generalize this. shared_ptr ps; if (this->psevaluator) { diff --git a/src/CSGTermEvaluator.h b/src/CSGTermEvaluator.h index 3a8122b..49bac17 100644 --- a/src/CSGTermEvaluator.h +++ b/src/CSGTermEvaluator.h @@ -6,6 +6,7 @@ #include #include #include "visitor.h" +#include "memory.h" class CSGTermEvaluator : public Visitor { @@ -24,9 +25,9 @@ public: virtual Response visit(State &state, const class RenderNode &node); virtual Response visit(State &state, const class CgaladvNode &node); - class CSGTerm *evaluateCSGTerm(const AbstractNode &node, - std::vector &highlights, - std::vector &background); + shared_ptr evaluateCSGTerm(const AbstractNode &node, + std::vector > &highlights, + std::vector > &background); private: enum CsgOp {CSGT_UNION, CSGT_INTERSECTION, CSGT_DIFFERENCE, CSGT_MINKOWSKI}; @@ -38,10 +39,10 @@ private: std::map visitedchildren; public: - std::map stored_term; // The term evaluated from each node index + std::map > stored_term; // The term evaluated from each node index - std::vector highlights; - std::vector background; + std::vector > highlights; + std::vector > background; const Tree &tree; class PolySetEvaluator *psevaluator; }; diff --git a/src/MainWindow.h b/src/MainWindow.h index 06332b0..b2d0f60 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -7,6 +7,7 @@ #include "context.h" #include "module.h" #include "Tree.h" +#include "memory.h" #include class MainWindow : public QMainWindow, public Ui::MainWindow @@ -34,8 +35,8 @@ public: AbstractNode *root_node; // Root if the root modifier (!) is used Tree tree; - class CSGTerm *root_raw_term; // Result of CSG term rendering - CSGTerm *root_norm_term; // Normalized CSG products + shared_ptr root_raw_term; // Result of CSG term rendering + shared_ptr root_norm_term; // Normalized CSG products class CSGChain *root_chain; #ifdef ENABLE_CGAL class CGAL_Nef_polyhedron *root_N; @@ -46,9 +47,9 @@ public: #endif class ThrownTogetherRenderer *thrownTogetherRenderer; - std::vector highlight_terms; + std::vector > highlight_terms; CSGChain *highlights_chain; - std::vector background_terms; + std::vector > background_terms; CSGChain *background_chain; QString last_compiled_doc; diff --git a/src/Tree.cc b/src/Tree.cc index 7c4866b..d27e198 100644 --- a/src/Tree.cc +++ b/src/Tree.cc @@ -4,6 +4,12 @@ #include #include +Tree::~Tree() +{ + this->nodecache.clear(); + this->nodeidcache.clear(); +} + /*! Returns the cached string representation of the subtree rooted by \a node. If node is not cached, the cache will be rebuilt. diff --git a/src/Tree.h b/src/Tree.h index 41ae613..938353b 100644 --- a/src/Tree.h +++ b/src/Tree.h @@ -13,7 +13,7 @@ class Tree { public: Tree(const AbstractNode *root = NULL) : root_node(root) {} - ~Tree() {} + ~Tree(); void setRoot(const AbstractNode *root); const AbstractNode *root() const { return this->root_node; } diff --git a/src/csgterm.cc b/src/csgterm.cc index 16ef75f..b21a20c 100644 --- a/src/csgterm.cc +++ b/src/csgterm.cc @@ -48,20 +48,28 @@ CSGTerm::CSGTerm(const shared_ptr &polyset, const Transform3d &matrix, const double color[4], const std::string &label) - : type(TYPE_PRIMITIVE), polyset(polyset), label(label), left(NULL), right(NULL) + : type(TYPE_PRIMITIVE), polyset(polyset), label(label) { this->m = matrix; for (int i = 0; i < 4; i++) this->color[i] = color[i]; - refcounter = 1; +} + +CSGTerm::CSGTerm(type_e type, shared_ptr left, shared_ptr right) + : type(type), left(left), right(right) +{ } CSGTerm::CSGTerm(type_e type, CSGTerm *left, CSGTerm *right) : type(type), left(left), right(right) { - refcounter = 1; } -CSGTerm *CSGTerm::normalize() +CSGTerm::~CSGTerm() +{ +} + + +shared_ptr CSGTerm::normalize(shared_ptr &term) { // This function implements the CSG normalization // Reference: Florian Kirsch, Juergen Doeller, @@ -69,103 +77,100 @@ CSGTerm *CSGTerm::normalize() // University of Potsdam, Hasso-Plattner-Institute, Germany // http://www.opencsg.org/data/csg_freenix2005_paper.pdf - if (type == TYPE_PRIMITIVE) - return link(); - - CSGTerm *t1, *t2, *x, *y; + if (term->type == TYPE_PRIMITIVE) return term; - x = left->normalize(); - y = right->normalize(); + shared_ptr x = normalize(term->left); + shared_ptr y = normalize(term->right); - if (x != left || y != right) { - t1 = new CSGTerm(type, x, y); - } else { - t1 = link(); - x->unlink(); - y->unlink(); - } + shared_ptr t1(term); + if (x != term->left || y != term->right) t1.reset(new CSGTerm(term->type, x, y)); + shared_ptr t2; while (1) { - t2 = t1->normalize_tail(); - t1->unlink(); - if (t1 == t2) - break; + t2 = normalize_tail(t1); + if (t1 == t2) break; t1 = t2; } return t1; } -CSGTerm *CSGTerm::normalize_tail() +shared_ptr CSGTerm::normalize_tail(shared_ptr &term) { - CSGTerm *x, *y, *z; - // Part A: The 'x . (y . z)' expressions - x = left; - y = right->left; - z = right->right; + shared_ptr x = term->left; + shared_ptr y = term->right->left; + shared_ptr z = term->right->right; - // 1. x - (y + z) -> (x - y) - z - if (type == TYPE_DIFFERENCE && right->type == TYPE_UNION) - return new CSGTerm(TYPE_DIFFERENCE, new CSGTerm(TYPE_DIFFERENCE, x->link(), y->link()), z->link()); + CSGTerm *result = NULL; + // 1. x - (y + z) -> (x - y) - z + if (term->type == TYPE_DIFFERENCE && term->right->type == TYPE_UNION) { + result = new CSGTerm(TYPE_DIFFERENCE, + shared_ptr(new CSGTerm(TYPE_DIFFERENCE, x, y)), + z); + } // 2. x * (y + z) -> (x * y) + (x * z) - if (type == TYPE_INTERSECTION && right->type == TYPE_UNION) - return new CSGTerm(TYPE_UNION, new CSGTerm(TYPE_INTERSECTION, x->link(), y->link()), new CSGTerm(TYPE_INTERSECTION, x->link(), z->link())); - + else if (term->type == TYPE_INTERSECTION && term->right->type == TYPE_UNION) { + result = new CSGTerm(TYPE_UNION, + new CSGTerm(TYPE_INTERSECTION, x, y), + new CSGTerm(TYPE_INTERSECTION, x, z)); + } // 3. x - (y * z) -> (x - y) + (x - z) - if (type == TYPE_DIFFERENCE && right->type == TYPE_INTERSECTION) - return new CSGTerm(TYPE_UNION, new CSGTerm(TYPE_DIFFERENCE, x->link(), y->link()), new CSGTerm(TYPE_DIFFERENCE, x->link(), z->link())); - + else if (term->type == TYPE_DIFFERENCE && term->right->type == TYPE_INTERSECTION) { + result = new CSGTerm(TYPE_UNION, + new CSGTerm(TYPE_DIFFERENCE, x, y), + new CSGTerm(TYPE_DIFFERENCE, x, z)); + } // 4. x * (y * z) -> (x * y) * z - if (type == TYPE_INTERSECTION && right->type == TYPE_INTERSECTION) - return new CSGTerm(TYPE_INTERSECTION, new CSGTerm(TYPE_INTERSECTION, x->link(), y->link()), z->link()); - + else if (term->type == TYPE_INTERSECTION && term->right->type == TYPE_INTERSECTION) { + result = new CSGTerm(TYPE_INTERSECTION, + shared_ptr(new CSGTerm(TYPE_INTERSECTION, x, y)), + z); + } // 5. x - (y - z) -> (x - y) + (x * z) - if (type == TYPE_DIFFERENCE && right->type == TYPE_DIFFERENCE) - return new CSGTerm(TYPE_UNION, new CSGTerm(TYPE_DIFFERENCE, x->link(), y->link()), new CSGTerm(TYPE_INTERSECTION, x->link(), z->link())); - + else if (term->type == TYPE_DIFFERENCE && term->right->type == TYPE_DIFFERENCE) { + result = new CSGTerm(TYPE_UNION, + new CSGTerm(TYPE_DIFFERENCE, x, y), + new CSGTerm(TYPE_INTERSECTION, x, z)); + } // 6. x * (y - z) -> (x * y) - z - if (type == TYPE_INTERSECTION && right->type == TYPE_DIFFERENCE) - return new CSGTerm(TYPE_DIFFERENCE, new CSGTerm(TYPE_INTERSECTION, x->link(), y->link()), z->link()); + else if (term->type == TYPE_INTERSECTION && term->right->type == TYPE_DIFFERENCE) { + result = new CSGTerm(TYPE_DIFFERENCE, + shared_ptr(new CSGTerm(TYPE_INTERSECTION, x, y)), + z); + } + if (result) return shared_ptr(result); // Part B: The '(x . y) . z' expressions - x = left->left; - y = left->right; - z = right; + x = term->left->left; + y = term->left->right; + z = term->right; // 7. (x - y) * z -> (x * z) - y - if (left->type == TYPE_DIFFERENCE && type == TYPE_INTERSECTION) - return new CSGTerm(TYPE_DIFFERENCE, new CSGTerm(TYPE_INTERSECTION, x->link(), z->link()), y->link()); - + if (term->left->type == TYPE_DIFFERENCE && term->type == TYPE_INTERSECTION) { + result = new CSGTerm(TYPE_DIFFERENCE, + shared_ptr(new CSGTerm(TYPE_INTERSECTION, x, z)), + y); + } // 8. (x + y) - z -> (x - z) + (y - z) - if (left->type == TYPE_UNION && type == TYPE_DIFFERENCE) - return new CSGTerm(TYPE_UNION, new CSGTerm(TYPE_DIFFERENCE, x->link(), z->link()), new CSGTerm(TYPE_DIFFERENCE, y->link(), z->link())); - + else if (term->left->type == TYPE_UNION && term->type == TYPE_DIFFERENCE) { + result = new CSGTerm(TYPE_UNION, + new CSGTerm(TYPE_DIFFERENCE, x, z), + new CSGTerm(TYPE_DIFFERENCE, y, z)); + } // 9. (x + y) * z -> (x * z) + (y * z) - if (left->type == TYPE_UNION && type == TYPE_INTERSECTION) - return new CSGTerm(TYPE_UNION, new CSGTerm(TYPE_INTERSECTION, x->link(), z->link()), new CSGTerm(TYPE_INTERSECTION, y->link(), z->link())); - - return link(); -} - -CSGTerm *CSGTerm::link() -{ - refcounter++; - return this; -} - -void CSGTerm::unlink() -{ - if (--refcounter <= 0) { - if (left) - left->unlink(); - if (right) - right->unlink(); - delete this; + else if (term->left->type == TYPE_UNION && term->type == TYPE_INTERSECTION) { + result = new CSGTerm(TYPE_UNION, + new CSGTerm(TYPE_INTERSECTION, x, z), + new CSGTerm(TYPE_INTERSECTION, y, z)); } + + if (result) return shared_ptr(result); + + return term; } std::string CSGTerm::dump() @@ -197,7 +202,7 @@ void CSGChain::add(const shared_ptr &polyset, const Transform3d &m, dou labels.push_back(label); } -void CSGChain::import(CSGTerm *term, CSGTerm::type_e type) +void CSGChain::import(shared_ptr term, CSGTerm::type_e type) { if (term->type == CSGTerm::TYPE_PRIMITIVE) { add(term->polyset, term->m, term->color, type, term->label); diff --git a/src/csgterm.h b/src/csgterm.h index 1d9d9fd..1895839 100644 --- a/src/csgterm.h +++ b/src/csgterm.h @@ -21,20 +21,19 @@ public: type_e type; shared_ptr polyset; std::string label; - CSGTerm *left; - CSGTerm *right; + shared_ptr left; + shared_ptr right; Transform3d m; double color[4]; - int refcounter; CSGTerm(const shared_ptr &polyset, const Transform3d &matrix, const double color[4], const std::string &label); + CSGTerm(type_e type, shared_ptr left, shared_ptr right); CSGTerm(type_e type, CSGTerm *left, CSGTerm *right); + ~CSGTerm(); - CSGTerm *normalize(); - CSGTerm *normalize_tail(); + static shared_ptr normalize(shared_ptr &term); + static shared_ptr normalize_tail(shared_ptr &term); - CSGTerm *link(); - void unlink(); std::string dump(); }; @@ -50,7 +49,7 @@ public: CSGChain(); void add(const shared_ptr &polyset, const Transform3d &m, double *color, CSGTerm::type_e type, std::string label); - void import(CSGTerm *term, CSGTerm::type_e type = CSGTerm::TYPE_UNION); + void import(shared_ptr term, CSGTerm::type_e type = CSGTerm::TYPE_UNION); std::string dump(); BoundingBox getBoundingBox() const; diff --git a/src/mainwin.cc b/src/mainwin.cc index 29c84b0..c81f2f2 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -147,8 +147,6 @@ MainWindow::MainWindow(const QString &filename) root_module = NULL; absolute_root_node = NULL; - root_raw_term = NULL; - root_norm_term = NULL; root_chain = NULL; #ifdef ENABLE_CGAL this->root_N = NULL; @@ -619,30 +617,18 @@ void MainWindow::compile(bool procevents) this->absolute_root_node = NULL; } - if (this->root_raw_term) { - this->root_raw_term->unlink(); - this->root_raw_term = NULL; - } - - if (this->root_norm_term) { - this->root_norm_term->unlink(); - this->root_norm_term = NULL; - } + this->root_raw_term.reset(); + this->root_norm_term.reset(); if (this->root_chain) { delete this->root_chain; this->root_chain = NULL; } - std::for_each(this->highlight_terms.begin(), this->highlight_terms.end(), - bind(&CSGTerm::unlink, _1)); - this->highlight_terms.clear(); delete this->highlights_chain; this->highlights_chain = NULL; - std::for_each(this->background_terms.begin(), this->background_terms.end(), - bind(&CSGTerm::unlink, _1)); this->background_terms.clear(); delete this->background_chain; this->background_chain = NULL; @@ -771,7 +757,7 @@ void MainWindow::compileCSG(bool procevents) CGALEvaluator cgalevaluator(this->tree); PolySetCGALEvaluator psevaluator(cgalevaluator); CSGTermEvaluator csgrenderer(this->tree, &psevaluator); - root_raw_term = csgrenderer.evaluateCSGTerm(*root_node, highlight_terms, background_terms); + this->root_raw_term = csgrenderer.evaluateCSGTerm(*root_node, highlight_terms, background_terms); if (!root_raw_term) { PRINT("ERROR: CSG generation failed! (no top level object found)"); if (procevents) @@ -794,21 +780,19 @@ void MainWindow::compileCSG(bool procevents) if (procevents) QApplication::processEvents(); - root_norm_term = root_raw_term->link(); + this->root_norm_term = this->root_raw_term; // CSG normalization while (1) { - CSGTerm *n = root_norm_term->normalize(); - root_norm_term->unlink(); - if (root_norm_term == n) - break; - root_norm_term = n; + shared_ptr n = CSGTerm::normalize(this->root_norm_term); + if (this->root_norm_term == n) break; + this->root_norm_term = n; } - assert(root_norm_term); + assert(this->root_norm_term); root_chain = new CSGChain(); - root_chain->import(root_norm_term); + root_chain->import(this->root_norm_term); if (highlight_terms.size() > 0) { @@ -819,10 +803,8 @@ void MainWindow::compileCSG(bool procevents) highlights_chain = new CSGChain(); for (unsigned int i = 0; i < highlight_terms.size(); i++) { while (1) { - CSGTerm *n = highlight_terms[i]->normalize(); - highlight_terms[i]->unlink(); - if (highlight_terms[i] == n) - break; + shared_ptr n = CSGTerm::normalize(highlight_terms[i]); + if (highlight_terms[i] == n) break; highlight_terms[i] = n; } highlights_chain->import(highlight_terms[i]); @@ -838,10 +820,8 @@ void MainWindow::compileCSG(bool procevents) background_chain = new CSGChain(); for (unsigned int i = 0; i < background_terms.size(); i++) { while (1) { - CSGTerm *n = background_terms[i]->normalize(); - background_terms[i]->unlink(); - if (background_terms[i] == n) - break; + shared_ptr n = CSGTerm::normalize(background_terms[i]); + if (background_terms[i] == n) break; background_terms[i] = n; } background_chain->import(background_terms[i]); diff --git a/tests/csgtermtest.cc b/tests/csgtermtest.cc index 2383126..aabbc05 100644 --- a/tests/csgtermtest.cc +++ b/tests/csgtermtest.cc @@ -116,11 +116,11 @@ int main(int argc, char **argv) // cout << tree.getString(*root_node) << "\n"; - std::vector highlights; - std::vector background; + std::vector > highlights; + std::vector > background; PolySetEvaluator psevaluator(tree); CSGTermEvaluator evaluator(tree, &psevaluator); - CSGTerm *root_term = evaluator.evaluateCSGTerm(*root_node, highlights, background); + shared_ptr root_term = evaluator.evaluateCSGTerm(*root_node, highlights, background); // cout << "Stored terms: " << evaluator.stored_term.size() << "\n"; // for (map::iterator iter = evaluator.stored_term.begin(); @@ -143,7 +143,6 @@ int main(int argc, char **argv) } outfile.close(); - if (root_term) root_term->unlink(); delete root_node; delete root_module; diff --git a/tests/csgtestcore.cc b/tests/csgtestcore.cc index 49bd473..864d40e 100644 --- a/tests/csgtestcore.cc +++ b/tests/csgtestcore.cc @@ -39,21 +39,18 @@ class CsgInfo { public: CsgInfo(); - CSGTerm *root_norm_term; // Normalized CSG products + shared_ptr root_norm_term; // Normalized CSG products class CSGChain *root_chain; - std::vector highlight_terms; + std::vector > highlight_terms; CSGChain *highlights_chain; - std::vector background_terms; + std::vector > background_terms; CSGChain *background_chain; OffscreenView *glview; }; CsgInfo::CsgInfo() { - root_norm_term = NULL; root_chain = NULL; - highlight_terms = std::vector(); highlights_chain = NULL; - background_terms = std::vector(); background_chain = NULL; glview = NULL; } @@ -129,9 +126,9 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type) CsgInfo csgInfo = CsgInfo(); CGALEvaluator cgalevaluator(tree); CSGTermEvaluator evaluator(tree, &cgalevaluator.psevaluator); - CSGTerm *root_raw_term = evaluator.evaluateCSGTerm(*root_node, - csgInfo.highlight_terms, - csgInfo.background_terms); + shared_ptr root_raw_term = evaluator.evaluateCSGTerm(*root_node, + csgInfo.highlight_terms, + csgInfo.background_terms); if (!root_raw_term) { cerr << "Error: CSG generation failed! (no top level object found)\n"; @@ -139,16 +136,17 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type) } // CSG normalization - csgInfo.root_norm_term = root_raw_term->link(); + csgInfo.root_norm_term = root_raw_term; while (1) { - CSGTerm *n = csgInfo.root_norm_term->normalize(); - csgInfo.root_norm_term->unlink(); - if (csgInfo.root_norm_term == n) - break; + shared_ptr n = CSGTerm::normalize(csgInfo.root_norm_term); + if (csgInfo.root_norm_term == n) break; csgInfo.root_norm_term = n; } assert(csgInfo.root_norm_term); + if (csgInfo.root_norm_term.use_count() <= 1) { + fprintf(stderr, "XXX\n"); + } csgInfo.root_chain = new CSGChain(); csgInfo.root_chain->import(csgInfo.root_norm_term); @@ -160,10 +158,8 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type) csgInfo.highlights_chain = new CSGChain(); for (unsigned int i = 0; i < csgInfo.highlight_terms.size(); i++) { while (1) { - CSGTerm *n = csgInfo.highlight_terms[i]->normalize(); - csgInfo.highlight_terms[i]->unlink(); - if (csgInfo.highlight_terms[i] == n) - break; + shared_ptr n = CSGTerm::normalize(csgInfo.highlight_terms[i]); + if (csgInfo.highlight_terms[i] == n) break; csgInfo.highlight_terms[i] = n; } csgInfo.highlights_chain->import(csgInfo.highlight_terms[i]); @@ -176,10 +172,8 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type) csgInfo.background_chain = new CSGChain(); for (unsigned int i = 0; i < csgInfo.background_terms.size(); i++) { while (1) { - CSGTerm *n = csgInfo.background_terms[i]->normalize(); - csgInfo.background_terms[i]->unlink(); - if (csgInfo.background_terms[i] == n) - break; + shared_ptr n = CSGTerm::normalize(csgInfo.background_terms[i]); + if (csgInfo.background_terms[i] == n) break; csgInfo.background_terms[i] = n; } csgInfo.background_chain->import(csgInfo.background_terms[i]); -- cgit v0.10.1 From bb0ec94290733835df0716531c30460fc5b5210a Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Tue, 6 Dec 2011 01:43:44 +0100 Subject: #undef NDEBUG before including any CGAL headers diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index 78b9c78..1772354 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -16,9 +16,15 @@ #include "CGALCache.h" #include "cgal.h" #include "cgalutils.h" -#include -#include + +#ifdef NDEBUG +#define PREV_NDEBUG NDEBUG +#undef NDEBUG +#endif #include +#ifdef PREV_NDEBUG +#define NDEBUG PREV_NDEBUG +#endif #include #include diff --git a/src/CGAL_Nef_polyhedron.cc b/src/CGAL_Nef_polyhedron.cc index 61ca2f8..8c65777 100644 --- a/src/CGAL_Nef_polyhedron.cc +++ b/src/CGAL_Nef_polyhedron.cc @@ -5,7 +5,6 @@ #include "polyset.h" #include "dxfdata.h" #include "dxftess.h" -#include CGAL_Nef_polyhedron::CGAL_Nef_polyhedron(CGAL_Nef_polyhedron2 *p) { diff --git a/src/cgal.h b/src/cgal.h index 669e5b1..9810340 100644 --- a/src/cgal.h +++ b/src/cgal.h @@ -16,6 +16,16 @@ using boost::uintmax_t; #error CGAL >= 3.6 is required! #endif +// NDEBUG must be disabled when including CGAL headers, otherwise CGAL assertions +// will not be thrown, causing OpenSCAD's CGAL error checking to fail. +// To be on the safe side, this has to be done when including any CGAL header file. +// FIXME: It might be possible to rewrite the error checking to get rid of this +// requirement. kintel 20111206. +#ifdef NDEBUG +#define PREV_NDEBUG NDEBUG +#undef NDEBUG +#endif + #include #include #include @@ -26,6 +36,11 @@ using boost::uintmax_t; #include #include #include +#include +#include + +#include +#include typedef CGAL::Gmpq NT; typedef CGAL::Extended_cartesian CGAL_Kernel2; @@ -44,6 +59,10 @@ typedef CGAL::Polyhedron_3 CGAL_Polyhedron; typedef CGAL_Polyhedron::HalfedgeDS CGAL_HDS; typedef CGAL::Polyhedron_incremental_builder_3 CGAL_Polybuilder; +#ifdef PREV_NDEBUG +#define NDEBUG PREV_NDEBUG +#endif + #endif /* ENABLE_CGAL */ #endif diff --git a/src/cgaladv_minkowski2.cc b/src/cgaladv_minkowski2.cc index 4ce684f..583217b 100644 --- a/src/cgaladv_minkowski2.cc +++ b/src/cgaladv_minkowski2.cc @@ -30,9 +30,6 @@ #include "grid.h" #include "cgal.h" - -#include - extern CGAL_Poly2 nef2p2(CGAL_Nef_polyhedron2 p); //----------------------------------------------------------------------------- diff --git a/src/cgalutils.cc b/src/cgalutils.cc index 1de7ab4..64782fb 100644 --- a/src/cgalutils.cc +++ b/src/cgalutils.cc @@ -5,8 +5,6 @@ #include "printutils.h" #include "cgal.h" -#include -#include #include diff --git a/src/dxftess-cgal.cc b/src/dxftess-cgal.cc index cf5b75d..5b4e953 100644 --- a/src/dxftess-cgal.cc +++ b/src/dxftess-cgal.cc @@ -3,15 +3,22 @@ #include "dxfdata.h" #include "polyset.h" #include "grid.h" +#include "cgal.h" +#ifdef NDEBUG +#define PREV_NDEBUG NDEBUG +#undef NDEBUG +#endif #include #include #include #include #include #include -#include -#include +#include +#ifdef PREV_NDEBUG +#define NDEBUG PREV_NDEBUG +#endif typedef CGAL::Exact_predicates_inexact_constructions_kernel K; typedef CGAL::Triangulation_vertex_base_2 Vb; @@ -23,8 +30,6 @@ typedef CGAL::Constrained_Delaunay_triangulation_2 CDT; typedef CDT::Vertex_handle Vertex_handle; typedef CDT::Point CDTPoint; -#include - #include template class DummyCriteria { diff --git a/src/openscad.cc b/src/openscad.cc index 67112d8..0d5b25e 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -42,7 +42,6 @@ #ifdef ENABLE_CGAL #include "CGAL_Nef_polyhedron.h" -#include #include "CGALEvaluator.h" #include "PolySetCGALEvaluator.h" #endif diff --git a/tests/cgalpngtest.cc b/tests/cgalpngtest.cc index fcc5977..800a829 100644 --- a/tests/cgalpngtest.cc +++ b/tests/cgalpngtest.cc @@ -54,10 +54,6 @@ #include #include -#ifdef ENABLE_CGAL -#include -#endif - std::string commandline_commands; QString currentdir; QString examplesdir; -- cgit v0.10.1