Merge branch 'visitor' of github.com:openscad/openscad into visitor

stl_dim
Marius Kintel 2011-08-28 04:43:44 +02:00
commit f3775d4bdc
5 changed files with 32 additions and 31 deletions

View File

@ -40,7 +40,7 @@ bool CGALEvaluator::isCached(const AbstractNode &node) const
Modifies target by applying op to target and src:
target = target [op] src
*/
void CGALEvaluator::process(CGAL_Nef_polyhedron &target, const CGAL_Nef_polyhedron &src, CsgOp op)
void CGALEvaluator::process(CGAL_Nef_polyhedron &target, const CGAL_Nef_polyhedron &src, CGALEvaluator::CsgOp op)
{
if (target.dim != 2 && target.dim != 3) {
assert(false && "Dimension of Nef polyhedron must be 2 or 3");
@ -48,19 +48,19 @@ void CGALEvaluator::process(CGAL_Nef_polyhedron &target, const CGAL_Nef_polyhedr
if (target.dim == 2) {
switch (op) {
case UNION:
case CGE_UNION:
target.p2 += src.p2;
break;
case INTERSECTION:
case CGE_INTERSECTION:
target.p2 *= src.p2;
break;
case DIFFERENCE:
case CGE_DIFFERENCE:
target.p2 -= src.p2;
break;
case MINKOWSKI:
case CGE_MINKOWSKI:
target.p2 = minkowski2(target.p2, src.p2);
break;
case HULL:
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);
@ -69,19 +69,19 @@ void CGALEvaluator::process(CGAL_Nef_polyhedron &target, const CGAL_Nef_polyhedr
}
else if (target.dim == 3) {
switch (op) {
case UNION:
case CGE_UNION:
target.p3 += src.p3;
break;
case INTERSECTION:
case CGE_INTERSECTION:
target.p3 *= src.p3;
break;
case DIFFERENCE:
case CGE_DIFFERENCE:
target.p3 -= src.p3;
break;
case MINKOWSKI:
case CGE_MINKOWSKI:
target.p3 = minkowski3(target.p3, src.p3);
break;
case HULL:
case CGE_HULL:
// FIXME: Print warning: hull() not supported in 3D
break;
}
@ -130,7 +130,7 @@ Response CGALEvaluator::visit(State &state, const AbstractNode &node)
{
if (state.isPrefix() && isCached(node)) return PruneTraversal;
if (state.isPostfix()) {
if (!isCached(node)) applyToChildren(node, UNION);
if (!isCached(node)) applyToChildren(node, CGE_UNION);
addToParent(state, node);
}
return ContinueTraversal;
@ -140,7 +140,7 @@ Response CGALEvaluator::visit(State &state, const AbstractIntersectionNode &node
{
if (state.isPrefix() && isCached(node)) return PruneTraversal;
if (state.isPostfix()) {
if (!isCached(node)) applyToChildren(node, INTERSECTION);
if (!isCached(node)) applyToChildren(node, CGE_INTERSECTION);
addToParent(state, node);
}
return ContinueTraversal;
@ -151,16 +151,16 @@ Response CGALEvaluator::visit(State &state, const CsgNode &node)
if (state.isPrefix() && isCached(node)) return PruneTraversal;
if (state.isPostfix()) {
if (!isCached(node)) {
CsgOp op;
CGALEvaluator::CsgOp op;
switch (node.type) {
case CSG_TYPE_UNION:
op = UNION;
op = CGE_UNION;
break;
case CSG_TYPE_DIFFERENCE:
op = DIFFERENCE;
op = CGE_DIFFERENCE;
break;
case CSG_TYPE_INTERSECTION:
op = INTERSECTION;
op = CGE_INTERSECTION;
break;
}
applyToChildren(node, op);
@ -176,7 +176,7 @@ Response CGALEvaluator::visit(State &state, const TransformNode &node)
if (state.isPostfix()) {
if (!isCached(node)) {
// First union all children
applyToChildren(node, UNION);
applyToChildren(node, CGE_UNION);
// Then apply transform
CGAL_Nef_polyhedron N = this->cache[this->tree.getString(node)];
@ -235,7 +235,7 @@ Response CGALEvaluator::visit(State &state, const AbstractPolyNode &node)
if (state.isPostfix()) {
if (!isCached(node)) {
// First union all children
applyToChildren(node, UNION);
applyToChildren(node, CGE_UNION);
// Then apply polyset operation
PolySet *ps = node.evaluate_polyset(AbstractPolyNode::RENDER_CGAL, &this->psevaluator);

View File

@ -22,7 +22,7 @@ using std::pair;
class CGALEvaluator : public Visitor
{
public:
enum CsgOp {UNION, INTERSECTION, DIFFERENCE, MINKOWSKI, HULL};
enum CsgOp {CGE_UNION, CGE_INTERSECTION, CGE_DIFFERENCE, CGE_MINKOWSKI, CGE_HULL};
// 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() {}

View File

@ -45,11 +45,11 @@ void CSGTermEvaluator::applyToChildren(const AbstractNode &node, CSGTermEvaluato
if (t2 && !t1) {
t1 = t2;
} else if (t2 && t1) {
if (op == UNION) {
if (op == CSGT_UNION) {
t1 = new CSGTerm(CSGTerm::TYPE_UNION, t1, t2);
} else if (op == DIFFERENCE) {
} else if (op == CSGT_DIFFERENCE) {
t1 = new CSGTerm(CSGTerm::TYPE_DIFFERENCE, t1, t2);
} else if (op == INTERSECTION) {
} else if (op == CSGT_INTERSECTION) {
t1 = new CSGTerm(CSGTerm::TYPE_INTERSECTION, t1, t2);
}
}
@ -67,7 +67,7 @@ void CSGTermEvaluator::applyToChildren(const AbstractNode &node, CSGTermEvaluato
Response CSGTermEvaluator::visit(State &state, const AbstractNode &node)
{
if (state.isPostfix()) {
applyToChildren(node, UNION);
applyToChildren(node, CSGT_UNION);
addToParent(state, node);
}
return ContinueTraversal;
@ -76,7 +76,7 @@ Response CSGTermEvaluator::visit(State &state, const AbstractNode &node)
Response CSGTermEvaluator::visit(State &state, const AbstractIntersectionNode &node)
{
if (state.isPostfix()) {
applyToChildren(node, INTERSECTION);
applyToChildren(node, CSGT_INTERSECTION);
addToParent(state, node);
}
return ContinueTraversal;
@ -120,13 +120,13 @@ Response CSGTermEvaluator::visit(State &state, const CsgNode &node)
CsgOp op;
switch (node.type) {
case CSG_TYPE_UNION:
op = UNION;
op = CSGT_UNION;
break;
case CSG_TYPE_DIFFERENCE:
op = DIFFERENCE;
op = CSGT_DIFFERENCE;
break;
case CSG_TYPE_INTERSECTION:
op = INTERSECTION;
op = CSGT_INTERSECTION;
break;
}
applyToChildren(node, op);
@ -157,7 +157,7 @@ Response CSGTermEvaluator::visit(State &state, const TransformNode &node)
state.setMatrix(m);
}
if (state.isPostfix()) {
applyToChildren(node, UNION);
applyToChildren(node, CSGT_UNION);
addToParent(state, node);
}
return ContinueTraversal;
@ -168,7 +168,7 @@ Response CSGTermEvaluator::visit(State &state, const RenderNode &node)
{
PRINT("WARNING: Found render() statement but compiled without CGAL support!");
if (state.isPostfix()) {
applyToChildren(node, UNION);
applyToChildren(node, CSGT_UNION);
addToParent(state, node);
}
return ContinueTraversal;

View File

@ -34,7 +34,7 @@ public:
vector<CSGTerm*> &background);
private:
enum CsgOp {UNION, INTERSECTION, DIFFERENCE, MINKOWSKI};
enum CsgOp {CSGT_UNION, CSGT_INTERSECTION, CSGT_DIFFERENCE, CSGT_MINKOWSKI};
void addToParent(const State &state, const AbstractNode &node);
void applyToChildren(const AbstractNode &node, CSGTermEvaluator::CsgOp op);

View File

@ -30,6 +30,7 @@
#include "dxfdim.h"
#include "builtin.h"
#include <sstream>
#include <ctime>
#include "mathc99.h"
AbstractFunction::~AbstractFunction()