summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README10
-rwxr-xr-xscripts/macosx-build-dependencies.sh4
-rw-r--r--src/CGALEvaluator.cc10
-rw-r--r--src/CGAL_Nef_polyhedron.cc1
-rw-r--r--src/CSGTermEvaluator.cc47
-rw-r--r--src/CSGTermEvaluator.h13
-rw-r--r--src/MainWindow.h9
-rw-r--r--src/OpenCSGRenderer.cc2
-rw-r--r--src/ThrownTogetherRenderer.cc2
-rw-r--r--src/Tree.cc6
-rw-r--r--src/Tree.h2
-rw-r--r--src/cgal.h19
-rw-r--r--src/cgaladv_minkowski2.cc3
-rw-r--r--src/cgalutils.cc2
-rw-r--r--src/csgterm.cc153
-rw-r--r--src/csgterm.h15
-rw-r--r--src/dxftess-cgal.cc13
-rw-r--r--src/expr.cc2
-rw-r--r--src/glview.cc1
-rw-r--r--src/mainwin.cc50
-rw-r--r--src/openscad.cc1
-rw-r--r--src/primitives.cc2
-rw-r--r--tests/cgalpngtest.cc4
-rw-r--r--tests/csgtermtest.cc7
-rw-r--r--tests/csgtestcore.cc38
25 files changed, 209 insertions, 207 deletions
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):
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
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 <CGAL/assertions_behaviour.h>
-#include <CGAL/exceptions.h>
+
+#ifdef NDEBUG
+#define PREV_NDEBUG NDEBUG
+#undef NDEBUG
+#endif
#include <CGAL/convex_hull_3.h>
+#ifdef PREV_NDEBUG
+#define NDEBUG PREV_NDEBUG
+#endif
#include <string>
#include <map>
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/minkowski_sum_3.h>
CGAL_Nef_polyhedron::CGAL_Nef_polyhedron(CGAL_Nef_polyhedron2 *p)
{
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 <iostream>
#include <assert.h>
#include <cstddef>
+#include <boost/foreach.hpp>
/*!
\class CSGTermEvaluator
@@ -26,9 +27,9 @@
with OpenCSG.
*/
-CSGTerm *CSGTermEvaluator::evaluateCSGTerm(const AbstractNode &node,
- std::vector<CSGTerm*> &highlights,
- std::vector<CSGTerm*> &background)
+shared_ptr<CSGTerm> CSGTermEvaluator::evaluateCSGTerm(const AbstractNode &node,
+ std::vector<shared_ptr<CSGTerm> > &highlights,
+ std::vector<shared_ptr<CSGTerm> > &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<CSGTerm> t1;
+ BOOST_FOREACH(const AbstractNode *chnode, this->visitedchildren[node.index()]) {
+ shared_ptr<CSGTerm> 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<CSGTerm*> &highlights,
- std::vector<CSGTerm*> &background,
+static shared_ptr<CSGTerm> evaluate_csg_term_from_ps(const State &state,
+ std::vector<shared_ptr<CSGTerm> > &highlights,
+ std::vector<shared_ptr<CSGTerm> > &background,
const shared_ptr<PolySet> &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<CSGTerm> 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<CSGTerm> t1;
if (this->psevaluator) {
shared_ptr<PolySet> 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<CSGTerm> t1;
shared_ptr<PolySet> 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<CSGTerm> t1;
// FIXME: Calling evaluator directly since we're not a PolyNode. Generalize this.
shared_ptr<PolySet> 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 <vector>
#include <cstddef>
#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<CSGTerm*> &highlights,
- std::vector<CSGTerm*> &background);
+ shared_ptr<class CSGTerm> evaluateCSGTerm(const AbstractNode &node,
+ std::vector<shared_ptr<CSGTerm> > &highlights,
+ std::vector<shared_ptr<CSGTerm> > &background);
private:
enum CsgOp {CSGT_UNION, CSGT_INTERSECTION, CSGT_DIFFERENCE, CSGT_MINKOWSKI};
@@ -38,10 +39,10 @@ private:
std::map<int, ChildList> visitedchildren;
public:
- std::map<int, class CSGTerm*> stored_term; // The term evaluated from each node index
+ std::map<int, shared_ptr<CSGTerm> > stored_term; // The term evaluated from each node index
- std::vector<CSGTerm*> highlights;
- std::vector<CSGTerm*> background;
+ std::vector<shared_ptr<CSGTerm> > highlights;
+ std::vector<shared_ptr<CSGTerm> > 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 <vector>
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<class CSGTerm> root_raw_term; // Result of CSG term rendering
+ shared_ptr<CSGTerm> 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<CSGTerm*> highlight_terms;
+ std::vector<shared_ptr<CSGTerm> > highlight_terms;
CSGChain *highlights_chain;
- std::vector<CSGTerm*> background_terms;
+ std::vector<shared_ptr<CSGTerm> > background_terms;
CSGChain *background_chain;
QString last_compiled_doc;
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/Tree.cc b/src/Tree.cc
index 7c4866b..d27e198 100644
--- a/src/Tree.cc
+++ b/src/Tree.cc
@@ -4,6 +4,12 @@
#include <assert.h>
#include <algorithm>
+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/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 <CGAL/Gmpq.h>
#include <CGAL/Extended_cartesian.h>
#include <CGAL/Nef_polyhedron_2.h>
@@ -26,6 +36,11 @@ using boost::uintmax_t;
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/Polygon_with_holes_2.h>
+#include <CGAL/minkowski_sum_2.h>
+#include <CGAL/minkowski_sum_3.h>
+
+#include <CGAL/assertions_behaviour.h>
+#include <CGAL/exceptions.h>
typedef CGAL::Gmpq NT;
typedef CGAL::Extended_cartesian<NT> CGAL_Kernel2;
@@ -44,6 +59,10 @@ typedef CGAL::Polyhedron_3<CGAL_Kernel3> CGAL_Polyhedron;
typedef CGAL_Polyhedron::HalfedgeDS CGAL_HDS;
typedef CGAL::Polyhedron_incremental_builder_3<CGAL_HDS> 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 <CGAL/minkowski_sum_2.h>
-
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 <CGAL/assertions_behaviour.h>
-#include <CGAL/exceptions.h>
#include <map>
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> &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<CSGTerm> left, shared_ptr<CSGTerm> 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> CSGTerm::normalize(shared_ptr<CSGTerm> &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<CSGTerm> x = normalize(term->left);
+ shared_ptr<CSGTerm> y = normalize(term->right);
- if (x != left || y != right) {
- t1 = new CSGTerm(type, x, y);
- } else {
- t1 = link();
- x->unlink();
- y->unlink();
- }
+ shared_ptr<CSGTerm> t1(term);
+ if (x != term->left || y != term->right) t1.reset(new CSGTerm(term->type, x, y));
+ shared_ptr<CSGTerm> 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> CSGTerm::normalize_tail(shared_ptr<CSGTerm> &term)
{
- CSGTerm *x, *y, *z;
-
// Part A: The 'x . (y . z)' expressions
- x = left;
- y = right->left;
- z = right->right;
+ shared_ptr<CSGTerm> x = term->left;
+ shared_ptr<CSGTerm> y = term->right->left;
+ shared_ptr<CSGTerm> 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<CSGTerm>(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<CSGTerm>(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<CSGTerm>(new CSGTerm(TYPE_INTERSECTION, x, y)),
+ z);
+ }
+ if (result) return shared_ptr<CSGTerm>(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<CSGTerm>(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<CSGTerm>(result);
+
+ return term;
}
std::string CSGTerm::dump()
@@ -197,7 +202,7 @@ void CSGChain::add(const shared_ptr<PolySet> &polyset, const Transform3d &m, dou
labels.push_back(label);
}
-void CSGChain::import(CSGTerm *term, CSGTerm::type_e type)
+void CSGChain::import(shared_ptr<CSGTerm> 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> polyset;
std::string label;
- CSGTerm *left;
- CSGTerm *right;
+ shared_ptr<CSGTerm> left;
+ shared_ptr<CSGTerm> right;
Transform3d m;
double color[4];
- int refcounter;
CSGTerm(const shared_ptr<PolySet> &polyset, const Transform3d &matrix, const double color[4], const std::string &label);
+ CSGTerm(type_e type, shared_ptr<CSGTerm> left, shared_ptr<CSGTerm> right);
CSGTerm(type_e type, CSGTerm *left, CSGTerm *right);
+ ~CSGTerm();
- CSGTerm *normalize();
- CSGTerm *normalize_tail();
+ static shared_ptr<CSGTerm> normalize(shared_ptr<CSGTerm> &term);
+ static shared_ptr<CSGTerm> normalize_tail(shared_ptr<CSGTerm> &term);
- CSGTerm *link();
- void unlink();
std::string dump();
};
@@ -50,7 +49,7 @@ public:
CSGChain();
void add(const shared_ptr<PolySet> &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<CSGTerm> term, CSGTerm::type_e type = CSGTerm::TYPE_UNION);
std::string dump();
BoundingBox getBoundingBox() const;
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 <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/Delaunay_mesher_2.h>
#include <CGAL/Delaunay_mesher_no_edge_refinement_2.h>
#include <CGAL/Delaunay_mesh_face_base_2.h>
#include <CGAL/Delaunay_mesh_criteria_2.h>
-#include <CGAL/assertions_behaviour.h>
-#include <CGAL/exceptions.h>
+#include <CGAL/Mesh_2/Face_badness.h>
+#ifdef PREV_NDEBUG
+#define NDEBUG PREV_NDEBUG
+#endif
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_vertex_base_2<K> Vb;
@@ -23,8 +30,6 @@ typedef CGAL::Constrained_Delaunay_triangulation_2<K, Tds> CDT;
typedef CDT::Vertex_handle Vertex_handle;
typedef CDT::Point CDTPoint;
-#include <CGAL/Mesh_2/Face_badness.h>
-
#include <boost/unordered_map.hpp>
template <class T> class DummyCriteria {
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..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<CSGTerm> 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<CSGTerm> 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<CSGTerm> n = CSGTerm::normalize(background_terms[i]);
+ if (background_terms[i] == n) break;
background_terms[i] = n;
}
background_chain->import(background_terms[i]);
@@ -849,11 +829,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/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 <CGAL/assertions_behaviour.h>
#include "CGALEvaluator.h"
#include "PolySetCGALEvaluator.h"
#endif
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; i<this->points.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;
}
diff --git a/tests/cgalpngtest.cc b/tests/cgalpngtest.cc
index 7aa4b25..608fb08 100644
--- a/tests/cgalpngtest.cc
+++ b/tests/cgalpngtest.cc
@@ -54,10 +54,6 @@
#include <assert.h>
#include <sstream>
-#ifdef ENABLE_CGAL
-#include <CGAL/assertions_behaviour.h>
-#endif
-
std::string commandline_commands;
QString currentdir;
QString examplesdir;
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<CSGTerm*> highlights;
- std::vector<CSGTerm*> background;
+ std::vector<shared_ptr<CSGTerm> > highlights;
+ std::vector<shared_ptr<CSGTerm> > background;
PolySetEvaluator psevaluator(tree);
CSGTermEvaluator evaluator(tree, &psevaluator);
- CSGTerm *root_term = evaluator.evaluateCSGTerm(*root_node, highlights, background);
+ shared_ptr<CSGTerm> root_term = evaluator.evaluateCSGTerm(*root_node, highlights, background);
// cout << "Stored terms: " << evaluator.stored_term.size() << "\n";
// for (map<int, class CSGTerm*>::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 cd4d4b4..4cdc5d8 100644
--- a/tests/csgtestcore.cc
+++ b/tests/csgtestcore.cc
@@ -47,21 +47,18 @@ class CsgInfo
{
public:
CsgInfo();
- CSGTerm *root_norm_term; // Normalized CSG products
+ shared_ptr<CSGTerm> root_norm_term; // Normalized CSG products
class CSGChain *root_chain;
- vector<CSGTerm*> highlight_terms;
+ std::vector<shared_ptr<CSGTerm> > highlight_terms;
CSGChain *highlights_chain;
- vector<CSGTerm*> background_terms;
+ std::vector<shared_ptr<CSGTerm> > background_terms;
CSGChain *background_chain;
OffscreenView *glview;
};
CsgInfo::CsgInfo() {
- root_norm_term = NULL;
root_chain = NULL;
- highlight_terms = vector<CSGTerm*>();
highlights_chain = NULL;
- background_terms = vector<CSGTerm*>();
background_chain = NULL;
glview = NULL;
}
@@ -306,9 +303,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<CSGTerm> 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";
@@ -316,16 +313,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<CSGTerm> 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);
@@ -337,10 +335,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<CSGTerm> 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]);
@@ -353,10 +349,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<CSGTerm> 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]);
contact: Jan Huwald // Impressum