New seal_position option that replaces randomize_start, start_perimeters_at_concave_points and start_perimeters_at_non_overhang. The two latter options are now always on by default. A new "Aligned" seal position value has been added, that forces starting points to be aligned when not randomized. #1741 #925

This commit is contained in:
Alessandro Ranellucci 2014-05-22 19:34:49 +02:00
parent c63bd8165d
commit a3bd1b5302
17 changed files with 153 additions and 112 deletions

View file

@ -1,7 +1,13 @@
#include "MultiPoint.hpp"
#include "BoundingBox.hpp"
namespace Slic3r {
MultiPoint::operator Points() const
{
return this->points;
}
void
MultiPoint::scale(double factor)
{
@ -64,6 +70,12 @@ MultiPoint::find_point(const Point &point) const
return -1; // not found
}
void
MultiPoint::bounding_box(BoundingBox* bb) const
{
*bb = BoundingBox(this->points);
}
Points
MultiPoint::_douglas_peucker(const Points &points, const double tolerance)
{

View file

@ -2,17 +2,21 @@
#define slic3r_MultiPoint_hpp_
#include <myinit.h>
#include "Line.hpp"
#include "Point.hpp"
#include <algorithm>
#include <vector>
#include "Line.hpp"
#include "Point.hpp"
namespace Slic3r {
class BoundingBox;
class MultiPoint
{
public:
Points points;
operator Points() const;
void scale(double factor);
void translate(double x, double y);
void rotate(double angle, const Point &center);
@ -23,6 +27,8 @@ class MultiPoint
double length() const;
bool is_valid() const;
int find_point(const Point &point) const;
void bounding_box(BoundingBox* bb) const;
static Points _douglas_peucker(const Points &points, const double tolerance);
#ifdef SLIC3RXS

View file

@ -191,6 +191,24 @@ Polygon::triangulate_convex(Polygons* polygons) const
}
}
// center of mass
Point
Polygon::centroid() const
{
double area_temp = this->area();
double x_temp = 0;
double y_temp = 0;
Polyline polyline;
this->split_at_first_point(&polyline);
for (Points::const_iterator point = polyline.points.begin(); point != polyline.points.end() - 1; ++point) {
x_temp += (double)( point->x + (point+1)->x ) * ( (double)point->x*(point+1)->y - (double)(point+1)->x*point->y );
y_temp += (double)( point->y + (point+1)->y ) * ( (double)point->x*(point+1)->y - (double)(point+1)->x*point->y );
}
return Point(x_temp/(6*area_temp), y_temp/(6*area_temp));
}
#ifdef SLIC3RXS
REGISTER_CLASS(Polygon, "Polygon");

View file

@ -35,6 +35,7 @@ class Polygon : public MultiPoint {
Polygons simplify(double tolerance) const;
void simplify(double tolerance, Polygons &polygons) const;
void triangulate_convex(Polygons* polygons) const;
Point centroid() const;
#ifdef SLIC3RXS
void from_SV_check(SV* poly_sv);

View file

@ -18,6 +18,10 @@ enum SupportMaterialPattern {
smpRectilinear, smpRectilinearGrid, smpHoneycomb, smpPillars,
};
enum SealPosition {
spRandom, spNearest, spAligned
};
template<> inline t_config_enum_values ConfigOptionEnum<GCodeFlavor>::get_enum_values() {
t_config_enum_values keys_map;
keys_map["reprap"] = gcfRepRap;
@ -50,6 +54,14 @@ template<> inline t_config_enum_values ConfigOptionEnum<SupportMaterialPattern>:
return keys_map;
}
template<> inline t_config_enum_values ConfigOptionEnum<SealPosition>::get_enum_values() {
t_config_enum_values keys_map;
keys_map["random"] = spRandom;
keys_map["nearest"] = spNearest;
keys_map["aligned"] = spAligned;
return keys_map;
}
class PrintConfigDef
{
public:
@ -584,11 +596,6 @@ class PrintConfigDef
Options["raft_layers"].sidetext = "layers";
Options["raft_layers"].cli = "raft-layers=i";
Options["randomize_start"].type = coBool;
Options["randomize_start"].label = "Randomize starting points";
Options["randomize_start"].tooltip = "Start each layer from a different vertex to prevent plastic build-up on the same corner.";
Options["randomize_start"].cli = "randomize-start!";
Options["resolution"].type = coFloat;
Options["resolution"].label = "Resolution";
Options["resolution"].tooltip = "Minimum detail resolution, used to simplify the input file for speeding up the slicing job and reducing memory usage. High-resolution models often carry more detail than printers can render. Set to zero to disable any simplification and use full resolution from input.";
@ -644,6 +651,19 @@ class PrintConfigDef
Options["retract_speed"].cli = "retract-speed=f@";
Options["retract_speed"].max = 1000;
Options["seal_position"].type = coEnum;
Options["seal_position"].label = "Seal position";
Options["seal_position"].category = "Layers and perimeters";
Options["seal_position"].tooltip = "Position of perimeters starting points.";
Options["seal_position"].cli = "seal-position=s";
Options["seal_position"].enum_keys_map = ConfigOptionEnum<SealPosition>::get_enum_values();
Options["seal_position"].enum_values.push_back("random");
Options["seal_position"].enum_values.push_back("nearest");
Options["seal_position"].enum_values.push_back("aligned");
Options["seal_position"].enum_labels.push_back("Random");
Options["seal_position"].enum_labels.push_back("Nearest");
Options["seal_position"].enum_labels.push_back("Aligned");
Options["skirt_distance"].type = coFloat;
Options["skirt_distance"].label = "Distance from object";
Options["skirt_distance"].tooltip = "Distance between skirt and object(s). Set this to zero to attach the skirt to the object(s) and get a brim for better adhesion.";
@ -753,16 +773,6 @@ class PrintConfigDef
Options["start_gcode"].full_width = true;
Options["start_gcode"].height = 120;
Options["start_perimeters_at_concave_points"].type = coBool;
Options["start_perimeters_at_concave_points"].label = "Concave points";
Options["start_perimeters_at_concave_points"].tooltip = "Prefer to start perimeters at a concave point.";
Options["start_perimeters_at_concave_points"].cli = "start-perimeters-at-concave-points!";
Options["start_perimeters_at_non_overhang"].type = coBool;
Options["start_perimeters_at_non_overhang"].label = "Non-overhang points";
Options["start_perimeters_at_non_overhang"].tooltip = "Prefer to start perimeters at non-overhanging points.";
Options["start_perimeters_at_non_overhang"].cli = "start-perimeters-at-non-overhang!";
Options["support_material"].type = coBool;
Options["support_material"].label = "Generate support material";
Options["support_material"].category = "Support material";
@ -996,6 +1006,7 @@ class PrintObjectConfig : public virtual StaticPrintConfig
ConfigOptionBool interface_shells;
ConfigOptionFloat layer_height;
ConfigOptionInt raft_layers;
ConfigOptionEnum<SealPosition> seal_position;
ConfigOptionBool support_material;
ConfigOptionInt support_material_angle;
ConfigOptionInt support_material_enforce_layers;
@ -1020,6 +1031,7 @@ class PrintObjectConfig : public virtual StaticPrintConfig
this->interface_shells.value = false;
this->layer_height.value = 0.4;
this->raft_layers.value = 0;
this->seal_position.value = spAligned;
this->support_material.value = false;
this->support_material_angle.value = 0;
this->support_material_enforce_layers.value = 0;
@ -1045,6 +1057,7 @@ class PrintObjectConfig : public virtual StaticPrintConfig
if (opt_key == "interface_shells") return &this->interface_shells;
if (opt_key == "layer_height") return &this->layer_height;
if (opt_key == "raft_layers") return &this->raft_layers;
if (opt_key == "seal_position") return &this->seal_position;
if (opt_key == "support_material") return &this->support_material;
if (opt_key == "support_material_angle") return &this->support_material_angle;
if (opt_key == "support_material_enforce_layers") return &this->support_material_enforce_layers;
@ -1214,7 +1227,6 @@ class PrintConfig : public virtual StaticPrintConfig
ConfigOptionFloat perimeter_acceleration;
ConfigOptionStrings post_process;
ConfigOptionPoint print_center;
ConfigOptionBool randomize_start;
ConfigOptionFloat resolution;
ConfigOptionFloats retract_before_travel;
ConfigOptionBools retract_layer_change;
@ -1231,8 +1243,6 @@ class PrintConfig : public virtual StaticPrintConfig
ConfigOptionBool spiral_vase;
ConfigOptionInt standby_temperature_delta;
ConfigOptionString start_gcode;
ConfigOptionBool start_perimeters_at_concave_points;
ConfigOptionBool start_perimeters_at_non_overhang;
ConfigOptionInts temperature;
ConfigOptionInt threads;
ConfigOptionString toolchange_gcode;
@ -1296,7 +1306,6 @@ class PrintConfig : public virtual StaticPrintConfig
this->output_filename_format.value = "[input_filename_base].gcode";
this->perimeter_acceleration.value = 0;
this->print_center.point = Pointf(100,100);
this->randomize_start.value = false;
this->resolution.value = 0;
this->retract_before_travel.values.resize(1);
this->retract_before_travel.values[0] = 2;
@ -1321,8 +1330,6 @@ class PrintConfig : public virtual StaticPrintConfig
this->spiral_vase.value = false;
this->standby_temperature_delta.value = -5;
this->start_gcode.value = "G28 ; home all axes\nG1 Z5 F5000 ; lift nozzle\n";
this->start_perimeters_at_concave_points.value = false;
this->start_perimeters_at_non_overhang.value = false;
this->temperature.values.resize(1);
this->temperature.values[0] = 200;
this->threads.value = 2;
@ -1383,7 +1390,6 @@ class PrintConfig : public virtual StaticPrintConfig
if (opt_key == "perimeter_acceleration") return &this->perimeter_acceleration;
if (opt_key == "post_process") return &this->post_process;
if (opt_key == "print_center") return &this->print_center;
if (opt_key == "randomize_start") return &this->randomize_start;
if (opt_key == "resolution") return &this->resolution;
if (opt_key == "retract_before_travel") return &this->retract_before_travel;
if (opt_key == "retract_layer_change") return &this->retract_layer_change;
@ -1400,8 +1406,6 @@ class PrintConfig : public virtual StaticPrintConfig
if (opt_key == "spiral_vase") return &this->spiral_vase;
if (opt_key == "standby_temperature_delta") return &this->standby_temperature_delta;
if (opt_key == "start_gcode") return &this->start_gcode;
if (opt_key == "start_perimeters_at_concave_points") return &this->start_perimeters_at_concave_points;
if (opt_key == "start_perimeters_at_non_overhang") return &this->start_perimeters_at_non_overhang;
if (opt_key == "temperature") return &this->temperature;
if (opt_key == "threads") return &this->threads;
if (opt_key == "toolchange_gcode") return &this->toolchange_gcode;

View file

@ -5,7 +5,7 @@ use warnings;
use List::Util qw(first);
use Slic3r::XS;
use Test::More tests => 19;
use Test::More tests => 20;
use constant PI => 4 * atan2(1, 1);
@ -69,6 +69,10 @@ ok $cw_polygon->contains_point(Slic3r::Point->new(150,150)), 'cw contains_point'
ok !(defined first { $_->is_clockwise } @$triangles), 'all triangles are ccw';
}
{
is_deeply $polygon->centroid->pp, [150,150], 'centroid';
}
# this is not a test: this just demonstrates bad usage, where $polygon->clone gets
# DESTROY'ed before the derived object ($point), causing bad memory access
if (0) {

View file

@ -64,7 +64,7 @@ _constant()
ALIAS:
EXTRL_ROLE_DEFAULT = elrDefault
EXTRL_ROLE_EXTERNAL_PERIMETER = elrExternalPerimeter
EXTRL_ROLE_CONTOUR_INTERNAL_PERIMETER = erInternalInfill
EXTRL_ROLE_CONTOUR_INTERNAL_PERIMETER = elrContourInternalPerimeter
PROTOTYPE:
CODE:
RETVAL = ix;

View file

@ -38,6 +38,12 @@
Polygons simplify(double tolerance);
Polygons triangulate_convex()
%code{% THIS->triangulate_convex(&RETVAL); %};
Clone<Point> centroid();
BoundingBox* bounding_box()
%code{%
RETVAL = new BoundingBox();
THIS->bounding_box(RETVAL);
%};
%{
Polygon*