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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 162 additions and 2 deletions

View file

@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="24"
height="24"
viewBox="0 0 6.3499998 6.3499998"
version="1.1"
id="svg8"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
sodipodi:docname="param_quartercubic.svg">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="31.678384"
inkscape:cx="9.2016388"
inkscape:cy="13.550773"
inkscape:document-units="mm"
inkscape:current-layer="g3735"
showgrid="false"
inkscape:window-width="3440"
inkscape:window-height="1361"
inkscape:window-x="-9"
inkscape:window-y="-9"
inkscape:window-maximized="1"
units="px" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(471.60224,-51.657005)">
<g
id="g3735"
transform="matrix(0.26458333,0,0,0.26458333,-471.86548,51.920238)">
<path
style="fill:#949494;fill-opacity:1;stroke:#949494;stroke-width:0.65595609;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 2.6869721,2.7931307 21.370006,21.252951"
id="path4983"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
id="path3713"
d="M 17.436421,21.426712 2.6364216,6.6267129 m 4.8,14.7999991 -4.8,-4.8 M 16.436421,0.4267129 l 7.2,7.2 m -17.1999994,-7.2 17.1999994,17.1999991"
inkscape:connector-curvature="0"
style="fill:none;stroke:#009688;stroke-width:0.7937008;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none" />
<path
id="path3715"
d="M 14.752492,21.394569 2.6364216,9.2776059 M 23.48285,19.879391 4.1739216,0.66957 m 9.6232134,-0.086607 3.037826,2.9618941 6.823781,6.6997119"
inkscape:connector-curvature="0"
style="fill:none;stroke:#009688;stroke-width:0.7937008;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none"
sodipodi:nodetypes="ccccccc" />
<path
style="fill:#949494;fill-opacity:1;stroke:#949494;stroke-width:0.65595609;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 9.7429205,0.43681 23.684533,13.798665"
id="path4983-8"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
id="path3715-1"
d="M 2.6374683,7.77313 9.7429205,0.43681 M 2.8040351,18.864878 20.992951,0.52555773 M 23.629234,9.7763932 12.204235,21.423716"
inkscape:connector-curvature="0"
style="fill:none;stroke:#009688;stroke-width:0.7937008;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none"
sodipodi:nodetypes="cccccc" />
<path
id="path3713-0"
d="M 2.6042413,10.559661 12.242993,0.67821811 M 23.658129,12.52874 15.20813,21.405022 M 23.332474,1.1732923 3.4398186,20.95627"
inkscape:connector-curvature="0"
style="fill:none;stroke:#009688;stroke-width:0.7937008;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none"
sodipodi:nodetypes="cccccc" />
<path
id="path3721"
d="M 4.6364216,0.4267129 H 21.636421 c 1.1,0 2,0.9 2,2 V 19.426712 c 0,1.1 -0.9,2 -2,2 H 4.6364216 c -1.1,0 -2,-0.9 -2,-2 V 2.4267129 c 0,-1.1 0.9,-2 2,-2 z"
inkscape:connector-curvature="0"
style="fill:none;stroke:#949494;stroke-width:0.89461362;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none" />
<path
style="fill:#949494;fill-opacity:1;stroke:#949494;stroke-width:0.65595609;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 2.5685844,13.016265 8.7276766,8.61607"
id="path4983-2"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.8 KiB

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,
};