fix centroid error for two points and merge with dev.

This commit is contained in:
tamasmeszaros 2018-08-27 16:20:13 +02:00
commit 1c4574d42e
39 changed files with 849 additions and 132 deletions

View file

@ -793,11 +793,16 @@ void WipeTowerPrusaMM::toolchange_Unload(
float turning_point = (!m_left_to_right ? xl : xr );
float total_retraction_distance = m_cooling_tube_retraction + m_cooling_tube_length/2.f - 15.f; // the 15mm is reserved for the first part after ramming
writer.suppress_preview()
.load_move_x_advanced(turning_point, -15.f, 83.f, 50.f) // this is done at fixed speed
.retract(15.f, m_filpar[m_current_tool].unloading_speed_start * 60.f) // feedrate 5000mm/min = 83mm/s
.retract(0.70f * total_retraction_distance, 1.0f * m_filpar[m_current_tool].unloading_speed * 60.f)
.retract(0.20f * total_retraction_distance, 0.5f * m_filpar[m_current_tool].unloading_speed * 60.f)
.retract(0.10f * total_retraction_distance, 0.3f * m_filpar[m_current_tool].unloading_speed * 60.f)
/*.load_move_x_advanced(turning_point, -15.f, 83.f, 50.f) // this is done at fixed speed
.load_move_x_advanced(old_x, -0.70f * total_retraction_distance, 1.0f * m_filpar[m_current_tool].unloading_speed)
.load_move_x_advanced(turning_point, -0.20f * total_retraction_distance, 0.5f * m_filpar[m_current_tool].unloading_speed)
.load_move_x_advanced(old_x, -0.10f * total_retraction_distance, 0.3f * m_filpar[m_current_tool].unloading_speed)
.travel(old_x, writer.y()) // in case previous move was shortened to limit feedrate
.travel(old_x, writer.y()) // in case previous move was shortened to limit feedrate*/
.resume_preview();
if (new_temperature != 0 && new_temperature != m_old_temperature ) { // Set the extruder temperature, but don't wait.
@ -874,10 +879,15 @@ void WipeTowerPrusaMM::toolchange_Load(
writer.append("; CP TOOLCHANGE LOAD\n")
.suppress_preview()
.load_move_x_advanced(turning_point, 0.2f * edist, 0.3f * m_filpar[m_current_tool].loading_speed) // Acceleration
/*.load_move_x_advanced(turning_point, 0.2f * edist, 0.3f * m_filpar[m_current_tool].loading_speed) // Acceleration
.load_move_x_advanced(oldx, 0.5f * edist, m_filpar[m_current_tool].loading_speed) // Fast phase
.load_move_x_advanced(turning_point, 0.2f * edist, 0.3f * m_filpar[m_current_tool].loading_speed) // Slowing down
.load_move_x_advanced(oldx, 0.1f * edist, 0.1f * m_filpar[m_current_tool].loading_speed) // Super slow
.load_move_x_advanced(oldx, 0.1f * edist, 0.1f * m_filpar[m_current_tool].loading_speed) // Super slow*/
.load(0.2f * edist, 60.f * m_filpar[m_current_tool].loading_speed_start)
.load_move_x_advanced(turning_point, 0.7f * edist, m_filpar[m_current_tool].loading_speed) // Fast phase
.load_move_x_advanced(oldx, 0.1f * edist, 0.1f * m_filpar[m_current_tool].loading_speed) // Super slow*/
.travel(oldx, writer.y()) // in case last move was shortened to limit x feedrate
.resume_preview();

View file

@ -65,9 +65,9 @@ public:
// Set the extruder properties.
void set_extruder(size_t idx, material_type material, int temp, int first_layer_temp, float loading_speed,
float unloading_speed, float delay, int cooling_moves, float cooling_initial_speed,
float cooling_final_speed, std::string ramming_parameters, float nozzle_diameter)
void set_extruder(size_t idx, material_type material, int temp, int first_layer_temp, float loading_speed, float loading_speed_start,
float unloading_speed, float unloading_speed_start, float delay, int cooling_moves,
float cooling_initial_speed, float cooling_final_speed, std::string ramming_parameters, float nozzle_diameter)
{
//while (m_filpar.size() < idx+1) // makes sure the required element is in the vector
m_filpar.push_back(FilamentParameters());
@ -76,7 +76,9 @@ public:
m_filpar[idx].temperature = temp;
m_filpar[idx].first_layer_temperature = first_layer_temp;
m_filpar[idx].loading_speed = loading_speed;
m_filpar[idx].loading_speed_start = loading_speed_start;
m_filpar[idx].unloading_speed = unloading_speed;
m_filpar[idx].unloading_speed_start = unloading_speed_start;
m_filpar[idx].delay = delay;
m_filpar[idx].cooling_moves = cooling_moves;
m_filpar[idx].cooling_initial_speed = cooling_initial_speed;
@ -216,7 +218,9 @@ private:
int temperature = 0;
int first_layer_temperature = 0;
float loading_speed = 0.f;
float loading_speed_start = 0.f;
float unloading_speed = 0.f;
float unloading_speed_start = 0.f;
float delay = 0.f ;
int cooling_moves = 0;
float cooling_initial_speed = 0.f;

View file

@ -195,47 +195,110 @@ using namespace boost::polygon; // provides also high() and low()
namespace Slic3r { namespace Geometry {
static bool
sort_points (Point a, Point b)
static bool sort_points(const Point& a, const Point& b)
{
return (a(0) < b(0)) || (a(0) == b(0) && a(1) < b(1));
}
/* This implementation is based on Andrew's monotone chain 2D convex hull algorithm */
static bool sort_pointfs(const Vec3d& a, const Vec3d& b)
{
return (a(0) < b(0)) || (a(0) == b(0) && a(1) < b(1));
}
// This implementation is based on Andrew's monotone chain 2D convex hull algorithm
Polygon
convex_hull(Points points)
{
assert(points.size() >= 3);
// sort input points
std::sort(points.begin(), points.end(), sort_points);
int n = points.size(), k = 0;
Polygon hull;
if (n >= 3) {
hull.points.resize(2*n);
hull.points.resize(2 * n);
// Build lower hull
for (int i = 0; i < n; i++) {
while (k >= 2 && points[i].ccw(hull.points[k-2], hull.points[k-1]) <= 0) k--;
hull.points[k++] = points[i];
while (k >= 2 && points[i].ccw(hull[k-2], hull[k-1]) <= 0) k--;
hull[k++] = points[i];
}
// Build upper hull
for (int i = n-2, t = k+1; i >= 0; i--) {
while (k >= t && points[i].ccw(hull.points[k-2], hull.points[k-1]) <= 0) k--;
hull.points[k++] = points[i];
while (k >= t && points[i].ccw(hull[k-2], hull[k-1]) <= 0) k--;
hull[k++] = points[i];
}
hull.points.resize(k);
assert( hull.points.front() == hull.points.back() );
assert(hull.points.front() == hull.points.back());
hull.points.pop_back();
}
return hull;
}
Pointf3s
convex_hull(Pointf3s points)
{
assert(points.size() >= 3);
// sort input points
std::sort(points.begin(), points.end(), sort_pointfs);
int n = points.size(), k = 0;
Pointf3s hull;
if (n >= 3)
{
hull.resize(2 * n);
// Build lower hull
for (int i = 0; i < n; ++i)
{
Point p = Point::new_scale(points[i](0), points[i](1));
while (k >= 2)
{
Point k1 = Point::new_scale(hull[k - 1](0), hull[k - 1](1));
Point k2 = Point::new_scale(hull[k - 2](0), hull[k - 2](1));
if (p.ccw(k2, k1) <= 0)
--k;
else
break;
}
hull[k++] = points[i];
}
// Build upper hull
for (int i = n - 2, t = k + 1; i >= 0; --i)
{
Point p = Point::new_scale(points[i](0), points[i](1));
while (k >= t)
{
Point k1 = Point::new_scale(hull[k - 1](0), hull[k - 1](1));
Point k2 = Point::new_scale(hull[k - 2](0), hull[k - 2](1));
if (p.ccw(k2, k1) <= 0)
--k;
else
break;
}
hull[k++] = points[i];
}
hull.resize(k);
assert(hull.front() == hull.back());
hull.pop_back();
}
return hull;
}
Polygon
convex_hull(const Polygons &polygons)
{
@ -243,7 +306,7 @@ convex_hull(const Polygons &polygons)
for (Polygons::const_iterator p = polygons.begin(); p != polygons.end(); ++p) {
pp.insert(pp.end(), p->points.begin(), p->points.end());
}
return convex_hull(pp);
return convex_hull(std::move(pp));
}
/* accepts an arrayref of points and returns a list of indices

View file

@ -108,8 +108,10 @@ inline bool segment_segment_intersection(const Vec2d &p1, const Vec2d &v1, const
return true;
}
Pointf3s convex_hull(Pointf3s points);
Polygon convex_hull(Points points);
Polygon convex_hull(const Polygons &polygons);
void chained_path(const Points &points, std::vector<Points::size_type> &retval, Point start_near);
void chained_path(const Points &points, std::vector<Points::size_type> &retval);
template<class T> void chained_path_items(Points &points, T &items, T &retval);

View file

@ -715,7 +715,21 @@ void ModelObject::scale(const Vec3d &versor)
this->invalidate_bounding_box();
}
void ModelObject::rotate(float angle, const Axis &axis)
void ModelObject::rotate(float angle, const Axis& axis)
{
for (ModelVolume *v : this->volumes)
{
v->mesh.rotate(angle, axis);
v->m_convex_hull.rotate(angle, axis);
}
center_around_origin();
this->origin_translation = Vec3d::Zero();
this->invalidate_bounding_box();
}
void ModelObject::rotate(float angle, const Vec3d& axis)
{
for (ModelVolume *v : this->volumes)
{

View file

@ -121,7 +121,8 @@ public:
void translate(coordf_t x, coordf_t y, coordf_t z);
void scale(const Vec3d &versor);
void rotate(float angle, const Axis &axis);
void transform(const float* matrix3x4);
void rotate(float angle, const Vec3d& axis);
void transform(const float* matrix3x4); // <<<<<<<<< FIXME (using eigen)
void mirror(const Axis &axis);
size_t materials_count() const;
size_t facets_count() const;

View file

@ -204,7 +204,9 @@ bool Print::invalidate_state_by_config_options(const std::vector<t_config_option
|| opt_key == "filament_soluble"
|| opt_key == "first_layer_temperature"
|| opt_key == "filament_loading_speed"
|| opt_key == "filament_loading_speed_start"
|| opt_key == "filament_unloading_speed"
|| opt_key == "filament_unloading_speed_start"
|| opt_key == "filament_toolchange_delay"
|| opt_key == "filament_cooling_moves"
|| opt_key == "filament_minimal_purge_on_wipe_tower"
@ -1127,7 +1129,9 @@ void Print::_make_wipe_tower()
this->config.temperature.get_at(i),
this->config.first_layer_temperature.get_at(i),
this->config.filament_loading_speed.get_at(i),
this->config.filament_loading_speed_start.get_at(i),
this->config.filament_unloading_speed.get_at(i),
this->config.filament_unloading_speed_start.get_at(i),
this->config.filament_toolchange_delay.get_at(i),
this->config.filament_cooling_moves.get_at(i),
this->config.filament_cooling_initial_speed.get_at(i),

View file

@ -511,6 +511,14 @@ void PrintConfigDef::init_fff_params()
def->min = 0;
def->default_value = new ConfigOptionFloats { 28. };
def = this->add("filament_loading_speed_start", coFloats);
def->label = L("Loading speed at the start");
def->tooltip = L("Speed used at the very beginning of loading phase. ");
def->sidetext = L("mm/s");
def->cli = "filament-loading-speed-start=f@";
def->min = 0;
def->default_value = new ConfigOptionFloats { 3. };
def = this->add("filament_unloading_speed", coFloats);
def->label = L("Unloading speed");
def->tooltip = L("Speed used for unloading the filament on the wipe tower (does not affect "
@ -520,6 +528,14 @@ void PrintConfigDef::init_fff_params()
def->min = 0;
def->default_value = new ConfigOptionFloats { 90. };
def = this->add("filament_unloading_speed_start", coFloats);
def->label = L("Unloading speed at the start");
def->tooltip = L("Speed used for unloading the tip of the filament immediately after ramming. ");
def->sidetext = L("mm/s");
def->cli = "filament-unloading-speed-start=f@";
def->min = 0;
def->default_value = new ConfigOptionFloats { 100. };
def = this->add("filament_toolchange_delay", coFloats);
def->label = L("Delay after unloading");
def->tooltip = L("Time to wait after the filament is unloaded. "
@ -2064,7 +2080,7 @@ void PrintConfigDef::init_fff_params()
def = this->add("wipe_into_infill", coBool);
def->category = L("Extruders");
def->label = L("Purge into this object's infill");
def->label = L("Wipe into this object's infill");
def->tooltip = L("Purging after toolchange will done inside this object's infills. "
"This lowers the amount of waste but may result in longer print time "
" due to additional travel moves.");
@ -2073,7 +2089,7 @@ void PrintConfigDef::init_fff_params()
def = this->add("wipe_into_objects", coBool);
def->category = L("Extruders");
def->label = L("Purge into this object");
def->label = L("Wipe into this object");
def->tooltip = L("Object will be used to purge the nozzle after a toolchange to save material "
"that would otherwise end up in the wipe tower and decrease print time. "
"Colours of the objects will be mixed as a result.");

View file

@ -563,8 +563,10 @@ public:
ConfigOptionFloats filament_cost;
ConfigOptionFloats filament_max_volumetric_speed;
ConfigOptionFloats filament_loading_speed;
ConfigOptionFloats filament_loading_speed_start;
ConfigOptionFloats filament_load_time;
ConfigOptionFloats filament_unloading_speed;
ConfigOptionFloats filament_unloading_speed_start;
ConfigOptionFloats filament_toolchange_delay;
ConfigOptionFloats filament_unload_time;
ConfigOptionInts filament_cooling_moves;
@ -629,8 +631,10 @@ protected:
OPT_PTR(filament_cost);
OPT_PTR(filament_max_volumetric_speed);
OPT_PTR(filament_loading_speed);
OPT_PTR(filament_loading_speed_start);
OPT_PTR(filament_load_time);
OPT_PTR(filament_unloading_speed);
OPT_PTR(filament_unloading_speed_start);
OPT_PTR(filament_unload_time);
OPT_PTR(filament_toolchange_delay);
OPT_PTR(filament_cooling_moves);

View file

@ -357,10 +357,20 @@ inline ExPolygons unify(const ExPolygons& shapes) {
}
inline Point centroid(Points& pp) {
Polygon p;
p.points.swap(pp);
Point c = p.centroid();
pp.swap(p.points);
Point c;
switch(pp.size()) {
case 0: break;
case 1: c = pp.front(); break;
case 2: c = (pp[0] + pp[1]) / 2; break;
default: {
Polygon p;
p.points.swap(pp);
c = p.centroid();
pp.swap(p.points);
break;
}
}
return c;
}

View file

@ -13,6 +13,7 @@
#include <utility>
#include <algorithm>
#include <math.h>
#include <type_traits>
#include <boost/log/trivial.hpp>
@ -255,6 +256,17 @@ void TriangleMesh::rotate(float angle, const Axis &axis)
stl_invalidate_shared_vertices(&this->stl);
}
void TriangleMesh::rotate(float angle, const Vec3d& axis)
{
if (angle == 0.f)
return;
Vec3f axis_norm = axis.cast<float>().normalized();
Transform3f m = Transform3f::Identity();
m.rotate(Eigen::AngleAxisf(angle, axis_norm));
stl_transform(&stl, (float*)m.data());
}
void TriangleMesh::mirror(const Axis &axis)
{
if (axis == X) {
@ -459,6 +471,11 @@ ExPolygons TriangleMesh::horizontal_projection() const
return union_ex(offset(pp, scale_(0.01)), true);
}
const float* TriangleMesh::first_vertex() const
{
return this->stl.facet_start ? &this->stl.facet_start->vertex[0](0) : nullptr;
}
Polygon TriangleMesh::convex_hull()
{
this->require_shared_vertices();
@ -597,6 +614,7 @@ TriangleMesh TriangleMesh::convex_hull_3d() const
TriangleMesh output_mesh(dst_vertices, facets);
output_mesh.repair();
output_mesh.require_shared_vertices();
return output_mesh;
}

View file

@ -40,6 +40,7 @@ public:
void scale(const Vec3d &versor);
void translate(float x, float y, float z);
void rotate(float angle, const Axis &axis);
void rotate(float angle, const Vec3d& axis);
void rotate_x(float angle) { this->rotate(angle, X); }
void rotate_y(float angle) { this->rotate(angle, Y); }
void rotate_z(float angle) { this->rotate(angle, Z); }
@ -53,6 +54,7 @@ public:
TriangleMeshPtrs split() const;
void merge(const TriangleMesh &mesh);
ExPolygons horizontal_projection() const;
const float* first_vertex() const;
Polygon convex_hull();
BoundingBoxf3 bounding_box() const;
// Returns the bbox of this TriangleMesh transformed by the given transformation

View file

@ -14,7 +14,7 @@
#include <boost/thread.hpp>
#define SLIC3R_FORK_NAME "Slic3r Prusa Edition"
#define SLIC3R_VERSION "1.41.0-beta"
#define SLIC3R_VERSION "1.41.0-beta2"
#define SLIC3R_BUILD "UNKNOWN"
typedef int32_t coord_t;