Port Quartercubic infill pattern (#7243)

* Ported Quarter Cubic infill pattern from Cura

* Code reformat
This commit is contained in:
Patrick Carnahan
2025-01-22 01:22:22 -05:00
committed by GitHub
parent 880081226a
commit 302b40af22
6 changed files with 162 additions and 2 deletions

View File

@@ -50,6 +50,7 @@ Fill* Fill::new_from_type(const InfillPattern type)
case ipTriangles: return new FillTriangles();
case ipStars: return new FillStars();
case ipCubic: return new FillCubic();
case ipQuarterCubic: return new FillQuarterCubic();
case ipArchimedeanChords: return new FillArchimedeanChords();
case ipHilbertCurve: return new FillHilbertCurve();
case ipOctagramSpiral: return new FillOctagramSpiral();

View File

@@ -9,6 +9,7 @@
#include <boost/container/small_vector.hpp>
#include <boost/log/trivial.hpp>
#include <boost/static_assert.hpp>
#include <boost/math/constants/constants.hpp>
#include "../ClipperUtils.hpp"
#include "../ExPolygon.hpp"
@@ -3035,6 +3036,39 @@ Polylines FillCubic::fill_surface(const Surface *surface, const FillParams &para
return polylines_out;
}
Polylines FillQuarterCubic::fill_surface(const Surface* surface, const FillParams& params)
{
using namespace boost::math::float_constants;
Polylines polylines_out;
coord_t line_width = coord_t(scale_(this->spacing));
coord_t period = coord_t(scale_(this->spacing) / params.density) * 4;
// First half tetrahedral fill
double pattern_z_shift = 0.0;
coord_t shift = coord_t(one_div_root_two * (scale_(z) + pattern_z_shift * period * 2)) % period;
shift = std::min(shift, period - shift); // symmetry due to the fact that we are applying the shift in both directions
shift = std::min(shift, period / 2 - line_width / 2); // don't put lines too close to each other
shift = std::max(shift, line_width / 2); // don't put lines too close to each other
float dx1 = unscale_(shift);
// Second half tetrahedral fill
pattern_z_shift = 0.5;
shift = coord_t(one_div_root_two * (scale_(z) + pattern_z_shift * period * 2)) % period;
shift = std::min(shift, period - shift); // symmetry due to the fact that we are applying the shift in both directions
shift = std::min(shift, period / 2 - line_width / 2); // don't put lines too close to each other
shift = std::max(shift, line_width / 2); // don't put lines too close to each other
float dx2 = unscale_(shift);
if (!this->fill_surface_by_multilines(
surface, params,
{{0.f, dx1}, {0.f, -dx1}, {float(M_PI / 2.), dx2}, {float(M_PI / 2.), -dx2}},
polylines_out))
BOOST_LOG_TRIVIAL(error) << "FillQuarterCubic::fill_surface() failed to fill a region.";
return polylines_out;
}
Polylines FillSupportBase::fill_surface(const Surface *surface, const FillParams &params)
{
assert(! params.full_infill());

View File

@@ -107,6 +107,20 @@ protected:
float _layer_angle(size_t idx) const override { return 0.f; }
};
// Added QuarterCubic pattern from Cura
class FillQuarterCubic : public FillRectilinear
{
public:
Fill* clone() const override { return new FillQuarterCubic(*this); }
~FillQuarterCubic() override = default;
Polylines fill_surface(const Surface *surface, const FillParams &params) override;
protected:
// The grid fill will keep the angle constant between the layers, see the implementation of Slic3r::Fill.
float _layer_angle(size_t idx) const override { return 0.f; }
};
class FillSupportBase : public FillRectilinear
{
public:

View File

@@ -143,7 +143,8 @@ static t_config_enum_values s_keys_map_InfillPattern {
{ "octagramspiral", ipOctagramSpiral },
{ "supportcubic", ipSupportCubic },
{ "lightning", ipLightning },
{ "crosshatch", ipCrossHatch}
{ "crosshatch", ipCrossHatch},
{ "quartercubic", ipQuarterCubic}
};
CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(InfillPattern)
@@ -2272,6 +2273,7 @@ void PrintConfigDef::init_fff_params()
def->enum_values.push_back("supportcubic");
def->enum_values.push_back("lightning");
def->enum_values.push_back("crosshatch");
def->enum_values.push_back("quartercubic");
def->enum_labels.push_back(L("Concentric"));
def->enum_labels.push_back(L("Rectilinear"));
def->enum_labels.push_back(L("Grid"));
@@ -2290,6 +2292,7 @@ void PrintConfigDef::init_fff_params()
def->enum_labels.push_back(L("Support Cubic"));
def->enum_labels.push_back(L("Lightning"));
def->enum_labels.push_back(L("Cross Hatch"));
def->enum_labels.push_back(L("Quarter Cubic"));
def->set_default_value(new ConfigOptionEnum<InfillPattern>(ipCrossHatch));
auto def_infill_anchor_min = def = this->add("infill_anchor", coFloatOrPercent);

View File

@@ -52,7 +52,7 @@ enum AuthorizationType {
enum InfillPattern : int {
ipConcentric, ipRectilinear, ipGrid, ipLine, ipCubic, ipTriangles, ipStars, ipGyroid, ipHoneycomb, ipAdaptiveCubic, ipMonotonic, ipMonotonicLine, ipAlignedRectilinear, ip3DHoneycomb,
ipHilbertCurve, ipArchimedeanChords, ipOctagramSpiral, ipSupportCubic, ipSupportBase, ipConcentricInternal,
ipLightning, ipCrossHatch,
ipLightning, ipCrossHatch, ipQuarterCubic,
ipCount,
};