diff options
Diffstat (limited to 'src/csgops.cc')
-rw-r--r-- | src/csgops.cc | 137 |
1 files changed, 19 insertions, 118 deletions
diff --git a/src/csgops.cc b/src/csgops.cc index 55d91d2..53e9ed6 100644 --- a/src/csgops.cc +++ b/src/csgops.cc @@ -24,22 +24,14 @@ * */ +#include "csgnode.h" + #include "module.h" -#include "node.h" #include "csgterm.h" #include "builtin.h" #include "printutils.h" -#ifdef ENABLE_CGAL -# include "cgal.h" -# include <CGAL/assertions_behaviour.h> -# include <CGAL/exceptions.h> -#endif - -enum csg_type_e { - CSG_TYPE_UNION, - CSG_TYPE_DIFFERENCE, - CSG_TYPE_INTERSECTION -}; +#include <sstream> +#include <assert.h> class CsgModule : public AbstractModule { @@ -49,18 +41,6 @@ public: virtual AbstractNode *evaluate(const Context *ctx, const ModuleInstantiation *inst) const; }; -class CsgNode : public AbstractNode -{ -public: - csg_type_e type; - CsgNode(const ModuleInstantiation *mi, csg_type_e type) : AbstractNode(mi), type(type) { } -#ifdef ENABLE_CGAL - virtual CGAL_Nef_polyhedron render_cgal_nef_polyhedron() const; -#endif - CSGTerm *render_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const; - virtual QString dump(QString indent) const; -}; - AbstractNode *CsgModule::evaluate(const Context*, const ModuleInstantiation *inst) const { CsgNode *node = new CsgNode(inst, type); @@ -72,105 +52,26 @@ AbstractNode *CsgModule::evaluate(const Context*, const ModuleInstantiation *ins return node; } -#ifdef ENABLE_CGAL - -CGAL_Nef_polyhedron CsgNode::render_cgal_nef_polyhedron() const +std::string CsgNode::toString() const { - QString cache_id = mk_cache_id(); - if (cgal_nef_cache.contains(cache_id)) { - progress_report(); - PRINT(cgal_nef_cache[cache_id]->msg); - return cgal_nef_cache[cache_id]->N; - } - - print_messages_push(); - - CGAL::Failure_behaviour old_behaviour = CGAL::set_error_behaviour(CGAL::THROW_EXCEPTION); - bool first = true; - CGAL_Nef_polyhedron N; - try { - foreach (AbstractNode *v, children) { - if (v->modinst->tag_background) - continue; - if (first) { - N = v->render_cgal_nef_polyhedron(); - if (N.dim != 0) - first = false; - } else if (N.dim == 2) { - if (type == CSG_TYPE_UNION) { - N.p2 += v->render_cgal_nef_polyhedron().p2; - } else if (type == CSG_TYPE_DIFFERENCE) { - N.p2 -= v->render_cgal_nef_polyhedron().p2; - } else if (type == CSG_TYPE_INTERSECTION) { - N.p2 *= v->render_cgal_nef_polyhedron().p2; - } - } else if (N.dim == 3) { - if (type == CSG_TYPE_UNION) { - N.p3 += v->render_cgal_nef_polyhedron().p3; - } else if (type == CSG_TYPE_DIFFERENCE) { - N.p3 -= v->render_cgal_nef_polyhedron().p3; - } else if (type == CSG_TYPE_INTERSECTION) { - N.p3 *= v->render_cgal_nef_polyhedron().p3; - } - } - v->progress_report(); - } - cgal_nef_cache.insert(cache_id, new cgal_nef_cache_entry(N), N.weight()); - } - catch (CGAL::Assertion_exception e) { - PRINTF("ERROR: Illegal polygonal object - make sure all polygons are defined with the same winding order. Skipping affected object."); - } - CGAL::set_error_behaviour(old_behaviour); - - print_messages_pop(); - progress_report(); - - return N; -} - -#endif /* ENABLE_CGAL */ - -CSGTerm *CsgNode::render_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const -{ - CSGTerm *t1 = NULL; - foreach (AbstractNode *v, children) { - CSGTerm *t2 = v->render_csg_term(m, highlights, background); - if (t2 && !t1) { - t1 = t2; - } else if (t2 && t1) { - if (type == CSG_TYPE_UNION) { - t1 = new CSGTerm(CSGTerm::TYPE_UNION, t1, t2); - } else if (type == CSG_TYPE_DIFFERENCE) { - t1 = new CSGTerm(CSGTerm::TYPE_DIFFERENCE, t1, t2); - } else if (type == CSG_TYPE_INTERSECTION) { - t1 = new CSGTerm(CSGTerm::TYPE_INTERSECTION, t1, t2); - } - } - } - if (t1 && modinst->tag_highlight && highlights) - highlights->append(t1->link()); - if (t1 && modinst->tag_background && background) { - background->append(t1); - return NULL; - } - return t1; + return this->name() + "()"; } -QString CsgNode::dump(QString indent) const +std::string CsgNode::name() const { - if (dump_cache.isEmpty()) { - QString text = indent + QString("n%1: ").arg(idx); - if (type == CSG_TYPE_UNION) - text += "union() {\n"; - if (type == CSG_TYPE_DIFFERENCE) - text += "difference() {\n"; - if (type == CSG_TYPE_INTERSECTION) - text += "intersection() {\n"; - foreach (AbstractNode *v, children) - text += v->dump(indent + QString("\t")); - ((AbstractNode*)this)->dump_cache = text + indent + "}\n"; + switch (this->type) { + case CSG_TYPE_UNION: + return "union"; + break; + case CSG_TYPE_DIFFERENCE: + return "difference"; + break; + case CSG_TYPE_INTERSECTION: + return "intersection"; + break; + default: + assert(false); } - return dump_cache; } void register_builtin_csgops() |