FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ORNLSlicer/src/optimizers/layer_order_optimizer.cpp at develop · ORNLSlicer/ORNLSlicer · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
ORNLSlicer
/
ORNLSlicer
Public
Notifications
You must be signed in to change notification settings
Fork
20
Star
92
Code
Issues
21
Pull requests
9
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
ORNLSlicer
/
src
/
optimizers
/
layer_order_optimizer.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
161 lines (131 loc) · 6.89 KB
Breadcrumbs
ORNLSlicer
/
src
/
optimizers
/
layer_order_optimizer.cpp
Copy path
File metadata and controls
161 lines (131 loc) · 6.89 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
"
optimizers/layer_order_optimizer.h
"
#
include
<
qassert.h
>
#
include
<
qcontainerfwd.h
>
#
include
<
qlist.h
>
#
include
<
qmap.h
>
#
include
<
qminmax.h
>
#
include
<
qsharedpointer.h
>
#
include
<
quuid.h
>
#
include
<
qvectornd.h
>
#
include
"
configs/settings_base.h
"
#
include
"
geometry/plane.h
"
#
include
"
geometry/point.h
"
#
include
"
part/part.h
"
#
include
"
step/global_layer.h
"
#
include
"
step/step.h
"
#
include
"
units/unit.h
"
#
include
"
utilities/constants.h
"
#
include
"
utilities/enums.h
"
#
include
"
utilities/mathutils.h
"
namespace
ORNL
{
QList<QSharedPointer<GlobalLayer>>
LayerOrderOptimizer::populateSteps
(QSharedPointer<SettingsBase> global_sb,
QVector<QSharedPointer<Part>> build_parts) {
//
list to return at end of function
QList<QSharedPointer<GlobalLayer>> global_layers = QList<QSharedPointer<GlobalLayer>>();
//
get the layer ordering method, and then populate the global layers accordingly
LayerOrdering order_method = global_sb->
setting
<LayerOrdering>(
PS
::Optimizations::
kLayerOrdering
);
if
(order_method == LayerOrdering::
kByHeight
) {
//
Retrieve the slicing plane normal
QVector3D slicing_vector = {global_sb->
setting
<
float
>(
PS
::Slicing::
kSlicePlaneNormalX
),
global_sb->
setting
<
float
>(
PS
::Slicing::
kSlicePlaneNormalY
),
global_sb->
setting
<
float
>(
PS
::Slicing::
kSlicePlaneNormalZ
)};
slicing_vector.
normalize
();
bool
steps_left =
true
;
int
num_global_steps =
0
;
//
Make a map to track the step/layer number each part is currently on
//
Start each part at zero
QMap<QUuid,
int
> current_layer;
for
(
auto
& part : build_parts) current_layer.
insert
(part->
getId
(),
0
);
while
(steps_left) {
//
Check the current step of all the parts, find the minimum plane
QUuid part_with_min_plane =
QUuid
();
//
null quuid initially
Plane min_plane;
Distance min_dist;
//
Check all the parts for the next "lowest" layer to print
for
(
auto
& part : build_parts) {
QUuid part_id = part->
getId
();
//
Skip the part if all its layers have been assigned to a global layer
if
(current_layer[part_id] >= part->
countStepPairs
())
continue
;
//
Get the current layer for this part
QSharedPointer<Step> current_step = part->
getStepPair
(current_layer[part_id]).
printing_layer
;
//
calculate the distance from
Plane layer_plane = current_step->
getSlicingPlane
();
Distance layer_height = current_step->
getSb
()->
setting
<Distance>(
PS
::Layer::
kLayerHeight
);
layer_plane.
shiftAlongNormal
(
layer_height
() /
2.0
);
Distance layer_dist =
MathUtils::linePlaneIntersection
(
Point
(
0
,
0
,
0
), slicing_vector, layer_plane).
distance
();
//
If this is the first plane in this loop, or its lower than the current min, set this layer as the min
if
(part_with_min_plane.
isNull
() || layer_dist < min_dist) {
part_with_min_plane = part_id;
min_plane = layer_plane;
min_dist = layer_dist;
}
}
//
check all the parts (again) for layers with the same plane as the lowest layer. Layers with same plane
//
can be printed at the same time, and go on the same global layer
QSharedPointer<GlobalLayer> new_global_layer = QSharedPointer<GlobalLayer>::
create
(num_global_steps);
for
(
auto
& part : build_parts) {
QUuid part_id = part->
getId
();
//
skip the part if all its layers have been assigned to a global layer
if
(current_layer[part_id] >= part->
countStepPairs
())
continue
;
//
get the current layer for this part
QSharedPointer<Step> current_step = part->
getStepPair
(current_layer[part_id]).
printing_layer
;
Distance layer_height = current_step->
getSb
()->
setting
<Distance>(
PS
::Layer::
kLayerHeight
);
Distance layer_grouping_tolerance =
global_sb->
setting
<Distance>(
PS
::Optimizations::
kLayerGroupingTolerance
);
Plane layer_plane = current_step->
getSlicingPlane
();
layer_plane.
shiftAlongNormal
(
layer_height
() /
2.0
);
//
if this part's current layer is equal to the min plane, add it to the global layer
if
(layer_plane.
isEqual
(min_plane,
layer_grouping_tolerance
())) {
new_global_layer->
addStepPair
(part_id, part->
getStepPair
(current_layer[part_id]));
++current_layer[part_id];
}
}
//
add the new global layer to the list
global_layers.
push_back
(new_global_layer);
++num_global_steps;
//
update steps_left
steps_left =
false
;
for
(
auto
& part : build_parts)
steps_left = steps_left || (current_layer[part->
getId
()] < part->
countStepPairs
());
}
//
end while(steps left)
}
else
if
(order_method == LayerOrdering::
kByLayerNumber
) {
//
look at all the parts to find the maximum number of steps
//
this will be the number of global layers
int
max_steps =
0
;
for
(
auto
part : build_parts) max_steps =
qMax
(max_steps, part->
countStepPairs
());
global_layers.
reserve
(max_steps);
//
for each global layer
//
make a new layer
//
add the steps/layers/scan layers from all the parts
for
(
int
step =
0
; step < max_steps; ++step) {
QSharedPointer<GlobalLayer> new_global_layer = QSharedPointer<GlobalLayer>::
create
(step);
for
(
auto
part : build_parts) {
if
(step < part->
countStepPairs
())
new_global_layer->
addStepPair
(part->
getId
(), part->
getStepPair
(step));
}
global_layers.
push_back
(new_global_layer);
}
}
else
if
(order_method == LayerOrdering::
kByPart
) {
//
printing parts sequentially, so every part layer gets its own global layer
int
max_steps =
0
;
for
(
auto
part : build_parts) max_steps += part->
countStepPairs
();
global_layers.
reserve
(max_steps);
int
num_g_steps =
0
;
for
(
auto
part : build_parts) {
for
(
int
s =
0
, max_steps = part->
countStepPairs
(); s < max_steps; ++s) {
QSharedPointer<GlobalLayer> new_global_layer = QSharedPointer<GlobalLayer>::
create
(num_g_steps);
new_global_layer->
addStepPair
(part->
getId
(), part->
getStepPair
(s));
global_layers.
push_back
(new_global_layer);
++num_g_steps;
}
}
}
else
{
Q_ASSERT
(
false
);
//
invalid order method
}
return
global_layers;
}
}
//
namespace ORNL
Back
|
FazBrowse Home
|
New Git URL