forked from smartavionics/CuraEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
layerPart.cpp
122 lines (110 loc) · 4.58 KB
/
layerPart.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
//Copyright (c) 2018 Ultimaker B.V.
//CuraEngine is released under the terms of the AGPLv3 or higher.
#include "layerPart.h"
#include "sliceDataStorage.h"
#include "slicer.h"
#include "settings/EnumSettings.h" //For ESurfaceMode.
#include "settings/Settings.h"
#include "progress/Progress.h"
#include "utils/SVG.h" // debug output
/*
The layer-part creation step is the first step in creating actual useful data for 3D printing.
It takes the result of the Slice step, which is an unordered list of polygons, and makes groups of polygons,
each of these groups is called a "part", which sometimes are also known as "islands". These parts represent
isolated areas in the 2D layer with possible holes.
Creating "parts" is an important step, as all elements in a single part should be printed before going to another part.
And all every bit inside a single part can be printed without the nozzle leaving the boundary of this part.
It's also the first step that stores the result in the "data storage" so all other steps can access it.
*/
namespace cura {
void createLayerWithParts(const Settings& settings, SliceLayer& storageLayer, SlicerLayer* layer)
{
storageLayer.openPolyLines = layer->openPolylines;
const bool union_all_remove_holes = settings.get<bool>("meshfix_union_all_remove_holes");
if (union_all_remove_holes)
{
for(unsigned int i=0; i<layer->polygons.size(); i++)
{
if (layer->polygons[i].orientation())
layer->polygons[i].reverse();
}
}
std::vector<PolygonsPart> result;
const bool union_layers = settings.get<bool>("meshfix_union_all");
const ESurfaceMode surface_only = settings.get<ESurfaceMode>("magic_mesh_surface_mode");
if (surface_only == ESurfaceMode::SURFACE && !union_layers)
{ // Don't do anything with overlapping areas; no union nor xor
result.reserve(layer->polygons.size());
for (const PolygonRef poly : layer->polygons)
{
result.emplace_back();
result.back().add(poly);
}
}
else
{
result = layer->polygons.splitIntoParts(union_layers || union_all_remove_holes);
}
const coord_t hole_offset = settings.get<coord_t>("hole_xy_offset");
for(unsigned int i=0; i<result.size(); i++)
{
storageLayer.parts.emplace_back();
if (hole_offset != 0)
{
// holes are to be expanded or shrunk
PolygonsPart outline;
Polygons holes;
for (const PolygonRef poly : result[i])
{
if (poly.orientation())
{
outline.add(poly);
}
else
{
holes.add(poly.offset(hole_offset));
}
}
for (PolygonRef hole : holes.unionPolygons().intersection(outline))
{
hole.reverse();
outline.add(hole);
}
storageLayer.parts[i].outline = outline;
}
else
{
storageLayer.parts[i].outline = result[i];
}
storageLayer.parts[i].boundaryBox.calculate(storageLayer.parts[i].outline);
}
}
void createLayerParts(SliceMeshStorage& mesh, Slicer* slicer)
{
const auto total_layers = slicer->layers.size();
assert(mesh.layers.size() == total_layers);
// OpenMP compatibility fix for GCC <= 8 and GCC >= 9
// See https://www.gnu.org/software/gcc/gcc-9/porting_to.html, section "OpenMP data sharing"
#if defined(__GNUC__) && __GNUC__ <= 8
#pragma omp parallel for default(none) shared(mesh, slicer) schedule(dynamic)
#else
#pragma omp parallel for default(none) shared(mesh, slicer, total_layers) schedule(dynamic)
#endif // defined(__GNUC__) && __GNUC__ <= 8
// Use a signed type for the loop counter so MSVC compiles (because it uses OpenMP 2.0, an old version).
for (int layer_nr = 0; layer_nr < static_cast<int>(total_layers); layer_nr++)
{
SliceLayer& layer_storage = mesh.layers[layer_nr];
SlicerLayer& slice_layer = slicer->layers[layer_nr];
createLayerWithParts(mesh.settings, layer_storage, &slice_layer);
}
for (LayerIndex layer_nr = total_layers - 1; layer_nr >= 0; layer_nr--)
{
SliceLayer& layer_storage = mesh.layers[layer_nr];
if (layer_storage.parts.size() > 0 || (mesh.settings.get<ESurfaceMode>("magic_mesh_surface_mode") != ESurfaceMode::NORMAL && layer_storage.openPolyLines.size() > 0))
{
mesh.layer_nr_max_filled_layer = layer_nr; // last set by the highest non-empty layer
break;
}
}
}
}//namespace cura