diff options
Diffstat (limited to 'src/surface.cc')
-rw-r--r-- | src/surface.cc | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/src/surface.cc b/src/surface.cc index 2a4fec6..35449ed 100644 --- a/src/surface.cc +++ b/src/surface.cc @@ -31,13 +31,16 @@ #include "builtin.h" #include "dxftess.h" #include "printutils.h" -#include "openscad.h" // handle_dep() +#include "handle_dep.h" // handle_dep() #include "visitor.h" #include <QFile> #include <QRegExp> #include <QStringList> #include <sstream> +#include <boost/unordered_map.hpp> +#include <boost/assign/std/vector.hpp> +using namespace boost::assign; // bring 'operator+=()' into scope class SurfaceModule : public AbstractModule { @@ -56,10 +59,10 @@ public: virtual std::string toString() const; virtual std::string name() const { return "surface"; } - QString filename; + std::string filename; bool center; int convexity; - virtual PolySet *evaluate_polyset(render_mode_e mode, class PolySetEvaluator *) const; + virtual PolySet *evaluate_polyset(class PolySetEvaluator *) const; }; AbstractNode *SurfaceModule::evaluate(const Context *ctx, const ModuleInstantiation *inst) const @@ -68,13 +71,14 @@ AbstractNode *SurfaceModule::evaluate(const Context *ctx, const ModuleInstantiat node->center = false; node->convexity = 1; - QVector<QString> argnames = QVector<QString>() << "file" << "center" << "convexity"; - QVector<Expression*> argexpr; + std::vector<std::string> argnames; + argnames += "file", "center", "convexity"; + std::vector<Expression*> argexpr; Context c(ctx); c.args(argnames, argexpr, inst->argnames, inst->argvalues); - node->filename = c.get_absolute_path(QString::fromStdString(c.lookup_variable("file").text)); + node->filename = c.getAbsolutePath(c.lookup_variable("file").text); Value center = c.lookup_variable("center", true); if (center.type == Value::BOOL) { @@ -94,19 +98,19 @@ void register_builtin_surface() builtin_modules["surface"] = new SurfaceModule(); } -PolySet *SurfaceNode::evaluate_polyset(render_mode_e, class PolySetEvaluator *) const +PolySet *SurfaceNode::evaluate_polyset(class PolySetEvaluator *) const { - PolySet *p = new PolySet(); handle_dep(filename); - QFile f(filename); + QFile f(QString::fromStdString(filename)); if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) { - PRINTF("WARNING: Can't open DAT file `%s'.", filename.toAscii().data()); - return p; + PRINTF("WARNING: Can't open DAT file `%s'.", filename.c_str()); + return NULL; } + PolySet *p = new PolySet(); int lines = 0, columns = 0; - QHash<QPair<int,int>,double> data; + boost::unordered_map<std::pair<int,int>,double> data; double min_val = 0; while (!f.atEnd()) @@ -123,7 +127,7 @@ PolySet *SurfaceNode::evaluate_polyset(render_mode_e, class PolySetEvaluator *) if (i >= columns) columns = i + 1; double v = fields[i].toDouble(); - data[QPair<int,int>(lines, i)] = v; + data[std::make_pair(lines, i)] = v; min_val = fmin(v-1, min_val); } lines++; @@ -137,10 +141,10 @@ PolySet *SurfaceNode::evaluate_polyset(render_mode_e, class PolySetEvaluator *) for (int i = 1; i < lines; i++) for (int j = 1; j < columns; j++) { - double v1 = data[QPair<int,int>(i-1, j-1)]; - double v2 = data[QPair<int,int>(i-1, j)]; - double v3 = data[QPair<int,int>(i, j-1)]; - double v4 = data[QPair<int,int>(i, j)]; + double v1 = data[std::make_pair(i-1, j-1)]; + double v2 = data[std::make_pair(i-1, j)]; + double v3 = data[std::make_pair(i, j-1)]; + double v4 = data[std::make_pair(i, j)]; double vx = (v1 + v2 + v3 + v4) / 4; p->append_poly(); @@ -168,14 +172,14 @@ PolySet *SurfaceNode::evaluate_polyset(render_mode_e, class PolySetEvaluator *) { p->append_poly(); p->append_vertex(ox + 0, oy + i-1, min_val); - p->append_vertex(ox + 0, oy + i-1, data[QPair<int,int>(i-1, 0)]); - p->append_vertex(ox + 0, oy + i, data[QPair<int,int>(i, 0)]); + p->append_vertex(ox + 0, oy + i-1, data[std::make_pair(i-1, 0)]); + p->append_vertex(ox + 0, oy + i, data[std::make_pair(i, 0)]); p->append_vertex(ox + 0, oy + i, min_val); p->append_poly(); p->insert_vertex(ox + columns-1, oy + i-1, min_val); - p->insert_vertex(ox + columns-1, oy + i-1, data[QPair<int,int>(i-1, columns-1)]); - p->insert_vertex(ox + columns-1, oy + i, data[QPair<int,int>(i, columns-1)]); + p->insert_vertex(ox + columns-1, oy + i-1, data[std::make_pair(i-1, columns-1)]); + p->insert_vertex(ox + columns-1, oy + i, data[std::make_pair(i, columns-1)]); p->insert_vertex(ox + columns-1, oy + i, min_val); } @@ -183,14 +187,14 @@ PolySet *SurfaceNode::evaluate_polyset(render_mode_e, class PolySetEvaluator *) { p->append_poly(); p->insert_vertex(ox + i-1, oy + 0, min_val); - p->insert_vertex(ox + i-1, oy + 0, data[QPair<int,int>(0, i-1)]); - p->insert_vertex(ox + i, oy + 0, data[QPair<int,int>(0, i)]); + p->insert_vertex(ox + i-1, oy + 0, data[std::make_pair(0, i-1)]); + p->insert_vertex(ox + i, oy + 0, data[std::make_pair(0, i)]); p->insert_vertex(ox + i, oy + 0, min_val); p->append_poly(); p->append_vertex(ox + i-1, oy + lines-1, min_val); - p->append_vertex(ox + i-1, oy + lines-1, data[QPair<int,int>(lines-1, i-1)]); - p->append_vertex(ox + i, oy + lines-1, data[QPair<int,int>(lines-1, i)]); + p->append_vertex(ox + i-1, oy + lines-1, data[std::make_pair(lines-1, i-1)]); + p->append_vertex(ox + i, oy + lines-1, data[std::make_pair(lines-1, i)]); p->append_vertex(ox + i, oy + lines-1, min_val); } |