Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::arrangement Namespace Reference

Classes

struct  ArrangeParams
 
struct  ArrangePolygon
 Input/Output structure for the arrange() function. The poly field will not be modified during arrangement. Instead, the translation and rotation fields will mark the needed transformation for the polygon to be in the arranged position. These can also be set to an initial offset and rotation. More...
 
class  AutoArranger
 
class  CircleBed
 A geometry abstraction for a circular print bed. Similarly to BoundingBox. More...
 
struct  InfiniteBed
 Representing an unbounded bed. More...
 
struct  IrregularBed
 
struct  RectangleBed
 
struct  SegmentedRectangleBed
 

Typedefs

using Item = _Item< ExPolygon >
 
using Box = _Box< Point >
 
using Circle = _Circle< Point >
 
using Segment = _Segment< Point >
 
using MultiPolygon = ExPolygons
 
using SpatElement = std::pair< Box, unsigned >
 
using SpatIndex = bgi::rtree< SpatElement, bgi::rstar< 16, 4 > >
 
using ItemGroup = std::vector< std::reference_wrapper< Item > >
 
using ArrangeBed = boost::variant< InfiniteBed, RectangleBed, CircleBed, SegmentedRectangleBed, IrregularBed >
 
using ArrangePolygons = std::vector< ArrangePolygon >
 

Enumerations

enum class  Pivots {
  Center , TopLeft , BottomLeft , BottomRight ,
  TopRight
}
 

Functions

template<class PConf >
void fill_config (PConf &pcfg, const ArrangeParams &params)
 
static double fixed_overfit (const std::tuple< double, Box > &result, const Box &binbb)
 
template<class Bin >
void remove_large_items (std::vector< Item > &items, Bin &&bin)
 
template<class S >
Radians min_area_boundingbox_rotation (const S &sh)
 
template<class S >
Radians fit_into_box_rotation (const S &sh, const _Box< TPoint< S > > &box)
 
template<class BinT >
void _arrange (std::vector< Item > &shapes, std::vector< Item > &excludes, const BinT &bin, const ArrangeParams &params, std::function< void(unsigned)> progressfn, std::function< bool()> stopfn)
 
Box to_nestbin (const BoundingBox &bb)
 
Circle to_nestbin (const CircleBed &c)
 
ExPolygon to_nestbin (const Polygon &p)
 
Box to_nestbin (const InfiniteBed &bed)
 
coord_t width (const BoundingBox &box)
 
coord_t height (const BoundingBox &box)
 
double area (const BoundingBox &box)
 
double poly_area (const Points &pts)
 
double distance_to (const Point &p1, const Point &p2)
 
static CircleBed to_circle (const Point &center, const Points &points)
 
static void process_arrangeable (const ArrangePolygon &arrpoly, std::vector< Item > &outp)
 
template<class Fn >
auto call_with_bed (const Points &bed, Fn &&fn)
 
bool is_box (const Points &bed)
 
template<>
void arrange (ArrangePolygons &items, const ArrangePolygons &excludes, const Points &bed, const ArrangeParams &params)
 
template<class BedT >
void arrange (ArrangePolygons &arrangables, const ArrangePolygons &excludes, const BedT &bed, const ArrangeParams &params)
 
template void arrange (ArrangePolygons &items, const ArrangePolygons &excludes, const BoundingBox &bed, const ArrangeParams &params)
 
template void arrange (ArrangePolygons &items, const ArrangePolygons &excludes, const CircleBed &bed, const ArrangeParams &params)
 
template void arrange (ArrangePolygons &items, const ArrangePolygons &excludes, const Polygon &bed, const ArrangeParams &params)
 
template void arrange (ArrangePolygons &items, const ArrangePolygons &excludes, const InfiniteBed &bed, const ArrangeParams &params)
 
ArrangeBed to_arrange_bed (const Points &bedpts)
 
void arrange (ArrangePolygons &items, const ArrangePolygons &excludes, const SegmentedRectangleBed &bed, const ArrangeParams &params)
 
BoundingBox bounding_box (const InfiniteBed &bed)
 
BoundingBox bounding_box (const RectangleBed &b)
 
BoundingBox bounding_box (const SegmentedRectangleBed &b)
 
BoundingBox bounding_box (const CircleBed &b)
 
BoundingBox bounding_box (const ArrangeBed &b)
 
template<class TBed >
void arrange (ArrangePolygons &items, const ArrangePolygons &excludes, const TBed &bed, const ArrangeParams &params={})
 Arranges the input polygons.
 
template<>
void arrange (ArrangePolygons &items, const ArrangePolygons &excludes, const Points &bed, const ArrangeParams &params)
 
void arrange (ArrangePolygons &items, const ArrangePolygons &excludes, const RectangleBed &bed, const ArrangeParams &params)
 
void arrange (ArrangePolygons &items, const ArrangePolygons &excludes, const IrregularBed &bed, const ArrangeParams &params)
 
void arrange (ArrangePolygons &items, const ArrangePolygons &excludes, const ArrangeBed &bed, const ArrangeParams &params)
 
void arrange (ArrangePolygons &items, const Points &bed, const ArrangeParams &params={})
 
void arrange (ArrangePolygons &items, const BoundingBox &bed, const ArrangeParams &params={})
 
void arrange (ArrangePolygons &items, const CircleBed &bed, const ArrangeParams &params={})
 
void arrange (ArrangePolygons &items, const Polygon &bed, const ArrangeParams &params={})
 
void arrange (ArrangePolygons &items, const InfiniteBed &bed, const ArrangeParams &params={})
 

Variables

const double BIG_ITEM_TRESHOLD = 0.02
 
static const constexpr int UNARRANGED = -1
 A logical bed representing an object not being arranged. Either the arrange has not yet successfully run on this ArrangePolygon or it could not fit the object due to overly large size or invalid geometry.
 

Class Documentation

◆ Slic3r::arrangement::IrregularBed

struct Slic3r::arrangement::IrregularBed
+ Collaboration diagram for Slic3r::arrangement::IrregularBed:
Class Members
ExPolygon poly

◆ Slic3r::arrangement::RectangleBed

struct Slic3r::arrangement::RectangleBed
+ Collaboration diagram for Slic3r::arrangement::RectangleBed:
Class Members
BoundingBox bb

Typedef Documentation

◆ ArrangeBed

◆ ArrangePolygons

◆ Box

◆ Circle

◆ Item

◆ ItemGroup

using Slic3r::arrangement::ItemGroup = typedef std::vector<std::reference_wrapper<Item> >

◆ MultiPolygon

◆ Segment

◆ SpatElement

using Slic3r::arrangement::SpatElement = typedef std::pair<Box, unsigned>

◆ SpatIndex

using Slic3r::arrangement::SpatIndex = typedef bgi::rtree< SpatElement, bgi::rstar<16, 4> >

Enumeration Type Documentation

◆ Pivots

enum class Slic3r::arrangement::Pivots
strong
Enumerator
Center 
TopLeft 
BottomLeft 
BottomRight 
TopRight 
126 {
127 Center, TopLeft, BottomLeft, BottomRight, TopRight
128};

Function Documentation

◆ _arrange()

template<class BinT >
void Slic3r::arrangement::_arrange ( std::vector< Item > &  shapes,
std::vector< Item > &  excludes,
const BinT &  bin,
const ArrangeParams params,
std::function< void(unsigned)>  progressfn,
std::function< bool()>  stopfn 
)
482{
483 // Integer ceiling the min distance from the bed perimeters
484 coord_t md = params.min_obj_distance;
485 md = md / 2 - params.min_bed_distance;
486
487 auto corrected_bin = bin;
488 sl::offset(corrected_bin, md);
489 ArrangeParams mod_params = params;
490 mod_params.min_obj_distance = 0;
491
492 AutoArranger<BinT> arranger{corrected_bin, mod_params, progressfn, stopfn};
493
494 auto infl = coord_t(std::ceil(params.min_obj_distance / 2.0));
495 for (Item& itm : shapes) itm.inflate(infl);
496 for (Item& itm : excludes) itm.inflate(infl);
497
498 remove_large_items(excludes, corrected_bin);
499
500 // If there is something on the plate
501 if (!excludes.empty()) arranger.preload(excludes);
502
503 std::vector<std::reference_wrapper<Item>> inp;
504 inp.reserve(shapes.size() + excludes.size());
505 for (auto &itm : shapes ) inp.emplace_back(itm);
506 for (auto &itm : excludes) inp.emplace_back(itm);
507
508 // Use the minimum bounding box rotation as a starting point.
509 // TODO: This only works for convex hull. If we ever switch to concave
510 // polygon nesting, a convex hull needs to be calculated.
511 if (params.allow_rotations) {
512 for (auto &itm : shapes) {
513 itm.rotation(min_area_boundingbox_rotation(itm.rawShape()));
514
515 // If the item is too big, try to find a rotation that makes it fit
516 if constexpr (std::is_same_v<BinT, Box>) {
517 auto bb = itm.boundingBox();
518 if (bb.width() >= bin.width() || bb.height() >= bin.height())
519 itm.rotate(fit_into_box_rotation(itm.transformedShape(), bin));
520 }
521 }
522 }
523
524 if (sl::area(corrected_bin) > 0)
525 arranger(inp.begin(), inp.end());
526 else {
527 for (Item &itm : inp)
528 itm.binId(BIN_ID_UNSET);
529 }
530
531 for (Item &itm : inp) itm.inflate(-infl);
532}
Definition Arrange.cpp:131
int32_t coord_t
Definition libslic3r.h:39
#define inflate
Definition miniz.h:455
Definition CustomGCode.hpp:23
Definition Arrange.hpp:130
coord_t min_obj_distance
The minimum distance which is allowed for any pair of items on the print bed in any direction.
Definition Arrange.hpp:134
coord_t min_bed_distance
The minimum distance of any object from bed edges.
Definition Arrange.hpp:137
bool allow_rotations
Definition Arrange.hpp:146

References _arrange(), Slic3r::arrangement::ArrangeParams::allow_rotations, fit_into_box_rotation(), min_area_boundingbox_rotation(), Slic3r::arrangement::ArrangeParams::min_bed_distance, Slic3r::arrangement::ArrangeParams::min_obj_distance, and remove_large_items().

Referenced by _arrange(), and arrange().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ area()

double Slic3r::arrangement::area ( const BoundingBox box)
inline
541{ return double(width(box)) * height(box); }
coord_t width(const BoundingBox &box)
Definition Arrange.cpp:539
coord_t height(const BoundingBox &box)
Definition Arrange.cpp:540

References height(), and width().

+ Here is the call graph for this function:

◆ arrange() [1/17]

template<class BedT >
void Slic3r::arrangement::arrange ( ArrangePolygons arrangables,
const ArrangePolygons excludes,
const BedT &  bed,
const ArrangeParams params 
)
634{
635 namespace clppr = Slic3r::ClipperLib;
636
637 std::vector<Item> items, fixeditems;
638 items.reserve(arrangables.size());
639
640 for (ArrangePolygon &arrangeable : arrangables)
641 process_arrangeable(arrangeable, items);
642
643 for (const ArrangePolygon &fixed: excludes)
644 process_arrangeable(fixed, fixeditems);
645
646 for (Item &itm : fixeditems) itm.inflate(scaled(-2. * EPSILON));
647
648 auto &cfn = params.stopcondition;
649 auto &pri = params.progressind;
650
651 _arrange(items, fixeditems, to_nestbin(bed), params, pri, cfn);
652
653 for(size_t i = 0; i < items.size(); ++i) {
654 Point tr = items[i].translation();
655 arrangables[i].translation = {coord_t(tr.x()), coord_t(tr.y())};
656 arrangables[i].rotation = items[i].rotation();
657 arrangables[i].bed_idx = items[i].binId();
658 }
659}
Definition Point.hpp:158
An item to be placed on a bin.
Definition nester.hpp:28
static constexpr double EPSILON
Definition libslic3r.h:51
Definition ShortestPath.hpp:13
Box to_nestbin(const BoundingBox &bb)
Definition Arrange.cpp:534
static void process_arrangeable(const ArrangePolygon &arrpoly, std::vector< Item > &outp)
Definition Arrange.cpp:576
void _arrange(std::vector< Item > &shapes, std::vector< Item > &excludes, const BinT &bin, const ArrangeParams &params, std::function< void(unsigned)> progressfn, std::function< bool()> stopfn)
Definition Arrange.cpp:475
BoundingBox scaled(const BoundingBoxf &bb)
Definition BoundingBox.hpp:240
std::function< void(unsigned)> progressind
Progress indicator callback called when an object gets packed. The unsigned argument is the number of...
Definition Arrange.hpp:156
std::function< bool(void)> stopcondition
A predicate returning true if abort is needed.
Definition Arrange.hpp:161
Input/Output structure for the arrange() function. The poly field will not be modified during arrange...
Definition Arrange.hpp:93

References _arrange(), arrange(), EPSILON, process_arrangeable(), Slic3r::arrangement::ArrangeParams::progressind, Slic3r::scaled(), Slic3r::arrangement::ArrangeParams::stopcondition, and to_nestbin().

+ Here is the call graph for this function:

◆ arrange() [2/17]

void Slic3r::arrangement::arrange ( ArrangePolygons items,
const ArrangePolygons excludes,
const ArrangeBed bed,
const ArrangeParams params 
)
inline
201{
202 auto call_arrange = [&](const auto &realbed) { arrange(items, excludes, realbed, params); };
203 boost::apply_visitor(call_arrange, bed);
204}
void arrange(ArrangePolygons &items, const ArrangePolygons &excludes, const Points &bed, const ArrangeParams &params)
Definition Arrange.cpp:621

References arrange().

+ Here is the call graph for this function:

◆ arrange() [3/17]

template void Slic3r::arrangement::arrange ( ArrangePolygons items,
const ArrangePolygons excludes,
const BoundingBox bed,
const ArrangeParams params 
)

References arrange().

+ Here is the call graph for this function:

◆ arrange() [4/17]

template void Slic3r::arrangement::arrange ( ArrangePolygons items,
const ArrangePolygons excludes,
const CircleBed bed,
const ArrangeParams params 
)

References arrange().

+ Here is the call graph for this function:

◆ arrange() [5/17]

template void Slic3r::arrangement::arrange ( ArrangePolygons items,
const ArrangePolygons excludes,
const InfiniteBed bed,
const ArrangeParams params 
)

References arrange().

+ Here is the call graph for this function:

◆ arrange() [6/17]

void Slic3r::arrangement::arrange ( ArrangePolygons items,
const ArrangePolygons excludes,
const IrregularBed bed,
const ArrangeParams params 
)
inline
194{
195 arrange(items, excludes, bed.poly.contour, params);
196}
Polygon contour
Definition ExPolygon.hpp:35
ExPolygon poly
Definition Arrange.hpp:51

References arrange(), Slic3r::ExPolygon::contour, and Slic3r::arrangement::IrregularBed::poly.

+ Here is the call graph for this function:

◆ arrange() [7/17]

template<>
void Slic3r::arrangement::arrange ( ArrangePolygons items,
const ArrangePolygons excludes,
const Points bed,
const ArrangeParams params 
)
625{
626 arrange(items, excludes, to_arrange_bed(bed), params);
627}
ArrangeBed to_arrange_bed(const Points &bedpts)
Definition Arrange.cpp:666

References arrange(), and to_arrange_bed().

Referenced by arrange(), arrange(), arrange(), arrange(), arrange(), arrange(), arrange(), arrange(), arrange(), arrange(), Slic3r::arrange_objects(), Slic3r::duplicate(), Slic3r::GUI::ArrangeJob::process(), and Slic3r::GUI::FillBedJob::process().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ arrange() [8/17]

template<>
void Slic3r::arrangement::arrange ( ArrangePolygons items,
const ArrangePolygons excludes,
const Points bed,
const ArrangeParams params 
)
625{
626 arrange(items, excludes, to_arrange_bed(bed), params);
627}

References arrange(), and to_arrange_bed().

Referenced by arrange(), arrange(), arrange(), arrange(), arrange(), arrange(), arrange(), arrange(), arrange(), arrange(), Slic3r::arrange_objects(), Slic3r::duplicate(), Slic3r::GUI::ArrangeJob::process(), and Slic3r::GUI::FillBedJob::process().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ arrange() [9/17]

template void Slic3r::arrangement::arrange ( ArrangePolygons items,
const ArrangePolygons excludes,
const Polygon bed,
const ArrangeParams params 
)

References arrange().

+ Here is the call graph for this function:

◆ arrange() [10/17]

void Slic3r::arrangement::arrange ( ArrangePolygons items,
const ArrangePolygons excludes,
const RectangleBed bed,
const ArrangeParams params 
)
inline
189{
190 arrange(items, excludes, bed.bb, params);
191}
BoundingBox bb
Definition Arrange.hpp:22

References arrange(), and Slic3r::arrangement::RectangleBed::bb.

+ Here is the call graph for this function:

◆ arrange() [11/17]

void Slic3r::arrangement::arrange ( ArrangePolygons items,
const ArrangePolygons excludes,
const SegmentedRectangleBed bed,
const ArrangeParams params 
)
681{
682 arrange(items, excludes, bed.bb, params);
683
684 if (! excludes.empty())
685 return;
686
687 auto it = std::max_element(items.begin(), items.end(),
688 [](auto &i1, auto &i2) {
689 return i1.bed_idx < i2.bed_idx;
690 });
691
692 size_t beds = 0;
693 if (it != items.end())
694 beds = it->bed_idx + 1;
695
696 std::vector<BoundingBox> pilebb(beds);
697
698 for (auto &itm : items) {
699 if (itm.bed_idx >= 0)
700 pilebb[itm.bed_idx].merge(get_extents(itm.transformed_poly()));
701 }
702
703 auto piecesz = unscaled(bed.bb).size();
704 piecesz.x() /= bed.segments.x();
705 piecesz.y() /= bed.segments.y();
706
707 for (size_t bedidx = 0; bedidx < beds; ++bedidx) {
708 BoundingBox bb;
709 auto pilesz = unscaled(pilebb[bedidx]).size();
710 bb.max.x() = scaled(std::ceil(pilesz.x() / piecesz.x()) * piecesz.x());
711 bb.max.y() = scaled(std::ceil(pilesz.y() / piecesz.y()) * piecesz.y());
712 switch (params.alignment) {
713 case Pivots::BottomLeft:
714 bb.translate(bed.bb.min - bb.min);
715 break;
716 case Pivots::TopRight:
717 bb.translate(bed.bb.max - bb.max);
718 break;
719 case Pivots::BottomRight: {
720 Point bedref{bed.bb.max.x(), bed.bb.min.y()};
721 Point bbref {bb.max.x(), bb.min.y()};
722 bb.translate(bedref - bbref);
723 break;
724 }
725 case Pivots::TopLeft: {
726 Point bedref{bed.bb.min.x(), bed.bb.max.y()};
727 Point bbref {bb.min.x(), bb.max.y()};
728 bb.translate(bedref - bbref);
729 break;
730 }
731 case Pivots::Center: {
732 bb.translate(bed.bb.center() - bb.center());
733 break;
734 }
735 }
736
737 Vec2crd d = bb.center() - pilebb[bedidx].center();
738
739 auto bedbb = bed.bb;
740 bedbb.offset(-params.min_bed_distance);
741 auto pilebbx = pilebb[bedidx];
742 pilebbx.translate(d);
743
744 Point corr{0, 0};
745 corr.x() = -std::min(0, pilebbx.min.x() - bedbb.min.x())
746 -std::max(0, pilebbx.max.x() - bedbb.max.x());
747 corr.y() = -std::min(0, pilebbx.min.y() - bedbb.min.y())
748 -std::max(0, pilebbx.max.y() - bedbb.max.y());
749
750 d += corr;
751
752 for (auto &itm : items)
753 if (itm.bed_idx == int(bedidx))
754 itm.translation += d;
755 }
756}
PointType max
Definition BoundingBox.hpp:17
PointType center() const
Definition BoundingBox.cpp:194
void offset(coordf_t delta)
Definition BoundingBox.cpp:175
void translate(coordf_t x, coordf_t y)
Definition BoundingBox.hpp:41
PointType min
Definition BoundingBox.hpp:16
Definition BoundingBox.hpp:181
if(!(yy_init))
Definition lexer.c:1190
BoundingBox get_extents(const ExPolygon &expolygon)
Definition ExPolygon.cpp:352
constexpr Eigen::Matrix< Tout, 2, EigenArgs... > unscaled(const Slic3r::ClipperLib::IntPoint &v) noexcept
Definition Arrange.cpp:55
Eigen::Matrix< coord_t, 2, 1, Eigen::DontAlign > Vec2crd
Definition Point.hpp:37
Kernel::Point_2 Point
Definition point_areas.cpp:20
Pivots alignment
Final alignment of the merged pile after arrangement.
Definition Arrange.hpp:149
BoundingBox bb
Definition Arrange.hpp:40
Vec< 2, size_t > segments
Definition Arrange.hpp:39

References Slic3r::arrangement::ArrangeParams::alignment, arrange(), Slic3r::arrangement::SegmentedRectangleBed::bb, Slic3r::BoundingBoxBase< PointType, APointsType >::center(), Slic3r::get_extents(), Slic3r::BoundingBoxBase< PointType, APointsType >::max, Slic3r::BoundingBoxBase< PointType, APointsType >::min, Slic3r::arrangement::ArrangeParams::min_bed_distance, Slic3r::BoundingBoxBase< PointType, APointsType >::offset(), Slic3r::scaled(), Slic3r::arrangement::SegmentedRectangleBed::segments, Slic3r::BoundingBoxBase< PointType, APointsType >::translate(), and Slic3r::unscaled().

+ Here is the call graph for this function:

◆ arrange() [12/17]

template<class TBed >
void Slic3r::arrangement::arrange ( ArrangePolygons items,
const ArrangePolygons excludes,
const TBed &  bed,
const ArrangeParams params = {} 
)

Arranges the input polygons.

WARNING: Currently, only convex polygons are supported by the libnest2d library which is used to do the arrangement. This might change in the future this is why the interface contains a general polygon capable to have holes.

Parameters
itemsInput vector of ArrangePolygons. The transformation, rotation and bin_idx fields will be changed after the call finished and can be used to apply the result on the input polygon.

◆ arrange() [13/17]

void Slic3r::arrangement::arrange ( ArrangePolygons items,
const BoundingBox bed,
const ArrangeParams params = {} 
)
inline
207{}) { arrange(items, {}, bed, params); }

◆ arrange() [14/17]

void Slic3r::arrangement::arrange ( ArrangePolygons items,
const CircleBed bed,
const ArrangeParams params = {} 
)
inline
208{}) { arrange(items, {}, bed, params); }

◆ arrange() [15/17]

void Slic3r::arrangement::arrange ( ArrangePolygons items,
const InfiniteBed bed,
const ArrangeParams params = {} 
)
inline
210{}) { arrange(items, {}, bed, params); }

◆ arrange() [16/17]

void Slic3r::arrangement::arrange ( ArrangePolygons items,
const Points bed,
const ArrangeParams params = {} 
)
inline
206{}) { arrange(items, {}, bed, params); }

◆ arrange() [17/17]

void Slic3r::arrangement::arrange ( ArrangePolygons items,
const Polygon bed,
const ArrangeParams params = {} 
)
inline
209{}) { arrange(items, {}, bed, params); }

◆ bounding_box() [1/5]

BoundingBox Slic3r::arrangement::bounding_box ( const ArrangeBed b)
inline
69{
70 BoundingBox ret;
71 auto visitor = [&ret](const auto &b) { ret = bounding_box(b); };
72 boost::apply_visitor(visitor, b);
73
74 return ret;
75}

References bounding_box().

+ Here is the call graph for this function:

◆ bounding_box() [2/5]

BoundingBox Slic3r::arrangement::bounding_box ( const CircleBed b)
inline
62{
63 auto r = static_cast<coord_t>(std::round(b.radius()));
64 Point R{r, r};
65
66 return {b.center() - R, b.center() + R};
67}

◆ bounding_box() [3/5]

BoundingBox Slic3r::arrangement::bounding_box ( const InfiniteBed bed)
759{
760 BoundingBox ret;
761 using C = coord_t;
762
763 // It is important for Mx and My to be strictly less than half of the
764 // range of type C. width(), height() and area() will not overflow this way.
765 C Mx = C((std::numeric_limits<C>::lowest() + 2 * bed.center.x()) / 4.01);
766 C My = C((std::numeric_limits<C>::lowest() + 2 * bed.center.y()) / 4.01);
767
768 ret.max = bed.center - Point{Mx, My};
769 ret.min = bed.center + Point{Mx, My};
770
771 return ret;
772}
Point center
Definition Arrange.hpp:17

References Slic3r::arrangement::InfiniteBed::center, Slic3r::BoundingBoxBase< PointType, APointsType >::max, and Slic3r::BoundingBoxBase< PointType, APointsType >::min.

Referenced by bounding_box().

+ Here is the caller graph for this function:

◆ bounding_box() [4/5]

BoundingBox Slic3r::arrangement::bounding_box ( const RectangleBed b)
inline
59{ return b.bb; }

◆ bounding_box() [5/5]

BoundingBox Slic3r::arrangement::bounding_box ( const SegmentedRectangleBed b)
inline
60{ return b.bb; }

◆ call_with_bed()

template<class Fn >
auto Slic3r::arrangement::call_with_bed ( const Points bed,
Fn &&  fn 
)
595{
596 if (bed.empty())
597 return fn(InfiniteBed{});
598 else if (bed.size() == 1)
599 return fn(InfiniteBed{bed.front()});
600 else {
601 auto bb = BoundingBox(bed);
602 CircleBed circ = to_circle(bb.center(), bed);
603 auto parea = poly_area(bed);
604
605 if ((1.0 - parea / area(bb)) < 1e-3)
606 return fn(RectangleBed{bb});
607 else if (!std::isnan(circ.radius()))
608 return fn(circ);
609 else
610 return fn(IrregularBed{ExPolygon(bed)});
611 }
612}
Representing an unbounded bed.
Definition Arrange.hpp:16

References Slic3r::area(), call_with_bed(), poly_area(), Slic3r::arrangement::CircleBed::radius(), and to_circle().

Referenced by call_with_bed(), and to_arrange_bed().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ distance_to()

double Slic3r::arrangement::distance_to ( const Point p1,
const Point p2 
)
inline
544{
545 double dx = p2.x() - p1.x();
546 double dy = p2.y() - p1.y();
547 return std::sqrt(dx*dx + dy*dy);
548}

References distance_to().

Referenced by distance_to(), and to_circle().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fill_config()

template<class PConf >
void Slic3r::arrangement::fill_config ( PConf &  pcfg,
const ArrangeParams params 
)
85 {
86
87 // Align the arranged pile into the center of the bin
88 switch (params.alignment) {
89 case Pivots::Center: pcfg.alignment = PConf::Alignment::CENTER; break;
90 case Pivots::BottomLeft: pcfg.alignment = PConf::Alignment::BOTTOM_LEFT; break;
91 case Pivots::BottomRight: pcfg.alignment = PConf::Alignment::BOTTOM_RIGHT; break;
92 case Pivots::TopLeft: pcfg.alignment = PConf::Alignment::TOP_LEFT; break;
93 case Pivots::TopRight: pcfg.alignment = PConf::Alignment::TOP_RIGHT; break;
94 }
95
96 // Start placing the items from the center of the print bed
97 pcfg.starting_point = PConf::Alignment::CENTER;
98
99 // TODO cannot use rotations until multiple objects of same geometry can
100 // handle different rotations.
101 if (params.allow_rotations)
102 pcfg.rotations = {0., PI / 2., PI, 3. * PI / 2. };
103 else
104 pcfg.rotations = {0.};
105
106 // The accuracy of optimization.
107 // Goes from 0.0 to 1.0 and scales performance as well
108 pcfg.accuracy = params.accuracy;
109
110 // Allow parallel execution.
111 pcfg.parallel = params.parallel;
112}
static constexpr double PI
Definition libslic3r.h:58
float accuracy
The accuracy of optimization. Goes from 0.0 to 1.0 and scales performance as well.
Definition Arrange.hpp:141
bool parallel
Allow parallel execution.
Definition Arrange.hpp:144

References Slic3r::arrangement::ArrangeParams::accuracy, Slic3r::arrangement::ArrangeParams::alignment, Slic3r::arrangement::ArrangeParams::allow_rotations, BottomLeft, BottomRight, Center, Slic3r::arrangement::ArrangeParams::parallel, PI, TopLeft, and TopRight.

Referenced by Slic3r::arrangement::AutoArranger< TBin >::AutoArranger().

+ Here is the caller graph for this function:

◆ fit_into_box_rotation()

template<class S >
Radians Slic3r::arrangement::fit_into_box_rotation ( const S &  sh,
const _Box< TPoint< S > > &  box 
)
470{
471 return fitIntoBoxRotation<S, TCompute<S>, boost::rational<LargeInt>>(sh, box);
472}

References fit_into_box_rotation().

Referenced by _arrange(), and fit_into_box_rotation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fixed_overfit()

static double Slic3r::arrangement::fixed_overfit ( const std::tuple< double, Box > &  result,
const Box binbb 
)
static
118{
119 double score = std::get<0>(result);
120 Box pilebb = std::get<1>(result);
121 Box fullbb = sl::boundingBox(pilebb, binbb);
122 auto diff = double(fullbb.area()) - binbb.area();
123 if(diff > 0) score += diff;
124
125 return score;
126}
Unit area() const BP2D_NOEXCEPT
Definition geometry_traits.hpp:202
Slic3r::Polygons diff(const Slic3r::Polygon &subject, const Slic3r::Polygon &clip, ApplySafetyOffset do_safety_offset)
Definition ClipperUtils.cpp:672

References libnest2d::_Box< P >::area(), libnest2d::shapelike::boundingBox(), and Slic3r::diff().

+ Here is the call graph for this function:

◆ height()

coord_t Slic3r::arrangement::height ( const BoundingBox box)
inline
540{ return box.max.y() - box.min.y(); }

References height(), Slic3r::BoundingBoxBase< PointType, APointsType >::max, and Slic3r::BoundingBoxBase< PointType, APointsType >::min.

Referenced by area(), and height().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_box()

bool Slic3r::arrangement::is_box ( const Points bed)
615{
616 return !bed.empty() &&
617 ((1.0 - poly_area(bed) / area(BoundingBox(bed))) < 1e-3);
618}
double poly_area(const Points &pts)
Definition Arrange.cpp:542

References Slic3r::area(), is_box(), and poly_area().

Referenced by Slic3r::GUI::GLCanvas3D::_render_arrange_menu(), and is_box().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ min_area_boundingbox_rotation()

template<class S >
Radians Slic3r::arrangement::min_area_boundingbox_rotation ( const S &  sh)
463{
464 return minAreaBoundingBox<S, TCompute<S>, boost::rational<LargeInt>>(sh)
465 .angleToX();
466}

References min_area_boundingbox_rotation().

Referenced by _arrange(), and min_area_boundingbox_rotation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ poly_area()

double Slic3r::arrangement::poly_area ( const Points pts)
inline
542{ return std::abs(Polygon::area(pts)); }

References Slic3r::Polygon::area(), and poly_area().

Referenced by call_with_bed(), is_box(), and poly_area().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ process_arrangeable()

static void Slic3r::arrangement::process_arrangeable ( const ArrangePolygon arrpoly,
std::vector< Item > &  outp 
)
static
578{
579 Polygon p = arrpoly.poly.contour;
580 const Vec2crd &offs = arrpoly.translation;
581 double rotation = arrpoly.rotation;
582
583 outp.emplace_back(std::move(p));
584 outp.back().rotation(rotation);
585 outp.back().translation({offs.x(), offs.y()});
586 outp.back().inflate(arrpoly.inflation);
587 outp.back().binId(arrpoly.bed_idx);
588 outp.back().priority(arrpoly.priority);
589 outp.back().setOnPackedFn([&arrpoly](Item &itm){
590 itm.inflate(-arrpoly.inflation);
591 });
592}
Definition Polygon.hpp:24
ExPolygon poly
Definition Arrange.hpp:94
Vec2crd translation
The 2D silhouette to be arranged.
Definition Arrange.hpp:95
double rotation
The translation of the poly.
Definition Arrange.hpp:96
int priority
To which logical bed does poly belong...
Definition Arrange.hpp:99
coord_t inflation
The rotation of the poly in radians.
Definition Arrange.hpp:97
int bed_idx
Arrange with inflated polygon.
Definition Arrange.hpp:98

References Slic3r::arrangement::ArrangePolygon::bed_idx, Slic3r::ExPolygon::contour, libnest2d::_Item< RawShape >::inflate(), Slic3r::arrangement::ArrangePolygon::inflation, Slic3r::arrangement::ArrangePolygon::poly, Slic3r::arrangement::ArrangePolygon::priority, process_arrangeable(), Slic3r::arrangement::ArrangePolygon::rotation, and Slic3r::arrangement::ArrangePolygon::translation.

Referenced by arrange(), and process_arrangeable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ remove_large_items()

template<class Bin >
void Slic3r::arrangement::remove_large_items ( std::vector< Item > &  items,
Bin &&  bin 
)
455{
456 auto it = items.begin();
457 while (it != items.end())
458 sl::isInside(it->transformedShape(), bin) ?
459 ++it : it = items.erase(it);
460}

References remove_large_items().

Referenced by _arrange(), and remove_large_items().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ to_arrange_bed()

ArrangeBed Slic3r::arrangement::to_arrange_bed ( const Points bedpts)
667{
668 ArrangeBed ret;
669
670 call_with_bed(bedpts, [&](const auto &bed) {
671 ret = bed;
672 });
673
674 return ret;
675}
auto call_with_bed(const Points &bed, Fn &&fn)
Definition Arrange.cpp:594
boost::variant< InfiniteBed, RectangleBed, CircleBed, SegmentedRectangleBed, IrregularBed > ArrangeBed
Definition Arrange.hpp:56

References call_with_bed(), and to_arrange_bed().

Referenced by arrange(), Slic3r::get_bed_shape(), Slic3r::GUI::FillBedJob::prepare(), and to_arrange_bed().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ to_circle()

static CircleBed Slic3r::arrangement::to_circle ( const Point center,
const Points points 
)
static
550 {
551 std::vector<double> vertex_distances;
552 double avg_dist = 0;
553
554 for (const Point& pt : points)
555 {
556 double distance = distance_to(center, pt);
557 vertex_distances.push_back(distance);
558 avg_dist += distance;
559 }
560
561 avg_dist /= vertex_distances.size();
562
563 CircleBed ret(center, avg_dist);
564 for(auto el : vertex_distances)
565 {
566 if (std::abs(el - avg_dist) > 10 * SCALED_EPSILON) {
567 ret = {};
568 break;
569 }
570 }
571
572 return ret;
573}
A geometry abstraction for a circular print bed. Similarly to BoundingBox.
Definition Arrange.hpp:26
#define SCALED_EPSILON
Definition libslic3r.h:71
double distance_to(const Point &p1, const Point &p2)
Definition Arrange.cpp:543

References distance_to(), SCALED_EPSILON, and to_circle().

Referenced by call_with_bed(), and to_circle().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ to_nestbin() [1/4]

Box Slic3r::arrangement::to_nestbin ( const BoundingBox bb)
inline
534{ return Box{{bb.min(X), bb.min(Y)}, {bb.max(X), bb.max(Y)}};}

References Slic3r::BoundingBoxBase< PointType, APointsType >::max, Slic3r::BoundingBoxBase< PointType, APointsType >::min, to_nestbin(), Slic3r::X, and Slic3r::Y.

Referenced by arrange(), to_nestbin(), to_nestbin(), to_nestbin(), and to_nestbin().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ to_nestbin() [2/4]

Circle Slic3r::arrangement::to_nestbin ( const CircleBed c)
inline
535{ return Circle({c.center()(0), c.center()(1)}, c.radius()); }
Definition geometry_traits.hpp:216

References Slic3r::Circle, and to_nestbin().

+ Here is the call graph for this function:

◆ to_nestbin() [3/4]

Box Slic3r::arrangement::to_nestbin ( const InfiniteBed bed)
inline
537{ return Box::infinite({bed.center.x(), bed.center.y()}); }

References Slic3r::arrangement::InfiniteBed::center, and to_nestbin().

+ Here is the call graph for this function:

◆ to_nestbin() [4/4]

ExPolygon Slic3r::arrangement::to_nestbin ( const Polygon p)
inline
536{ return ExPolygon{p}; }
Definition ExPolygon.hpp:16

References to_nestbin().

+ Here is the call graph for this function:

◆ width()

coord_t Slic3r::arrangement::width ( const BoundingBox box)
inline
539{ return box.max.x() - box.min.x(); }

References Slic3r::BoundingBoxBase< PointType, APointsType >::max, Slic3r::BoundingBoxBase< PointType, APointsType >::min, and width().

Referenced by area(), and width().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ BIG_ITEM_TRESHOLD

const double Slic3r::arrangement::BIG_ITEM_TRESHOLD = 0.02

◆ UNARRANGED

const constexpr int Slic3r::arrangement::UNARRANGED = -1
staticconstexpr

A logical bed representing an object not being arranged. Either the arrange has not yet successfully run on this ArrangePolygon or it could not fit the object due to overly large size or invalid geometry.

Referenced by Slic3r::GUI::assign_logical_beds(), Slic3r::GUI::FillBedJob::finalize(), Slic3r::arrangement::ArrangePolygon::is_arranged(), and Slic3r::GUI::FillBedJob::prepare().