Skip to content

Commit

Permalink
[TASK] Add credits, format code, improve input labels
Browse files Browse the repository at this point in the history
  • Loading branch information
mjonuschat committed Dec 30, 2023
1 parent 3c169cd commit c55fc05
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 28 deletions.
35 changes: 21 additions & 14 deletions src/libslic3r/GCode/SmallAreaInfillFlowCompensator.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
// Modify the flow of extrusion lines inversely proportional to the length of
// the extrusion line. When infill lines get shorter the flow rate will auto-
// matically be reduced to mitigate the effect of small infill areas being
// over-extruded.

// Based on original work by Alexander Þór licensed under the GPLv3:
// https://github.com/Alexander-T-Moss/Small-Area-Flow-Comp

#include <math.h>
#include <cstring>
#include <cfloat>
Expand All @@ -11,94 +19,93 @@ namespace Slic3r {

bool nearly_equal(double a, double b)
{
return std::nextafter(a, std::numeric_limits<double>::lowest()) <= b
&& std::nextafter(a, std::numeric_limits<double>::max()) >= b;
return std::nextafter(a, std::numeric_limits<double>::lowest()) <= b && std::nextafter(a, std::numeric_limits<double>::max()) >= b;
}

SmallAreaInfillFlowCompensator::SmallAreaInfillFlowCompensator(const Slic3r::GCodeConfig &config)
SmallAreaInfillFlowCompensator::SmallAreaInfillFlowCompensator(const Slic3r::GCodeConfig& config)
{
auto curLength = 0.0;

if(nearly_equal(config.small_area_infill_flow_compensation_extrusion_length_0, 0.0)) {
if (nearly_equal(config.small_area_infill_flow_compensation_extrusion_length_0, 0.0)) {
eLengths.push_back(config.small_area_infill_flow_compensation_extrusion_length_0);
flowComps.push_back(config.small_area_infill_flow_compensation_compensation_factor_0);
} else {
throw Slic3r::InvalidArgument("First extrusion length for small area infill compensation length must be 0");
}

curLength = config.small_area_infill_flow_compensation_extrusion_length_1;
if(curLength > 0.0 && curLength > eLengths.back()) {
if (curLength > 0.0 && curLength > eLengths.back()) {
eLengths.push_back(config.small_area_infill_flow_compensation_extrusion_length_1);
flowComps.push_back(config.small_area_infill_flow_compensation_compensation_factor_1);
} else {
throw Slic3r::InvalidArgument("Extrusion lengths for subsequent points must be increasing");
}

curLength = config.small_area_infill_flow_compensation_extrusion_length_2;
if(curLength > 0.0 && curLength > eLengths.back()) {
if (curLength > 0.0 && curLength > eLengths.back()) {
eLengths.push_back(config.small_area_infill_flow_compensation_extrusion_length_2);
flowComps.push_back(config.small_area_infill_flow_compensation_compensation_factor_2);
} else {
throw Slic3r::InvalidArgument("Extrusion lengths for subsequent points must be increasing");
}

curLength = config.small_area_infill_flow_compensation_extrusion_length_3;
if(curLength > 0.0 && curLength > eLengths.back()) {
if (curLength > 0.0 && curLength > eLengths.back()) {
eLengths.push_back(config.small_area_infill_flow_compensation_extrusion_length_3);
flowComps.push_back(config.small_area_infill_flow_compensation_compensation_factor_3);
} else {
throw Slic3r::InvalidArgument("Extrusion lengths for subsequent points must be increasing");
}

curLength = config.small_area_infill_flow_compensation_extrusion_length_4;
if(curLength > 0.0 && curLength > eLengths.back()) {
if (curLength > 0.0 && curLength > eLengths.back()) {
eLengths.push_back(config.small_area_infill_flow_compensation_extrusion_length_4);
flowComps.push_back(config.small_area_infill_flow_compensation_compensation_factor_4);
} else {
throw Slic3r::InvalidArgument("Extrusion lengths for subsequent points must be increasing");
}

curLength = config.small_area_infill_flow_compensation_extrusion_length_5;
if(curLength > 0.0 && curLength > eLengths.back()) {
if (curLength > 0.0 && curLength > eLengths.back()) {
eLengths.push_back(config.small_area_infill_flow_compensation_extrusion_length_5);
flowComps.push_back(config.small_area_infill_flow_compensation_compensation_factor_5);
} else {
throw Slic3r::InvalidArgument("Extrusion lengths for subsequent points must be increasing");
}

curLength = config.small_area_infill_flow_compensation_extrusion_length_6;
if(curLength > 0.0 && curLength > eLengths.back()) {
if (curLength > 0.0 && curLength > eLengths.back()) {
eLengths.push_back(config.small_area_infill_flow_compensation_extrusion_length_6);
flowComps.push_back(config.small_area_infill_flow_compensation_compensation_factor_6);
} else {
throw Slic3r::InvalidArgument("Extrusion lengths for subsequent points must be increasing");
}

curLength = config.small_area_infill_flow_compensation_extrusion_length_7;
if(curLength > 0.0 && curLength > eLengths.back()) {
if (curLength > 0.0 && curLength > eLengths.back()) {
eLengths.push_back(config.small_area_infill_flow_compensation_extrusion_length_7);
flowComps.push_back(config.small_area_infill_flow_compensation_compensation_factor_7);
} else {
throw Slic3r::InvalidArgument("Extrusion lengths for subsequent points must be increasing");
}

curLength = config.small_area_infill_flow_compensation_extrusion_length_8;
if(curLength > 0.0 && curLength > eLengths.back()) {
if (curLength > 0.0 && curLength > eLengths.back()) {
eLengths.push_back(config.small_area_infill_flow_compensation_extrusion_length_8);
flowComps.push_back(config.small_area_infill_flow_compensation_compensation_factor_8);
} else {
throw Slic3r::InvalidArgument("Extrusion lengths for subsequent points must be increasing");
}

curLength = config.small_area_infill_flow_compensation_extrusion_length_9;
if(curLength > 0.0 && curLength > eLengths.back()) {
if (curLength > 0.0 && curLength > eLengths.back()) {
eLengths.push_back(config.small_area_infill_flow_compensation_extrusion_length_9);
flowComps.push_back(config.small_area_infill_flow_compensation_compensation_factor_9);
} else {
throw Slic3r::InvalidArgument("Extrusion lengths for subsequent points must be increasing");
}

if(!nearly_equal(flowComps.back(), 1.0)) {
if (!nearly_equal(flowComps.back(), 1.0)) {
throw Slic3r::InvalidArgument("Final compensation factor for small area infill flow compensation must be 1.0");
}

Expand Down
6 changes: 2 additions & 4 deletions src/libslic3r/GCode/SmallAreaInfillFlowCompensator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SmallAreaInfillFlowCompensator
{
public:
SmallAreaInfillFlowCompensator() = delete;
explicit SmallAreaInfillFlowCompensator(const Slic3r::GCodeConfig &config);
explicit SmallAreaInfillFlowCompensator(const Slic3r::GCodeConfig& config);
~SmallAreaInfillFlowCompensator() = default;

double modify_flow(const double line_length, const double dE, const ExtrusionRole role);
Expand All @@ -27,9 +27,7 @@ class SmallAreaInfillFlowCompensator

double flow_comp_model(const double line_length);

double max_modified_length() {
return eLengths.back();
}
double max_modified_length() { return eLengths.back(); }
};

} // namespace Slic3r
Expand Down
20 changes: 10 additions & 10 deletions src/libslic3r/PrintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2687,79 +2687,79 @@ def = this->add("filament_loading_speed", coFloats);
def->set_default_value(new ConfigOptionFloat(10));

def = this->add("small_area_infill_flow_compensation_compensation_factor_0", coFloat);
def->label = L("1: Data point");
def->label = L("1: Flow Compensation");
def->tooltip = L("Spline data point that defines the compensation curve");
def->min = 0;
def->max = 1;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(0));

def = this->add("small_area_infill_flow_compensation_compensation_factor_1", coFloat);
def->label = L("2: Data point");
def->label = L("2: Flow Compensation");
def->tooltip = L("Spline data point that defines the compensation curve");
def->min = 0;
def->max = 1;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(0.4444));

def = this->add("small_area_infill_flow_compensation_compensation_factor_2", coFloat);
def->label = L("3: Data point");
def->label = L("3: Flow Compensation");
def->tooltip = L("Spline data point that defines the compensation curve");
def->min = 0;
def->max = 1;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(0.6145));

def = this->add("small_area_infill_flow_compensation_compensation_factor_3", coFloat);
def->label = L("4: Data point");
def->label = L("4: Flow Compensation");
def->tooltip = L("Spline data point that defines the compensation curve");
def->min = 0;
def->max = 1;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(0.7059));

def = this->add("small_area_infill_flow_compensation_compensation_factor_4", coFloat);
def->label = L("5: Data point");
def->label = L("5: Flow Compensation");
def->tooltip = L("Spline data point that defines the compensation curve");
def->min = 0;
def->max = 1;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(0.7619));

def = this->add("small_area_infill_flow_compensation_compensation_factor_5", coFloat);
def->label = L("6: Data point");
def->label = L("6: Flow Compensation");
def->tooltip = L("Spline data point that defines the compensation curve");
def->min = 0;
def->max = 1;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(0.8571));

def = this->add("small_area_infill_flow_compensation_compensation_factor_6", coFloat);
def->label = L("7: Data point");
def->label = L("7: Flow Compensation");
def->tooltip = L("Spline data point that defines the compensation curve");
def->min = 0;
def->max = 1;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(0.8889));

def = this->add("small_area_infill_flow_compensation_compensation_factor_7", coFloat);
def->label = L("8: Data point");
def->label = L("8: Flow Compensation");
def->tooltip = L("Spline data point that defines the compensation curve");
def->min = 0;
def->max = 1;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(0.9231));

def = this->add("small_area_infill_flow_compensation_compensation_factor_8", coFloat);
def->label = L("9: Data point");
def->label = L("9: Flow Compensation");
def->tooltip = L("Spline data point that defines the compensation curve");
def->min = 0;
def->max = 1;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(0.9520));

def = this->add("small_area_infill_flow_compensation_compensation_factor_9", coFloat);
def->label = L("10: Data point");
def->label = L("10: Flow Compensation");
def->tooltip = L("Spline data point that defines the compensation curve");
def->min = 0;
def->max = 1;
Expand Down

0 comments on commit c55fc05

Please sign in to comment.