diff options
author | Marius Kintel <marius@kintel.net> | 2011-10-04 19:06:40 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2011-10-04 19:06:40 (GMT) |
commit | 799ca1d1b3f2e9142460ab3ce895a0641f54dfda (patch) | |
tree | 6c168de6d55cb92b94b0ddeb54c668bd4946c10d /src | |
parent | 9259d57659f61e9e56942bb36125f605f8f3c338 (diff) | |
parent | f5e0f3a531b0c8806e4ebc62cd91ca31275ae481 (diff) |
Merge branch 'master' into visitortests
Conflicts:
src/polyset.h
Diffstat (limited to 'src')
43 files changed, 173 insertions, 266 deletions
diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index d950cb8..10160ae 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -11,6 +11,7 @@ #include "polyset.h" #include "dxfdata.h" #include "dxftess.h" +#include "Tree.h" #include "CGALCache.h" #include "cgal.h" @@ -205,8 +206,8 @@ Response CGALEvaluator::visit(State &state, const TransformNode &node) // tesselate it and create a new CGAL_Nef_polyhedron2 from it.. What a hack! CGAL_Aff_transformation2 t( - node.matrix[0], node.matrix[4], node.matrix[12], - node.matrix[1], node.matrix[5], node.matrix[13], node.matrix[15]); + node.matrix(0,0), node.matrix(0,1), node.matrix(0,3), + node.matrix(1,0), node.matrix(1,1), node.matrix(1,3), node.matrix(3,3)); DxfData *dd = N.convertToDxfData(); for (size_t i=0; i < dd->points.size(); i++) { @@ -225,9 +226,9 @@ Response CGALEvaluator::visit(State &state, const TransformNode &node) } else if (N.dim == 3) { CGAL_Aff_transformation t( - node.matrix[0], node.matrix[4], node.matrix[ 8], node.matrix[12], - node.matrix[1], node.matrix[5], node.matrix[ 9], node.matrix[13], - node.matrix[2], node.matrix[6], node.matrix[10], node.matrix[14], node.matrix[15]); + node.matrix(0,0), node.matrix(0,1), node.matrix(0,2), node.matrix(0,3), + node.matrix(1,0), node.matrix(1,1), node.matrix(1,2), node.matrix(1,3), + node.matrix(2,0), node.matrix(2,1), node.matrix(2,2), node.matrix(2,3), node.matrix(3,3)); N.p3->transform(t); } CGALCache::instance()->insert(this->tree.getIdString(node), N); diff --git a/src/CGALEvaluator.h b/src/CGALEvaluator.h index c1b5ae8..0ac716c 100644 --- a/src/CGALEvaluator.h +++ b/src/CGALEvaluator.h @@ -3,7 +3,6 @@ #include "myqhash.h" #include "visitor.h" -#include "Tree.h" #include "CGAL_Nef_polyhedron.h" #include "PolySetCGALEvaluator.h" @@ -11,16 +10,11 @@ #include <map> #include <list> -using std::string; -using std::map; -using std::list; -using std::pair; - class CGALEvaluator : public Visitor { public: enum CsgOp {CGE_UNION, CGE_INTERSECTION, CGE_DIFFERENCE, CGE_MINKOWSKI}; - CGALEvaluator(const Tree &tree) : tree(tree), psevaluator(*this) {} + CGALEvaluator(const class Tree &tree) : tree(tree), psevaluator(*this) {} virtual ~CGALEvaluator() {} virtual Response visit(State &state, const AbstractNode &node); @@ -42,9 +36,9 @@ private: CGAL_Nef_polyhedron applyToChildren(const AbstractNode &node, CGALEvaluator::CsgOp op); CGAL_Nef_polyhedron applyHull(const CgaladvNode &node); - string currindent; - typedef list<pair<const AbstractNode *, string> > ChildList; - map<int, ChildList> visitedchildren; + std::string currindent; + typedef std::list<std::pair<const AbstractNode *, std::string> > ChildList; + std::map<int, ChildList> visitedchildren; const Tree &tree; public: diff --git a/src/CGALRenderer.h b/src/CGALRenderer.h index 5f854ea..9c19e5a 100644 --- a/src/CGALRenderer.h +++ b/src/CGALRenderer.h @@ -2,12 +2,11 @@ #define CGALRENDERER_H_ #include "renderer.h" -#include "CGAL_Nef_polyhedron.h" class CGALRenderer : public Renderer { public: - CGALRenderer(const CGAL_Nef_polyhedron &root); + CGALRenderer(const class CGAL_Nef_polyhedron &root); ~CGALRenderer(); void draw(bool showfaces, bool showedges) const; diff --git a/src/CSGTermEvaluator.cc b/src/CSGTermEvaluator.cc index ebea89c..d1af987 100644 --- a/src/CSGTermEvaluator.cc +++ b/src/CSGTermEvaluator.cc @@ -86,8 +86,8 @@ Response CSGTermEvaluator::visit(State &state, const AbstractIntersectionNode &n } static CSGTerm *evaluate_csg_term_from_ps(const State &state, - vector<CSGTerm*> &highlights, - vector<CSGTerm*> &background, + std::vector<CSGTerm*> &highlights, + std::vector<CSGTerm*> &background, const shared_ptr<PolySet> &ps, const ModuleInstantiation *modinst, const AbstractNode &node) @@ -147,18 +147,7 @@ Response CSGTermEvaluator::visit(State &state, const CsgNode &node) Response CSGTermEvaluator::visit(State &state, const TransformNode &node) { if (state.isPrefix()) { - double m[16]; - - for (int i = 0; i < 16; i++) - { - int c_row = i%4; - int m_col = i/4; - m[i] = 0; - for (int j = 0; j < 4; j++) { - m[i] += state.matrix()[c_row + j*4] * node.matrix[m_col*4 + j]; - } - } - state.setMatrix(m); + state.setMatrix(state.matrix() * node.matrix); } if (state.isPostfix()) { applyToChildren(node, CSGT_UNION); diff --git a/src/CSGTermEvaluator.h b/src/CSGTermEvaluator.h index ac22906..cca6c91 100644 --- a/src/CSGTermEvaluator.h +++ b/src/CSGTermEvaluator.h @@ -1,39 +1,31 @@ #ifndef CSGTERMEVALUATOR_H_ #define CSGTERMEVALUATOR_H_ -#include <string> #include <map> #include <list> #include <vector> -#include "Tree.h" #include "visitor.h" -#include "node.h" - -using std::string; -using std::map; -using std::list; -using std::vector; class CSGTermEvaluator : public Visitor { public: - CSGTermEvaluator(const Tree &tree, class PolySetEvaluator *psevaluator = NULL) + CSGTermEvaluator(const class Tree &tree, class PolySetEvaluator *psevaluator = NULL) : tree(tree), psevaluator(psevaluator) { } virtual ~CSGTermEvaluator() {} - virtual Response visit(State &state, const AbstractNode &node); - virtual Response visit(State &state, const AbstractIntersectionNode &node); - virtual Response visit(State &state, const AbstractPolyNode &node); - virtual Response visit(State &state, const CsgNode &node); - virtual Response visit(State &state, const TransformNode &node); - virtual Response visit(State &state, const ColorNode &node); - virtual Response visit(State &state, const RenderNode &node); - virtual Response visit(State &state, const CgaladvNode &node); + virtual Response visit(State &state, const class AbstractNode &node); + virtual Response visit(State &state, const class AbstractIntersectionNode &node); + virtual Response visit(State &state, const class AbstractPolyNode &node); + virtual Response visit(State &state, const class CsgNode &node); + virtual Response visit(State &state, const class TransformNode &node); + virtual Response visit(State &state, const class ColorNode &node); + virtual Response visit(State &state, const class RenderNode &node); + virtual Response visit(State &state, const class CgaladvNode &node); class CSGTerm *evaluateCSGTerm(const AbstractNode &node, - vector<CSGTerm*> &highlights, - vector<CSGTerm*> &background); + std::vector<CSGTerm*> &highlights, + std::vector<CSGTerm*> &background); private: enum CsgOp {CSGT_UNION, CSGT_INTERSECTION, CSGT_DIFFERENCE, CSGT_MINKOWSKI}; @@ -41,14 +33,14 @@ private: void applyToChildren(const AbstractNode &node, CSGTermEvaluator::CsgOp op); const AbstractNode *root; - typedef list<const AbstractNode *> ChildList; - map<int, ChildList> visitedchildren; + typedef std::list<const AbstractNode *> ChildList; + std::map<int, ChildList> visitedchildren; public: - map<int, class CSGTerm*> stored_term; // The term evaluated from each node index + std::map<int, class CSGTerm*> stored_term; // The term evaluated from each node index - vector<CSGTerm*> highlights; - vector<CSGTerm*> background; + std::vector<CSGTerm*> highlights; + std::vector<CSGTerm*> background; const Tree &tree; class PolySetEvaluator *psevaluator; }; diff --git a/src/GLView.h b/src/GLView.h index 1001754..3a36a15 100644 --- a/src/GLView.h +++ b/src/GLView.h @@ -1,11 +1,7 @@ #ifndef GLVIEW_H_ #define GLVIEW_H_ -#ifdef ENABLE_OPENCSG -// this must be included before the GL headers -# include <GL/glew.h> -#endif - +#include "system-gl.h" #include <QGLWidget> #include <QLabel> diff --git a/src/MainWindow.h b/src/MainWindow.h index 0ba3bd9..37a6a4c 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -6,9 +6,7 @@ #include "openscad.h" #include "context.h" #include "module.h" -#include "polyset.h" #include "Tree.h" -#include <QPointer> #include <vector> class MainWindow : public QMainWindow, public Ui::MainWindow diff --git a/src/OpenCSGRenderer.cc b/src/OpenCSGRenderer.cc index 4a86c5c..5d6b0da 100644 --- a/src/OpenCSGRenderer.cc +++ b/src/OpenCSGRenderer.cc @@ -24,7 +24,7 @@ * */ -#include <GL/glew.h> +#include "system-gl.h" #include "OpenCSGRenderer.h" #include "polyset.h" #include "csgterm.h" @@ -39,11 +39,11 @@ public: OpenCSGPrim(OpenCSG::Operation operation, unsigned int convexity) : OpenCSG::Primitive(operation, convexity) { } shared_ptr<PolySet> ps; - double *m; + Transform3d m; int csgmode; virtual void render() { glPushMatrix(); - glMultMatrixd(m); + glMultMatrixd(m.data()); ps->render_surface(PolySet::COLORMODE_NONE, PolySet::csgmode_e(csgmode), m); glPopMatrix(); } @@ -85,10 +85,10 @@ void OpenCSGRenderer::renderCSGChain(CSGChain *chain, GLint *shaderinfo, } if (shaderinfo) glUseProgram(shaderinfo[0]); for (; j < i; j++) { - double *m = chain->matrices[j]; + const Transform3d &m = chain->matrices[j]; double *c = chain->colors[j]; glPushMatrix(); - glMultMatrixd(m); + glMultMatrixd(m.data()); int csgmode = chain->types[j] == CSGTerm::TYPE_DIFFERENCE ? PolySet::CSGMODE_DIFFERENCE : PolySet::CSGMODE_NORMAL; if (highlight) { chain->polysets[j]->render_surface(PolySet::COLORMODE_HIGHLIGHT, PolySet::csgmode_e(csgmode + 20), m, shaderinfo); diff --git a/src/OpenCSGRenderer.h b/src/OpenCSGRenderer.h index 95ffc8e..e6091aa 100644 --- a/src/OpenCSGRenderer.h +++ b/src/OpenCSGRenderer.h @@ -2,8 +2,7 @@ #define OPENCSGRENDERER_H_ #include "renderer.h" -#include <GL/glew.h> // this must be included before the GL headers -#include <qgl.h> +#include "system-gl.h" class OpenCSGRenderer : public Renderer { diff --git a/src/PolySetEvaluator.cc b/src/PolySetEvaluator.cc index 1f09127..b5075ba 100644 --- a/src/PolySetEvaluator.cc +++ b/src/PolySetEvaluator.cc @@ -2,6 +2,7 @@ #include "PolySetEvaluator.h" #include "printutils.h" #include "polyset.h" +#include "Tree.h" /*! The task of PolySetEvaluator is to create, keep track of and cache PolySet instances. diff --git a/src/PolySetEvaluator.h b/src/PolySetEvaluator.h index 8d7d1a8..348cbba 100644 --- a/src/PolySetEvaluator.h +++ b/src/PolySetEvaluator.h @@ -1,19 +1,17 @@ #ifndef POLYSETEVALUATOR_H_ #define POLYSETEVALUATOR_H_ -#include "node.h" -#include "Tree.h" #include "memory.h" class PolySetEvaluator { public: - PolySetEvaluator(const Tree &tree) : tree(tree) {} + PolySetEvaluator(const class Tree &tree) : tree(tree) {} virtual ~PolySetEvaluator() {} const Tree &getTree() const { return this->tree; } - virtual shared_ptr<PolySet> getPolySet(const class AbstractNode &, bool cache); + virtual shared_ptr<class PolySet> getPolySet(const class AbstractNode &, bool cache); virtual PolySet *evaluatePolySet(const class ProjectionNode &) { return NULL; } virtual PolySet *evaluatePolySet(const class LinearExtrudeNode &) { return NULL; } diff --git a/src/ThrownTogetherRenderer.cc b/src/ThrownTogetherRenderer.cc index 956fc11..01c7513 100644 --- a/src/ThrownTogetherRenderer.cc +++ b/src/ThrownTogetherRenderer.cc @@ -28,8 +28,7 @@ #include "polyset.h" #include "csgterm.h" -#include <GL/glew.h> // this must be included before the GL headers -#include <qgl.h> +#include "system-gl.h" ThrownTogetherRenderer::ThrownTogetherRenderer(CSGChain *root_chain, CSGChain *highlights_chain, @@ -61,14 +60,14 @@ void ThrownTogetherRenderer::renderCSGChain(CSGChain *chain, bool highlight, bool fberror) const { glDepthFunc(GL_LEQUAL); - QHash<QPair<PolySet*,double*>,int> polySetVisitMark; + QHash<QPair<PolySet*,Transform3d*>,int> polySetVisitMark; for (size_t i = 0; i < chain->polysets.size(); i++) { - if (polySetVisitMark[QPair<PolySet*,double*>(chain->polysets[i].get(), chain->matrices[i])]++ > 0) + if (polySetVisitMark[QPair<PolySet*,Transform3d*>(chain->polysets[i].get(), &chain->matrices[i])]++ > 0) continue; - double *m = chain->matrices[i]; + const Transform3d &m = chain->matrices[i]; double *c = chain->colors[i]; glPushMatrix(); - glMultMatrixd(m); + glMultMatrixd(m.data()); int csgmode = chain->types[i] == CSGTerm::TYPE_DIFFERENCE ? PolySet::CSGMODE_DIFFERENCE : PolySet::CSGMODE_NORMAL; if (highlight) { chain->polysets[i]->render_surface(PolySet::COLORMODE_HIGHLIGHT, PolySet::csgmode_e(csgmode + 20), m); diff --git a/src/cgaladv.cc b/src/cgaladv.cc index 5014133..c83e18b 100644 --- a/src/cgaladv.cc +++ b/src/cgaladv.cc @@ -28,7 +28,6 @@ #include "module.h" #include "context.h" #include "builtin.h" -#include "printutils.h" #include "PolySetEvaluator.h" #include <sstream> #include <assert.h> diff --git a/src/cgaladv_minkowski2.cc b/src/cgaladv_minkowski2.cc index f08e7d6..4ce684f 100644 --- a/src/cgaladv_minkowski2.cc +++ b/src/cgaladv_minkowski2.cc @@ -26,7 +26,6 @@ #ifdef ENABLE_CGAL -#include "node.h" #include "printutils.h" #include "grid.h" #include "cgal.h" diff --git a/src/color.cc b/src/color.cc index a65a8e4..ee8f872 100644 --- a/src/color.cc +++ b/src/color.cc @@ -29,7 +29,6 @@ #include "context.h" #include "builtin.h" #include "printutils.h" -#include "visitor.h" #include <sstream> #include <assert.h> #include <QColor> diff --git a/src/csgops.cc b/src/csgops.cc index 98d68c7..7b363f0 100644 --- a/src/csgops.cc +++ b/src/csgops.cc @@ -29,7 +29,6 @@ #include "module.h" #include "csgterm.h" #include "builtin.h" -#include "printutils.h" #include <sstream> #include <assert.h> diff --git a/src/csgterm.cc b/src/csgterm.cc index 5bccff8..0f56b82 100644 --- a/src/csgterm.cc +++ b/src/csgterm.cc @@ -47,10 +47,10 @@ */ -CSGTerm::CSGTerm(const shared_ptr<PolySet> &polyset, const double matrix[16], const double color[4], const std::string &label) +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) { - for (int i = 0; i < 16; i++) this->m[i] = matrix[i]; + this->m = matrix; for (int i = 0; i < 4; i++) this->color[i] = color[i]; refcounter = 1; } @@ -188,7 +188,7 @@ CSGChain::CSGChain() { } -void CSGChain::add(const shared_ptr<PolySet> &polyset, double *m, double *color, CSGTerm::type_e type, std::string label) +void CSGChain::add(const shared_ptr<PolySet> &polyset, const Transform3d &m, double *color, CSGTerm::type_e type, std::string label) { polysets.push_back(polyset); matrices.push_back(m); @@ -256,11 +256,7 @@ BoundingBox CSGChain::getBoundingBox() const if (!psbox.isNull()) { Eigen::Transform3d t; // Column-major vs. Row-major - t.matrix() << - matrices[i][0], matrices[i][4], matrices[i][8], matrices[i][12], - matrices[i][1], matrices[i][5], matrices[i][9], matrices[i][13], - matrices[i][2], matrices[i][6], matrices[i][10], matrices[i][14], - matrices[i][3], matrices[i][7], matrices[i][11], matrices[i][15]; + t = matrices[i]; bbox.extend(t * psbox.min()); bbox.extend(t * psbox.max()); } diff --git a/src/csgterm.h b/src/csgterm.h index c4e88a6..b09b2d2 100644 --- a/src/csgterm.h +++ b/src/csgterm.h @@ -3,8 +3,10 @@ #include <string> #include <vector> -#include "polyset.h" #include "memory.h" +#include "linalg.h" + +class PolySet; class CSGTerm { @@ -21,11 +23,11 @@ public: std::string label; CSGTerm *left; CSGTerm *right; - double m[16]; + Transform3d m; double color[4]; int refcounter; - CSGTerm(const shared_ptr<PolySet> &polyset, const double matrix[16], const double color[4], const std::string &label); + CSGTerm(const shared_ptr<PolySet> &polyset, const Transform3d &matrix, const double color[4], const std::string &label); CSGTerm(type_e type, CSGTerm *left, CSGTerm *right); CSGTerm *normalize(); @@ -40,14 +42,14 @@ class CSGChain { public: std::vector<shared_ptr<PolySet> > polysets; - std::vector<double*> matrices; + std::vector<Transform3d> matrices; std::vector<double*> colors; std::vector<CSGTerm::type_e> types; std::vector<std::string> labels; CSGChain(); - void add(const shared_ptr<PolySet> &polyset, double *m, double *color, CSGTerm::type_e type, std::string label); + 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); std::string dump(); std::string fulldump(); diff --git a/src/dxftess-glu.cc b/src/dxftess-glu.cc index 23d8a45..4ad2051 100644 --- a/src/dxftess-glu.cc +++ b/src/dxftess-glu.cc @@ -4,13 +4,11 @@ #include "grid.h" #include <stdio.h> -#ifdef ENABLE_OPENCSG -// this must be included before the GL headers -# include <GL/glew.h> -#endif -#include <qgl.h> +#include "system-gl.h" #include "mathc99.h" +#include <QVector> + #ifdef WIN32 # define STDCALL __stdcall #else diff --git a/src/editor.h b/src/editor.h index c2f3333..3088d20 100644 --- a/src/editor.h +++ b/src/editor.h @@ -22,7 +22,7 @@ public slots: //void zoomOut() { zoom(-1); } void zoomOut(int n = 1) { zoom(-n); } #else - Editor(QWidget *parent) : QTextEdit(parent) {} + Editor(QWidget *parent) : QTextEdit(parent) { setAcceptRichText(false); } public slots: void setLineWrapping(bool on) { if(on) setWordWrapMode(QTextOption::WrapAnywhere); } void setContentModified(bool y) { document()->setModified(y); } diff --git a/src/export.h b/src/export.h index cba0b23..dd6e3e0 100644 --- a/src/export.h +++ b/src/export.h @@ -5,8 +5,7 @@ #include <iostream> -void cgal_nef3_to_polyset(class PolySet *ps, class CGAL_Nef_polyhedron *root_N); -void export_stl(CGAL_Nef_polyhedron *root_N, std::ostream &output, class QProgressDialog *pd); +void export_stl(class CGAL_Nef_polyhedron *root_N, std::ostream &output, class QProgressDialog *pd); void export_off(CGAL_Nef_polyhedron *root_N, std::ostream &output, QProgressDialog *pd); void export_dxf(CGAL_Nef_polyhedron *root_N, std::ostream &output, QProgressDialog *pd); #endif diff --git a/src/func.cc b/src/func.cc index b58a1b7..b011a27 100644 --- a/src/func.cc +++ b/src/func.cc @@ -27,7 +27,6 @@ #include "function.h" #include "expression.h" #include "context.h" -#include "dxfdim.h" #include "builtin.h" #include <sstream> #include <ctime> @@ -354,7 +353,26 @@ Value builtin_lookup(const Context *, const std::vector<std::string>&, const std Value builtin_version(const Context *, const std::vector<std::string>&, const std::vector<Value> &) { - return Value(std::string(QUOTED(OPENSCAD_VERSION))); + Value val; + val.type = Value::VECTOR; + val.append(new Value(double(OPENSCAD_YEAR))); + val.append(new Value(double(OPENSCAD_MONTH))); +#ifdef OPENSCAD_DAY + val.append(new Value(double(OPENSCAD_DAY))); +#endif + return val; +} + +Value builtin_version_num(const Context *ctx, const std::vector<std::string>& call_argnames, const std::vector<Value> &args) +{ + Value val = (args.size() == 0) ? builtin_version(ctx, call_argnames, args) : args[0]; + double y, m, d = 0; + if (!val.getv3(y, m, d)) { + if (!val.getv2(y, m)) { + return Value(); + } + } + return Value(y * 10000 + m * 100 + d); } void initialize_builtin_functions() @@ -382,6 +400,7 @@ void initialize_builtin_functions() builtin_functions["str"] = new BuiltinFunction(&builtin_str); builtin_functions["lookup"] = new BuiltinFunction(&builtin_lookup); builtin_functions["version"] = new BuiltinFunction(&builtin_version); + builtin_functions["version_num"] = new BuiltinFunction(&builtin_version_num); initialize_builtin_dxf_dim(); } diff --git a/src/import.cc b/src/import.cc index f64a8f6..d86a60d 100644 --- a/src/import.cc +++ b/src/import.cc @@ -228,7 +228,6 @@ std::string ImportNode::toString() const { std::stringstream stream; - QString text; struct stat st; memset(&st, 0, sizeof(struct stat)); stat(this->filename.c_str(), &st); diff --git a/src/linalg.h b/src/linalg.h new file mode 100644 index 0000000..06991cf --- /dev/null +++ b/src/linalg.h @@ -0,0 +1,13 @@ +#ifndef LINALG_H_ +#define LINALG_H_ + +#include <Eigen/Core> +#include <Eigen/Geometry> + +using Eigen::Vector3d; +typedef Eigen::AlignedBox<double, 3> BoundingBox; +using Eigen::Matrix3f; +using Eigen::Matrix3d; +using Eigen::Transform3d; + +#endif diff --git a/src/linearextrude.cc b/src/linearextrude.cc index 4ce87db..5c3b684 100644 --- a/src/linearextrude.cc +++ b/src/linearextrude.cc @@ -30,11 +30,6 @@ #include "context.h" #include "printutils.h" #include "builtin.h" -#include "dxfdata.h" -#include "dxftess.h" -#include "polyset.h" -#include "progress.h" -#include "visitor.h" #include "PolySetEvaluator.h" #include "openscad.h" // get_fragments_from_r() @@ -124,7 +119,7 @@ void register_builtin_dxf_linear_extrude() builtin_modules["linear_extrude"] = new LinearExtrudeModule(); } -PolySet *LinearExtrudeNode::evaluate_polyset(PolySetEvaluator *evaluator) const +class PolySet *LinearExtrudeNode::evaluate_polyset(PolySetEvaluator *evaluator) const { if (!evaluator) { PRINTF("WARNING: No suitable PolySetEvaluator found for %s module!", this->name().c_str()); diff --git a/src/mainwin.cc b/src/mainwin.cc index e287f0d..fafe8ed 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -33,13 +33,10 @@ #include "polyset.h" #include "csgterm.h" #include "highlighter.h" -#include "grid.h" -#include "dxfdata.h" -#include "dxfdim.h" #include "export.h" #include "builtin.h" -#include "dxftess.h" #include "progress.h" +#include "dxfdim.h" #ifdef ENABLE_OPENCSG #include "CSGTermEvaluator.h" #include "OpenCSGRenderer.h" @@ -104,8 +101,7 @@ unsigned int GuiLocker::gui_locked = 0; #define QUOTED(x__) QUOTE(x__) static char helptitle[] = - "OpenSCAD " QUOTED(OPENSCAD_VERSION) " (www.openscad.org)\n" - "Visitor refactored version\n"; + "OpenSCAD " QUOTED(OPENSCAD_VERSION) " (www.openscad.org)\n\n"; static char copyrighttext[] = "Copyright (C) 2009-2011 Marius Kintel <marius@kintel.net> and Clifford Wolf <clifford@clifford.at>\n" "\n" @@ -1087,12 +1083,14 @@ void MainWindow::pasteViewportRotation() void MainWindow::checkAutoReload() { - QString new_stinfo; - QFileInfo finfo(this->fileName); - new_stinfo = QString::number(finfo.size()) + QString::number(finfo.lastModified().toTime_t()); - if (new_stinfo != autoReloadInfo) - actionReloadCompile(); - autoReloadInfo = new_stinfo; + if (!this->fileName.isEmpty()) { + QString new_stinfo; + QFileInfo finfo(this->fileName); + new_stinfo = QString::number(finfo.size()) + QString::number(finfo.lastModified().toTime_t()); + if (new_stinfo != autoReloadInfo) + actionReloadCompile(); + autoReloadInfo = new_stinfo; + } } void MainWindow::autoReloadSet(bool on) diff --git a/src/node.cc b/src/node.cc index e2f3fa0..12a7ca4 100644 --- a/src/node.cc +++ b/src/node.cc @@ -24,17 +24,13 @@ * */ -#include "printutils.h" #include "node.h" #include "module.h" -#include "csgterm.h" #include "progress.h" -#include "polyset.h" #include "visitor.h" -#include "nodedumper.h" #include "stl-utils.h" -#include <sstream> +#include <iostream> #include <algorithm> size_t AbstractNode::idx_counter; @@ -3,7 +3,6 @@ #include <vector> #include <string> - #include "traverser.h" extern int progress_report_count; diff --git a/src/nodedumper.cc b/src/nodedumper.cc index d75c703..4523bac 100644 --- a/src/nodedumper.cc +++ b/src/nodedumper.cc @@ -1,13 +1,8 @@ #include "nodedumper.h" -#include <string> -#include <map> -#include <list> -#include "visitor.h" #include "state.h" -#include "nodecache.h" +#include <string> #include <sstream> -#include <iostream> #include <assert.h> /*! @@ -42,7 +37,7 @@ void NodeDumper::handleIndent(const State &state) including braces and indentation. All children are assumed to be cached already. */ -string NodeDumper::dumpChildren(const AbstractNode &node) +std::string NodeDumper::dumpChildren(const AbstractNode &node) { std::stringstream dump; if (!this->visitedchildren[node.index()].empty()) { diff --git a/src/openscad.h b/src/openscad.h index 9d97bac..e6b9b9f 100644 --- a/src/openscad.h +++ b/src/openscad.h @@ -27,11 +27,6 @@ #ifndef OPENSCAD_H #define OPENSCAD_H -#ifdef ENABLE_OPENCSG -// this must be included before the GL headers -# include <GL/glew.h> -#endif - // for win32 and maybe others.. #ifndef M_PI # define M_PI 3.14159265358979323846 diff --git a/src/polyset.cc b/src/polyset.cc index 23b9876..1d31005 100644 --- a/src/polyset.cc +++ b/src/polyset.cc @@ -25,14 +25,13 @@ */ #include "polyset.h" -#include "printutils.h" // FIXME: Reenable/rewrite - don't be dependant on GUI // #include "Preferences.h" #ifdef ENABLE_CGAL #include <CGAL/assertions_behaviour.h> #include <CGAL/exceptions.h> #endif -#include <Eigen/Core> +#include "linalg.h" #include <Eigen/LU> #include <QColor> @@ -113,13 +112,9 @@ static void gl_draw_triangle(GLint *shaderinfo, const Vector3d &p0, const Vector } } -void PolySet::render_surface(colormode_e colormode, csgmode_e csgmode, double *m, GLint *shaderinfo) const +void PolySet::render_surface(colormode_e colormode, csgmode_e csgmode, const Transform3d &m, GLint *shaderinfo) const { - Eigen::Matrix3f m3f; - m3f << m[0], m[4], m[8], - m[1], m[5], m[9], - m[2], m[6], m[10]; - bool mirrored = m3f.determinant() < 0; + bool mirrored = m.matrix().determinant() < 0; if (colormode == COLORMODE_MATERIAL) { // FIXME: Reenable/rewrite - don't be dependant on GUI diff --git a/src/polyset.h b/src/polyset.h index 3cfb21a..57f5057 100644 --- a/src/polyset.h +++ b/src/polyset.h @@ -1,20 +1,11 @@ #ifndef POLYSET_H_ #define POLYSET_H_ -#ifndef __APPLE__ -#define EIGEN_DONT_VECTORIZE 1 -#define EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT 1 -#endif - -#include <GL/glew.h> +#include "system-gl.h" #include "grid.h" -#include <Eigen/Core> -#include <Eigen/Geometry> +#include "linalg.h" #include <vector> -using Eigen::Vector3d; -typedef Eigen::AlignedBox<double, 3> BoundingBox; - class PolySet { public: @@ -54,7 +45,7 @@ public: CSGMODE_HIGHLIGHT_DIFFERENCE = 22 }; - void render_surface(colormode_e colormode, csgmode_e csgmode, double *m, GLint *shaderinfo = NULL) const; + void render_surface(colormode_e colormode, csgmode_e csgmode, const Transform3d &m, GLint *shaderinfo = NULL) const; void render_edges(colormode_e colormode, csgmode_e csgmode) const; }; diff --git a/src/primitives.cc b/src/primitives.cc index 08b9c62..a651ff8 100644 --- a/src/primitives.cc +++ b/src/primitives.cc @@ -32,7 +32,6 @@ #include "dxftess.h" #include "builtin.h" #include "printutils.h" -#include <assert.h> #include "visitor.h" #include <sstream> #include <assert.h> diff --git a/src/printutils.cc b/src/printutils.cc index 01fa06b..a315ab3 100644 --- a/src/printutils.cc +++ b/src/printutils.cc @@ -1,5 +1,6 @@ #include "printutils.h" #include <stdio.h> +#include <QDate> QList<QString> print_messages_stack; OutputHandlerFunc *outputhandler = NULL; diff --git a/src/printutils.h b/src/printutils.h index 0432622..60cd12a 100644 --- a/src/printutils.h +++ b/src/printutils.h @@ -5,7 +5,6 @@ #include <QList> #include <iostream> #include <QFileInfo> -#include <QDateTime> typedef void (OutputHandlerFunc)(const QString &msg, void *userdata); extern OutputHandlerFunc *outputhandler; diff --git a/src/projection.cc b/src/projection.cc index 2c9d821..1333d19 100644 --- a/src/projection.cc +++ b/src/projection.cc @@ -29,19 +29,9 @@ #include "context.h" #include "printutils.h" #include "builtin.h" -#include "dxfdata.h" -#include "dxftess.h" -#include "polyset.h" -#include "export.h" -#include "progress.h" #include "visitor.h" #include "PolySetEvaluator.h" -#ifdef ENABLE_CGAL -# include <CGAL/assertions_behaviour.h> -# include <CGAL/exceptions.h> -#endif - #include <assert.h> #include <sstream> #include <boost/assign/std/vector.hpp> diff --git a/src/render.cc b/src/render.cc index f08423a..b79fa56 100644 --- a/src/render.cc +++ b/src/render.cc @@ -28,9 +28,6 @@ #include "module.h" #include "context.h" #include "builtin.h" -#include "printutils.h" -#include "progress.h" -#include "visitor.h" #include "PolySetEvaluator.h" #include <sstream> diff --git a/src/rotateextrude.cc b/src/rotateextrude.cc index 3a6eb55..4d6de73 100644 --- a/src/rotateextrude.cc +++ b/src/rotateextrude.cc @@ -30,8 +30,6 @@ #include "printutils.h" #include "builtin.h" #include "polyset.h" -#include "dxfdata.h" -#include "progress.h" #include "visitor.h" #include "PolySetEvaluator.h" #include "openscad.h" // get_fragments_from_r() diff --git a/src/state.h b/src/state.h index 69aee87..5dc74df 100644 --- a/src/state.h +++ b/src/state.h @@ -2,13 +2,14 @@ #define STATE_H_ #include <cstring> +#include "linalg.h" class State { public: State(const class AbstractNode *parent) : parentnode(parent), isprefix(false), ispostfix(false), numchildren(0) { - for (int i=0;i<16;i++) this->m[i] = i % 5 == 0 ? 1.0 : 0.0; + m = Transform3d::Identity(); for (int i=0;i<4;i++) this->c[i] = -1.0; } virtual ~State() {} @@ -17,14 +18,14 @@ public: void setPostfix(bool on) { this->ispostfix = on; } void setNumChildren(unsigned int numc) { this->numchildren = numc; } void setParent(const AbstractNode *parent) { this->parentnode = parent; } - void setMatrix(const double m[16]) { memcpy(this->m, m, 16*sizeof(double)); } + void setMatrix(const Transform3d &m) { this->m = m; } void setColor(const double c[4]) { memcpy(this->c, c, 4*sizeof(double)); } bool isPrefix() const { return this->isprefix; } bool isPostfix() const { return this->ispostfix; } unsigned int numChildren() const { return this->numchildren; } const AbstractNode *parent() const { return this->parentnode; } - const double *matrix() const { return this->m; } + const Transform3d &matrix() const { return this->m; } const double *color() const { return this->c; } private: @@ -34,7 +35,7 @@ private: unsigned int numchildren; // Transformation matrix and color. FIXME: Generalize such state variables? - double m[16]; + Transform3d m; double c[4]; }; diff --git a/src/surface.cc b/src/surface.cc index 35449ed..8349afd 100644 --- a/src/surface.cc +++ b/src/surface.cc @@ -29,7 +29,6 @@ #include "polyset.h" #include "context.h" #include "builtin.h" -#include "dxftess.h" #include "printutils.h" #include "handle_dep.h" // handle_dep() #include "visitor.h" diff --git a/src/system-gl.h b/src/system-gl.h new file mode 100644 index 0000000..cdbf3dc --- /dev/null +++ b/src/system-gl.h @@ -0,0 +1,11 @@ +#ifndef SYSTEMGL_H_ +#define SYSTEMGL_H_ + +#include <GL/glew.h> +#ifdef __APPLE__ +#include <OpenGL/OpenGL.h> +#else +#include <GL/gl.h> +#endif + +#endif diff --git a/src/transform.cc b/src/transform.cc index f473f6a..eda69c2 100644 --- a/src/transform.cc +++ b/src/transform.cc @@ -27,13 +27,8 @@ #include "transformnode.h" #include "module.h" #include "context.h" -#include "dxfdata.h" -#include "csgterm.h" #include "polyset.h" -#include "dxftess.h" #include "builtin.h" -#include "printutils.h" -#include "visitor.h" #include <sstream> #include <vector> #include <assert.h> @@ -60,8 +55,7 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanti { TransformNode *node = new TransformNode(inst); - for (int i = 0; i < 16; i++) - node->matrix[i] = i % 5 == 0 ? 1.0 : 0.0; + node->matrix = Transform3d::Identity(); std::vector<std::string> argnames; std::vector<Expression*> argexpr; @@ -91,82 +85,50 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanti if (this->type == SCALE) { + Vector3d scalevec(1,1,1); Value v = c.lookup_variable("v"); - v.getnum(node->matrix[0]); - v.getnum(node->matrix[5]); - v.getnum(node->matrix[10]); - v.getv3(node->matrix[0], node->matrix[5], node->matrix[10]); - if (node->matrix[10] <= 0) - node->matrix[10] = 1; + v.getnum(scalevec[0]); + v.getnum(scalevec[1]); + v.getnum(scalevec[2]); + v.getv3(scalevec[0], scalevec[1], scalevec[2]); + if (scalevec[2] == 0) scalevec[2] = 1; + node->matrix.scale(scalevec); } else if (this->type == ROTATE) { Value val_a = c.lookup_variable("a"); if (val_a.type == Value::VECTOR) { - for (size_t i = 0; i < 3 && i < val_a.vec.size(); i++) { - double a; - val_a.vec[i]->getnum(a); - double c = cos(a*M_PI/180.0); - double s = sin(a*M_PI/180.0); - double x = i == 0, y = i == 1, z = i == 2; - double mr[16] = { - x*x*(1-c)+c, - y*x*(1-c)+z*s, - z*x*(1-c)-y*s, - 0, - x*y*(1-c)-z*s, - y*y*(1-c)+c, - z*y*(1-c)+x*s, - 0, - x*z*(1-c)+y*s, - y*z*(1-c)-x*s, - z*z*(1-c)+c, - 0, - 0, 0, 0, 1 - }; - double m[16]; - for (int x = 0; x < 4; x++) - for (int y = 0; y < 4; y++) - { - m[x+y*4] = 0; - for (int i = 0; i < 4; i++) - m[x+y*4] += node->matrix[i+y*4] * mr[x+i*4]; - } - for (int i = 0; i < 16; i++) - node->matrix[i] = m[i]; + Eigen::AngleAxisd rotx, roty, rotz; + double a; + if (val_a.vec.size() > 0) { + val_a.vec[0]->getnum(a); + rotx = Eigen::AngleAxisd(a*M_PI/180, Vector3d::UnitX()); } + if (val_a.vec.size() > 1) { + val_a.vec[1]->getnum(a); + roty = Eigen::AngleAxisd(a*M_PI/180, Vector3d::UnitY()); + } + if (val_a.vec.size() > 2) { + val_a.vec[2]->getnum(a); + rotz = Eigen::AngleAxisd(a*M_PI/180, Vector3d::UnitZ()); + } + node->matrix.rotate(rotz * roty * rotx); } else { Value val_v = c.lookup_variable("v"); - double a = 0, x = 0, y = 0, z = 1; + double a = 0; val_a.getnum(a); - if (val_v.getv3(x, y, z)) { - if (x != 0.0 || y != 0.0 || z != 0.0) { - double sn = 1.0 / sqrt(x*x + y*y + z*z); - x *= sn, y *= sn, z *= sn; - } + Vector3d axis(0,0,1); + if (val_v.getv3(axis[0], axis[1], axis[2])) { + if (axis.squaredNorm() > 0) axis.normalize(); } - if (x != 0.0 || y != 0.0 || z != 0.0) - { - double c = cos(a*M_PI/180.0); - double s = sin(a*M_PI/180.0); - - node->matrix[ 0] = x*x*(1-c)+c; - node->matrix[ 1] = y*x*(1-c)+z*s; - node->matrix[ 2] = z*x*(1-c)-y*s; - - node->matrix[ 4] = x*y*(1-c)-z*s; - node->matrix[ 5] = y*y*(1-c)+c; - node->matrix[ 6] = z*y*(1-c)+x*s; - - node->matrix[ 8] = x*z*(1-c)+y*s; - node->matrix[ 9] = y*z*(1-c)-x*s; - node->matrix[10] = z*z*(1-c)+c; + if (axis.squaredNorm() > 0) { + node->matrix = Eigen::AngleAxisd(a*M_PI/180, axis); } } } @@ -184,23 +146,20 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanti if (x != 0.0 || y != 0.0 || z != 0.0) { - node->matrix[ 0] = 1-2*x*x; - node->matrix[ 1] = -2*y*x; - node->matrix[ 2] = -2*z*x; - - node->matrix[ 4] = -2*x*y; - node->matrix[ 5] = 1-2*y*y; - node->matrix[ 6] = -2*z*y; - - node->matrix[ 8] = -2*x*z; - node->matrix[ 9] = -2*y*z; - node->matrix[10] = 1-2*z*z; + Eigen::Matrix4d m; + m << 1-2*x*x, -2*y*x, -2*z*x, 0, + -2*x*y, 1-2*y*y, -2*z*y, 0, + -2*x*z, -2*y*z, 1-2*z*z, 0, + 0, 0, 0, 1; + node->matrix = m; } } else if (this->type == TRANSLATE) { Value v = c.lookup_variable("v"); - v.getv3(node->matrix[12], node->matrix[13], node->matrix[14]); + Vector3d translatevec(0,0,0); + v.getv3(translatevec[0], translatevec[1], translatevec[2]); + node->matrix.translate(translatevec); } else if (this->type == MULTMATRIX) { @@ -209,7 +168,7 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanti for (int i = 0; i < 16; i++) { size_t x = i / 4, y = i % 4; if (y < v.vec.size() && v.vec[y]->type == Value::VECTOR && x < v.vec[y]->vec.size()) - v.vec[y]->vec[x]->getnum(node->matrix[i]); + v.vec[y]->vec[x]->getnum(node->matrix(y, x)); } } } @@ -229,7 +188,7 @@ std::string TransformNode::toString() const stream << "["; for (int i=0;i<4;i++) { // FIXME: The 0 test is to avoid a leading minus before a single 0 (cosmetics) - stream << ((this->matrix[i*4+j]==0)?0:this->matrix[i*4+j]); + stream << ((this->matrix(j, i)==0)?0:this->matrix(j, i)); if (i != 3) stream << ", "; } stream << "]"; diff --git a/src/transformnode.h b/src/transformnode.h index 9d822cb..29c6d43 100644 --- a/src/transformnode.h +++ b/src/transformnode.h @@ -3,6 +3,7 @@ #include "node.h" #include "visitor.h" +#include "linalg.h" class TransformNode : public AbstractNode { @@ -14,7 +15,7 @@ public: virtual std::string toString() const; virtual std::string name() const; - double matrix[16]; + Transform3d matrix; }; #endif |