Skip to content

Commit

Permalink
Instead of randomizing, go to farthest point each layer
Browse files Browse the repository at this point in the history
- don't displace polygon startpoints by sharp edges or randomly
+ add debug option to show only z changing gcode
  • Loading branch information
hurzl committed Nov 28, 2013
1 parent 732695c commit 673027c
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 62 deletions.
21 changes: 15 additions & 6 deletions src/gcode/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ void GCode::draw(const Settings &settings, int layer,

drawCommands(settings, start, end, liveprinting, linewidth,
arrows && settings.get_boolean("Display","DisplayGCodeArrows"),
!liveprinting && settings.get_boolean("Display","DisplayGCodeBorders"));
!liveprinting && settings.get_boolean("Display","DisplayGCodeBorders"),
settings.get_boolean("Display","DebugGCodeOnlyZChange"));

if (currentCursorWhere!=Vector3d::ZERO) {
glDisable(GL_DEPTH_TEST);
Expand All @@ -454,7 +455,8 @@ void GCode::draw(const Settings &settings, int layer,


void GCode::drawCommands(const Settings &settings, uint start, uint end,
bool liveprinting, int linewidth, bool arrows, bool boundary)
bool liveprinting, int linewidth, bool arrows, bool boundary,
bool onlyZChange)
{
// if (gl_List < 0) {
// gl_List = glGenLists(1);
Expand Down Expand Up @@ -529,6 +531,13 @@ void GCode::drawCommands(const Settings &settings, uint start, uint end,
}
double extrwidth = extrusionwidth;
if (commands[i].is_value) continue;
if (onlyZChange && commands[i].where.z() == pos.z()) {
pos = commands[i].where;
LastE=commands[i].e;
continue;
}


switch(commands[i].Code)
{
case SETSPEED:
Expand Down Expand Up @@ -591,16 +600,16 @@ void GCode::drawCommands(const Settings &settings, uint start, uint end,
}
if (luminanceshowsspeed)
Color *= luma;
commands[i].draw(pos, extruder_offset, linewidth,
Color, extrwidth, arrows, debug_arcs);
commands[i].draw(pos, extruder_offset, linewidth,
Color, extrwidth, arrows, debug_arcs);
LastE=commands[i].e;
break;
}
case RAPIDMOTION:
{
Color = gcodemovecolour;
commands[i].draw(pos, extruder_offset, 1, Color,
extrwidth, arrows, debug_arcs);
commands[i].draw(pos, extruder_offset, 1, Color,
extrwidth, arrows, debug_arcs);
break;
}
default:
Expand Down
3 changes: 2 additions & 1 deletion src/gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class GCode
int layer=-1, bool liveprinting=false,
int linewidth=3);
void drawCommands(const Settings &settings, uint start, uint end,
bool liveprinting, int linewidth, bool arrows, bool boundary=false);
bool liveprinting, int linewidth, bool arrows, bool boundary=false,
bool onlyZChange = false);
void MakeText(string &GcodeTxt, const Settings &settings,
ViewProgress * progress);

Expand Down
10 changes: 6 additions & 4 deletions src/model_slice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ void Model::ConvertToGCode()

bool cont = true;
vector<PLine3> plines;
bool randomizeStart = settings.get_boolean("Slicing","RandomizeLayerStart");
bool farthestStart = settings.get_boolean("Slicing","FarthestLayerStart");
Vector3d start = state.LastPosition();
for (uint p=0; p<count; p++) {
cont = (m_progress->update(p)) ;
Expand All @@ -874,9 +874,11 @@ void Model::ConvertToGCode()
// << " have commands: " <<commands.size()
// << " start " << start << endl;;
// try {
if (randomizeStart) {
Vector2d randstart = layers[p]->getRandomPolygonPoint();
start.set(randstart.x(), randstart.y());
if (farthestStart) {
// Vector2d randstart = layers[p]->getRandomPolygonPoint();
// start.set(randstart.x(), randstart.y());
Vector2d fartheststart = layers[p]->getFarthestPolygonPoint(start);
start.set(fartheststart.x(), fartheststart.y());
}
layers[p]->MakePrintlines(start,
plines,
Expand Down
4 changes: 3 additions & 1 deletion src/repsnapper.conf
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ NoBridges=false
BridgeExtrusion=1
GCodePostprocess=false
GCodePostprocessor=
RandomizeLayerStart=true
RandomizeLayerStart=false
FarthestLayerStart=true

[Milling]
ToolDiameter=2
Expand Down Expand Up @@ -138,6 +139,7 @@ DisplayDebug=false
DisplayDebugArcs=true
DebugGCodeExtruders=false
DebugGCodeOffset=true
DisplayDebugGCodeOnlyZChange=false
DisplayFilledAreas=true
ShowLayerOverhang=false
CommsDebug=false
Expand Down
90 changes: 49 additions & 41 deletions src/repsnapper.ui
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,6 @@
<property name="short_label">Calibrate</property>
<property name="tooltip">An interactive calibration routine</property>
</object>
<object class="GtkAdjustment" id="Display.HighlightAdjustment">
<property name="upper">1</property>
<property name="step_increment">0.10000000000000001</property>
<property name="page_increment">0.25</property>
</object>
<object class="GtkAdjustment" id="Display.NormalsLengthAdjustment">
<property name="upper">30</property>
<property name="value">10</property>
<property name="step_increment">0.10000000000000001</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="Display.PolygonOpacityAdjustment">
<property name="upper">1</property>
<property name="step_increment">0.10000000000000001</property>
<property name="page_increment">0.25</property>
</object>
<object class="GtkAdjustment" id="DisplayEndPointSizeAdjustment">
<property name="upper">20</property>
<property name="value">8</property>
<property name="step_increment">0.10000000000000001</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAction" id="Fullscreen">
<property name="label">Fullscreen</property>
<property name="short_label" translatable="yes">Fullscreen</property>
<property name="tooltip">Toggle Fullscreen</property>
</object>
<object class="GtkAction" id="LoadSettings">
<property name="label" translatable="yes">Load Settings</property>
<property name="short_label" translatable="yes">Load Settings</property>
<property name="tooltip" translatable="yes">Load application settings profile</property>
</object>
<object class="GtkAction" id="OpenGCode">
<property name="label" translatable="yes">Load _GCode</property>
<property name="short_label" translatable="yes">Load GCode</property>
Expand Down Expand Up @@ -79,6 +47,38 @@
<property name="short_label" translatable="yes">Save Settings As</property>
<property name="tooltip" translatable="yes">Save settings in a custom file</property>
</object>
<object class="GtkAdjustment" id="Display.HighlightAdjustment">
<property name="upper">1</property>
<property name="step_increment">0.10000000000000001</property>
<property name="page_increment">0.25</property>
</object>
<object class="GtkAdjustment" id="Display.NormalsLengthAdjustment">
<property name="upper">30</property>
<property name="value">10</property>
<property name="step_increment">0.10000000000000001</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="Display.PolygonOpacityAdjustment">
<property name="upper">1</property>
<property name="step_increment">0.10000000000000001</property>
<property name="page_increment">0.25</property>
</object>
<object class="GtkAdjustment" id="DisplayEndPointSizeAdjustment">
<property name="upper">20</property>
<property name="value">8</property>
<property name="step_increment">0.10000000000000001</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAction" id="Fullscreen">
<property name="label">Fullscreen</property>
<property name="short_label" translatable="yes">Fullscreen</property>
<property name="tooltip">Toggle Fullscreen</property>
</object>
<object class="GtkAction" id="LoadSettings">
<property name="label" translatable="yes">Load Settings</property>
<property name="short_label" translatable="yes">Load Settings</property>
<property name="tooltip" translatable="yes">Load application settings profile</property>
</object>
<object class="GtkWindow" id="PrinterControlWindowTest">
<property name="can_focus">False</property>
<property name="default_width">200</property>
Expand Down Expand Up @@ -7246,25 +7246,19 @@ Otherwise the STL will contain separate Objects and it will be in ASCII mode (so
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<object class="GtkCheckButton" id="Slicing.RandomizeLayerStart">
<property name="label" translatable="yes">Randomize Layer Start</property>
<object class="GtkCheckButton" id="Slicing.FarthestLayerStart">
<property name="label" translatable="yes">Move to Farthest Point on Layer Start</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="right_attach">2</property>
<property name="right_attach">4</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
Expand Down Expand Up @@ -9463,6 +9457,20 @@ Otherwise the STL will contain separate Objects and it will be in ASCII mode (so
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="Display.DebugGCodeOnlyZChange">
<property name="label" translatable="yes">Show only GCode with Z Change</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
</child>
</object>
Expand Down
15 changes: 15 additions & 0 deletions src/slicer/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@ Vector2d Layer::getRandomPolygonPoint() const
Poly p = polygons[rand()%polygons.size()];
return p.vertices[rand()%p.size()];
}
Vector2d Layer::getFarthestPolygonPoint(const Vector2d &from) const
{
uint pindex = 0, pvindex = 0;
double maxdist = 0.;
for (uint i = 0; i<polygons.size(); i++) {
uint fi = polygons[i].getFarthestIndex(from);
double pdist = from.squared_distance(polygons[i][fi]);
if (pdist > maxdist) {
maxdist = pdist;
pindex = i;
pvindex = fi;
}
}
return polygons[pindex][pvindex];
}

bool Layer::pointInPolygons(const Vector2d &p) const
{
Expand Down
1 change: 1 addition & 0 deletions src/slicer/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Layer
bool pointInPolygons(const Vector2d &p) const;

Vector2d getRandomPolygonPoint() const;
Vector2d getFarthestPolygonPoint(const Vector2d &from) const;
/* void setBBox(Vector2d min, Vector2d max); */
/* void setBBox(vector<Vector2d> minmax); */
/* void setBBox(Vector3d min, Vector3d max); */
Expand Down
18 changes: 11 additions & 7 deletions src/slicer/poly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,24 @@ void Poly::mirrorX(const Vector3d &center)

uint Poly::getFarthestIndex(uint &thisindex) const
{
int findex = thisindex;
return getFarthestIndex(vertices[thisindex]);
}

uint Poly::getFarthestIndex(const Vector2d &from) const
{
uint findex = 0;
double maxdist = 0.;
for (uint i = 0; i < size(); i++) {
if (i != thisindex) {
double d = vertices[thisindex].squared_distance(vertices[i]);
if (d > maxdist) {
maxdist = d;
findex = i;
}
double d = from.squared_distance(vertices[i]);
if (d > maxdist) {
maxdist = d;
findex = i;
}
}
return findex;
}


// nearest connection point indices of this and other poly
// if poly is not closed, only test first and last point
void Poly::nearestIndices(const Poly &p2, int &thisindex, int &otherindex) const
Expand Down
1 change: 1 addition & 0 deletions src/slicer/poly.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Poly
vector<Vector2d> getCenterline() const;

uint getFarthestIndex(uint &thisindex) const;
uint getFarthestIndex(const Vector2d &from) const;

void rotate(const Vector2d &center, double angle);
void move(const Vector2d &delta);
Expand Down
4 changes: 2 additions & 2 deletions src/slicer/printlines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ uint PrintPoly::getDisplacedStart(uint start) const
{
//cerr << start << " --> ";
if (displace_start) {
#if 1
#if 0
// find next sharp corner (>pi/4)
uint oldstart = start; // save start position
start = m_poly->nextVertex(start);
Expand All @@ -658,7 +658,7 @@ uint PrintPoly::getDisplacedStart(uint start) const
// no sharp corner found:
if (start == oldstart)
#endif
start = rand()%m_poly->size(); // randomize
// start = rand()%m_poly->size(); // randomize
//start = m_poly->getFarthestIndex(start); // take farthest point
}
//cerr << start << endl;
Expand Down

0 comments on commit 673027c

Please sign in to comment.