diff options
author | Marius Kintel <kintel@sim.no> | 2010-03-02 18:22:31 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2010-10-31 00:42:34 (GMT) |
commit | 393c5a19fedfa4f97ca939fbcf52c2ccab1cde6a (patch) | |
tree | fbcb75d32e8763aac3f0ad28528936a0ec11930b /src/csgops.cc | |
parent | 746159d1838e895e80725cdc892f7bef85feb1af (diff) |
Committed current version of visitor refactoring
Diffstat (limited to 'src/csgops.cc')
-rw-r--r-- | src/csgops.cc | 65 |
1 files changed, 33 insertions, 32 deletions
diff --git a/src/csgops.cc b/src/csgops.cc index ae97085..5baa149 100644 --- a/src/csgops.cc +++ b/src/csgops.cc @@ -23,22 +23,13 @@ * */ +#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> class CsgModule : public AbstractModule { @@ -48,18 +39,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); @@ -73,7 +52,7 @@ AbstractNode *CsgModule::evaluate(const Context*, const ModuleInstantiation *ins #ifdef ENABLE_CGAL -CGAL_Nef_polyhedron CsgNode::render_cgal_nef_polyhedron() const +CGAL_Nef_polyhedron CsgNode::renderCSGMesh() const { QString cache_id = mk_cache_id(); if (cgal_nef_cache.contains(cache_id)) { @@ -92,24 +71,24 @@ CGAL_Nef_polyhedron CsgNode::render_cgal_nef_polyhedron() const if (v->modinst->tag_background) continue; if (first) { - N = v->render_cgal_nef_polyhedron(); + N = v->renderCSGMesh(); if (N.dim != 0) first = false; } else if (N.dim == 2) { if (type == CSG_TYPE_UNION) { - N.p2 += v->render_cgal_nef_polyhedron().p2; + N.p2 += v->renderCSGMesh().p2; } else if (type == CSG_TYPE_DIFFERENCE) { - N.p2 -= v->render_cgal_nef_polyhedron().p2; + N.p2 -= v->renderCSGMesh().p2; } else if (type == CSG_TYPE_INTERSECTION) { - N.p2 *= v->render_cgal_nef_polyhedron().p2; + N.p2 *= v->renderCSGMesh().p2; } } else if (N.dim == 3) { if (type == CSG_TYPE_UNION) { - N.p3 += v->render_cgal_nef_polyhedron().p3; + N.p3 += v->renderCSGMesh().p3; } else if (type == CSG_TYPE_DIFFERENCE) { - N.p3 -= v->render_cgal_nef_polyhedron().p3; + N.p3 -= v->renderCSGMesh().p3; } else if (type == CSG_TYPE_INTERSECTION) { - N.p3 *= v->render_cgal_nef_polyhedron().p3; + N.p3 *= v->renderCSGMesh().p3; } } v->progress_report(); @@ -172,6 +151,28 @@ QString CsgNode::dump(QString indent) const return dump_cache; } +std::string CsgNode::toString() const +{ + std::stringstream stream; + stream << "n" << this->index() << ": "; + + switch (this->type) { + case CSG_TYPE_UNION: + stream << "union()"; + break; + case CSG_TYPE_DIFFERENCE: + stream << "difference()"; + break; + case CSG_TYPE_INTERSECTION: + stream << "intersection()"; + break; + default: + assert(false); + } + + return stream.str(); +} + void register_builtin_csgops() { builtin_modules["union"] = new CsgModule(CSG_TYPE_UNION); |