- UI Locks up when operating (need to add threading?) - Performance is very, very, very slow On the upside, it works.
#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;
#define RESOLUTION_THRESHOLD .01f
#define EXTRUSION_THRESHOLD .0005f
string removeWhitespace(string s) {
string::iterator end_pos = remove(s.begin(), s.end(), ' ');
s.erase(end_pos, s.end());
return s;
}
bool startsWith(const string &s, const string &prefix) {
return (s.length() >= s.length() && s.find(prefix) == 0);
}
float getParameter(const string &s, char c, bool * found = NULL) {
size_t i = s.find(c);
if (i != string::npos) {
if (found) *found = true;
size_t n = s.find_first_not_of("-0123456789.", i+1);
string valstring = s.substr(i+1, n-i-1);
return atof(valstring.c_str());
} else {
if (found) *found = false;
return 0;
}
}
float xyDistance(const string &a, const string &b) {
bool found = true;
float aX = getParameter(a, 'X', &found);
if (!found) return -1;
float aY = getParameter(a, 'Y', &found);
if (!found) return -1;
float bX = getParameter(b, 'X', &found);
if (!found) return -1;
float bY = getParameter(b, 'Y', &found);
if (!found) return -1;
float dX = bX - aX;
float dY = bY - aY;
return sqrtf(dX*dX + dY*dY);
}
bool isRedundant(const string &a, const string &b) {
if (!startsWith(a, "G1") || !startsWith(b, "G1")) {
return false;
}
bool found = true;
float aE = getParameter(a, 'E', &found);
if (!found) return 0;
float bE = getParameter(b, 'E', &found);
if (!found) return 0;
if (fabsf(aE - bE) < EXTRUSION_THRESHOLD) {
// this distance check is probably unnecessary as travel moves are automatically filtered out (they don't have an E parameter)
float dist = xyDistance(a,b);
if (dist < 0) return false; // no distance data
return dist < RESOLUTION_THRESHOLD;
}
return false;
}
int main(int argc, const char * argv[]) {
if (argc < 2 || argc > 3) {
cout << "usage: gcodefix [input filename] [output filename]\n";
return 0;
}
string filename = argv[1];
cout << "Parsing " << filename.c_str() << ":" << endl;
// output file
bool output = false;
ofstream outstream;
if (argc == 3) {
output = true;
string outfile = argv[2];
outstream.open(outfile);
if (!outstream.is_open()) {
cout << "unable to open output file " << outfile.c_str() << "\n";
return 0;
}
}
// read file
int totalCount = 0;
int duplicateCount = 0;
bool relativeMotion = false;
string line;
string previousLine = "";
ifstream infile(filename);
if (infile.is_open()) {
while (getline (infile,line)) {
totalCount++;
// don't filter relative motion gcode
if (startsWith(line,"G91")) {
relativeMotion = true;
} else if (startsWith(line,"G90")) {
relativeMotion = false;
}
// ignore redundant gcode
if (!relativeMotion && startsWith(line, "G1") && isRedundant(previousLine, line)) {
duplicateCount++;
// cout << totalCount << ": " << line << endl;
continue;
}
if (output) {
outstream << line << endl;
}
previousLine = line;
}
infile.close();
if (output) {
outstream.close();
}
printf("Finished: %d / %d Lines Removed [%f%%]\n", duplicateCount, totalCount, (duplicateCount * 100.0f)/totalCount);
} else {
cout << "Unable to open input file " << filename.c_str() << endl;
}
return 0;
}
--
You received this message because you are subscribed to the Google Groups "Smoothieware Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to smoothieware-sup...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<S3DFix.zip>
I had a quick look at your code out of curiosity as I’ve been slowly building my Swift skills up too. Looks good.
You’re probably already aware that buffering the output in fileData string is the most likely cause of the performance issue, but I though I should throw it out there and break the fundamental rule of performance optimisation by optimising before profiling.Also hasPrefix should just work without needing the string length checks which I can see were inherited from the C++ code you started with.
On 22 Oct 2015, at 06:14, Leon Grossman <leongr...@gmail.com> wrote:
It's still slow (230 seconds for a 23MB file) but here is a decent version compile for Mac with a background thread. Note: the app is not signed.
On Wednesday, October 21, 2015 at 7:47:59 AM UTC-5, Leon Grossman wrote:This has now reached the point of needing it's own topic. Whether it's to avoid the dreaded crash or to improve your performance of USB printing, these apps are for you.I wanted to learn swift so I made this app. https://github.com/leonmf/S3DFix
--
You received this message because you are subscribed to the Google Groups "Smoothieware Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to smoothieware-support+unsub...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to smoothieware-support+unsub...@googlegroups.com.
Removing the SQRT function is a great idea! The class property can set the square at the top of the app. I still think my killer is the string functions but I'm betting this gives us nontrivial gains since SQRT is relatively computationally expensive. Unfortunately, I won't be able to touch this again until later tonight.