-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpostprocess.cpp
57 lines (56 loc) · 2.17 KB
/
postprocess.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
#include "postprocess.h"
namespace nesting {
std::vector<Polygon_with_holes_2> postprocess(
std::vector<TransformedShape>& solution,
double offset,
double left_offset,
double bottom_offset,
const std::vector<Item>& simplified_items,
const std::vector<Item>& original_items) {
std::vector<Polygon_with_holes_2> res;
res.reserve(solution.size());
for (auto& t : solution) {
// Step1 将所有多边形平移(left_offset, bottom_offset)
if (left_offset != 0 || bottom_offset != 0) {
t.set_translate(t.get_translate_ft_x() + left_offset,
t.get_translate_ft_y() + bottom_offset);
}
if (offset == 0 && !t.simplified) {
res.push_back(t.transformed);
continue;
}
// Step2 复原膨胀的多边形
auto rotate = geo::get_rotate(t.get_rotation(), t.allowed_rotations);
auto translate = t.get_translate();
Polygon_with_holes_2 simplified_pwh(simplified_items[t.item_idx].poly);
if (offset != 0) {
if (rotate) {
simplified_pwh = geo::transform_polygon_with_holes(
translate * (*rotate), simplified_pwh);
} else {
simplified_pwh =
geo::transform_polygon_with_holes(translate, simplified_pwh);
}
}
// Step3 判断是否需要复原简化,需要就复原简化的多边形
if (t.simplified) {
Polygon_with_holes_2 original_pwh(original_items[t.item_idx].poly);
if (rotate) {
original_pwh = geo::transform_polygon_with_holes(*rotate, original_pwh);
}
auto& outer1 = original_pwh.outer_boundary();
auto p1 = geo::find_bottom_left_vertex(outer1);
auto& outer0 = (offset != 0) ? simplified_pwh.outer_boundary()
: t.transformed.outer_boundary();
auto p0 = geo::find_bottom_left_vertex(outer0);
Transformation tr(CGAL::TRANSLATION,
Vector_2(p0.x() - p1.x(), p0.y() - p1.y()));
original_pwh = geo::transform_polygon_with_holes(tr, original_pwh);
res.push_back(original_pwh);
} else {
res.push_back(simplified_pwh);
}
}
return res;
}
} // namespace nesting