Permalink
Browse files

incredible antiooze speedup

  • Loading branch information...
1 parent 046ccf4 commit ec912b0bcce0a4aec3684161cc03f5c79cb4f643 @hurzl hurzl committed Oct 17, 2012
Showing with 100 additions and 64 deletions.
  1. +4 −4 src/slicer/printlines.cpp
  2. +11 −3 src/slicer/printlines.h
  3. +85 −57 src/slicer/printlines_antiooze.cpp
@@ -365,15 +365,15 @@ vector<PLine3> PLine3::division(const vector<Vector3d> &points) const
}
-void PLine3::addAbsoluteExtrusionAmount(double amount, double max_absspeed)
+void PLine3::addAbsoluteExtrusionAmount(double amount, double max_absspeed, double ltime)
{
if (area == COMMAND) return;
absolute_extrusion += amount;
// slowdown if max speed given and not enough time for absolute feed:
- const double t = time();
const double feedt = abs(absolute_extrusion/max_absspeed);
- if ( feedt > t ) // too fast
- speed *= t / feedt;
+ if (ltime == 0) ltime = time();
+ if (ltime>0 && feedt > ltime ) // too fast
+ speed *= ltime / feedt;
//cerr << "added abs at speed " << ( absolute_extrusion)/time() << endl;
}
double PLine3::addMaxAbsoluteExtrusionAmount(double max_absspeed)
@@ -106,7 +106,7 @@ class PLine3 : public PLine<3>
double calcangle() const {return angle;}
- void addAbsoluteExtrusionAmount(double amount, double max_absspeed);
+ void addAbsoluteExtrusionAmount(double amount, double max_absspeed, double time=0);
double addMaxAbsoluteExtrusionAmount(double max_absspeed);
double max_abs_speed(double max_espeed, double max_absspeed) const;
@@ -191,6 +191,15 @@ class PrintPoly
string info() const;
};
+
+typedef struct {
+ uint movestart, moveend, tractstart, pushend;
+ void add(uint a) {
+ movestart+=a, moveend+=a; tractstart+=a; pushend+=a;
+ }
+} AORange;
+
+
// a bunch of printlines: lines with feedrate
// optimize for corners etc.
class Printlines
@@ -258,8 +267,7 @@ class Printlines
uint ind, vector<PLine2> &lines) const;
static bool find_nextmoves(double minlength, uint startindex,
- uint &movestart, uint &moveend,
- uint &tractstart, uint &pushend,
+ AORange &range,
const vector< PLine3 > &lines);
static uint makeAntioozeRetract(vector< PLine3 > &lines,
const Settings &settings,
@@ -22,14 +22,13 @@
#define AODEBUG 0
+
#if AODEBUG
-void test_range(uint movestart, uint moveend,
- uint tractstart, uint pushend,
- const vector<PLine3> &lines)
+void test_range(AORange range, const vector<PLine3> &lines)
{
ostringstream o;
bool error=false;
- for (uint i = tractstart; i < movestart; i++)
+ for (uint i = range.tractstart; i < range.movestart; i++)
if (lines[i].is_command()) o << "C";
else if (lines[i].is_move()) {
error = true;
@@ -38,7 +37,7 @@ void test_range(uint movestart, uint moveend,
}
else o << "+"; // ok
o << "|";
- for (uint i = movestart; i<=moveend; i++)
+ for (uint i = range.movestart; i<=range.moveend; i++)
if (lines[i].is_command()) o << "C";
else if (lines[i].is_move()) o << "-"; //ok
else {
@@ -47,7 +46,7 @@ void test_range(uint movestart, uint moveend,
o << "!";
}
o << "|";
- for (uint i = moveend+1; i<=pushend; i++)
+ for (uint i = range.moveend+1; i<=range.pushend; i++)
if (lines[i].is_command()) o << "C";
else if (lines[i].is_move()) {
error = true;
@@ -114,40 +113,41 @@ inline bool find_moverange(double minlength, uint startindex,
// find ranges for retract and repush
bool Printlines::find_nextmoves(double minlength, uint startindex,
- uint &movestart, uint &moveend,
- uint &tractstart, uint &pushend,
+ AORange &range,
const vector<PLine3> &lines)
{
- if (!find_moverange(minlength, startindex, movestart, moveend, lines)) return false;
+ if (!find_moverange(minlength, startindex,
+ range.movestart, range.moveend, lines)) return false;
uint num_lines = lines.size();
// find previous move
- if (movestart == 0) tractstart = 0;
+ if (range.movestart == 0) range.tractstart = 0;
else {
- int i = movestart-1;
- tractstart = movestart;
+ int i = range.movestart-1;
+ range.tractstart = range.movestart;
while ( i >= (int)startindex
&& ( !(lines[i].is_move() || lines[i].has_absolute_extrusion())
|| lines[i].is_command() )) {
- tractstart = i; i--;
+ range.tractstart = i; i--;
}
}
- while (tractstart < num_lines-1 && lines[tractstart].is_command()) tractstart++;
+ while (range.tractstart < num_lines-1
+ && lines[range.tractstart].is_command()) range.tractstart++;
// find next move after
- if (moveend == num_lines-1) pushend = moveend;
+ if (range.moveend == num_lines-1) range.pushend = range.moveend;
else {
- uint i = moveend+1;
- pushend = moveend;
+ uint i = range.moveend+1;
+ range.pushend = range.moveend;
while ( i < num_lines && (!(lines[i].is_move() || lines[i].has_absolute_extrusion())
|| lines[i].is_command()) ) {
- pushend = i; i++;
+ range.pushend = i; i++;
}
}
- while (pushend > 0 && lines[pushend].is_command()) pushend--;
+ while (range.pushend > 0 && lines[range.pushend].is_command()) range.pushend--;
#if AODEBUG
- test_range(movestart,moveend,tractstart,pushend, lines);
+ test_range(range, lines);
#endif
// cerr << "found move " << tractstart << "..." <<movestart
// << "--"<<moveend<< "..."<< pushend << endl;
@@ -222,8 +222,9 @@ int Printlines::distribute_AntioozeAmount(double AOamount, double AOspeed,
distCase = 2;
#endif
for (uint i=fromline; i<=toline; i++) {
- double ratio = lines[i].time() / linestime;
- lines[i].addAbsoluteExtrusionAmount(AOamount * ratio, AOspeed);// will slow line down
+ const double time = lines[i].time();
+ const double ratio = time / linestime;
+ lines[i].addAbsoluteExtrusionAmount(AOamount * ratio, AOspeed, time);// will slow line down
#if AODEBUG
havedistributed += AOamount * ratio;
#endif
@@ -242,7 +243,8 @@ int Printlines::distribute_AntioozeAmount(double AOamount, double AOspeed,
const double sign = (negative?-1.:1.);
const double signedSpeed = AOspeed * sign;
int i;
- for (i = (int)fromline; i != (int)toline+di; i+=di) {
+ int end = (int)toline+di;
+ for (i = (int)fromline; i != end; i+=di) {
if (i<0) break;
double lineamount = lines[i].addMaxAbsoluteExtrusionAmount(signedSpeed); // +-
havedistributed += lineamount;
@@ -259,7 +261,7 @@ int Printlines::distribute_AntioozeAmount(double AOamount, double AOspeed,
const double line_ex = lines[i].absolute_extrusion;
const double neededtime = abs(line_ex / AOspeed);
double fraction = neededtime/lines[i].time();
- if (fraction < 1) {
+ if (fraction < 0.9) { // allow 10% slower AO to avoid split
if (reverse) fraction = 1-fraction;
added = divideline(i, fraction * lines[i].length(), lines);
if (added == 1) {
@@ -297,83 +299,109 @@ uint Printlines::makeAntioozeRetract(vector<PLine3> &lines,
// const double onmove_amount = AOamount - onhalt_amount;
uint linescount = lines.size();
- if (progress) progress->restart (_("Antiooze Retract"), linescount);
uint total_added = 0;
#if AODEBUG
double total_extrusionsum = 0;
double total_ext = total_Extrusion(lines);
double total_rel = total_rel_Extrusion(lines);
#endif
- uint
- movestart = 0, moveend = 0, // move-only range
- tractstart = 0, pushend = 0; // ends of ranges of retract and repush
uint count = 0;
+ if (progress) if (!progress->restart (_("Antiooze Retract find ranges"), linescount)) return 0;
+ vector<AORange> ranges;
+ AORange range;
+ uint lastend = 0;
while ( find_nextmoves(AOmindistance,
- pushend+1, // set
- movestart, moveend, // get
- tractstart, pushend, // get
+ lastend, // set
+ range, //get
lines) ) {
- if (movestart > linescount-1) break;
+ if (range.movestart > linescount-1) break;
if (progress){
if (count%20 == 0)
- if (!progress->update(movestart)) break;
+ if (!progress->update(range.movestart)) break;
}
count++;
+ ranges.push_back(range);
+ lastend = range.pushend+1;
+ }
+
+ // copy all lines successively to avoid mid-insertion
+ vector<PLine3> newlines;
+ // at most count*2 lines will be added
+ newlines.reserve(linescount + count*2);
+
+ if (progress) if (!progress->restart (_("Antiooze Retract"), ranges.size())) return 0;
+ lastend = 0;
+ for (uint r = 0; r < ranges.size(); r++) {
+ //for (int r = ranges.size()-1; r >= 0; r--) {
+ if (progress){
+ if (r%20 == 0)
+ if (!progress->update(r)) break;
+ }
+
+ ranges[r].add(total_added); // shift by previous insertion
uint added = 0;
- if (moveend > lines.size()-2) moveend = lines.size()-2;
+
+ // get next slice of lines
+ uint endcopy = min(ranges[r].pushend+1, linescount);
+ newlines.insert(newlines.end(),
+ lines.begin()+lastend, lines.begin()+endcopy);
+ lastend = endcopy;
+
+ if (ranges[r].moveend > newlines.size()-2) ranges[r].moveend = newlines.size()-2;
// lift move-only range
if (settings.Extruder.AntioozeZlift > 0)
- for (uint i = movestart; i <= moveend; i++) {
- lines[i].lifted = settings.Extruder.AntioozeZlift;
+ for (uint i = ranges[r].movestart; i <= ranges[r].moveend; i++) {
+ newlines[i].lifted = settings.Extruder.AntioozeZlift;
}
// do repush first to keep indices before right
double havedist = 0;
uint newl = distribute_AntioozeAmount(AOamount, AOspeed,
- moveend+1, pushend,
- lines, havedist);
+ ranges[r].moveend+1, ranges[r].pushend,
+ newlines, havedist);
added += newl;
- pushend += newl;
- //test_range(movestart,moveend,tractstart,pushend, lines);
+ ranges[r].pushend += newl;
+ //test_range(movestart,moveend,tractstart,pushend, newlines);
#if AODEBUG
double extrusionsum = 0;
double linesext = 0;
- for (uint i = moveend+1; i<=pushend; i++) linesext+=lines[i].absolute_extrusion;
+ for (uint i = ranges[r].moveend+1; i<=ranges[r].pushend; i++)
+ linesext+=newlines[i].absolute_extrusion;
if (abs(linesext-AOamount)>0.01) cerr << "wrong lines dist push " << linesext << endl;
extrusionsum += havedist;
if (abs(havedist-AOamount)>0.01) cerr << " wrong distrib push " << havedist << endl;
#endif
// find lines to distribute retract
- if (movestart < 1) movestart = 1;
+ if (ranges[r].movestart < 1) ranges[r].movestart = 1;
#if AODEBUG
double linesextbefore = 0;
- for (uint i = tractstart; i < movestart; i++)
- linesextbefore += lines[i].absolute_extrusion;
+ for (uint i = ranges[r].tractstart; i < ranges[r].movestart; i++)
+ linesextbefore += newlines[i].absolute_extrusion;
#endif
havedist = 0;
newl = distribute_AntioozeAmount(-AOamount, AOspeed,
- movestart-1, tractstart,
- lines, havedist);
+ ranges[r].movestart-1, ranges[r].tractstart,
+ newlines, havedist);
added += newl;
- movestart += newl;
- moveend += newl;
- pushend += newl;
+ ranges[r].movestart += newl;
+ ranges[r].moveend += newl;
+ ranges[r].pushend += newl;
total_added += added;
#if AODEBUG
linesext = -linesextbefore;
- for (uint i = tractstart; i < movestart; i++)
- linesext += lines[i].absolute_extrusion;
+ for (uint i = ranges[r].tractstart; i < ranges[r].movestart; i++)
+ linesext += newlines[i].absolute_extrusion;
if (abs(linesext+AOamount)>0.01)
cerr << "wrong lines dist tract " << distCase << " : "<<linesextbefore << " : "<<linesext << " (" << havedist << ") != " << -AOamount
- << " - " << tractstart << "->" << movestart
+ << " - " << ranges[r].tractstart << "->" << ranges[r].movestart
<< " new: "<< newl << " -- before: "<<linesextbefore<< endl;
// else
// cerr << "dist tract ok: " << distCase << " : " << linesext << " new: " << newl <<endl;
@@ -383,21 +411,21 @@ uint Printlines::makeAntioozeRetract(vector<PLine3> &lines,
total_extrusionsum += extrusionsum;
#endif
}
-
#if AODEBUG
if (abs(total_extrusionsum) > 0.01) cerr << "wrong total AO extr.: " << total_extrusionsum << endl;
- double totalabs = total_abs_Extrusion(lines);
+ double totalabs = total_abs_Extrusion(newlines);
if (abs(totalabs)>0.01)
cerr << "abs-extrusion difference after antiooze " << totalabs << endl;
- double total_rel2 = total_rel_Extrusion(lines) - total_rel;
+ double total_rel2 = total_rel_Extrusion(newlines) - total_rel;
if (abs(total_rel2)>0.01)
cerr << "rel-extrusion difference after antiooze " << total_rel2 << endl;
- double total_ext2 = total_Extrusion(lines) - total_ext;
+ double total_ext2 = total_Extrusion(newlines) - total_ext;
if (abs(total_ext2)>0.01)
cerr << "total extrusion difference after antiooze " << total_ext2 << endl;
#endif
-
+ //cerr << lines.size() << " - " << newlines.size() << "- " <<total_added << endl;
+ lines = newlines;
return total_added;
}

0 comments on commit ec912b0

Please sign in to comment.