diff options
author | Marius Kintel <marius@kintel.net> | 2011-12-06 21:35:03 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2011-12-06 21:35:03 (GMT) |
commit | 33a2b0e502ae893c1f3a1c2927eab30de3737e58 (patch) | |
tree | f5e064748cb94ce968fe86258a7e0077bd0ce0e8 /src/import.cc | |
parent | b3fa4d98a41b32547e1ec661f826913d3540c929 (diff) |
Ported away more of the STL parser from Qt
Diffstat (limited to 'src/import.cc')
-rw-r--r-- | src/import.cc | 76 |
1 files changed, 43 insertions, 33 deletions
diff --git a/src/import.cc b/src/import.cc index 63bdb86..07100e3 100644 --- a/src/import.cc +++ b/src/import.cc @@ -48,6 +48,7 @@ #include <assert.h> #include <boost/algorithm/string.hpp> #include <boost/regex.hpp> +#include <boost/lexical_cast.hpp> #include <boost/filesystem.hpp> using namespace boost::filesystem; #include <boost/assign/std/vector.hpp> @@ -121,55 +122,62 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *evaluator) const if (this->type == TYPE_STL) { handle_dep(this->filename); - QFile f(QString::fromStdString(this->filename)); - if (!f.open(QIODevice::ReadOnly)) { + std::ifstream f(this->filename.c_str()); + if (!f.good()) { +// QFile f(QString::fromStdString(this->filename)); +// if (!f.open(QIODevice::ReadOnly)) { PRINTF("WARNING: Can't open import file `%s'.", this->filename.c_str()); return p; } p = new PolySet(); - // char data[5]; - // f.read(data, 5); - // if (!f.eof() && memcmp(data, "solid", 5)) { - QByteArray data = f.read(5); - if (data.size() == 5 && QString(data) == QString("solid")) { + boost::regex ex_sfe("solid|facet|endloop"); + boost::regex ex_outer("outer loop"); + boost::regex ex_vertex("vertex"); + boost::regex ex_vertices("\\s*vertex\\s+([^\\s]+)\\s+([^\\s]+)\\s+([^\\s]+)"); + + char data[5]; + f.read(data, 5); + if (!f.eof() && !memcmp(data, "solid", 5)) { +// QByteArray data = f.read(5); +// if (data.size() == 5 && QString(data) == QString("solid")) { int i = 0; double vdata[3][3]; QRegExp splitre = QRegExp("\\s*(vertex)?\\s+"); - // std::string line; - // std::getline(f, line); - f.readLine(); -// while (!f.eof()) { -// boost::regex ex_sfe("solid|facet|endloop"); -// boost::regex ex_outer("outer loop"); -// boost::regex ex_vertex("vertex"); - while (!f.atEnd()) { - // std::getline(f, line); - // boost::trim(line); - QString line = QString(f.readLine()).remove("\n").remove("\r"); -// if (boost.regex_search(line, ex_sfe)) { - if (line.contains("solid") || line.contains("facet") || line.contains("endloop")) { + std::string line; + std::getline(f, line); +// f.readLine(); + while (!f.eof()) { + +// while (!f.atEnd()) { + std::getline(f, line); + boost::trim(line); +// QString line = QString(f.readLine()).remove("\n").remove("\r"); + if (boost::regex_search(line, ex_sfe)) { +// if (line.contains("solid") || line.contains("facet") || line.contains("endloop")) { continue; } -// if (boost.regex_search(line, ex_outer)) { - if (line.contains("outer loop")) { + if (boost::regex_search(line, ex_outer)) { +// if (line.contains("outer loop")) { i = 0; continue; } -// if (boost.regex_search(line, ex_vertex)) { - if (line.contains("vertex")) { - QStringList tokens = line.split(splitre); - bool ok[3] = { false, false, false }; - if (tokens.size() == 4) { - vdata[i][0] = tokens[1].toDouble(&ok[0]); - vdata[i][1] = tokens[2].toDouble(&ok[1]); - vdata[i][2] = tokens[3].toDouble(&ok[2]); + boost::smatch results; + if (boost::regex_search(line, results, ex_vertices)) { +// if (line.contains("vertex")) { +// QStringList tokens = QString::fromStdString(line).split(splitre); + try { + for (int v=0;v<3;v++) { + vdata[i][v] = boost::lexical_cast<double>(results[v+1]); + } } - if (!ok[0] || !ok[1] || !ok[2]) { - PRINTF("WARNING: Can't parse vertex line `%s'.", line.toAscii().data()); + catch (boost::bad_lexical_cast &blc) { + PRINTF("WARNING: Can't parse vertex line `%s'.", line.c_str()); i = 10; - } else if (++i == 3) { + continue; + } + if (++i == 3) { p->append_poly(); p->append_vertex(vdata[0][0], vdata[0][1], vdata[0][2]); p->append_vertex(vdata[1][0], vdata[1][1], vdata[1][2]); @@ -180,6 +188,7 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *evaluator) const } else { +/* f.read(80-5+4); while (1) { #ifdef _MSC_VER @@ -207,6 +216,7 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *evaluator) const p->append_vertex(data.x2, data.y2, data.z2); p->append_vertex(data.x3, data.y3, data.z3); } +*/ } } |