forked from prusa3d/PrusaSlicer
-
-
Notifications
You must be signed in to change notification settings - Fork 526
/
Copy pathPrintObject.cpp
3419 lines (3154 loc) · 201 KB
/
PrintObject.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "Exception.hpp"
#include "Print.hpp"
#include "BoundingBox.hpp"
#include "ClipperUtils.hpp"
#include "ElephantFootCompensation.hpp"
#include "Geometry.hpp"
#include "I18N.hpp"
#include "Layer.hpp"
#include "MutablePolygon.hpp"
#include "SupportMaterial.hpp"
#include "Surface.hpp"
#include "Slicing.hpp"
#include "Tesselate.hpp"
#include "TriangleMeshSlicer.hpp"
#include "Utils.hpp"
#include "Fill/FillAdaptive.hpp"
#include "Fill/FillLightning.hpp"
#include "Format/STL.hpp"
#include <atomic>
#include <float.h>
#include <string_view>
#include <utility>
#include <boost/log/trivial.hpp>
#include <tbb/parallel_for.h>
#include <Shiny/Shiny.h>
using namespace std::literals;
//! macro used to mark string used at localization,
//! return same string
#define L(s) Slic3r::I18N::translate(s)
#ifdef SLIC3R_DEBUG_SLICE_PROCESSING
#define SLIC3R_DEBUG
#endif
// #define SLIC3R_DEBUG
// Make assert active if SLIC3R_DEBUG
#ifdef SLIC3R_DEBUG
#undef NDEBUG
#define DEBUG
#define _DEBUG
#include "SVG.hpp"
#undef assert
#include <cassert>
#endif
namespace Slic3r {
// Constructor is called from the main thread, therefore all Model / ModelObject / ModelIntance data are valid.
PrintObject::PrintObject(Print* print, ModelObject* model_object, const Transform3d& trafo, PrintInstances&& instances) :
PrintObjectBaseWithState(print, model_object),
m_trafo(trafo)
{
// Compute centering offet to be applied to our meshes so that we work with smaller coordinates
// requiring less bits to represent Clipper coordinates.
// Snug bounding box of a rotated and scaled object by the 1st instantion, without the instance translation applied.
// All the instances share the transformation matrix with the exception of translation in XY and rotation by Z,
// therefore a bounding box from 1st instance of a ModelObject is good enough for calculating the object center,
// snug height and an approximate bounding box in XY.
BoundingBoxf3 bbox = model_object->raw_bounding_box();
Vec3d bbox_center = bbox.center();
// We may need to rotate the bbox / bbox_center from the original instance to the current instance.
double z_diff = Geometry::rotation_diff_z(model_object->instances.front()->get_rotation(), instances.front().model_instance->get_rotation());
if (std::abs(z_diff) > EPSILON) {
auto z_rot = Eigen::AngleAxisd(z_diff, Vec3d::UnitZ());
bbox = bbox.transformed(Transform3d(z_rot));
bbox_center = (z_rot * bbox_center).eval();
}
// Center of the transformed mesh (without translation).
m_center_offset = Point::new_scale(bbox_center.x(), bbox_center.y());
// Size of the transformed mesh. This bounding may not be snug in XY plane, but it is snug in Z.
m_size = (bbox.size() * (1. / SCALING_FACTOR)).cast<coord_t>();
this->set_instances(std::move(instances));
//create config hierarchy
m_config.parent = &print->config();
}
PrintBase::ApplyStatus PrintObject::set_instances(PrintInstances&& instances)
{
for (PrintInstance& i : instances)
// Add the center offset, which will be subtracted from the mesh when slicing.
i.shift += m_center_offset;
// Invalidate and set copies.
PrintBase::ApplyStatus status = PrintBase::APPLY_STATUS_UNCHANGED;
bool equal_length = instances.size() == m_instances.size();
bool equal = equal_length && std::equal(instances.begin(), instances.end(), m_instances.begin(),
[](const PrintInstance& lhs, const PrintInstance& rhs) { return lhs.model_instance == rhs.model_instance && lhs.shift == rhs.shift; });
if (!equal) {
status = PrintBase::APPLY_STATUS_CHANGED;
if (m_print->invalidate_steps({ psSkirtBrim, psGCodeExport }) ||
(!equal_length && m_print->invalidate_step(psWipeTower)))
status = PrintBase::APPLY_STATUS_INVALIDATED;
m_instances = std::move(instances);
for (PrintInstance& i : m_instances)
i.print_object = this;
}
return status;
}
std::vector<std::reference_wrapper<const PrintRegion>> PrintObject::all_regions() const
{
std::vector<std::reference_wrapper<const PrintRegion>> out;
out.reserve(m_shared_regions->all_regions.size());
for (const std::unique_ptr<Slic3r::PrintRegion> ®ion : m_shared_regions->all_regions)
out.emplace_back(*region.get());
return out;
}
Polygons create_polyholes(const Point center, const coord_t radius, const coord_t nozzle_diameter, bool multiple)
{
// n = max(round(2 * d), 3); // for 0.4mm nozzle
size_t nb_edges = (int)std::max(3, (int)std::round(4.0 * unscaled(radius) * 0.4 / unscaled(nozzle_diameter)));
// cylinder(h = h, r = d / cos (180 / n), $fn = n);
//create x polyholes by rotation if multiple
int nb_polyhole = 1;
float rotation = 0;
if (multiple) {
nb_polyhole = 5;
rotation = 2 * float(PI) / (nb_edges * nb_polyhole);
}
Polygons list;
for (int i_poly = 0; i_poly < nb_polyhole; i_poly++)
list.emplace_back();
for (int i_poly = 0; i_poly < nb_polyhole; i_poly++) {
Polygon& pts = (((i_poly % 2) == 0) ? list[i_poly / 2] : list[(nb_polyhole + 1) / 2 + i_poly / 2]);
const float new_radius = radius / float(std::cos(PI / nb_edges));
for (size_t i_edge = 0; i_edge < nb_edges; ++i_edge) {
float angle = rotation * i_poly + (float(PI) * 2 * (float)i_edge) / nb_edges;
pts.points.emplace_back(center.x() + new_radius * cos(angle), center.y() + new_radius * sin(angle));
}
pts.make_clockwise();
}
//alternate
return list;
}
void PrintObject::_transform_hole_to_polyholes()
{
// get all circular holes for each layer
// the id is center-diameter-extruderid
//the tuple is Point center; float diameter_max; int extruder_id; coord_t max_variation; bool twist;
std::vector<std::vector<std::pair<std::tuple<Point, float, int, coord_t, bool>, Polygon*>>> layerid2center;
for (size_t i = 0; i < this->m_layers.size(); i++) layerid2center.emplace_back();
tbb::parallel_for(
tbb::blocked_range<size_t>(0, m_layers.size()),
[this, &layerid2center](const tbb::blocked_range<size_t>& range) {
for (size_t layer_idx = range.begin(); layer_idx < range.end(); ++layer_idx) {
m_print->throw_if_canceled();
Layer* layer = m_layers[layer_idx];
for (size_t region_idx = 0; region_idx < layer->m_regions.size(); ++region_idx)
{
if (layer->m_regions[region_idx]->region().config().hole_to_polyhole) {
for (Surface& surf : layer->m_regions[region_idx]->m_slices.surfaces) {
for (Polygon& hole : surf.expolygon.holes) {
//test if convex (as it's clockwise bc it's a hole, we have to do the opposite)
if (hole.convex_points().empty() && hole.points.size() > 8) {
// Computing circle center
Point center = hole.centroid();
double diameter_min = std::numeric_limits<float>::max(), diameter_max = 0;
double diameter_sum = 0;
for (int i = 0; i < hole.points.size(); ++i) {
double dist = hole.points[i].distance_to(center);
diameter_min = std::min(diameter_min, dist);
diameter_max = std::max(diameter_max, dist);
diameter_sum += dist;
}
//also use center of lines to check it's not a rectangle
double diameter_line_min = std::numeric_limits<float>::max(), diameter_line_max = 0;
Lines hole_lines = hole.lines();
for (Line l : hole_lines) {
Point midline = (l.a + l.b) / 2;
double dist = center.distance_to(midline);
diameter_line_min = std::min(diameter_line_min, dist);
diameter_line_max = std::max(diameter_line_max, dist);
}
// SCALED_EPSILON was a bit too harsh. Now using a config, as some may want some harsh setting and some don't.
coord_t max_variation = std::max(SCALED_EPSILON, scale_(this->m_layers[layer_idx]->m_regions[region_idx]->region().config().hole_to_polyhole_threshold.get_abs_value(unscaled(diameter_sum / hole.points.size()))));
bool twist = this->m_layers[layer_idx]->m_regions[region_idx]->region().config().hole_to_polyhole_twisted.value;
if (diameter_max - diameter_min < max_variation * 2 && diameter_line_max - diameter_line_min < max_variation * 2) {
layerid2center[layer_idx].emplace_back(
std::tuple<Point, float, int, coord_t, bool>{center, diameter_max, layer->m_regions[region_idx]->region().config().perimeter_extruder.value, max_variation, twist}, & hole);
}
}
}
}
}
}
// for layer->slices, it will be also replaced later.
}
});
//sort holes per center-diameter
std::map<std::tuple<Point, float, int, coord_t, bool>, std::vector<std::pair<Polygon*, int>>> id2layerz2hole;
//search & find hole that span at least X layers
const size_t min_nb_layers = 2;
for (size_t layer_idx = 0; layer_idx < this->m_layers.size(); ++layer_idx) {
for (size_t hole_idx = 0; hole_idx < layerid2center[layer_idx].size(); ++hole_idx) {
//get all other same polygons
std::tuple<Point, float, int, coord_t, bool>& id = layerid2center[layer_idx][hole_idx].first;
float max_z = layers()[layer_idx]->print_z;
std::vector<std::pair<Polygon*, int>> holes;
holes.emplace_back(layerid2center[layer_idx][hole_idx].second, layer_idx);
for (size_t search_layer_idx = layer_idx + 1; search_layer_idx < this->m_layers.size(); ++search_layer_idx) {
if (layers()[search_layer_idx]->print_z - layers()[search_layer_idx]->height - max_z > EPSILON) break;
//search an other polygon with same id
for (size_t search_hole_idx = 0; search_hole_idx < layerid2center[search_layer_idx].size(); ++search_hole_idx) {
std::tuple<Point, float, int, coord_t, bool>& search_id = layerid2center[search_layer_idx][search_hole_idx].first;
if (std::get<2>(id) == std::get<2>(search_id)
&& std::get<0>(id).distance_to(std::get<0>(search_id)) < std::get<3>(id)
&& std::abs(std::get<1>(id) - std::get<1>(search_id)) < std::get<3>(id)
) {
max_z = layers()[search_layer_idx]->print_z;
holes.emplace_back(layerid2center[search_layer_idx][search_hole_idx].second, search_layer_idx);
layerid2center[search_layer_idx].erase(layerid2center[search_layer_idx].begin() + search_hole_idx);
search_hole_idx--;
break;
}
}
}
//check if strait hole or first layer hole (cause of first layer compensation)
if (holes.size() >= min_nb_layers || (holes.size() == 1 && holes[0].second == 0)) {
id2layerz2hole.emplace(std::move(id), std::move(holes));
}
}
}
//create a polyhole per id and replace holes points by it.
for (auto entry : id2layerz2hole) {
Polygons polyholes = create_polyholes(std::get<0>(entry.first), std::get<1>(entry.first), scale_(print()->config().nozzle_diameter.get_at(std::get<2>(entry.first) - 1)), std::get<4>(entry.first));
for (auto& poly_to_replace : entry.second) {
Polygon polyhole = polyholes[poly_to_replace.second % polyholes.size()];
//search the clone in layers->slices
for (ExPolygon& explo_slice : m_layers[poly_to_replace.second]->lslices) {
for (Polygon& poly_slice : explo_slice.holes) {
if (poly_slice.points == poly_to_replace.first->points) {
poly_slice.points = polyhole.points;
}
}
}
// copy
poly_to_replace.first->points = polyhole.points;
}
}
}
// 1) Merges typed region slices into stInternal type.
// 2) Increases an "extra perimeters" counter at region slices where needed.
// 3) Generates perimeters, gap fills and fill regions (fill regions of type stInternal).
void PrintObject::make_perimeters()
{
// prerequisites
this->slice();
if (!this->set_started(posPerimeters))
return;
m_print->set_status(10, L("Generating perimeters"));
BOOST_LOG_TRIVIAL(info) << "Generating perimeters..." << log_memory_info();
// Revert the typed slices into untyped slices.
if (m_typed_slices) {
for (Layer* layer : m_layers) {
layer->restore_untyped_slices();
m_print->throw_if_canceled();
}
m_typed_slices = false;
}
// atomic counter for gui progress
std::atomic<int> atomic_count{ 0 };
int nb_layers_update = std::max(1, (int)m_layers.size() / 20);
// compare each layer to the one below, and mark those slices needing
// one additional inner perimeter, like the top of domed objects-
// this algorithm makes sure that at least one perimeter is overlapping
// but we don't generate any extra perimeter if fill density is zero, as they would be floating
// inside the object - infill_only_where_needed should be the method of choice for printing
// hollow objects
for (size_t region_id = 0; region_id < this->num_printing_regions(); ++ region_id) {
const PrintRegion ®ion = this->printing_region(region_id);
if (!region.config().extra_perimeters || region.config().perimeters == 0 || region.config().fill_density == 0 || this->layer_count() < 2)
continue;
BOOST_LOG_TRIVIAL(debug) << "Generating extra perimeters for region " << region_id << " in parallel - start";
tbb::parallel_for(
tbb::blocked_range<size_t>(0, m_layers.size() - 1),
[this, ®ion, region_id](const tbb::blocked_range<size_t>& range) {
for (size_t layer_idx = range.begin(); layer_idx < range.end(); ++layer_idx) {
m_print->throw_if_canceled();
LayerRegion &layerm = *m_layers[layer_idx]->get_region(region_id);
const LayerRegion &upper_layerm = *m_layers[layer_idx+1]->get_region(region_id);
const Polygons upper_layerm_polygons = to_polygons(upper_layerm.slices().surfaces);
// Filter upper layer polygons in intersection_ppl by their bounding boxes?
// my $upper_layerm_poly_bboxes= [ map $_->bounding_box, @{$upper_layerm_polygons} ];
const double total_loop_length = total_length(upper_layerm_polygons);
const coord_t perimeter_spacing = layerm.flow(frPerimeter).scaled_spacing();
const Flow ext_perimeter_flow = layerm.flow(frExternalPerimeter);
const coord_t ext_perimeter_width = ext_perimeter_flow.scaled_width();
const coord_t ext_perimeter_spacing = ext_perimeter_flow.scaled_spacing();
for (Surface& slice : layerm.m_slices.surfaces) {
for (;;) {
// compute the total thickness of perimeters
const coord_t perimeters_thickness = ext_perimeter_width / 2 + ext_perimeter_spacing / 2
+ (region.config().perimeters - 1 + slice.extra_perimeters) * perimeter_spacing;
// define a critical area where we don't want the upper slice to fall into
// (it should either lay over our perimeters or outside this area)
const coord_t critical_area_depth = coord_t(perimeter_spacing * 1.5);
const Polygons critical_area = diff(
offset(slice.expolygon, double(-perimeters_thickness)),
offset(slice.expolygon, double(-perimeters_thickness - critical_area_depth))
);
// check whether a portion of the upper slices falls inside the critical area
const Polylines intersection = intersection_pl(to_polylines(upper_layerm_polygons), critical_area);
// only add an additional loop if at least 30% of the slice loop would benefit from it
if (total_length(intersection) <= total_loop_length * 0.3)
break;
/*
if (0) {
require "Slic3r/SVG.pm";
Slic3r::SVG::output(
"extra.svg",
no_arrows => 1,
expolygons => union_ex($critical_area),
polylines => [ map $_->split_at_first_point, map $_->p, @{$upper_layerm->slices} ],
);
}
*/
++slice.extra_perimeters;
}
#ifdef DEBUG
if (slice.extra_perimeters > 0)
printf(" adding %d more perimeter(s) at layer %zu\n", slice.extra_perimeters, layer_idx);
#endif
}
}
});
m_print->throw_if_canceled();
BOOST_LOG_TRIVIAL(debug) << "Generating extra perimeters for region " << region_id << " in parallel - end";
}
BOOST_LOG_TRIVIAL(debug) << "Generating perimeters in parallel - start";
tbb::parallel_for(
tbb::blocked_range<size_t>(0, m_layers.size()),
[this, &atomic_count, nb_layers_update](const tbb::blocked_range<size_t>& range) {
for (size_t layer_idx = range.begin(); layer_idx < range.end(); ++layer_idx) {
std::chrono::time_point<std::chrono::system_clock> start_make_perimeter = std::chrono::system_clock::now();
m_print->throw_if_canceled();
m_layers[layer_idx]->make_perimeters();
// updating progress
int nb_layers_done = (++atomic_count);
std::chrono::time_point<std::chrono::system_clock> end_make_perimeter = std::chrono::system_clock::now();
if (nb_layers_done % nb_layers_update == 0 || (static_cast<std::chrono::duration<double>>(end_make_perimeter - start_make_perimeter)).count() > 5) {
m_print->set_status( int((nb_layers_done * 100) / m_layers.size()), L("Generating perimeters: layer %s / %s"), { std::to_string(nb_layers_done), std::to_string(m_layers.size()) }, PrintBase::SlicingStatus::SECONDARY_STATE);
}
}
}
);
m_print->set_status(100, "", PrintBase::SlicingStatus::SECONDARY_STATE);
m_print->throw_if_canceled();
BOOST_LOG_TRIVIAL(debug) << "Generating perimeters in parallel - end";
if (print()->config().milling_diameter.size() > 0) {
BOOST_LOG_TRIVIAL(debug) << "Generating milling post-process in parallel - start";
tbb::parallel_for(
tbb::blocked_range<size_t>(0, m_layers.size()),
[this](const tbb::blocked_range<size_t>& range) {
for (size_t layer_idx = range.begin(); layer_idx < range.end(); ++layer_idx) {
m_print->throw_if_canceled();
m_layers[layer_idx]->make_milling_post_process();
}
}
);
m_print->throw_if_canceled();
BOOST_LOG_TRIVIAL(debug) << "Generating milling post-process in parallel - end";
}
this->set_done(posPerimeters);
}
void PrintObject::prepare_infill()
{
if (!this->set_started(posPrepareInfill))
return;
m_print->set_status(25, L("Preparing infill"));
if (m_typed_slices) {
// To improve robustness of detect_surfaces_type() when reslicing (working with typed slices), see GH issue #7442.
// The preceding step (perimeter generator) only modifies extra_perimeters and the extra perimeters are only used by discover_vertical_shells()
// with more than a single region. If this step does not use Surface::extra_perimeters or Surface::extra_perimeters is always zero, it is safe
// to reset to the untyped slices before re-runnning detect_surfaces_type().
for (Layer* layer : m_layers) {
layer->restore_untyped_slices_no_extra_perimeters();
m_print->throw_if_canceled();
}
}
// This will assign a type (top/bottom/internal) to $layerm->slices.
// Then the classifcation of $layerm->slices is transfered onto
// the $layerm->fill_surfaces by clipping $layerm->fill_surfaces
// by the cummulative area of the previous $layerm->fill_surfaces.
this->detect_surfaces_type();
m_print->throw_if_canceled();
// Decide what surfaces are to be filled.
// Here the stTop / stBottomBridge / stBottom infill is turned to just stInternal if zero top / bottom infill layers are configured.
// Also tiny stInternal surfaces are turned to stInternalSolid.
BOOST_LOG_TRIVIAL(info) << "Preparing fill surfaces..." << log_memory_info();
for (auto* layer : m_layers)
for (auto* region : layer->m_regions) {
region->prepare_fill_surfaces();
m_print->throw_if_canceled();
}
// this will detect bridges and reverse bridges
// and rearrange top/bottom/internal surfaces
// It produces enlarged overlapping bridging areas.
//
// 1) stBottomBridge / stBottom infill is grown by 3mm and clipped by the total infill area. Bridges are detected. The areas may overlap.
// 2) stTop is grown by 3mm and clipped by the grown bottom areas. The areas may overlap.
// 3) Clip the internal surfaces by the grown top/bottom surfaces.
// 4) Merge surfaces with the same style. This will mostly get rid of the overlaps.
//FIXME This does not likely merge surfaces, which are supported by a material with different colors, but same properties.
this->process_external_surfaces();
m_print->throw_if_canceled();
// Add solid fills to ensure the shell vertical thickness.
this->discover_vertical_shells();
m_print->throw_if_canceled();
// Debugging output.
#ifdef SLIC3R_DEBUG_SLICE_PROCESSING
for (size_t region_id = 0; region_id < this->num_printing_regions(); ++ region_id) {
for (const Layer* layer : m_layers) {
LayerRegion* layerm = layer->m_regions[region_id];
layerm->export_region_slices_to_svg_debug("6_discover_vertical_shells-final");
layerm->export_region_fill_surfaces_to_svg_debug("6_discover_vertical_shells-final");
} // for each layer
} // for each region
#endif /* SLIC3R_DEBUG_SLICE_PROCESSING */
// Detect, which fill surfaces are near external layers.
// They will be split in internal and internal-solid surfaces.
// The purpose is to add a configurable number of solid layers to support the TOP surfaces
// and to add a configurable number of solid layers above the BOTTOM / BOTTOMBRIDGE surfaces
// to close these surfaces reliably.
//FIXME Vojtech: Is this a good place to add supporting infills below sloping perimeters?
//note: only if not "ensure vertical shell"
this->discover_horizontal_shells();
m_print->throw_if_canceled();
//as there is some too thin solid surface, please deleted them and merge all of the surfacesthat are contigous.
this->clean_surfaces();
#ifdef SLIC3R_DEBUG_SLICE_PROCESSING
for (size_t region_id = 0; region_id < this->num_printing_regions(); ++ region_id) {
for (const Layer* layer : m_layers) {
LayerRegion* layerm = layer->m_regions[region_id];
layerm->export_region_slices_to_svg_debug("7_discover_horizontal_shells-final");
layerm->export_region_fill_surfaces_to_svg_debug("7_discover_horizontal_shells-final");
} // for each layer
} // for each region
#endif /* SLIC3R_DEBUG_SLICE_PROCESSING */
// Only active if config->infill_only_where_needed. This step trims the sparse infill,
// so it acts as an internal support. It maintains all other infill types intact.
// Here the internal surfaces and perimeters have to be supported by the sparse infill.
//FIXME The surfaces are supported by a sparse infill, but the sparse infill is only as large as the area to support.
// Likely the sparse infill will not be anchored correctly, so it will not work as intended.
// Also one wishes the perimeters to be supported by a full infill.
this->clip_fill_surfaces();
m_print->throw_if_canceled();
#ifdef SLIC3R_DEBUG_SLICE_PROCESSING
for (size_t region_id = 0; region_id < this->num_printing_regions(); ++ region_id) {
for (const Layer* layer : m_layers) {
LayerRegion* layerm = layer->m_regions[region_id];
layerm->export_region_slices_to_svg_debug("8_clip_surfaces-final");
layerm->export_region_fill_surfaces_to_svg_debug("8_clip_surfaces-final");
} // for each layer
} // for each region
#endif /* SLIC3R_DEBUG_SLICE_PROCESSING */
// the following step needs to be done before combination because it may need
// to remove only half of the combined infill
this->bridge_over_infill();
m_print->throw_if_canceled();
this->replaceSurfaceType(stPosInternal | stDensSolid,
stPosInternal | stDensSolid | stModOverBridge,
stPosInternal | stDensSolid | stModBridge);
m_print->throw_if_canceled();
this->replaceSurfaceType(stPosTop | stDensSolid,
stPosTop | stDensSolid | stModOverBridge,
stPosInternal | stDensSolid | stModBridge);
m_print->throw_if_canceled();
this->replaceSurfaceType(stPosInternal | stDensSolid,
stPosInternal | stDensSolid | stModOverBridge,
stPosBottom | stDensSolid | stModBridge);
m_print->throw_if_canceled();
this->replaceSurfaceType(stPosTop | stDensSolid,
stPosTop | stDensSolid | stModOverBridge,
stPosBottom | stDensSolid | stModBridge);
m_print->throw_if_canceled();
// combine fill surfaces to honor the "infill every N layers" option
this->combine_infill();
m_print->throw_if_canceled();
// count the distance from the nearest top surface, to allow to use denser infill
// if needed and if infill_dense_layers is positive.
this->tag_under_bridge();
m_print->throw_if_canceled();
#ifdef SLIC3R_DEBUG_SLICE_PROCESSING
for (size_t region_id = 0; region_id < this->num_printing_regions(); ++ region_id) {
for (const Layer* layer : m_layers) {
LayerRegion* layerm = layer->m_regions[region_id];
layerm->export_region_slices_to_svg_debug("9_prepare_infill-final");
layerm->export_region_fill_surfaces_to_svg_debug("9_prepare_infill-final");
} // for each layer
} // for each region
for (const Layer* layer : m_layers) {
layer->export_region_slices_to_svg_debug("9_prepare_infill-final");
layer->export_region_fill_surfaces_to_svg_debug("9_prepare_infill-final");
} // for each layer
#endif /* SLIC3R_DEBUG_SLICE_PROCESSING */
this->set_done(posPrepareInfill);
}
void PrintObject::infill()
{
// prerequisites
this->prepare_infill();
m_print->set_status(35, L("Infilling layers"));
m_print->set_status(0, L("Infilling layer %s / %s"), { std::to_string(0), std::to_string(m_layers.size()) }, PrintBase::SlicingStatus::SECONDARY_STATE);
if (this->set_started(posInfill)) {
auto [adaptive_fill_octree, support_fill_octree] = this->prepare_adaptive_infill_data();
auto lightning_generator = this->prepare_lightning_infill_data();
// atomic counter for gui progress
std::atomic<int> atomic_count{ 0 };
const int nb_layers_update = std::max(1, (int)m_layers.size() / 20);
BOOST_LOG_TRIVIAL(debug) << "Filling layers in parallel - start";
tbb::parallel_for(
tbb::blocked_range<size_t>(0, m_layers.size()),
[this, &adaptive_fill_octree = adaptive_fill_octree, &support_fill_octree = support_fill_octree, &lightning_generator, &atomic_count, nb_layers_update](const tbb::blocked_range<size_t>& range) {
for (size_t layer_idx = range.begin(); layer_idx < range.end(); ++layer_idx) {
std::chrono::time_point<std::chrono::system_clock> start_make_fill = std::chrono::system_clock::now();
m_print->throw_if_canceled();
m_layers[layer_idx]->make_fills(adaptive_fill_octree.get(), support_fill_octree.get(), lightning_generator.get());
// updating progress
int nb_layers_done = (++atomic_count);
std::chrono::time_point<std::chrono::system_clock> end_make_fill = std::chrono::system_clock::now();
if (nb_layers_done % nb_layers_update == 0 || (static_cast<std::chrono::duration<double>>(end_make_fill - start_make_fill)).count() > 5) {
m_print->set_status( int((nb_layers_done * 100) / m_layers.size()), L("Infilling layer %s / %s"), { std::to_string(nb_layers_done), std::to_string(m_layers.size()) }, PrintBase::SlicingStatus::SECONDARY_STATE);
}
}
}
);
m_print->set_status(100, "", PrintBase::SlicingStatus::SECONDARY_STATE);
//for (size_t layer_idx = 0; layer_idx < m_layers.size(); ++ layer_idx) {
// m_print->throw_if_canceled();
// m_layers[layer_idx]->make_fills();
//}
m_print->throw_if_canceled();
BOOST_LOG_TRIVIAL(debug) << "Filling layers in parallel - end";
/* we could free memory now, but this would make this step not idempotent
### $_->fill_surfaces->clear for map @{$_->regions}, @{$object->layers};
*/
this->set_done(posInfill);
}
}
void PrintObject::ironing()
{
if (this->set_started(posIroning)) {
BOOST_LOG_TRIVIAL(debug) << "Ironing in parallel - start";
tbb::parallel_for(
// Ironing starting with layer 0 to support ironing all surfaces.
tbb::blocked_range<size_t>(0, m_layers.size()),
[this](const tbb::blocked_range<size_t>& range) {
for (size_t layer_idx = range.begin(); layer_idx < range.end(); ++layer_idx) {
m_print->throw_if_canceled();
m_layers[layer_idx]->make_ironing();
}
}
);
m_print->throw_if_canceled();
BOOST_LOG_TRIVIAL(debug) << "Ironing in parallel - end";
this->set_done(posIroning);
}
}
void PrintObject::generate_support_material()
{
if (this->set_started(posSupportMaterial)) {
this->clear_support_layers();
if ((this->has_support() && m_layers.size() > 1) || (this->has_raft() && ! m_layers.empty())) {
this->_generate_support_material();
m_print->throw_if_canceled();
} else {
#if 0
// Printing without supports. Empty layer means some objects or object parts are levitating,
// therefore they cannot be printed without supports.
for (const Layer* layer : m_layers)
if (layer->empty())
throw Slic3r::SlicingError("Levitating objects cannot be printed without supports.");
#endif
}
this->set_done(posSupportMaterial);
}
}
void PrintObject::simplify_extrusion_path()
{
if (this->set_started(posSimplifyPath)) {
const PrintConfig& print_config = this->print()->config();
const bool spiral_mode = print_config.spiral_vase;
const bool enable_arc_fitting = print_config.arc_fitting && !spiral_mode;
m_print->set_status(0, L("Optimizing layer %s / %s"), { std::to_string(0), std::to_string(m_layers.size()) }, PrintBase::SlicingStatus::SECONDARY_STATE);
BOOST_LOG_TRIVIAL(debug) << "Simplify extrusion path of object in parallel - start";
//BBS: infill and walls
std::atomic<int> atomic_count{ 0 };
tbb::parallel_for(
tbb::blocked_range<size_t>(0, m_layers.size()),
[this, &atomic_count](const tbb::blocked_range<size_t>& range) {
for (size_t layer_idx = range.begin(); layer_idx < range.end(); ++layer_idx) {
m_print->throw_if_canceled();
m_layers[layer_idx]->simplify_extrusion_path();
int nb_layers_done = (++atomic_count);
m_print->set_status(int((nb_layers_done * 100) / m_layers.size()), L("Optimizing layer %s / %s"), { std::to_string(nb_layers_done), std::to_string(m_layers.size()) }, PrintBase::SlicingStatus::SECONDARY_STATE);
}
}
);
//also simplify object skirt & brim
if (enable_arc_fitting) {
coordf_t scaled_resolution = scale_d(print_config.resolution.value);
if (scaled_resolution == 0) scaled_resolution = enable_arc_fitting ? SCALED_EPSILON * 2 : SCALED_EPSILON;
const ConfigOptionFloatOrPercent& arc_fitting_tolerance = print_config.arc_fitting_tolerance;
GetPathsVisitor visitor;
this->m_skirt.visit(visitor);
this->m_brim.visit(visitor);
tbb::parallel_for(
tbb::blocked_range<size_t>(0, visitor.paths.size() + visitor.paths3D.size()),
[this, &visitor, scaled_resolution, &arc_fitting_tolerance](const tbb::blocked_range<size_t>& range) {
size_t path_idx = range.begin();
for (; path_idx < range.end() && path_idx < visitor.paths.size(); ++path_idx) {
visitor.paths[path_idx]->simplify(scaled_resolution, true, arc_fitting_tolerance.get_abs_value(visitor.paths[path_idx]->width));
}
for (; path_idx < range.end() && path_idx - visitor.paths.size() < visitor.paths3D.size(); ++path_idx) {
visitor.paths3D[path_idx - visitor.paths.size()]->simplify(scaled_resolution, true, arc_fitting_tolerance.get_abs_value(visitor.paths3D[path_idx - visitor.paths.size()]->width));
}
}
);
}
m_print->throw_if_canceled();
BOOST_LOG_TRIVIAL(debug) << "Simplify extrusion path of object in parallel - end";
//BBS: share same progress
BOOST_LOG_TRIVIAL(debug) << "Simplify extrusion path of support in parallel - start";
m_print->set_status(0, L("Optimizing support layer %s / %s"), { std::to_string(0), std::to_string(m_layers.size()) }, PrintBase::SlicingStatus::SECONDARY_STATE);
atomic_count.store(0);
tbb::parallel_for(
tbb::blocked_range<size_t>(0, m_support_layers.size()),
[this, &atomic_count](const tbb::blocked_range<size_t>& range) {
for (size_t layer_idx = range.begin(); layer_idx < range.end(); ++layer_idx) {
m_print->throw_if_canceled();
m_support_layers[layer_idx]->simplify_support_extrusion_path();
int nb_layers_done = (++atomic_count);
m_print->set_status(int((nb_layers_done * 100) / m_layers.size()), L("Optimizing layer %s / %s"), { std::to_string(nb_layers_done), std::to_string(m_layers.size()) }, PrintBase::SlicingStatus::SECONDARY_STATE);
}
}
);
m_print->throw_if_canceled();
BOOST_LOG_TRIVIAL(debug) << "Simplify extrusion path of support in parallel - end";
this->set_done(posSimplifyPath);
}
}
std::pair<FillAdaptive::OctreePtr, FillAdaptive::OctreePtr> PrintObject::prepare_adaptive_infill_data()
{
using namespace FillAdaptive;
auto [adaptive_line_spacing, support_line_spacing] = adaptive_fill_line_spacing(*this);
if ((adaptive_line_spacing == 0. && support_line_spacing == 0.) || this->layers().empty())
return std::make_pair(OctreePtr(), OctreePtr());
indexed_triangle_set mesh = this->model_object()->raw_indexed_triangle_set();
// Rotate mesh and build octree on it with axis-aligned (standart base) cubes.
auto to_octree = transform_to_octree().toRotationMatrix();
its_transform(mesh, to_octree * this->trafo_centered(), true);
// Triangulate internal bridging surfaces.
std::vector<std::vector<Vec3d>> overhangs(this->layers().size());
tbb::parallel_for(
tbb::blocked_range<int>(0, int(m_layers.size()) - 1),
[this, &to_octree, &overhangs](const tbb::blocked_range<int>& range) {
std::vector<Vec3d>& out = overhangs[range.begin()];
for (int idx_layer = range.begin(); idx_layer < range.end(); ++idx_layer) {
m_print->throw_if_canceled();
const Layer* layer = this->layers()[idx_layer];
for (const LayerRegion* layerm : layer->regions())
for (const Surface& surface : layerm->fill_surfaces.surfaces)
if (surface.surface_type == (stPosInternal | stDensSolid | stModBridge))
append(out, triangulate_expolygon_3d(surface.expolygon, layer->bottom_z()));
}
for (Vec3d& p : out)
p = (to_octree * p).eval();
});
// and gather them.
for (size_t i = 1; i < overhangs.size(); ++i)
append(overhangs.front(), std::move(overhangs[i]));
return std::make_pair(
adaptive_line_spacing ? build_octree(mesh, overhangs.front(), adaptive_line_spacing, false) : OctreePtr(),
support_line_spacing ? build_octree(mesh, overhangs.front(), support_line_spacing, true) : OctreePtr());
}
FillLightning::GeneratorPtr PrintObject::prepare_lightning_infill_data()
{
bool has_lightning_infill = false;
coordf_t lightning_density = 0.;
size_t lightning_cnt = 0;
for (size_t region_id = 0; region_id < this->num_printing_regions(); ++region_id)
if (const PrintRegionConfig &config = this->printing_region(region_id).config(); config.fill_density > 0 && config.fill_pattern.value == ipLightning) {
has_lightning_infill = true;
lightning_density += config.fill_density;
++lightning_cnt;
}
if (has_lightning_infill)
lightning_density /= coordf_t(lightning_cnt);
return has_lightning_infill ? FillLightning::build_generator(std::as_const(*this), lightning_density, [this]() -> void { this->throw_if_canceled(); }) : FillLightning::GeneratorPtr();
}
void PrintObject::clear_layers()
{
for (Layer* l : m_layers)
delete l;
m_layers.clear();
}
Layer* PrintObject::add_layer(int id, coordf_t height, coordf_t print_z, coordf_t slice_z)
{
m_layers.emplace_back(new Layer(id, this, height, print_z, slice_z));
return m_layers.back();
}
void PrintObject::clear_support_layers()
{
for (Layer* l : m_support_layers)
delete l;
m_support_layers.clear();
}
SupportLayer* PrintObject::add_support_layer(int id, int interface_id, coordf_t height, coordf_t print_z)
{
m_support_layers.emplace_back(new SupportLayer(id, interface_id, this, height, print_z, -1));
return m_support_layers.back();
}
SupportLayerPtrs::iterator PrintObject::insert_support_layer(SupportLayerPtrs::const_iterator pos, size_t id, size_t interface_id, coordf_t height, coordf_t print_z, coordf_t slice_z)
{
return m_support_layers.insert(pos, new SupportLayer(id, interface_id, this, height, print_z, slice_z));
}
// Called by Print::apply().
// This method only accepts PrintObjectConfig and PrintRegionConfig option keys.
bool PrintObject::invalidate_state_by_config_options(
const ConfigOptionResolver &old_config, const ConfigOptionResolver &new_config, const std::vector<t_config_option_key> &opt_keys)
{
if (opt_keys.empty())
return false;
std::vector<PrintObjectStep> steps;
bool invalidated = false;
for (const t_config_option_key& opt_key : opt_keys) {
if (
opt_key == "gap_fill_enabled"
|| opt_key == "gap_fill_extension"
|| opt_key == "gap_fill_last"
|| opt_key == "gap_fill_max_width"
|| opt_key == "gap_fill_min_area"
|| opt_key == "gap_fill_min_length"
|| opt_key == "gap_fill_min_width"
|| opt_key == "only_one_perimeter_first_layer"
|| opt_key == "only_one_perimeter_top"
|| opt_key == "only_one_perimeter_top_other_algo"
|| opt_key == "overhangs_width_speed"
|| opt_key == "overhangs_width"
|| opt_key == "overhangs_reverse"
|| opt_key == "overhangs_reverse_threshold"
|| opt_key == "overhangs_speed_enforce"
|| opt_key == "perimeter_extrusion_change_odd_layers"
|| opt_key == "perimeter_extrusion_spacing"
|| opt_key == "perimeter_extrusion_width"
|| opt_key == "infill_overlap"
|| opt_key == "thin_perimeters"
|| opt_key == "thin_perimeters_all"
|| opt_key == "thin_walls"
|| opt_key == "thin_walls_min_width"
|| opt_key == "thin_walls_overlap"
|| opt_key == "external_perimeters_first"
|| opt_key == "external_perimeters_hole"
|| opt_key == "external_perimeters_nothole"
|| opt_key == "external_perimeter_extrusion_change_odd_layers"
|| opt_key == "external_perimeter_extrusion_spacing"
|| opt_key == "external_perimeter_extrusion_width"
|| opt_key == "external_perimeters_vase"
|| opt_key == "perimeter_loop"
|| opt_key == "perimeter_loop_seam") {
steps.emplace_back(posPerimeters);
} else if (
opt_key == "gap_fill_enabled"
|| opt_key == "gap_fill_speed") {
// Return true if gap-fill speed has changed from zero value to non-zero or from non-zero value to zero.
auto is_gap_fill_changed_state_due_to_speed = [&opt_key, &old_config, &new_config]() -> bool {
if (opt_key == "gap_fill_speed") {
const auto *old_gap_fill_speed = old_config.option<ConfigOptionFloat>(opt_key);
const auto *new_gap_fill_speed = new_config.option<ConfigOptionFloat>(opt_key);
assert(old_gap_fill_speed && new_gap_fill_speed);
return (old_gap_fill_speed->value > 0.f && new_gap_fill_speed->value == 0.f) ||
(old_gap_fill_speed->value == 0.f && new_gap_fill_speed->value > 0.f);
}
return false;
};
// Filtering of unprintable regions in multi-material segmentation depends on if gap-fill is enabled or not.
// So step posSlice is invalidated when gap-fill was enabled/disabled by option "gap_fill_enabled" or by
// changing "gap_fill_speed" to force recomputation of the multi-material segmentation.
if (this->is_mm_painted() && (opt_key == "gap_fill_enabled" || (opt_key == "gap_fill_speed" && is_gap_fill_changed_state_due_to_speed())))
steps.emplace_back(posSlice);
steps.emplace_back(posPerimeters);
} else if (
opt_key == "layer_height"
|| opt_key == "first_layer_height"
|| opt_key == "mmu_segmented_region_max_width"
|| opt_key == "exact_last_layer_height"
|| opt_key == "raft_contact_distance"
|| opt_key == "raft_interface_layer_height"
|| opt_key == "raft_layers"
|| opt_key == "raft_layer_height"
|| opt_key == "slice_closing_radius"
|| opt_key == "clip_multipart_objects"
|| opt_key == "first_layer_size_compensation"
|| opt_key == "first_layer_size_compensation_layers"
|| opt_key == "elephant_foot_min_width"
|| opt_key == "dont_support_bridges"
|| opt_key == "slice_closing_radius"
|| opt_key == "slicing_mode"
|| opt_key == "support_material_contact_distance_type"
|| opt_key == "support_material_contact_distance_top"
|| opt_key == "support_material_contact_distance_bottom"
|| opt_key == "support_material_interface_layer_height"
|| opt_key == "support_material_layer_height"
|| opt_key == "xy_size_compensation"
|| opt_key == "hole_size_compensation"
|| opt_key == "hole_size_threshold"
|| opt_key == "hole_to_polyhole"
|| opt_key == "hole_to_polyhole_threshold") {
steps.emplace_back(posSlice);
} else if (opt_key == "support_material") {
steps.emplace_back(posSupportMaterial);
if (m_config.support_material_contact_distance.value == 0. || m_config.support_material_bottom_contact_distance.value == 0.) {
// Enabling / disabling supports while soluble support interface is enabled.
// This changes the bridging logic (bridging enabled without supports, disabled with supports).
// Reset everything.
// See GH #1482 for details.
steps.emplace_back(posSlice);
}
} else if (
opt_key == "raft_expansion"
|| opt_key == "raft_first_layer_density"
|| opt_key == "raft_first_layer_expansion"
|| opt_key == "support_material_auto"
|| opt_key == "support_material_angle"
|| opt_key == "support_material_angle_height"
|| opt_key == "support_material_buildplate_only"
|| opt_key == "support_material_enforce_layers"
|| opt_key == "support_material_extruder"
|| opt_key == "support_material_extrusion_width"
|| opt_key == "support_material_bottom_contact_distance"
|| opt_key == "support_material_interface_layers"
|| opt_key == "support_material_bottom_interface_layers"
|| opt_key == "support_material_interface_angle"
|| opt_key == "support_material_interface_angle_increment"
|| opt_key == "support_material_interface_pattern"
|| opt_key == "support_material_interface_contact_loops"
|| opt_key == "support_material_interface_extruder"
|| opt_key == "support_material_interface_spacing"
|| opt_key == "support_material_pattern"
|| opt_key == "support_material_interface_pattern"
|| opt_key == "support_material_style"
|| opt_key == "support_material_xy_spacing"
|| opt_key == "support_material_spacing"
|| opt_key == "support_material_closing_radius"
|| opt_key == "support_material_synchronize_layers"
|| opt_key == "support_material_threshold"
|| opt_key == "support_material_with_sheath") {
steps.emplace_back(posSupportMaterial);
} else if (opt_key == "bottom_solid_layers") {
steps.emplace_back(posPrepareInfill);
if (m_print->config().spiral_vase
|| opt_key == "z_step") {
// Changing the number of bottom layers when a spiral vase is enabled requires re-slicing the object again.
// Otherwise, holes in the bottom layers could be filled, as is reported in GH #5528.
steps.emplace_back(posSlice);
}
} else if (
opt_key == "bottom_solid_min_thickness"
|| opt_key == "ensure_vertical_shell_thickness"
|| opt_key == "interface_shells"
|| opt_key == "infill_extruder"
|| opt_key == "infill_extrusion_change_odd_layers"
|| opt_key == "infill_extrusion_spacing"
|| opt_key == "infill_extrusion_width"
|| opt_key == "infill_every_layers"
|| opt_key == "infill_dense"
|| opt_key == "infill_dense_algo"
|| opt_key == "infill_not_connected"
|| opt_key == "infill_only_where_needed"
|| opt_key == "ironing_type"
|| opt_key == "solid_infill_below_area"
|| opt_key == "solid_infill_extruder"
|| opt_key == "solid_infill_every_layers"
|| opt_key == "solid_over_perimeters"
|| opt_key == "top_solid_layers"
|| opt_key == "top_solid_min_thickness") {
steps.emplace_back(posPrepareInfill);
} else if (
opt_key == "top_fill_pattern"
|| opt_key == "bottom_fill_pattern"
|| opt_key == "bridge_fill_pattern"
|| opt_key == "solid_fill_pattern"
|| opt_key == "enforce_full_fill_volume"
|| opt_key == "fill_angle"
|| opt_key == "fill_angle_increment"
|| opt_key == "fill_top_flow_ratio"
|| opt_key == "fill_smooth_width"
|| opt_key == "fill_smooth_distribution"
|| opt_key == "infill_anchor"
|| opt_key == "infill_anchor_max"
|| opt_key == "infill_connection"
|| opt_key == "infill_connection_bottom"
|| opt_key == "infill_connection_bridge"
|| opt_key == "infill_connection_solid"
|| opt_key == "infill_connection_top"
|| opt_key == "seam_gap"
|| opt_key == "seam_gap_external"
|| opt_key == "top_infill_extrusion_spacing"
|| opt_key == "top_infill_extrusion_width" ) {
steps.emplace_back(posInfill);
} else if (opt_key == "fill_pattern") {
steps.emplace_back(posInfill);
const auto *old_fill_pattern = old_config.option<ConfigOptionEnum<InfillPattern>>(opt_key);
const auto *new_fill_pattern = new_config.option<ConfigOptionEnum<InfillPattern>>(opt_key);
assert(old_fill_pattern && new_fill_pattern);
// We need to recalculate infill surfaces when infill_only_where_needed is enabled, and we are switching from
// the Lightning infill to another infill or vice versa.
if (m_config.infill_only_where_needed && (new_fill_pattern->value == ipLightning || old_fill_pattern->value == ipLightning))
steps.emplace_back(posPrepareInfill);
} else if (opt_key == "fill_density") {
// One likely wants to reslice only when switching between zero infill to simulate boolean difference (subtracting volumes),
// normal infill and 100% (solid) infill.
const auto *old_density = old_config.option<ConfigOptionPercent>(opt_key);
const auto *new_density = new_config.option<ConfigOptionPercent>(opt_key);
assert(old_density && new_density);
//FIXME Vojtech is not quite sure about the 100% here, maybe it is not needed.
if (is_approx(old_density->value, 0.) || is_approx(old_density->value, 100.) ||
is_approx(new_density->value, 0.) || is_approx(new_density->value, 100.))
steps.emplace_back(posPerimeters);
steps.emplace_back(posPrepareInfill);
} else if (
opt_key == "bridge_angle"
|| opt_key == "bridged_infill_margin"